@firstpick/pi-package-webui 0.7.7 → 0.7.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.
- package/README.md +23 -0
- package/bin/pi-webui-rpc-supervisor.mjs +115 -21
- package/bin/pi-webui.mjs +447 -88
- package/lib/queue-mutation.mjs +109 -0
- package/lib/rpc-supervisor-client.mjs +18 -2
- package/lib/rpc-supervisor-protocol.mjs +11 -2
- package/lib/scoped-models.mjs +19 -0
- package/lib/webui-workspaces.mjs +265 -0
- package/package.json +4 -4
- package/public/app.js +2227 -195
- package/public/index.html +143 -2
- package/public/issue-bot-client.mjs +344 -0
- package/public/issue-wizard-state.mjs +443 -0
- package/public/service-worker.js +3 -1
- package/public/styles.css +787 -56
- package/public/voice-conversation.mjs +1 -1
- package/tests/boot-failure-diagnostics.test.mjs +3 -3
- package/tests/compaction-mutation-contract.test.mjs +166 -0
- package/tests/compaction-resume-harness.test.mjs +113 -2
- package/tests/compaction-static.test.mjs +5 -0
- package/tests/completion-signal-contract.test.mjs +156 -0
- package/tests/cwd-footer-reliability-static.test.mjs +112 -0
- package/tests/durable-rpc-supervisor-harness.test.mjs +25 -2
- package/tests/fast-mode-client-static.test.mjs +1 -1
- package/tests/file-selection-overlay-static.test.mjs +21 -0
- package/tests/file-viewer-search-static.test.mjs +65 -0
- package/tests/fixtures/compacting-pi.mjs +0 -0
- package/tests/fixtures/fake-pi.mjs +186 -49
- package/tests/footer-context-contrast-static.test.mjs +10 -0
- package/tests/git-panel-file-preview-static.test.mjs +20 -5
- package/tests/git-panel-render-stability-static.test.mjs +11 -1
- package/tests/http-endpoints-harness.test.mjs +160 -1
- package/tests/issue-bot-client.test.mjs +135 -0
- package/tests/issue-wizard-state.test.mjs +126 -0
- package/tests/mobile-static.test.mjs +61 -42
- package/tests/native-parity.test.mjs +3 -3
- package/tests/open-issue-wizard-static.test.mjs +75 -0
- package/tests/prompt-routing-tab-status.test.mjs +5 -0
- package/tests/queue-edit-reorder-static.test.mjs +101 -0
- package/tests/queue-mutation-contract.test.mjs +143 -0
- package/tests/rpc-supervisor-host.test.mjs +135 -2
- package/tests/rpc-supervisor-protocol.test.mjs +26 -0
- package/tests/scoped-models.test.mjs +42 -0
- package/tests/streaming-ui-coupling.test.mjs +3 -2
- package/tests/subagents-helper.test.mjs +216 -3
- package/tests/terminal-tab-workspace-static.test.mjs +101 -0
- package/tests/webui-workspaces-harness.test.mjs +223 -0
- package/tests/webui-workspaces.test.mjs +106 -0
- package/tests/workspace-save-load-static.test.mjs +69 -0
- package/webui-rpc-helper.mjs +300 -41
|
@@ -391,6 +391,63 @@ try {
|
|
|
391
391
|
const tabId = tabList[0].id;
|
|
392
392
|
assert.ok(tabId, "tab should have an id");
|
|
393
393
|
|
|
394
|
+
const runtimeQueueBefore = { steering: ["runtime steering"], followUp: ["runtime first", "runtime second", "runtime third"] };
|
|
395
|
+
const runtimeQueueEdit = await waitForSseEvent(
|
|
396
|
+
tabId,
|
|
397
|
+
(event) => event.type === "queue_update" && event.source === "pi-runtime" && event.followUp?.[0] === "runtime edited",
|
|
398
|
+
() => request("127.0.0.1", "/api/queue/mutate", {
|
|
399
|
+
method: "POST",
|
|
400
|
+
body: {
|
|
401
|
+
tab: tabId,
|
|
402
|
+
source: "pi-runtime",
|
|
403
|
+
kind: "followUp",
|
|
404
|
+
expected: runtimeQueueBefore,
|
|
405
|
+
operation: { type: "edit", index: 0, expectedText: "runtime first", text: " runtime edited " },
|
|
406
|
+
},
|
|
407
|
+
}),
|
|
408
|
+
);
|
|
409
|
+
assert.equal(runtimeQueueEdit.triggerResult.status, 200, `runtime queue edit should succeed: ${runtimeQueueEdit.triggerResult.body?.error || ""}`);
|
|
410
|
+
assert.deepEqual(runtimeQueueEdit.triggerResult.body?.data, {
|
|
411
|
+
mutated: true,
|
|
412
|
+
source: "pi-runtime",
|
|
413
|
+
queue: { source: "pi-runtime", steering: ["runtime steering"], followUp: ["runtime edited", "runtime second", "runtime third"] },
|
|
414
|
+
}, "queue mutation should return the authoritative normalized runtime snapshot");
|
|
415
|
+
assert.equal(runtimeQueueEdit.event.source, "pi-runtime", "runtime queue events must retain their source");
|
|
416
|
+
|
|
417
|
+
const staleRuntimeQueueEdit = await request("127.0.0.1", "/api/queue/mutate", {
|
|
418
|
+
method: "POST",
|
|
419
|
+
body: {
|
|
420
|
+
tab: tabId,
|
|
421
|
+
source: "pi-runtime",
|
|
422
|
+
kind: "followUp",
|
|
423
|
+
expected: runtimeQueueBefore,
|
|
424
|
+
operation: { type: "move", from: 0, to: 2, expectedText: "runtime first" },
|
|
425
|
+
},
|
|
426
|
+
});
|
|
427
|
+
assert.equal(staleRuntimeQueueEdit.status, 409, "stale runtime queue snapshots must conflict");
|
|
428
|
+
assert.equal(staleRuntimeQueueEdit.body?.ok, false);
|
|
429
|
+
assert.equal(staleRuntimeQueueEdit.body?.data?.reason, "queue-changed");
|
|
430
|
+
assert.deepEqual(staleRuntimeQueueEdit.body?.data?.queue?.followUp, ["runtime edited", "runtime second", "runtime third"], "conflicts return the authoritative runtime queue");
|
|
431
|
+
|
|
432
|
+
const runtimeQueueMove = await request("127.0.0.1", "/api/queue/mutate", {
|
|
433
|
+
method: "POST",
|
|
434
|
+
body: {
|
|
435
|
+
tab: tabId,
|
|
436
|
+
source: "pi-runtime",
|
|
437
|
+
kind: "followUp",
|
|
438
|
+
expected: { steering: ["runtime steering"], followUp: ["runtime edited", "runtime second", "runtime third"] },
|
|
439
|
+
operation: { type: "move", from: 0, to: 2, expectedText: "runtime edited" },
|
|
440
|
+
},
|
|
441
|
+
});
|
|
442
|
+
assert.equal(runtimeQueueMove.status, 200, "runtime queue moves should use final zero-based indices");
|
|
443
|
+
assert.deepEqual(runtimeQueueMove.body?.data?.queue?.followUp, ["runtime second", "runtime third", "runtime edited"]);
|
|
444
|
+
|
|
445
|
+
const invalidRuntimeQueueMutation = await request("127.0.0.1", "/api/queue/mutate", {
|
|
446
|
+
method: "POST",
|
|
447
|
+
body: { tab: tabId, source: "pi-runtime", kind: "steering", expected: { steering: [], followUp: [] }, operation: { type: "edit", index: 0, expectedText: "x", text: "y" } },
|
|
448
|
+
});
|
|
449
|
+
assert.equal(invalidRuntimeQueueMutation.status, 400, "queue mutation must stay follow-up-only and reject malformed source contracts");
|
|
450
|
+
|
|
394
451
|
const extensionResponseId = `fixture-extension-response-${Date.now()}`;
|
|
395
452
|
const extensionResponseStartedAt = Date.now();
|
|
396
453
|
const extensionResponse = await request("127.0.0.1", "/api/extension-ui-response", {
|
|
@@ -626,6 +683,10 @@ try {
|
|
|
626
683
|
}
|
|
627
684
|
assert.equal(subagentsResponse?.status, 200, "subagent overview endpoint should respond");
|
|
628
685
|
assert.equal(subagentsResponse.body?.data?.totalAgents, 2, "subagent overview should count all running agents");
|
|
686
|
+
assert.equal(subagentsResponse.body?.data?.runningRuns, 1, "subagent overview should expose running run counts separately from retained totals");
|
|
687
|
+
assert.equal(subagentsResponse.body?.data?.runningAgents, 2, "subagent overview should expose running agent counts separately from retained totals");
|
|
688
|
+
assert.equal(subagentsResponse.body?.data?.tabs?.[0]?.runningRuns, 1);
|
|
689
|
+
assert.equal(subagentsResponse.body?.data?.tabs?.[0]?.runningAgents, 2);
|
|
629
690
|
assert.equal(subagentsResponse.body?.data?.tabs?.[0]?.tabId, tabId, "subagent overview should group agents under their terminal tab");
|
|
630
691
|
assert.equal(subagentsResponse.body?.data?.tabs?.[0]?.runs?.[0]?.source, "async", "ordinary async overview rows should retain their source");
|
|
631
692
|
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");
|
|
@@ -662,6 +723,104 @@ try {
|
|
|
662
723
|
], "subagent output endpoint should preserve normalized structured transcript roles, order, IDs, and tool metadata");
|
|
663
724
|
const unknownSubagentOutput = await request("127.0.0.1", `/api/subagents/output?tab=${encodeURIComponent(tabId)}&run=missing&agent=missing`);
|
|
664
725
|
assert.equal(unknownSubagentOutput.status, 404, "subagent output endpoint should reject untracked selections");
|
|
726
|
+
|
|
727
|
+
const dismissRunningSubagent = await request("127.0.0.1", "/api/subagents/dismiss", {
|
|
728
|
+
method: "POST",
|
|
729
|
+
body: { tab: tabId, runId: "fixture-run" },
|
|
730
|
+
});
|
|
731
|
+
assert.equal(dismissRunningSubagent.status, 400, "dismiss endpoint should reject running runs through the helper");
|
|
732
|
+
const cancelUnknownSubagent = await request("127.0.0.1", "/api/subagents/cancel", {
|
|
733
|
+
method: "POST",
|
|
734
|
+
body: { tab: tabId, runId: "missing" },
|
|
735
|
+
});
|
|
736
|
+
assert.equal(cancelUnknownSubagent.status, 400, "cancel endpoint should return helper errors for unknown runs");
|
|
737
|
+
|
|
738
|
+
const cancelledSubagent = await request("127.0.0.1", "/api/subagents/cancel", {
|
|
739
|
+
method: "POST",
|
|
740
|
+
body: { tab: tabId, runId: "fixture-run", reason: "Taking too long", note: "Use the existing result instead." },
|
|
741
|
+
});
|
|
742
|
+
assert.equal(cancelledSubagent.status, 200, `cancel endpoint should relay helper cancellation: ${cancelledSubagent.body?.error || ""}`);
|
|
743
|
+
assert.deepEqual(cancelledSubagent.body?.data, {
|
|
744
|
+
runId: "fixture-run",
|
|
745
|
+
state: "cancelled",
|
|
746
|
+
delivery: "context",
|
|
747
|
+
rpcMethod: "stop",
|
|
748
|
+
}, "cancel endpoint should preserve the helper cancellation response contract");
|
|
749
|
+
for (let attempt = 0; attempt < 20; attempt++) {
|
|
750
|
+
subagentsResponse = await request("127.0.0.1", "/api/subagents");
|
|
751
|
+
if (subagentsResponse.body?.data?.tabs?.[0]?.runs?.[0]?.status === "cancelled") break;
|
|
752
|
+
await delay(50);
|
|
753
|
+
}
|
|
754
|
+
const cancelledRun = subagentsResponse.body?.data?.tabs?.[0]?.runs?.find((run) => run.id === "fixture-run");
|
|
755
|
+
assert.deepEqual(cancelledRun && {
|
|
756
|
+
status: cancelledRun.status,
|
|
757
|
+
endedAt: typeof cancelledRun.endedAt,
|
|
758
|
+
cancelledBy: cancelledRun.cancelledBy,
|
|
759
|
+
cancelReason: cancelledRun.cancelReason,
|
|
760
|
+
cancelNote: cancelledRun.cancelNote,
|
|
761
|
+
agentStatuses: cancelledRun.agents.map((agent) => agent.status),
|
|
762
|
+
}, {
|
|
763
|
+
status: "cancelled",
|
|
764
|
+
endedAt: "number",
|
|
765
|
+
cancelledBy: "user",
|
|
766
|
+
cancelReason: "Taking too long",
|
|
767
|
+
cancelNote: "Use the existing result instead.",
|
|
768
|
+
agentStatuses: ["cancelled", "cancelled"],
|
|
769
|
+
}, "subagent normalization should retain cancelled run and agent metadata");
|
|
770
|
+
assert.equal(subagentsResponse.body?.data?.totalRuns, 1, "retained runs should remain included in total counts");
|
|
771
|
+
assert.equal(subagentsResponse.body?.data?.runningRuns, 0, "retained cancelled runs should not count as running");
|
|
772
|
+
assert.equal(subagentsResponse.body?.data?.runningAgents, 0, "retained cancelled agents should not count as running");
|
|
773
|
+
const retainedCancelledOutput = await request("127.0.0.1", `/api/subagents/output?tab=${encodeURIComponent(tabId)}&run=fixture-run&agent=fixture-run%3A0`);
|
|
774
|
+
assert.equal(retainedCancelledOutput.status, 200, "subagent output should remain accessible for retained cancelled runs");
|
|
775
|
+
assert.equal(retainedCancelledOutput.body?.data?.agent?.status, "cancelled");
|
|
776
|
+
const duplicateCancel = await request("127.0.0.1", "/api/subagents/cancel", {
|
|
777
|
+
method: "POST",
|
|
778
|
+
body: { tab: tabId, runId: "fixture-run" },
|
|
779
|
+
});
|
|
780
|
+
assert.equal(duplicateCancel.status, 400, "cancel endpoint should reject an already-finished run");
|
|
781
|
+
|
|
782
|
+
const dismissedSubagent = await request("127.0.0.1", "/api/subagents/dismiss", {
|
|
783
|
+
method: "POST",
|
|
784
|
+
body: { tab: tabId, runId: "fixture-run" },
|
|
785
|
+
});
|
|
786
|
+
assert.equal(dismissedSubagent.status, 200, `dismiss endpoint should relay helper dismissal: ${dismissedSubagent.body?.error || ""}`);
|
|
787
|
+
assert.deepEqual(dismissedSubagent.body?.data, { runId: "fixture-run", dismissed: true });
|
|
788
|
+
subagentsResponse = await request("127.0.0.1", "/api/subagents");
|
|
789
|
+
assert.equal(subagentsResponse.body?.data?.totalRuns, 0, "dismissed runs should be removed from the overview");
|
|
790
|
+
|
|
791
|
+
const retainedFixture = await request("127.0.0.1", "/api/prompt", { method: "POST", body: { tab: tabId, message: "fixture subagents retained" } });
|
|
792
|
+
assert.equal(retainedFixture.status, 200, "retained subagent fixture should be accepted");
|
|
793
|
+
for (let attempt = 0; attempt < 20; attempt++) {
|
|
794
|
+
subagentsResponse = await request("127.0.0.1", "/api/subagents");
|
|
795
|
+
if (subagentsResponse.body?.data?.totalRuns === 2) break;
|
|
796
|
+
await delay(50);
|
|
797
|
+
}
|
|
798
|
+
assert.equal(subagentsResponse.body?.data?.totalRuns, 2, "finished runs should survive payload normalization");
|
|
799
|
+
assert.equal(subagentsResponse.body?.data?.totalAgents, 2, "finished agents should remain represented in retained totals");
|
|
800
|
+
assert.equal(subagentsResponse.body?.data?.runningRuns, 0);
|
|
801
|
+
assert.equal(subagentsResponse.body?.data?.runningAgents, 0);
|
|
802
|
+
const normalizedDoneRun = subagentsResponse.body?.data?.tabs?.[0]?.runs?.find((run) => run.id === "fixture-done");
|
|
803
|
+
const normalizedCancelledRun = subagentsResponse.body?.data?.tabs?.[0]?.runs?.find((run) => run.id === "fixture-cancelled");
|
|
804
|
+
assert.deepEqual(normalizedDoneRun && { status: normalizedDoneRun.status, endedAt: typeof normalizedDoneRun.endedAt, agentStatus: normalizedDoneRun.agents[0]?.status }, {
|
|
805
|
+
status: "done", endedAt: "number", agentStatus: "done",
|
|
806
|
+
}, "normalization should retain completed run state and final agent status");
|
|
807
|
+
assert.deepEqual(normalizedCancelledRun && {
|
|
808
|
+
status: normalizedCancelledRun.status,
|
|
809
|
+
cancelledBy: normalizedCancelledRun.cancelledBy,
|
|
810
|
+
cancelReason: normalizedCancelledRun.cancelReason,
|
|
811
|
+
cancelNote: normalizedCancelledRun.cancelNote,
|
|
812
|
+
agentStatus: normalizedCancelledRun.agents[0]?.status,
|
|
813
|
+
}, {
|
|
814
|
+
status: "cancelled",
|
|
815
|
+
cancelledBy: "user",
|
|
816
|
+
cancelReason: "Taking too long",
|
|
817
|
+
cancelNote: "Use the existing result instead.",
|
|
818
|
+
agentStatus: "cancelled",
|
|
819
|
+
}, "normalization should retain bounded user cancellation metadata");
|
|
820
|
+
const retainedDoneOutput = await request("127.0.0.1", `/api/subagents/output?tab=${encodeURIComponent(tabId)}&run=fixture-done&agent=fixture-done%3A0`);
|
|
821
|
+
assert.equal(retainedDoneOutput.status, 200, "subagent output should remain accessible for retained completed runs");
|
|
822
|
+
assert.equal(retainedDoneOutput.body?.data?.agent?.status, "done");
|
|
823
|
+
|
|
665
824
|
const subagentFixtureClear = await request("127.0.0.1", "/api/prompt", { method: "POST", body: { tab: tabId, message: "fixture subagents clear" } });
|
|
666
825
|
assert.equal(subagentFixtureClear.status, 200, "subagent fixture clear should be accepted");
|
|
667
826
|
for (let attempt = 0; attempt < 20; attempt++) {
|
|
@@ -669,7 +828,7 @@ try {
|
|
|
669
828
|
if (subagentsResponse.body?.data?.totalAgents === 0) break;
|
|
670
829
|
await delay(50);
|
|
671
830
|
}
|
|
672
|
-
assert.equal(subagentsResponse.body?.data?.totalAgents, 0, "
|
|
831
|
+
assert.equal(subagentsResponse.body?.data?.totalAgents, 0, "an empty helper snapshot should clear retained subagent rows");
|
|
673
832
|
assert.equal(subagentsResponse.body?.data?.totalGates, 0, "cleared retry gates should disappear from the overview");
|
|
674
833
|
|
|
675
834
|
const state = await request("127.0.0.1", `/api/state?tab=${encodeURIComponent(tabId)}`);
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { createIssueBotClient, readIssueBotRuntimeConfig } from "../public/issue-bot-client.mjs";
|
|
3
|
+
|
|
4
|
+
const submissionId = "AbCdEfGhIjKlMnOpQrStUv";
|
|
5
|
+
const statusToken = "a".repeat(43);
|
|
6
|
+
const uuid = "123e4567-e89b-42d3-a456-426614174000";
|
|
7
|
+
const issue = Object.freeze({
|
|
8
|
+
categoryId: "bug",
|
|
9
|
+
componentId: "webui",
|
|
10
|
+
templateId: "bug-defect-report",
|
|
11
|
+
summary: "Panel fails to open",
|
|
12
|
+
fields: Object.freeze({
|
|
13
|
+
severity: "high",
|
|
14
|
+
expectedBehavior: "The panel opens.",
|
|
15
|
+
actualBehavior: "Nothing appears.",
|
|
16
|
+
reproductionSteps: "1. Open the deck\n2. Select the panel",
|
|
17
|
+
}),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const config = Object.freeze({
|
|
21
|
+
enabled: true,
|
|
22
|
+
gatewayBaseUrl: "https://issue-intake.example.test/",
|
|
23
|
+
turnstileSiteKey: "1x00000000000000000000AA",
|
|
24
|
+
privateSecurityReportUrl: "https://github.com/Firstp1ck/pi-coding-agent-forge/security/advisories/new",
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
assert.deepEqual(readIssueBotRuntimeConfig(), {
|
|
28
|
+
enabled: false,
|
|
29
|
+
gatewayBaseUrl: "",
|
|
30
|
+
turnstileSiteKey: "",
|
|
31
|
+
privateSecurityReportUrl: "",
|
|
32
|
+
}, "missing public runtime configuration must leave the bot disabled");
|
|
33
|
+
assert.equal(readIssueBotRuntimeConfig({ ...config, gatewayBaseUrl: "http://localhost:8787" }).enabled, false, "non-HTTPS gateway configuration must fail closed");
|
|
34
|
+
assert.equal(readIssueBotRuntimeConfig({ ...config, turnstileSiteKey: "contains whitespace" }).enabled, false, "invalid public Turnstile configuration must fail closed");
|
|
35
|
+
|
|
36
|
+
let disabledFetches = 0;
|
|
37
|
+
const disabled = createIssueBotClient({ config: readIssueBotRuntimeConfig(), fetchImpl: async () => { disabledFetches += 1; } });
|
|
38
|
+
const disabledResult = await disabled.submit({ issue });
|
|
39
|
+
assert.equal(disabled.available, false);
|
|
40
|
+
assert.equal(disabledResult.result.status, "unavailable");
|
|
41
|
+
assert.equal(disabledFetches, 0, "disabled configuration must not contact an arbitrary endpoint");
|
|
42
|
+
|
|
43
|
+
const calls = [];
|
|
44
|
+
const statuses = [];
|
|
45
|
+
const client = createIssueBotClient({
|
|
46
|
+
config,
|
|
47
|
+
uuidFactory: () => uuid,
|
|
48
|
+
getTurnstileToken: async ({ siteKey, idempotencyKey }) => {
|
|
49
|
+
assert.equal(siteKey, config.turnstileSiteKey);
|
|
50
|
+
assert.equal(idempotencyKey, uuid, "Turnstile cData must bind the challenge to the admission UUID");
|
|
51
|
+
return "fresh-turnstile-token";
|
|
52
|
+
},
|
|
53
|
+
sleep: async () => {},
|
|
54
|
+
fetchImpl: async (url, options) => {
|
|
55
|
+
calls.push({ url, options });
|
|
56
|
+
if (options.method === "POST") {
|
|
57
|
+
return new Response(JSON.stringify({
|
|
58
|
+
ok: true,
|
|
59
|
+
status: "queued",
|
|
60
|
+
submissionId,
|
|
61
|
+
statusToken,
|
|
62
|
+
pollAfterMs: 2_500,
|
|
63
|
+
}), { status: 202, headers: { "content-type": "application/json" } });
|
|
64
|
+
}
|
|
65
|
+
return new Response(JSON.stringify({
|
|
66
|
+
ok: true,
|
|
67
|
+
status: "created",
|
|
68
|
+
submissionId,
|
|
69
|
+
issueUrl: "https://github.com/Firstp1ck/pi-coding-agent-forge/issues/42",
|
|
70
|
+
issueNumber: 42,
|
|
71
|
+
}), { headers: { "content-type": "application/json" } });
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
const completed = await client.submit({ issue, onStatus: (status) => statuses.push(status.status) });
|
|
75
|
+
assert.equal(completed.result.status, "created");
|
|
76
|
+
assert.equal(completed.result.issueNumber, 42);
|
|
77
|
+
assert.equal(completed.handle.refresh instanceof Function, true, "the in-memory opaque refresh handle must support manual polling");
|
|
78
|
+
assert.deepEqual(Object.keys(completed.handle), ["refresh"], "the refresh handle must not expose a status capability");
|
|
79
|
+
assert.deepEqual(statuses, ["queued", "queued", "created"], "admission and every safe poll state should be observable without raw upstream data");
|
|
80
|
+
assert.equal(calls.length, 2);
|
|
81
|
+
assert.equal(calls[0].url, "https://issue-intake.example.test/v1/submissions");
|
|
82
|
+
assert.equal(calls[0].options.credentials, "omit");
|
|
83
|
+
const sent = JSON.parse(calls[0].options.body);
|
|
84
|
+
assert.deepEqual(Object.keys(sent).sort(), ["idempotencyKey", "issue", "schemaVersion", "turnstileToken"]);
|
|
85
|
+
assert.equal(sent.idempotencyKey, uuid, "each admission uses the injected fresh UUID-v4 source");
|
|
86
|
+
assert.deepEqual(sent.issue, issue, "the adapter sends structured wizard state, not canonical title/body fields");
|
|
87
|
+
assert.equal("title" in sent.issue, false);
|
|
88
|
+
assert.equal("body" in sent.issue, false);
|
|
89
|
+
assert.equal(calls[1].options.headers.authorization, `Bearer ${statusToken}`, "only the in-memory capability authorizes status polling");
|
|
90
|
+
|
|
91
|
+
let timeoutClock = 0;
|
|
92
|
+
const timeoutClient = createIssueBotClient({
|
|
93
|
+
config,
|
|
94
|
+
uuidFactory: () => uuid,
|
|
95
|
+
getTurnstileToken: async () => "fresh-turnstile-token",
|
|
96
|
+
sleep: async () => { timeoutClock += 500; },
|
|
97
|
+
now: () => timeoutClock,
|
|
98
|
+
maxPollDurationMs: 500,
|
|
99
|
+
fetchImpl: async (_url, options) => new Response(JSON.stringify(options.method === "POST" ? {
|
|
100
|
+
ok: true, status: "queued", submissionId, statusToken, pollAfterMs: 2_500,
|
|
101
|
+
} : {
|
|
102
|
+
ok: true, status: "checking", submissionId, pollAfterMs: 2_500,
|
|
103
|
+
}), { status: options.method === "POST" ? 202 : 200, headers: { "content-type": "application/json" } }),
|
|
104
|
+
});
|
|
105
|
+
const timedOut = await timeoutClient.submit({ issue });
|
|
106
|
+
assert.equal(timedOut.result.status, "checking");
|
|
107
|
+
assert.equal(timedOut.result.timedOut, true, "polling must stop after its bounded duration and retain a manual refresh handle");
|
|
108
|
+
assert.equal(typeof timedOut.handle.refresh, "function");
|
|
109
|
+
|
|
110
|
+
const invalidEnvelopeClient = createIssueBotClient({
|
|
111
|
+
config,
|
|
112
|
+
uuidFactory: () => uuid,
|
|
113
|
+
getTurnstileToken: async () => "fresh-turnstile-token",
|
|
114
|
+
sleep: async () => {},
|
|
115
|
+
fetchImpl: async (_url, options) => new Response(JSON.stringify(options.method === "POST" ? {
|
|
116
|
+
ok: true, status: "queued", submissionId, statusToken, pollAfterMs: 2_500,
|
|
117
|
+
} : {
|
|
118
|
+
ok: true, status: "created", submissionId,
|
|
119
|
+
issueUrl: "https://github.com/Firstp1ck/pi-coding-agent-forge/issues/43", issueNumber: 43, unexpected: true,
|
|
120
|
+
}), { status: options.method === "POST" ? 202 : 200, headers: { "content-type": "application/json" } }),
|
|
121
|
+
});
|
|
122
|
+
assert.equal((await invalidEnvelopeClient.submit({ issue })).result.status, "unavailable", "unknown response properties must fail closed");
|
|
123
|
+
|
|
124
|
+
const abortController = new AbortController();
|
|
125
|
+
const abortClient = createIssueBotClient({
|
|
126
|
+
config,
|
|
127
|
+
uuidFactory: () => uuid,
|
|
128
|
+
getTurnstileToken: ({ signal }) => new Promise((_resolve, reject) => signal.addEventListener("abort", () => reject(new DOMException("aborted", "AbortError")), { once: true })),
|
|
129
|
+
fetchImpl: async () => { throw new Error("fetch must not run after Turnstile abort"); },
|
|
130
|
+
});
|
|
131
|
+
const aborted = abortClient.submit({ issue, signal: abortController.signal });
|
|
132
|
+
abortController.abort();
|
|
133
|
+
await assert.rejects(aborted, (error) => error?.name === "AbortError", "dialog-close cancellation must abort before admission");
|
|
134
|
+
|
|
135
|
+
console.log("issue-bot-client.test.mjs passed");
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import {
|
|
3
|
+
ISSUE_WIZARD_STEP_COUNT,
|
|
4
|
+
IssueWizardValidationError,
|
|
5
|
+
buildIssuePayload,
|
|
6
|
+
createIssueWizardCatalog,
|
|
7
|
+
createIssueWizardState,
|
|
8
|
+
getCompatibleTemplates,
|
|
9
|
+
isIssueWizardStepValid,
|
|
10
|
+
issueClipboardText,
|
|
11
|
+
normalizeIssueText,
|
|
12
|
+
reduceIssueWizardState,
|
|
13
|
+
serializeIssuePayload,
|
|
14
|
+
submitIssueToGithubBot,
|
|
15
|
+
validateIssueWizardState,
|
|
16
|
+
} from "../public/issue-wizard-state.mjs";
|
|
17
|
+
|
|
18
|
+
const catalog = createIssueWizardCatalog([
|
|
19
|
+
"Guided Git workflow",
|
|
20
|
+
"NPM Release",
|
|
21
|
+
"Guided Git workflow",
|
|
22
|
+
"WebUI",
|
|
23
|
+
" Theme bundle ",
|
|
24
|
+
"",
|
|
25
|
+
]);
|
|
26
|
+
|
|
27
|
+
assert.deepEqual(
|
|
28
|
+
catalog.categories.map((category) => category.label),
|
|
29
|
+
["Feature", "Bug", "UX", "Documentation", "Performance", "Compatibility", "Other"],
|
|
30
|
+
"the approved category catalog should be deterministic and omit Security",
|
|
31
|
+
);
|
|
32
|
+
assert.deepEqual(
|
|
33
|
+
catalog.components.map((component) => component.label),
|
|
34
|
+
["WebUI", "Guided Git workflow", "NPM Release", "Theme bundle"],
|
|
35
|
+
"optional component labels should come only from caller input and be normalized/deduplicated",
|
|
36
|
+
);
|
|
37
|
+
assert.equal(catalog.components[0].id, "webui");
|
|
38
|
+
assert.ok(Object.isFrozen(catalog), "the generated catalog should not be mutable by a caller");
|
|
39
|
+
assert.ok(catalog.templates.every((template) => template.fields.some((field) => field.kind === "choices" || field.kind === "select")), "every template should prefer a structured choice or dropdown field");
|
|
40
|
+
|
|
41
|
+
const featureTemplates = getCompatibleTemplates(catalog, "feature", "webui");
|
|
42
|
+
assert.deepEqual(featureTemplates.map((template) => template.id), ["feature-new-capability"], "template choices should be filtered by category and component");
|
|
43
|
+
assert.deepEqual(getCompatibleTemplates(catalog, "feature", "missing"), [], "an unknown component must not expose templates");
|
|
44
|
+
assert.deepEqual(getCompatibleTemplates(catalog, "bug", "webui").map((template) => template.id), ["bug-defect-report"]);
|
|
45
|
+
|
|
46
|
+
let state = createIssueWizardState();
|
|
47
|
+
assert.equal(state.step, 1);
|
|
48
|
+
assert.equal(isIssueWizardStepValid(state, catalog), false, "the first page requires a category");
|
|
49
|
+
state = reduceIssueWizardState(state, { type: "next" }, catalog);
|
|
50
|
+
assert.equal(state.step, 1, "next must not advance an invalid step");
|
|
51
|
+
state = reduceIssueWizardState(state, { type: "select-category", categoryId: "bug" }, catalog);
|
|
52
|
+
assert.equal(state.categoryId, "bug");
|
|
53
|
+
assert.equal(state.templateId, "", "choosing a category resets its dependent template state");
|
|
54
|
+
state = reduceIssueWizardState(state, { type: "next" }, catalog);
|
|
55
|
+
assert.equal(state.step, 2);
|
|
56
|
+
state = reduceIssueWizardState(state, { type: "select-component", componentId: "webui" }, catalog);
|
|
57
|
+
state = reduceIssueWizardState(state, { type: "next" }, catalog);
|
|
58
|
+
assert.equal(state.step, 3);
|
|
59
|
+
state = reduceIssueWizardState(state, { type: "select-template", templateId: "feature-new-capability" }, catalog);
|
|
60
|
+
assert.equal(state.templateId, "", "an incompatible template action must preserve the current state");
|
|
61
|
+
state = reduceIssueWizardState(state, { type: "select-template", templateId: "bug-defect-report" }, catalog);
|
|
62
|
+
assert.equal(state.templateId, "bug-defect-report");
|
|
63
|
+
state = reduceIssueWizardState(state, { type: "next" }, catalog);
|
|
64
|
+
assert.equal(state.step, 4);
|
|
65
|
+
state = reduceIssueWizardState(state, { type: "set-summary", summary: "Panel fails to open" }, catalog);
|
|
66
|
+
state = reduceIssueWizardState(state, { type: "set-field", fieldId: "severity", value: "high" }, catalog);
|
|
67
|
+
state = reduceIssueWizardState(state, { type: "set-field", fieldId: "expectedBehavior", value: "The panel opens." }, catalog);
|
|
68
|
+
state = reduceIssueWizardState(state, { type: "set-field", fieldId: "actualBehavior", value: "Nothing appears." }, catalog);
|
|
69
|
+
state = reduceIssueWizardState(state, { type: "set-field", fieldId: "reproductionSteps", value: "1. Open the deck\n2. Select the panel" }, catalog);
|
|
70
|
+
assert.equal(isIssueWizardStepValid(state, catalog), true, "a completed form should validate at the details step");
|
|
71
|
+
state = reduceIssueWizardState(state, { type: "next" }, catalog);
|
|
72
|
+
assert.equal(state.step, ISSUE_WIZARD_STEP_COUNT, "a valid details form should advance to review");
|
|
73
|
+
state = reduceIssueWizardState(state, { type: "back" }, catalog);
|
|
74
|
+
assert.equal(state.step, 4, "back should preserve prior selections and answers");
|
|
75
|
+
state = reduceIssueWizardState(state, { type: "select-component", componentId: "feature-npm-release" }, catalog);
|
|
76
|
+
assert.equal(state.templateId, "", "changing component resets template and field answers");
|
|
77
|
+
assert.deepEqual(state.fields, {});
|
|
78
|
+
assert.equal(state.summary, "Panel fails to open", "changing a dependent selection must retain the independent summary");
|
|
79
|
+
|
|
80
|
+
const incomplete = createIssueWizardState();
|
|
81
|
+
const incompleteValidation = validateIssueWizardState(incomplete, catalog);
|
|
82
|
+
assert.equal(incompleteValidation.valid, false);
|
|
83
|
+
assert.deepEqual(Object.keys(incompleteValidation.errors).sort(), ["categoryId", "componentId", "summary"], "validation should expose field-specific errors without inventing a template error before selections exist");
|
|
84
|
+
|
|
85
|
+
const payloadState = {
|
|
86
|
+
step: 5,
|
|
87
|
+
categoryId: "bug",
|
|
88
|
+
componentId: "webui",
|
|
89
|
+
templateId: "bug-defect-report",
|
|
90
|
+
summary: " Preview [breaks]\n on launch ",
|
|
91
|
+
fields: {
|
|
92
|
+
severity: "high",
|
|
93
|
+
expectedBehavior: "A preview appears.",
|
|
94
|
+
actualBehavior: "# heading\n- fake list\n[untrusted](https://example.test)",
|
|
95
|
+
reproductionSteps: "1. Open preview\r\n2. Observe failure\u0000",
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
const payload = buildIssuePayload(payloadState, catalog);
|
|
99
|
+
assert.equal(payload.title, "[Bug] [WebUI] [Defect report] Preview breaks on launch", "titles must use the approved category/component/template prefix and a normalized summary");
|
|
100
|
+
assert.match(payload.body, /^## Defect report/m);
|
|
101
|
+
assert.match(payload.body, /### Actual behavior\n\\# heading\n\\- fake list\n\\\[untrusted\\\]\\\(https:\/\/example\.test\\\)/, "prose must be escaped so it cannot introduce user-controlled Markdown structure");
|
|
102
|
+
assert.match(payload.body, /\\1\. Open preview\n\\2\. Observe failure/, "multiline prose should normalize CRLF and remove controls");
|
|
103
|
+
assert.deepEqual(JSON.parse(serializeIssuePayload(payload)), payload, "serialization should contain the exact complete title/body payload");
|
|
104
|
+
assert.equal(issueClipboardText(payload), `${payload.title}\n\n${payload.body}`, "copy output should include both title and body");
|
|
105
|
+
assert.equal(normalizeIssueText(" a\r\nb\u0000 "), "a\nb", "normalization should trim surrounding whitespace while removing controls");
|
|
106
|
+
|
|
107
|
+
assert.equal(
|
|
108
|
+
validateIssueWizardState({ ...payloadState, summary: "[ ]" }, catalog).valid,
|
|
109
|
+
false,
|
|
110
|
+
"a bracket-only summary must not pass when brackets are removed from the generated title",
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
assert.throws(
|
|
114
|
+
() => buildIssuePayload({ ...payloadState, fields: { ...payloadState.fields, severity: "critical" } }, catalog),
|
|
115
|
+
(error) => error instanceof IssueWizardValidationError && Boolean(error.errors.severity),
|
|
116
|
+
"unknown choice values must be rejected before payload generation",
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
const submission = await submitIssueToGithubBot(payload);
|
|
120
|
+
assert.deepEqual(submission, {
|
|
121
|
+
ok: false,
|
|
122
|
+
status: "unavailable",
|
|
123
|
+
message: "Automatic submission is coming soon. Copy the issue instead.",
|
|
124
|
+
}, "the future submission seam must explicitly remain unavailable");
|
|
125
|
+
|
|
126
|
+
console.log("issue-wizard-state.test.mjs passed");
|