@firstpick/pi-package-webui 0.6.7 → 0.6.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,10 +22,10 @@ function lanAddress() {
22
22
  return undefined;
23
23
  }
24
24
 
25
- async function request(host, pathname, { method = "GET", body, timeoutMs = 5_000 } = {}) {
25
+ async function request(host, pathname, { method = "GET", body, headers = {}, timeoutMs = 5_000 } = {}) {
26
26
  const response = await fetch(`http://${host}:${port}${pathname}`, {
27
27
  method,
28
- headers: body === undefined ? undefined : { "Content-Type": "application/json" },
28
+ headers: body === undefined ? headers : { "Content-Type": "application/json", ...headers },
29
29
  body: body === undefined ? undefined : JSON.stringify(body),
30
30
  signal: AbortSignal.timeout(timeoutMs),
31
31
  });
@@ -35,7 +35,43 @@ async function request(host, pathname, { method = "GET", body, timeoutMs = 5_000
35
35
  } catch {
36
36
  payload = undefined;
37
37
  }
38
- return { status: response.status, body: payload };
38
+ return { status: response.status, body: payload, headers: response.headers };
39
+ }
40
+
41
+ async function waitForSseEvent(tabId, predicate, trigger) {
42
+ const controller = new AbortController();
43
+ const timeout = setTimeout(() => controller.abort(new Error("timed out waiting for SSE event")), 8_000);
44
+ let triggerResult;
45
+ try {
46
+ const response = await fetch(`http://127.0.0.1:${port}/api/events?tab=${encodeURIComponent(tabId)}`, { signal: controller.signal });
47
+ assert.equal(response.status, 200, "SSE connection should open");
48
+ const triggerPromise = trigger ? Promise.resolve().then(trigger) : Promise.resolve(undefined);
49
+ const reader = response.body.getReader();
50
+ const decoder = new TextDecoder();
51
+ let buffer = "";
52
+ while (true) {
53
+ const { done, value } = await reader.read();
54
+ if (done) break;
55
+ buffer += decoder.decode(value, { stream: true });
56
+ let boundary;
57
+ while ((boundary = buffer.indexOf("\n\n")) >= 0) {
58
+ const block = buffer.slice(0, boundary);
59
+ buffer = buffer.slice(boundary + 2);
60
+ const data = block.split("\n").filter((line) => line.startsWith("data:")).map((line) => line.slice(5).trim()).join("\n");
61
+ if (!data) continue;
62
+ const event = JSON.parse(data);
63
+ if (predicate(event)) {
64
+ triggerResult = await triggerPromise;
65
+ controller.abort();
66
+ return { event, triggerResult };
67
+ }
68
+ }
69
+ }
70
+ throw new Error("SSE stream ended before the expected event");
71
+ } finally {
72
+ clearTimeout(timeout);
73
+ controller.abort();
74
+ }
39
75
  }
40
76
 
41
77
  async function rmWithRetry(target) {
@@ -77,6 +113,8 @@ const cwd = await mkdtemp(path.join(tmpdir(), "pi-webui-http-harness-"));
77
113
  const harnessSideEffectsRoot = await mkdtemp(path.join(tmpdir(), "pi-webui-http-harness-side-effects-"));
78
114
  const settingsFile = path.join(harnessSideEffectsRoot, "webui-settings.json");
79
115
  const openCommandLog = path.join(harnessSideEffectsRoot, "open-default.log");
116
+ const fakePiCommandLog = path.join(harnessSideEffectsRoot, "fake-pi-commands.jsonl");
117
+ const recoveryEndpointToken = "test-recovery-token-6e1cc61d22d44c8dbf3c";
80
118
  const openCommandScript = path.join(harnessSideEffectsRoot, "fake-open-default.mjs");
81
119
  const fakeOpenBinDir = path.join(harnessSideEffectsRoot, "bin");
82
120
  const artifactRoot = path.join(harnessSideEffectsRoot, "artifacts"), artifactDir = path.join(artifactRoot, "fixture-document-artifact"), artifactManifest = path.join(artifactDir, "manifest.json"), artifactDownload = path.join(artifactDir, "document.docx"), artifactPage = path.join(artifactDir, "page-1.png"), artifactExpiresAt = new Date(Date.now() + 60 * 60 * 1000).toISOString();
@@ -109,6 +147,17 @@ const voiceProvider = createServer(async (req, res) => {
109
147
  res.end(Buffer.from("fake mp3 bytes"));
110
148
  return;
111
149
  }
150
+ if (req.url?.startsWith("/pi-releases/")) {
151
+ const tagName = decodeURIComponent(req.url.slice("/pi-releases/".length));
152
+ res.writeHead(200, { "content-type": "application/json" });
153
+ res.end(JSON.stringify({
154
+ tag_name: tagName,
155
+ name: `Pi ${tagName} test release`,
156
+ body: "## Highlights\n\n- Release notes from the test GitHub endpoint.",
157
+ published_at: "2026-07-16T12:00:00Z",
158
+ }));
159
+ return;
160
+ }
112
161
  res.writeHead(404, { "content-type": "application/json" });
113
162
  res.end(JSON.stringify({ error: "not found" }));
114
163
  });
@@ -131,9 +180,12 @@ const child = spawn(process.execPath, [serverScript, "--cwd", cwd, "--host", "0.
131
180
  PI_WEBUI_ARTIFACT_ROOTS: artifactRoot,
132
181
  FAKE_PI_ARTIFACT_MANIFEST: artifactManifest,
133
182
  FAKE_PI_ARTIFACT_DOWNLOAD: artifactDownload,
183
+ FAKE_PI_LOG_FILE: fakePiCommandLog,
134
184
  FAKE_PI_VOICE_SCRIPTS: "1",
185
+ PI_WEBUI_RECOVERY_TOKEN: recoveryEndpointToken,
135
186
  PI_VOICE_STT_URL: `http://127.0.0.1:${voiceProviderPort}/stt`,
136
187
  PI_VOICE_TTS_URL: `http://127.0.0.1:${voiceProviderPort}/tts`,
188
+ PI_WEBUI_PI_RELEASES_API_BASE_URL: `http://127.0.0.1:${voiceProviderPort}/pi-releases`,
137
189
  },
138
190
  });
139
191
  let serverOutput = "";
@@ -160,6 +212,19 @@ try {
160
212
  assert.equal(health?.status, 200, `server should become healthy, output:\n${serverOutput}`);
161
213
  assert.equal(health.body.ok, true);
162
214
  assert.equal(health.body.piRunning, true, "fake pi RPC process should be attached and running");
215
+ assert.match(health.body.piVersion, /^\d+\.\d+\.\d+/, "health metadata should expose the installed Pi version");
216
+
217
+ const releaseNotes = await request("127.0.0.1", "/api/pi-release-notes");
218
+ assert.equal(releaseNotes.status, 200, `Pi release notes should load through the server: ${releaseNotes.body?.error || ""}`);
219
+ assert.equal(releaseNotes.body?.data?.version, health.body.piVersion);
220
+ assert.equal(releaseNotes.body?.data?.tagName, `v${health.body.piVersion}`);
221
+ assert.equal(releaseNotes.body?.data?.title, `Pi v${health.body.piVersion} test release`);
222
+ assert.match(releaseNotes.body?.data?.body || "", /Release notes from the test GitHub endpoint/);
223
+ assert.equal(releaseNotes.body?.data?.url, `https://github.com/earendil-works/pi/releases/tag/v${health.body.piVersion}`);
224
+ assert.equal(releaseNotes.headers.get("cache-control"), "private, no-store", "browser caches should not retain notes across Pi upgrades");
225
+ const cachedReleaseNotes = await request("127.0.0.1", "/api/pi-release-notes");
226
+ assert.equal(cachedReleaseNotes.body?.data?.tagName, `v${health.body.piVersion}`);
227
+ assert.equal(voiceProviderRequests.filter((item) => item.url === `/pi-releases/v${health.body.piVersion}`).length, 1, "the server should fetch each installed Pi release only once");
163
228
 
164
229
  // Static assets: brotli/gzip compression plus ETag revalidation (P0-2).
165
230
  const brotliResponse = await fetch(`http://127.0.0.1:${port}/app.js`, {
@@ -225,6 +290,82 @@ try {
225
290
  const tabId = tabList[0].id;
226
291
  assert.ok(tabId, "tab should have an id");
227
292
 
293
+ const sessionToolsBefore = await request("127.0.0.1", `/api/tools?tab=${encodeURIComponent(tabId)}&scope=session`);
294
+ assert.equal(sessionToolsBefore.status, 200);
295
+ assert.equal(sessionToolsBefore.body?.data?.scope, "session");
296
+ assert.deepEqual(sessionToolsBefore.body?.data?.tools?.map((tool) => [tool.name, tool.enabled]), [["read", true], ["bash", true]]);
297
+
298
+ const globalToolsBefore = await request("127.0.0.1", `/api/tools?tab=${encodeURIComponent(tabId)}&scope=global`);
299
+ assert.equal(globalToolsBefore.status, 200);
300
+ assert.equal(globalToolsBefore.body?.data?.configured, false, "global tools should initially inherit the current runtime defaults");
301
+
302
+ const saveGlobalTools = await request("127.0.0.1", "/api/tools", {
303
+ method: "POST",
304
+ body: { tab: tabId, scope: "global", enabledTools: ["read"] },
305
+ });
306
+ assert.equal(saveGlobalTools.status, 200);
307
+ assert.equal(saveGlobalTools.body?.data?.configured, true);
308
+ assert.deepEqual(saveGlobalTools.body?.data?.tools?.map((tool) => [tool.name, tool.enabled]), [["read", true], ["bash", false]]);
309
+
310
+ const settingsWithUnavailableResources = JSON.parse(await readFile(settingsFile, "utf8"));
311
+ settingsWithUnavailableResources.resourceDefaults.tools.enabledTools.push("future-tool");
312
+ settingsWithUnavailableResources.resourceDefaults.skills.enabledSkills = ["future-skill"];
313
+ await writeFile(settingsFile, `${JSON.stringify(settingsWithUnavailableResources, null, 2)}\n`, "utf8");
314
+
315
+ const sessionToolsAfterGlobal = await request("127.0.0.1", `/api/tools?tab=${encodeURIComponent(tabId)}&scope=session`);
316
+ assert.deepEqual(sessionToolsAfterGlobal.body?.data?.tools?.map((tool) => [tool.name, tool.enabled]), [["read", true], ["bash", true]], "saving a global tool default must not rewrite the current session");
317
+
318
+ const saveSessionTools = await request("127.0.0.1", "/api/tools", {
319
+ method: "POST",
320
+ body: { tab: tabId, scope: "session", enabledTools: ["bash"] },
321
+ });
322
+ assert.equal(saveSessionTools.status, 200);
323
+ assert.deepEqual(saveSessionTools.body?.data?.tools?.map((tool) => [tool.name, tool.enabled]), [["read", false], ["bash", true]]);
324
+ const globalToolsAfterSession = await request("127.0.0.1", `/api/tools?tab=${encodeURIComponent(tabId)}&scope=global`);
325
+ assert.deepEqual(globalToolsAfterSession.body?.data?.tools?.map((tool) => [tool.name, tool.enabled]), [["read", true], ["bash", false]], "session tool changes must not rewrite the global default");
326
+
327
+ const saveGlobalSkills = await request("127.0.0.1", "/api/skills", {
328
+ method: "POST",
329
+ body: { tab: tabId, scope: "global", enabledSkills: ["repo-explorer"] },
330
+ });
331
+ assert.equal(saveGlobalSkills.status, 200);
332
+ assert.deepEqual(saveGlobalSkills.body?.data?.skills?.map((skill) => [skill.name, skill.enabled]), [["repo-explorer", true], ["code-security", false]]);
333
+ const sessionSkillsAfterGlobal = await request("127.0.0.1", `/api/skills?tab=${encodeURIComponent(tabId)}&scope=session`);
334
+ assert.deepEqual(sessionSkillsAfterGlobal.body?.data?.skills?.map((skill) => [skill.name, skill.enabled]), [["repo-explorer", true], ["code-security", true]], "saving a global skill default must not rewrite the current session");
335
+
336
+ const persistedResourceDefaults = JSON.parse(await readFile(settingsFile, "utf8"));
337
+ assert.deepEqual(persistedResourceDefaults.resourceDefaults?.tools?.enabledTools, ["read", "future-tool"], "saving visible tool choices should preserve defaults for tools unavailable in the active tab");
338
+ assert.deepEqual(persistedResourceDefaults.resourceDefaults?.skills?.enabledSkills, ["repo-explorer", "future-skill"], "saving visible skill choices should preserve defaults for skills unavailable in the active tab");
339
+ const invalidResourceScope = await request("127.0.0.1", `/api/tools?tab=${encodeURIComponent(tabId)}&scope=project`);
340
+ assert.equal(invalidResourceScope.status, 400, "resource selectors should reject unsupported scope values");
341
+
342
+ const workflowRpc = await waitForSseEvent(
343
+ tabId,
344
+ (event) => event.type === "extension_ui_request" && event.method === "setWidget" && event.widgetKey === "workflow:rpc",
345
+ () => request("127.0.0.1", "/api/prompt", { method: "POST", body: { tab: tabId, message: "fixture workflow inspector running" } }),
346
+ );
347
+ assert.equal(workflowRpc.triggerResult.status, 200, "workflow RPC fixture prompt should be accepted");
348
+ assert.equal(workflowRpc.event.widgetLines?.[0]?.startsWith("WORKFLOW_RPC_PAYLOAD "), true, "real Pi RPC events should transport the versioned Workflow inspector payload");
349
+ const workflowPayload = JSON.parse(workflowRpc.event.widgetLines[0].slice("WORKFLOW_RPC_PAYLOAD ".length));
350
+ assert.equal(workflowPayload.version, 1);
351
+ assert.equal(workflowPayload.runs[0].status, "running");
352
+ assert.equal(workflowPayload.runs[0].phases[0].agents[0].prompt, "Inspect fixture");
353
+
354
+ const workflowReplay = await waitForSseEvent(
355
+ tabId,
356
+ (event) => event.type === "extension_ui_request" && event.method === "setWidget" && event.widgetKey === "workflow:rpc",
357
+ );
358
+ assert.equal(workflowReplay.event.replayed, true, "server reconnect should replay the latest Workflow inspector widget");
359
+ assert.equal(JSON.parse(workflowReplay.event.widgetLines[0].slice("WORKFLOW_RPC_PAYLOAD ".length)).runs[0].runId, "fixture-workflow-run");
360
+
361
+ const workflowCompleted = await waitForSseEvent(
362
+ tabId,
363
+ (event) => event.type === "extension_ui_request" && event.method === "setWidget" && event.widgetKey === "workflow:rpc" && event.widgetLines?.[0]?.includes('"status":"completed"'),
364
+ () => request("127.0.0.1", "/api/prompt", { method: "POST", body: { tab: tabId, message: "fixture workflow inspector completed" } }),
365
+ );
366
+ assert.equal(workflowCompleted.triggerResult.status, 200);
367
+ assert.equal(JSON.parse(workflowCompleted.event.widgetLines[0].slice("WORKFLOW_RPC_PAYLOAD ".length)).runs[0].controls.canRetry, true);
368
+
228
369
  const artifactFixture = await request("127.0.0.1", "/api/prompt", { method: "POST", body: { tab: tabId, message: "fixture document artifact" } });
229
370
  assert.equal(artifactFixture.status, 200, "document artifact fixture should be accepted");
230
371
  const artifactMessages = await request("127.0.0.1", `/api/messages?tab=${encodeURIComponent(tabId)}`);
@@ -541,6 +682,25 @@ try {
541
682
  assert.equal(gitRemote.body?.ok, true, "remote endpoint should add origin without pushing");
542
683
  assert.equal(gitRemote.body?.data?.remoteUrl, "https://github.com/Firstp1ck/pi-webui-http-harness.git");
543
684
 
685
+ if (process.platform === "win32") {
686
+ const ordinaryPath = path.join(cwd, "preflight-should-not-stage.txt");
687
+ const reservedPath = path.toNamespacedPath(path.join(cwd, "NUL"));
688
+ await writeFile(ordinaryPath, "ordinary untracked file\n");
689
+ await writeFile(reservedPath, "accidental device-name file\n");
690
+ try {
691
+ const reservedAdd = await request("127.0.0.1", "/api/git-workflow/add", { method: "POST", body: { tab: tabId } });
692
+ assert.equal(reservedAdd.status, 200);
693
+ assert.equal(reservedAdd.body?.ok, false, "git add endpoint should reject Windows-reserved paths before staging");
694
+ assert.equal(reservedAdd.body?.code, "INVALID_WORKTREE_PATH");
695
+ assert.match(String(reservedAdd.body?.error || ""), /Windows-reserved path "NUL"/);
696
+ assert.match(String(reservedAdd.body?.hint || ""), /Delete or rename "NUL"/);
697
+ assert.equal(runGitFixture(["diff", "--cached", "--name-only"], cwd, "reserved-path preflight should leave the index untouched"), "");
698
+ } finally {
699
+ await rm(reservedPath, { force: true });
700
+ await rm(ordinaryPath, { force: true });
701
+ }
702
+ }
703
+
544
704
  await writeFile(path.join(cwd, "single.txt"), "created\n");
545
705
  const gitAddCreated = await request("127.0.0.1", "/api/git-workflow/add", { method: "POST", body: { tab: tabId } });
546
706
  assert.equal(gitAddCreated.status, 200);
@@ -589,6 +749,7 @@ try {
589
749
  const dir = path.join(gitFixturesRoot, name);
590
750
  await mkdir(dir, { recursive: true });
591
751
  runGitFixture(["init", "-b", "main", dir], gitFixturesRoot, `${name} fixture should initialize`);
752
+ runGitFixture(["config", "core.autocrlf", "false"], dir, `${name} fixture should keep line endings deterministic`);
592
753
  runGitFixture(["config", "user.name", "Pi WebUI Test"], dir, `${name} fixture should set user name`);
593
754
  runGitFixture(["config", "user.email", "pi-webui-test@example.invalid"], dir, `${name} fixture should set user email`);
594
755
  await writeFile(path.join(dir, "file.txt"), "base\n");
@@ -682,6 +843,20 @@ try {
682
843
  assert.equal(operationSnapshot.body?.data?.conflicts?.[0]?.status, "UU");
683
844
  assert.equal(operationSnapshot.body?.data?.conflicts?.[0]?.preview?.hasMarkers, true, "conflict preview should detect conflict markers");
684
845
 
846
+ const conflictAgent = await request("127.0.0.1", "/api/git-operation/resolve-with-agent", { method: "POST", body: { tab: mergeTab }, timeoutMs: 20_000 });
847
+ assert.equal(conflictAgent.status, 200);
848
+ assert.equal(conflictAgent.body?.ok, true, `conflict handoff should open an agent tab: ${conflictAgent.body?.error || ""}`);
849
+ assert.notEqual(conflictAgent.body?.data?.tab?.id, mergeTab, "conflict handoff should create a separate tab");
850
+ assert.equal(conflictAgent.body?.data?.tab?.cwd, mergeRepo, "conflict agent should use the conflicted repository root");
851
+ assert.equal(conflictAgent.body?.data?.tab?.title, "Resolve merge conflicts");
852
+ assert.deepEqual(conflictAgent.body?.data?.operation?.conflicts, [{ path: "file.txt", status: "UU" }]);
853
+ const loggedCommands = (await readFile(fakePiCommandLog, "utf8")).trim().split(/\r?\n/).filter(Boolean).map((line) => JSON.parse(line));
854
+ const handoffPrompt = loggedCommands.findLast((entry) => entry.direction === "command" && entry.type === "prompt" && /Resolve the current Git merge conflicts/.test(entry.message || ""));
855
+ assert.ok(handoffPrompt, "conflict agent should receive a resolution prompt");
856
+ assert.match(handoffPrompt.message, /Conflicted files:\n- UU "file\.txt"/, "handoff prompt should identify each conflicted path and status");
857
+ assert.match(handoffPrompt.message, /Do not continue, skip, abort, commit, reset, or push the merge/, "handoff prompt should keep operation completion under user control");
858
+ assert.match(handoffPrompt.message, /git diff --name-only --diff-filter=U is empty/, "handoff prompt should require unmerged-path verification");
859
+
685
860
  const continueBlocked = await request("127.0.0.1", "/api/git-operation/continue", { method: "POST", body: { tab: mergeTab } });
686
861
  assert.equal(continueBlocked.status, 200);
687
862
  assert.equal(continueBlocked.body?.ok, false, "continue with unmerged paths must fail");
@@ -1547,6 +1722,68 @@ try {
1547
1722
  console.log("http-endpoints-harness: no LAN address detected; skipping remote-client checks");
1548
1723
  }
1549
1724
 
1725
+ const recoveryTabsBefore = await request("127.0.0.1", "/api/tabs");
1726
+ const sourceTabId = recoveryTabsBefore.body?.data?.tabs?.[0]?.id;
1727
+ assert.ok(sourceTabId, "recovery endpoint test needs an active source tab");
1728
+ const recoveryBody = {
1729
+ prompt: "Inspect the Anthropic compatibility patch and run status/plan only.",
1730
+ cwd,
1731
+ model: { provider: "fake", id: "fake-model" },
1732
+ mode: "plan-only",
1733
+ };
1734
+ const unauthenticatedRecovery = await request("127.0.0.1", "/api/recovery/plan", { method: "POST", body: recoveryBody });
1735
+ assert.equal(unauthenticatedRecovery.status, 401, "recovery endpoint must reject missing bearer credentials");
1736
+ const wrongCredentialRecovery = await request("127.0.0.1", "/api/recovery/plan", {
1737
+ method: "POST",
1738
+ headers: { authorization: "Bearer wrong-recovery-token" },
1739
+ body: recoveryBody,
1740
+ });
1741
+ assert.equal(wrongCredentialRecovery.status, 401, "recovery endpoint must reject an incorrect bearer credential");
1742
+ const invalidModeRecovery = await request("127.0.0.1", "/api/recovery/plan", {
1743
+ method: "POST",
1744
+ headers: { authorization: `Bearer ${recoveryEndpointToken}` },
1745
+ body: { ...recoveryBody, mode: "apply" },
1746
+ });
1747
+ assert.equal(invalidModeRecovery.status, 400, "recovery endpoint must accept plan-only mode exclusively");
1748
+ if (lan) {
1749
+ const remoteRecovery = await request(lan, "/api/recovery/plan", {
1750
+ method: "POST",
1751
+ headers: { authorization: `Bearer ${recoveryEndpointToken}` },
1752
+ body: recoveryBody,
1753
+ });
1754
+ assert.equal(remoteRecovery.status, 403, "even a credentialed LAN client must not open recovery plans");
1755
+ }
1756
+ const rejectedRecovery = await request("127.0.0.1", "/api/recovery/plan", {
1757
+ method: "POST",
1758
+ headers: { authorization: `Bearer ${recoveryEndpointToken}` },
1759
+ body: { ...recoveryBody, model: { provider: "fake", id: "missing-model" } },
1760
+ });
1761
+ assert.equal(rejectedRecovery.status, 409, "an unavailable recovery model should be rejected");
1762
+ const recoveryTabsAfterRejection = await request("127.0.0.1", "/api/tabs");
1763
+ assert.equal(recoveryTabsAfterRejection.body?.data?.tabs?.length, recoveryTabsBefore.body?.data?.tabs?.length, "failed recovery initialization must discard its temporary tab");
1764
+ const recoveryOpened = await waitForSseEvent(
1765
+ sourceTabId,
1766
+ (event) => event.type === "webui_recovery_opened",
1767
+ () => request("127.0.0.1", "/api/recovery/plan", {
1768
+ method: "POST",
1769
+ headers: { authorization: `Bearer ${recoveryEndpointToken}` },
1770
+ body: recoveryBody,
1771
+ }),
1772
+ );
1773
+ assert.equal(recoveryOpened.triggerResult.status, 201, `recovery endpoint should create a tab: ${recoveryOpened.triggerResult.body?.error || ""}`);
1774
+ assert.equal(recoveryOpened.triggerResult.body?.requestId, recoveryOpened.event.recoveryTabId);
1775
+ assert.equal(recoveryOpened.event.model?.provider, "fake");
1776
+ const recoveryTabs = await request("127.0.0.1", "/api/tabs");
1777
+ const recoveryTab = recoveryTabs.body?.data?.tabs?.find((tab) => tab.id === recoveryOpened.event.recoveryTabId);
1778
+ assert.equal(recoveryTab?.title, "Anthropic compatibility recovery");
1779
+ assert.equal(recoveryTab?.cwd, cwd);
1780
+ assert.equal(recoveryTab?.activity?.isWorking, true);
1781
+ const recoveryCommands = (await readFile(fakePiCommandLog, "utf8")).trim().split(/\r?\n/).filter(Boolean).map((line) => JSON.parse(line));
1782
+ assert.ok(recoveryCommands.some((entry) => entry.direction === "startup" && entry.recoveryUrl === `http://127.0.0.1:${port}/api/recovery/plan` && entry.recoveryTokenConfigured), "Pi RPC children should receive the internal recovery URL and a credential");
1783
+ const recoveryModelIndex = recoveryCommands.findIndex((entry) => entry.direction === "command" && entry.type === "set_model" && entry.provider === "fake" && entry.modelId === "fake-model");
1784
+ const recoveryPromptIndex = recoveryCommands.findIndex((entry) => entry.direction === "command" && entry.type === "prompt" && entry.message === recoveryBody.prompt);
1785
+ assert.ok(recoveryModelIndex >= 0 && recoveryPromptIndex > recoveryModelIndex, "recovery should select the requested model before sending the plan-only prompt");
1786
+
1550
1787
  const localClose = await request("127.0.0.1", "/api/network/close", { method: "POST" });
1551
1788
  assert.equal(localClose.status, 202, "network close from localhost should be accepted");
1552
1789