@firstpick/pi-package-webui 0.9.7 → 0.9.8
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 -3
- package/bin/pi-webui.mjs +114 -25
- package/index.ts +2 -1
- package/lib/optional-feature-catalog.mjs +1 -1
- package/package.json +1 -1
- package/public/app.js +629 -98
- package/public/guided-git-command-state.mjs +175 -1
- package/public/index.html +12 -9
- package/public/service-worker.js +1 -1
- package/public/styles.css +133 -31
- package/public/transcript-renderer.mjs +62 -0
- package/tests/boot-failure-diagnostics.test.mjs +3 -3
- package/tests/browser/footer-model-advanced-layout.spec.mjs +512 -0
- package/tests/browser/guided-git-extension-command.spec.mjs +180 -0
- package/tests/browser/guided-git-fallback.spec.mjs +68 -3
- package/tests/browser/interaction-continuity.spec.mjs +33 -0
- package/tests/codex-fast-mode-static.test.mjs +2 -2
- package/tests/compaction-static.test.mjs +1 -1
- package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
- package/tests/control-visibility-static.test.mjs +3 -3
- package/tests/controls-layout-static.test.mjs +3 -3
- package/tests/events-tree-context-menu-static.test.mjs +3 -3
- package/tests/fast-mode-client-static.test.mjs +1 -1
- package/tests/feature-decision-output-popup-static.test.mjs +2 -2
- package/tests/file-viewer-image-static.test.mjs +3 -3
- package/tests/fixtures/fake-pi.mjs +34 -3
- package/tests/git-footer-context-menu-static.test.mjs +103 -1
- package/tests/guided-git-activation-http.test.mjs +194 -0
- package/tests/guided-git-activation-static.test.mjs +80 -0
- package/tests/guided-git-activation.test.mjs +244 -0
- package/tests/guided-git-fallback-runtime.test.mjs +1 -0
- package/tests/guided-git-fallback-ui-static.test.mjs +2 -2
- package/tests/guided-git-message-reliability-static.test.mjs +2 -1
- package/tests/guided-git-optional-feature.test.mjs +31 -0
- package/tests/http-endpoints-harness.test.mjs +3 -0
- package/tests/interaction-state-stability-static.test.mjs +1 -1
- package/tests/intercom-conversation-viewer-static.test.mjs +3 -3
- package/tests/main-output-loading-static.test.mjs +11 -9
- package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
- package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
- package/tests/mobile-foundation-static.test.mjs +3 -3
- package/tests/mobile-phone-experience-static.test.mjs +1 -1
- package/tests/mobile-static.test.mjs +85 -4
- package/tests/open-issue-wizard-static.test.mjs +1 -1
- package/tests/persistent-ui-layout-static.test.mjs +3 -3
- package/tests/prompt-input-vertical-scroll-static.test.mjs +6 -6
- package/tests/prompt-routing-input-clear-static.test.mjs +1 -1
- package/tests/questionnaire-dialog.test.mjs +3 -3
- package/tests/session-sampling-ui-static.test.mjs +3 -3
- package/tests/side-panel-section-height-removal-static.test.mjs +3 -3
- package/tests/subagent-observability-static.test.mjs +2 -2
- package/tests/syntax-highlighting-static.test.mjs +3 -3
- package/tests/tab-close-continuity-static.test.mjs +2 -0
- package/tests/theme-customizer-static.test.mjs +1 -1
- package/tests/thinking-block-grouping.test.mjs +79 -0
|
@@ -4,9 +4,10 @@ import { dirname, join } from "node:path";
|
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
|
|
6
6
|
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
7
|
-
const [html, app] = await Promise.all([
|
|
7
|
+
const [html, app, css] = await Promise.all([
|
|
8
8
|
readFile(join(root, "public", "index.html"), "utf8"),
|
|
9
9
|
readFile(join(root, "public", "app.js"), "utf8"),
|
|
10
|
+
readFile(join(root, "public", "styles.css"), "utf8"),
|
|
10
11
|
]);
|
|
11
12
|
|
|
12
13
|
assert.match(
|
|
@@ -55,4 +56,105 @@ assert.match(
|
|
|
55
56
|
"clicking outside should close the Git footer context menu",
|
|
56
57
|
);
|
|
57
58
|
|
|
59
|
+
assert.match(
|
|
60
|
+
html,
|
|
61
|
+
/role="menuitemcheckbox"[^>]*aria-checked="false"[^>]*data-git-footer-menu-action="toggle-advanced"[^>]*hidden>Toggle advanced<\/button>/,
|
|
62
|
+
"the advanced-layout action should be a hidden-by-default checkbox menu item",
|
|
63
|
+
);
|
|
64
|
+
assert.match(
|
|
65
|
+
app,
|
|
66
|
+
/function syncGitFooterAdvancedMenuItem\(key = gitFooterContextMenuState\?\.key\)[\s\S]*advancedButton\.hidden = key !== "model"[\s\S]*advancedButton\.textContent = footerScopedModelLayout === "advanced" \? "Toggle Simple" : "Toggle advanced"[\s\S]*advancedButton\.setAttribute\("aria-checked", footerScopedModelLayout === "advanced" \? "true" : "false"\)[\s\S]*function showGitFooterContextMenu\(event, chip, trigger\)[\s\S]*syncGitFooterAdvancedMenuItem\(key\)/,
|
|
67
|
+
"the Model-only layout action should show the destination label and expose its current checked state",
|
|
68
|
+
);
|
|
69
|
+
assert.match(
|
|
70
|
+
app,
|
|
71
|
+
/const FOOTER_SCOPED_MODEL_LAYOUT_STORAGE_KEY = "pi-webui-footer-scoped-model-layout-v1"[\s\S]*function normalizeFooterScopedModelLayout\(value\)[\s\S]*value === "advanced" \? "advanced" : "flat"[\s\S]*localStorage\.setItem\(FOOTER_SCOPED_MODEL_LAYOUT_STORAGE_KEY, next\)/,
|
|
72
|
+
"the browser-local layout preference should normalize unknown values and persist explicit flat or advanced state",
|
|
73
|
+
);
|
|
74
|
+
assert.match(
|
|
75
|
+
app,
|
|
76
|
+
/window\.addEventListener\("storage"[\s\S]*event\.key === FOOTER_SCOPED_MODEL_LAYOUT_STORAGE_KEY[\s\S]*setFooterScopedModelLayout\(event\.newValue, \{ persist: false \}\)/,
|
|
77
|
+
"same-origin Web UI tabs should adopt advanced-layout storage changes without rewriting them",
|
|
78
|
+
);
|
|
79
|
+
assert.match(
|
|
80
|
+
app,
|
|
81
|
+
/function setFooterScopedModelLayout\([\s\S]*syncGitFooterAdvancedMenuItem\(\)[\s\S]*renderFooter\(\)/,
|
|
82
|
+
"live layout adoption should refresh an open checkbox",
|
|
83
|
+
);
|
|
84
|
+
assert.match(
|
|
85
|
+
app,
|
|
86
|
+
/function footerModelPickerRenderKey\(\)[\s\S]*footerScopedModelLayout[\s\S]*orderedFooterScopedModels\(\)/,
|
|
87
|
+
"layout and scoped order should invalidate open-picker fast rendering",
|
|
88
|
+
);
|
|
89
|
+
assert.match(
|
|
90
|
+
app,
|
|
91
|
+
/function footerScopedModelProviderGroups\(models = orderedFooterScopedModels\(\)\)[\s\S]*modelsByProvider\.get\(provider\)\.push\(model\)[\s\S]*sort\(\(\[a\], \[b\]\) => compareFooterScopedModelProviders\(a, b\)\)[\s\S]*models: providerModels/,
|
|
92
|
+
"provider grouping should sort provider columns while preserving each provider's existing model order",
|
|
93
|
+
);
|
|
94
|
+
assert.match(
|
|
95
|
+
app,
|
|
96
|
+
/footer-model-provider-column[\s\S]*dataset\.footerProviderIndex = String\(providerIndex\)[\s\S]*setAttribute\("role", "group"\)[\s\S]*setAttribute\("aria-labelledby", heading\.id\)[\s\S]*renderFooterModelOption\(model, \{ advanced: true, providerIndex, modelIndex, initialKey \}\)/,
|
|
97
|
+
"advanced rendering should expose labelled provider groups and stable provider/model indices",
|
|
98
|
+
);
|
|
99
|
+
assert.match(
|
|
100
|
+
app,
|
|
101
|
+
/function footerScopedModelOrderWithProviderOrder\(provider, providerOrder\)[\s\S]*allowedKeys[\s\S]*nextProviderKeys[\s\S]*String\(model\?\.provider \|\| ""\) === provider[\s\S]*function commitFooterScopedModelProviderOrder[\s\S]*commitFooterScopedModelOrder\(nextOrder/,
|
|
102
|
+
"advanced provider reordering should replace only that provider's existing global order slots",
|
|
103
|
+
);
|
|
104
|
+
assert.match(
|
|
105
|
+
app,
|
|
106
|
+
/function handleAdvancedFooterModelKeydown\(event, model\)[\s\S]*event\.key === "Enter" \|\| event\.key === " "[\s\S]*!event\.repeat[\s\S]*applyFooterModel\(model\)[\s\S]*event\.key === "Escape"[\s\S]*setFooterModelPickerOpen\(false, \{ restoreFocus: true \}\)[\s\S]*event\.altKey[\s\S]*moveFooterScopedModelWithinProviderByOffset[\s\S]*event\.key === "ArrowUp" \|\| event\.key === "ArrowDown" \|\| event\.key === "Home" \|\| event\.key === "End"[\s\S]*event\.key === "ArrowLeft" \|\| event\.key === "ArrowRight"/,
|
|
107
|
+
"advanced options should implement provider-local reorder, apply, close/focus restoration, row, and provider keyboard contracts",
|
|
108
|
+
);
|
|
109
|
+
assert.match(
|
|
110
|
+
app,
|
|
111
|
+
/function focusAdvancedFooterModelOption\([\s\S]*scrollIntoView\(\{ block: "nearest", inline: "nearest" \}\)/,
|
|
112
|
+
"advanced navigation should reveal focused options",
|
|
113
|
+
);
|
|
114
|
+
assert.match(
|
|
115
|
+
app,
|
|
116
|
+
/function syncAdvancedFooterModelRovingTabStop\([\s\S]*option\.tabIndex = option === target \? 0 : -1[\s\S]*restoreScopedControlContinuity[\s\S]*syncAdvancedFooterModelRovingTabStop\(\)/,
|
|
117
|
+
"footer rerenders should preserve one advanced roving tab stop",
|
|
118
|
+
);
|
|
119
|
+
assert.match(
|
|
120
|
+
app,
|
|
121
|
+
/let footerModelApplyInFlight = false[\s\S]*async function applyFooterModel\(model\)[\s\S]*footerModelApplyInFlight[\s\S]*footerModelPickerOpen = false[\s\S]*renderFooter\(\)[\s\S]*await api\("\/api\/model"[\s\S]*footerModelApplyInFlight = false/,
|
|
122
|
+
"model application should close synchronously and reject duplicate in-flight activation",
|
|
123
|
+
);
|
|
124
|
+
assert.match(
|
|
125
|
+
app,
|
|
126
|
+
/Drag within provider[\s\S]*Alt\+Up\/Down reorders[\s\S]*Home\/End[\s\S]*Enter\/Space[\s\S]*help\.id = "footerModelPickerHelp"[\s\S]*setAttribute\("aria-describedby", help\.id\)/,
|
|
127
|
+
"the picker should programmatically associate complete advanced reorder and keyboard help",
|
|
128
|
+
);
|
|
129
|
+
assert.match(
|
|
130
|
+
app,
|
|
131
|
+
/if \(advanced\) \{[\s\S]*handleAdvancedFooterModelKeydown\(event, model\)[\s\S]*\} else \{[\s\S]*event\.altKey[\s\S]*moveFooterScopedModelByOffset[\s\S]*\}\s*button\.addEventListener\("pointerdown", \(event\) => beginFooterScopedModelPointerDrag/,
|
|
132
|
+
"flat and advanced options should share pointer reordering while retaining their mode-specific keyboard handlers",
|
|
133
|
+
);
|
|
134
|
+
assert.match(
|
|
135
|
+
css,
|
|
136
|
+
/body\.footer-model-picker-open \.workspace-column \{[\s\S]*z-index:\s*112;[\s\S]*body\.footer-model-picker-open \.workspace-column > \.chat-panel,[\s\S]*overflow:\s*visible;/,
|
|
137
|
+
"an open picker should escape the chat-panel clip and stack its workspace above side panels",
|
|
138
|
+
);
|
|
139
|
+
assert.match(
|
|
140
|
+
css,
|
|
141
|
+
/\.footer-model-picker-advanced \{[\s\S]*width:\s*max-content;[\s\S]*max-width:\s*calc\(100vw - 1rem\);[\s\S]*\.footer-model-picker-advanced \.footer-model-picker-source \{[\s\S]*width:\s*100%;[\s\S]*max-width:\s*none;[\s\S]*\.footer-model-provider-columns \{[\s\S]*grid-auto-flow:\s*column;[\s\S]*grid-auto-columns:\s*13rem;[\s\S]*width:\s*fit-content;[\s\S]*max-width:\s*calc\(100vw - 2\.5rem\);[\s\S]*overflow:\s*auto;/,
|
|
142
|
+
"desktop advanced layout should give help text the full picker width, grow by provider count, stop at the viewport, and scroll internally",
|
|
143
|
+
);
|
|
144
|
+
assert.match(
|
|
145
|
+
css,
|
|
146
|
+
/\.footer-model-picker-advanced \.footer-model-option\[data-footer-model-key\] \{[\s\S]*cursor:\s*grab;[\s\S]*touch-action:\s*none;[\s\S]*user-select:\s*none;/,
|
|
147
|
+
"advanced models should expose draggable styling",
|
|
148
|
+
);
|
|
149
|
+
assert.match(
|
|
150
|
+
css,
|
|
151
|
+
/\.footer-model-provider-column:focus-within[\s\S]*\.footer-model-provider-title[\s\S]*\.footer-model-picker-advanced \.footer-model-option:focus-visible/,
|
|
152
|
+
"provider headings, focused columns, and focused models should remain visible",
|
|
153
|
+
);
|
|
154
|
+
assert.match(
|
|
155
|
+
css,
|
|
156
|
+
/@media \(max-width: 720px\), \(max-device-width: 720px\), \(pointer: coarse\) and \(hover: none\)[\s\S]*\.footer-model-picker-advanced \{[\s\S]*overflow:\s*hidden;[\s\S]*\.footer-model-provider-columns \{[\s\S]*grid-auto-flow:\s*row;[\s\S]*grid-template-columns:\s*minmax\(0, 1fr\);[\s\S]*overflow-x:\s*hidden;/,
|
|
157
|
+
"narrow advanced layout should stack providers and keep horizontal overflow inside the viewport",
|
|
158
|
+
);
|
|
159
|
+
|
|
58
160
|
console.log("git-footer-context-menu-static.test.mjs passed");
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
4
|
+
import { createServer } from "node:net";
|
|
5
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
6
|
+
import { tmpdir } from "node:os";
|
|
7
|
+
import { dirname, join } from "node:path";
|
|
8
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
10
|
+
|
|
11
|
+
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
12
|
+
const serverScript = join(root, "bin", "pi-webui.mjs");
|
|
13
|
+
const fakePi = join(root, "tests", "fixtures", "fake-pi.mjs");
|
|
14
|
+
const statusKey = "git-guided-workflow:webui-start";
|
|
15
|
+
|
|
16
|
+
async function freePort() {
|
|
17
|
+
const server = createServer();
|
|
18
|
+
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
19
|
+
const { port } = server.address();
|
|
20
|
+
await new Promise((resolve) => server.close(resolve));
|
|
21
|
+
return port;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function readEvents(url, { trigger, until, timeoutMs = 5000 } = {}) {
|
|
25
|
+
const controller = new AbortController();
|
|
26
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
27
|
+
const events = [];
|
|
28
|
+
try {
|
|
29
|
+
const response = await fetch(url, { signal: controller.signal });
|
|
30
|
+
assert.equal(response.status, 200);
|
|
31
|
+
const triggerPromise = trigger ? Promise.resolve().then(trigger) : Promise.resolve();
|
|
32
|
+
const reader = response.body.getReader();
|
|
33
|
+
const decoder = new TextDecoder();
|
|
34
|
+
let buffer = "";
|
|
35
|
+
while (true) {
|
|
36
|
+
const { done, value } = await reader.read();
|
|
37
|
+
if (done) break;
|
|
38
|
+
buffer += decoder.decode(value, { stream: true });
|
|
39
|
+
let boundary;
|
|
40
|
+
while ((boundary = buffer.indexOf("\n\n")) >= 0) {
|
|
41
|
+
const block = buffer.slice(0, boundary);
|
|
42
|
+
buffer = buffer.slice(boundary + 2);
|
|
43
|
+
const data = block.split("\n").filter((line) => line.startsWith("data:")).map((line) => line.slice(5).trim()).join("\n");
|
|
44
|
+
if (!data) continue;
|
|
45
|
+
const event = JSON.parse(data);
|
|
46
|
+
events.push(event);
|
|
47
|
+
if (until?.(events, event)) {
|
|
48
|
+
await triggerPromise;
|
|
49
|
+
controller.abort();
|
|
50
|
+
return events;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
await triggerPromise;
|
|
55
|
+
return events;
|
|
56
|
+
} catch (error) {
|
|
57
|
+
if (error?.name !== "AbortError") throw error;
|
|
58
|
+
return events;
|
|
59
|
+
} finally {
|
|
60
|
+
clearTimeout(timer);
|
|
61
|
+
controller.abort();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
test("Guided Git activation is delivered set-then-clear and is absent from reconnect replay", async () => {
|
|
66
|
+
const port = await freePort();
|
|
67
|
+
const cwd = await mkdtemp(join(tmpdir(), "pi-webui-guided-git-http-"));
|
|
68
|
+
assert.equal(spawnSync("git", ["init", "--quiet"], { cwd }).status, 0);
|
|
69
|
+
let output = "";
|
|
70
|
+
const child = spawn(process.execPath, [serverScript, "--cwd", cwd, "--host", "127.0.0.1", "--port", String(port), "--pi", fakePi], {
|
|
71
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
72
|
+
env: {
|
|
73
|
+
...process.env,
|
|
74
|
+
PI_WEBUI_RPC_SUPERVISOR: "0",
|
|
75
|
+
PI_CODING_AGENT_DIR: join(cwd, "agent"),
|
|
76
|
+
FAKE_PI_GUIDED_GIT_ACTIVATION: "1",
|
|
77
|
+
FAKE_PI_GUIDED_GIT_ACTIVATION_DELAY_MS: "150",
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
child.stdout.on("data", (chunk) => { output += String(chunk); });
|
|
81
|
+
child.stderr.on("data", (chunk) => { output += String(chunk); });
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
const base = `http://127.0.0.1:${port}`;
|
|
85
|
+
for (let attempt = 0; attempt < 100; attempt += 1) {
|
|
86
|
+
try {
|
|
87
|
+
const response = await fetch(`${base}/api/health`, { signal: AbortSignal.timeout(500) });
|
|
88
|
+
if (response.ok) break;
|
|
89
|
+
} catch {}
|
|
90
|
+
if (attempt === 99) throw new Error(`WebUI failed to start:\n${output}`);
|
|
91
|
+
await delay(100);
|
|
92
|
+
}
|
|
93
|
+
const tabs = await (await fetch(`${base}/api/tabs`)).json();
|
|
94
|
+
const tabId = tabs.data?.tabs?.[0]?.id;
|
|
95
|
+
assert.ok(tabId);
|
|
96
|
+
const eventsUrl = `${base}/api/events?tab=${encodeURIComponent(tabId)}`;
|
|
97
|
+
const launchId = "aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa";
|
|
98
|
+
const missingLaunch = await fetch(`${base}/api/prompt?tab=${encodeURIComponent(tabId)}`, {
|
|
99
|
+
method: "POST",
|
|
100
|
+
headers: { "Content-Type": "application/json" },
|
|
101
|
+
body: JSON.stringify({ message: "/git-guided-workflow", requestId: "guided-git-http-missing-launch" }),
|
|
102
|
+
});
|
|
103
|
+
assert.equal(missingLaunch.status, 400, "the exact command requires a validated browser launch UUID");
|
|
104
|
+
|
|
105
|
+
const events = await readEvents(eventsUrl, {
|
|
106
|
+
trigger: async () => {
|
|
107
|
+
const response = await fetch(`${base}/api/prompt?tab=${encodeURIComponent(tabId)}`, {
|
|
108
|
+
method: "POST",
|
|
109
|
+
headers: { "Content-Type": "application/json" },
|
|
110
|
+
body: JSON.stringify({ message: "/git-guided-workflow", requestId: "guided-git-http-12345678", guidedGitLaunchId: launchId }),
|
|
111
|
+
});
|
|
112
|
+
assert.equal(response.status, 200, await response.text());
|
|
113
|
+
const concurrent = await fetch(`${base}/api/prompt?tab=${encodeURIComponent(tabId)}`, {
|
|
114
|
+
method: "POST",
|
|
115
|
+
headers: { "Content-Type": "application/json" },
|
|
116
|
+
body: JSON.stringify({ message: "/git-guided-workflow:2", requestId: "guided-git-http-concurrent", guidedGitLaunchId: "bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb" }),
|
|
117
|
+
});
|
|
118
|
+
assert.equal(concurrent.status, 409, "a second pending guided launch must be rejected, never queued");
|
|
119
|
+
},
|
|
120
|
+
until: (all) => all.filter((event) => event.type === "extension_ui_request" && event.method === "setStatus" && event.statusKey === statusKey).length === 2,
|
|
121
|
+
});
|
|
122
|
+
const activationEvents = events.filter((event) => event.type === "extension_ui_request" && event.method === "setStatus" && event.statusKey === statusKey);
|
|
123
|
+
assert.equal(activationEvents.length, 2);
|
|
124
|
+
const canonicalPayload = JSON.parse(activationEvents[0].statusText);
|
|
125
|
+
assert.equal(canonicalPayload.action, "start");
|
|
126
|
+
assert.deepEqual(Object.keys(canonicalPayload).sort(), ["action", "requestId", "type", "version"], "the extension payload stays exact v1");
|
|
127
|
+
assert.equal(activationEvents[0].tabId, tabId);
|
|
128
|
+
assert.equal(activationEvents[0].guidedGitLaunchId, launchId, "the server adds correlation only to the trusted envelope");
|
|
129
|
+
assert.equal(activationEvents[1].statusText, undefined);
|
|
130
|
+
assert.equal(activationEvents[1].guidedGitLaunchId, undefined);
|
|
131
|
+
|
|
132
|
+
const replay = await readEvents(eventsUrl, { timeoutMs: 700 });
|
|
133
|
+
assert.equal(replay.some((event) => event.replayed === true && event.statusKey === statusKey), false, "cleared activation must not survive reconnect replay");
|
|
134
|
+
} finally {
|
|
135
|
+
if (child.exitCode === null) child.kill("SIGTERM");
|
|
136
|
+
if (child.exitCode === null) await new Promise((resolve) => child.once("exit", resolve));
|
|
137
|
+
await rm(cwd, { recursive: true, force: true });
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test("Guided Git authoritative admission rejects streaming, compaction, and pending messages before queueing", async () => {
|
|
142
|
+
for (const mode of ["streaming", "compacting", "pending"]) {
|
|
143
|
+
const port = await freePort();
|
|
144
|
+
const cwd = await mkdtemp(join(tmpdir(), `pi-webui-guided-git-${mode}-`));
|
|
145
|
+
assert.equal(spawnSync("git", ["init", "--quiet"], { cwd }).status, 0);
|
|
146
|
+
let output = "";
|
|
147
|
+
const child = spawn(process.execPath, [serverScript, "--cwd", cwd, "--host", "127.0.0.1", "--port", String(port), "--pi", fakePi], {
|
|
148
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
149
|
+
env: {
|
|
150
|
+
...process.env,
|
|
151
|
+
PI_WEBUI_RPC_SUPERVISOR: "0",
|
|
152
|
+
PI_CODING_AGENT_DIR: join(cwd, "agent"),
|
|
153
|
+
FAKE_PI_GUIDED_GIT_ACTIVATION: "1",
|
|
154
|
+
FAKE_PI_GUIDED_GIT_STATE: mode,
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
child.stdout.on("data", (chunk) => { output += String(chunk); });
|
|
158
|
+
child.stderr.on("data", (chunk) => { output += String(chunk); });
|
|
159
|
+
try {
|
|
160
|
+
const base = `http://127.0.0.1:${port}`;
|
|
161
|
+
for (let attempt = 0; attempt < 100; attempt += 1) {
|
|
162
|
+
try {
|
|
163
|
+
const response = await fetch(`${base}/api/health`, { signal: AbortSignal.timeout(500) });
|
|
164
|
+
if (response.ok) break;
|
|
165
|
+
} catch {}
|
|
166
|
+
if (attempt === 99) throw new Error(`WebUI failed to start for ${mode}:\n${output}`);
|
|
167
|
+
await delay(100);
|
|
168
|
+
}
|
|
169
|
+
const tabs = await (await fetch(`${base}/api/tabs`)).json();
|
|
170
|
+
const tabId = tabs.data?.tabs?.[0]?.id;
|
|
171
|
+
assert.ok(tabId);
|
|
172
|
+
const prompt = await fetch(`${base}/api/prompt?tab=${encodeURIComponent(tabId)}`, {
|
|
173
|
+
method: "POST",
|
|
174
|
+
headers: { "Content-Type": "application/json" },
|
|
175
|
+
body: JSON.stringify({
|
|
176
|
+
message: "/git-guided-workflow:2",
|
|
177
|
+
requestId: `guided-git-${mode}-request`,
|
|
178
|
+
guidedGitLaunchId: "cccccccc-cccc-4ccc-8ccc-cccccccccccc",
|
|
179
|
+
}),
|
|
180
|
+
});
|
|
181
|
+
assert.equal(prompt.status, 409, `${mode} exact command must be refused rather than returning 202`);
|
|
182
|
+
const legacy = await fetch(`${base}/api/git-workflow/launch-admission?tab=${encodeURIComponent(tabId)}`, {
|
|
183
|
+
method: "POST",
|
|
184
|
+
headers: { "Content-Type": "application/json" },
|
|
185
|
+
body: "{}",
|
|
186
|
+
});
|
|
187
|
+
assert.equal(legacy.status, 409, `${mode} legacy fallback admission must fail authoritatively`);
|
|
188
|
+
} finally {
|
|
189
|
+
if (child.exitCode === null) child.kill("SIGTERM");
|
|
190
|
+
if (child.exitCode === null) await new Promise((resolve) => child.once("exit", resolve));
|
|
191
|
+
await rm(cwd, { recursive: true, force: true });
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
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, state, server, html, serviceWorker, readme, technical, development, fakePi] = await Promise.all([
|
|
9
|
+
readFile(join(root, "public", "app.js"), "utf8"),
|
|
10
|
+
readFile(join(root, "public", "guided-git-command-state.mjs"), "utf8"),
|
|
11
|
+
readFile(join(root, "bin", "pi-webui.mjs"), "utf8"),
|
|
12
|
+
readFile(join(root, "public", "index.html"), "utf8"),
|
|
13
|
+
readFile(join(root, "public", "service-worker.js"), "utf8"),
|
|
14
|
+
readFile(join(root, "README.md"), "utf8"),
|
|
15
|
+
readFile(join(root, "TECHNICAL.md"), "utf8"),
|
|
16
|
+
readFile(join(root, "DEVELOPMENT.md"), "utf8"),
|
|
17
|
+
readFile(join(root, "tests", "fixtures", "fake-pi.mjs"), "utf8"),
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
test("Guided Git activation is intercepted before generic status rendering and bound to the envelope tab", () => {
|
|
21
|
+
assert.match(app, /function handleExtensionUiRequest\(request\) \{\n if \(handleGuidedGitActivationRequest\(request\)\) return;\n request\.tabId \|\|= activeTabId;/u);
|
|
22
|
+
assert.match(app, /function handleInactiveTabEvent\(event\) \{\n if \(handleGuidedGitActivationRequest\(event\)\) return;/u);
|
|
23
|
+
assert.match(app, /guidedGitActivationController\.consume\(request, async \(tabId, activationIsCurrent\)/u);
|
|
24
|
+
assert.match(app, /startGitWorkflow\(tabId, \{ activationIsCurrent \}\)/u, "tab reset or close must invalidate an asynchronous activation start");
|
|
25
|
+
assert.match(app, /openNativeGitWorkflowSetupDialog\(\{\s+tabId,\s+activationIsCurrent,\s+onSaved: \(\) => startGitWorkflow\(tabId, \{ skipSetup: true, activationIsCurrent \}\),\s+\}\)/u, "setup and its local continuation must preserve the envelope tab and the same activation owner");
|
|
26
|
+
assert.match(app, /async function openNativeGitWorkflowSetupDialog\(\{ onSaved, tabId = activeTabId, activationIsCurrent = \(\) => true \} = \{\}\)[\s\S]*nativeCommandTabId = tabId[\s\S]*nativeCommandApi\("\/api\/git-workflow\/preferences", \{ tabId \}\)[\s\S]*const targetState = tabId === activeTabId \? currentState : tabStateCache\.get\(tabId\)/u, "setup loads models and preferences only for the originating tab");
|
|
27
|
+
assert.match(app, /const setupOwner = Symbol\(tabId\);[\s\S]*const setupOwnsDialog = \(\) => guidedGitSetupDialogOwner === setupOwner;[\s\S]*const handleSetupClose = \(\) => \{\s+if \(!saveInFlight\) settleSetup\("cancelled"\);[\s\S]*if \(!activationIsCurrent\(\)\) \{\s+closeOwnedSetupDialog\(\);\s+settleSetup\("stale"\);/u, "Cancel must settle ownership, stale reset\/cwd\/session owners must fail closed, and an old response must not close a replacement setup dialog");
|
|
28
|
+
assert.match(app, /nativeCommandApi\("\/api\/git-workflow\/preferences", \{\s+method: "POST",\s+tabId,[\s\S]*if \(typeof onSaved === "function" && activationIsCurrent\(\)\)/u, "Save and its continuation must stay tab-bound and owner-guarded");
|
|
29
|
+
assert.match(app, /function resetGitWorkflowForTab[\s\S]*guidedGitLaunchPermits\.clearTab\(tabId\);[\s\S]*guidedGitActivationController\.clearTab\(tabId\);/u, "reset, cwd change, and new-session seams must invalidate permits and activation ownership together");
|
|
30
|
+
assert.doesNotMatch(state, /tabId.*JSON|cwd|repositoryPath/u, "the exact activation payload parser must not accept routing or repository data");
|
|
31
|
+
assert.match(state, /Object\.keys\(value\)\.sort\(\)/u);
|
|
32
|
+
assert.match(state, /request\?\.replayed === true/u);
|
|
33
|
+
assert.match(state, /maxSeenPerTab = 64, maxTrackedTabs = 64/u);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("all visible Guided Git entry points prefer the extension launcher without composer mutation", () => {
|
|
37
|
+
assert.match(app, /async function launchGuidedGitWorkflow\(tabId = activeTabId\)[\s\S]*!guidedGitLaunchAdmitted\(tabId\)[\s\S]*guidedGitLaunchModeForTabCatalog\(commandCatalogForTab\(tabId\)[\s\S]*resolveAvailableCommandName\("git-guided-workflow", \{ tabId, rpcOnly: true \}\)[\s\S]*sendPrompt\("prompt", `\/\$\{commandName\}`, \{ targetTabId: tabId, throwOnError: true \}\)/u);
|
|
38
|
+
assert.match(app, /Guided Git workflow"[\s\S]{0,180}run: \(\) => launchGuidedGitWorkflow\(\)/u, "command palette must use the launcher");
|
|
39
|
+
assert.match(app, /elements\.gitWorkflowButton\.addEventListener\("click"[\s\S]{0,160}launchGuidedGitWorkflow\(\)/u, "composer and mobile-proxied button must use the launcher");
|
|
40
|
+
assert.match(app, /addGitWorkflowAction\("Start another", \(\) => launchGuidedGitWorkflow\(gitWorkflowActionTabId\(\)\)/u);
|
|
41
|
+
assert.match(app, /addGitWorkflowAction\("Restart", \(\) => launchGuidedGitWorkflow\(gitWorkflowActionTabId\(\)\)/u);
|
|
42
|
+
assert.match(app, /const usesPromptInput = explicitMessage === undefined;/u);
|
|
43
|
+
assert.match(app, /function clearPromptInputForRouting\(\{ usesPromptInput[\s\S]{0,160}if \(!usesPromptInput\) return;/u, "explicit command dispatch must preserve composer draft and attachments");
|
|
44
|
+
assert.match(app, /const guidedGitExtensionLaunch = kind === "prompt"[\s\S]*guidedGitWorkflowCommandForTabCatalog\(commandCatalogForTab\(targetTabId\), originalMessage\)[\s\S]*if \(!guidedGitLaunchAdmitted\(targetTabId\)\) return;[\s\S]*guidedGitLaunchPermits\.grant\(targetTabId, guidedGitLaunchId\)/u, "typed commands must refuse before generic busy queue routing and grant one correlated origin-client permit");
|
|
45
|
+
assert.match(app, /if \(promptRoutingTabs\.has\(tabId\)\) return "pending";/u, "an unresolved local prompt handoff must refuse another Guided Git launch");
|
|
46
|
+
assert.match(app, /if \(guidedGitLaunchId\) bodyBase\.guidedGitLaunchId = guidedGitLaunchId;/u, "only exact guided commands add the dedicated launch field");
|
|
47
|
+
assert.match(app, /const targetState = targetTabId === activeTabId \? currentState : tabStateCache\.get\(targetTabId\);\s+const targetWasStreaming = !!targetState\?\.isStreaming;/u, "prompt routing must inspect the captured target tab rather than whichever tab becomes active later");
|
|
48
|
+
assert.match(app, /guidedGitLaunchBlockedReason\(guidedGitLaunchStateForTab\(tabId\), queueMessageCount\(queuedSnapshotForTab\(tabId\)\)\)/u, "busy admission must include streaming, compaction, canonical pending count, and the real tab-local queue snapshot");
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("temporary fallback and prompt capabilities are explicit and tab-local", () => {
|
|
52
|
+
assert.match(app, /async function startLegacyGuidedGitWorkflowFallback\(tabId\) \{\s+if \(!guidedGitLaunchAdmitted\(tabId\)\) return;[\s\S]*api\("\/api\/git-workflow\/launch-admission", \{ method: "POST", body: \{\}, tabId \}\)/u, "the direct compatibility fallback must receive authoritative server admission immediately before local start");
|
|
53
|
+
assert.match(app, /if \(launchMode === "fallback"\) \{\n await startLegacyGuidedGitWorkflowFallback\(tabId\);/u);
|
|
54
|
+
assert.match(state, /function guidedGitLaunchModeForTabCatalog[\s\S]*return "extension"[\s\S]*return "fallback"[\s\S]*return "unavailable"/u);
|
|
55
|
+
assert.match(state, /createGuidedGitLaunchPermitController\(\{ maxTrackedTabs = 64, permitTtlMs = 15_000 \}/u);
|
|
56
|
+
assert.match(app, /claimStart: \(tabId, _payload, request, now\) => guidedGitLaunchPermits\.consume\(tabId, request\?\.guidedGitLaunchId, now\)/u, "only the browser client holding the exact envelope-correlated permit may claim activation");
|
|
57
|
+
assert.match(server, /GUIDED_GIT_COMMAND_MESSAGE = .*git-guided-workflow.*\\d/u);
|
|
58
|
+
assert.match(server, /authoritativeGuidedGitLaunchAdmission\(tab, \{ launchId: guidedGitLaunchId, reserve: true \}\)[\s\S]*queuedForCompaction = guidedGitLaunch \? null : maybeQueueCommandDuringCompaction/u, "the exact command must reserve authoritatively before and bypass generic compaction queueing");
|
|
59
|
+
assert.match(server, /scopedGuidedGitLaunchEvent\(tab, eventForTabClients\(tab, event\)\)/u);
|
|
60
|
+
assert.match(server, /return \{ \.\.\.event, guidedGitLaunchId: pending\.launchId \};/u, "browser launch correlation belongs only to the trusted transport envelope");
|
|
61
|
+
assert.match(server, /GUIDED_GIT_LAUNCH_TTL_MS = 15_000/u);
|
|
62
|
+
assert.match(server, /guidedGitPendingLaunch: null/u, "pending launch state is bounded to one record per tab and dies with the tab");
|
|
63
|
+
assert.match(app, /temporary prompt-only Guided Git compatibility launcher/u);
|
|
64
|
+
assert.match(app, /hasLoadedRpcCommand\("git-staged-msg", \{ tabId \}\)/u);
|
|
65
|
+
assert.match(app, /hasLoadedRpcCommand\("git-branch-name", \{ tabId \}\)/u);
|
|
66
|
+
assert.match(app, /hasLoadedRpcCommand\("pr", \{ tabId \}\)/u);
|
|
67
|
+
assert.match(app, /packageName: "@firstpick\/pi-extension-git-guided-workflow"[\s\S]*Browser generation also requires @firstpick\/pi-prompts-git-pr/u);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("fixture, cache revisions, and layered docs expose the migration contract", () => {
|
|
71
|
+
assert.match(fakePi, /FAKE_PI_GUIDED_GIT_ACTIVATION/u);
|
|
72
|
+
assert.match(fakePi, /git-guided-workflow:webui-start/u);
|
|
73
|
+
assert.match(html, /styles\.css\?v=142/u);
|
|
74
|
+
assert.match(html, /app\.js\?v=172/u);
|
|
75
|
+
assert.match(serviceWorker, /pi-webui-pwa-v139/u);
|
|
76
|
+
assert.match(serviceWorker, /"\/guided-git-command-state\.mjs"/u);
|
|
77
|
+
assert.match(readme, /pi-extension-git-guided-workflow/u);
|
|
78
|
+
assert.match(technical, /\/git-guided-workflow/u);
|
|
79
|
+
assert.match(development, /git-guided-workflow:webui-start/u);
|
|
80
|
+
});
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import {
|
|
4
|
+
GUIDED_GIT_START_PAYLOAD_MAX_BYTES,
|
|
5
|
+
GUIDED_GIT_START_PAYLOAD_TYPE,
|
|
6
|
+
GUIDED_GIT_START_PAYLOAD_VERSION,
|
|
7
|
+
GUIDED_GIT_START_STATUS_KEY,
|
|
8
|
+
createGuidedGitActivationController,
|
|
9
|
+
createGuidedGitLaunchPermitController,
|
|
10
|
+
guidedGitLaunchBlockedReason,
|
|
11
|
+
guidedGitLaunchModeForTabCatalog,
|
|
12
|
+
guidedGitWorkflowCommandForTabCatalog,
|
|
13
|
+
parseGuidedGitStartPayload,
|
|
14
|
+
resolveCommandForTabCatalog,
|
|
15
|
+
resolveRpcSlashCommandForTabCatalog,
|
|
16
|
+
} from "../public/guided-git-command-state.mjs";
|
|
17
|
+
|
|
18
|
+
const ids = [
|
|
19
|
+
"11111111-1111-4111-8111-111111111111",
|
|
20
|
+
"22222222-2222-4222-8222-222222222222",
|
|
21
|
+
"33333333-3333-4333-8333-333333333333",
|
|
22
|
+
"44444444-4444-4444-8444-444444444444",
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
function payload(requestId = ids[0], patch = {}) {
|
|
26
|
+
return JSON.stringify({
|
|
27
|
+
type: GUIDED_GIT_START_PAYLOAD_TYPE,
|
|
28
|
+
version: GUIDED_GIT_START_PAYLOAD_VERSION,
|
|
29
|
+
action: "start",
|
|
30
|
+
requestId,
|
|
31
|
+
...patch,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function request(tabId, requestId = ids[0], patch = {}) {
|
|
36
|
+
return {
|
|
37
|
+
method: "setStatus",
|
|
38
|
+
statusKey: GUIDED_GIT_START_STATUS_KEY,
|
|
39
|
+
statusText: payload(requestId),
|
|
40
|
+
tabId,
|
|
41
|
+
...patch,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
test("Guided Git activation parser accepts only the exact bounded v1 payload", () => {
|
|
46
|
+
assert.deepEqual(parseGuidedGitStartPayload(payload()), {
|
|
47
|
+
type: GUIDED_GIT_START_PAYLOAD_TYPE,
|
|
48
|
+
version: 1,
|
|
49
|
+
action: "start",
|
|
50
|
+
requestId: ids[0],
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
for (const invalid of [
|
|
54
|
+
"",
|
|
55
|
+
"not json",
|
|
56
|
+
"[]",
|
|
57
|
+
JSON.stringify(null),
|
|
58
|
+
payload(ids[0], { type: "other" }),
|
|
59
|
+
payload(ids[0], { version: 2 }),
|
|
60
|
+
payload(ids[0], { action: "restart" }),
|
|
61
|
+
payload("not-a-uuid"),
|
|
62
|
+
payload(ids[0], { extra: true }),
|
|
63
|
+
"x".repeat(GUIDED_GIT_START_PAYLOAD_MAX_BYTES + 1),
|
|
64
|
+
]) assert.equal(parseGuidedGitStartPayload(invalid), null, `rejected: ${invalid.slice(0, 80)}`);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("browser-local launch permits correlate one exact envelope and remain bounded", async () => {
|
|
68
|
+
const originPermits = createGuidedGitLaunchPermitController({ maxTrackedTabs: 2, permitTtlMs: 50 });
|
|
69
|
+
const otherClientPermits = createGuidedGitLaunchPermitController({ maxTrackedTabs: 2, permitTtlMs: 50 });
|
|
70
|
+
const origin = createGuidedGitActivationController({ claimStart: (tabId, _payload, event, now) => originPermits.consume(tabId, event?.guidedGitLaunchId, now) });
|
|
71
|
+
const otherClient = createGuidedGitActivationController({ claimStart: (tabId, _payload, event, now) => otherClientPermits.consume(tabId, event?.guidedGitLaunchId, now) });
|
|
72
|
+
const starts = [];
|
|
73
|
+
|
|
74
|
+
assert.equal(originPermits.grant("tab-a", ids[1], 100), true);
|
|
75
|
+
assert.equal(otherClientPermits.grant("tab-a", ids[2], 100), true, "two browser clients may independently await server arbitration");
|
|
76
|
+
assert.equal(originPermits.grant("tab-a", ids[3], 101), false, "one browser cannot queue multiple permits for one tab");
|
|
77
|
+
const correlated = request("tab-a", ids[0], { guidedGitLaunchId: ids[1] });
|
|
78
|
+
assert.equal(otherClient.consume(correlated, async () => starts.push("other"), 102).status, "unclaimed", "a concurrent client cannot cross-claim another launch");
|
|
79
|
+
assert.equal(otherClientPermits.inspect().launchIdForTab("tab-a"), ids[2], "wrong envelopes do not consume orphan permits");
|
|
80
|
+
const claimed = origin.consume(correlated, async () => starts.push("origin"), 102);
|
|
81
|
+
assert.equal(claimed.status, "started");
|
|
82
|
+
await claimed.promise;
|
|
83
|
+
assert.deepEqual(starts, ["origin"]);
|
|
84
|
+
assert.equal(originPermits.inspect().hasPermit("tab-a"), false);
|
|
85
|
+
assert.equal(otherClient.consume(request("tab-a", ids[1]), async () => starts.push("missing"), 103).status, "unclaimed", "a missing launch envelope fails closed");
|
|
86
|
+
assert.equal(otherClient.consume(request("tab-a", ids[2], { guidedGitLaunchId: ids[3] }), async () => starts.push("wrong"), 104).status, "unclaimed", "a wrong launch envelope fails closed");
|
|
87
|
+
|
|
88
|
+
assert.equal(otherClientPermits.consume("tab-a", ids[2], 151), false, "expired permits fail closed");
|
|
89
|
+
assert.equal(originPermits.grant("tab-a", ids[0], 300), true);
|
|
90
|
+
assert.equal(originPermits.grant("tab-b", ids[1], 301), true);
|
|
91
|
+
assert.equal(originPermits.grant("tab-c", ids[2], 302), true);
|
|
92
|
+
assert.equal(originPermits.inspect().trackedTabs, 2);
|
|
93
|
+
assert.equal(originPermits.inspect().hasPermit("tab-a"), false, "oldest tab permit is evicted at the count bound");
|
|
94
|
+
originPermits.clearTab("tab-b");
|
|
95
|
+
assert.equal(originPermits.inspect().hasPermit("tab-b"), false);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test("Guided Git launch admission recognizes tab-local aliases and refuses every non-idle state", () => {
|
|
99
|
+
const catalog = {
|
|
100
|
+
raw: [{ name: "git-guided-workflow:2", source: "extension", invokeName: "git-guided-workflow:2", duplicateCount: 2 }],
|
|
101
|
+
available: [{ name: "git-guided-workflow", source: "extension", invokeName: "git-guided-workflow:2", duplicateNames: ["git-guided-workflow:2"], duplicateCount: 2 }],
|
|
102
|
+
};
|
|
103
|
+
assert.equal(guidedGitWorkflowCommandForTabCatalog(catalog, "/git-guided-workflow"), true);
|
|
104
|
+
assert.equal(guidedGitWorkflowCommandForTabCatalog(catalog, "/git-guided-workflow:2"), true);
|
|
105
|
+
assert.equal(guidedGitWorkflowCommandForTabCatalog(catalog, "/git-guided-workflow extra"), false);
|
|
106
|
+
assert.equal(guidedGitWorkflowCommandForTabCatalog(catalog, "/other"), false);
|
|
107
|
+
assert.equal(guidedGitLaunchBlockedReason(null, 0), "state-unavailable");
|
|
108
|
+
assert.equal(guidedGitLaunchBlockedReason({ isStreaming: true, isCompacting: false, pendingMessageCount: 0 }, 0), "streaming");
|
|
109
|
+
assert.equal(guidedGitLaunchBlockedReason({ isStreaming: false, isCompacting: true, pendingMessageCount: 0 }, 0), "compacting");
|
|
110
|
+
assert.equal(guidedGitLaunchBlockedReason({ isStreaming: false, isCompacting: false, pendingMessageCount: 1 }, 0), "pending");
|
|
111
|
+
assert.equal(guidedGitLaunchBlockedReason({ isStreaming: false, isCompacting: false, pendingMessageCount: 0 }, 1), "pending");
|
|
112
|
+
assert.equal(guidedGitLaunchBlockedReason({ isStreaming: false, isCompacting: false, pendingMessageCount: 0 }, 0), "");
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test("activation controller ignores clear and replay, deduplicates per tab, and clears tab state", async () => {
|
|
116
|
+
const controller = createGuidedGitActivationController();
|
|
117
|
+
const starts = [];
|
|
118
|
+
const start = async (tabId) => { starts.push(tabId); };
|
|
119
|
+
|
|
120
|
+
assert.equal(controller.consume({ tabId: "tab-a", statusText: undefined }, start).status, "ignored");
|
|
121
|
+
assert.equal(controller.consume(request("tab-a", ids[0], { replayed: true }), start).status, "ignored");
|
|
122
|
+
const first = controller.consume(request("tab-a"), start, 100);
|
|
123
|
+
assert.equal(first.status, "started");
|
|
124
|
+
await first.promise;
|
|
125
|
+
assert.equal(controller.consume(request("tab-a"), start, 101).status, "duplicate");
|
|
126
|
+
const otherTab = controller.consume(request("tab-b"), start, 102);
|
|
127
|
+
assert.equal(otherTab.status, "started");
|
|
128
|
+
await otherTab.promise;
|
|
129
|
+
assert.deepEqual(starts, ["tab-a", "tab-b"]);
|
|
130
|
+
|
|
131
|
+
controller.clearTab("tab-a");
|
|
132
|
+
const afterClear = controller.consume(request("tab-a"), start, 103);
|
|
133
|
+
assert.equal(afterClear.status, "started");
|
|
134
|
+
await afterClear.promise;
|
|
135
|
+
assert.equal(controller.inspect().seenForTab("tab-a"), 1);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test("clearing a tab invalidates ownership held by an asynchronous start", async () => {
|
|
139
|
+
const controller = createGuidedGitActivationController();
|
|
140
|
+
let release;
|
|
141
|
+
const blocked = new Promise((resolve) => { release = resolve; });
|
|
142
|
+
let activationIsCurrent;
|
|
143
|
+
const promise = controller.run("tab-a", async (_tabId, isCurrent) => {
|
|
144
|
+
activationIsCurrent = isCurrent;
|
|
145
|
+
await blocked;
|
|
146
|
+
});
|
|
147
|
+
await Promise.resolve();
|
|
148
|
+
assert.equal(activationIsCurrent(), true);
|
|
149
|
+
controller.clearTab("tab-a");
|
|
150
|
+
assert.equal(activationIsCurrent(), false);
|
|
151
|
+
release();
|
|
152
|
+
await promise;
|
|
153
|
+
assert.equal(controller.inspect().inFlightTabs, 0);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test("activation controller folds rapid distinct starts and keeps dedupe storage bounded", async () => {
|
|
157
|
+
const controller = createGuidedGitActivationController({ maxSeenPerTab: 2, maxTrackedTabs: 2, seenTtlMs: 50 });
|
|
158
|
+
let release;
|
|
159
|
+
const blocked = new Promise((resolve) => { release = resolve; });
|
|
160
|
+
let starts = 0;
|
|
161
|
+
const start = async () => { starts += 1; await blocked; };
|
|
162
|
+
|
|
163
|
+
const first = controller.consume(request("tab-a", ids[0]), start, 100);
|
|
164
|
+
const folded = controller.consume(request("tab-a", ids[1]), start, 101);
|
|
165
|
+
assert.equal(first.status, "started");
|
|
166
|
+
assert.equal(folded.status, "folded");
|
|
167
|
+
assert.equal(first.promise, folded.promise);
|
|
168
|
+
await Promise.resolve();
|
|
169
|
+
assert.equal(starts, 1);
|
|
170
|
+
release();
|
|
171
|
+
await first.promise;
|
|
172
|
+
|
|
173
|
+
const third = controller.consume(request("tab-a", ids[2]), async () => {}, 102);
|
|
174
|
+
await third.promise;
|
|
175
|
+
assert.equal(controller.inspect().seenForTab("tab-a"), 2);
|
|
176
|
+
const evicted = controller.consume(request("tab-a", ids[0]), async () => {}, 103);
|
|
177
|
+
assert.equal(evicted.status, "started", "oldest per-tab request is evicted at the bound");
|
|
178
|
+
await evicted.promise;
|
|
179
|
+
|
|
180
|
+
await controller.consume(request("tab-b", ids[0]), async () => {}, 104).promise;
|
|
181
|
+
await controller.consume(request("tab-c", ids[0]), async () => {}, 105).promise;
|
|
182
|
+
assert.equal(controller.inspect().trackedTabs, 2);
|
|
183
|
+
|
|
184
|
+
const expired = controller.consume(request("tab-c", ids[0]), async () => {}, 200);
|
|
185
|
+
assert.equal(expired.status, "started", "expired request IDs may be accepted again");
|
|
186
|
+
await expired.promise;
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
test("originating tab stays authoritative across an active-tab switch", async () => {
|
|
190
|
+
const controller = createGuidedGitActivationController();
|
|
191
|
+
let activeTabId = "tab-a";
|
|
192
|
+
let release;
|
|
193
|
+
const blocked = new Promise((resolve) => { release = resolve; });
|
|
194
|
+
let startedTabId = "";
|
|
195
|
+
const start = controller.consume(request("tab-a"), async (tabId) => {
|
|
196
|
+
await blocked;
|
|
197
|
+
startedTabId = tabId;
|
|
198
|
+
});
|
|
199
|
+
activeTabId = "tab-b";
|
|
200
|
+
release();
|
|
201
|
+
await start.promise;
|
|
202
|
+
assert.equal(activeTabId, "tab-b");
|
|
203
|
+
assert.equal(startedTabId, "tab-a", "the transport envelope tab, not the active browser tab, owns activation");
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
test("RPC resolution falls back to extension aliases when native commands own the base names", () => {
|
|
207
|
+
const catalog = {
|
|
208
|
+
raw: [
|
|
209
|
+
{ name: "skills", source: "native", invokeName: "skills" },
|
|
210
|
+
{ name: "skills:1", source: "extension", invokeName: "skills:1" },
|
|
211
|
+
{ name: "tools", source: "native", invokeName: "tools" },
|
|
212
|
+
{ name: "tools:1", source: "extension", invokeName: "tools:1" },
|
|
213
|
+
],
|
|
214
|
+
available: [
|
|
215
|
+
{ name: "skills", source: "native", invokeName: "skills" },
|
|
216
|
+
{ name: "skills:1", source: "extension", invokeName: "skills:1" },
|
|
217
|
+
{ name: "tools", source: "native", invokeName: "tools" },
|
|
218
|
+
{ name: "tools:1", source: "extension", invokeName: "tools:1" },
|
|
219
|
+
],
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
assert.equal(resolveCommandForTabCatalog(catalog, "skills", { rpcOnly: true })?.name, "skills:1");
|
|
223
|
+
assert.equal(resolveCommandForTabCatalog(catalog, "tools", { rpcOnly: true })?.name, "tools:1");
|
|
224
|
+
assert.equal(resolveRpcSlashCommandForTabCatalog(catalog, "/skills"), "/skills:1");
|
|
225
|
+
assert.equal(resolveRpcSlashCommandForTabCatalog(catalog, "/tools list"), "/tools:1 list");
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
test("tab catalog resolves the duplicate-suffixed command and the exact fallback eligibility", () => {
|
|
229
|
+
const catalog = {
|
|
230
|
+
raw: [
|
|
231
|
+
{ name: "git-guided-workflow:2", source: "extension", invokeName: "git-guided-workflow:2", duplicateCount: 2 },
|
|
232
|
+
{ name: "git-staged-msg", source: "prompt" },
|
|
233
|
+
],
|
|
234
|
+
available: [
|
|
235
|
+
{ name: "git-guided-workflow", source: "extension", invokeName: "git-guided-workflow:2", duplicateNames: ["git-guided-workflow:2"], duplicateCount: 2 },
|
|
236
|
+
{ name: "git-staged-msg", source: "prompt" },
|
|
237
|
+
],
|
|
238
|
+
};
|
|
239
|
+
assert.equal(resolveCommandForTabCatalog(catalog, "git-guided-workflow", { rpcOnly: true })?.name, "git-guided-workflow:2");
|
|
240
|
+
assert.equal(guidedGitLaunchModeForTabCatalog(catalog), "extension");
|
|
241
|
+
assert.equal(guidedGitLaunchModeForTabCatalog({ raw: [{ name: "git-staged-msg", source: "prompt" }] }), "fallback");
|
|
242
|
+
assert.equal(guidedGitLaunchModeForTabCatalog({ raw: [] }), "unavailable");
|
|
243
|
+
assert.equal(guidedGitLaunchModeForTabCatalog(catalog, { disabled: true }), "disabled");
|
|
244
|
+
});
|
|
@@ -373,6 +373,7 @@ await runScenario("artifact-primary-then-fallback", async ({ request, readLog })
|
|
|
373
373
|
await waitFor(async () => (await readLog()).some((entry) => entry.type === "set_model" && entry.modelId === "fallback"), "fallback should begin after primary artifacts");
|
|
374
374
|
const intermediate = await request(`/api/git-workflow/message?generationId=${encodeURIComponent(generationId)}`);
|
|
375
375
|
assert.equal(intermediate.body.data.ready, false, "failed-primary artifacts must remain pending while fallback runs");
|
|
376
|
+
assert.equal(intermediate.body.data.running, true, "the browser must be told that the correlated fallback generation is still active");
|
|
376
377
|
await waitFor(async () => (await readLog()).some((entry) => entry.type === "set_model" && entry.modelId === "original"), "fallback artifact generation should settle");
|
|
377
378
|
const final = await request(`/api/git-workflow/message?generationId=${encodeURIComponent(generationId)}`);
|
|
378
379
|
assert.equal(final.body.data.ready, true);
|