@firstpick/pi-package-webui 0.8.5 → 0.8.6
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 -1
- package/bin/pi-webui.mjs +375 -30
- package/index.ts +8 -1
- package/lib/git-workflow-preferences.mjs +3 -0
- package/lib/session-summary-core.mjs +4 -3
- package/lib/trust-boundaries.mjs +13 -0
- package/lib/workspace-session-summaries.mjs +400 -0
- package/package.json +2 -2
- package/public/app.js +1197 -267
- package/public/index.html +76 -3
- package/public/service-worker.js +3 -1
- package/public/stream-output-controller.mjs +327 -0
- package/public/styles.css +249 -70
- package/public/theme-contract.mjs +244 -0
- package/session-summary.ts +164 -4
- package/tests/aur-review-widget-static.test.mjs +2 -1
- package/tests/browser/interaction-continuity.spec.mjs +2 -2
- package/tests/browser/session-summary.spec.mjs +131 -3
- package/tests/browser/stream-output-isolation.spec.mjs +510 -0
- package/tests/codex-fast-mode-static.test.mjs +1 -1
- package/tests/composer-action-grid-reorder-static.test.mjs +1 -1
- package/tests/fast-mode-client-static.test.mjs +2 -1
- package/tests/fixtures/fake-pi.mjs +203 -2
- package/tests/git-workflow-preferences.test.mjs +7 -1
- package/tests/guided-git-aur-review.test.mjs +4 -3
- package/tests/http-endpoints-harness.test.mjs +207 -6
- package/tests/mobile-continuity-tablet-static.test.mjs +1 -1
- package/tests/mobile-foundation-static.test.mjs +2 -3
- package/tests/mobile-phone-experience-static.test.mjs +1 -1
- package/tests/mobile-static.test.mjs +62 -29
- package/tests/native-parity.test.mjs +1 -1
- package/tests/open-issue-wizard-static.test.mjs +2 -3
- package/tests/persistent-ui-layout-static.test.mjs +1 -1
- package/tests/questionnaire-dialog.test.mjs +1 -1
- package/tests/remote-auth-settings-harness.test.mjs +9 -0
- package/tests/session-summary-core.test.mjs +183 -1
- package/tests/side-panel-section-reorder-static.test.mjs +1 -1
- package/tests/stream-lifecycle-core.test.mjs +134 -0
- package/tests/stream-output-controller.test.mjs +252 -0
- package/tests/stream-output-isolation-static.test.mjs +89 -0
- package/tests/streaming-ui-coupling.test.mjs +50 -0
- package/tests/subagent-gate-visibility.test.mjs +1 -1
- package/tests/subagent-launch-slots-static.test.mjs +1 -1
- package/tests/theme-contract.test.mjs +104 -0
- package/tests/theme-customizer-static.test.mjs +82 -0
- package/tests/theme-scheme-mode.test.mjs +15 -0
- package/tests/workspace-session-summaries.test.mjs +288 -0
|
@@ -50,6 +50,7 @@ const continuityModeEnabled = process.env.FAKE_PI_CONTINUITY_MODE === "1";
|
|
|
50
50
|
const largePayloadsEnabled = process.env.FAKE_PI_LARGE_PAYLOADS === "1";
|
|
51
51
|
const sseFloodEnabled = process.env.FAKE_PI_SSE_FLOOD === "1";
|
|
52
52
|
const statsPromptContextEnabled = process.env.FAKE_PI_STATS_PROMPT_CONTEXT === "1";
|
|
53
|
+
const streamIsolationEnabled = process.env.FAKE_PI_STREAM_ISOLATION === "1";
|
|
53
54
|
const commandLogFile = process.env.FAKE_PI_LOG_FILE || "";
|
|
54
55
|
const largeRpcText = "large-rpc-payload:" + "λ".repeat(70_000);
|
|
55
56
|
const largeTokenSamples = Array.from({ length: 300 }, (_, index) => ({ index, input: index + 1, output: index + 2 }));
|
|
@@ -63,6 +64,8 @@ const dynamicMessages = [];
|
|
|
63
64
|
let dynamicLeafId = "u0000002";
|
|
64
65
|
let scriptedStreaming = false;
|
|
65
66
|
let continuityRun = 0;
|
|
67
|
+
let streamIsolationRun = 0;
|
|
68
|
+
const pendingStreamIsolationRuns = new Map();
|
|
66
69
|
let largeTranscriptEnabled = false;
|
|
67
70
|
const fixtureSubagentRuns = [];
|
|
68
71
|
const fixtureSubagentGates = [];
|
|
@@ -203,7 +206,16 @@ function emitEvent(payload) {
|
|
|
203
206
|
}
|
|
204
207
|
|
|
205
208
|
function emitScriptedEvent(payload) {
|
|
206
|
-
logJsonLine({
|
|
209
|
+
logJsonLine({
|
|
210
|
+
direction: "event",
|
|
211
|
+
type: payload.type,
|
|
212
|
+
...(payload.toolName ? { toolName: payload.toolName } : {}),
|
|
213
|
+
...(payload.assistantMessageEvent?.type ? { assistantMessageEventType: payload.assistantMessageEvent.type } : {}),
|
|
214
|
+
...(payload.isolationRunId ? { isolationRunId: payload.isolationRunId } : {}),
|
|
215
|
+
...(payload.isolationMode ? { isolationMode: payload.isolationMode } : {}),
|
|
216
|
+
...(payload.isolationPhase ? { isolationPhase: payload.isolationPhase } : {}),
|
|
217
|
+
...(Number.isInteger(payload.isolationDeltaIndex) ? { isolationDeltaIndex: payload.isolationDeltaIndex } : {}),
|
|
218
|
+
});
|
|
207
219
|
emitEvent(payload);
|
|
208
220
|
}
|
|
209
221
|
|
|
@@ -773,6 +785,181 @@ function handleFastModeFixturePrompt(command, base) {
|
|
|
773
785
|
return true;
|
|
774
786
|
}
|
|
775
787
|
|
|
788
|
+
function streamIsolationTextDelta(index) {
|
|
789
|
+
const digit = String(index % 10);
|
|
790
|
+
if (index === 0) return `ISOLATION-TEXT-BEGIN ${digit}`;
|
|
791
|
+
if (index === 999) return `${digit} ISOLATION-TEXT-TAIL`;
|
|
792
|
+
return digit;
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
function logStreamIsolationPhase(runId, mode, scenario, phase) {
|
|
796
|
+
logJsonLine({ direction: "isolation-phase", isolationRunId: runId, isolationMode: mode, isolationScenario: scenario, isolationPhase: phase });
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
function runStreamIsolationFixtureFlow(mode, scenario = "standard") {
|
|
800
|
+
const runId = `stream-isolation-${mode}-${scenario}-${++streamIsolationRun}`;
|
|
801
|
+
const toolCallId = `${runId}-execution`;
|
|
802
|
+
const streamedToolCallId = `${runId}-call`;
|
|
803
|
+
const textDeltas = Array.from({ length: 1_000 }, (_, index) => streamIsolationTextDelta(index));
|
|
804
|
+
const finalText = textDeltas.join("");
|
|
805
|
+
const thinkingText = "ISOLATION-THINKING-PATH";
|
|
806
|
+
const toolCall = { type: "toolCall", id: streamedToolCallId, name: "read", arguments: { path: "isolation.txt" } };
|
|
807
|
+
const tagged = (payload, phase) => ({
|
|
808
|
+
...payload,
|
|
809
|
+
isolationRunId: runId,
|
|
810
|
+
isolationMode: mode,
|
|
811
|
+
isolationScenario: scenario,
|
|
812
|
+
isolationPhase: phase,
|
|
813
|
+
});
|
|
814
|
+
const emitTextRange = (start, end, { finish = false } = {}) => {
|
|
815
|
+
if (start === 0) emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "text_start", contentIndex: 1 } }, "raw"));
|
|
816
|
+
for (let index = start; index < end; index += 1) {
|
|
817
|
+
emitScriptedEvent({
|
|
818
|
+
...tagged({ type: "message_update", assistantMessageEvent: { type: "text_delta", contentIndex: 1, delta: textDeltas[index] } }, "raw"),
|
|
819
|
+
isolationDeltaIndex: index,
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
if (finish) emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "text_end", contentIndex: 1, text: finalText } }, "raw"));
|
|
823
|
+
};
|
|
824
|
+
|
|
825
|
+
scriptedStreaming = true;
|
|
826
|
+
const preburstStep = {
|
|
827
|
+
afterMs: 25,
|
|
828
|
+
run: () => {
|
|
829
|
+
emitScriptedEvent(tagged({ type: "agent_start" }, "pre-burst"));
|
|
830
|
+
if (mode === "compact") {
|
|
831
|
+
emitScriptedEvent(tagged({ type: "message_start", message: { role: "assistant" } }, "pre-burst"));
|
|
832
|
+
emitScriptedEvent(tagged({ type: "tool_execution_start", toolCallId, toolName: "read", args: { path: "isolation.txt" } }, "pre-burst"));
|
|
833
|
+
} else {
|
|
834
|
+
emitScriptedEvent(tagged({ type: "tool_execution_start", toolCallId, toolName: "read", args: { path: "isolation.txt" } }, "pre-burst"));
|
|
835
|
+
emitScriptedEvent(tagged({ type: "message_start", message: { role: "assistant" } }, "pre-burst"));
|
|
836
|
+
}
|
|
837
|
+
logStreamIsolationPhase(runId, mode, scenario, "ready");
|
|
838
|
+
},
|
|
839
|
+
};
|
|
840
|
+
const steps = [
|
|
841
|
+
{
|
|
842
|
+
afterMs: 0,
|
|
843
|
+
run: () => {
|
|
844
|
+
logStreamIsolationPhase(runId, mode, scenario, "raw-start");
|
|
845
|
+
emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "thinking_start" } }, "raw"));
|
|
846
|
+
emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "thinking_delta", delta: thinkingText } }, "raw"));
|
|
847
|
+
emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "thinking_end", delta: thinkingText } }, "raw"));
|
|
848
|
+
},
|
|
849
|
+
},
|
|
850
|
+
{
|
|
851
|
+
afterMs: 100,
|
|
852
|
+
run: () => {
|
|
853
|
+
if (scenario === "abort") {
|
|
854
|
+
emitTextRange(0, 500);
|
|
855
|
+
logStreamIsolationPhase(runId, mode, scenario, "abort-ready");
|
|
856
|
+
} else {
|
|
857
|
+
emitTextRange(0, 1_000, { finish: true });
|
|
858
|
+
logStreamIsolationPhase(runId, mode, scenario, "text-complete");
|
|
859
|
+
}
|
|
860
|
+
},
|
|
861
|
+
},
|
|
862
|
+
];
|
|
863
|
+
|
|
864
|
+
if (scenario === "abort") {
|
|
865
|
+
// Keep a deterministic partial stream pending long enough for the browser
|
|
866
|
+
// proof to inspect it and issue Abort; cancelScriptedSteps() must prevent
|
|
867
|
+
// this fallback tail from ever being emitted after cancellation.
|
|
868
|
+
steps.push({ afterMs: 30_000, run: () => emitTextRange(500, 1_000, { finish: true }) });
|
|
869
|
+
}
|
|
870
|
+
const completionSteps = [];
|
|
871
|
+
steps.push(
|
|
872
|
+
{
|
|
873
|
+
afterMs: 1_500,
|
|
874
|
+
run: () => {
|
|
875
|
+
emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "toolcall_start", contentIndex: 2, name: "read", toolCall: { ...toolCall, arguments: undefined } } }, "raw"));
|
|
876
|
+
emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "toolcall_delta", contentIndex: 2, name: "read", toolCall: { ...toolCall, arguments: undefined }, delta: "{\"path\":\"isolation.txt\"}" } }, "raw"));
|
|
877
|
+
emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "toolcall_end", contentIndex: 2, name: "read", toolCall } }, "raw"));
|
|
878
|
+
},
|
|
879
|
+
},
|
|
880
|
+
{
|
|
881
|
+
afterMs: 100,
|
|
882
|
+
run: () => {
|
|
883
|
+
emitScriptedEvent(tagged({
|
|
884
|
+
type: "tool_execution_update",
|
|
885
|
+
toolCallId,
|
|
886
|
+
toolName: "read",
|
|
887
|
+
partialResult: { content: [{ type: "text", text: "ISOLATION-TOOL-UPDATE-COMPLETE" }] },
|
|
888
|
+
}, "raw"));
|
|
889
|
+
if (scenario === "lifecycle") {
|
|
890
|
+
pendingStreamIsolationRuns.set(runId, () => {
|
|
891
|
+
pendingStreamIsolationRuns.delete(runId);
|
|
892
|
+
runScriptedSteps(completionSteps);
|
|
893
|
+
});
|
|
894
|
+
}
|
|
895
|
+
logStreamIsolationPhase(runId, mode, scenario, "raw-end");
|
|
896
|
+
},
|
|
897
|
+
},
|
|
898
|
+
);
|
|
899
|
+
if (scenario === "lifecycle") {
|
|
900
|
+
completionSteps.push({
|
|
901
|
+
afterMs: 0,
|
|
902
|
+
run: () => {
|
|
903
|
+
emitScriptedEvent(tagged({ type: "auto_retry_start", attempt: 1, maxAttempts: 2, delayMs: 10, errorMessage: "fixture retry" }, "semantic"));
|
|
904
|
+
emitScriptedEvent(tagged({ type: "auto_retry_end", attempt: 1, success: true }, "semantic"));
|
|
905
|
+
emitScriptedEvent(tagged({ type: "compaction_start", reason: "fixture" }, "semantic"));
|
|
906
|
+
emitScriptedEvent(tagged({ type: "compaction_end", aborted: false }, "semantic"));
|
|
907
|
+
emitScriptedEvent(tagged({ type: "webui_supervisor_reconnected", supervisorScopeId: runId, supervisorEpoch: "1", supervisorSeq: "1" }, "semantic"));
|
|
908
|
+
logStreamIsolationPhase(runId, mode, scenario, "lifecycle-complete");
|
|
909
|
+
},
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
completionSteps.push(
|
|
913
|
+
{
|
|
914
|
+
afterMs: 1_200,
|
|
915
|
+
run: () => {
|
|
916
|
+
emitScriptedEvent(tagged({ type: "tool_execution_end", toolCallId, toolName: "read", isError: false, result: { content: [{ type: "text", text: "ISOLATION-TOOL-RESULT" }] } }, "post-burst"));
|
|
917
|
+
logStreamIsolationPhase(runId, mode, scenario, "tool-complete");
|
|
918
|
+
},
|
|
919
|
+
},
|
|
920
|
+
{
|
|
921
|
+
afterMs: 500,
|
|
922
|
+
run: () => {
|
|
923
|
+
const message = {
|
|
924
|
+
role: "assistant",
|
|
925
|
+
content: [{ type: "thinking", thinking: thinkingText }, toolCall, { type: "text", text: finalText }],
|
|
926
|
+
timestamp: Date.now(),
|
|
927
|
+
};
|
|
928
|
+
appendDynamicMessage(message);
|
|
929
|
+
emitScriptedEvent(tagged({ type: "message_end", message }, "post-burst"));
|
|
930
|
+
emitScriptedEvent(tagged({ type: "agent_end" }, "post-burst"));
|
|
931
|
+
scriptedStreaming = false;
|
|
932
|
+
emitScriptedEvent(tagged({ type: "agent_settled" }, "post-burst"));
|
|
933
|
+
logStreamIsolationPhase(runId, mode, scenario, "settled");
|
|
934
|
+
},
|
|
935
|
+
},
|
|
936
|
+
);
|
|
937
|
+
runScriptedSteps([preburstStep]);
|
|
938
|
+
pendingStreamIsolationRuns.set(runId, () => {
|
|
939
|
+
pendingStreamIsolationRuns.delete(runId);
|
|
940
|
+
runScriptedSteps(scenario === "lifecycle" ? steps : [...steps, ...completionSteps]);
|
|
941
|
+
});
|
|
942
|
+
return { runId, finalText };
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
function continueStreamIsolationFixture(runId) {
|
|
946
|
+
const start = pendingStreamIsolationRuns.get(runId);
|
|
947
|
+
if (!start) return false;
|
|
948
|
+
start();
|
|
949
|
+
return true;
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
function handleStreamIsolationFixturePrompt(command, base) {
|
|
953
|
+
if (!streamIsolationEnabled) return false;
|
|
954
|
+
const match = String(command.message || "").trim().match(/^fixture stream isolation (normal|compact)(?: (standard|abort|lifecycle))?$/);
|
|
955
|
+
if (!match) return false;
|
|
956
|
+
const mode = match[1];
|
|
957
|
+
const scenario = match[2] || "standard";
|
|
958
|
+
const { runId, finalText } = runStreamIsolationFixtureFlow(mode, scenario);
|
|
959
|
+
respond({ ...base, data: { output: "stream isolation fixture accepted", runId, deltaCount: 1_000, mode, scenario, finalText } });
|
|
960
|
+
return true;
|
|
961
|
+
}
|
|
962
|
+
|
|
776
963
|
function handleTransportFixturePrompt(command, base) {
|
|
777
964
|
const message = String(command.message || "").trim();
|
|
778
965
|
if (message === "fixture stderr diagnostic") {
|
|
@@ -1163,6 +1350,7 @@ rl.on("line", (line) => {
|
|
|
1163
1350
|
if (handleStatsPromptContextFixturePrompt(command, base)) return;
|
|
1164
1351
|
if (handleWebuiHelperPrompt(command, base)) return;
|
|
1165
1352
|
if (handleFastModeFixturePrompt(command, base)) return;
|
|
1353
|
+
if (handleStreamIsolationFixturePrompt(command, base)) return;
|
|
1166
1354
|
if (handleTransportFixturePrompt(command, base)) return;
|
|
1167
1355
|
if (handleSubagentFixturePrompt(command, base)) return;
|
|
1168
1356
|
if (handleDocumentArtifactFixturePrompt(command, base)) return;
|
|
@@ -1177,9 +1365,22 @@ rl.on("line", (line) => {
|
|
|
1177
1365
|
if (handleVoiceScriptPrompt(command, base)) return;
|
|
1178
1366
|
respond({ ...base, data: { output: "fake prompt accepted" } });
|
|
1179
1367
|
return;
|
|
1180
|
-
case "steer":
|
|
1368
|
+
case "steer": {
|
|
1369
|
+
const match = String(command.message || "").trim().match(/^fixture stream isolation continue (stream-isolation-[A-Za-z0-9-]+)$/);
|
|
1370
|
+
if (match && continueStreamIsolationFixture(match[1])) {
|
|
1371
|
+
respond({ ...base, data: { output: "stream isolation raw phase started" } });
|
|
1372
|
+
return;
|
|
1373
|
+
}
|
|
1181
1374
|
respond({ ...base, data: { output: "fake steer accepted" } });
|
|
1182
1375
|
return;
|
|
1376
|
+
}
|
|
1377
|
+
case "abort":
|
|
1378
|
+
cancelScriptedSteps();
|
|
1379
|
+
respond({ ...base, data: { output: "fake abort accepted" } });
|
|
1380
|
+
emitScriptedEvent({ type: "agent_end", aborted: true });
|
|
1381
|
+
scriptedStreaming = false;
|
|
1382
|
+
emitScriptedEvent({ type: "agent_settled", aborted: true });
|
|
1383
|
+
return;
|
|
1183
1384
|
case "set_thinking_level":
|
|
1184
1385
|
thinkingLevel = String(command.level || "off");
|
|
1185
1386
|
respond({ ...base, data: { level: thinkingLevel } });
|
|
@@ -43,6 +43,7 @@ try {
|
|
|
43
43
|
assert.equal(migrated.resourceDefaults.tools.enabledTools, null, "legacy settings should inherit Pi's normal tool defaults");
|
|
44
44
|
assert.equal(migrated.resourceDefaults.skills.enabledSkills, null, "legacy settings should inherit Pi's normal skill defaults");
|
|
45
45
|
assert.equal(migrated.gitWorkflow.stagingPolicy, "review");
|
|
46
|
+
assert.equal(migrated.gitWorkflow.reviewProcessEnabled, true, "legacy settings should preserve the existing review-process behavior");
|
|
46
47
|
assert.equal(migrated.gitWorkflow.generation.thinkingLevel, "low");
|
|
47
48
|
assert.equal(migrated.uiLayout.version, 1);
|
|
48
49
|
assert.equal(migrated.uiLayout.sidePanel.sectionOrder, null);
|
|
@@ -54,6 +55,7 @@ try {
|
|
|
54
55
|
generation: { provider: "fake", modelId: "fake-model", thinkingLevel: "off", unavailablePolicy: "ask" },
|
|
55
56
|
commit: { language: "de", defaultVariant: "long", scope: "required" },
|
|
56
57
|
stagingPolicy: "preserve",
|
|
58
|
+
reviewProcessEnabled: false,
|
|
57
59
|
deliveryMode: "pr-worktree",
|
|
58
60
|
verificationPolicy: "none",
|
|
59
61
|
}, settingsFile);
|
|
@@ -62,6 +64,7 @@ try {
|
|
|
62
64
|
assert.equal(saved.commit.language, "de");
|
|
63
65
|
assert.equal(saved.commit.defaultVariant, "long");
|
|
64
66
|
assert.equal(saved.stagingPolicy, "preserve");
|
|
67
|
+
assert.equal(saved.reviewProcessEnabled, false);
|
|
65
68
|
|
|
66
69
|
await writeWebuiSettings({
|
|
67
70
|
outputModeDefault: "compact-v1",
|
|
@@ -76,6 +79,7 @@ try {
|
|
|
76
79
|
assert.equal(partiallyUpdated.generation.modelId, "fake-model", "partial updates should preserve the selected model");
|
|
77
80
|
assert.equal(partiallyUpdated.commit.language, "de", "partial updates should preserve nested commit preferences");
|
|
78
81
|
assert.equal(partiallyUpdated.deliveryMode, "current");
|
|
82
|
+
assert.equal(partiallyUpdated.reviewProcessEnabled, false, "partial updates should preserve the review-process choice");
|
|
79
83
|
|
|
80
84
|
const persisted = JSON.parse(await readFile(settingsFile, "utf8"));
|
|
81
85
|
assert.equal(persisted.version, 6);
|
|
@@ -86,7 +90,9 @@ try {
|
|
|
86
90
|
assert.deepEqual(persisted.resourceDefaults.skills.enabledSkills, ["repo-explorer", "code-security"], "global skill defaults should persist beside other Web UI settings");
|
|
87
91
|
assert.equal(persisted.interfacePreferences.sidePanelWidth, 612, "the user-scoped Control Deck width should persist beside other Web UI settings");
|
|
88
92
|
assert.equal((await readWebuiSettings(settingsFile)).interfacePreferences.sidePanelWidth, 612);
|
|
89
|
-
|
|
93
|
+
const summary = gitWorkflowPreferencesSummary(await readGitWorkflowPreferences(settingsFile));
|
|
94
|
+
assert.match(summary, /fake\/fake-model/);
|
|
95
|
+
assert.match(summary, /Review process: disabled/);
|
|
90
96
|
if (process.platform !== "win32") assert.equal((await stat(settingsFile)).mode & 0o777, 0o600);
|
|
91
97
|
|
|
92
98
|
console.log("git-workflow-preferences.test.mjs passed");
|
|
@@ -148,8 +148,8 @@ assert.equal(resolveRpcSlashCommandForTabCatalog(catalogByTab.get("tab-b"), "/au
|
|
|
148
148
|
|
|
149
149
|
const runGitAdd = app.slice(app.indexOf("async function runGitAdd"), app.indexOf("async function acceptCurrentGitStaging"));
|
|
150
150
|
const acceptStaging = app.slice(app.indexOf("async function acceptCurrentGitStaging"), app.indexOf("async function loadGitWorkflowDefaultCommitMessage"));
|
|
151
|
-
assert.match(runGitAdd, /guidedGitReviewAvailable\(tabId\)
|
|
152
|
-
assert.match(acceptStaging, /guidedGitReviewAvailable\(tabId\)
|
|
151
|
+
assert.match(runGitAdd, /workflow\.preferences\?\.reviewProcessEnabled !== false && guidedGitReviewAvailable\(tabId\)[\s\S]*\|\| workflow\.guidedReviewRequired === true[\s\S]*await requestGuidedGitReview\(tabId, \{ output \}\)/s, "git add . must honor the saved review-process option while keeping an already-required gate fail-closed");
|
|
152
|
+
assert.match(acceptStaging, /workflow\.preferences\?\.reviewProcessEnabled !== false && guidedGitReviewAvailable\(tabId\)[\s\S]*\|\| workflow\.guidedReviewRequired === true[\s\S]*await requestGuidedGitReview\(tabId, \{ output \}\)/s, "accepting a staged set must honor the saved review-process option while keeping an already-required gate fail-closed");
|
|
153
153
|
const reconcileReview = app.slice(app.indexOf("function reconcileGuidedGitReviewPayload"), app.indexOf("async function startGitWorkflow"));
|
|
154
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
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");
|
|
@@ -158,12 +158,13 @@ assert.match(reconcileReview, /function reconcileGuidedGitReviewWidgetRemoval[\s
|
|
|
158
158
|
const resetReviewToStaging = app.slice(app.indexOf("function resetGuidedGitReviewToStaging"), app.indexOf("function reconcileGuidedGitReviewPayload"));
|
|
159
159
|
assert.match(resetReviewToStaging, /step: "add"[\s\S]*stage: false/s, "decline and close return the flow to staging and require restaging");
|
|
160
160
|
const workflowRender = app.slice(app.indexOf("function renderGitWorkflow"), app.indexOf("async function gitWorkflowRequest"));
|
|
161
|
+
assert.match(workflowRender, /preferences\.reviewProcessEnabled !== false && guidedGitReviewAvailable\(activeTabId\)[\s\S]*\|\| gitWorkflow\.guidedReviewRequired === true/, "the Review process should be shown only when enabled and available, while an active required gate remains visible");
|
|
161
162
|
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
163
|
const processSelection = app.slice(app.indexOf("function selectGitWorkflowProcess"), app.indexOf("function gitWorkflowTitle"));
|
|
163
164
|
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
165
|
assert.doesNotMatch(processSelection, /resetGuidedGitReviewPatch/, "process selection must not share a reset that drops an approved binding during later navigation");
|
|
165
166
|
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(startWorkflow, /guidedReviewRequired: preferences\.reviewProcessEnabled !== false && guidedGitReviewAvailable\(tabId\)/, "a fresh standard flow must require review only when setup enables it and aur-review is available in its originating tab");
|
|
167
168
|
assert.match(app, /function guidedGitReviewAvailable\(tabId = activeTabId\)[\s\S]*commandCatalogForTab\(tabId\)/, "Guided Git availability must read the originating tab catalog");
|
|
168
169
|
assert.match(app, /resolveRpcSlashCommandMessage\(guidedGitReviewCommand\(\), \{ tabId \}\)/, "Guided Git review requests must resolve aliases from the originating tab catalog");
|
|
169
170
|
assert.match(app, /message = resolveRpcSlashCommandMessage\(message, \{ tabId: targetTabId \}\)/, "generic targeted slash-command dispatch must resolve aliases from its captured target tab");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import { spawn, spawnSync } from "node:child_process";
|
|
3
3
|
import { createServer } from "node:http";
|
|
4
|
-
import { chmod, link, mkdir, mkdtemp, readFile, rename, rm, stat, symlink, writeFile } from "node:fs/promises";
|
|
4
|
+
import { chmod, link, mkdir, mkdtemp, readFile, readdir, rename, rm, stat, symlink, writeFile } from "node:fs/promises";
|
|
5
5
|
import { networkInterfaces, tmpdir } from "node:os";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import { setTimeout as delay } from "node:timers/promises";
|
|
@@ -9,6 +9,7 @@ import { dirname, join } from "node:path";
|
|
|
9
9
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
10
10
|
import { terminateProcessTree } from "../lib/process-tree.mjs";
|
|
11
11
|
import { readSupervisorState, supervisorPaths, supervisorPidIsAlive } from "../lib/rpc-supervisor-state.mjs";
|
|
12
|
+
import { REQUIRED_THEME_TOKENS, serializeTheme } from "../public/theme-contract.mjs";
|
|
12
13
|
|
|
13
14
|
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
14
15
|
const serverScript = join(root, "bin", "pi-webui.mjs");
|
|
@@ -16,6 +17,14 @@ const fakePi = join(root, "tests", "fixtures", "fake-pi.mjs");
|
|
|
16
17
|
const port = 30000 + Math.floor(Math.random() * 20000);
|
|
17
18
|
const optionalFeatureFocus = process.env.PI_WEBUI_OPTIONAL_FEATURES_FOCUS === "1";
|
|
18
19
|
|
|
20
|
+
function themeFixture(name, color = "#123456") {
|
|
21
|
+
return {
|
|
22
|
+
name,
|
|
23
|
+
colors: Object.fromEntries(REQUIRED_THEME_TOKENS.map((token) => [token, color])),
|
|
24
|
+
export: { pageBg: color, cardBg: color, infoBg: color },
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
19
28
|
function lanAddress() {
|
|
20
29
|
for (const entries of Object.values(networkInterfaces())) {
|
|
21
30
|
for (const entry of entries || []) {
|
|
@@ -121,6 +130,8 @@ const cwd = await mkdtemp(path.join(tmpdir(), "pi-webui-http-harness-"));
|
|
|
121
130
|
const harnessSideEffectsRoot = await mkdtemp(path.join(tmpdir(), "pi-webui-http-harness-side-effects-"));
|
|
122
131
|
const settingsFile = path.join(harnessSideEffectsRoot, "webui-settings.json");
|
|
123
132
|
const workflowPolicyAgentDir = path.join(harnessSideEffectsRoot, "agent");
|
|
133
|
+
const managedThemePackageRoot = path.join(workflowPolicyAgentDir, "npm", "node_modules", "@firstpick", "pi-themes-bundle");
|
|
134
|
+
const managedThemeDir = path.join(managedThemePackageRoot, "themes");
|
|
124
135
|
const workflowPolicyFile = path.join(workflowPolicyAgentDir, "workflow-policy.json");
|
|
125
136
|
const sessionSummaryConfigFile = path.join(workflowPolicyAgentDir, "session-summary.json");
|
|
126
137
|
const canonicalWorkflowPolicySuggestions = {
|
|
@@ -140,6 +151,10 @@ await mkdir(artifactDir, { recursive: true });
|
|
|
140
151
|
await writeFile(artifactDownload, Buffer.from("fixture docx download bytes"));
|
|
141
152
|
await writeFile(artifactPage, Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]));
|
|
142
153
|
await writeFile(artifactManifest, JSON.stringify({ artifact: { schema: "pi.artifact/v1", kind: "document", id: "fixture-document-artifact", revisionId: "fixture-revision", title: "fixture.docx", mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", pageCount: 1, manifestPath: artifactManifest, downloadPath: artifactDownload, expiresAt: artifactExpiresAt }, sourcePath: "/private/source.docx", sourceSha256: "a".repeat(64), renderer: { engine: "fixture" }, pages: [{ pageNum: 1, width: 10, height: 20, outputPath: artifactPage }], warnings: [] }));
|
|
154
|
+
await mkdir(managedThemeDir, { recursive: true });
|
|
155
|
+
await writeFile(path.join(managedThemePackageRoot, "package.json"), JSON.stringify({ name: "@firstpick/pi-themes-bundle", version: "0.0.0-test", pi: { themes: ["./themes"] } }));
|
|
156
|
+
await writeFile(path.join(managedThemeDir, "managed-fixture.json"), serializeTheme(themeFixture("managed-fixture")));
|
|
157
|
+
await writeFile(path.join(workflowPolicyAgentDir, "trust.json"), `${JSON.stringify({ [cwd]: true }, null, 2)}\n`);
|
|
143
158
|
await chmod(fakePi, 0o755);
|
|
144
159
|
await mkdir(fakeOpenBinDir, { recursive: true });
|
|
145
160
|
await writeFile(openCommandScript, `#!/usr/bin/env node\nimport { appendFile } from "node:fs/promises";\nawait appendFile(process.env.PI_WEBUI_OPEN_LOG, "custom-open\\t" + process.argv.slice(2).join("\\t") + "\\n", "utf8");\n`, "utf8");
|
|
@@ -441,6 +456,188 @@ try {
|
|
|
441
456
|
assert.equal(health.body.piRunning, true, "fake pi RPC process should be attached and running");
|
|
442
457
|
assert.match(health.body.piVersion, /^\d+\.\d+\.\d+/, "health metadata should expose the installed Pi version");
|
|
443
458
|
|
|
459
|
+
const managedThemesResponse = await request("127.0.0.1", "/api/themes");
|
|
460
|
+
assert.equal(managedThemesResponse.status, 200, managedThemesResponse.body?.error);
|
|
461
|
+
assert.equal(managedThemesResponse.body?.data?.source, "@firstpick/pi-themes-bundle");
|
|
462
|
+
assert.deepEqual(managedThemesResponse.body?.data?.themes?.map(({ name }) => name), ["managed-fixture"], "themes installed only under PI_CODING_AGENT_DIR/npm/node_modules should be exposed to the browser");
|
|
463
|
+
assert.equal(managedThemesResponse.body?.data?.themes?.[0]?.colors?.accent, "#123456");
|
|
464
|
+
assert.equal(managedThemesResponse.body?.data?.themes?.[0]?.scope, "bundled");
|
|
465
|
+
|
|
466
|
+
const themeTabs = await request("127.0.0.1", "/api/tabs");
|
|
467
|
+
const themeTabId = themeTabs.body?.data?.tabs?.[0]?.id;
|
|
468
|
+
assert.ok(themeTabId, "custom theme endpoint checks require the startup tab");
|
|
469
|
+
const customThemePath = `/api/themes/custom?tab=${encodeURIComponent(themeTabId)}`;
|
|
470
|
+
const globalTheme = themeFixture("global-fixture", "#224466");
|
|
471
|
+
const createdGlobalTheme = await request("127.0.0.1", customThemePath, {
|
|
472
|
+
method: "POST",
|
|
473
|
+
body: { scope: "global", fileName: "global-fixture.json", theme: globalTheme, overwrite: false, expectedMtimeMs: null },
|
|
474
|
+
});
|
|
475
|
+
assert.equal(createdGlobalTheme.status, 201, createdGlobalTheme.body?.error);
|
|
476
|
+
assert.deepEqual({ created: createdGlobalTheme.body?.data?.created, overwritten: createdGlobalTheme.body?.data?.overwritten }, { created: true, overwritten: false });
|
|
477
|
+
assert.equal(Object.hasOwn(createdGlobalTheme.body?.data || {}, "path"), false, "theme save responses must not disclose host paths");
|
|
478
|
+
const globalThemeFile = path.join(workflowPolicyAgentDir, "themes", "global-fixture.json");
|
|
479
|
+
assert.equal(await readFile(globalThemeFile, "utf8"), serializeTheme(globalTheme), "global themes must use canonical Pi JSON bytes");
|
|
480
|
+
assert.equal((await stat(globalThemeFile)).mode & 0o777, 0o600, "saved themes must have private permissions");
|
|
481
|
+
|
|
482
|
+
const projectTheme = themeFixture("project-fixture", "#335577");
|
|
483
|
+
const createdProjectTheme = await request("127.0.0.1", customThemePath, {
|
|
484
|
+
method: "POST",
|
|
485
|
+
headers: { "Sec-Fetch-Site": "same-site" },
|
|
486
|
+
body: { scope: "project", fileName: "project-fixture.json", theme: projectTheme, overwrite: false, expectedMtimeMs: null },
|
|
487
|
+
});
|
|
488
|
+
assert.equal(createdProjectTheme.status, 201, createdProjectTheme.body?.error);
|
|
489
|
+
assert.equal(await readFile(path.join(cwd, ".pi", "themes", "project-fixture.json"), "utf8"), serializeTheme(projectTheme));
|
|
490
|
+
|
|
491
|
+
const customCatalog = await request("127.0.0.1", `/api/themes?tab=${encodeURIComponent(themeTabId)}`);
|
|
492
|
+
assert.equal(customCatalog.status, 200);
|
|
493
|
+
assert.deepEqual(customCatalog.body?.data?.themes?.map(({ name }) => name), ["managed-fixture", "global-fixture", "project-fixture"]);
|
|
494
|
+
assert.deepEqual(customCatalog.body?.data?.themes?.map(({ scope }) => scope), ["bundled", "global", "project"]);
|
|
495
|
+
assert.equal(customCatalog.body?.data?.scopes?.project?.trusted, true);
|
|
496
|
+
|
|
497
|
+
const bundledCollision = await request("127.0.0.1", customThemePath, {
|
|
498
|
+
method: "POST",
|
|
499
|
+
body: { scope: "global", fileName: "managed-fixture.json", theme: themeFixture("managed-fixture"), overwrite: false, expectedMtimeMs: null },
|
|
500
|
+
});
|
|
501
|
+
assert.equal(bundledCollision.status, 409);
|
|
502
|
+
assert.equal(bundledCollision.body?.code, "THEME_NAME_COLLISION");
|
|
503
|
+
const oppositeScopeCollision = await request("127.0.0.1", customThemePath, {
|
|
504
|
+
method: "POST",
|
|
505
|
+
body: { scope: "global", fileName: "project-fixture.json", theme: projectTheme, overwrite: false, expectedMtimeMs: null },
|
|
506
|
+
});
|
|
507
|
+
assert.equal(oppositeScopeCollision.status, 409);
|
|
508
|
+
assert.equal(oppositeScopeCollision.body?.code, "THEME_NAME_COLLISION");
|
|
509
|
+
|
|
510
|
+
const existingGlobalTheme = await request("127.0.0.1", customThemePath, {
|
|
511
|
+
method: "POST",
|
|
512
|
+
body: { scope: "global", fileName: "global-fixture.json", theme: globalTheme, overwrite: false, expectedMtimeMs: null },
|
|
513
|
+
});
|
|
514
|
+
assert.equal(existingGlobalTheme.status, 409);
|
|
515
|
+
assert.equal(existingGlobalTheme.body?.code, "THEME_EXISTS");
|
|
516
|
+
assert.deepEqual(
|
|
517
|
+
{ scope: existingGlobalTheme.body?.details?.scope, fileName: existingGlobalTheme.body?.details?.fileName },
|
|
518
|
+
{ scope: "global", fileName: "global-fixture.json" },
|
|
519
|
+
);
|
|
520
|
+
assert.equal(typeof existingGlobalTheme.body?.details?.mtimeMs, "number");
|
|
521
|
+
await delay(25);
|
|
522
|
+
await writeFile(globalThemeFile, serializeTheme(themeFixture("global-fixture", "#446688")), { mode: 0o600 });
|
|
523
|
+
const staleOverwrite = await request("127.0.0.1", customThemePath, {
|
|
524
|
+
method: "POST",
|
|
525
|
+
body: { scope: "global", fileName: "global-fixture.json", theme: globalTheme, overwrite: true, expectedMtimeMs: existingGlobalTheme.body.details.mtimeMs },
|
|
526
|
+
});
|
|
527
|
+
assert.equal(staleOverwrite.status, 409);
|
|
528
|
+
assert.equal(staleOverwrite.body?.code, "THEME_CHANGED");
|
|
529
|
+
assert.equal(await readFile(globalThemeFile, "utf8"), serializeTheme(themeFixture("global-fixture", "#446688")), "a stale overwrite must preserve current bytes");
|
|
530
|
+
const refreshedConflict = await request("127.0.0.1", customThemePath, {
|
|
531
|
+
method: "POST",
|
|
532
|
+
body: { scope: "global", fileName: "global-fixture.json", theme: globalTheme, overwrite: false, expectedMtimeMs: null },
|
|
533
|
+
});
|
|
534
|
+
const overwrittenGlobalTheme = await request("127.0.0.1", customThemePath, {
|
|
535
|
+
method: "POST",
|
|
536
|
+
body: { scope: "global", fileName: "global-fixture.json", theme: globalTheme, overwrite: true, expectedMtimeMs: refreshedConflict.body?.details?.mtimeMs },
|
|
537
|
+
});
|
|
538
|
+
assert.equal(overwrittenGlobalTheme.status, 200, overwrittenGlobalTheme.body?.error);
|
|
539
|
+
assert.deepEqual({ created: overwrittenGlobalTheme.body?.data?.created, overwritten: overwrittenGlobalTheme.body?.data?.overwritten }, { created: false, overwritten: true });
|
|
540
|
+
assert.equal(await readFile(globalThemeFile, "utf8"), serializeTheme(globalTheme));
|
|
541
|
+
assert.equal((await readdir(path.dirname(globalThemeFile))).some((name) => name.endsWith(".tmp")), false, "atomic theme saves must clean temporary artifacts");
|
|
542
|
+
|
|
543
|
+
const rejectedThemeBodies = [
|
|
544
|
+
{ body: { scope: "global", fileName: "bad-name.json", theme: themeFixture("different-name"), overwrite: false, expectedMtimeMs: null }, code: "THEME_NAME_MISMATCH" },
|
|
545
|
+
{ body: { scope: "global", fileName: "path-field.json", theme: themeFixture("path-field"), overwrite: false, expectedMtimeMs: null, path: "/tmp/escape" }, code: "THEME_REQUEST_INVALID" },
|
|
546
|
+
{ body: { scope: "elsewhere", fileName: "scope.json", theme: themeFixture("scope"), overwrite: false, expectedMtimeMs: null }, code: "THEME_SCOPE_INVALID" },
|
|
547
|
+
{ body: { scope: "global", fileName: "invalid.json", theme: { name: "invalid", colors: {} }, overwrite: false, expectedMtimeMs: null }, code: "THEME_INVALID" },
|
|
548
|
+
];
|
|
549
|
+
for (const { body, code } of rejectedThemeBodies) {
|
|
550
|
+
const rejected = await request("127.0.0.1", customThemePath, { method: "POST", body });
|
|
551
|
+
assert.equal(rejected.status, 400, rejected.body?.error);
|
|
552
|
+
assert.equal(rejected.body?.code, code);
|
|
553
|
+
}
|
|
554
|
+
const nonJsonTheme = await fetch(`http://127.0.0.1:${port}${customThemePath}`, { method: "POST", headers: { "content-type": "text/plain" }, body: "{}" });
|
|
555
|
+
assert.equal(nonJsonTheme.status, 415);
|
|
556
|
+
const crossSiteTheme = await request("127.0.0.1", customThemePath, {
|
|
557
|
+
method: "POST",
|
|
558
|
+
headers: { "Sec-Fetch-Site": "cross-site" },
|
|
559
|
+
body: { scope: "global", fileName: "cross-site.json", theme: themeFixture("cross-site"), overwrite: false, expectedMtimeMs: null },
|
|
560
|
+
});
|
|
561
|
+
assert.equal(crossSiteTheme.status, 403);
|
|
562
|
+
assert.equal(crossSiteTheme.body?.code, "THEME_CROSS_SITE_BLOCKED");
|
|
563
|
+
const malformedThemeJson = await fetch(`http://127.0.0.1:${port}${customThemePath}`, { method: "POST", headers: { "content-type": "application/json" }, body: "{" });
|
|
564
|
+
assert.equal(malformedThemeJson.status, 400);
|
|
565
|
+
assert.equal((await malformedThemeJson.json()).code, "THEME_JSON_INVALID");
|
|
566
|
+
const oversizedTheme = await fetch(`http://127.0.0.1:${port}${customThemePath}`, {
|
|
567
|
+
method: "POST",
|
|
568
|
+
headers: { "content-type": "application/json" },
|
|
569
|
+
body: JSON.stringify({ padding: "x".repeat(257 * 1024) }),
|
|
570
|
+
});
|
|
571
|
+
assert.equal(oversizedTheme.status, 413);
|
|
572
|
+
|
|
573
|
+
const untrustedThemeCwd = await mkdtemp(path.join(harnessSideEffectsRoot, "untrusted-theme-"));
|
|
574
|
+
const untrustedTab = await request("127.0.0.1", "/api/tabs", { method: "POST", body: { cwd: untrustedThemeCwd, title: "untrusted theme fixture" } });
|
|
575
|
+
assert.equal(untrustedTab.status, 201, untrustedTab.body?.error);
|
|
576
|
+
const untrustedTabId = untrustedTab.body?.data?.tab?.id;
|
|
577
|
+
const untrustedSave = await request("127.0.0.1", `/api/themes/custom?tab=${encodeURIComponent(untrustedTabId)}`, {
|
|
578
|
+
method: "POST",
|
|
579
|
+
body: { scope: "project", fileName: "untrusted.json", theme: themeFixture("untrusted"), overwrite: false, expectedMtimeMs: null },
|
|
580
|
+
});
|
|
581
|
+
assert.equal(untrustedSave.status, 403);
|
|
582
|
+
assert.equal(untrustedSave.body?.code, "THEME_PROJECT_UNTRUSTED");
|
|
583
|
+
assert.equal(await pathExists(path.join(untrustedThemeCwd, ".pi", "themes")), false, "untrusted project saves must not create .pi/themes");
|
|
584
|
+
await request("127.0.0.1", "/api/tabs/close", { method: "POST", body: { ids: [untrustedTabId] } });
|
|
585
|
+
|
|
586
|
+
const outsideTheme = path.join(harnessSideEffectsRoot, "outside-theme.json");
|
|
587
|
+
await writeFile(outsideTheme, "outside bytes", "utf8");
|
|
588
|
+
const symlinkThemeTarget = path.join(workflowPolicyAgentDir, "themes", "symlink-fixture.json");
|
|
589
|
+
try {
|
|
590
|
+
await symlink(outsideTheme, symlinkThemeTarget);
|
|
591
|
+
const symlinkSave = await request("127.0.0.1", customThemePath, {
|
|
592
|
+
method: "POST",
|
|
593
|
+
body: { scope: "global", fileName: "symlink-fixture.json", theme: themeFixture("symlink-fixture"), overwrite: false, expectedMtimeMs: null },
|
|
594
|
+
});
|
|
595
|
+
assert.equal(symlinkSave.status, 409);
|
|
596
|
+
assert.equal(symlinkSave.body?.code, "THEME_UNSAFE_TARGET");
|
|
597
|
+
assert.equal(await readFile(outsideTheme, "utf8"), "outside bytes", "theme saves must never follow a target symlink");
|
|
598
|
+
} catch (error) {
|
|
599
|
+
if (!["EPERM", "EACCES", "EINVAL", "ENOTSUP"].includes(error?.code)) throw error;
|
|
600
|
+
console.log(`http-endpoints-harness: symlink unavailable (${error.code}); skipping theme target symlink check`);
|
|
601
|
+
} finally {
|
|
602
|
+
await rm(symlinkThemeTarget, { force: true });
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
const symlinkProjectCwd = await mkdtemp(path.join(harnessSideEffectsRoot, "symlink-theme-project-"));
|
|
606
|
+
const outsideProjectPi = await mkdtemp(path.join(harnessSideEffectsRoot, "outside-project-pi-"));
|
|
607
|
+
const symlinkProjectPi = path.join(symlinkProjectCwd, ".pi");
|
|
608
|
+
let symlinkProjectTabId;
|
|
609
|
+
try {
|
|
610
|
+
await symlink(outsideProjectPi, symlinkProjectPi, process.platform === "win32" ? "junction" : "dir");
|
|
611
|
+
await writeFile(path.join(workflowPolicyAgentDir, "trust.json"), `${JSON.stringify({ [cwd]: true, [symlinkProjectCwd]: true }, null, 2)}\n`);
|
|
612
|
+
const symlinkProjectTab = await request("127.0.0.1", "/api/tabs", { method: "POST", body: { cwd: symlinkProjectCwd, title: "symlink theme project" } });
|
|
613
|
+
assert.equal(symlinkProjectTab.status, 201, symlinkProjectTab.body?.error);
|
|
614
|
+
symlinkProjectTabId = symlinkProjectTab.body?.data?.tab?.id;
|
|
615
|
+
const symlinkProjectSave = await request("127.0.0.1", `/api/themes/custom?tab=${encodeURIComponent(symlinkProjectTabId)}`, {
|
|
616
|
+
method: "POST",
|
|
617
|
+
body: { scope: "project", fileName: "escaped.json", theme: themeFixture("escaped"), overwrite: false, expectedMtimeMs: null },
|
|
618
|
+
});
|
|
619
|
+
assert.equal(symlinkProjectSave.status, 409);
|
|
620
|
+
assert.equal(symlinkProjectSave.body?.code, "THEME_UNSAFE_TARGET");
|
|
621
|
+
assert.equal(await pathExists(path.join(outsideProjectPi, "themes")), false, "a symlinked .pi directory must not receive theme writes");
|
|
622
|
+
} catch (error) {
|
|
623
|
+
if (!["EPERM", "EACCES", "EINVAL", "ENOTSUP"].includes(error?.code)) throw error;
|
|
624
|
+
console.log(`http-endpoints-harness: directory symlink unavailable (${error.code}); skipping theme root symlink check`);
|
|
625
|
+
} finally {
|
|
626
|
+
if (symlinkProjectTabId) await request("127.0.0.1", "/api/tabs/close", { method: "POST", body: { ids: [symlinkProjectTabId] } });
|
|
627
|
+
await rm(symlinkProjectPi, { force: true });
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
const themeLanHost = lanAddress();
|
|
631
|
+
if (themeLanHost) {
|
|
632
|
+
const remoteThemeSave = await request(themeLanHost, customThemePath, {
|
|
633
|
+
method: "POST",
|
|
634
|
+
body: { scope: "global", fileName: "remote.json", theme: themeFixture("remote"), overwrite: false, expectedMtimeMs: null },
|
|
635
|
+
});
|
|
636
|
+
assert.equal(remoteThemeSave.status, 403, "custom theme saves must be localhost-only");
|
|
637
|
+
}
|
|
638
|
+
// Keep this focused persistence fixture out of the later git-workflow fixture.
|
|
639
|
+
await rm(path.join(cwd, ".pi"), { recursive: true, force: true });
|
|
640
|
+
|
|
444
641
|
if (optionalFeatureFocus) {
|
|
445
642
|
await runOptionalFeatureFocus();
|
|
446
643
|
} else {
|
|
@@ -778,12 +975,16 @@ try {
|
|
|
778
975
|
const appSource = await readFile(join(root, "public", "app.js"), "utf8");
|
|
779
976
|
const startupModuleNames = [...new Set([...appSource.matchAll(/(?:\bfrom\s+|\bimport\s*(?:\(\s*)?)["']\.\/([^"'?]+)(?:\?[^"']*)?["']/g)].map((match) => match[1]))];
|
|
780
977
|
assert.ok(startupModuleNames.length >= 1, "the startup-module harness should discover app.js imports");
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
978
|
+
const startupHosts = [...new Set(["127.0.0.1", lanAddress()].filter(Boolean))];
|
|
979
|
+
for (const host of startupHosts) {
|
|
980
|
+
for (const moduleName of startupModuleNames) {
|
|
981
|
+
const response = await fetch(`http://${host}:${port}/${moduleName}`, { signal: AbortSignal.timeout(5_000) });
|
|
982
|
+
assert.equal(response.status, 200, `${moduleName} is imported by app.js and must be served by the WebUI on ${host}`);
|
|
983
|
+
assert.match(response.headers.get("content-type") || "", /text\/javascript/, `${moduleName} should use a JavaScript MIME type on ${host}`);
|
|
984
|
+
assert.equal(await response.text(), await readFile(join(root, "public", moduleName), "utf8"), `served startup module ${moduleName} must match its source file on ${host}`);
|
|
985
|
+
}
|
|
786
986
|
}
|
|
987
|
+
assert.ok(startupModuleNames.includes("stream-output-controller.mjs"), "the remote startup regression must exercise the stream output controller import");
|
|
787
988
|
|
|
788
989
|
const mermaidModuleResponse = await fetch(`http://127.0.0.1:${port}/vendor/mermaid/mermaid.esm.min.mjs`, {
|
|
789
990
|
signal: AbortSignal.timeout(5_000),
|
|
@@ -47,7 +47,7 @@ assert.match(css, /html\[data-tablet-shell="v2"\] \.mobile-shell-nav[\s\S]*?widt
|
|
|
47
47
|
assert.match(css, /html\[data-tablet-shell="v2"\] \.mobile-shell-surface[\s\S]*?width: min\(30rem, 72vw\)/, "tablet inspector must be a bounded right-side sheet");
|
|
48
48
|
assert.match(css, /html\[data-tablet-shell="v2"\] \.file-viewer-pane[\s\S]*?position: fixed[\s\S]*?inset: 0/, "tablet files must default to full-screen replacement");
|
|
49
49
|
assert.match(css, /and \(pointer: coarse\)[\s\S]*?min-height: 44px/, "coarse tablet pointers must retain the 44px target floor");
|
|
50
|
-
assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-
|
|
50
|
+
assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v74"/, "continuity/tablet assets need a coherent cache identity");
|
|
51
51
|
assert.match(html, /styles\.css\?v=98/, "tablet CSS must have a coherent HTML revision");
|
|
52
52
|
assert.match(html, /app\.js\?v=113/, "continuity app logic must have a coherent HTML revision");
|
|
53
53
|
assert.match(readme, /tabletShell=v2/, "tablet preview and rollback must be documented");
|
|
@@ -34,11 +34,10 @@ assert.equal(pkg.devDependencies?.["@axe-core/playwright"], "4.12.1", "axe must
|
|
|
34
34
|
assert.match(app, /from "\.\/mobile-shell-state\.mjs"/, "app boot must import the pure mobile shell module");
|
|
35
35
|
assert.match(pkg.scripts.check, /node --check public\/mobile-shell-state\.mjs/, "package checks must syntax-check every public module in the startup graph");
|
|
36
36
|
assert.match(pkg.scripts.check, /node --check public\/transcript-renderer\.mjs/, "package checks must syntax-check the transcript startup module");
|
|
37
|
-
assert.match(server, /"
|
|
38
|
-
assert.match(server, /"transcript-renderer\.mjs"/, "the server allowlist must serve the transcript startup module");
|
|
37
|
+
assert.match(server, /STATIC_PUBLIC_FILE_EXTENSIONS[\s\S]*"\.mjs"/, "the server must serve typed startup modules from the public asset boundary");
|
|
39
38
|
assert.match(serviceWorker, /"\/mobile-shell-state\.mjs"/, "the PWA shell must cache the new startup module");
|
|
40
39
|
assert.match(serviceWorker, /"\/transcript-renderer\.mjs"/, "the PWA shell must cache the transcript startup module");
|
|
41
|
-
assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-
|
|
40
|
+
assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v74"/, "the cache identity must change with the startup graph");
|
|
42
41
|
assert.match(html, /styles\.css\?v=98/, "the stylesheet revision must change with mobile/tablet CSS fixes");
|
|
43
42
|
assert.match(html, /app\.js\?v=113/, "the app revision must change with continuity/tablet wiring");
|
|
44
43
|
assert.match(serviceWorker, /const APP_SHELL_NETWORK_TIMEOUT_MS = 8_000;[\s\S]*?event\.waitUntil\([\s\S]*?cache\.put\(request, response\.clone\(\)\)[\s\S]*?return networkResponse;/, "runtime cache writes must extend the event lifetime without blocking bounded network responses");
|
|
@@ -60,6 +60,6 @@ assert.match(css, /data-mobile-presentation="essential"/, "Essential presentatio
|
|
|
60
60
|
assert.match(css, /html\[data-mobile-shell="v2"\] body\.mobile-keyboard-open \.widget-area,[\s\S]*?\.composer-actions-button \{ display: block !important; \}/, "v2 keyboard mode must keep run widgets and the actions entry available");
|
|
61
61
|
assert.match(css, /@media \(prefers-reduced-motion: reduce\)/, "reduced-motion behavior is required");
|
|
62
62
|
assert.match(css, /@media \(forced-colors: active\)/, "forced-color affordances are required");
|
|
63
|
-
assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-
|
|
63
|
+
assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v74"/, "browser asset changes need a coherent cache tuple");
|
|
64
64
|
|
|
65
65
|
console.log("mobile-phone-experience-static.test.mjs passed");
|