@firstpick/pi-package-webui 0.7.1 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -5
- package/bin/pi-webui.mjs +507 -66
- package/index.ts +4 -0
- package/lib/git-live-watcher.mjs +135 -0
- package/lib/git-message-artifacts.mjs +103 -0
- package/lib/process-tree.mjs +3 -1
- package/lib/subagent-gate.mjs +618 -0
- package/package.json +8 -6
- package/public/app.js +1261 -117
- package/public/index.html +25 -3
- package/public/styles.css +479 -4
- package/tests/app-runner-windows-conpty-harness.test.mjs +140 -0
- package/tests/danger-button-contrast-static.test.mjs +32 -0
- package/tests/fixtures/fake-pi.mjs +22 -4
- package/tests/footer-middle-truncation.test.mjs +118 -0
- package/tests/git-live-watcher.test.mjs +93 -0
- package/tests/git-message-artifacts.test.mjs +59 -0
- package/tests/git-panel-live-updates-static.test.mjs +54 -0
- package/tests/git-panel-render-stability-static.test.mjs +43 -0
- package/tests/guided-git-message-reliability-static.test.mjs +38 -0
- package/tests/http-endpoints-harness.test.mjs +103 -5
- package/tests/image-payload-hardening-harness.test.mjs +115 -0
- package/tests/mobile-static.test.mjs +74 -10
- package/tests/pi-footer-calibration-static.test.mjs +55 -0
- package/tests/runtime-error-visibility.test.mjs +63 -0
- package/tests/side-panel-context-menu-static.test.mjs +74 -0
- package/tests/subagent-gate.test.mjs +300 -0
- package/tests/subagents-helper.test.mjs +34 -3
- package/webui-rpc-helper.mjs +165 -11
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
3
|
+
import { chmod, mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
7
|
+
import { dirname, join } from "node:path";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
|
|
10
|
+
if (process.platform !== "win32") {
|
|
11
|
+
console.log("app-runner-windows-conpty-harness.test.mjs skipped (Windows only)");
|
|
12
|
+
process.exit(0);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
assert.equal(spawnSync("bash", ["--version"], { stdio: "ignore" }).status, 0, "Windows ConPTY test requires bash on PATH");
|
|
16
|
+
await import("node-pty");
|
|
17
|
+
|
|
18
|
+
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
19
|
+
const serverScript = join(root, "bin", "pi-webui.mjs");
|
|
20
|
+
const fakePi = join(root, "tests", "fixtures", "fake-pi.mjs");
|
|
21
|
+
const port = 30000 + Math.floor(Math.random() * 20000);
|
|
22
|
+
|
|
23
|
+
async function request(pathname, { method = "GET", body, timeoutMs = 5_000 } = {}) {
|
|
24
|
+
const response = await fetch(`http://127.0.0.1:${port}${pathname}`, {
|
|
25
|
+
method,
|
|
26
|
+
headers: body === undefined ? undefined : { "content-type": "application/json" },
|
|
27
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
28
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
29
|
+
});
|
|
30
|
+
const payload = await response.json().catch(() => undefined);
|
|
31
|
+
return { status: response.status, body: payload };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function waitFor(description, probe, { attempts = 100, intervalMs = 100 } = {}) {
|
|
35
|
+
let last;
|
|
36
|
+
for (let attempt = 0; attempt < attempts; attempt += 1) {
|
|
37
|
+
last = await probe();
|
|
38
|
+
if (last) return last;
|
|
39
|
+
await delay(intervalMs);
|
|
40
|
+
}
|
|
41
|
+
assert.fail(`${description} did not happen in time${last ? `; last=${JSON.stringify(last)}` : ""}`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function rmWithRetry(target) {
|
|
45
|
+
for (let attempt = 0; attempt < 8; attempt += 1) {
|
|
46
|
+
try {
|
|
47
|
+
await rm(target, { recursive: true, force: true });
|
|
48
|
+
return;
|
|
49
|
+
} catch (error) {
|
|
50
|
+
if (attempt === 7 || !["EBUSY", "EPERM", "ENOTEMPTY"].includes(error?.code)) throw error;
|
|
51
|
+
await delay(150 * (attempt + 1));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const cwd = await mkdtemp(path.join(tmpdir(), "pi-webui-conpty-"));
|
|
57
|
+
const settingsFile = path.join(cwd, "webui-settings.json");
|
|
58
|
+
await chmod(fakePi, 0o755);
|
|
59
|
+
await writeFile(path.join(cwd, "interactive-fixture"), [
|
|
60
|
+
"#!/usr/bin/env bash",
|
|
61
|
+
"set -euo pipefail",
|
|
62
|
+
"if [[ -t 0 && -t 1 ]]; then printf 'tty=yes\\n'; else printf 'tty=no\\n'; fi",
|
|
63
|
+
"read -r -p 'choice? ' answer",
|
|
64
|
+
"printf 'selected:%s\\n' \"$answer\"",
|
|
65
|
+
"",
|
|
66
|
+
].join("\n"));
|
|
67
|
+
|
|
68
|
+
const server = spawn(process.execPath, [serverScript, "--cwd", cwd, "--host", "127.0.0.1", "--port", String(port), "--pi", fakePi], {
|
|
69
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
70
|
+
env: { ...process.env, PI_WEBUI_SETTINGS_FILE: settingsFile },
|
|
71
|
+
windowsHide: true,
|
|
72
|
+
});
|
|
73
|
+
let serverOutput = "";
|
|
74
|
+
server.stdout.on("data", (chunk) => { serverOutput += String(chunk); });
|
|
75
|
+
server.stderr.on("data", (chunk) => { serverOutput += String(chunk); });
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
await waitFor("server health", async () => {
|
|
79
|
+
if (server.exitCode !== null) return false;
|
|
80
|
+
try {
|
|
81
|
+
const health = await request("/api/health", { timeoutMs: 1_000 });
|
|
82
|
+
return health.status === 200 && health.body?.ok === true;
|
|
83
|
+
} catch {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const tabsResponse = await request("/api/tabs");
|
|
89
|
+
const tabId = tabsResponse.body?.data?.tabs?.[0]?.id || tabsResponse.body?.tabs?.[0]?.id;
|
|
90
|
+
assert.ok(tabId, `startup tab should exist, output:\n${serverOutput}`);
|
|
91
|
+
|
|
92
|
+
const saved = await request("/api/app-runner-config", {
|
|
93
|
+
method: "POST",
|
|
94
|
+
body: { tab: tabId, runner: { label: "Windows ConPTY bash", command: "bash", path: "interactive-fixture" } },
|
|
95
|
+
timeoutMs: 10_000,
|
|
96
|
+
});
|
|
97
|
+
assert.equal(saved.status, 200, `saving ConPTY runner should succeed: ${saved.body?.error || serverOutput}`);
|
|
98
|
+
const runner = saved.body?.data?.runners?.find((item) => item.custom === true && item.label === "Windows ConPTY bash");
|
|
99
|
+
assert.ok(runner?.id, "Windows ConPTY custom runner should be available");
|
|
100
|
+
|
|
101
|
+
let state = await request("/api/app-runner", {
|
|
102
|
+
method: "POST",
|
|
103
|
+
body: { tab: tabId, runnerId: runner.id },
|
|
104
|
+
timeoutMs: 10_000,
|
|
105
|
+
});
|
|
106
|
+
assert.equal(state.status, 200, `ConPTY runner should start: ${state.body?.error || serverOutput}`);
|
|
107
|
+
assert.equal(state.body?.data?.activeRun?.executionMode, "conpty", "Windows runner should use ConPTY");
|
|
108
|
+
|
|
109
|
+
await waitFor("TTY prompt", async () => {
|
|
110
|
+
state = await request(`/api/app-runners?tab=${encodeURIComponent(tabId)}`);
|
|
111
|
+
const output = [...(state.body?.data?.activeRun?.lines || []), state.body?.data?.activeRun?.pendingLine || ""].join("\n");
|
|
112
|
+
return /tty=yes/.test(output) && /choice\?/.test(output);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const input = await request("/api/app-runner/input", {
|
|
116
|
+
method: "POST",
|
|
117
|
+
body: { tab: tabId, text: "alpha", closeStdin: true },
|
|
118
|
+
timeoutMs: 10_000,
|
|
119
|
+
});
|
|
120
|
+
assert.equal(input.status, 200, `ConPTY input should be accepted: ${input.body?.error || serverOutput}`);
|
|
121
|
+
|
|
122
|
+
await waitFor("interactive runner completion", async () => {
|
|
123
|
+
state = await request(`/api/app-runners?tab=${encodeURIComponent(tabId)}`);
|
|
124
|
+
return state.body?.data?.activeRun?.status === "done";
|
|
125
|
+
});
|
|
126
|
+
const output = [...(state.body?.data?.activeRun?.lines || []), state.body?.data?.activeRun?.pendingLine || ""].join("\n");
|
|
127
|
+
assert.match(output, /selected:alpha/, "Windows ConPTY runner should receive WebUI input");
|
|
128
|
+
|
|
129
|
+
await request("/api/shutdown", { method: "POST" }).catch(() => undefined);
|
|
130
|
+
for (let attempt = 0; attempt < 50 && server.exitCode === null; attempt += 1) await delay(100);
|
|
131
|
+
assert.notEqual(server.exitCode, null, "server should exit after shutdown");
|
|
132
|
+
console.log("app-runner-windows-conpty-harness.test.mjs passed");
|
|
133
|
+
} finally {
|
|
134
|
+
if (server.exitCode === null) {
|
|
135
|
+
await request("/api/shutdown", { method: "POST", timeoutMs: 1_000 }).catch(() => undefined);
|
|
136
|
+
for (let attempt = 0; attempt < 20 && server.exitCode === null; attempt += 1) await delay(100);
|
|
137
|
+
if (server.exitCode === null) server.kill("SIGKILL");
|
|
138
|
+
}
|
|
139
|
+
await rmWithRetry(cwd);
|
|
140
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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 css = await readFile(join(root, "public", "styles.css"), "utf8");
|
|
8
|
+
|
|
9
|
+
function ruleBody(selector) {
|
|
10
|
+
const escaped = selector.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
11
|
+
const match = css.match(new RegExp(`${escaped}\\s*\\{([^}]+)\\}`));
|
|
12
|
+
assert.ok(match, `${selector} should have a CSS rule`);
|
|
13
|
+
return match[1];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const filledDanger = ruleBody("button.danger");
|
|
17
|
+
assert.match(filledDanger, /color:\s*var\(--button-primary-text\)/, "filled danger buttons should retain dark high-contrast text");
|
|
18
|
+
assert.match(filledDanger, /background:\s*linear-gradient\([^;]*var\(--ctp-red\)[^;]*var\(--ctp-peach\)/, "filled danger buttons should retain their danger gradient");
|
|
19
|
+
|
|
20
|
+
for (const selector of [
|
|
21
|
+
".git-side-panel-context-menu button.danger",
|
|
22
|
+
".aur-review-action.danger",
|
|
23
|
+
".git-operation-button.danger",
|
|
24
|
+
".git-file-action.danger",
|
|
25
|
+
]) {
|
|
26
|
+
const body = ruleBody(selector);
|
|
27
|
+
assert.match(body, /color:\s*var\(--ctp-red\)/, `${selector} should retain its red outline-button text`);
|
|
28
|
+
assert.match(body, /background:\s*rgba\(var\(--ctp-crust-rgb\),\s*0\.[0-9]+\)/, `${selector} should place red text on a neutral surface`);
|
|
29
|
+
assert.doesNotMatch(body, /background:[^;]*(?:--ctp-red|--ctp-peach)/, `${selector} must not place red text on a red danger background`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
console.log("danger button contrast static tests passed");
|
|
@@ -259,6 +259,8 @@ function handleWebuiHelperPrompt(command, base) {
|
|
|
259
259
|
status: "running",
|
|
260
260
|
currentTool: "read",
|
|
261
261
|
currentToolArgs: "README.md",
|
|
262
|
+
model: "anthropic/claude-opus-4-8:high",
|
|
263
|
+
thinking: "high",
|
|
262
264
|
recentTools: [{ tool: "grep", args: "Subagents", endMs: Date.now() - 200 }],
|
|
263
265
|
recentOutput: ["Inspecting current implementation", "Waiting for the next tool result"],
|
|
264
266
|
transcript: [
|
|
@@ -333,15 +335,30 @@ function handleTransportFixturePrompt(command, base) {
|
|
|
333
335
|
function handleSubagentFixturePrompt(command, base) {
|
|
334
336
|
const message = String(command.message || "").trim();
|
|
335
337
|
if (message !== "fixture subagents running" && message !== "fixture subagents clear") return false;
|
|
336
|
-
const
|
|
338
|
+
const clearing = message.endsWith("clear");
|
|
339
|
+
const runs = clearing ? [] : [{
|
|
337
340
|
id: "fixture-run",
|
|
338
341
|
source: "async",
|
|
339
342
|
mode: "parallel",
|
|
340
343
|
status: "running",
|
|
341
344
|
startedAt: Date.now() - 2500,
|
|
342
345
|
agents: [
|
|
343
|
-
{ id: "fixture-run:0", name: "reviewer", status: "running", index: 0, currentTool: "read", nested: false },
|
|
344
|
-
{ id: "fixture-run:1", name: "scout", status: "running", index: 1, nested: false },
|
|
346
|
+
{ id: "fixture-run:0", name: "reviewer", status: "running", index: 0, currentTool: "read", model: "anthropic/claude-opus-4-8:high", thinking: "high", nested: false },
|
|
347
|
+
{ id: "fixture-run:1", name: "scout", status: "running", index: 1, model: "openai-codex/gpt-5.6-sol", thinking: "high", nested: false },
|
|
348
|
+
],
|
|
349
|
+
}];
|
|
350
|
+
const gates = clearing ? [] : [{
|
|
351
|
+
version: 1,
|
|
352
|
+
id: "fixture-gate",
|
|
353
|
+
status: "running",
|
|
354
|
+
requiredSuccesses: 2,
|
|
355
|
+
qualifyingSuccesses: 1,
|
|
356
|
+
requireDistinctProviders: true,
|
|
357
|
+
startedAt: Date.now() - 3000,
|
|
358
|
+
updatedAt: Date.now(),
|
|
359
|
+
attempts: [
|
|
360
|
+
{ id: "fixture-gate:0:1", taskIndex: 0, attempt: 1, maxAttempts: 2, agent: "reviewer", retrySafety: "read-only", runId: "fixture-review-1", model: "anthropic/claude-opus-4-8", provider: "anthropic", status: "succeeded" },
|
|
361
|
+
{ id: "fixture-gate:1:1", taskIndex: 1, attempt: 1, maxAttempts: 2, agent: "reviewer", retrySafety: "read-only", runId: "fixture-review-2", model: "openrouter/moonshotai/kimi-k3", provider: "openrouter", status: "failed", failureKind: "transient-provider", error: "provider overloaded" },
|
|
345
362
|
],
|
|
346
363
|
}];
|
|
347
364
|
respond({ ...base, data: { output: "fake subagent status emitted" } });
|
|
@@ -350,7 +367,7 @@ function handleSubagentFixturePrompt(command, base) {
|
|
|
350
367
|
id: randomUUID(),
|
|
351
368
|
method: "setStatus",
|
|
352
369
|
statusKey: "webui-subagents",
|
|
353
|
-
statusText: `PI_WEBUI_SUBAGENTS_V1 ${JSON.stringify({ version: 1, available: true, updatedAt: Date.now(), runs })}`,
|
|
370
|
+
statusText: `PI_WEBUI_SUBAGENTS_V1 ${JSON.stringify({ version: 1, available: true, updatedAt: Date.now(), runs, gates })}`,
|
|
354
371
|
});
|
|
355
372
|
return true;
|
|
356
373
|
}
|
|
@@ -422,6 +439,7 @@ rl.on("line", (line) => {
|
|
|
422
439
|
direction: "command",
|
|
423
440
|
type,
|
|
424
441
|
...(command.message !== undefined ? { message: String(command.message) } : {}),
|
|
442
|
+
...(Array.isArray(command.images) ? { images: command.images } : {}),
|
|
425
443
|
...(command.provider !== undefined ? { provider: String(command.provider) } : {}),
|
|
426
444
|
...(command.modelId !== undefined ? { modelId: String(command.modelId) } : {}),
|
|
427
445
|
});
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import vm from "node:vm";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
|
|
7
|
+
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
8
|
+
const [app, css] = await Promise.all([
|
|
9
|
+
readFile(join(root, "public", "app.js"), "utf8"),
|
|
10
|
+
readFile(join(root, "public", "styles.css"), "utf8"),
|
|
11
|
+
]);
|
|
12
|
+
|
|
13
|
+
function findFunctionSource(source, name) {
|
|
14
|
+
const signature = new RegExp(`function\\s+${name}\\s*\\(`, "m");
|
|
15
|
+
const match = signature.exec(source);
|
|
16
|
+
assert.ok(match, `${name} should be defined`);
|
|
17
|
+
let parenDepth = 0;
|
|
18
|
+
let openBrace = -1;
|
|
19
|
+
for (let index = match.index + match[0].length - 1; index < source.length; index += 1) {
|
|
20
|
+
const char = source[index];
|
|
21
|
+
if (char === "(") parenDepth += 1;
|
|
22
|
+
else if (char === ")") parenDepth -= 1;
|
|
23
|
+
else if (char === "{" && parenDepth === 0) {
|
|
24
|
+
openBrace = index;
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
assert.notEqual(openBrace, -1, `${name} body should open`);
|
|
29
|
+
let depth = 0;
|
|
30
|
+
for (let index = openBrace; index < source.length; index += 1) {
|
|
31
|
+
const char = source[index];
|
|
32
|
+
if (char === "{") depth += 1;
|
|
33
|
+
else if (char === "}") {
|
|
34
|
+
depth -= 1;
|
|
35
|
+
if (depth === 0) return source.slice(match.index, index + 1);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
assert.fail(`${name} body should close`);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const context = {
|
|
42
|
+
FOOTER_MIDDLE_TRUNCATION_END_CHARS: 16,
|
|
43
|
+
FOOTER_MIDDLE_TRUNCATION_MIN_START_CHARS: 6,
|
|
44
|
+
};
|
|
45
|
+
vm.runInNewContext(
|
|
46
|
+
`${findFunctionSource(app, "splitMiddleTruncationText")}\nthis.splitMiddleTruncationText = splitMiddleTruncationText;`,
|
|
47
|
+
context,
|
|
48
|
+
);
|
|
49
|
+
const { splitMiddleTruncationText } = context;
|
|
50
|
+
|
|
51
|
+
assert.deepEqual(
|
|
52
|
+
{ ...splitMiddleTruncationText("/tmp/project") },
|
|
53
|
+
{ start: "/tmp/project", end: "" },
|
|
54
|
+
"short paths should remain a single uninterrupted value",
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const boundary = "x".repeat(22);
|
|
58
|
+
assert.deepEqual(
|
|
59
|
+
{ ...splitMiddleTruncationText(boundary) },
|
|
60
|
+
{ start: boundary, end: "" },
|
|
61
|
+
"the split threshold should leave enough room for the visible prefix",
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const longPath = "/mnt/SSD_NVME_4TB/GitHub/laboratory-planning-app";
|
|
65
|
+
const split = { ...splitMiddleTruncationText(longPath) };
|
|
66
|
+
assert.equal(split.start + split.end, longPath, "split spans should preserve the complete path text and accessible name");
|
|
67
|
+
assert.equal(split.end, "/laboratory-planning-app", "the suffix should preserve the complete final POSIX path component");
|
|
68
|
+
assert.ok(split.start.startsWith("/mnt/"), "the flexible prefix should contain the path beginning");
|
|
69
|
+
|
|
70
|
+
const windowsPath = String.raw`C:\Users\Dev\Repos\project-tail-component`;
|
|
71
|
+
const windowsSplit = { ...splitMiddleTruncationText(windowsPath) };
|
|
72
|
+
assert.equal(windowsSplit.end, String.raw`\project-tail-component`, "the suffix should preserve the complete final Windows path component");
|
|
73
|
+
assert.equal(windowsSplit.start + windowsSplit.end, windowsPath, "Windows split spans should preserve the complete path");
|
|
74
|
+
|
|
75
|
+
const trailingSeparatorsPath = "/mnt/data/project-tail-component///";
|
|
76
|
+
const trailingSeparatorsSplit = { ...splitMiddleTruncationText(trailingSeparatorsPath) };
|
|
77
|
+
assert.equal(trailingSeparatorsSplit.end, "/project-tail-component///", "trailing separators should remain attached to the final component");
|
|
78
|
+
assert.equal(trailingSeparatorsSplit.start + trailingSeparatorsSplit.end, trailingSeparatorsPath, "trailing-separator paths should reconstruct exactly");
|
|
79
|
+
assert.deepEqual(
|
|
80
|
+
{ ...splitMiddleTruncationText(longPath, 0) },
|
|
81
|
+
{ start: longPath, end: "" },
|
|
82
|
+
"a disabled suffix should fall back to the untouched value",
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
const unicodeBoundaryPath = `/long/prefix/${"x".repeat(20)}😀${"y".repeat(15)}`;
|
|
86
|
+
const unicodeSplit = { ...splitMiddleTruncationText(unicodeBoundaryPath) };
|
|
87
|
+
assert.equal(unicodeSplit.start + unicodeSplit.end, unicodeBoundaryPath, "Unicode paths should reconstruct exactly");
|
|
88
|
+
assert.ok(unicodeSplit.end.includes("😀"), "the suffix split should preserve an astral character at the boundary");
|
|
89
|
+
assert.doesNotMatch(unicodeSplit.start, /[\uD800-\uDBFF]$/, "the prefix should not end with an unpaired high surrogate");
|
|
90
|
+
assert.doesNotMatch(unicodeSplit.end, /^[\uDC00-\uDFFF]/, "the suffix should not begin with an unpaired low surrogate");
|
|
91
|
+
|
|
92
|
+
assert.match(
|
|
93
|
+
app,
|
|
94
|
+
/function setMiddleTruncatedText[\s\S]*?if \(!parts\.end\)[\s\S]*?classList\.remove\("middle-truncate-value"\)[\s\S]*?classList\.add\("middle-truncate-value"\)/,
|
|
95
|
+
"short unsplit CWD values should retain the normal end-ellipsis fallback",
|
|
96
|
+
);
|
|
97
|
+
assert.match(
|
|
98
|
+
app,
|
|
99
|
+
/function renderTuiFooterLine[\s\S]*?footer-tui-cwd[\s\S]*?middleTruncate: true/,
|
|
100
|
+
"the fallback TUI footer should middle-truncate its CWD",
|
|
101
|
+
);
|
|
102
|
+
assert.match(
|
|
103
|
+
app,
|
|
104
|
+
/function renderGitFooterPayloadMeta[\s\S]*?options\.middleTruncate = chip\.key === "cwd";[\s\S]*?footerMeta\(chip\.label, chip\.value/,
|
|
105
|
+
"the enhanced git footer should middle-truncate only its CWD chip",
|
|
106
|
+
);
|
|
107
|
+
assert.match(
|
|
108
|
+
app,
|
|
109
|
+
/function updateGitFooterChipNodeValue[\s\S]*?chip\.key === "cwd"[\s\S]*?setMiddleTruncatedText\(valueNode, nextValue\)/,
|
|
110
|
+
"dynamic CWD updates should retain structured middle truncation",
|
|
111
|
+
);
|
|
112
|
+
assert.match(
|
|
113
|
+
css,
|
|
114
|
+
/\.middle-truncate-start \{[\s\S]*?min-width:\s*6ch;[\s\S]*?text-overflow:\s*ellipsis[\s\S]*?\.middle-truncate-end \{[\s\S]*?flex:\s*0 0 auto/,
|
|
115
|
+
"responsive styling should shrink the prefix while keeping the suffix fixed",
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
console.log("footer-middle-truncation.test.mjs passed");
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { EventEmitter } from "node:events";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
5
|
+
import { createGitLiveWatcher } from "../lib/git-live-watcher.mjs";
|
|
6
|
+
|
|
7
|
+
const created = [];
|
|
8
|
+
const changes = [];
|
|
9
|
+
const errors = [];
|
|
10
|
+
|
|
11
|
+
function fakeWatch(root, options, listener) {
|
|
12
|
+
const watcher = new EventEmitter();
|
|
13
|
+
watcher.root = root;
|
|
14
|
+
watcher.options = options;
|
|
15
|
+
watcher.listener = listener;
|
|
16
|
+
watcher.closed = false;
|
|
17
|
+
watcher.close = () => {
|
|
18
|
+
watcher.closed = true;
|
|
19
|
+
};
|
|
20
|
+
created.push(watcher);
|
|
21
|
+
return watcher;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const manager = createGitLiveWatcher({
|
|
25
|
+
watch: fakeWatch,
|
|
26
|
+
debounceMs: 20,
|
|
27
|
+
onChange: (event) => changes.push(event),
|
|
28
|
+
onError: (event) => errors.push(event),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const firstRoot = path.resolve("/tmp/pi-webui-live-one");
|
|
32
|
+
const secondRoot = path.resolve("/tmp/pi-webui-live-two");
|
|
33
|
+
|
|
34
|
+
assert.equal(manager.subscribe("tab-a", firstRoot), true);
|
|
35
|
+
assert.equal(manager.subscribe("tab-b", firstRoot), true);
|
|
36
|
+
assert.equal(created.length, 1, "tabs in one repository should share one recursive watcher");
|
|
37
|
+
assert.deepEqual(created[0].options, { recursive: true, persistent: false });
|
|
38
|
+
assert.equal(manager.watchedRootCount(), 1);
|
|
39
|
+
|
|
40
|
+
created[0].listener("change", "file.txt");
|
|
41
|
+
created[0].listener("rename", "created.txt");
|
|
42
|
+
created[0].listener("change", "file.txt");
|
|
43
|
+
await delay(50);
|
|
44
|
+
assert.equal(changes.length, 1, "one filesystem burst should emit one debounced invalidation");
|
|
45
|
+
assert.equal(changes[0].root, firstRoot);
|
|
46
|
+
assert.match(changes[0].changedAt, /^\d{4}-\d{2}-\d{2}T/);
|
|
47
|
+
|
|
48
|
+
const maxWaitChanges = [];
|
|
49
|
+
const maxWaitManager = createGitLiveWatcher({
|
|
50
|
+
watch: fakeWatch,
|
|
51
|
+
debounceMs: 80,
|
|
52
|
+
maxWaitMs: 40,
|
|
53
|
+
onChange: (event) => maxWaitChanges.push(event),
|
|
54
|
+
});
|
|
55
|
+
assert.equal(maxWaitManager.subscribe("tab-max-wait", firstRoot), true);
|
|
56
|
+
const maxWaitWatcher = created.at(-1);
|
|
57
|
+
maxWaitWatcher.listener("change", "continuous.txt");
|
|
58
|
+
await delay(25);
|
|
59
|
+
maxWaitWatcher.listener("change", "continuous.txt");
|
|
60
|
+
await delay(30);
|
|
61
|
+
assert.equal(maxWaitChanges.length, 1, "sustained writes should emit by the bounded maximum wait");
|
|
62
|
+
maxWaitManager.closeAll();
|
|
63
|
+
|
|
64
|
+
assert.equal(manager.unsubscribe("tab-a"), true);
|
|
65
|
+
assert.equal(created[0].closed, false, "the shared watcher should remain while another tab subscribes");
|
|
66
|
+
assert.equal(manager.subscribe("tab-b", secondRoot), true, "moving a tab should subscribe its new repository");
|
|
67
|
+
assert.equal(created[0].closed, true, "moving the last subscriber should close the old watcher");
|
|
68
|
+
assert.equal(created.length, 3);
|
|
69
|
+
assert.equal(manager.subscribedRootForTab("tab-b"), secondRoot);
|
|
70
|
+
|
|
71
|
+
created.at(-1).emit("error", new Error("fixture watcher failed"));
|
|
72
|
+
assert.equal(errors.length, 1, "runtime watcher failures should be reported once");
|
|
73
|
+
assert.equal(errors[0].root, secondRoot);
|
|
74
|
+
assert.equal(manager.watchedRootCount(), 0, "a failed watcher should be removed");
|
|
75
|
+
assert.equal(manager.subscribedRootForTab("tab-b"), "", "failed roots should release tab subscriptions for later retry");
|
|
76
|
+
|
|
77
|
+
const throwingManager = createGitLiveWatcher({
|
|
78
|
+
watch: () => {
|
|
79
|
+
throw new Error("watch unsupported");
|
|
80
|
+
},
|
|
81
|
+
onError: (event) => errors.push(event),
|
|
82
|
+
});
|
|
83
|
+
assert.equal(throwingManager.subscribe("tab-c", firstRoot), false, "synchronous watcher startup errors should be non-fatal");
|
|
84
|
+
assert.match(errors.at(-1)?.error?.message || "", /watch unsupported/);
|
|
85
|
+
|
|
86
|
+
assert.equal(manager.subscribe("tab-d", firstRoot), true);
|
|
87
|
+
assert.equal(manager.subscribe("tab-e", secondRoot), true);
|
|
88
|
+
const latestWatchers = created.slice(-2);
|
|
89
|
+
manager.closeAll();
|
|
90
|
+
assert.equal(manager.watchedRootCount(), 0);
|
|
91
|
+
assert.equal(latestWatchers.every((watcher) => watcher.closed), true, "closeAll should release every watcher");
|
|
92
|
+
|
|
93
|
+
console.log("git-live-watcher.test.mjs passed");
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { mkdtemp, mkdir, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import {
|
|
6
|
+
gitMessageArtifactPairReadiness,
|
|
7
|
+
readStableGitMessageArtifactPair,
|
|
8
|
+
sameGitMessageArtifactPair,
|
|
9
|
+
sameGitMessageArtifactVersion,
|
|
10
|
+
} from "../lib/git-message-artifacts.mjs";
|
|
11
|
+
|
|
12
|
+
const root = await mkdtemp(path.join(tmpdir(), "pi-webui-git-messages-"));
|
|
13
|
+
const commitDir = path.join(root, "dev", "COMMIT");
|
|
14
|
+
const paths = {
|
|
15
|
+
shortPath: path.join(commitDir, "staged-commit-short.txt"),
|
|
16
|
+
longPath: path.join(commitDir, "staged-commit-long.txt"),
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
await mkdir(commitDir, { recursive: true });
|
|
21
|
+
|
|
22
|
+
const missingBaseline = await readStableGitMessageArtifactPair(paths);
|
|
23
|
+
assert.equal(missingBaseline.short.exists, false);
|
|
24
|
+
assert.equal(missingBaseline.long.exists, false);
|
|
25
|
+
assert.equal(gitMessageArtifactPairReadiness(missingBaseline, missingBaseline).ready, false, "missing files must not be ready");
|
|
26
|
+
|
|
27
|
+
await writeFile(paths.shortPath, "feat: correlated message\n", "utf8");
|
|
28
|
+
await writeFile(paths.longPath, "feat: correlated message\n\n- feat: load both files\n", "utf8");
|
|
29
|
+
const firstPair = await readStableGitMessageArtifactPair(paths);
|
|
30
|
+
assert.equal(gitMessageArtifactPairReadiness(missingBaseline, firstPair).ready, true, "two new non-empty files should be ready");
|
|
31
|
+
assert.equal(sameGitMessageArtifactPair(firstPair, await readStableGitMessageArtifactPair(paths)), true, "unchanged stable pairs should compare equal");
|
|
32
|
+
|
|
33
|
+
await writeFile(paths.shortPath, "fix: only short changed\n", "utf8");
|
|
34
|
+
const partialPair = await readStableGitMessageArtifactPair(paths);
|
|
35
|
+
const partialReadiness = gitMessageArtifactPairReadiness(firstPair, partialPair);
|
|
36
|
+
assert.equal(partialReadiness.ready, false, "one stale member must keep the pair pending");
|
|
37
|
+
assert.deepEqual(partialReadiness.unchanged, ["long"]);
|
|
38
|
+
|
|
39
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
40
|
+
await writeFile(paths.shortPath, firstPair.short.text, "utf8");
|
|
41
|
+
await writeFile(paths.longPath, firstPair.long.text, "utf8");
|
|
42
|
+
const identicalRewrite = await readStableGitMessageArtifactPair(paths);
|
|
43
|
+
assert.equal(identicalRewrite.short.sha256, firstPair.short.sha256, "test setup keeps identical short content");
|
|
44
|
+
assert.equal(identicalRewrite.long.sha256, firstPair.long.sha256, "test setup keeps identical long content");
|
|
45
|
+
assert.equal(sameGitMessageArtifactVersion(firstPair.short, identicalRewrite.short), false, "metadata must identify an identical-content rewrite");
|
|
46
|
+
assert.equal(sameGitMessageArtifactVersion(firstPair.long, identicalRewrite.long), false, "both identical-content rewrites must be fresh");
|
|
47
|
+
assert.equal(gitMessageArtifactPairReadiness(firstPair, identicalRewrite).ready, true, "identical generated text is valid when both files were rewritten");
|
|
48
|
+
|
|
49
|
+
await writeFile(paths.shortPath, "", "utf8");
|
|
50
|
+
await writeFile(paths.longPath, "fix: long is present\n", "utf8");
|
|
51
|
+
const emptyPair = await readStableGitMessageArtifactPair(paths);
|
|
52
|
+
const emptyReadiness = gitMessageArtifactPairReadiness(identicalRewrite, emptyPair);
|
|
53
|
+
assert.equal(emptyReadiness.ready, false, "empty generated files must remain pending");
|
|
54
|
+
assert.deepEqual(emptyReadiness.empty, ["short"]);
|
|
55
|
+
|
|
56
|
+
console.log("git message artifact tests passed");
|
|
57
|
+
} finally {
|
|
58
|
+
await rm(root, { recursive: true, force: true });
|
|
59
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
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, server, watcher, readme] = await Promise.all([
|
|
8
|
+
readFile(join(root, "public", "app.js"), "utf8"),
|
|
9
|
+
readFile(join(root, "bin", "pi-webui.mjs"), "utf8"),
|
|
10
|
+
readFile(join(root, "lib", "git-live-watcher.mjs"), "utf8"),
|
|
11
|
+
readFile(join(root, "README.md"), "utf8"),
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
function functionBody(source, name) {
|
|
15
|
+
const syncStart = source.indexOf(`function ${name}(`);
|
|
16
|
+
const asyncStart = source.indexOf(`async function ${name}(`);
|
|
17
|
+
const start = syncStart === -1 ? asyncStart : asyncStart === -1 ? syncStart : Math.min(syncStart, asyncStart);
|
|
18
|
+
assert.notEqual(start, -1, `${name} should be defined`);
|
|
19
|
+
const nextSync = source.indexOf("\nfunction ", start + 1);
|
|
20
|
+
const nextAsync = source.indexOf("\nasync function ", start + 1);
|
|
21
|
+
const candidates = [nextSync, nextAsync].filter((index) => index !== -1);
|
|
22
|
+
return source.slice(start, candidates.length ? Math.min(...candidates) : source.length);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const loadRepository = functionBody(app, "loadGitPanelRepository");
|
|
26
|
+
const invalidateRepository = functionBody(app, "invalidateGitPanelRepository");
|
|
27
|
+
const ensureVisibleFresh = functionBody(app, "ensureGitPanelVisibleRepositoriesFresh");
|
|
28
|
+
const handleEvent = functionBody(app, "handleEvent");
|
|
29
|
+
|
|
30
|
+
assert.match(watcher, /watch\(root, \{ recursive: true, persistent: false \}/, "repository watches should be recursive and non-persistent");
|
|
31
|
+
assert.match(watcher, /record\.timer = setTimeout[\s\S]*onChange\(\{ root, changedAt:/, "filesystem bursts should debounce to a repository invalidation");
|
|
32
|
+
assert.match(watcher, /maximumWaitMs[\s\S]*remainingMs[\s\S]*Math\.min\(delayMs, remainingMs\)/, "continuous writes should still invalidate within a bounded maximum wait");
|
|
33
|
+
assert.match(watcher, /record\.tabs:|tabs: new Set\(\)/, "shared roots should track tab subscribers");
|
|
34
|
+
assert.match(watcher, /if \(!record\.tabs\.size\) closeRoot/, "the last tab unsubscribe should close its root watcher");
|
|
35
|
+
assert.match(watcher, /function closeAll\(\)[\s\S]*closeRoot\(root\)/, "server shutdown should release every root watcher");
|
|
36
|
+
|
|
37
|
+
assert.match(server, /createGitLiveWatcher\(\{[\s\S]*type: "webui_git_changed"[\s\S]*broadcastServerEvent/, "watcher changes should use the existing server-wide SSE channel");
|
|
38
|
+
assert.match(server, /env: \{ GIT_OPTIONAL_LOCKS: "0" \}/, "read-only Git commands should not feed optional index refreshes back into the watcher");
|
|
39
|
+
assert.match(server, /trackGitRepositoryForTab\(tab, await getGitRoot\(tab\.cwd\)\)/, "Git-root discovery should register the tab watcher");
|
|
40
|
+
assert.match(server, /trackGitRepositoryForTab\(tab, data\.root\)/, "Git-panel reads should ensure watcher registration");
|
|
41
|
+
assert.match(server, /async function updateTabCwd[\s\S]*gitLiveWatcher\.unsubscribe\(tab\.id\)/, "cwd changes should release old repository subscriptions");
|
|
42
|
+
assert.match(server, /async function closeTab[\s\S]*gitLiveWatcher\.unsubscribe\(tab\.id\)/, "tab closure should release repository subscriptions");
|
|
43
|
+
assert.match(server, /function shutdown[\s\S]*gitLiveWatcher\.closeAll\(\)/, "server shutdown should close all repository watches");
|
|
44
|
+
|
|
45
|
+
assert.match(loadRepository, /existing\?\.loading[\s\S]*refreshPending: true/, "an invalidation during a request should queue a follow-up refresh");
|
|
46
|
+
assert.match(loadRepository, /if \(refreshAgain\) queueMicrotask\(\(\) => loadGitPanelRepository\(card, \{ force: true \}\)\)/, "queued invalidations should trigger one follow-up Git snapshot");
|
|
47
|
+
assert.match(invalidateRepository, /error: ""[\s\S]*loadedAt: 0/, "a fresh SSE invalidation should clear a previous read error and expire the cache");
|
|
48
|
+
assert.match(invalidateRepository, /if \(!gitPanelSectionExpanded\(\)\) return;/, "collapsed Git sections should defer HTTP refresh work");
|
|
49
|
+
assert.match(ensureVisibleFresh, /snapshot\?\.error/, "persistent Git read errors should not cause an unbounded render/reload loop");
|
|
50
|
+
assert.match(ensureVisibleFresh, /gitPanelSnapshotFresh\(snapshot\)[\s\S]*loadGitPanelRepository\(card\)/, "visible stale repositories should refresh on render");
|
|
51
|
+
assert.match(handleEvent, /case "webui_git_changed":[\s\S]*invalidateGitPanelRepository\(event\.root\)/, "the browser event stream should route Git invalidations to the cache");
|
|
52
|
+
assert.match(readme, /live filesystem updates[\s\S]*SSE/, "README should document live watcher-driven Git refresh behavior");
|
|
53
|
+
|
|
54
|
+
console.log("git-panel-live-updates-static.test.mjs passed");
|
|
@@ -0,0 +1,43 @@
|
|
|
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 = await readFile(join(root, "public", "app.js"), "utf8");
|
|
8
|
+
|
|
9
|
+
function functionBody(name) {
|
|
10
|
+
const start = app.indexOf(`function ${name}(`);
|
|
11
|
+
assert.notEqual(start, -1, `${name} should be defined`);
|
|
12
|
+
const next = app.indexOf("\nfunction ", start + 1);
|
|
13
|
+
return app.slice(start, next === -1 ? app.length : next);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const renderGitPanel = functionBody("renderGitPanel");
|
|
17
|
+
const renderGitPanelFolder = functionBody("renderGitPanelFolder");
|
|
18
|
+
const renderContextMeter = functionBody("renderContextMeter");
|
|
19
|
+
const renderWorkspaceDashboard = functionBody("renderWorkspaceDashboard");
|
|
20
|
+
|
|
21
|
+
assert.match(app, /openFolders: new Map\(\)/, "Git panel state should persist folder toggles");
|
|
22
|
+
assert.match(renderGitPanelFolder, /const defaultOpen = true;/, "folder rendering should expand every directory depth by default");
|
|
23
|
+
assert.match(renderGitPanelFolder, /details\.open = gitPanelState\.openFolders\.has\(folderKey\) \? gitPanelState\.openFolders\.get\(folderKey\) : defaultOpen;/, "folder rendering should prefer a stored override over its default");
|
|
24
|
+
assert.match(renderGitPanelFolder, /if \(details\.open === defaultOpen\) gitPanelState\.openFolders\.delete\(folderKey\);/, "folder toggles back to the default should remove the override");
|
|
25
|
+
assert.match(renderGitPanelFolder, /else gitPanelState\.openFolders\.set\(folderKey, details\.open\);/, "folder toggles away from the default should store an override");
|
|
26
|
+
assert.match(renderGitPanel, /gitPanelState\.openFolders\.keys\(\)/, "folder state for removed roots should be pruned");
|
|
27
|
+
assert.doesNotMatch(renderGitPanel, /\bsectionExpanded\b/, "Git panel signature should not include the always-true section state");
|
|
28
|
+
|
|
29
|
+
const gitGuard = renderGitPanel.indexOf("signature === gitPanelRenderSignature");
|
|
30
|
+
const gitRebuild = renderGitPanel.indexOf("elements.gitPanelGroups.replaceChildren");
|
|
31
|
+
assert.ok(gitGuard > 0 && gitGuard < gitRebuild, "Git panel signature guard should precede its DOM rebuild");
|
|
32
|
+
assert.match(renderGitPanel, /snapshot\?\.loadedAt/, "Git panel signature should include repository snapshot versions");
|
|
33
|
+
assert.match(renderGitPanel, /gitPanelState\.activeViews\.get/, "Git panel signature should include active repository views");
|
|
34
|
+
|
|
35
|
+
const contextGuard = renderContextMeter.indexOf("signature === contextMeterSignature");
|
|
36
|
+
const contextRebuild = renderContextMeter.lastIndexOf("root.replaceChildren");
|
|
37
|
+
assert.ok(contextGuard > 0 && contextGuard < contextRebuild, "context meter signature guard should precede its DOM rebuild");
|
|
38
|
+
|
|
39
|
+
const dashboardGuard = renderWorkspaceDashboard.indexOf("signature === workspaceDashboardSignature");
|
|
40
|
+
const dashboardRebuild = renderWorkspaceDashboard.indexOf("root.replaceChildren");
|
|
41
|
+
assert.ok(dashboardGuard > 0 && dashboardGuard < dashboardRebuild, "workspace dashboard signature guard should precede its DOM rebuild");
|
|
42
|
+
|
|
43
|
+
console.log("git-panel-render-stability-static.test.mjs passed");
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
|
|
6
|
+
const testsDir = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
const packageDir = path.resolve(testsDir, "..");
|
|
8
|
+
const [app, server, artifacts] = await Promise.all([
|
|
9
|
+
readFile(path.join(packageDir, "public", "app.js"), "utf8"),
|
|
10
|
+
readFile(path.join(packageDir, "bin", "pi-webui.mjs"), "utf8"),
|
|
11
|
+
readFile(path.join(packageDir, "lib", "git-message-artifacts.mjs"), "utf8"),
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
assert.match(server, /async function createGitWorkflowMessageGeneration\(tab\)[\s\S]*id: randomUUID\(\)[\s\S]*baseline: await readStableGitMessageArtifactPair\(paths\)/, "commit generation must capture a server-owned ID and exact two-file baseline");
|
|
15
|
+
assert.match(server, /generationId: messageGeneration\?\.id \|\| ""/, "generation dispatch must return the server correlation ID");
|
|
16
|
+
assert.match(server, /tab\.gitWorkflowMessageGeneration = messageGeneration/, "the generation record must be owned by the originating tab");
|
|
17
|
+
assert.match(server, /case "\/api\/git-workflow\/message"[\s\S]*generationId[\s\S]*tab\?\.gitWorkflowMessageGeneration/, "fresh message reads must resolve the generation from the requested tab");
|
|
18
|
+
assert.match(server, /readGitWorkflowMessages\(cwd, \{ generationId = "", generation = null \} = \{\}\)[\s\S]*generation\.cwd !== messageCwd[\s\S]*expired: true/, "message readiness must reject wrong-ID, wrong-kind, and wrong-cwd generations");
|
|
19
|
+
assert.match(server, /gitMessageArtifactPairReadiness\(generation\.baseline, pair\)[\s\S]*GIT_WORKFLOW_MESSAGE_PAIR_SETTLE_MS[\s\S]*sameGitMessageArtifactPair\(pair, settledPair\)/, "the backend must require both changed artifacts and a stable settled pair");
|
|
20
|
+
assert.doesNotMatch(app, /newestMtime \+ 10000 < currentWorkflow\.messageRequestedAt/, "freshness must not use the previous wall-clock/mtime tolerance");
|
|
21
|
+
|
|
22
|
+
assert.match(app, /const gitWorkflowMessageLoadsByTab = new Map\(\)/, "browser message loading must have tab-scoped single-flight ownership");
|
|
23
|
+
assert.match(app, /messageGenerationId: ""/, "workflow state must retain the active commit-message generation ID");
|
|
24
|
+
assert.match(app, /const generationId = String\(generation\.generationId \|\| ""\)\.trim\(\)[\s\S]*setGitWorkflow\(\{ messageGenerationId: generationId \}/, "the browser must bind the returned generation ID before loading files");
|
|
25
|
+
assert.match(app, /const loadKey = `\$\{expectedRunId\}:\$\{expectedGenerationId \|\| "preview"\}`[\s\S]*existing\?\.key === loadKey[\s\S]*return existing\.promise/, "duplicate timer/resume/agent_end wakeups must reuse one poll promise");
|
|
26
|
+
assert.match(app, /gitWorkflowMessageLoadIsCurrent\(tabId, expectedRunId, expectedGenerationId\)/, "poll results must be guarded by tab, run, and generation identity");
|
|
27
|
+
assert.match(app, /GIT_WORKFLOW_MESSAGE_POLL_TIMEOUT_MS = 30_000[\s\S]*GIT_WORKFLOW_MESSAGE_POLL_DELAYS_MS/, "fresh message polling must be adaptive and bounded");
|
|
28
|
+
assert.match(app, /\?generationId=\$\{encodeURIComponent\(expectedGenerationId\)\}/, "fresh reads must send the correlation ID to the backend");
|
|
29
|
+
assert.match(app, /message\.ready === false[\s\S]*message\.expired[\s\S]*Regenerate/, "pending and expired generation states must remain actionable");
|
|
30
|
+
assert.match(app, /gitWorkflow\.step === "generating"[\s\S]*gitWorkflow\.messageGenerationId[\s\S]*Starting message generation…/, "the refresh action must stay disabled until the server correlation ID is bound");
|
|
31
|
+
assert.match(app, /requireFresh && !expectedGenerationId[\s\S]*workflow\.step === "generating"\) return;/, "early timer and agent_end wakeups must no-op during the generation-ID dispatch window");
|
|
32
|
+
assert.doesNotMatch(app, /loadGitWorkflowMessage\(\{ requireFresh: true, retries:/, "legacy competing retry chains must be removed");
|
|
33
|
+
|
|
34
|
+
assert.match(artifacts, /mtimeNs: String\(stats\.mtimeNs\)[\s\S]*ctimeNs: String\(stats\.ctimeNs\)[\s\S]*sha256: createHash\("sha256"\)/, "artifact snapshots must combine high-resolution metadata with a content hash");
|
|
35
|
+
assert.match(artifacts, /stat\(filePath, \{ bigint: true \}\)[\s\S]*readFile\(filePath\)[\s\S]*stat\(filePath, \{ bigint: true \}\)/, "artifact reads must verify stable metadata around the file read");
|
|
36
|
+
assert.match(artifacts, /for \(const key of \["short", "long"\]\)[\s\S]*unchanged\.push\(key\)[\s\S]*empty\.push\(key\)/, "pair readiness must independently validate both non-empty files");
|
|
37
|
+
|
|
38
|
+
console.log("guided Git message reliability static tests passed");
|