@firstpick/pi-package-webui 0.6.9 → 0.7.1
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 +7 -2
- package/bin/pi-webui.mjs +407 -31
- package/index.ts +7 -91
- package/package.json +8 -7
- package/public/app.js +1140 -100
- package/public/aur-review-payload.mjs +108 -0
- package/public/guided-git-command-state.mjs +34 -0
- package/public/guided-git-review-state.mjs +137 -0
- package/public/index.html +54 -1
- package/public/styles.css +290 -20
- package/tests/aur-review-payload.test.mjs +57 -0
- package/tests/aur-review-widget-static.test.mjs +38 -0
- package/tests/compaction-resume-harness.test.mjs +55 -3
- package/tests/compaction-static.test.mjs +3 -3
- package/tests/fixtures/compacting-pi.mjs +10 -5
- package/tests/fixtures/fake-pi.mjs +46 -0
- package/tests/guided-git-aur-review.test.mjs +183 -0
- package/tests/http-endpoints-harness.test.mjs +118 -1
- package/tests/mobile-static.test.mjs +123 -12
- package/tests/staged-content-hash-contract.test.mjs +174 -0
- package/tests/subagents-helper.test.mjs +83 -4
- package/tests/transport-hardening-harness.test.mjs +157 -0
- package/webui-rpc-helper.mjs +108 -25
|
@@ -261,6 +261,26 @@ function handleWebuiHelperPrompt(command, base) {
|
|
|
261
261
|
currentToolArgs: "README.md",
|
|
262
262
|
recentTools: [{ tool: "grep", args: "Subagents", endMs: Date.now() - 200 }],
|
|
263
263
|
recentOutput: ["Inspecting current implementation", "Waiting for the next tool result"],
|
|
264
|
+
transcript: [
|
|
265
|
+
{
|
|
266
|
+
role: "assistant",
|
|
267
|
+
timestamp: "2026-07-19T12:00:00.000Z",
|
|
268
|
+
content: [
|
|
269
|
+
{ type: "thinking", thinking: "Checking the fixture transcript." },
|
|
270
|
+
{ type: "text", text: "Inspecting current implementation" },
|
|
271
|
+
{ type: "toolCall", id: "fixture-read", name: "read", arguments: { path: "README.md", offset: 1 } },
|
|
272
|
+
{ type: "text", text: "Waiting for the next tool result" },
|
|
273
|
+
],
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
role: "toolResult",
|
|
277
|
+
timestamp: "2026-07-19T12:00:01.000Z",
|
|
278
|
+
toolCallId: "fixture-read",
|
|
279
|
+
toolName: "read",
|
|
280
|
+
isError: false,
|
|
281
|
+
content: [{ type: "text", text: "# Fixture README" }],
|
|
282
|
+
},
|
|
283
|
+
],
|
|
264
284
|
turnCount: 2,
|
|
265
285
|
toolCount: 3,
|
|
266
286
|
tokens: 420,
|
|
@@ -285,6 +305,31 @@ function handleDocumentArtifactFixturePrompt(command, base) {
|
|
|
285
305
|
return true;
|
|
286
306
|
}
|
|
287
307
|
|
|
308
|
+
function handleTransportFixturePrompt(command, base) {
|
|
309
|
+
const message = String(command.message || "").trim();
|
|
310
|
+
if (message === "fixture stderr diagnostic") {
|
|
311
|
+
process.stderr.write("fixture Pi RPC stderr diagnostic\n");
|
|
312
|
+
respond({ ...base, data: { output: "fake stderr diagnostic emitted" } });
|
|
313
|
+
return true;
|
|
314
|
+
}
|
|
315
|
+
if (message === "fixture oversized jsonl") {
|
|
316
|
+
const bytes = Math.max(0, Math.min(64 * 1024 * 1024, Number.parseInt(process.env.FAKE_PI_OVERSIZED_JSONL_BYTES || "0", 10) || 0));
|
|
317
|
+
if (bytes === 0) {
|
|
318
|
+
respond({ ...base, success: false, error: "FAKE_PI_OVERSIZED_JSONL_BYTES must be configured" });
|
|
319
|
+
return true;
|
|
320
|
+
}
|
|
321
|
+
// Intentionally leave this physical JSONL line unterminated long enough
|
|
322
|
+
// for the server to switch into discard mode before sending a valid reply.
|
|
323
|
+
process.stdout.write("x".repeat(bytes));
|
|
324
|
+
setTimeout(() => {
|
|
325
|
+
process.stdout.write("\n");
|
|
326
|
+
respond({ ...base, data: { output: "fake oversized JSONL line discarded" } });
|
|
327
|
+
}, 50);
|
|
328
|
+
return true;
|
|
329
|
+
}
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
|
|
288
333
|
function handleSubagentFixturePrompt(command, base) {
|
|
289
334
|
const message = String(command.message || "").trim();
|
|
290
335
|
if (message !== "fixture subagents running" && message !== "fixture subagents clear") return false;
|
|
@@ -447,6 +492,7 @@ rl.on("line", (line) => {
|
|
|
447
492
|
}
|
|
448
493
|
case "prompt":
|
|
449
494
|
if (handleWebuiHelperPrompt(command, base)) return;
|
|
495
|
+
if (handleTransportFixturePrompt(command, base)) return;
|
|
450
496
|
if (handleSubagentFixturePrompt(command, base)) return;
|
|
451
497
|
if (handleDocumentArtifactFixturePrompt(command, base)) return;
|
|
452
498
|
if (handleWorkflowFixturePrompt(command, base)) return;
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import {
|
|
6
|
+
guidedGitReviewCanRequestStagedContent,
|
|
7
|
+
guidedGitReviewHasApprovedBinding,
|
|
8
|
+
guidedGitReviewProcessNavigationAllowed,
|
|
9
|
+
guidedGitReviewProcessSelectionPatch,
|
|
10
|
+
guidedGitReviewTransition,
|
|
11
|
+
guidedGitReviewWidgetRemovalTransition,
|
|
12
|
+
} from "../public/guided-git-review-state.mjs";
|
|
13
|
+
import { guidedGitReviewAvailableForTabCatalog, resolveRpcSlashCommandForTabCatalog } from "../public/guided-git-command-state.mjs";
|
|
14
|
+
|
|
15
|
+
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
16
|
+
const app = await readFile(join(root, "public", "app.js"), "utf8");
|
|
17
|
+
const fingerprint = "a".repeat(64);
|
|
18
|
+
const stagedContentHash = "c".repeat(64);
|
|
19
|
+
const repoRoot = "/workspace/repository";
|
|
20
|
+
const pendingPayload = {
|
|
21
|
+
scope: "staged",
|
|
22
|
+
origin: "guided-git",
|
|
23
|
+
repoRoot,
|
|
24
|
+
fingerprint,
|
|
25
|
+
stagedContentHash,
|
|
26
|
+
updatedAt: "2026-06-01T00:00:02.000Z",
|
|
27
|
+
decision: { state: "pending" },
|
|
28
|
+
};
|
|
29
|
+
const requestingWorkflow = {
|
|
30
|
+
active: true,
|
|
31
|
+
step: "reviewRequesting",
|
|
32
|
+
guidedReviewStatus: "requesting",
|
|
33
|
+
guidedReviewRequestedAt: Date.parse("2026-06-01T00:00:01.000Z"),
|
|
34
|
+
guidedReviewFingerprint: "",
|
|
35
|
+
guidedReviewRepoRoot: "",
|
|
36
|
+
guidedReviewStagedContentHash: "",
|
|
37
|
+
guidedReviewDeclinedStagedContentHash: "",
|
|
38
|
+
};
|
|
39
|
+
const pendingWorkflow = {
|
|
40
|
+
...requestingWorkflow,
|
|
41
|
+
step: "review",
|
|
42
|
+
guidedReviewStatus: "pending",
|
|
43
|
+
guidedReviewRequired: true,
|
|
44
|
+
guidedReviewFingerprint: fingerprint,
|
|
45
|
+
guidedReviewRepoRoot: repoRoot,
|
|
46
|
+
guidedReviewStagedContentHash: stagedContentHash,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
assert.equal(guidedGitReviewTransition(requestingWorkflow, pendingPayload), "pending", "only a fresh staged/guided-git pending payload may bind a request");
|
|
50
|
+
assert.equal(guidedGitReviewTransition(pendingWorkflow, { ...pendingPayload, decision: { state: "approved", decidedAt: "2026-06-01T00:00:03.000Z", reviewedFingerprint: fingerprint, reviewedStagedContentHash: stagedContentHash } }), "approved", "matching approval may advance the matching flow");
|
|
51
|
+
assert.equal(guidedGitReviewTransition(pendingWorkflow, { ...pendingPayload, decision: { state: "declined", decidedAt: "2026-06-01T00:00:03.000Z", reviewedFingerprint: fingerprint, reviewedStagedContentHash: stagedContentHash } }), "declined", "matching decline must reset the matching flow");
|
|
52
|
+
assert.equal(guidedGitReviewTransition(pendingWorkflow, { ...pendingPayload, decision: { state: "closed" } }), "closed", "a matching closed payload must return the pending flow to recovery without approval");
|
|
53
|
+
assert.equal(guidedGitReviewTransition(requestingWorkflow, { ...pendingPayload, decision: { state: "closed" } }), "closed", "a freshly requested review may close before its pending card is replayed");
|
|
54
|
+
assert.equal(guidedGitReviewTransition(pendingWorkflow, { ...pendingPayload, origin: "standalone", scope: "working-tree", decision: { state: "approved", decidedAt: "2026-06-01T00:00:03.000Z", reviewedFingerprint: fingerprint, reviewedStagedContentHash: stagedContentHash } }), "ignore", "standalone payloads cannot advance Guided Git");
|
|
55
|
+
assert.equal(guidedGitReviewTransition(pendingWorkflow, { ...pendingPayload, fingerprint: "b".repeat(64), decision: { state: "approved", decidedAt: "2026-06-01T00:00:03.000Z", reviewedFingerprint: "b".repeat(64), reviewedStagedContentHash: stagedContentHash } }), "ignore", "a stale/wrong review cannot advance Guided Git");
|
|
56
|
+
assert.equal(guidedGitReviewTransition(pendingWorkflow, { ...pendingPayload, decision: { state: "approved", decidedAt: "2026-06-01T00:00:03.000Z", reviewedFingerprint: fingerprint, reviewedStagedContentHash: "d".repeat(64) } }), "ignore", "approval must bind the exact staged-content hash");
|
|
57
|
+
assert.equal(guidedGitReviewTransition({ ...pendingWorkflow, active: false }, { ...pendingPayload, decision: { state: "approved", decidedAt: "2026-06-01T00:00:03.000Z", reviewedFingerprint: fingerprint, reviewedStagedContentHash: stagedContentHash } }), "ignore", "a payload for another tab's inactive flow cannot advance this tab");
|
|
58
|
+
assert.equal(guidedGitReviewWidgetRemovalTransition(pendingWorkflow), "closed", "clearing a matching pending widget is equivalent to close");
|
|
59
|
+
assert.equal(guidedGitReviewWidgetRemovalTransition({ ...pendingWorkflow, step: "add", guidedReviewStatus: "" }), "ignore", "a replayed widget removal cannot disturb a recovered staging flow");
|
|
60
|
+
|
|
61
|
+
const freshAvailableWorkflow = {
|
|
62
|
+
...requestingWorkflow,
|
|
63
|
+
step: "add",
|
|
64
|
+
process: "stage",
|
|
65
|
+
guidedReviewRequired: true,
|
|
66
|
+
};
|
|
67
|
+
for (const process of ["message", "commit", "push"]) {
|
|
68
|
+
assert.equal(guidedGitReviewProcessNavigationAllowed(requestingWorkflow, process), false, `${process} navigation must be rejected while review request is outstanding`);
|
|
69
|
+
assert.equal(guidedGitReviewProcessNavigationAllowed(pendingWorkflow, process), false, `${process} navigation must be rejected while review is pending`);
|
|
70
|
+
assert.equal(guidedGitReviewProcessNavigationAllowed(freshAvailableWorkflow, process), false, `a fresh available-review flow must block ${process} before staging and approval`);
|
|
71
|
+
assert.equal(guidedGitReviewProcessSelectionPatch(freshAvailableWorkflow, process), null, `a fresh available-review flow must not transition to ${process}`);
|
|
72
|
+
}
|
|
73
|
+
assert.equal(guidedGitReviewProcessNavigationAllowed(pendingWorkflow, "stage"), true, "staging recovery remains available while review is pending");
|
|
74
|
+
assert.equal(guidedGitReviewProcessNavigationAllowed(pendingWorkflow, "review"), true, "review recovery remains available while review is pending");
|
|
75
|
+
|
|
76
|
+
const approvedWorkflow = {
|
|
77
|
+
...pendingWorkflow,
|
|
78
|
+
step: "generate",
|
|
79
|
+
process: "message",
|
|
80
|
+
guidedReviewStatus: "approved",
|
|
81
|
+
guidedReviewRequired: false,
|
|
82
|
+
};
|
|
83
|
+
assert.equal(guidedGitReviewHasApprovedBinding(approvedWorkflow), true, "approval must carry the exact repo, fingerprint, and staged-content binding");
|
|
84
|
+
for (const process of ["message", "commit", "push"]) {
|
|
85
|
+
assert.equal(guidedGitReviewProcessNavigationAllowed(approvedWorkflow, process), true, `matching approval may navigate to ${process}`);
|
|
86
|
+
const patch = guidedGitReviewProcessSelectionPatch(approvedWorkflow, process);
|
|
87
|
+
assert.equal(patch?.guidedReviewStatus, "approved", `${process} navigation must preserve approval status`);
|
|
88
|
+
assert.equal(patch?.guidedReviewRepoRoot, repoRoot, `${process} navigation must preserve the approved repo root`);
|
|
89
|
+
assert.equal(patch?.guidedReviewFingerprint, fingerprint, `${process} navigation must preserve the approved fingerprint`);
|
|
90
|
+
assert.equal(patch?.guidedReviewStagedContentHash, stagedContentHash, `${process} navigation must preserve the approved staged-content hash`);
|
|
91
|
+
assert.equal(patch?.guidedReviewRequired, false, `${process} navigation must not convert matching approval to legacy state`);
|
|
92
|
+
}
|
|
93
|
+
for (const process of ["stage", "review"]) {
|
|
94
|
+
const patch = guidedGitReviewProcessSelectionPatch(approvedWorkflow, process);
|
|
95
|
+
assert.equal(patch?.guidedReviewRequired, true, `${process} must re-arm required review after approval`);
|
|
96
|
+
assert.equal(patch?.guidedReviewStatus, "", `${process} must clear prior approval status`);
|
|
97
|
+
assert.equal(patch?.guidedReviewRepoRoot, "", `${process} must clear prior repo binding`);
|
|
98
|
+
assert.equal(patch?.guidedReviewFingerprint, "", `${process} must clear prior fingerprint binding`);
|
|
99
|
+
assert.equal(patch?.guidedReviewStagedContentHash, "", `${process} must clear prior staged-content binding`);
|
|
100
|
+
const rearmedWorkflow = { ...approvedWorkflow, ...patch, step: process === "stage" ? "add" : "review", process };
|
|
101
|
+
for (const laterProcess of ["message", "commit", "push"]) {
|
|
102
|
+
assert.equal(guidedGitReviewProcessNavigationAllowed(rearmedWorkflow, laterProcess), false, `${laterProcess} must remain blocked after approval is cleared via ${process}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const legacyWorkflow = {
|
|
107
|
+
...requestingWorkflow,
|
|
108
|
+
step: "add",
|
|
109
|
+
process: "stage",
|
|
110
|
+
guidedReviewRequired: false,
|
|
111
|
+
};
|
|
112
|
+
for (const process of ["message", "commit", "push"]) {
|
|
113
|
+
assert.equal(guidedGitReviewProcessNavigationAllowed(legacyWorkflow, process), true, `a flow started without aur-review retains legacy ${process} navigation`);
|
|
114
|
+
assert.equal(guidedGitReviewProcessSelectionPatch(legacyWorkflow, process)?.guidedReviewRequired, false, `legacy ${process} navigation must remain ungated`);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const recoveredWorkflow = {
|
|
118
|
+
...pendingWorkflow,
|
|
119
|
+
step: "add",
|
|
120
|
+
process: "stage",
|
|
121
|
+
guidedReviewStatus: "",
|
|
122
|
+
guidedReviewFingerprint: "",
|
|
123
|
+
guidedReviewRepoRoot: "",
|
|
124
|
+
guidedReviewStagedContentHash: "",
|
|
125
|
+
guidedReviewDeclinedStagedContentHash: stagedContentHash,
|
|
126
|
+
guidedReviewRequired: true,
|
|
127
|
+
};
|
|
128
|
+
for (const process of ["message", "commit", "push"]) {
|
|
129
|
+
assert.equal(guidedGitReviewProcessNavigationAllowed(recoveredWorkflow, process), false, `${process} remains blocked after Stage/Review recovery`);
|
|
130
|
+
}
|
|
131
|
+
assert.equal(guidedGitReviewProcessNavigationAllowed(recoveredWorkflow, "stage"), true, "recovery stage remains available with durable requirement");
|
|
132
|
+
assert.equal(guidedGitReviewProcessNavigationAllowed(recoveredWorkflow, "review"), true, "recovery review remains available with durable requirement");
|
|
133
|
+
const rerequestedWorkflow = { ...pendingWorkflow, guidedReviewRequired: true };
|
|
134
|
+
assert.equal(guidedGitReviewTransition(rerequestedWorkflow, { ...pendingPayload, decision: { state: "approved", decidedAt: "2026-06-01T00:00:03.000Z", reviewedFingerprint: fingerprint, reviewedStagedContentHash: stagedContentHash } }), "approved", "a new matching approval advances the recovered review flow");
|
|
135
|
+
assert.equal(guidedGitReviewCanRequestStagedContent(recoveredWorkflow, stagedContentHash), false, "an unchanged declined staged hash must be rejected");
|
|
136
|
+
assert.equal(guidedGitReviewCanRequestStagedContent(recoveredWorkflow, "d".repeat(64)), true, "changed/restaged content may request a new review");
|
|
137
|
+
|
|
138
|
+
const catalogByTab = new Map();
|
|
139
|
+
const delay = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
140
|
+
await Promise.all([
|
|
141
|
+
(async () => { await delay(12); catalogByTab.set("tab-a", { raw: [{ name: "git-staged-msg", source: "extension" }], available: [{ name: "git-staged-msg", source: "extension" }] }); })(),
|
|
142
|
+
(async () => { await delay(1); catalogByTab.set("tab-b", { raw: [{ name: "aur-review:2", source: "extension" }], available: [{ name: "aur-review:2", invokeName: "aur-review:2", duplicateCount: 2, source: "extension" }] }); })(),
|
|
143
|
+
]);
|
|
144
|
+
assert.equal(guidedGitReviewAvailableForTabCatalog(catalogByTab.get("tab-a")), false, "tab A cannot inherit tab B's review command after async tab switching");
|
|
145
|
+
assert.equal(resolveRpcSlashCommandForTabCatalog(catalogByTab.get("tab-a"), "/aur-review start --scope staged"), "/aur-review start --scope staged", "tab A cannot inherit tab B's alias");
|
|
146
|
+
assert.equal(guidedGitReviewAvailableForTabCatalog(catalogByTab.get("tab-b")), true, "tab B retains its own review command");
|
|
147
|
+
assert.equal(resolveRpcSlashCommandForTabCatalog(catalogByTab.get("tab-b"), "/aur-review start --scope staged"), "/aur-review:2 start --scope staged", "tab B resolves only its own alias");
|
|
148
|
+
|
|
149
|
+
const runGitAdd = app.slice(app.indexOf("async function runGitAdd"), app.indexOf("async function acceptCurrentGitStaging"));
|
|
150
|
+
const acceptStaging = app.slice(app.indexOf("async function acceptCurrentGitStaging"), app.indexOf("async function loadGitWorkflowDefaultCommitMessage"));
|
|
151
|
+
assert.match(runGitAdd, /guidedGitReviewAvailable\(tabId\) \|\| workflow\.guidedReviewRequired === true[\s\S]*await requestGuidedGitReview\(tabId, \{ output \}\)/s, "git add . must keep an already-required review gate fail-closed while preserving disabled-from-start fallback");
|
|
152
|
+
assert.match(acceptStaging, /guidedGitReviewAvailable\(tabId\) \|\| workflow\.guidedReviewRequired === true[\s\S]*await requestGuidedGitReview\(tabId, \{ output \}\)/s, "accepting a staged set must keep an already-required review gate fail-closed");
|
|
153
|
+
const reconcileReview = app.slice(app.indexOf("function reconcileGuidedGitReviewPayload"), app.indexOf("async function startGitWorkflow"));
|
|
154
|
+
assert.match(reconcileReview, /transition === "approved"[\s\S]*step: "generate"[\s\S]*guidedReviewDeclinedStagedContentHash: ""/s, "only approval advances to message generation and clears an older decline binding");
|
|
155
|
+
assert.match(reconcileReview, /transition === "pending"[\s\S]*guidedReviewDeclinedStagedContentHash[\s\S]*same staged content that was declined/s, "extension payload replay cannot retry an unchanged declined staged hash");
|
|
156
|
+
assert.match(reconcileReview, /transition === "closed"[\s\S]*resetGuidedGitReviewToStaging/s, "closed payloads must reset the matching flow to staging");
|
|
157
|
+
assert.match(reconcileReview, /function reconcileGuidedGitReviewWidgetRemoval[\s\S]*guidedGitReviewWidgetRemovalTransition[\s\S]*resetGuidedGitReviewToStaging/s, "matching widget removal must reset the gate rather than imply approval");
|
|
158
|
+
const resetReviewToStaging = app.slice(app.indexOf("function resetGuidedGitReviewToStaging"), app.indexOf("function reconcileGuidedGitReviewPayload"));
|
|
159
|
+
assert.match(resetReviewToStaging, /step: "add"[\s\S]*stage: false/s, "decline and close return the flow to staging and require restaging");
|
|
160
|
+
const workflowRender = app.slice(app.indexOf("function renderGitWorkflow"), app.indexOf("async function gitWorkflowRequest"));
|
|
161
|
+
assert.match(workflowRender, /item\.disabled = !!gitWorkflow\.busy \|\| !guidedGitReviewProcessNavigationAllowed\(gitWorkflow, process\.value\);/, "the UI must disable later process buttons while the review gate is active");
|
|
162
|
+
const processSelection = app.slice(app.indexOf("function selectGitWorkflowProcess"), app.indexOf("function gitWorkflowTitle"));
|
|
163
|
+
assert.match(processSelection, /const guidedReviewPatch = guidedGitReviewProcessSelectionPatch\(workflow, process\);[\s\S]*if \(!guidedReviewPatch\) return;[\s\S]*\.\.\.guidedReviewPatch/s, "process selection must use the tested patch that preserves approval or re-arms review");
|
|
164
|
+
assert.doesNotMatch(processSelection, /resetGuidedGitReviewPatch/, "process selection must not share a reset that drops an approved binding during later navigation");
|
|
165
|
+
const startWorkflow = app.slice(app.indexOf("async function startGitWorkflow"), app.indexOf("async function startGitInitWorkflow"));
|
|
166
|
+
assert.match(startWorkflow, /guidedReviewRequired: guidedGitReviewAvailable\(tabId\)/, "a fresh standard flow must require review when aur-review is available in its originating tab");
|
|
167
|
+
assert.match(app, /function guidedGitReviewAvailable\(tabId = activeTabId\)[\s\S]*commandCatalogForTab\(tabId\)/, "Guided Git availability must read the originating tab catalog");
|
|
168
|
+
assert.match(app, /resolveRpcSlashCommandMessage\(guidedGitReviewCommand\(\), \{ tabId \}\)/, "Guided Git review requests must resolve aliases from the originating tab catalog");
|
|
169
|
+
assert.match(app, /message = resolveRpcSlashCommandMessage\(message, \{ tabId: targetTabId \}\)/, "generic targeted slash-command dispatch must resolve aliases from its captured target tab");
|
|
170
|
+
for (const [name, action] of [["runGitMessagePrompt", "commit-message generation"], ["commitGitWorkflow", "commit"], ["createGitPrBranchWithSuggestion", "PR worktree creation"]]) {
|
|
171
|
+
const start = app.indexOf(`async function ${name}`);
|
|
172
|
+
const next = app.indexOf("\nasync function ", start + 1);
|
|
173
|
+
const source = app.slice(start, next === -1 ? undefined : next);
|
|
174
|
+
assert.match(source, /assertGuidedGitStagedContentBinding/, `${name} must recheck the approved staged-content hash at its action boundary`);
|
|
175
|
+
assert.match(source, /expectedStagedContentHash/, `${name} must send the approved staged-content hash to its gated endpoint`);
|
|
176
|
+
}
|
|
177
|
+
assert.match(app, /function requestGuidedGitReview[\s\S]*readGuidedGitStagedContent[\s\S]*git add \. produced no substantive staged changes[\s\S]*guideded|function requestGuidedGitReview[\s\S]*readGuidedGitStagedContent[\s\S]*git add \. produced no substantive staged changes/s, "manual-review requests must preflight no-staged content instead of waiting for a card");
|
|
178
|
+
assert.match(app, /guidedGitReviewUnavailableMessage[\s\S]*No message, commit, worktree, or push action was performed/, "a disappeared extension after a required gate must remain fail-closed with recovery guidance");
|
|
179
|
+
assert.match(app, /commandCatalogsByTab\.set\(tabContext\.tabId, catalog\)[\s\S]*if \(!isCurrentTabContext\(tabContext\)\) return;/, "async command refresh must cache inactive-tab results rather than discard or activate them");
|
|
180
|
+
assert.match(app, /widgetKey === AUR_REVIEW_RPC_WIDGET_KEY[\s\S]*else if \(!Array\.isArray\(request\.widgetLines\)\) reconcileGuidedGitReviewWidgetRemoval\(requestTabId\)/s, "active-tab widget clearing must reconcile a matching pending review");
|
|
181
|
+
assert.match(app, /AUR_REVIEW_RPC_WIDGET_KEY\)[\s\S]*else if \(!Array\.isArray\(event\.widgetLines\)\) reconcileGuidedGitReviewWidgetRemoval\(event\.tabId\)/s, "inactive-tab widget clearing must reconcile the owning tab only");
|
|
182
|
+
assert.match(app, /handleInactiveTabEvent[\s\S]*AUR_REVIEW_RPC_WIDGET_KEY[\s\S]*reconcileGuidedGitReviewPayload\(event\.tabId, payload\)/s, "tab-local review events must reconcile using their event tab id");
|
|
183
|
+
console.log("guided Git aur-review tests passed");
|
|
@@ -269,6 +269,21 @@ try {
|
|
|
269
269
|
const rawVoiceModuleSize = (await stat(join(root, "public", "voice-conversation.mjs"))).size;
|
|
270
270
|
assert.equal(voiceModuleBody.byteLength, rawVoiceModuleSize, "served voice-conversation.mjs should match the raw file byte-for-byte in size");
|
|
271
271
|
|
|
272
|
+
// app.js imports this pure Guided Git review gate at startup. Fetch it over
|
|
273
|
+
// the real server so an omitted static allowlist entry cannot 404 the UI.
|
|
274
|
+
const guidedGitReviewStateResponse = await fetch(`http://127.0.0.1:${port}/guided-git-review-state.mjs`, {
|
|
275
|
+
signal: AbortSignal.timeout(5_000),
|
|
276
|
+
});
|
|
277
|
+
assert.equal(guidedGitReviewStateResponse.status, 200, "guided-git-review-state.mjs must be served for the Guided Git review gate");
|
|
278
|
+
assert.match(guidedGitReviewStateResponse.headers.get("content-type") || "", /text\/javascript/, "guided-git-review-state.mjs should use a JavaScript MIME type");
|
|
279
|
+
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");
|
|
280
|
+
for (const moduleName of ["aur-review-payload.mjs", "guided-git-command-state.mjs"]) {
|
|
281
|
+
const response = await fetch(`http://127.0.0.1:${port}/${moduleName}`, { signal: AbortSignal.timeout(5_000) });
|
|
282
|
+
assert.equal(response.status, 200, `${moduleName} must be served for the Guided Git review gate`);
|
|
283
|
+
assert.match(response.headers.get("content-type") || "", /text\/javascript/, `${moduleName} should use a JavaScript MIME type`);
|
|
284
|
+
assert.equal(await response.text(), await readFile(join(root, "public", moduleName), "utf8"), `served ${moduleName} must match the source module`);
|
|
285
|
+
}
|
|
286
|
+
|
|
272
287
|
const mermaidModuleResponse = await fetch(`http://127.0.0.1:${port}/vendor/mermaid/mermaid.esm.min.mjs`, {
|
|
273
288
|
signal: AbortSignal.timeout(5_000),
|
|
274
289
|
});
|
|
@@ -290,6 +305,12 @@ try {
|
|
|
290
305
|
const tabId = tabList[0].id;
|
|
291
306
|
assert.ok(tabId, "tab should have an id");
|
|
292
307
|
|
|
308
|
+
const optionalFeatures = await request("127.0.0.1", "/api/optional-features");
|
|
309
|
+
assert.equal(optionalFeatures.status, 200, "optional feature status should load");
|
|
310
|
+
const aurReviewFeature = optionalFeatures.body?.data?.features?.find((feature) => feature.featureId === "aurReview");
|
|
311
|
+
assert.equal(aurReviewFeature?.installed, true, "workspace discovery should find the local pi-extension-aur-review sibling without an npm dependency");
|
|
312
|
+
assert.equal(path.basename(aurReviewFeature?.installedRoot || ""), "pi-extension-aur-review", "aur-review discovery must validate the exact sibling manifest/name");
|
|
313
|
+
|
|
293
314
|
const sessionToolsBefore = await request("127.0.0.1", `/api/tools?tab=${encodeURIComponent(tabId)}&scope=session`);
|
|
294
315
|
assert.equal(sessionToolsBefore.status, 200);
|
|
295
316
|
assert.equal(sessionToolsBefore.body?.data?.scope, "session");
|
|
@@ -409,6 +430,25 @@ try {
|
|
|
409
430
|
assert.equal(subagentOutputResponse.body?.data?.agent?.name, "reviewer", "subagent output should target the selected child agent");
|
|
410
431
|
assert.deepEqual(subagentOutputResponse.body?.data?.agent?.recentOutput, ["Inspecting current implementation", "Waiting for the next tool result"], "subagent output should preserve bounded live output lines");
|
|
411
432
|
assert.equal(subagentOutputResponse.body?.data?.agent?.currentToolArgs, "README.md", "subagent output should include current tool state");
|
|
433
|
+
assert.deepEqual(subagentOutputResponse.body?.data?.agent?.transcript, [
|
|
434
|
+
{
|
|
435
|
+
role: "assistant",
|
|
436
|
+
timestamp: "2026-07-19T12:00:00.000Z",
|
|
437
|
+
content: [
|
|
438
|
+
{ type: "thinking", thinking: "Checking the fixture transcript." },
|
|
439
|
+
{ type: "text", text: "Inspecting current implementation" },
|
|
440
|
+
{ type: "toolCall", id: "fixture-read", name: "read", arguments: "{\"path\":\"README.md\",\"offset\":1}" },
|
|
441
|
+
{ type: "text", text: "Waiting for the next tool result" },
|
|
442
|
+
],
|
|
443
|
+
},
|
|
444
|
+
{
|
|
445
|
+
role: "toolResult",
|
|
446
|
+
timestamp: "2026-07-19T12:00:01.000Z",
|
|
447
|
+
toolCallId: "fixture-read",
|
|
448
|
+
toolName: "read",
|
|
449
|
+
content: [{ type: "text", text: "# Fixture README" }],
|
|
450
|
+
},
|
|
451
|
+
], "subagent output endpoint should preserve normalized structured transcript roles, order, IDs, and tool metadata");
|
|
412
452
|
const unknownSubagentOutput = await request("127.0.0.1", `/api/subagents/output?tab=${encodeURIComponent(tabId)}&run=missing&agent=missing`);
|
|
413
453
|
assert.equal(unknownSubagentOutput.status, 404, "subagent output endpoint should reject untracked selections");
|
|
414
454
|
const subagentFixtureClear = await request("127.0.0.1", "/api/prompt", { method: "POST", body: { tab: tabId, message: "fixture subagents clear" } });
|
|
@@ -515,6 +555,30 @@ try {
|
|
|
515
555
|
assert.equal(initialWorktrees.body?.ok, true, "worktree list endpoint should return data for a git repository");
|
|
516
556
|
assert.ok(initialWorktrees.body?.data?.worktrees?.some((worktree) => worktree.isMainWorktree && worktree.current), "worktree list should include the current main worktree");
|
|
517
557
|
|
|
558
|
+
const originMainBase = runGitFixture(["rev-parse", "HEAD"], cwd, "origin/main base fixture should resolve current HEAD");
|
|
559
|
+
runGitFixture(["update-ref", "refs/remotes/origin/main", originMainBase], cwd, "origin/main base fixture should create a remote-tracking ref");
|
|
560
|
+
await writeFile(path.join(cwd, "workspace-head.txt"), "current workspace only\n");
|
|
561
|
+
runGitFixture(["add", "workspace-head.txt"], cwd, "workspace HEAD fixture should stage its marker");
|
|
562
|
+
runGitFixture(["commit", "-m", "test: advance workspace head"], cwd, "workspace HEAD fixture should advance main beyond origin/main");
|
|
563
|
+
const workspaceHead = runGitFixture(["rev-parse", "HEAD"], cwd, "workspace HEAD fixture should resolve advanced HEAD");
|
|
564
|
+
assert.notEqual(workspaceHead, originMainBase, "workspace HEAD should differ from origin/main for base selection coverage");
|
|
565
|
+
|
|
566
|
+
const originBasedBranch = "feat/origin-main-base";
|
|
567
|
+
const originBasedWorktree = await request("127.0.0.1", "/api/git-worktrees", {
|
|
568
|
+
method: "POST",
|
|
569
|
+
body: { tab: tabId, branchName: originBasedBranch, baseRef: "origin/main", sessionMode: "empty", openTab: true },
|
|
570
|
+
timeoutMs: 20_000,
|
|
571
|
+
});
|
|
572
|
+
assert.equal(originBasedWorktree.status, 200);
|
|
573
|
+
assert.equal(originBasedWorktree.body?.ok, true, `origin/main-based worktree should be created: ${originBasedWorktree.body?.error || ""}`);
|
|
574
|
+
const originBasedWorktreePath = originBasedWorktree.body?.data?.worktree?.path || originBasedWorktree.body?.data?.path;
|
|
575
|
+
const originBasedWorktreeTabId = originBasedWorktree.body?.data?.tab?.id;
|
|
576
|
+
assert.equal(runGitFixture(["rev-parse", "HEAD"], originBasedWorktreePath, "origin/main-based worktree should resolve its HEAD"), originMainBase, "explicit baseRef should create the branch from origin/main rather than the current workspace HEAD");
|
|
577
|
+
const closeOriginBasedTab = await request("127.0.0.1", "/api/tabs/close", { method: "POST", body: { ids: [originBasedWorktreeTabId] }, timeoutMs: 10_000 });
|
|
578
|
+
assert.equal(closeOriginBasedTab.body?.ok, true, "origin/main-based worktree tab should close before cleanup");
|
|
579
|
+
const removeOriginBasedWorktree = await request("127.0.0.1", "/api/git-worktrees", { method: "DELETE", body: { tab: tabId, path: originBasedWorktreePath, confirmed: true }, timeoutMs: 20_000 });
|
|
580
|
+
assert.equal(removeOriginBasedWorktree.body?.ok, true, "origin/main-based worktree should be removable after the tab closes");
|
|
581
|
+
|
|
518
582
|
await writeFile(path.join(cwd, "guided.txt"), "guided worktree flow\n");
|
|
519
583
|
runGitFixture(["add", "guided.txt"], cwd, "source checkout should stage guided workflow changes");
|
|
520
584
|
await mkdir(path.join(cwd, "dev", "COMMIT"), { recursive: true });
|
|
@@ -557,7 +621,7 @@ try {
|
|
|
557
621
|
const worktreeBranch = "feat/http-worktree";
|
|
558
622
|
const createWorktree = await request("127.0.0.1", "/api/git-worktrees", {
|
|
559
623
|
method: "POST",
|
|
560
|
-
body: { tab: tabId, branchName: worktreeBranch, sessionMode: "empty", openTab: true },
|
|
624
|
+
body: { tab: tabId, branchName: worktreeBranch, baseRef: "HEAD", sessionMode: "empty", openTab: true },
|
|
561
625
|
timeoutMs: 20_000,
|
|
562
626
|
});
|
|
563
627
|
assert.equal(createWorktree.status, 200);
|
|
@@ -571,6 +635,7 @@ try {
|
|
|
571
635
|
assert.equal(createWorktree.body?.data?.tab?.cwd, worktreePath, "opened worktree tab should be rooted at the worktree path");
|
|
572
636
|
assert.equal(createWorktree.body?.data?.tab?.gitWorkspace?.branch, worktreeBranch, "opened tab metadata should record the worktree branch");
|
|
573
637
|
assert.equal(createWorktree.body?.data?.tab?.gitWorkspace?.worktreePath, worktreePath, "opened tab metadata should record the worktree path");
|
|
638
|
+
assert.equal(runGitFixture(["rev-parse", "HEAD"], worktreePath, "current-HEAD-based worktree should resolve its HEAD"), workspaceHead, "explicit HEAD baseRef should create the branch from the active workspace commit");
|
|
574
639
|
|
|
575
640
|
const branchesWithWorktree = await request("127.0.0.1", `/api/git-branches?tab=${encodeURIComponent(tabId)}`);
|
|
576
641
|
assert.equal(branchesWithWorktree.status, 200);
|
|
@@ -1055,6 +1120,58 @@ try {
|
|
|
1055
1120
|
const closeGitActionTabs = await request("127.0.0.1", "/api/tabs/close", { method: "POST", body: { ids: [stagingTab, truncationTab, mergeTab, abortTab, rebaseTab, bisectTab, stashTab, undoTab] }, timeoutMs: 10_000 });
|
|
1056
1121
|
assert.equal(closeGitActionTabs.status, 200, "git action fixture tabs should close");
|
|
1057
1122
|
await rmWithRetry(gitFixturesRoot);
|
|
1123
|
+
|
|
1124
|
+
// AUR-review paths are repo-root-relative even when a tab starts in a
|
|
1125
|
+
// subdirectory. The dedicated read-only route must not reuse cwd-scoped
|
|
1126
|
+
// workspace file access.
|
|
1127
|
+
const reportRepo = await mkdtemp(path.join(tmpdir(), "pi-webui-aur-report-"));
|
|
1128
|
+
let reportTabId = "";
|
|
1129
|
+
try {
|
|
1130
|
+
const reportSubdir = path.join(reportRepo, "subdir");
|
|
1131
|
+
const reportPath = path.join(reportRepo, "reports", "audit.md");
|
|
1132
|
+
const oversizedReportPath = path.join(reportRepo, "reports", "oversized.md");
|
|
1133
|
+
await mkdir(reportSubdir, { recursive: true });
|
|
1134
|
+
await mkdir(path.dirname(reportPath), { recursive: true });
|
|
1135
|
+
runGitFixture(["init", "-b", "main"], reportRepo, "report fixture should initialize");
|
|
1136
|
+
await writeFile(reportPath, "# Audit report\n\nCanonical repo-root report.\n", "utf8");
|
|
1137
|
+
const reportTab = await request("127.0.0.1", "/api/tabs", { method: "POST", body: { cwd: reportSubdir, title: "aur-report-subdir" } });
|
|
1138
|
+
assert.equal(reportTab.status, 201, `subdirectory report tab should open: ${reportTab.body?.error || ""}`);
|
|
1139
|
+
reportTabId = reportTab.body?.data?.tab?.id || "";
|
|
1140
|
+
assert.ok(reportTabId, "subdirectory report tab should have an id");
|
|
1141
|
+
const reportRequestPath = (reportFile, repoRoot = reportRepo) => `/api/aur-review/report-content?tab=${encodeURIComponent(reportTabId)}&path=${encodeURIComponent(reportFile)}&repoRoot=${encodeURIComponent(repoRoot)}`;
|
|
1142
|
+
|
|
1143
|
+
const cwdScopedMiss = await request("127.0.0.1", `/api/files/content?tab=${encodeURIComponent(reportTabId)}&path=${encodeURIComponent("reports/audit.md")}`);
|
|
1144
|
+
assert.equal(cwdScopedMiss.status, 404, "generic workspace file access must remain scoped to the tab subdirectory");
|
|
1145
|
+
const openedReport = await request("127.0.0.1", reportRequestPath("reports/audit.md"));
|
|
1146
|
+
assert.equal(openedReport.status, 200, `repo-root report should open from a subdirectory tab: ${openedReport.body?.error || ""}`);
|
|
1147
|
+
assert.equal(openedReport.body?.data?.root, reportRepo, "report endpoint should return the canonical Git root");
|
|
1148
|
+
assert.equal(openedReport.body?.data?.path, "reports/audit.md", "report endpoint should retain the repo-relative report path");
|
|
1149
|
+
assert.equal(openedReport.body?.data?.content, "# Audit report\n\nCanonical repo-root report.\n");
|
|
1150
|
+
assert.equal(openedReport.body?.data?.language, "markdown", "repo-root reports should use the existing Markdown viewer metadata");
|
|
1151
|
+
|
|
1152
|
+
const wrongRoot = await request("127.0.0.1", reportRequestPath("reports/audit.md", reportSubdir));
|
|
1153
|
+
assert.equal(wrongRoot.status, 403, "report endpoint must require the payload repoRoot to equal the canonical Git root");
|
|
1154
|
+
const traversal = await request("127.0.0.1", reportRequestPath("../reports/audit.md"));
|
|
1155
|
+
assert.equal(traversal.status, 400, "report endpoint must reject traversal paths");
|
|
1156
|
+
const absolute = await request("127.0.0.1", reportRequestPath(reportPath));
|
|
1157
|
+
assert.equal(absolute.status, 400, "report endpoint must reject absolute report paths");
|
|
1158
|
+
const nonRegular = await request("127.0.0.1", reportRequestPath("reports"));
|
|
1159
|
+
assert.equal(nonRegular.status, 400, "report endpoint must reject non-regular paths");
|
|
1160
|
+
await writeFile(oversizedReportPath, Buffer.alloc(2 * 1024 * 1024 + 1, 0x61));
|
|
1161
|
+
const oversized = await request("127.0.0.1", reportRequestPath("reports/oversized.md"));
|
|
1162
|
+
assert.equal(oversized.status, 413, "report endpoint must reject oversized reports before returning content");
|
|
1163
|
+
try {
|
|
1164
|
+
await symlink(reportPath, path.join(reportRepo, "reports", "audit-link.md"));
|
|
1165
|
+
const symlinked = await request("127.0.0.1", reportRequestPath("reports/audit-link.md"));
|
|
1166
|
+
assert.equal(symlinked.status, 403, "report endpoint must reject symlinked reports even when their targets stay in the repository");
|
|
1167
|
+
} catch (error) {
|
|
1168
|
+
if (!["EPERM", "EACCES", "EINVAL", "ENOTSUP"].includes(error?.code)) throw error;
|
|
1169
|
+
console.log(`http-endpoints-harness: symlink unavailable (${error.code}); skipping report symlink check`);
|
|
1170
|
+
}
|
|
1171
|
+
} finally {
|
|
1172
|
+
if (reportTabId) await request("127.0.0.1", "/api/tabs/close", { method: "POST", body: { ids: [reportTabId] }, timeoutMs: 10_000 });
|
|
1173
|
+
await rmWithRetry(reportRepo);
|
|
1174
|
+
}
|
|
1058
1175
|
} else {
|
|
1059
1176
|
console.log("http-endpoints-harness: git not available; skipping git init workflow endpoint checks");
|
|
1060
1177
|
}
|