@firstpick/pi-package-webui 0.7.6 → 0.7.7
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.
- package/README.md +37 -4
- package/bin/pi-webui-rpc-supervisor.mjs +518 -0
- package/bin/pi-webui.mjs +1003 -82
- package/lib/WEBUI_TUI_NATIVE_PARITY.json +13 -0
- package/lib/rpc-supervisor-client.mjs +301 -0
- package/lib/rpc-supervisor-protocol.mjs +236 -0
- package/lib/rpc-supervisor-state.mjs +165 -0
- package/lib/trust-boundaries.mjs +1 -0
- package/package.json +2 -2
- package/public/app.js +1237 -82
- package/public/index.html +334 -25
- package/public/service-worker.js +6 -1
- package/public/styles.css +366 -52
- package/public/subagent-gate-visibility.mjs +36 -0
- package/public/workflow-status-stack.mjs +69 -0
- package/tests/app-runner-process-tree-harness.test.mjs +37 -3
- package/tests/boot-failure-diagnostics.test.mjs +180 -0
- package/tests/durable-rpc-supervisor-harness.test.mjs +252 -0
- package/tests/fast-mode-client-static.test.mjs +2 -2
- package/tests/fixtures/compacting-pi.mjs +0 -0
- package/tests/fixtures/fake-pi.mjs +81 -2
- package/tests/git-panel-file-preview-static.test.mjs +221 -0
- package/tests/http-endpoints-harness.test.mjs +458 -33
- package/tests/mobile-static.test.mjs +74 -12
- package/tests/native-parity-harness.test.mjs +2 -1
- package/tests/native-parity.test.mjs +11 -0
- package/tests/numpad-decimal-input-static.test.mjs +128 -0
- package/tests/prompt-routing-input-clear-static.test.mjs +34 -0
- package/tests/prompt-routing-tab-status.test.mjs +103 -0
- package/tests/rpc-supervisor-host.test.mjs +275 -0
- package/tests/rpc-supervisor-protocol.test.mjs +67 -0
- package/tests/rpc-supervisor-state.test.mjs +62 -0
- package/tests/run-all.mjs +4 -1
- package/tests/streaming-ui-coupling.test.mjs +15 -0
- package/tests/subagent-gate-visibility.test.mjs +66 -0
- package/tests/subagent-launch-slots-static.test.mjs +1 -1
- package/tests/subagents-helper.test.mjs +136 -0
- package/tests/workflow-status-stack.test.mjs +87 -0
- package/webui-rpc-helper.mjs +160 -2
|
@@ -93,6 +93,11 @@ async function pathExists(target) {
|
|
|
93
93
|
return !!(await stat(target).catch(() => null));
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
async function readJsonLines(target) {
|
|
97
|
+
const text = await readFile(target, "utf8").catch(() => "");
|
|
98
|
+
return text.split(/\r?\n/).filter(Boolean).map((line) => JSON.parse(line));
|
|
99
|
+
}
|
|
100
|
+
|
|
96
101
|
function runGitFixture(args, cwd, message) {
|
|
97
102
|
const result = spawnSync("git", args, {
|
|
98
103
|
cwd,
|
|
@@ -112,6 +117,13 @@ function runGitFixture(args, cwd, message) {
|
|
|
112
117
|
const cwd = await mkdtemp(path.join(tmpdir(), "pi-webui-http-harness-"));
|
|
113
118
|
const harnessSideEffectsRoot = await mkdtemp(path.join(tmpdir(), "pi-webui-http-harness-side-effects-"));
|
|
114
119
|
const settingsFile = path.join(harnessSideEffectsRoot, "webui-settings.json");
|
|
120
|
+
const workflowPolicyAgentDir = path.join(harnessSideEffectsRoot, "agent");
|
|
121
|
+
const workflowPolicyFile = path.join(workflowPolicyAgentDir, "workflow-policy.json");
|
|
122
|
+
const canonicalWorkflowPolicySuggestions = {
|
|
123
|
+
shellAllowlist: ["git", "node", "npm"],
|
|
124
|
+
networkAllowlist: ["api.github.com", "registry.npmjs.org"],
|
|
125
|
+
verificationCommands: [["npm", "test"], ["npm", "run", "lint"]],
|
|
126
|
+
};
|
|
115
127
|
const openCommandLog = path.join(harnessSideEffectsRoot, "open-default.log");
|
|
116
128
|
const fakePiCommandLog = path.join(harnessSideEffectsRoot, "fake-pi-commands.jsonl");
|
|
117
129
|
const recoveryEndpointToken = "test-recovery-token-6e1cc61d22d44c8dbf3c";
|
|
@@ -173,8 +185,9 @@ const child = spawn(process.execPath, [serverScript, "--cwd", cwd, "--host", "0.
|
|
|
173
185
|
GIT_COMMITTER_NAME: "Pi WebUI Test",
|
|
174
186
|
GIT_COMMITTER_EMAIL: "pi-webui-test@example.invalid",
|
|
175
187
|
PATH: `${fakeOpenBinDir}${path.delimiter}${process.env.PATH || ""}`,
|
|
176
|
-
PI_CODING_AGENT_DIR:
|
|
188
|
+
PI_CODING_AGENT_DIR: workflowPolicyAgentDir,
|
|
177
189
|
PI_WEBUI_SETTINGS_FILE: settingsFile,
|
|
190
|
+
PI_WEBUI_RPC_SUPERVISOR: "1",
|
|
178
191
|
...(process.platform === "linux" ? {} : { PI_WEBUI_OPEN_COMMAND: openCommandScript }),
|
|
179
192
|
PI_WEBUI_OPEN_LOG: openCommandLog,
|
|
180
193
|
PI_WEBUI_ARTIFACT_ROOTS: artifactRoot,
|
|
@@ -182,6 +195,7 @@ const child = spawn(process.execPath, [serverScript, "--cwd", cwd, "--host", "0.
|
|
|
182
195
|
FAKE_PI_ARTIFACT_DOWNLOAD: artifactDownload,
|
|
183
196
|
FAKE_PI_LOG_FILE: fakePiCommandLog,
|
|
184
197
|
FAKE_PI_VOICE_SCRIPTS: "1",
|
|
198
|
+
FAKE_PI_LARGE_PAYLOADS: "1",
|
|
185
199
|
PI_WEBUI_RECOVERY_TOKEN: recoveryEndpointToken,
|
|
186
200
|
PI_VOICE_STT_URL: `http://127.0.0.1:${voiceProviderPort}/stt`,
|
|
187
201
|
PI_VOICE_TTS_URL: `http://127.0.0.1:${voiceProviderPort}/tts`,
|
|
@@ -214,6 +228,91 @@ try {
|
|
|
214
228
|
assert.equal(health.body.piRunning, true, "fake pi RPC process should be attached and running");
|
|
215
229
|
assert.match(health.body.piVersion, /^\d+\.\d+\.\d+/, "health metadata should expose the installed Pi version");
|
|
216
230
|
|
|
231
|
+
// Workflow policy setup is server-scoped: missing policy reads as canonical
|
|
232
|
+
// deny-default state without creating PI_CODING_AGENT_DIR or its policy file.
|
|
233
|
+
const missingWorkflowPolicy = await request("127.0.0.1", "/api/workflow-policy");
|
|
234
|
+
assert.equal(missingWorkflowPolicy.status, 200, `missing workflow policy should load: ${missingWorkflowPolicy.body?.error || ""}`);
|
|
235
|
+
assert.equal(missingWorkflowPolicy.body?.data?.filePath, workflowPolicyFile, "workflow policy path must use server-derived PI_CODING_AGENT_DIR");
|
|
236
|
+
assert.equal(missingWorkflowPolicy.body?.data?.exists, false, "missing workflow policy should report absent state");
|
|
237
|
+
assert.equal(missingWorkflowPolicy.body?.data?.revision, null, "missing workflow policy should have no revision");
|
|
238
|
+
assert.deepEqual(missingWorkflowPolicy.body?.data?.policy, {
|
|
239
|
+
schemaVersion: 1,
|
|
240
|
+
permissions: { write: false, shell: false, network: false },
|
|
241
|
+
shellAllowlist: [],
|
|
242
|
+
networkAllowlist: [],
|
|
243
|
+
verificationCommands: [],
|
|
244
|
+
}, "missing workflow policy should expose canonical deny defaults");
|
|
245
|
+
assert.deepEqual(missingWorkflowPolicy.body?.data?.suggestions, canonicalWorkflowPolicySuggestions, "workflow policy GET should expose the canonical advisory catalog");
|
|
246
|
+
assert.equal(await pathExists(workflowPolicyFile), false, "workflow policy GET must not create a missing file");
|
|
247
|
+
|
|
248
|
+
const workflowPolicyToSave = {
|
|
249
|
+
schemaVersion: 1,
|
|
250
|
+
permissions: { write: true, shell: true, network: false },
|
|
251
|
+
shellAllowlist: [" npm ", "git", "npm"],
|
|
252
|
+
networkAllowlist: ["https://registry.npmjs.org", "https://npmjs.org"],
|
|
253
|
+
verificationCommands: [["npm", "test"], ["node", "--check", "bin/pi-webui.mjs"]],
|
|
254
|
+
};
|
|
255
|
+
const savedWorkflowPolicy = await request("127.0.0.1", "/api/workflow-policy", {
|
|
256
|
+
method: "POST",
|
|
257
|
+
body: { policy: workflowPolicyToSave, expectedRevision: missingWorkflowPolicy.body?.data?.revision },
|
|
258
|
+
});
|
|
259
|
+
assert.equal(savedWorkflowPolicy.status, 200, `workflow policy save should succeed: ${savedWorkflowPolicy.body?.error || ""}`);
|
|
260
|
+
assert.equal(savedWorkflowPolicy.body?.data?.filePath, workflowPolicyFile);
|
|
261
|
+
assert.equal(savedWorkflowPolicy.body?.data?.exists, true);
|
|
262
|
+
assert.match(savedWorkflowPolicy.body?.data?.revision || "", /^sha256:[a-f0-9]{64}$/, "saved workflow policy should expose a content revision");
|
|
263
|
+
assert.deepEqual(savedWorkflowPolicy.body?.data?.policy?.shellAllowlist, ["git", "npm"], "canonical writer should normalize workflow shell allowlists");
|
|
264
|
+
const persistedWorkflowPolicy = JSON.parse(await readFile(workflowPolicyFile, "utf8"));
|
|
265
|
+
assert.deepEqual(persistedWorkflowPolicy, savedWorkflowPolicy.body?.data?.policy, "workflow policy file should contain exactly the canonical saved policy");
|
|
266
|
+
assert.equal(Object.hasOwn(savedWorkflowPolicy.body?.data?.policy || {}, "suggestions"), false, "saved v1 response policy must not persist advisory suggestions");
|
|
267
|
+
assert.equal(Object.hasOwn(persistedWorkflowPolicy, "suggestions"), false, "saved v1 file must not persist advisory suggestions");
|
|
268
|
+
assert.equal((await stat(workflowPolicyFile)).mode & 0o777, 0o600, "workflow policy file must be private");
|
|
269
|
+
|
|
270
|
+
const readWorkflowPolicy = await request("127.0.0.1", "/api/workflow-policy");
|
|
271
|
+
assert.equal(readWorkflowPolicy.status, 200, `saved workflow policy should reload: ${readWorkflowPolicy.body?.error || ""}`);
|
|
272
|
+
assert.equal(readWorkflowPolicy.body?.data?.revision, savedWorkflowPolicy.body?.data?.revision, "workflow policy read should preserve the saved revision");
|
|
273
|
+
assert.deepEqual(readWorkflowPolicy.body?.data?.policy, savedWorkflowPolicy.body?.data?.policy, "workflow policy read should preserve canonical data");
|
|
274
|
+
assert.equal(Object.hasOwn(readWorkflowPolicy.body?.data?.policy || {}, "suggestions"), false, "read v1 policy must not expose persisted advisory suggestions");
|
|
275
|
+
|
|
276
|
+
const clientSelectedPolicyPath = path.join(harnessSideEffectsRoot, "client-selected-workflow-policy.json");
|
|
277
|
+
const clientPathWorkflowPolicy = await request("127.0.0.1", "/api/workflow-policy", {
|
|
278
|
+
method: "POST",
|
|
279
|
+
body: { policy: workflowPolicyToSave, expectedRevision: savedWorkflowPolicy.body?.data?.revision, agentDir: clientSelectedPolicyPath },
|
|
280
|
+
});
|
|
281
|
+
assert.equal(clientPathWorkflowPolicy.status, 400, "workflow policy save must reject a client-selected target path");
|
|
282
|
+
assert.equal(await pathExists(clientSelectedPolicyPath), false, "client-selected workflow policy path must never be written");
|
|
283
|
+
|
|
284
|
+
const unknownWorkflowPolicyField = await request("127.0.0.1", "/api/workflow-policy", {
|
|
285
|
+
method: "POST",
|
|
286
|
+
body: { policy: { ...workflowPolicyToSave, unsupported: true }, expectedRevision: savedWorkflowPolicy.body?.data?.revision },
|
|
287
|
+
});
|
|
288
|
+
assert.equal(unknownWorkflowPolicyField.status, 400, "workflow policy save must reject canonical unknown fields");
|
|
289
|
+
|
|
290
|
+
const malformedWorkflowPolicy = await request("127.0.0.1", "/api/workflow-policy", {
|
|
291
|
+
method: "POST",
|
|
292
|
+
body: { policy: { ...workflowPolicyToSave, permissions: { ...workflowPolicyToSave.permissions, shell: "yes" } }, expectedRevision: savedWorkflowPolicy.body?.data?.revision },
|
|
293
|
+
});
|
|
294
|
+
assert.equal(malformedWorkflowPolicy.status, 400, "workflow policy save must reject malformed canonical policy values");
|
|
295
|
+
|
|
296
|
+
const staleWorkflowPolicy = await request("127.0.0.1", "/api/workflow-policy", {
|
|
297
|
+
method: "POST",
|
|
298
|
+
body: { policy: workflowPolicyToSave, expectedRevision: missingWorkflowPolicy.body?.data?.revision },
|
|
299
|
+
});
|
|
300
|
+
assert.equal(staleWorkflowPolicy.status, 409, "workflow policy save must reject a stale read revision");
|
|
301
|
+
|
|
302
|
+
const nonJsonWorkflowPolicy = await request("127.0.0.1", "/api/workflow-policy", {
|
|
303
|
+
method: "POST",
|
|
304
|
+
headers: { "Content-Type": "text/plain" },
|
|
305
|
+
body: { policy: workflowPolicyToSave, expectedRevision: savedWorkflowPolicy.body?.data?.revision },
|
|
306
|
+
});
|
|
307
|
+
assert.equal(nonJsonWorkflowPolicy.status, 415, "workflow policy saves must reject cross-origin-simple non-JSON content types");
|
|
308
|
+
|
|
309
|
+
const crossOriginWorkflowPolicy = await request("127.0.0.1", "/api/workflow-policy", {
|
|
310
|
+
method: "POST",
|
|
311
|
+
headers: { "Sec-Fetch-Site": "cross-site" },
|
|
312
|
+
body: { policy: workflowPolicyToSave, expectedRevision: savedWorkflowPolicy.body?.data?.revision },
|
|
313
|
+
});
|
|
314
|
+
assert.equal(crossOriginWorkflowPolicy.status, 403, "workflow policy saves must reject browser cross-origin requests");
|
|
315
|
+
|
|
217
316
|
const releaseNotes = await request("127.0.0.1", "/api/pi-release-notes");
|
|
218
317
|
assert.equal(releaseNotes.status, 200, `Pi release notes should load through the server: ${releaseNotes.body?.error || ""}`);
|
|
219
318
|
assert.equal(releaseNotes.body?.data?.version, health.body.piVersion);
|
|
@@ -258,39 +357,17 @@ try {
|
|
|
258
357
|
assert.equal(gzipResponse.headers.get("content-encoding"), "gzip", "styles.css should fall back to gzip");
|
|
259
358
|
await gzipResponse.arrayBuffer();
|
|
260
359
|
|
|
261
|
-
//
|
|
262
|
-
//
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
assert.
|
|
267
|
-
|
|
268
|
-
assert.equal(await fastOutputModuleResponse.text(), await readFile(join(root, "public", "fast-output-live.mjs"), "utf8"), "served fast-output-live.mjs must match the source module");
|
|
269
|
-
|
|
270
|
-
// The browser voice loop is dynamically imported by app.js; a missing static
|
|
271
|
-
// allowlist entry would 404 the module and silently disable voice mode.
|
|
272
|
-
const voiceModuleResponse = await fetch(`http://127.0.0.1:${port}/voice-conversation.mjs`, {
|
|
273
|
-
signal: AbortSignal.timeout(5_000),
|
|
274
|
-
});
|
|
275
|
-
assert.equal(voiceModuleResponse.status, 200, "voice-conversation.mjs must be served for the Natural Conversation browser voice loop");
|
|
276
|
-
assert.match(voiceModuleResponse.headers.get("content-type") || "", /text\/javascript/, "voice-conversation.mjs should use a JavaScript MIME type");
|
|
277
|
-
const voiceModuleBody = await voiceModuleResponse.arrayBuffer();
|
|
278
|
-
const rawVoiceModuleSize = (await stat(join(root, "public", "voice-conversation.mjs"))).size;
|
|
279
|
-
assert.equal(voiceModuleBody.byteLength, rawVoiceModuleSize, "served voice-conversation.mjs should match the raw file byte-for-byte in size");
|
|
280
|
-
|
|
281
|
-
// app.js imports this pure Guided Git review gate at startup. Fetch it over
|
|
282
|
-
// the real server so an omitted static allowlist entry cannot 404 the UI.
|
|
283
|
-
const guidedGitReviewStateResponse = await fetch(`http://127.0.0.1:${port}/guided-git-review-state.mjs`, {
|
|
284
|
-
signal: AbortSignal.timeout(5_000),
|
|
285
|
-
});
|
|
286
|
-
assert.equal(guidedGitReviewStateResponse.status, 200, "guided-git-review-state.mjs must be served for the Guided Git review gate");
|
|
287
|
-
assert.match(guidedGitReviewStateResponse.headers.get("content-type") || "", /text\/javascript/, "guided-git-review-state.mjs should use a JavaScript MIME type");
|
|
288
|
-
assert.equal(await guidedGitReviewStateResponse.text(), await readFile(join(root, "public", "guided-git-review-state.mjs"), "utf8"), "served Guided Git review state must match the source module");
|
|
289
|
-
for (const moduleName of ["aur-review-payload.mjs", "guided-git-command-state.mjs"]) {
|
|
360
|
+
// Every literal same-origin module imported by app.js is startup-critical.
|
|
361
|
+
// Derive the set so adding a new import without a server allowlist entry fails
|
|
362
|
+
// this harness before it can ship as a blank browser UI.
|
|
363
|
+
const appSource = await readFile(join(root, "public", "app.js"), "utf8");
|
|
364
|
+
const startupModuleNames = [...new Set([...appSource.matchAll(/(?:\bfrom\s+|\bimport\s*(?:\(\s*)?)["']\.\/([^"'?]+)(?:\?[^"']*)?["']/g)].map((match) => match[1]))];
|
|
365
|
+
assert.ok(startupModuleNames.length >= 1, "the startup-module harness should discover app.js imports");
|
|
366
|
+
for (const moduleName of startupModuleNames) {
|
|
290
367
|
const response = await fetch(`http://127.0.0.1:${port}/${moduleName}`, { signal: AbortSignal.timeout(5_000) });
|
|
291
|
-
assert.equal(response.status, 200, `${moduleName} must be served
|
|
368
|
+
assert.equal(response.status, 200, `${moduleName} is imported by app.js and must be served by the WebUI`);
|
|
292
369
|
assert.match(response.headers.get("content-type") || "", /text\/javascript/, `${moduleName} should use a JavaScript MIME type`);
|
|
293
|
-
assert.equal(await response.text(), await readFile(join(root, "public", moduleName), "utf8"), `served ${moduleName} must match
|
|
370
|
+
assert.equal(await response.text(), await readFile(join(root, "public", moduleName), "utf8"), `served startup module ${moduleName} must match its source file`);
|
|
294
371
|
}
|
|
295
372
|
|
|
296
373
|
const mermaidModuleResponse = await fetch(`http://127.0.0.1:${port}/vendor/mermaid/mermaid.esm.min.mjs`, {
|
|
@@ -314,6 +391,31 @@ try {
|
|
|
314
391
|
const tabId = tabList[0].id;
|
|
315
392
|
assert.ok(tabId, "tab should have an id");
|
|
316
393
|
|
|
394
|
+
const extensionResponseId = `fixture-extension-response-${Date.now()}`;
|
|
395
|
+
const extensionResponseStartedAt = Date.now();
|
|
396
|
+
const extensionResponse = await request("127.0.0.1", "/api/extension-ui-response", {
|
|
397
|
+
method: "POST",
|
|
398
|
+
body: { tab: tabId, id: extensionResponseId, value: "fixture choice" },
|
|
399
|
+
timeoutMs: 2_000,
|
|
400
|
+
});
|
|
401
|
+
const extensionResponseElapsedMs = Date.now() - extensionResponseStartedAt;
|
|
402
|
+
assert.equal(extensionResponse.status, 200, `supervised extension UI response should return after the raw write: ${extensionResponse.body?.error || ""}`);
|
|
403
|
+
assert.ok(extensionResponseElapsedMs < 1_500, `supervised one-way extension UI response should return promptly (took ${extensionResponseElapsedMs}ms)`);
|
|
404
|
+
let extensionResponseCommands = [];
|
|
405
|
+
for (let attempt = 0; attempt < 20; attempt++) {
|
|
406
|
+
extensionResponseCommands = (await readJsonLines(fakePiCommandLog)).filter((entry) => entry.direction === "command" && entry.type === "extension_ui_response" && entry.id === extensionResponseId);
|
|
407
|
+
if (extensionResponseCommands.length) break;
|
|
408
|
+
await delay(25);
|
|
409
|
+
}
|
|
410
|
+
assert.deepEqual(extensionResponseCommands, [{
|
|
411
|
+
at: extensionResponseCommands[0]?.at,
|
|
412
|
+
direction: "command",
|
|
413
|
+
type: "extension_ui_response",
|
|
414
|
+
id: extensionResponseId,
|
|
415
|
+
value: "fixture choice",
|
|
416
|
+
cancelled: false,
|
|
417
|
+
}], "supervisor must preserve the extension request ID and write the raw response to fake Pi exactly once without a Pi reply");
|
|
418
|
+
|
|
317
419
|
const initialUserLaunchSlots = await request("127.0.0.1", `/api/subagents/config?tab=${encodeURIComponent(tabId)}&scope=user`);
|
|
318
420
|
assert.equal(initialUserLaunchSlots.status, 200, `user launch-slot config should load: ${initialUserLaunchSlots.body?.error || ""}`);
|
|
319
421
|
assert.equal(initialUserLaunchSlots.body?.data?.reloadRequired, false);
|
|
@@ -525,6 +627,7 @@ try {
|
|
|
525
627
|
assert.equal(subagentsResponse?.status, 200, "subagent overview endpoint should respond");
|
|
526
628
|
assert.equal(subagentsResponse.body?.data?.totalAgents, 2, "subagent overview should count all running agents");
|
|
527
629
|
assert.equal(subagentsResponse.body?.data?.tabs?.[0]?.tabId, tabId, "subagent overview should group agents under their terminal tab");
|
|
630
|
+
assert.equal(subagentsResponse.body?.data?.tabs?.[0]?.runs?.[0]?.source, "async", "ordinary async overview rows should retain their source");
|
|
528
631
|
assert.deepEqual(subagentsResponse.body?.data?.tabs?.[0]?.runs?.[0]?.agents?.map((agent) => agent.name), ["reviewer", "scout"], "subagent overview should preserve agent order within the session run");
|
|
529
632
|
assert.deepEqual(subagentsResponse.body?.data?.tabs?.[0]?.runs?.[0]?.agents?.map((agent) => [agent.model, agent.thinking]), [["anthropic/claude-opus-4-8:high", "high"], ["openai-codex/gpt-5.6-sol", "high"]], "subagent overview should preserve bounded model and reasoning metadata");
|
|
530
633
|
assert.equal(subagentsResponse.body?.data?.totalGates, 1, "subagent overview should expose retry gates independently from running children");
|
|
@@ -532,6 +635,7 @@ try {
|
|
|
532
635
|
assert.deepEqual(subagentsResponse.body?.data?.tabs?.[0]?.gates?.[0]?.attempts?.map((attempt) => [attempt.status, attempt.failureKind]), [["succeeded", undefined], ["failed", "transient-provider"]], "retry gate attempts should preserve bounded status and failure classification");
|
|
533
636
|
const subagentOutputResponse = await request("127.0.0.1", `/api/subagents/output?tab=${encodeURIComponent(tabId)}&run=${encodeURIComponent("fixture-run")}&agent=${encodeURIComponent("fixture-run:0")}`);
|
|
534
637
|
assert.equal(subagentOutputResponse.status, 200, "running subagent output endpoint should respond");
|
|
638
|
+
assert.equal(subagentOutputResponse.body?.data?.source, "async", "ordinary selected output should retain its async source");
|
|
535
639
|
assert.equal(subagentOutputResponse.body?.data?.agent?.name, "reviewer", "subagent output should target the selected child agent");
|
|
536
640
|
assert.deepEqual(subagentOutputResponse.body?.data?.agent?.recentOutput, ["Inspecting current implementation", "Waiting for the next tool result"], "subagent output should preserve bounded live output lines");
|
|
537
641
|
assert.equal(subagentOutputResponse.body?.data?.agent?.currentToolArgs, "README.md", "subagent output should include current tool state");
|
|
@@ -938,6 +1042,82 @@ try {
|
|
|
938
1042
|
return id;
|
|
939
1043
|
};
|
|
940
1044
|
|
|
1045
|
+
// File-scoped Git diff endpoint: staged, unstaged, untracked, empty, deleted, and rejected inputs.
|
|
1046
|
+
const fileDiffRepo = await makeFixtureRepo("file-diff");
|
|
1047
|
+
const fileDiffTab = await openFixtureTab(fileDiffRepo, "file-diff-fixture");
|
|
1048
|
+
await writeFile(path.join(fileDiffRepo, "unchanged.txt"), "unchanged\n");
|
|
1049
|
+
await writeFile(path.join(fileDiffRepo, "deleted.txt"), "deleted\n");
|
|
1050
|
+
runGitFixture(["add", "unchanged.txt", "deleted.txt"], fileDiffRepo, "file-diff fixture should stage unchanged and deleted bases");
|
|
1051
|
+
runGitFixture(["commit", "-m", "additional file-diff bases"], fileDiffRepo, "file-diff fixture should commit unchanged and deleted bases");
|
|
1052
|
+
await writeFile(path.join(fileDiffRepo, "file.txt"), "staged\n");
|
|
1053
|
+
runGitFixture(["add", "file.txt"], fileDiffRepo, "file-diff fixture should stage a file-scoped change");
|
|
1054
|
+
|
|
1055
|
+
const gitFileDiffPath = (file, category) => `/api/git-file-diff?tab=${encodeURIComponent(fileDiffTab)}&path=${encodeURIComponent(file)}&category=${encodeURIComponent(category)}`;
|
|
1056
|
+
const stagedFileDiff = await request("127.0.0.1", gitFileDiffPath("file.txt", "staged"));
|
|
1057
|
+
assert.equal(stagedFileDiff.status, 200);
|
|
1058
|
+
assert.equal(stagedFileDiff.body?.ok, true, "git-file-diff should read a staged file diff");
|
|
1059
|
+
assert.equal(stagedFileDiff.body?.data?.root, fileDiffRepo);
|
|
1060
|
+
assert.equal(stagedFileDiff.body?.data?.path, "file.txt");
|
|
1061
|
+
assert.equal(stagedFileDiff.body?.data?.category, "staged");
|
|
1062
|
+
assert.equal(stagedFileDiff.body?.data?.label, "Staged");
|
|
1063
|
+
assert.match(stagedFileDiff.body?.data?.command || "", /^git diff --cached --no-ext-diff --no-textconv --no-color --unified=3 --src-prefix=a\/ --dst-prefix=b\/ -- file\.txt$/);
|
|
1064
|
+
assert.match(stagedFileDiff.body?.data?.diff || "", /-base\n\+staged/, "staged diff should compare the index against HEAD for only the requested path");
|
|
1065
|
+
assert.equal(stagedFileDiff.body?.data?.truncated, false);
|
|
1066
|
+
assert.ok(Number(stagedFileDiff.body?.data?.capBytes) > 0, "staged file diff should expose its output cap");
|
|
1067
|
+
|
|
1068
|
+
await writeFile(path.join(fileDiffRepo, "file.txt"), "unstaged\n");
|
|
1069
|
+
const unstagedFileDiff = await request("127.0.0.1", gitFileDiffPath("file.txt", "unstaged"));
|
|
1070
|
+
assert.equal(unstagedFileDiff.status, 200);
|
|
1071
|
+
assert.equal(unstagedFileDiff.body?.ok, true, "git-file-diff should read an unstaged file diff");
|
|
1072
|
+
assert.equal(unstagedFileDiff.body?.data?.category, "unstaged");
|
|
1073
|
+
assert.equal(unstagedFileDiff.body?.data?.label, "Unstaged");
|
|
1074
|
+
assert.match(unstagedFileDiff.body?.data?.command || "", /^git diff --no-ext-diff --no-textconv --no-color --unified=3 --src-prefix=a\/ --dst-prefix=b\/ -- file\.txt$/);
|
|
1075
|
+
assert.match(unstagedFileDiff.body?.data?.diff || "", /-staged\n\+unstaged/, "unstaged diff should compare the worktree against the index for only the requested path");
|
|
1076
|
+
|
|
1077
|
+
await writeFile(path.join(fileDiffRepo, "loose.txt"), "loose\n");
|
|
1078
|
+
const untrackedFileDiff = await request("127.0.0.1", gitFileDiffPath("loose.txt", "untracked"));
|
|
1079
|
+
assert.equal(untrackedFileDiff.status, 200);
|
|
1080
|
+
assert.equal(untrackedFileDiff.body?.ok, true, "git-file-diff should return verified untracked content");
|
|
1081
|
+
assert.equal(untrackedFileDiff.body?.data?.category, "untracked");
|
|
1082
|
+
assert.equal(untrackedFileDiff.body?.data?.label, "Untracked");
|
|
1083
|
+
assert.equal(untrackedFileDiff.body?.data?.command, "git ls-files --others --exclude-standard -- loose.txt");
|
|
1084
|
+
assert.equal(untrackedFileDiff.body?.data?.diff, "");
|
|
1085
|
+
assert.equal(untrackedFileDiff.body?.data?.path, "loose.txt");
|
|
1086
|
+
assert.equal(untrackedFileDiff.body?.data?.binary, false);
|
|
1087
|
+
assert.equal(untrackedFileDiff.body?.data?.size, 6);
|
|
1088
|
+
assert.equal(untrackedFileDiff.body?.data?.content, "loose\n");
|
|
1089
|
+
assert.equal(untrackedFileDiff.body?.data?.truncated, false);
|
|
1090
|
+
assert.ok(Number(untrackedFileDiff.body?.data?.capBytes) > 0, "untracked file response should expose its output cap");
|
|
1091
|
+
|
|
1092
|
+
const fileDiffCap = Number(untrackedFileDiff.body?.data?.capBytes) || 500_000;
|
|
1093
|
+
await writeFile(path.join(fileDiffRepo, "large-loose.txt"), "x".repeat(fileDiffCap + 1));
|
|
1094
|
+
const largeUntrackedFileDiff = await request("127.0.0.1", gitFileDiffPath("large-loose.txt", "untracked"));
|
|
1095
|
+
assert.equal(largeUntrackedFileDiff.status, 200);
|
|
1096
|
+
assert.equal(largeUntrackedFileDiff.body?.ok, true, "oversized untracked previews should remain a structured response");
|
|
1097
|
+
assert.equal(largeUntrackedFileDiff.body?.data?.size, fileDiffCap + 1);
|
|
1098
|
+
assert.equal(largeUntrackedFileDiff.body?.data?.content, "", "oversized untracked previews must not read file content into the response");
|
|
1099
|
+
assert.match(largeUntrackedFileDiff.body?.data?.error || "", /too large to preview/i, "oversized untracked previews should explain the output bound");
|
|
1100
|
+
|
|
1101
|
+
const emptyFileDiff = await request("127.0.0.1", gitFileDiffPath("unchanged.txt", "unstaged"));
|
|
1102
|
+
assert.equal(emptyFileDiff.status, 200);
|
|
1103
|
+
assert.equal(emptyFileDiff.body?.ok, true, "git-file-diff should return an empty diff for an unchanged file");
|
|
1104
|
+
assert.equal(emptyFileDiff.body?.data?.diff, "");
|
|
1105
|
+
|
|
1106
|
+
await rm(path.join(fileDiffRepo, "deleted.txt"));
|
|
1107
|
+
const deletedFileDiff = await request("127.0.0.1", gitFileDiffPath("deleted.txt", "unstaged"));
|
|
1108
|
+
assert.equal(deletedFileDiff.status, 200);
|
|
1109
|
+
assert.equal(deletedFileDiff.body?.ok, true, "git-file-diff should return a diff for a deleted tracked file");
|
|
1110
|
+
assert.match(deletedFileDiff.body?.data?.diff || "", /deleted file mode/, "deleted tracked files should retain a readable diff");
|
|
1111
|
+
|
|
1112
|
+
const invalidGitFileDiffCategory = await request("127.0.0.1", gitFileDiffPath("file.txt", "modified"));
|
|
1113
|
+
assert.equal(invalidGitFileDiffCategory.status, 200);
|
|
1114
|
+
assert.equal(invalidGitFileDiffCategory.body?.ok, false, "git-file-diff must allowlist categories");
|
|
1115
|
+
assert.match(String(invalidGitFileDiffCategory.body?.error || ""), /category must be staged, unstaged, conflicted, or untracked/i);
|
|
1116
|
+
const escapedGitFileDiff = await request("127.0.0.1", gitFileDiffPath("../outside.txt", "unstaged"));
|
|
1117
|
+
assert.equal(escapedGitFileDiff.status, 200);
|
|
1118
|
+
assert.equal(escapedGitFileDiff.body?.ok, false, "git-file-diff must reject paths escaping the repository root");
|
|
1119
|
+
assert.match(String(escapedGitFileDiff.body?.error || ""), /Git path escapes repository/i);
|
|
1120
|
+
|
|
941
1121
|
// Staging endpoints
|
|
942
1122
|
const stagingRepo = await makeFixtureRepo("staging");
|
|
943
1123
|
const stagingTab = await openFixtureTab(stagingRepo, "staging-fixture");
|
|
@@ -1060,6 +1240,12 @@ try {
|
|
|
1060
1240
|
|
|
1061
1241
|
const mergeRepo = await makeConflictRepo("merge-conflict");
|
|
1062
1242
|
const mergeTab = await openFixtureTab(mergeRepo, "merge-conflict-fixture");
|
|
1243
|
+
const conflictedFileDiff = await request("127.0.0.1", `/api/git-file-diff?tab=${encodeURIComponent(mergeTab)}&path=file.txt&category=conflicted`);
|
|
1244
|
+
assert.equal(conflictedFileDiff.status, 200);
|
|
1245
|
+
assert.equal(conflictedFileDiff.body?.ok, true, "git-file-diff should return a combined diff for an unmerged path");
|
|
1246
|
+
assert.equal(conflictedFileDiff.body?.data?.category, "conflicted");
|
|
1247
|
+
assert.match(conflictedFileDiff.body?.data?.command || "", /^git diff --cc --no-ext-diff --no-textconv --no-color --unified=3 /, "conflicted file diff should use the bounded combined-diff command");
|
|
1248
|
+
assert.match(conflictedFileDiff.body?.data?.diff || "", /diff --cc file\.txt[\s\S]*@@@ /, "conflicted file diff should include combined hunk syntax for the raw viewer fallback");
|
|
1063
1249
|
const operationSnapshot = await request("127.0.0.1", `/api/git-operation?tab=${encodeURIComponent(mergeTab)}`);
|
|
1064
1250
|
assert.equal(operationSnapshot.status, 200);
|
|
1065
1251
|
assert.equal(operationSnapshot.body?.ok, true, "operation endpoint should read a merging repo");
|
|
@@ -1355,6 +1541,53 @@ try {
|
|
|
1355
1541
|
assert.equal(clampedMessages.body?.data?.since, 3, "since beyond the transcript should clamp to the total count");
|
|
1356
1542
|
assert.equal((clampedMessages.body?.data?.messages || []).length, 0);
|
|
1357
1543
|
|
|
1544
|
+
const expectedLargeRpcText = "large-rpc-payload:" + "λ".repeat(70_000);
|
|
1545
|
+
assert.ok(Buffer.byteLength(expectedLargeRpcText) > 64 * 1024 && Buffer.byteLength(expectedLargeRpcText) < 32 * 1024 * 1024, "large RPC fixture must exceed the former sanitizer limit while staying within the transport bound");
|
|
1546
|
+
const largePayloadResponse = await request("127.0.0.1", "/api/prompt", {
|
|
1547
|
+
method: "POST",
|
|
1548
|
+
body: { tab: tabId, message: "fixture large rpc payload" },
|
|
1549
|
+
timeoutMs: 10_000,
|
|
1550
|
+
});
|
|
1551
|
+
assert.equal(largePayloadResponse.status, 200, "supervised live command must round-trip a large bounded response");
|
|
1552
|
+
assert.equal(largePayloadResponse.body?.data?.output, expectedLargeRpcText, "large multibyte live output must remain byte-exact");
|
|
1553
|
+
assert.deepEqual(largePayloadResponse.body?.data?.tokens, { input: 123456, output: 654321 }, "live token fields must not be stripped");
|
|
1554
|
+
assert.equal(largePayloadResponse.body?.data?.samples?.length, 300, "live response arrays above metadata caps must not be truncated");
|
|
1555
|
+
const largeStats = await request("127.0.0.1", `/api/stats?tab=${encodeURIComponent(tabId)}`);
|
|
1556
|
+
assert.deepEqual(largeStats.body?.data?.tokens, { input: 123456, output: 654321, total: 777777 }, "supervised token statistics must round-trip intact");
|
|
1557
|
+
assert.equal(largeStats.body?.data?.samples?.length, 300, "supervised statistics samples must remain complete");
|
|
1558
|
+
const largeTranscript = await request("127.0.0.1", `/api/messages?tab=${encodeURIComponent(tabId)}`, { timeoutMs: 10_000 });
|
|
1559
|
+
assert.equal(largeTranscript.body?.data?.messages?.at(-1)?.content?.[0]?.text, expectedLargeRpcText, "authoritative transcript must preserve the large multibyte assistant output");
|
|
1560
|
+
|
|
1561
|
+
// Project-local shell and Python discovery paths use a version-2 config without replacing custom runners.
|
|
1562
|
+
const searchToolsDir = path.join(cwd, "runner-tools");
|
|
1563
|
+
const searchNestedDir = path.join(cwd, "runner-nested", "scripts");
|
|
1564
|
+
const searchBuiltInDir = path.join(cwd, "scripts");
|
|
1565
|
+
const staleSearchDir = path.join(cwd, "stale-runner-tools");
|
|
1566
|
+
await Promise.all([
|
|
1567
|
+
mkdir(path.join(searchToolsDir, "deep"), { recursive: true }),
|
|
1568
|
+
mkdir(searchNestedDir, { recursive: true }),
|
|
1569
|
+
mkdir(searchBuiltInDir, { recursive: true }),
|
|
1570
|
+
mkdir(staleSearchDir, { recursive: true }),
|
|
1571
|
+
]);
|
|
1572
|
+
await Promise.all([
|
|
1573
|
+
writeFile(path.join(searchToolsDir, "alpha.sh"), "#!/usr/bin/env bash\nprintf 'configured alpha cwd=%s\\n' \"$PWD\"\n"),
|
|
1574
|
+
writeFile(path.join(searchToolsDir, "beta.bash"), "#!/usr/bin/env bash\nprintf 'configured beta\\n'\n"),
|
|
1575
|
+
writeFile(path.join(searchToolsDir, "gamma.zsh"), "#!/usr/bin/env zsh\nprintf 'configured gamma\\n'\n"),
|
|
1576
|
+
writeFile(path.join(searchToolsDir, "delta.fish"), "#!/usr/bin/env fish\nprintf 'configured delta\\n'\n"),
|
|
1577
|
+
writeFile(path.join(searchToolsDir, "shebang-run"), "#!/bin/sh\nprintf 'configured shebang\\n'\n"),
|
|
1578
|
+
writeFile(path.join(searchToolsDir, "ignored.txt"), "#!/bin/sh\nprintf 'not detected by existing extensionless semantics\\n'\n"),
|
|
1579
|
+
writeFile(path.join(searchToolsDir, "python-tool.py"), "import os\nprint(f'configured python cwd={os.getcwd()}')\n"),
|
|
1580
|
+
writeFile(path.join(searchToolsDir, "python-shebang"), "#!/usr/bin/env python3\nprint('configured python shebang')\n"),
|
|
1581
|
+
writeFile(path.join(searchToolsDir, "ignored-python.txt"), "#!/usr/bin/env python3\nprint('unsupported Python filename')\n"),
|
|
1582
|
+
writeFile(path.join(searchToolsDir, "deep", "recursive.sh"), "#!/usr/bin/env bash\nprintf 'not recursive\\n'\n"),
|
|
1583
|
+
writeFile(path.join(searchToolsDir, "deep", "recursive.py"), "print('not recursive')\n"),
|
|
1584
|
+
writeFile(path.join(searchNestedDir, "nested.sh"), "#!/usr/bin/env bash\nprintf 'configured nested\\n'\n"),
|
|
1585
|
+
writeFile(path.join(searchBuiltInDir, "shared.sh"), "#!/usr/bin/env bash\nprintf 'built-in and configured once\\n'\n"),
|
|
1586
|
+
writeFile(path.join(cwd, "root-search.sh"), "#!/usr/bin/env bash\nprintf 'configured root\\n'\n"),
|
|
1587
|
+
writeFile(path.join(cwd, "root-search.py"), "print('configured root python')\n"),
|
|
1588
|
+
writeFile(path.join(staleSearchDir, "stale.sh"), "#!/usr/bin/env bash\nprintf 'stale\\n'\n"),
|
|
1589
|
+
]);
|
|
1590
|
+
|
|
1358
1591
|
// Custom app runners: save failures must be explicit, saved runners must be runnable,
|
|
1359
1592
|
// and stale saved runners must explain why they are not shown in the Run menu.
|
|
1360
1593
|
await writeFile(path.join(cwd, "custom-runner.mjs"), "console.log('custom runner ok')\n");
|
|
@@ -1376,6 +1609,177 @@ try {
|
|
|
1376
1609
|
const customRunner = savedCustomRunner.body?.data?.runners?.find((runner) => runner.custom === true && runner.label === "Custom node");
|
|
1377
1610
|
assert.ok(customRunner?.id, "saved available custom runner should appear in detected app runners");
|
|
1378
1611
|
|
|
1612
|
+
const savedSearchPaths = await request("127.0.0.1", "/api/app-runner-config", {
|
|
1613
|
+
method: "POST",
|
|
1614
|
+
body: { tab: tabId, searchPaths: ["./runner-tools", "runner-nested/scripts", "scripts", ".", "stale-runner-tools"] },
|
|
1615
|
+
timeoutMs: 10_000,
|
|
1616
|
+
});
|
|
1617
|
+
assert.equal(savedSearchPaths.status, 200, `saving project discovery paths should succeed: ${savedSearchPaths.body?.error || ""}`);
|
|
1618
|
+
const expectedSearchPaths = ["runner-tools", "runner-nested/scripts", "scripts", ".", "stale-runner-tools"];
|
|
1619
|
+
assert.deepEqual(savedSearchPaths.body?.data?.customRunnerConfig?.searchPaths, expectedSearchPaths, "search paths should be slash-normalized while preserving user order");
|
|
1620
|
+
assert.equal(savedSearchPaths.body?.data?.customRunnerConfig?.version, 2, "search-path saves should expose the version-2 config contract");
|
|
1621
|
+
assert.ok(savedSearchPaths.body?.data?.customRunnerConfig?.runners?.some((runner) => runner.label === "Custom node"), "search-path saves must preserve custom runners");
|
|
1622
|
+
const persistedSearchConfig = JSON.parse(await readFile(path.join(cwd, ".pi-webui-runners.json"), "utf8"));
|
|
1623
|
+
assert.equal(persistedSearchConfig.version, 2, "search-path saves should write version 2");
|
|
1624
|
+
assert.deepEqual(persistedSearchConfig.searchPaths, expectedSearchPaths, "version-2 config should persist normalized search paths");
|
|
1625
|
+
assert.ok(persistedSearchConfig.runners.some((runner) => runner.label === "Custom node"), "version-2 config should retain existing custom runners");
|
|
1626
|
+
|
|
1627
|
+
const commandAvailable = (command) => spawnSync(command, ["--version"], { encoding: "utf8" }).status === 0;
|
|
1628
|
+
const availableShells = new Set(["bash", "zsh", "fish"].filter(commandAvailable));
|
|
1629
|
+
const configuredShellExpectations = [
|
|
1630
|
+
["runner-tools/alpha.sh", "bash"],
|
|
1631
|
+
["runner-tools/beta.bash", "bash"],
|
|
1632
|
+
["runner-tools/gamma.zsh", "zsh"],
|
|
1633
|
+
["runner-tools/delta.fish", "fish"],
|
|
1634
|
+
["runner-tools/shebang-run", "bash"],
|
|
1635
|
+
["runner-nested/scripts/nested.sh", "bash"],
|
|
1636
|
+
["scripts/shared.sh", "bash"],
|
|
1637
|
+
["root-search.sh", "bash"],
|
|
1638
|
+
];
|
|
1639
|
+
const detectedSearchRunners = savedSearchPaths.body?.data?.runners || [];
|
|
1640
|
+
for (const [projectFile, shell] of configuredShellExpectations) {
|
|
1641
|
+
const candidate = detectedSearchRunners.find((runner) => runner.kind === "shell" && runner.projectFile === projectFile);
|
|
1642
|
+
if (availableShells.has(shell)) {
|
|
1643
|
+
assert.equal(candidate?.command, shell, `${projectFile} should be detected with its supported ${shell} interpreter`);
|
|
1644
|
+
if (projectFile.startsWith("runner-")) assert.equal(candidate?.cwd, cwd, `${projectFile} should run from the project root`);
|
|
1645
|
+
} else {
|
|
1646
|
+
assert.equal(candidate, undefined, `${projectFile} should not be offered when ${shell} is unavailable`);
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
assert.equal(detectedSearchRunners.filter((runner) => runner.kind === "shell" && runner.projectFile === "scripts/shared.sh").length, availableShells.has("bash") ? 1 : 0, "configured paths overlapping built-in directories must not duplicate candidates");
|
|
1650
|
+
assert.equal(detectedSearchRunners.some((runner) => runner.projectFile === "runner-tools/deep/recursive.sh"), false, "configured discovery must not recurse into child directories");
|
|
1651
|
+
assert.equal(detectedSearchRunners.some((runner) => runner.projectFile === "runner-tools/ignored.txt"), false, "configured discovery must retain existing extensionless shell semantics");
|
|
1652
|
+
|
|
1653
|
+
const uvAvailable = commandAvailable("uv");
|
|
1654
|
+
const pythonCommand = commandAvailable("python3") ? "python3" : commandAvailable("python") ? "python" : "";
|
|
1655
|
+
for (const projectFile of ["runner-tools/python-tool.py", "runner-tools/python-shebang", "root-search.py"]) {
|
|
1656
|
+
const candidates = detectedSearchRunners.filter((runner) => runner.kind === "python" && runner.projectFile === projectFile);
|
|
1657
|
+
assert.equal(candidates.some((runner) => runner.command === "uv" && runner.args?.[0] === "run" && runner.args?.[1] === projectFile), uvAvailable, `${projectFile} should expose uv run when uv is available`);
|
|
1658
|
+
assert.equal(candidates.some((runner) => runner.command === pythonCommand && runner.args?.[0] === projectFile), Boolean(pythonCommand), `${projectFile} should expose the available Python interpreter`);
|
|
1659
|
+
assert.equal(candidates.length, Number(uvAvailable) + Number(Boolean(pythonCommand)), `${projectFile} should expose every applicable Python runtime once`);
|
|
1660
|
+
for (const candidate of candidates) assert.equal(candidate.cwd, cwd, `${projectFile} should run from the project root`);
|
|
1661
|
+
}
|
|
1662
|
+
assert.equal(detectedSearchRunners.some((runner) => runner.projectFile === "runner-tools/deep/recursive.py"), false, "configured Python discovery must not recurse into child directories");
|
|
1663
|
+
assert.equal(detectedSearchRunners.some((runner) => runner.projectFile === "runner-tools/ignored-python.txt"), false, "Python shebang detection must remain limited to extensionless files");
|
|
1664
|
+
|
|
1665
|
+
if (pythonCommand) {
|
|
1666
|
+
const pythonRunner = detectedSearchRunners.find((runner) => runner.kind === "python" && runner.command === pythonCommand && runner.projectFile === "runner-tools/python-tool.py");
|
|
1667
|
+
let pythonRunState = await request("127.0.0.1", "/api/app-runner", {
|
|
1668
|
+
method: "POST",
|
|
1669
|
+
body: { tab: tabId, runnerId: pythonRunner?.id },
|
|
1670
|
+
timeoutMs: 10_000,
|
|
1671
|
+
});
|
|
1672
|
+
assert.equal(pythonRunState.status, 200, `configured Python runner should start: ${pythonRunState.body?.error || ""}`);
|
|
1673
|
+
for (let attempt = 0; attempt < 50; attempt++) {
|
|
1674
|
+
if (pythonRunState.body?.data?.activeRun?.status && pythonRunState.body.data.activeRun.status !== "running") break;
|
|
1675
|
+
await delay(100);
|
|
1676
|
+
pythonRunState = await request("127.0.0.1", `/api/app-runners?tab=${encodeURIComponent(tabId)}`, { timeoutMs: 5_000 });
|
|
1677
|
+
}
|
|
1678
|
+
assert.equal(pythonRunState.body?.data?.activeRun?.status, "done", "configured Python runner should complete");
|
|
1679
|
+
assert.match((pythonRunState.body?.data?.activeRun?.lines || []).join("\n"), new RegExp(`configured python cwd=${cwd.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`), "configured Python runners should execute at the project root");
|
|
1680
|
+
await request("127.0.0.1", "/api/app-runner/clear", { method: "POST", body: { tab: tabId } });
|
|
1681
|
+
}
|
|
1682
|
+
|
|
1683
|
+
const configBeforeRejectedSearchPathSave = await readFile(path.join(cwd, ".pi-webui-runners.json"), "utf8");
|
|
1684
|
+
for (const [searchPaths, expectation] of [
|
|
1685
|
+
["runner-tools", /searchPaths must be an array/i],
|
|
1686
|
+
[["runner-tools", "runner-tools"], /Duplicate search path/i],
|
|
1687
|
+
[["../outside"], /cannot contain . or \.\. segments/i],
|
|
1688
|
+
[[path.join(cwd, "runner-tools")], /must be relative/i],
|
|
1689
|
+
[["C:\\runner-tools"], /must be relative/i],
|
|
1690
|
+
[["runner-tools\0bad"], /null bytes/i],
|
|
1691
|
+
[["missing-runner-tools"], /does not exist/i],
|
|
1692
|
+
[["custom-runner.mjs"], /not a directory/i],
|
|
1693
|
+
[[...Array.from({ length: 25 }, (_, index) => `many-runner-paths-${index}`)], /limit reached/i],
|
|
1694
|
+
]) {
|
|
1695
|
+
const rejected = await request("127.0.0.1", "/api/app-runner-config", {
|
|
1696
|
+
method: "POST",
|
|
1697
|
+
body: { tab: tabId, searchPaths },
|
|
1698
|
+
});
|
|
1699
|
+
assert.equal(rejected.status, 400, `invalid search path mutation should fail atomically: ${JSON.stringify(searchPaths)}`);
|
|
1700
|
+
assert.match(String(rejected.body?.error || ""), expectation);
|
|
1701
|
+
assert.equal(await readFile(path.join(cwd, ".pi-webui-runners.json"), "utf8"), configBeforeRejectedSearchPathSave, "a rejected search-path mutation must not change the config file");
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
let symlinkSearchPathAvailable = false;
|
|
1705
|
+
const escapedSearchRoot = await mkdtemp(path.join(tmpdir(), "pi-webui-runner-search-escape-"));
|
|
1706
|
+
try {
|
|
1707
|
+
await writeFile(path.join(escapedSearchRoot, "escaped.sh"), "#!/usr/bin/env bash\nprintf 'escaped\\n'\n");
|
|
1708
|
+
await symlink(escapedSearchRoot, path.join(cwd, "escaped-runner-tools"));
|
|
1709
|
+
symlinkSearchPathAvailable = true;
|
|
1710
|
+
const escapedSearchPath = await request("127.0.0.1", "/api/app-runner-config", {
|
|
1711
|
+
method: "POST",
|
|
1712
|
+
body: { tab: tabId, searchPaths: ["escaped-runner-tools"] },
|
|
1713
|
+
});
|
|
1714
|
+
assert.equal(escapedSearchPath.status, 400, "a configured directory symlink escaping the project root must be rejected");
|
|
1715
|
+
assert.match(String(escapedSearchPath.body?.error || ""), /outside the project root/i);
|
|
1716
|
+
assert.equal(await readFile(path.join(cwd, ".pi-webui-runners.json"), "utf8"), configBeforeRejectedSearchPathSave, "an escaped symlink mutation must not change the config file");
|
|
1717
|
+
await symlink(path.join(escapedSearchRoot, "escaped.sh"), path.join(searchToolsDir, "escaped-file.sh"));
|
|
1718
|
+
const escapedDiscoveredFile = await request("127.0.0.1", `/api/app-runners?tab=${encodeURIComponent(tabId)}`, { timeoutMs: 10_000 });
|
|
1719
|
+
assert.equal(escapedDiscoveredFile.body?.data?.runners?.some((runner) => runner.projectFile === "runner-tools/escaped-file.sh"), false, "a discovered file symlink escaping the project root must not become a candidate");
|
|
1720
|
+
} catch (error) {
|
|
1721
|
+
if (!["EPERM", "EACCES", "EINVAL", "ENOTSUP"].includes(error?.code)) throw error;
|
|
1722
|
+
console.log(`http-endpoints-harness: symlink unavailable (${error.code}); skipping app-runner search-path escape check`);
|
|
1723
|
+
} finally {
|
|
1724
|
+
if (symlinkSearchPathAvailable) {
|
|
1725
|
+
await rm(path.join(cwd, "escaped-runner-tools"), { force: true });
|
|
1726
|
+
await rm(path.join(searchToolsDir, "escaped-file.sh"), { force: true });
|
|
1727
|
+
}
|
|
1728
|
+
await rmWithRetry(escapedSearchRoot);
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1731
|
+
if (availableShells.has("bash")) {
|
|
1732
|
+
const nestedSearchTab = await request("127.0.0.1", "/api/tabs", {
|
|
1733
|
+
method: "POST",
|
|
1734
|
+
body: { cwd: path.join(searchToolsDir, "deep"), title: "search-path-nested" },
|
|
1735
|
+
});
|
|
1736
|
+
assert.equal(nestedSearchTab.status, 201, `nested app-runner tab should open: ${nestedSearchTab.body?.error || ""}`);
|
|
1737
|
+
const nestedSearchTabId = nestedSearchTab.body?.data?.tab?.id;
|
|
1738
|
+
try {
|
|
1739
|
+
const nestedSearchRunners = await request("127.0.0.1", `/api/app-runners?tab=${encodeURIComponent(nestedSearchTabId)}`, { timeoutMs: 10_000 });
|
|
1740
|
+
const nestedAlpha = nestedSearchRunners.body?.data?.runners?.find((runner) => runner.kind === "shell" && runner.projectFile === "runner-tools/alpha.sh");
|
|
1741
|
+
assert.equal(nestedAlpha?.cwd, cwd, "configured candidates from a nested tab must retain the project-root cwd");
|
|
1742
|
+
const nestedSearchStart = await request("127.0.0.1", "/api/app-runner", {
|
|
1743
|
+
method: "POST",
|
|
1744
|
+
body: { tab: nestedSearchTabId, runnerId: nestedAlpha?.id },
|
|
1745
|
+
timeoutMs: 10_000,
|
|
1746
|
+
});
|
|
1747
|
+
assert.equal(nestedSearchStart.status, 200, `configured shell runner should start from a nested tab: ${nestedSearchStart.body?.error || ""}`);
|
|
1748
|
+
let nestedSearchState = nestedSearchStart;
|
|
1749
|
+
for (let attempt = 0; attempt < 50; attempt++) {
|
|
1750
|
+
if (nestedSearchState.body?.data?.activeRun?.status && nestedSearchState.body.data.activeRun.status !== "running") break;
|
|
1751
|
+
await delay(100);
|
|
1752
|
+
nestedSearchState = await request("127.0.0.1", `/api/app-runners?tab=${encodeURIComponent(nestedSearchTabId)}`, { timeoutMs: 5_000 });
|
|
1753
|
+
}
|
|
1754
|
+
assert.equal(nestedSearchState.body?.data?.activeRun?.status, "done", "configured shell runner should complete");
|
|
1755
|
+
assert.match((nestedSearchState.body?.data?.activeRun?.lines || []).join("\n"), new RegExp(`configured alpha cwd=${cwd.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`), "configured shell runners should execute at the project root");
|
|
1756
|
+
} finally {
|
|
1757
|
+
if (nestedSearchTabId) await request("127.0.0.1", "/api/tabs/close", { method: "POST", body: { ids: [nestedSearchTabId] }, timeoutMs: 10_000 });
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
|
|
1761
|
+
await rmWithRetry(staleSearchDir);
|
|
1762
|
+
const staleSearchPaths = await request("127.0.0.1", "/api/app-runner-config", { timeoutMs: 10_000 });
|
|
1763
|
+
assert.deepEqual(staleSearchPaths.body?.data?.searchPaths, expectedSearchPaths, "stale on-disk search paths should remain visible so users can remove them");
|
|
1764
|
+
assert.ok(staleSearchPaths.body?.data?.diagnostics?.some((diagnostic) => diagnostic.path === "stale-runner-tools" && /does not exist/i.test(diagnostic.message)), "stale configured paths should surface a diagnostic");
|
|
1765
|
+
assert.equal(staleSearchPaths.body?.data?.runners?.some((runner) => runner.projectFile === "stale-runner-tools/stale.sh"), false, "stale configured paths must not be scanned");
|
|
1766
|
+
|
|
1767
|
+
const temporaryCustomRunner = await request("127.0.0.1", "/api/app-runner-config", {
|
|
1768
|
+
method: "POST",
|
|
1769
|
+
body: { tab: tabId, runner: { label: "Temporary search-path custom", command: process.execPath, path: "custom-runner.mjs" } },
|
|
1770
|
+
timeoutMs: 10_000,
|
|
1771
|
+
});
|
|
1772
|
+
assert.equal(temporaryCustomRunner.status, 200, `custom runner saves should preserve search paths: ${temporaryCustomRunner.body?.error || ""}`);
|
|
1773
|
+
assert.deepEqual(temporaryCustomRunner.body?.data?.customRunnerConfig?.searchPaths, expectedSearchPaths, "custom-runner POST must preserve search paths");
|
|
1774
|
+
const temporaryCustomRunnerId = temporaryCustomRunner.body?.data?.customRunnerConfig?.runners?.find((runner) => runner.label === "Temporary search-path custom")?.id;
|
|
1775
|
+
const deletedTemporaryCustomRunner = await request("127.0.0.1", "/api/app-runner-config", {
|
|
1776
|
+
method: "DELETE",
|
|
1777
|
+
body: { tab: tabId, id: temporaryCustomRunnerId },
|
|
1778
|
+
timeoutMs: 10_000,
|
|
1779
|
+
});
|
|
1780
|
+
assert.equal(deletedTemporaryCustomRunner.status, 200, `custom runner deletion should preserve search paths: ${deletedTemporaryCustomRunner.body?.error || ""}`);
|
|
1781
|
+
assert.deepEqual(deletedTemporaryCustomRunner.body?.data?.customRunnerConfig?.searchPaths, expectedSearchPaths, "custom-runner DELETE must preserve search paths");
|
|
1782
|
+
|
|
1379
1783
|
const customRunStart = await request("127.0.0.1", "/api/app-runner", {
|
|
1380
1784
|
method: "POST",
|
|
1381
1785
|
body: { tab: tabId, runnerId: customRunner.id },
|
|
@@ -1568,7 +1972,8 @@ try {
|
|
|
1568
1972
|
}
|
|
1569
1973
|
|
|
1570
1974
|
await writeFile(path.join(cwd, ".pi-webui-runners.json"), `${JSON.stringify({
|
|
1571
|
-
version:
|
|
1975
|
+
version: 2,
|
|
1976
|
+
searchPaths: ["runner-tools", "missing-stored-runner-tools", "../malformed-runner-tools", "runner-tools"],
|
|
1572
1977
|
runners: [{ id: "broken-custom", label: "Broken custom", command: "definitely-missing-pi-webui-runner", path: "custom-runner.mjs" }],
|
|
1573
1978
|
}, null, 2)}\n`);
|
|
1574
1979
|
const staleCustomRunner = await request("127.0.0.1", `/api/app-runners?tab=${encodeURIComponent(tabId)}`, { timeoutMs: 10_000 });
|
|
@@ -1577,6 +1982,10 @@ try {
|
|
|
1577
1982
|
assert.equal(brokenConfigRunner?.available, false, "unavailable saved custom runners should be flagged in config data");
|
|
1578
1983
|
assert.match(String(brokenConfigRunner?.unavailableReason || ""), /Command is not available: definitely-missing-pi-webui-runner/);
|
|
1579
1984
|
assert.equal(staleCustomRunner.body?.data?.runners?.some((runner) => runner.label === "Broken custom"), false, "unavailable custom runners should not appear in runnable menu data");
|
|
1985
|
+
assert.deepEqual(staleCustomRunner.body?.data?.customRunnerConfig?.searchPaths, ["runner-tools", "missing-stored-runner-tools"], "stored search paths should normalize and de-duplicate malformed config data");
|
|
1986
|
+
assert.ok(staleCustomRunner.body?.data?.customRunnerConfig?.diagnostics?.some((diagnostic) => diagnostic.path === "missing-stored-runner-tools" && /does not exist/i.test(diagnostic.message)), "missing stored search paths should report diagnostics");
|
|
1987
|
+
assert.ok(staleCustomRunner.body?.data?.customRunnerConfig?.diagnostics?.some((diagnostic) => /Invalid search path ignored/i.test(diagnostic.message)), "malformed stored search paths should report diagnostics");
|
|
1988
|
+
assert.ok(staleCustomRunner.body?.data?.customRunnerConfig?.diagnostics?.some((diagnostic) => diagnostic.path === "runner-tools" && /Duplicate search path/i.test(diagnostic.message)), "duplicate stored search paths should report diagnostics");
|
|
1580
1989
|
|
|
1581
1990
|
// Native slash command routed through the adapter (/copy → get_last_assistant_text).
|
|
1582
1991
|
const copy = await request("127.0.0.1", "/api/prompt", {
|
|
@@ -1817,6 +2226,13 @@ try {
|
|
|
1817
2226
|
assert.equal(blockedSettings.status, 409, "settings changes should be blocked while Natural Conversation is active");
|
|
1818
2227
|
assert.match(String(blockedSettings.body?.error || ""), /settings changes are blocked/);
|
|
1819
2228
|
|
|
2229
|
+
const blockedWorkflowPolicySave = await request("127.0.0.1", "/api/workflow-policy", {
|
|
2230
|
+
method: "POST",
|
|
2231
|
+
body: { policy: workflowPolicyToSave, expectedRevision: savedWorkflowPolicy.body?.data?.revision },
|
|
2232
|
+
});
|
|
2233
|
+
assert.equal(blockedWorkflowPolicySave.status, 409, "workflow policy changes should be blocked while Natural Conversation is active");
|
|
2234
|
+
assert.match(String(blockedWorkflowPolicySave.body?.error || ""), /workflow policy changes are blocked/);
|
|
2235
|
+
|
|
1820
2236
|
const blockedBash = await request("127.0.0.1", "/api/bash", { method: "POST", body: { command: "echo blocked", tab: tabId } });
|
|
1821
2237
|
assert.equal(blockedBash.status, 409, "user bash should be blocked while Natural Conversation is active");
|
|
1822
2238
|
assert.match(String(blockedBash.body?.error || ""), /bash is blocked|Natural Conversation Mode is active/);
|
|
@@ -1891,6 +2307,15 @@ try {
|
|
|
1891
2307
|
const remoteHealthBeforeAuth = await request(lan, "/api/health");
|
|
1892
2308
|
assert.equal(remoteHealthBeforeAuth.status, 200, "LAN clients should connect without a PIN while auth is off");
|
|
1893
2309
|
|
|
2310
|
+
const remoteWorkflowPolicyRead = await request(lan, "/api/workflow-policy");
|
|
2311
|
+
assert.equal(remoteWorkflowPolicyRead.status, 403, "workflow policy reads must be localhost-only");
|
|
2312
|
+
|
|
2313
|
+
const remoteWorkflowPolicySave = await request(lan, "/api/workflow-policy", {
|
|
2314
|
+
method: "POST",
|
|
2315
|
+
body: { policy: workflowPolicyToSave, expectedRevision: savedWorkflowPolicy.body?.data?.revision },
|
|
2316
|
+
});
|
|
2317
|
+
assert.equal(remoteWorkflowPolicySave.status, 403, "workflow policy saves must be localhost-only before the request body is processed");
|
|
2318
|
+
|
|
1894
2319
|
const remoteSttWithoutConsent = await request(lan, "/api/stt/transcribe", {
|
|
1895
2320
|
method: "POST",
|
|
1896
2321
|
body: { tab: tabId, provider: "local", mimeType: "audio/webm", audioBase64: Buffer.from("fake remote audio").toString("base64") },
|