#import "entity/telegram_connection" // Lumi's connection with real account storage and the real Lumi and // Telegram pumps; only the HTTP transport is synthetic and records every // request. Offline, or without the agreement, nothing reaches it at all. #import, file "../src/apps/lumi_online.zi"; #import, file "../src/screens/lumi_screen.zi"; #import, file "../src/apps/lumi_ui_types.zi"; #import, file "../src/apps/lumi_connection.zi"; #import, file "../src/apps/lumi_telegram.zi"; #import, file "../src/apps/feedback_store.zi"; #import, file "../src/apps/lumi_store.zi"; #import, file "../src/apps/diary_spelling.zi"; #import, file "../src/apps/habit_icon_choice.zi"; #import, file "../src/habits/habit_types.zi"; #import, file "../src/habits/habit_model.zi"; #import, file "../src/habits/habit_icons.zi"; #import "drawing_props" #import, file "../src/apps/package_files.zi"; #import, file "../src/app/app_types.zi"; #import, file "../src/app/app_clock_host.zi"; #import, file "../src/app/text_buffers.zi"; #import, file "../src/storage/account_types.zi"; #import, file "../src/storage/db.zi"; #import, file "../src/storage/data.zi"; #import, file "../src/storage/state.zi"; #import, file "../src/storage/storage_settings.zi"; #import, file "../src/storage/bundled_app_records.zi"; #import, file "../src/storage/sync_async.zi"; #import "keys" #import "mesh_client/crypto" #import, file "../src/storage/sync_account.zi"; #import, file "storage_test_support.zi"; #import "async_client" #import "net_http" #import "text_buffer" #import "wire" #import "transaction" #import, file "../src/apps/catalog.zi"; #import "vec" #import "byte_text_linux" #import "json_scan" #import, file "../src/apps/app_tools.zi"; c :: #system_library "c"; TestNow :: (out: *s64) -> s64 #foreign c "time"; // The full host state exceeds the native test process's stack limit. app: InnerBreeze; owner: AccountKeys; requests: s32; chat_requests: s32; developer_requests: s32; developer_id: [33]u8; provider_requests: s32; feedback_requests: s32; telegram_requests: s32; telegram_update_pending: bool; telegram_answers: s32; spelling_requests: s32; icon_requests: s32; icon_habits: Habits; provider_url: [256]u8; provider_token: [128]u8; provider_body: [65536]u8; provider_response_capacity: s64; continuation_test: bool; continuation_round: s32; tool_executions: s32; provider_reply: string; provider_empty_reply: bool; provider_hold: bool; provider_status: s32 = 200; provider_start_fail: bool; provider_switch_account: bool; TEST_KEY :: "sk-test-lumi-provider-0123456789" ContinuationReply :: (request: HttpRequest, output: []u8) -> bool { messages := FieldAt(request.body, 0, "messages") count := ArrayCount(request.body, messages) check_true("tool continuations fit the node's twenty-message limit", count <= 20) check_true("the current request survives history trimming", contains(request.body, "finish the six-step request")) if count > 20 { return false } // Every assistant tool call must still have its matching result directly // after it. Dropping an in-flight tool message would be an invalid repair. for index: cast(s32)0..count - 1 { at := ElementAt(request.body, messages, index) calls := FieldAt(request.body, at, "tool_calls") for call: cast(s32)0..ArrayCount(request.body, calls) - 1 { item := ElementAt(request.body, calls, call) result := ElementAt(request.body, messages, index + call + 1) id: [129]u8 result_id: [129]u8 check_true("each tool call retains its result", result >= 0 && ToolString(request.body[item:ValueEnd(request.body, item, 0)], "id", id[:]) == ToolString(request.body[result:ValueEnd(request.body, result, 0)], "tool_call_id", result_id[:])) } } if continuation_round == 6 { return AppCopyText("{\"message\":{\"role\":\"assistant\",\"content\":\"The six steps are complete\"}}", output) } out: Vec(u8) BuilderPrint(*out, "{\"message\":{\"role\":\"assistant\",\"tool_calls\":[") calls := ifx continuation_round < 3 then 3 else 1 for index: cast(s32)0..calls - 1 { BuilderPrint(*out, "%{\"id\":\"step-%-%\",\"type\":\"function\",\"function\":{\"name\":\"read_context\",\"arguments\":\"{}\"}}", ifx index == 0 then "" else ",", continuation_round, index) } BuilderPrint(*out, "]}}") response := BuilderFinish(out) defer { PackageFree(response) } continuation_round += 1 return AppCopyText(response, output) } // Records the request and answers it as the server or provider would. ConnectionStart :: (context: *void, request: HttpRequest, output: []u8) -> bool { unused context requests += 1 challenge_url := "https://api.waozi.xyz/api/v1/sync/challenge?user_id=" if request.url.count == challenge_url.count + 64 && request.url[:challenge_url.count] == challenge_url { return AppCopyText("{\"nonce\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"}", output) } if request.url == "https://api.waozi.xyz/api/v1/sync/login" { writer: Writer = .{output, 0, true} writer = WriteText(writer, "{\"auth_token\":\"synthetic-lumi-token\",\"expires_in_seconds\":3600,\"server_time\":") writer = WriteDecimal(writer, TestNow(null)) writer = WriteByte(writer, cast(u8)125) return writer.valid } if request.url == "https://api.waozi.xyz/api/v1/account/devices" { return AppCopyText("true", output) } if request.url == "https://api.waozi.xyz/api/v1/chat/completions" { chat_requests += 1 check_true("normal Lumi never sends private Harmony history", !contains(request.body, "private coding fixture")) if continuation_test { return ContinuationReply(request, output) } if telegram_update_pending { return AppCopyText("{\"message\":{\"role\":\"assistant\",\"content\":\"Telegram answer\"}}", output) } return AppCopyText("{\"message\":{\"role\":\"assistant\",\"content\":\"Hello from the server\"},\"remaining\":19}", output) } if request.url == "https://api.waozi.xyz/api/v1/lumi/developer" { developer_requests += 1 check_true("developer request uses the signed account session", request.token == "synthetic-lumi-token") check_true("developer request sends no Lumi tools or account context", FieldAt(request.body, 0, "context") < 0 && FieldAt(request.body, 0, "tools") < 0) id: [33]u8 value := ToolString(request.body, "id", id[:]) out: Vec(u8) if developer_requests == 1 { check_true("submit contains just the coding request", contains(request.body, "private coding fixture")) unused AppCopyText(value, developer_id[:]) BuilderPrint(*out, "{\"id\":\"%\"}", value) } else { check_true("poll reuses the accepted request id", value == TextUntilNul(developer_id[:])) check_true("poll doesn't resubmit the coding request", FieldAt(request.body, 0, "text") < 0) BuilderPrint(*out, "{\"id\":\"%\",\"reply\":\"Completed private coding fixture\"}", value) } reply := BuilderFinish(out) defer { PackageFree(reply) } return AppCopyText(reply, output) } if request.url == "https://api.waozi.xyz/api/v1/chat/spelling" { spelling_requests += 1 return AppCopyText("{\"text\":\"Hello\"}", output) } if request.url == "https://api.waozi.xyz/api/v1/chat/habit-icons" { icon_requests += 1 return AppCopyText("{\"icons\":[\"book\"]}", output) } if contains(request.url, "/api/v1/feedback") { feedback_requests += 1 return AppCopyText("{\"feedback\":[]}", output) } if request.url == "https://api.waozi.xyz/api/v1/lumi/telegram/ack" { telegram_answers += 1 check_true("acknowledgement retains the Telegram update ID", contains(request.body, "\"id\":38")) check_true("acknowledgement carries a reply", FieldAt(request.body, 0, "reply") >= 0) answer: [64]u8 check_true("only the final answer of the claimed turn reaches Telegram", ToolString(request.body, "reply", answer[:]) == "Telegram answer") telegram_update_pending = false return AppCopyText("true", output) } if contains(request.url, "/api/v1/lumi/telegram") { telegram_requests += 1 if telegram_update_pending { return AppCopyText("{\"linked\":true,\"update\":{\"id\":38,\"kind\":\"message\",\"text\":\"Can you explain this?\",\"can_reply\":true}}", output) } return AppCopyText("{\"linked\":false}", output) } if request.url.count > 17 && request.url[:17] == "http://127.0.0.1:" { provider_requests += 1 provider_response_capacity = output.count unused AppCopyText(request.url, provider_url[:]) unused AppCopyText(request.token, provider_token[:]) unused AppCopyText(request.body, provider_body[:]) if provider_start_fail { return false } if provider_empty_reply || provider_reply.count > 0 { out: Vec(u8) BuilderPrint(*out, "{\"choices\":[{\"message\":{\"role\":\"assistant\",\"content\":") LumiJsonString(*out, provider_reply) BuilderPrint(*out, "}}]}") response := BuilderFinish(out) defer { PackageFree(response) } return AppCopyText(response, output) } return AppCopyText("{\"id\":\"x\",\"choices\":[{\"index\":0,\"message\":{\"role\":\"assistant\",\"content\":\"Hello from the provider\"},\"finish_reason\":\"stop\"}]}", output) } check_true("no other address is contacted", false) return false } ConnectionPoll :: (context: *void, status: *s32) -> s32 { unused context if lumi_online_stage == LUMI_STAGE_PROVIDER { if provider_switch_account { provider_switch_account = false unused AppCopyText("another-account", g_storage.user_id[:]) } status.* = provider_status return ifx provider_hold then -1 else 1 } status.* = 200 return 1 } ConnectionCancel :: (context: *void) { unused context } #program_export ConnectionTestTransport :: () -> AsyncTransport { return AsyncTransport.{null, ConnectionStart, ConnectionPoll, ConnectionCancel} } // Lets every timed retry run now, then pumps a while. Pump :: (app: *InnerBreeze) { for step: cast(s32)0..29 { lumi_feedback_retry = 0 lumi_reply_retry = 0 lumi_telegram_connection.retry = 0 lumi_developer_retry = 0 app_lumi_pump(app) } } // The composer stores the person's message, then asks the host to go // online with it. Ask :: (text: string) -> bool { LumiStoreAppend(text, true) return LumiOnlineStart(text) } #program_export TelegramFixtureSubmit :: (text: string) -> bool { LumiStoreAppend(text, true) return LumiOnlineStart(text, false) } ProviderTail :: (expected: []string) { body := TextUntilNul(provider_body[:]) messages := FieldAt(body, 0, "messages") count := ArrayCount(body, messages) check_true("queued request has preceding conversation", count >= expected.count) for index: cast(s32)0..cast(s32)expected.count - 1 { at := ElementAt(body, messages, count - cast(s32)expected.count + index) content: [4096]u8 check_true("queued messages and preceding answers stay in order", at >= 0 && ToolString(body[at:ValueEnd(body, at, 0)], "content", content[:]) == expected[index]) } } QueuedTurns :: (app: *InnerBreeze) { before := provider_requests history := LumiStoreCount() provider_hold = true check_true("first rapid message starts", Ask("queued-first")) lumi_online_fresh = false app_lumi_pump(app) check_true("first rapid request is in flight", lumi_online_stage == LUMI_STAGE_PROVIDER) check_true("second rapid message is accepted", Ask("queued-second")) second_turn := PackageText(LumiStoreLatestUserKey(), "") defer { PackageFree(second_turn) } check_true("third rapid message is accepted", Ask("queued-third")) third_turn := PackageText(LumiStoreLatestUserKey(), "") defer { PackageFree(third_turn) } check_true("queued inputs retain distinct archived turn identities", lumi_online_inputs.count == 2 && lumi_online_inputs[0].turn_id == second_turn && lumi_online_inputs[1].turn_id == third_turn && second_turn != third_turn && feedback_turn_id != second_turn) check_int("waiting messages are immediately recorded", LumiStoreCount(), history + 3) check_true("recorded user order is preserved", LumiStoreRow(history).text == "queued-first" && LumiStoreRow(history + 1).text == "queued-second" && LumiStoreRow(history + 2).text == "queued-third") check_true("first request never sees later messages", !contains(TextUntilNul(provider_body[:]), "queued-second")) unused AppCopyText("unfinished draft 茶", lumi_input[:]) lumi_ui.cursor = 4 lumi_ui.anchor = 2 app_lumi_pump(app) check_int("pending responses never start concurrently", provider_requests, before + 1) provider_hold = false for step: cast(s32)0..9 { if provider_requests == before + 2 { break } app_lumi_pump(app) } second: [3]string = .["queued-first", "Hello from the provider", "queued-second"] ProviderTail(second[:]) check_true("starting queued turn uses its own message identity", feedback_turn_id == second_turn) check_true("second request never sees third input", !contains(TextUntilNul(provider_body[:]), "queued-third")) Pump(app) third: [5]string = .["queued-first", "Hello from the provider", "queued-second", "Hello from the provider", "queued-third"] ProviderTail(third[:]) check_int("each rapid input gets one request", provider_requests, before + 3) check_true("all rapid turns finish", !LumiOnlineWaiting() && lumi_online_inputs.count == 0) check_true("late answers preserve the current draft and selection", TextUntilNul(lumi_input[:]) == "unfinished draft 茶" && lumi_ui.cursor == 4 && lumi_ui.anchor == 2) check_true("failing turn starts", Ask("failed-first")) lumi_online_fresh = false app_lumi_pump(app) check_true("follow-up queues behind failure", Ask("after-failure")) provider_status = 503 app_lumi_pump(app) provider_status = 200 Pump(app) failed: [3]string = .["failed-first", "UNAVAILABLE", "after-failure"] ProviderTail(failed[:]) check_true("failure does not discard follow-up", LastRow() == "Hello from the provider" && !LumiOnlineWaiting()) check_true("start failure turn is accepted", Ask("start-failure")) check_true("start failure follow-up is accepted", Ask("after-start-failure")) lumi_online_fresh = false provider_start_fail = true app_lumi_pump(app) provider_start_fail = false Pump(app) start_failed: [3]string = .["start-failure", "UNAVAILABLE", "after-start-failure"] ProviderTail(start_failed[:]) check_true("start failure does not discard follow-up", !LumiOnlineWaiting()) check_true("offline cancellation turn starts", Ask("cancel-active")) lumi_online_fresh = false provider_hold = true app_lumi_pump(app) check_true("offline cancellation has queued input", Ask("cancel-queued")) history = LumiStoreCount() before = provider_requests storage_set_setting_int(LumiOnlineSetting, 0) Pump(app) check_true("offline cancels both active and queued turns", !LumiOnlineWaiting() && lumi_online_inputs.count == 0) check_int("offline cancellation preserves recorded messages", LumiStoreCount(), history) storage_set_setting_int(LumiOnlineSetting, 1) Pump(app) check_int("going online never resubmits canceled input", provider_requests, before) provider_hold = false check_true("provider change turn starts", Ask("old-provider-active")) lumi_online_fresh = false provider_hold = true app_lumi_pump(app) check_true("provider change has queued input", Ask("old-provider-queued")) before = provider_requests storage_set_setting_text(LumiProviderUrlSetting, "http://127.0.0.1:10/v1") check_true("replacement provider can be agreed", LumiAgree()) Pump(app) check_true("changing provider cancels previous turns", !LumiOnlineWaiting() && lumi_online_inputs.count == 0) check_int("old queued inputs never reach replacement provider", provider_requests, before) storage_set_setting_text(LumiProviderUrlSetting, "http://127.0.0.1:9/v1") check_true("original provider can be agreed again", LumiAgree()) provider_hold = false check_true("account cancellation turn starts", Ask("old-account-active")) check_true("account cancellation has queued input", Ask("old-account-queued")) saved_owner: [64]u8 unused AppCopyText(AppTextFromCString(storage_user_id_buffer(), 64), saved_owner[:]) unused AppCopyText("another-account", g_storage.user_id[:]) app_lumi_pump(app) check_true("account switch clears old pending requests", !LumiOnlineWaiting() && lumi_online_inputs.count == 0) check_int("old responses never enter the new account", LumiStoreCount(), 0) unused AppCopyText(TextUntilNul(saved_owner[:]), g_storage.user_id[:]) check_true("old account retains its submitted message order", LumiStoreRow(LumiStoreCount() - 2).text == "old-account-active" && LastRow() == "old-account-queued") check_true("polling account change turn starts", Ask("poll-account-active")) lumi_online_fresh = false app_lumi_pump(app) check_true("polling account change has queued input", Ask("poll-account-queued")) provider_switch_account = true app_lumi_pump(app) check_true("account change during provider polling cancels the queue", !LumiOnlineWaiting() && lumi_online_inputs.count == 0) check_int("late old-account answer never reaches another account", LumiStoreCount(), 0) unused AppCopyText(TextUntilNul(saved_owner[:]), g_storage.user_id[:]) check_true("poll cancellation preserves old account's message", LastRow() == "poll-account-queued") } // Run a real provider turn with the same monotonic times the frame loop // passes. The fixture controls only the remote transport and time. PacedStart :: (app: *InnerBreeze, text: string, now: float64) { check_true("paced turn is accepted", Ask(text)) app_lumi_pump(app, true, now) app_lumi_pump(app, true, now + 0.1) check_true("starting a network request never shows typing", !LumiOnlineTyping()) } PacedTurns :: (app: *InnerBreeze) { before := provider_requests provider_hold = true PacedStart(app, "paced first", 1.0) app_lumi_pump(app, true, 4.0) check_true("a slow network leaves the composer quiet", LumiOnlineWaiting() && !LumiOnlineTyping()) check_true("waiting reveals no assistant text", LastRow() == "paced first") provider_hold = false app_lumi_pump(app, true, 4.1) check_true("validated final text starts the typing precursor", LumiOnlineTyping() && LumiOnlineWaiting()) check_true("the answer stays out of history until shown", LastRow() == "paced first") check_true("another message can be sent during the precursor", Ask("paced follow-up")) submitted := LumiStoreCount() LumiOnlineTypingDrawn(4.3) LumiOnlineTypingDrawn(4.6) app_lumi_pump(app, true, 4.8) check_true("redrawing does not restart the lead-in", LumiOnlineTyping() && LumiStoreCount() == submitted) check_int("follow-up waits behind the confirmed reply", provider_requests, before + 1) app_lumi_pump(app, true, 5.0) check_true("lead-in completion reveals exactly one answer", !LumiOnlineTyping() && LumiStoreCount() == submitted + 1 && LastRow() == "Hello from the provider") app_lumi_pump(app, true, 5.1) check_int("the next pump does not repeat the answer", LumiStoreCount(), submitted + 1) app_lumi_pump(app, true, 5.2) queued: [3]string = .["paced first", "Hello from the provider", "paced follow-up"] ProviderTail(queued[:]) app_lumi_pump(app, true, 5.3) check_true("the next server reply gets its own precursor", LumiOnlineTyping()) app_lumi_pump(app, false, 5.4) check_true("leaving Lumi completes the ready reply without stale dots", !LumiOnlineWaiting() && !LumiOnlineTyping() && LumiStoreCount() == submitted + 2) PacedStart(app, "unpainted precursor", 7.0) app_lumi_pump(app, true, 7.2) check_true("an unpainted precursor initially keeps the reply ready", LumiOnlineTyping()) app_lumi_pump(app, true, 9.0) check_true("an unpainted precursor still has a bounded delivery", !LumiOnlineWaiting() && LastRow() == "Hello from the provider") PacedStart(app, "failed paced request", 10.0) provider_status = 503 app_lumi_pump(app, true, 10.2) provider_status = 200 check_true("transport errors are immediate and never show typing", !LumiOnlineWaiting() && !LumiOnlineTyping() && LastRow() == "UNAVAILABLE") provider_empty_reply = true PacedStart(app, "empty paced request", 11.0) app_lumi_pump(app, true, 11.2) provider_empty_reply = false check_true("a successful response without text has no precursor", !LumiOnlineWaiting() && !LumiOnlineTyping() && LastRow() == "UNAVAILABLE") PacedStart(app, "turn canceled during precursor", 12.0) app_lumi_pump(app, true, 12.2) check_true("canceled reply was ready", LumiOnlineTyping()) storage_set_setting_int(LumiOnlineSetting, 0) app_lumi_pump(app, true, 12.3) storage_set_setting_int(LumiOnlineSetting, 1) app_lumi_pump(app, true, 15.0) check_true("going offline clears the confirmed reply and its dots", !LumiOnlineWaiting() && !LumiOnlineTyping() && LastRow() == "turn canceled during precursor") PacedStart(app, "old account precursor", 16.0) app_lumi_pump(app, true, 16.2) check_true("old account reply was ready", LumiOnlineTyping()) saved_owner: [64]u8 unused AppCopyText(AppTextFromCString(storage_user_id_buffer(), 64), saved_owner[:]) unused AppCopyText("another-account", g_storage.user_id[:]) app_lumi_pump(app, true, 19.0) check_true("account change removes the confirmed reply and its dots", !LumiOnlineWaiting() && !LumiOnlineTyping() && LumiStoreCount() == 0) unused AppCopyText(TextUntilNul(saved_owner[:]), g_storage.user_id[:]) check_true("the discarded answer is never delivered on return", LastRow() == "old account precursor") } LastRow :: () -> string { count := LumiStoreCount() if count == 0 { return "" } return LumiStoreRow(count - 1).text } #program_export Check :: () -> s32 { transport := ConnectionTestTransport() check_true("fixture transport available", transport.start != null) guard := support_begin("/tmp/inbe-lumi-connection-test/") if guard != 0 { return guard } english_catalog = "[lumi_offline_unknown]\nOFFLINE\n---\n[lumi_online_setup]\nSETUP\n---\n[lumi_online_unavailable]\nUNAVAILABLE\n---\n[lumi_provider_rejected]\nREJECTED\n---\n" install_english_catalog() root := data_root() check_true("fixture database initialized", storage_init(root) != 0) check_true("owner created", CreateAccountKeys(*owner) != 0) check_true("owner saved", sync_account_save(*owner, cast(SyncAccountLocalDataChoice)SyncAccountLocalDataChoice.SYNC_ACCOUNT_LOCAL_DATA_MERGE) == cast(SyncAccountSaveResult)SyncAccountSaveResult.SYNC_ACCOUNT_SAVE_OK) // Before agreeing, Lumi is offline whatever its switch says: a request // it does not understand gets the offline answer, and a confirmed // feedback report waits. Nothing at all is sent. check_true("switch starts on", LumiOnlineWanted()) check_true("not agreed", !LumiNodeAgreed() && !LumiToggleOn()) check_true("an unknown request is answered offline", Ask("what should I do today?")) check_true("offline answer", LastRow() == "OFFLINE") draft := FeedbackDraft("Lumi freezes", "Please fix Lumi freezing", "view=lumi") defer { PackageFree(draft) } check_true("feedback confirmed", FeedbackChoice(draft, 1)) Pump(*app) // Diary spelling and habit icons follow the same agreement, quietly. check_true("spelling waits quietly", DiarySpellingStart("Helo") == "" && !DiarySpellingWaiting()) check_true("a habit without an icon", habits_add_custom(*icon_habits, "Read", Color.{.r = 99, .g = 196, .b = 165, .a = 255}, 0, 0) >= 0) check_true("icons wait quietly", !HabitIconChoiceStart(*icon_habits)) check_int("the habit keeps its letter for now", icon_habits.items[0].icon, 0) check_int("no request before agreeing", requests, 0) // Agreeing sends the waiting feedback, polls replies and Telegram, and // lets a conversation reach the server. check_true("agreed", LumiAgree()) check_true("agreement syncs as a Lumi record", contains(storage_get_setting_text(LumiAgreementRecord), "\"agreed\":true")) Pump(*app) check_true("feedback delivered after agreeing", feedback_requests > 0) check_true("Telegram relay polled after agreeing", telegram_requests > 0) check_true("a conversation starts", Ask("what should I do today?")) Pump(*app) check_int("one request to the server's AI", chat_requests, 1) check_true("the server's answer arrives", LastRow() == "Hello from the server") telegram_update_pending = true for step: cast(s32)0..29 { lumi_telegram_connection.retry = 0 LumiTelegramPump(*app) if LumiOnlineWaiting() { break } } check_true("Telegram receipt waits for the asynchronous answer", LumiOnlineWaiting() && telegram_answers == 0) check_true("Telegram input keeps the asynchronous turn's origin", lumi_telegram_online.id == 38) check_true("a regular app turn queues behind the Telegram turn", Ask("Regular app question")) Pump(*app) check_int("only the Telegram turn is acknowledged", telegram_answers, 1) check_true("the app turn completes locally", LastRow() == "Hello from the server") #if #defined(ANDROID_DEBUG) { input := "/dev Review the private coding fixture" check_true("private user request is saved locally", LumiStoreAppendRow(LumiChatRow.{.text = input, .user = true}, true)) key := LumiStoreLatestUserKey() check_true("developer record is outside the encrypted app outbox", LumiDeveloperRecord(key) && !BundledAppRecordValid(key)) check_true("debug composer starts the developer bridge", LumiOnlineStart(input)) Pump(*app) check_int("a developer submission and receipt poll complete", developer_requests, 2) check_true("the matched private response appears", LastRow() == "Completed private coding fixture") check_true("completed turn is no longer pending", storage_get_setting_text(LumiDeveloperPending) == "") LumiStoreReset() check_true("the private result survives reloading the archive", LastRow() == "Completed private coding fixture") } else { check_true("public builds have no developer command", LumiDeveloperCommand("/dev run the fixture") == "") } LumiStoreAppend("Remember the blue notebook", true) for index: cast(s32)0..5 { LumiStoreAppend("An earlier exchange", index % 2 == 0) } check_true("a follow-up starts", Ask("what did I ask you to remember?")) check_true("recent conversation is not cut to four messages", contains(lumi_online_messages, "Remember the blue notebook")) Pump(*app) continuation_test = true check_true("a six-step tool request starts", Ask("finish the six-step request")) Pump(*app) Pump(*app) check_int("all six permitted tool rounds finish", continuation_round, 6) check_int("each tool executes exactly once", tool_executions, 12) check_true("the final answer arrives after the tools", LastRow() == "The six steps are complete") check_true("the completed turn releases its state", !LumiOnlineWaiting()) continuation_test = false check_true("spelling starts after agreeing", DiarySpellingStart("Helo") == "" && DiarySpellingWaiting()) spelled := DiarySpellingPoll() for step: cast(s32)0..19 { if spelled.finished { break } spelled = DiarySpellingPoll() } check_true("spelling answered", spelled.finished && spelled.text == "Hello") check_int("one spelling request", spelling_requests, 1) check_true("icons asked after agreeing", HabitIconChoiceStart(*icon_habits)) for step: cast(s32)0..19 { if HabitIconChoicePoll(*icon_habits) { break } } check_int("one icon request", icon_requests, 1) check_true("the habit got its icon", icon_habits.items[0].icon == HabitIconNumber("book")) // Offline sends nothing, and switching off stops a turn in flight. check_true("a turn starts", Ask("and tomorrow?")) lumi_online_fresh = false app_lumi_pump(*app) check_true("the turn is in flight", LumiOnlineWaiting()) storage_set_setting_int(LumiOnlineSetting, 0) before := requests Pump(*app) check_true("switching off ends the turn", !LumiOnlineWaiting() && !lumi_online_operation.active) check_true("offline answer again", Ask("and next week?") && LastRow() == "OFFLINE") check_true("no spelling while offline", DiarySpellingStart("Helo") == "" && !DiarySpellingWaiting()) check_true("a second habit without an icon", habits_add_custom(*icon_habits, "Walk", Color.{.r = 99, .g = 196, .b = 165, .a = 255}, 0, 0) >= 0) check_true("no icons while offline", !HabitIconChoiceStart(*icon_habits)) Pump(*app) check_int("nothing is sent while offline", requests, before) // Switching off ends a spelling check and an icon question in flight; // the habit is asked about again once Lumi is online. storage_set_setting_int(LumiOnlineSetting, 1) check_true("spelling in flight", DiarySpellingStart("Helo") == "" && DiarySpellingWaiting()) check_true("icons in flight", HabitIconChoiceStart(*icon_habits)) storage_set_setting_int(LumiOnlineSetting, 0) check_true("switching off ends the check without an answer", !DiarySpellingPoll().finished && !DiarySpellingWaiting()) check_true("switching off ends the question", !HabitIconChoicePoll(*icon_habits) && !habit_icon_operation.active && icon_habits.items[1].icon == 0) storage_set_setting_int(LumiOnlineSetting, 1) check_true("asked again once online", HabitIconChoiceStart(*icon_habits)) CancelStoredOperation(*habit_icon_operation) storage_set_setting_int(LumiOnlineSetting, 0) before = requests // An own provider needs its own agreement, then gets the request // straight from this device with the key in its Authorization header. storage_set_setting_int(LumiOnlineSetting, 1) storage_set_setting_text(LumiProviderSetting, "own") storage_set_setting_text(LumiProviderUrlSetting, "http://127.0.0.1:9/v1") storage_set_setting_text(LumiProviderModelSetting, "test-model") storage_set_setting_text(LumiProviderKeySetting, TEST_KEY) check_true("a new provider is not agreed yet", !LumiToggleOn()) server_chats := chat_requests check_true("offline until agreed", Ask("hello") && LastRow() == "OFFLINE") Pump(*app) check_int("nothing reaches the provider", provider_requests, 0) check_int("nothing reaches the server's AI", chat_requests, server_chats) check_true("agreed to the provider", LumiAgree()) check_true("the provider answers", Ask("hello")) Pump(*app) check_int("one request to the provider", provider_requests, 1) check_int("no AI request to the server", chat_requests, server_chats) check_true("provider endpoint", TextUntilNul(provider_url[:]) == "http://127.0.0.1:9/v1/chat/completions") check_true("key only as the bearer token", TextUntilNul(provider_token[:]) == TEST_KEY) body := TextUntilNul(provider_body[:]) check_true("model named", contains(body, "\"model\":\"test-model\"")) check_true("system message with Lumi's instructions and context", contains(body, "\"role\":\"system\"") && contains(body, "Current app context")) check_true("app tools offered", contains(body, "\"tools\":[")) check_true("the user's message is sent", contains(body, "hello")) check_true("the key is never in the body", !contains(body, TEST_KEY)) check_true("the provider's answer arrives", LastRow() == "Hello from the provider") check_true("ordinary chat keeps provider budget and response bound", !contains(body, "max_tokens") && provider_response_capacity == 65536) check_true("requested list report starts", Ask("Based on my lists apps can you send a full report t developer for ever point mentioned clear and expanded")) Pump(*app) body = TextUntilNul(provider_body[:]) check_true("requested report has a complete output budget", contains(body, "\"max_tokens\":32768") && provider_response_capacity == 524288) QueuedTurns(*app) PacedTurns(*app) long_reply: Vec(u8) for index: cast(s32)0..1799 { BuilderPrint(*long_reply, "茶") } provider_reply = BuilderFinish(long_reply) before_long_reply := LumiStoreCount() check_true("a long provider reply starts", Ask("give me the complete reply")) Pump(*app) received: Vec(u8) for index: before_long_reply + 1..LumiStoreCount() - 1 { row := LumiStoreRow(index) check_true("long reply chunks are assistant messages", !row.user) BuilderPrint(*received, "%", row.text) } received_text := BuilderFinish(received) check_true("provider replies over four kilobytes arrive intact", received_text == provider_reply) PackageFree(received_text) PackageFree(provider_reply) provider_reply = "" check_true("the key is never synced", !BundledAppRecordValid(LumiProviderKeySetting) && !AppPreferenceValid(LumiProviderKeySetting)) // Another address needs agreeing again. storage_set_setting_text(LumiProviderUrlSetting, "https://example.com/v1") check_true("a changed address is not agreed", !LumiToggleOn()) check_true("plain http to another machine is refused", !LumiProviderUrlValid("http://example.com/v1")) check_true("credentials in the address are refused", !LumiProviderUrlValid("https://user:pass@example.com/v1")) // Withdrawing turns Lumi offline here and, through sync, elsewhere. storage_set_setting_text(LumiProviderSetting, "") check_true("withdrawn", LumiWithdraw()) check_true("withdrawal syncs as a Lumi record", contains(storage_get_setting_text(LumiAgreementRecord), "\"agreed\":false")) before = requests check_true("offline after withdrawing", Ask("hello") && LastRow() == "OFFLINE") storage_set_setting_int(LumiOnlineSetting, 1) Pump(*app) check_int("nothing is sent after withdrawing", requests, before) LumiOnlineCancel() SecureWipe(*owner.private_key_hex[0], ACCOUNT_PRIVATE_KEY_HEX_SIZE) storage_close() remove_tree(root) return failures }