@firstpick/pi-package-webui 0.6.9 → 0.7.0
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 +6 -2
- package/bin/pi-webui.mjs +407 -31
- package/index.ts +7 -91
- package/package.json +5 -4
- package/public/app.js +676 -70
- 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 +4 -1
- package/public/styles.css +92 -2
- 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 +92 -0
- package/tests/mobile-static.test.mjs +59 -6
- 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
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
export const AUR_REVIEW_MAX_DISPLAY_PATH_LENGTH = 1024;
|
|
2
|
+
export const AUR_REVIEW_RPC_PAYLOAD_PREFIX = "AUR_REVIEW_RPC_PAYLOAD ";
|
|
3
|
+
export const AUR_REVIEW_RPC_PAYLOAD_TYPE = "firstpick.pi-extension-aur-review.review";
|
|
4
|
+
export const AUR_REVIEW_RPC_PAYLOAD_VERSION = 3;
|
|
5
|
+
|
|
6
|
+
const FINGERPRINT = /^[a-f0-9]{64}$/i;
|
|
7
|
+
const STAT_KEYS = ["files", "staged", "unstaged", "untracked", "deleted", "renamed", "unmerged"];
|
|
8
|
+
|
|
9
|
+
function hasOnlyKeys(value, keys) {
|
|
10
|
+
return !!value && typeof value === "object" && !Array.isArray(value) && Object.keys(value).every((key) => keys.includes(key));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function validTimestamp(value) {
|
|
14
|
+
if (typeof value !== "string" || !Number.isFinite(Date.parse(value))) return false;
|
|
15
|
+
try {
|
|
16
|
+
return new Date(value).toISOString() === value;
|
|
17
|
+
} catch {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function aurReviewSafePath(value) {
|
|
23
|
+
const path = String(value || "");
|
|
24
|
+
if (!path || path.length > AUR_REVIEW_MAX_DISPLAY_PATH_LENGTH || path.includes("\0") || path.startsWith("/") || path.startsWith("\\")) return "";
|
|
25
|
+
const parts = path.split("/");
|
|
26
|
+
return parts.every((part) => part && part !== "." && part !== "..") ? path : "";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function changedFileStats(files) {
|
|
30
|
+
return files.reduce((stats, file) => ({
|
|
31
|
+
files: stats.files + 1,
|
|
32
|
+
staged: stats.staged + Number(file.staged),
|
|
33
|
+
unstaged: stats.unstaged + Number(file.unstaged),
|
|
34
|
+
untracked: stats.untracked + Number(file.untracked),
|
|
35
|
+
deleted: stats.deleted + Number(file.deleted),
|
|
36
|
+
renamed: stats.renamed + Number(file.renamed),
|
|
37
|
+
unmerged: stats.unmerged + Number(Boolean(file.unmerged)),
|
|
38
|
+
}), { files: 0, staged: 0, unstaged: 0, untracked: 0, deleted: 0, renamed: 0, unmerged: 0 });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function validChangedFile(file) {
|
|
42
|
+
return hasOnlyKeys(file, ["path", "oldPath", "indexStatus", "worktreeStatus", "staged", "unstaged", "untracked", "deleted", "renamed", "unmerged"])
|
|
43
|
+
&& !!aurReviewSafePath(file.path)
|
|
44
|
+
&& (file.oldPath === undefined || !!aurReviewSafePath(file.oldPath))
|
|
45
|
+
&& typeof file.indexStatus === "string" && file.indexStatus.length === 1
|
|
46
|
+
&& typeof file.worktreeStatus === "string" && file.worktreeStatus.length === 1
|
|
47
|
+
&& typeof file.staged === "boolean"
|
|
48
|
+
&& typeof file.unstaged === "boolean"
|
|
49
|
+
&& typeof file.untracked === "boolean"
|
|
50
|
+
&& typeof file.deleted === "boolean"
|
|
51
|
+
&& typeof file.renamed === "boolean"
|
|
52
|
+
&& (file.unmerged === undefined || typeof file.unmerged === "boolean");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function validStats(stats, files, total, truncated) {
|
|
56
|
+
if (!hasOnlyKeys(stats, STAT_KEYS)) return false;
|
|
57
|
+
if (!STAT_KEYS.every((key) => Number.isInteger(stats[key]) && stats[key] >= 0 && stats[key] <= total)) return false;
|
|
58
|
+
if (stats.files !== total) return false;
|
|
59
|
+
const stored = changedFileStats(files);
|
|
60
|
+
return STAT_KEYS.every((key) => truncated ? stored[key] <= stats[key] : stored[key] === stats[key]);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function validReport(report) {
|
|
64
|
+
return hasOnlyKeys(report, ["path", "size", "source"])
|
|
65
|
+
&& !!aurReviewSafePath(report.path)
|
|
66
|
+
&& Number.isFinite(report.size)
|
|
67
|
+
&& report.size >= 0
|
|
68
|
+
&& report.size <= 2 * 1024 * 1024
|
|
69
|
+
&& ["explicit", "changed-file", "conventional"].includes(report.source);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Fail closed on the authorization-relevant durable-record relations. */
|
|
73
|
+
export function parseAurReviewPayload(lines, {
|
|
74
|
+
prefix = AUR_REVIEW_RPC_PAYLOAD_PREFIX,
|
|
75
|
+
type = AUR_REVIEW_RPC_PAYLOAD_TYPE,
|
|
76
|
+
version = AUR_REVIEW_RPC_PAYLOAD_VERSION,
|
|
77
|
+
} = {}) {
|
|
78
|
+
const raw = String(lines?.[0] || "").trim();
|
|
79
|
+
if (!raw.startsWith(prefix)) return null;
|
|
80
|
+
try {
|
|
81
|
+
const payload = JSON.parse(raw.slice(prefix.length));
|
|
82
|
+
if (!payload || payload.type !== type || payload.version !== version) return null;
|
|
83
|
+
if (typeof payload.repoRoot !== "string" || !payload.repoRoot || payload.repoRoot.includes("\0") || !/^(?:\/|[A-Za-z]:[\\/])/.test(payload.repoRoot) || !FINGERPRINT.test(String(payload.fingerprint || ""))) return null;
|
|
84
|
+
if (!((payload.scope === "working-tree" && payload.origin === "standalone") || (payload.scope === "staged" && payload.origin === "guided-git"))) return null;
|
|
85
|
+
const stagedPayload = payload.scope === "staged";
|
|
86
|
+
if (stagedPayload ? !FINGERPRINT.test(String(payload.stagedContentHash || "")) : payload.stagedContentHash !== undefined) return null;
|
|
87
|
+
if (!validTimestamp(payload.createdAt) || !validTimestamp(payload.updatedAt) || Date.parse(payload.createdAt) > Date.parse(payload.updatedAt)) return null;
|
|
88
|
+
if (!Number.isInteger(payload.changedFileTotal) || payload.changedFileTotal <= 0 || payload.changedFileTotal > 1_000_000) return null;
|
|
89
|
+
if (typeof payload.changedFilesTruncated !== "boolean" || !Array.isArray(payload.changedFiles) || payload.changedFiles.length > 500 || !payload.changedFiles.every(validChangedFile)) return null;
|
|
90
|
+
if (payload.changedFilesTruncated ? payload.changedFiles.length >= payload.changedFileTotal : payload.changedFiles.length !== payload.changedFileTotal) return null;
|
|
91
|
+
if (!validStats(payload.stats, payload.changedFiles, payload.changedFileTotal, payload.changedFilesTruncated)) return null;
|
|
92
|
+
if (!Array.isArray(payload.reports) || payload.reports.length > 20 || !payload.reports.every(validReport)) return null;
|
|
93
|
+
if (!hasOnlyKeys(payload.decision, ["state", "decidedAt", "reviewedFingerprint", "reviewedStagedContentHash"]) || !["pending", "approved", "declined", "closed"].includes(payload.decision.state)) return null;
|
|
94
|
+
const decision = payload.decision;
|
|
95
|
+
if (["approved", "declined"].includes(decision.state)) {
|
|
96
|
+
if (!validTimestamp(decision.decidedAt)
|
|
97
|
+
|| decision.reviewedFingerprint !== payload.fingerprint
|
|
98
|
+
|| (stagedPayload ? decision.reviewedStagedContentHash !== payload.stagedContentHash : decision.reviewedStagedContentHash !== undefined)) return null;
|
|
99
|
+
const decidedAt = Date.parse(decision.decidedAt);
|
|
100
|
+
if (decidedAt < Date.parse(payload.createdAt) || decidedAt > Date.parse(payload.updatedAt)) return null;
|
|
101
|
+
} else if (decision.decidedAt !== undefined || decision.reviewedFingerprint !== undefined || decision.reviewedStagedContentHash !== undefined) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
return payload;
|
|
105
|
+
} catch {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
function commandBaseName(name) {
|
|
2
|
+
return String(name || "").replace(/:\d+$/, "");
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
function commandNameMatches(commandName, requestedName) {
|
|
6
|
+
const commandText = String(commandName || "");
|
|
7
|
+
const requested = String(requestedName || "");
|
|
8
|
+
return commandText === requested || (commandText.startsWith(`${requested}:`) && /^\d+$/.test(commandText.slice(requested.length + 1)));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Resolve only from one tab's already-normalized command catalog. */
|
|
12
|
+
export function resolveCommandForTabCatalog(catalog, name, { rpcOnly = false } = {}) {
|
|
13
|
+
const requested = String(name || "").trim();
|
|
14
|
+
if (!requested) return null;
|
|
15
|
+
const raw = Array.isArray(catalog?.raw) ? catalog.raw : [];
|
|
16
|
+
const available = Array.isArray(catalog?.available) ? catalog.available : raw;
|
|
17
|
+
const commands = (rpcOnly ? raw : available).filter((command) => !rpcOnly || command.source !== "native");
|
|
18
|
+
const exact = commands.find((command) => command.name === requested || command.invokeName === requested || command.duplicateNames?.includes(requested));
|
|
19
|
+
if (exact) return exact;
|
|
20
|
+
const canUseBaseAlias = available.some((command) => commandBaseName(command.name) === requested && command.invokeName && command.duplicateCount > 1);
|
|
21
|
+
return canUseBaseAlias ? commands.find((command) => commandNameMatches(command?.name, requested)) || null : null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function resolveRpcSlashCommandForTabCatalog(catalog, message) {
|
|
25
|
+
const text = String(message || "");
|
|
26
|
+
const match = text.match(/^\/([^\s]+)([\s\S]*)$/);
|
|
27
|
+
if (!match) return text;
|
|
28
|
+
const resolvedName = resolveCommandForTabCatalog(catalog, match[1], { rpcOnly: true })?.name || "";
|
|
29
|
+
return resolvedName && resolvedName !== match[1] ? `/${resolvedName}${match[2]}` : text;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function guidedGitReviewAvailableForTabCatalog(catalog) {
|
|
33
|
+
return !!resolveCommandForTabCatalog(catalog, "aur-review", { rpcOnly: true });
|
|
34
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
const GUIDED_SCOPE = "staged";
|
|
2
|
+
const GUIDED_ORIGIN = "guided-git";
|
|
3
|
+
const FINGERPRINT = /^[a-f0-9]{64}$/i;
|
|
4
|
+
const RECOVERY_PROCESSES = new Set(["stage", "review"]);
|
|
5
|
+
const LATER_PROCESSES = new Set(["message", "commit", "push"]);
|
|
6
|
+
|
|
7
|
+
/** A decline is content-specific: retries require a different staged digest. */
|
|
8
|
+
export function guidedGitReviewCanRequestStagedContent(workflow, stagedContentHash) {
|
|
9
|
+
return !workflow?.guidedReviewDeclinedStagedContentHash
|
|
10
|
+
|| workflow.guidedReviewDeclinedStagedContentHash !== stagedContentHash;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function validGuidedPayload(payload) {
|
|
14
|
+
return !!payload
|
|
15
|
+
&& payload.scope === GUIDED_SCOPE
|
|
16
|
+
&& payload.origin === GUIDED_ORIGIN
|
|
17
|
+
&& typeof payload.repoRoot === "string"
|
|
18
|
+
&& payload.repoRoot.length > 0
|
|
19
|
+
&& FINGERPRINT.test(String(payload.fingerprint || ""))
|
|
20
|
+
&& FINGERPRINT.test(String(payload.stagedContentHash || ""))
|
|
21
|
+
&& typeof payload.updatedAt === "string"
|
|
22
|
+
&& Number.isFinite(Date.parse(payload.updatedAt))
|
|
23
|
+
&& payload.decision
|
|
24
|
+
&& ["pending", "approved", "declined", "closed"].includes(payload.decision.state);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function sameReview(workflow, payload) {
|
|
28
|
+
return workflow.guidedReviewFingerprint === payload.fingerprint
|
|
29
|
+
&& workflow.guidedReviewRepoRoot === payload.repoRoot
|
|
30
|
+
&& workflow.guidedReviewStagedContentHash === payload.stagedContentHash;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function guidedGitReviewHasApprovedBinding(workflow) {
|
|
34
|
+
return workflow?.guidedReviewStatus === "approved"
|
|
35
|
+
&& typeof workflow.guidedReviewRepoRoot === "string"
|
|
36
|
+
&& workflow.guidedReviewRepoRoot.length > 0
|
|
37
|
+
&& FINGERPRINT.test(String(workflow.guidedReviewFingerprint || ""))
|
|
38
|
+
&& FINGERPRINT.test(String(workflow.guidedReviewStagedContentHash || ""));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function isGuidedReviewGateActive(workflow) {
|
|
42
|
+
if (!workflow?.active) return false;
|
|
43
|
+
// A malformed or lost approved binding is not a legacy workflow. Keep it
|
|
44
|
+
// fail-closed so no later process can consume staged content without a new
|
|
45
|
+
// matching review.
|
|
46
|
+
if (workflow.guidedReviewStatus === "approved" && !guidedGitReviewHasApprovedBinding(workflow)) return true;
|
|
47
|
+
// The requirement remains after Stage/Review recovery, decline, close, or a
|
|
48
|
+
// cleared card. Only the matching approval transition may clear it.
|
|
49
|
+
if (workflow.guidedReviewRequired === true) return true;
|
|
50
|
+
return ["reviewRequesting", "review"].includes(workflow.step)
|
|
51
|
+
&& ["requesting", "pending"].includes(workflow.guidedReviewStatus);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Recovery stays available while a staged review gate is active, but later
|
|
56
|
+
* process navigation cannot bypass an outstanding review decision.
|
|
57
|
+
*/
|
|
58
|
+
export function guidedGitReviewProcessNavigationAllowed(workflow, process) {
|
|
59
|
+
if (!isGuidedReviewGateActive(workflow)) return true;
|
|
60
|
+
if (RECOVERY_PROCESSES.has(process)) return true;
|
|
61
|
+
return !LATER_PROCESSES.has(process);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function clearedGuidedGitReviewPatch(workflow, guidedReviewRequired) {
|
|
65
|
+
return {
|
|
66
|
+
guidedReviewStatus: "",
|
|
67
|
+
guidedReviewFingerprint: "",
|
|
68
|
+
guidedReviewRepoRoot: "",
|
|
69
|
+
guidedReviewStagedContentHash: "",
|
|
70
|
+
guidedReviewRequestedAt: 0,
|
|
71
|
+
guidedReviewDeclinedStagedContentHash: workflow?.guidedReviewDeclinedStagedContentHash || "",
|
|
72
|
+
guidedReviewRequired,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Return the review-state patch for a process selection, or null when the
|
|
78
|
+
* requested process is blocked. Later process navigation retains the exact
|
|
79
|
+
* approved binding; recovery deliberately clears it and requires a new review.
|
|
80
|
+
*/
|
|
81
|
+
export function guidedGitReviewProcessSelectionPatch(workflow, process) {
|
|
82
|
+
if (!guidedGitReviewProcessNavigationAllowed(workflow, process)) return null;
|
|
83
|
+
const reviewWasRequired = workflow?.guidedReviewRequired === true || workflow?.guidedReviewStatus === "approved";
|
|
84
|
+
if (RECOVERY_PROCESSES.has(process)) return clearedGuidedGitReviewPatch(workflow, reviewWasRequired);
|
|
85
|
+
if (guidedGitReviewHasApprovedBinding(workflow)) {
|
|
86
|
+
return {
|
|
87
|
+
guidedReviewStatus: workflow.guidedReviewStatus,
|
|
88
|
+
guidedReviewFingerprint: workflow.guidedReviewFingerprint,
|
|
89
|
+
guidedReviewRepoRoot: workflow.guidedReviewRepoRoot,
|
|
90
|
+
guidedReviewStagedContentHash: workflow.guidedReviewStagedContentHash,
|
|
91
|
+
guidedReviewRequestedAt: workflow.guidedReviewRequestedAt || 0,
|
|
92
|
+
guidedReviewDeclinedStagedContentHash: workflow.guidedReviewDeclinedStagedContentHash || "",
|
|
93
|
+
guidedReviewRequired: false,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
return clearedGuidedGitReviewPatch(workflow, false);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** A cleared matching pending widget is equivalent to an explicit close. */
|
|
100
|
+
export function guidedGitReviewWidgetRemovalTransition(workflow) {
|
|
101
|
+
return workflow?.active
|
|
102
|
+
&& workflow.step === "review"
|
|
103
|
+
&& workflow.guidedReviewStatus === "pending"
|
|
104
|
+
&& typeof workflow.guidedReviewFingerprint === "string"
|
|
105
|
+
&& workflow.guidedReviewFingerprint.length > 0
|
|
106
|
+
&& typeof workflow.guidedReviewRepoRoot === "string"
|
|
107
|
+
&& workflow.guidedReviewRepoRoot.length > 0
|
|
108
|
+
&& FINGERPRINT.test(String(workflow.guidedReviewStagedContentHash || ""))
|
|
109
|
+
? "closed"
|
|
110
|
+
: "ignore";
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Return the only valid Guided Git transition for an already schema-validated
|
|
115
|
+
* browser payload. Keeping this pure makes approval gating independently testable.
|
|
116
|
+
*/
|
|
117
|
+
export function guidedGitReviewTransition(workflow, payload) {
|
|
118
|
+
if (!workflow?.active || !["reviewRequesting", "review"].includes(workflow.step) || !validGuidedPayload(payload)) return "ignore";
|
|
119
|
+
const decision = payload.decision.state;
|
|
120
|
+
const requestedAt = Number(workflow.guidedReviewRequestedAt || 0);
|
|
121
|
+
const isFreshRequestPayload = workflow.guidedReviewStatus === "requesting"
|
|
122
|
+
&& (!requestedAt || Date.parse(payload.updatedAt) >= requestedAt);
|
|
123
|
+
if (decision === "pending") {
|
|
124
|
+
if (isFreshRequestPayload) return "pending";
|
|
125
|
+
return workflow.guidedReviewStatus === "pending" && sameReview(workflow, payload) ? "pending" : "ignore";
|
|
126
|
+
}
|
|
127
|
+
if (decision === "closed") {
|
|
128
|
+
if (isFreshRequestPayload) return "closed";
|
|
129
|
+
return workflow.guidedReviewStatus === "pending" && sameReview(workflow, payload) ? "closed" : "ignore";
|
|
130
|
+
}
|
|
131
|
+
if (!["approved", "declined"].includes(decision) || workflow.guidedReviewStatus !== "pending" || !sameReview(workflow, payload)) return "ignore";
|
|
132
|
+
if (payload.decision.reviewedFingerprint !== payload.fingerprint
|
|
133
|
+
|| payload.decision.reviewedStagedContentHash !== payload.stagedContentHash
|
|
134
|
+
|| typeof payload.decision.decidedAt !== "string"
|
|
135
|
+
|| !Number.isFinite(Date.parse(payload.decision.decidedAt))) return "ignore";
|
|
136
|
+
return decision;
|
|
137
|
+
}
|
package/public/index.html
CHANGED
|
@@ -389,7 +389,10 @@
|
|
|
389
389
|
<aside id="sidePanel" class="side-panel" role="dialog" aria-label="Control Deck">
|
|
390
390
|
<div class="side-panel-header">
|
|
391
391
|
<div class="side-panel-heading">
|
|
392
|
-
<
|
|
392
|
+
<div class="side-panel-brand-row">
|
|
393
|
+
<span class="side-panel-kicker">Pi Web UI</span>
|
|
394
|
+
<a class="sponsor-link" href="https://github.com/sponsors/Firstp1ck" target="_blank" rel="noopener noreferrer" aria-label="Sponsor Firstp1ck on GitHub" title="Sponsor Firstp1ck on GitHub">♡</a>
|
|
395
|
+
</div>
|
|
393
396
|
<strong class="side-panel-title">Control Deck</strong>
|
|
394
397
|
<div class="side-panel-version-row" aria-label="Version and build information">
|
|
395
398
|
<button id="piVersionButton" class="pi-version-button" type="button" aria-label="View Pi release notes" aria-haspopup="dialog" aria-controls="piReleaseNotesDialog" hidden></button>
|
package/public/styles.css
CHANGED
|
@@ -1012,6 +1012,33 @@ body.embedded-split .side-panel-backdrop {
|
|
|
1012
1012
|
font-size: 1rem;
|
|
1013
1013
|
line-height: 1.25;
|
|
1014
1014
|
}
|
|
1015
|
+
.side-panel-brand-row {
|
|
1016
|
+
display: flex;
|
|
1017
|
+
align-items: center;
|
|
1018
|
+
gap: 0.32rem;
|
|
1019
|
+
min-width: 0;
|
|
1020
|
+
}
|
|
1021
|
+
.sponsor-link {
|
|
1022
|
+
display: inline-grid;
|
|
1023
|
+
place-items: center;
|
|
1024
|
+
flex: 0 0 auto;
|
|
1025
|
+
width: 1.25rem;
|
|
1026
|
+
height: 1.25rem;
|
|
1027
|
+
border-radius: 999px;
|
|
1028
|
+
color: rgba(245, 194, 231, 0.62);
|
|
1029
|
+
background: transparent;
|
|
1030
|
+
font-size: 0.95rem;
|
|
1031
|
+
line-height: 1;
|
|
1032
|
+
text-decoration: none;
|
|
1033
|
+
transition: color 140ms ease, background 140ms ease, box-shadow 140ms ease;
|
|
1034
|
+
}
|
|
1035
|
+
.sponsor-link:hover,
|
|
1036
|
+
.sponsor-link:focus-visible {
|
|
1037
|
+
color: var(--ctp-pink);
|
|
1038
|
+
background: rgba(245, 194, 231, 0.11);
|
|
1039
|
+
box-shadow: 0 0 0.75rem rgba(245, 194, 231, 0.2);
|
|
1040
|
+
outline: none;
|
|
1041
|
+
}
|
|
1015
1042
|
.side-panel-version-row {
|
|
1016
1043
|
display: flex;
|
|
1017
1044
|
align-items: center;
|
|
@@ -4864,6 +4891,66 @@ button.git-workflow-step:hover:not(:disabled) {
|
|
|
4864
4891
|
linear-gradient(145deg, rgba(var(--ctp-crust-rgb), 0.98), rgba(var(--ctp-mantle-rgb), 0.92));
|
|
4865
4892
|
}
|
|
4866
4893
|
.release-aur-widget .release-npm-kicker { color: var(--ctp-peach); }
|
|
4894
|
+
.aur-review-widget {
|
|
4895
|
+
display: grid;
|
|
4896
|
+
gap: 0.68rem;
|
|
4897
|
+
overflow: hidden;
|
|
4898
|
+
white-space: normal;
|
|
4899
|
+
border-color: rgba(250, 179, 135, 0.68);
|
|
4900
|
+
border-left: 0.28rem solid rgba(250, 179, 135, 0.92);
|
|
4901
|
+
background:
|
|
4902
|
+
radial-gradient(circle at 4% 0%, rgba(250, 179, 135, 0.2), transparent 16rem),
|
|
4903
|
+
radial-gradient(circle at 96% 12%, rgba(249, 226, 175, 0.14), transparent 18rem),
|
|
4904
|
+
linear-gradient(145deg, rgba(var(--ctp-crust-rgb), 0.98), rgba(var(--ctp-mantle-rgb), 0.92));
|
|
4905
|
+
}
|
|
4906
|
+
.aur-review-header,
|
|
4907
|
+
.aur-review-title-wrap,
|
|
4908
|
+
.aur-review-actions,
|
|
4909
|
+
.aur-review-summary,
|
|
4910
|
+
.aur-review-reports {
|
|
4911
|
+
display: flex;
|
|
4912
|
+
gap: 0.48rem;
|
|
4913
|
+
align-items: center;
|
|
4914
|
+
min-width: 0;
|
|
4915
|
+
}
|
|
4916
|
+
.aur-review-header { justify-content: space-between; gap: 0.8rem; }
|
|
4917
|
+
.aur-review-title-wrap { display: grid; gap: 0.08rem; align-items: start; }
|
|
4918
|
+
.aur-review-kicker { color: var(--ctp-peach); font-size: var(--text-xs); font-weight: 760; letter-spacing: 0.08em; text-transform: uppercase; }
|
|
4919
|
+
.aur-review-title { color: var(--ctp-text); }
|
|
4920
|
+
.aur-review-actions { flex-wrap: wrap; justify-content: flex-end; }
|
|
4921
|
+
.aur-review-action,
|
|
4922
|
+
.aur-review-report {
|
|
4923
|
+
min-height: 2rem;
|
|
4924
|
+
padding: 0.32rem 0.56rem;
|
|
4925
|
+
border: 1px solid rgba(250, 179, 135, 0.34);
|
|
4926
|
+
border-radius: 0.5rem;
|
|
4927
|
+
color: var(--ctp-text);
|
|
4928
|
+
background: rgba(var(--ctp-crust-rgb), 0.54);
|
|
4929
|
+
font-size: var(--text-xs);
|
|
4930
|
+
}
|
|
4931
|
+
.aur-review-action:hover,
|
|
4932
|
+
.aur-review-report:hover { border-color: rgba(250, 179, 135, 0.8); color: var(--ctp-peach); }
|
|
4933
|
+
.aur-review-action.primary { border-color: rgba(166, 227, 161, 0.58); color: var(--ctp-green); }
|
|
4934
|
+
.aur-review-action.danger { border-color: rgba(243, 139, 168, 0.58); color: var(--ctp-red); }
|
|
4935
|
+
.aur-review-summary { flex-wrap: wrap; align-items: baseline; color: var(--ctp-subtext0); font-size: var(--text-xs); }
|
|
4936
|
+
.aur-review-status { color: var(--ctp-peach); font-weight: 720; }
|
|
4937
|
+
.aur-review-root,
|
|
4938
|
+
.aur-review-fingerprint { max-width: 100%; overflow-wrap: anywhere; }
|
|
4939
|
+
.aur-review-fingerprint { color: var(--ctp-yellow); font-size: var(--text-xs); }
|
|
4940
|
+
.aur-review-files {
|
|
4941
|
+
border: 1px solid rgba(250, 179, 135, 0.2);
|
|
4942
|
+
border-radius: 0.58rem;
|
|
4943
|
+
background: rgba(var(--ctp-crust-rgb), 0.34);
|
|
4944
|
+
}
|
|
4945
|
+
.aur-review-files > summary { padding: 0.48rem 0.56rem; cursor: pointer; color: var(--ctp-subtext0); }
|
|
4946
|
+
.aur-review-file-list { display: grid; gap: 0.3rem; max-height: 12rem; margin: 0; padding: 0 0.8rem 0.65rem 1.7rem; overflow: auto; color: var(--ctp-text); font-size: var(--text-xs); overflow-wrap: anywhere; }
|
|
4947
|
+
.aur-review-reports { flex-wrap: wrap; align-items: baseline; color: var(--ctp-subtext0); font-size: var(--text-xs); }
|
|
4948
|
+
@media (max-width: 720px), (max-device-width: 720px), (pointer: coarse) and (hover: none) {
|
|
4949
|
+
.aur-review-header { align-items: stretch; flex-direction: column; }
|
|
4950
|
+
.aur-review-actions { justify-content: stretch; }
|
|
4951
|
+
.aur-review-action,
|
|
4952
|
+
.aur-review-report { flex: 1 1 7.25rem; min-height: 44px; }
|
|
4953
|
+
}
|
|
4867
4954
|
.app-runner-widget {
|
|
4868
4955
|
border-color: rgba(166, 227, 161, 0.62);
|
|
4869
4956
|
border-left-color: rgba(166, 227, 161, 0.88);
|
|
@@ -8488,10 +8575,13 @@ button.composer-skill-tag:focus-visible {
|
|
|
8488
8575
|
scrollbar-gutter: stable;
|
|
8489
8576
|
}
|
|
8490
8577
|
.subagent-overlay-message {
|
|
8491
|
-
margin: 0;
|
|
8578
|
+
margin: 0 0 0.55rem;
|
|
8579
|
+
}
|
|
8580
|
+
.subagent-overlay-message:last-child {
|
|
8581
|
+
margin-bottom: 0;
|
|
8492
8582
|
}
|
|
8493
8583
|
.subagent-overlay-message + .subagent-output-waiting {
|
|
8494
|
-
margin-top: 0
|
|
8584
|
+
margin-top: 0;
|
|
8495
8585
|
}
|
|
8496
8586
|
.subagent-output-waiting {
|
|
8497
8587
|
width: fit-content;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { AUR_REVIEW_MAX_DISPLAY_PATH_LENGTH, AUR_REVIEW_RPC_PAYLOAD_PREFIX, aurReviewSafePath, parseAurReviewPayload } from "../public/aur-review-payload.mjs";
|
|
3
|
+
|
|
4
|
+
const fingerprint = "a".repeat(64);
|
|
5
|
+
const file = {
|
|
6
|
+
path: "PKGBUILD",
|
|
7
|
+
indexStatus: "M",
|
|
8
|
+
worktreeStatus: ".",
|
|
9
|
+
staged: true,
|
|
10
|
+
unstaged: false,
|
|
11
|
+
untracked: false,
|
|
12
|
+
deleted: false,
|
|
13
|
+
renamed: false,
|
|
14
|
+
};
|
|
15
|
+
const basePayload = {
|
|
16
|
+
type: "firstpick.pi-extension-aur-review.review",
|
|
17
|
+
version: 3,
|
|
18
|
+
repoRoot: "/workspace/repository",
|
|
19
|
+
scope: "staged",
|
|
20
|
+
origin: "guided-git",
|
|
21
|
+
fingerprint,
|
|
22
|
+
stagedContentHash: fingerprint,
|
|
23
|
+
createdAt: "2026-06-01T00:00:00.000Z",
|
|
24
|
+
updatedAt: "2026-06-01T00:00:01.000Z",
|
|
25
|
+
changedFileTotal: 1,
|
|
26
|
+
changedFilesTruncated: false,
|
|
27
|
+
changedFiles: [file],
|
|
28
|
+
stats: { files: 1, staged: 1, unstaged: 0, untracked: 0, deleted: 0, renamed: 0, unmerged: 0 },
|
|
29
|
+
reports: [],
|
|
30
|
+
decision: { state: "pending" },
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
function parse(payload) {
|
|
34
|
+
return parseAurReviewPayload([`${AUR_REVIEW_RPC_PAYLOAD_PREFIX}${JSON.stringify(payload)}`]);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
assert.deepEqual(parse(basePayload), basePayload, "a relationally valid payload should render");
|
|
38
|
+
assert.equal(parse({ ...basePayload, createdAt: "2026-06-01T00:00:02.000Z" }), null, "createdAt must not be after updatedAt");
|
|
39
|
+
assert.equal(parse({ ...basePayload, updatedAt: "2026-06-01T00:00:01Z" }), null, "timestamps must be canonical ISO strings");
|
|
40
|
+
assert.equal(parse({ ...basePayload, stats: { ...basePayload.stats, files: 0 } }), null, "stats.files must equal changedFileTotal");
|
|
41
|
+
assert.equal(parse({ ...basePayload, stats: { ...basePayload.stats, staged: 2 } }), null, "each stat must not exceed changedFileTotal");
|
|
42
|
+
assert.equal(parse({ ...basePayload, changedFileTotal: 2, stats: { ...basePayload.stats, files: 2, staged: 2 } }), null, "non-truncated arrays must match changedFileTotal");
|
|
43
|
+
assert.ok(parse({ ...basePayload, changedFilesTruncated: true, changedFileTotal: 2, stats: { ...basePayload.stats, files: 2, staged: 2 } }), "truncated arrays may summarize fewer stored files than their total stats");
|
|
44
|
+
assert.equal(parse({ ...basePayload, changedFilesTruncated: true, changedFileTotal: 1 }), null, "a truncated file array must be strictly shorter than changedFileTotal");
|
|
45
|
+
assert.equal(parse({ ...basePayload, changedFilesTruncated: true, changedFileTotal: 2, stats: { ...basePayload.stats, files: 2, staged: 0 } }), null, "truncated arrays still need stats to cover their stored summaries");
|
|
46
|
+
assert.equal(parse({ ...basePayload, decision: { state: "approved", decidedAt: "2026-06-01T00:00:01.000Z", reviewedFingerprint: "b".repeat(64), reviewedStagedContentHash: fingerprint } }), null, "terminal decisions must bind the snapshot fingerprint");
|
|
47
|
+
assert.equal(parse({ ...basePayload, decision: { state: "approved", decidedAt: "2026-06-01T00:00:01.000Z", reviewedFingerprint: fingerprint, reviewedStagedContentHash: "b".repeat(64) } }), null, "terminal decisions must bind the staged-content hash");
|
|
48
|
+
assert.equal(parse({ ...basePayload, decision: { state: "declined", decidedAt: "2026-06-01T00:00:01.000Z", reviewedFingerprint: fingerprint, reviewedStagedContentHash: fingerprint } })?.decision.state, "declined", "matching terminal decisions are accepted");
|
|
49
|
+
assert.equal(parse({ ...basePayload, decision: { state: "pending", reviewedFingerprint: fingerprint } }), null, "pending payloads cannot carry terminal fingerprints");
|
|
50
|
+
assert.equal(parse({ ...basePayload, decision: { state: "closed", reviewedFingerprint: fingerprint } }), null, "closed payloads cannot carry terminal fingerprints");
|
|
51
|
+
assert.equal(parse({ ...basePayload, stagedContentHash: undefined }), null, "staged Guided Git payloads require an exact staged-content hash");
|
|
52
|
+
assert.equal(parse({ ...basePayload, scope: "working-tree", origin: "standalone", stagedContentHash: fingerprint }), null, "standalone payloads must not carry a staged-content hash");
|
|
53
|
+
assert.equal(parse({ ...basePayload, scope: "staged", origin: "standalone" }), null, "scope/origin pairs fail closed");
|
|
54
|
+
assert.equal(parse({ ...basePayload, changedFiles: [{ ...file, path: "../escape" }] }), null, "unsafe display paths fail closed");
|
|
55
|
+
assert.equal(aurReviewSafePath("a".repeat(AUR_REVIEW_MAX_DISPLAY_PATH_LENGTH)).length, AUR_REVIEW_MAX_DISPLAY_PATH_LENGTH, "browser display-path maximum includes every displayed character");
|
|
56
|
+
assert.equal(aurReviewSafePath("a".repeat(AUR_REVIEW_MAX_DISPLAY_PATH_LENGTH + 1)), "", "browser rejects paths beyond the shared display maximum");
|
|
57
|
+
console.log("aur review payload tests passed");
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
|
|
6
|
+
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
7
|
+
const [app, css, pkg, server, payloadParser] = await Promise.all([
|
|
8
|
+
readFile(join(root, "public", "app.js"), "utf8"),
|
|
9
|
+
readFile(join(root, "public", "styles.css"), "utf8"),
|
|
10
|
+
readFile(join(root, "package.json"), "utf8"),
|
|
11
|
+
readFile(join(root, "bin", "pi-webui.mjs"), "utf8"),
|
|
12
|
+
readFile(join(root, "public", "aur-review-payload.mjs"), "utf8"),
|
|
13
|
+
]);
|
|
14
|
+
|
|
15
|
+
assert.match(app, /const AUR_REVIEW_RPC_WIDGET_KEY = "aur-review:rpc"[\s\S]*AUR_REVIEW_RPC_PAYLOAD_PREFIX = "AUR_REVIEW_RPC_PAYLOAD "[\s\S]*AUR_REVIEW_RPC_PAYLOAD_TYPE = "firstpick\.pi-extension-aur-review\.review"[\s\S]*AUR_REVIEW_RPC_PAYLOAD_VERSION = 3/, "WebUI should identify the versioned AUR review payload");
|
|
16
|
+
assert.match(app, /parseValidatedAurReviewPayload[\s\S]*function parseAurReviewPayload\(lines\)[\s\S]*prefix: AUR_REVIEW_RPC_PAYLOAD_PREFIX/, "AUR review rendering should delegate parsing to the fail-closed payload module");
|
|
17
|
+
assert.match(payloadParser, /validTimestamp[\s\S]*Date\.parse\(payload\.createdAt\) > Date\.parse\(payload\.updatedAt\)/, "payload parsing should enforce ordered canonical timestamps");
|
|
18
|
+
assert.match(payloadParser, /stats\[key\] <= total[\s\S]*stats\.files !== total/, "payload parsing should enforce stats totals and bounds");
|
|
19
|
+
assert.match(payloadParser, /decision\.reviewedFingerprint !== payload\.fingerprint/, "payload parsing should bind terminal decisions to the snapshot fingerprint");
|
|
20
|
+
assert.match(payloadParser, /stagedPayload \? decision\.reviewedStagedContentHash !== payload\.stagedContentHash/, "payload parsing should bind staged terminal decisions to the staged-content hash");
|
|
21
|
+
assert.match(payloadParser, /payload\.changedFiles\.length >= payload\.changedFileTotal/, "payload parsing should reject equality at the truncated-file boundary");
|
|
22
|
+
assert.match(app, /function renderAurReviewWidget\(\)[\s\S]*Review changes[\s\S]*Refresh[\s\S]*Approve[\s\S]*Decline[\s\S]*Close[\s\S]*openAurReviewReportInViewer\(reportPath, payload\.repoRoot\)/, "renderer should open reports against the payload's repo root rather than the tab cwd");
|
|
23
|
+
assert.match(app, /async function openAurReviewReportInViewer\(path = "", repoRoot = ""\)[\s\S]*\/api\/aur-review\/report-content[\s\S]*readOnly: true/s, "report viewing must use the narrow read-only canonical-root endpoint");
|
|
24
|
+
assert.match(app, /viewer\.readOnly === true \|\| !viewer\.dirty[\s\S]*viewer\.readOnly === true \|\| !viewerPath/s, "repo-root report views must not enable generic save or default-editor actions");
|
|
25
|
+
assert.match(app, /function aurReviewActionButton\(label, action, className = ""\)[\s\S]*action === "review"[\s\S]*openGitChangesDialog\(\)[\s\S]*`\/aur-review \$\{action\}`/, "Review changes should reuse the current Git diff dialog and other controls should call canonical extension commands");
|
|
26
|
+
assert.match(app, /aurReviewActionButton\("Approve", "approve", "primary"\)/, "Approve should delegate to the extension slash command, which owns native confirmation");
|
|
27
|
+
assert.match(app, /id: "aurReview"[\s\S]*packageName: "@firstpick\/pi-extension-aur-review"[\s\S]*capabilityLabel: "\/aur-review or aur-review:rpc widget event"/, "optional feature discovery should identify the companion by command or payload");
|
|
28
|
+
assert.match(app, /optionalFeatureAvailability\.aurReview = hasAvailableCommand\("aur-review"\)[\s\S]*widgets\.has\(AUR_REVIEW_RPC_WIDGET_KEY\)/, "feature availability should detect commands and replayed widget state");
|
|
29
|
+
assert.match(app, /if \(key === AUR_REVIEW_RPC_WIDGET_KEY\) return "aurReview"[\s\S]*key === AUR_REVIEW_RPC_WIDGET_KEY/, "generic widget fallback should be preserved while the AUR review payload gets a specialized renderer");
|
|
30
|
+
assert.match(css, /\.aur-review-widget \{[\s\S]*\.aur-review-actions[\s\S]*\.aur-review-file-list[\s\S]*@media \(max-width: 720px\)[\s\S]*\.aur-review-action,[\s\S]*\.aur-review-report/, "AUR review card should be styled responsively for desktop and mobile");
|
|
31
|
+
assert.equal(JSON.parse(pkg).optionalDependencies?.["@firstpick/pi-extension-aur-review"], undefined, "WebUI must not reference the unpublished review extension from clean npm installs");
|
|
32
|
+
assert.equal(JSON.parse(pkg).pi?.extensions?.some((entry) => String(entry).includes("pi-extension-aur-review")), false, "WebUI must not bundle an unpublished nested review extension path");
|
|
33
|
+
assert.match(server, /\["aurReview", "@firstpick\/pi-extension-aur-review"\]/, "optional-feature installer should retain the future/local review companion mapping");
|
|
34
|
+
assert.match(server, /"aur-review-payload\.mjs", "guided-git-command-state\.mjs", "guided-git-review-state\.mjs"/, "server must serve every browser module used by the review gate");
|
|
35
|
+
assert.match(server, /STAGED_CONTENT_HASH_DOMAIN = "firstpick\/aur-review\/staged-content\/v1\\0"[\s\S]*git diff --cached[\s\S]*\/api\/git-workflow\/staged-content/, "server must expose the bounded read-only staged-content hash helper");
|
|
36
|
+
assert.match(server, /async function getAurReviewReportContentData\(tab, \{ path: requestedPath = "", repoRoot = "" \} = \{\}\)[\s\S]*repoRoot !== root[\s\S]*lstat\(targetPath\)[\s\S]*isSymbolicLink\(\)[\s\S]*readBoundedAurReviewReport[\s\S]*\/api\/aur-review\/report-content/s, "server must bind report reads to the canonical Git root and reject symlinked paths through a dedicated read-only route");
|
|
37
|
+
assert.match(server, /entry\.name\.startsWith\("pi-"\)[\s\S]*packageNameForResourcePath\(path\.join\(candidate, "package\.json"\)\)/, "workspace optional-package discovery must recognize the pi-extension-aur-review sibling by manifest name");
|
|
38
|
+
console.log("aur review widget static tests passed");
|
|
@@ -12,7 +12,12 @@ const serverScript = join(root, "bin", "pi-webui.mjs");
|
|
|
12
12
|
const compactingPi = join(root, "tests", "fixtures", "compacting-pi.mjs");
|
|
13
13
|
const port = 30000 + Math.floor(Math.random() * 20000);
|
|
14
14
|
const COMPACTION_TRIGGER = "__pi_webui_test_start_compaction__";
|
|
15
|
+
const ABORTED_COMPACTION_TRIGGER = "__pi_webui_test_start_aborted_compaction__";
|
|
15
16
|
const RESUME_PROMPT = "resume automatically after compaction";
|
|
17
|
+
const STEER_PROMPT = "steer automatically after compaction";
|
|
18
|
+
const FOLLOW_UP_PROMPT = "follow up automatically after compaction";
|
|
19
|
+
const QUEUED_SLASH_PROMPT = "/queued-extension-command";
|
|
20
|
+
const ABORTED_RESUME_PROMPT = "resume automatically after aborted compaction";
|
|
16
21
|
|
|
17
22
|
async function request(pathname, { method = "GET", body, timeoutMs = 5_000 } = {}) {
|
|
18
23
|
const response = await fetch(`http://127.0.0.1:${port}${pathname}`, {
|
|
@@ -87,22 +92,69 @@ try {
|
|
|
87
92
|
assert.equal(queuedPrompt.body?.data?.queuedFor, "compaction");
|
|
88
93
|
assert.equal(queuedPrompt.body?.data?.queueLength, 1);
|
|
89
94
|
|
|
95
|
+
const queuedSteer = await request("/api/steer", {
|
|
96
|
+
method: "POST",
|
|
97
|
+
body: { tab: tabId, message: STEER_PROMPT },
|
|
98
|
+
});
|
|
99
|
+
assert.equal(queuedSteer.status, 202, "steer sent during compaction should be accepted into the Web UI resume queue");
|
|
100
|
+
assert.equal(queuedSteer.body?.data?.queueLength, 2);
|
|
101
|
+
|
|
102
|
+
const queuedFollowUp = await request("/api/follow-up", {
|
|
103
|
+
method: "POST",
|
|
104
|
+
body: { tab: tabId, message: FOLLOW_UP_PROMPT },
|
|
105
|
+
});
|
|
106
|
+
assert.equal(queuedFollowUp.status, 202, "follow-up sent during compaction should be accepted into the Web UI resume queue");
|
|
107
|
+
assert.equal(queuedFollowUp.body?.data?.queueLength, 3);
|
|
108
|
+
|
|
109
|
+
const queuedSlashPrompt = await request("/api/prompt", {
|
|
110
|
+
method: "POST",
|
|
111
|
+
body: { tab: tabId, message: QUEUED_SLASH_PROMPT, streamingBehavior: "followUp" },
|
|
112
|
+
});
|
|
113
|
+
assert.equal(queuedSlashPrompt.status, 202, "slash prompt sent during compaction should remain a prompt in the resume queue");
|
|
114
|
+
assert.equal(queuedSlashPrompt.body?.data?.queueLength, 4);
|
|
115
|
+
|
|
90
116
|
const messagesBeforeEnd = await request(`/api/messages?tab=${encodeURIComponent(tabId)}`);
|
|
91
117
|
assert.equal(messagesBeforeEnd.status, 200);
|
|
92
|
-
|
|
118
|
+
const queuedMessages = [RESUME_PROMPT, STEER_PROMPT, FOLLOW_UP_PROMPT, QUEUED_SLASH_PROMPT];
|
|
119
|
+
for (const message of queuedMessages) {
|
|
120
|
+
assert.equal((messagesBeforeEnd.body?.data?.messages || []).some((entry) => String(entry.content || "").includes(message)), false, "queued messages should not reach Pi before compaction_end");
|
|
121
|
+
}
|
|
93
122
|
|
|
94
123
|
await waitFor("compaction to finish", async () => {
|
|
95
124
|
const state = await request(`/api/state?tab=${encodeURIComponent(tabId)}`);
|
|
96
125
|
return state.body?.data?.isCompacting === false ? state : false;
|
|
97
126
|
}, { attempts: 80, intervalMs: 100 });
|
|
98
127
|
|
|
99
|
-
const resumedMessages = await waitFor("queued
|
|
128
|
+
const resumedMessages = await waitFor("queued prompts to resume after compaction", async () => {
|
|
100
129
|
const messages = await request(`/api/messages?tab=${encodeURIComponent(tabId)}`);
|
|
101
130
|
const entries = messages.body?.data?.messages || [];
|
|
102
|
-
|
|
131
|
+
const expected = [`prompt:${RESUME_PROMPT}`, `steer:${STEER_PROMPT}`, `follow_up:${FOLLOW_UP_PROMPT}`, `prompt:${QUEUED_SLASH_PROMPT}`];
|
|
132
|
+
return expected.every((content, index) => String(entries[index]?.content || "") === content) ? messages : false;
|
|
103
133
|
}, { attempts: 80, intervalMs: 100 });
|
|
104
134
|
assert.equal(resumedMessages.status, 200);
|
|
105
135
|
|
|
136
|
+
const startAbortedCompaction = await request("/api/prompt", {
|
|
137
|
+
method: "POST",
|
|
138
|
+
body: { tab: tabId, message: ABORTED_COMPACTION_TRIGGER },
|
|
139
|
+
});
|
|
140
|
+
assert.equal(startAbortedCompaction.status, 200);
|
|
141
|
+
await waitFor("aborted compaction_start state", async () => {
|
|
142
|
+
const state = await request(`/api/state?tab=${encodeURIComponent(tabId)}`);
|
|
143
|
+
return state.body?.data?.isCompacting === true ? state : false;
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
const queuedDuringAbortedCompaction = await request("/api/prompt", {
|
|
147
|
+
method: "POST",
|
|
148
|
+
body: { tab: tabId, message: ABORTED_RESUME_PROMPT, streamingBehavior: "steer" },
|
|
149
|
+
});
|
|
150
|
+
assert.equal(queuedDuringAbortedCompaction.status, 202);
|
|
151
|
+
|
|
152
|
+
await waitFor("queued prompt to resume after aborted compaction", async () => {
|
|
153
|
+
const messages = await request(`/api/messages?tab=${encodeURIComponent(tabId)}`);
|
|
154
|
+
const entries = messages.body?.data?.messages || [];
|
|
155
|
+
return entries.some((message) => String(message.content || "") === `prompt:${ABORTED_RESUME_PROMPT}`) ? messages : false;
|
|
156
|
+
}, { attempts: 80, intervalMs: 100 });
|
|
157
|
+
|
|
106
158
|
await request("/api/shutdown", { method: "POST" }).catch(() => undefined);
|
|
107
159
|
for (let attempt = 0; attempt < 50 && child.exitCode === null; attempt += 1) await delay(100);
|
|
108
160
|
assert.notEqual(child.exitCode, null, "server should exit after /api/shutdown");
|
|
@@ -12,10 +12,10 @@ const [server, app] = await Promise.all([
|
|
|
12
12
|
assert.match(server, /function maybeQueueCommandDuringCompaction\(tab, command\)[\s\S]*tab\?\.lastState\?\.isCompacting[\s\S]*enqueueCommandUntilCompactionEnds/, "server should queue prompt-like commands while the tab is compacting");
|
|
13
13
|
assert.match(server, /url\.pathname === "\/api\/prompt" && req\.method === "POST"[\s\S]*maybeQueueCommandDuringCompaction\(tab, command\)[\s\S]*sendJson\(res, 202/, "POST /api/prompt should return 202 when a prompt is queued for post-compaction resume");
|
|
14
14
|
assert.match(server, /if \(command\) \{[\s\S]*maybeQueueCommandDuringCompaction\(tab, command\)[\s\S]*sendJson\(res, 202/, "generic prompt-like POST commands should share the compaction queue path");
|
|
15
|
-
assert.match(server, /event\?\.type === "compaction_end"
|
|
16
|
-
assert.match(server, /async function flushCompactionQueue\(tab, event = \{\}\)[\s\S]*queuedRetryCommand\(item\)/, "compaction queue flush should
|
|
15
|
+
assert.match(server, /event\?\.type === "compaction_end"\)[\s\S]*flushCompactionQueue\(tab, event\)/, "every compaction_end should flush queued prompts instead of stranding them after an abort");
|
|
16
|
+
assert.match(server, /async function flushCompactionQueue\(tab, event = \{\}\)[\s\S]*queuedRetryCommand\(item\)/, "compaction queue flush should preserve steering, follow-up, and slash-command delivery when joining an active run");
|
|
17
17
|
assert.match(server, /async function flushCompactionQueue\(tab, event = \{\}\)[\s\S]*queuedPromptCommand\(item\)/, "compaction queue flush should start a new prompt when no run resumes automatically");
|
|
18
|
-
assert.match(server, /
|
|
18
|
+
assert.match(server, /function queuedRetryCommand\(item\)[\s\S]*queuedStreamingCommand\(item\)/, "post-compaction continuation should send later queued items as steering or follow-up messages");
|
|
19
19
|
assert.match(server, /function stateWithPendingThinking\(tab, state\)[\s\S]*compactionQueueForTab\(tab\)\.length[\s\S]*pendingMessageCount/, "state responses should include Web UI compaction queue length while prompts wait to resume");
|
|
20
20
|
|
|
21
21
|
assert.match(app, /function isRunActive\(\) \{\n\s+return !!currentState\?\.isStreaming \|\| !!currentState\?\.isCompacting/, "frontend should treat compaction as an active run for composer controls");
|