@firstpick/pi-package-webui 0.7.9 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -9
- package/bin/pi-webui.mjs +750 -113
- package/lib/git-workflow-preferences.mjs +16 -0
- package/lib/git-worktrees.mjs +43 -4
- package/lib/npm-command.mjs +81 -0
- package/lib/queue-mutation.mjs +6 -0
- package/lib/workspace-files-live-watcher.mjs +138 -0
- package/package.json +11 -4
- package/public/app.js +3397 -380
- package/public/index.html +119 -20
- package/public/mobile-shell-state.mjs +166 -0
- package/public/service-worker.js +60 -13
- package/public/styles.css +1066 -362
- package/public/subagent-gate-visibility.mjs +16 -0
- package/public/subagent-launch-slot-state.mjs +16 -0
- package/public/transcript-renderer.mjs +433 -0
- package/tests/boot-failure-diagnostics.test.mjs +3 -3
- package/tests/browser/interaction-continuity.spec.mjs +739 -0
- package/tests/browser/mobile-foundation.spec.mjs +352 -0
- package/tests/browser/optimistic-prompt.spec.mjs +130 -0
- package/tests/chat-scroll-intent-static.test.mjs +6 -1
- package/tests/codex-fast-mode-static.test.mjs +59 -0
- package/tests/compact-sections-static.test.mjs +20 -2
- package/tests/compaction-mutation-contract.test.mjs +18 -4
- package/tests/compaction-static.test.mjs +1 -0
- package/tests/completion-signal-contract.test.mjs +13 -2
- package/tests/composer-skill-tag-layout.test.mjs +70 -0
- package/tests/fast-mode-client-static.test.mjs +14 -11
- package/tests/fixtures/fake-pi.mjs +222 -2
- package/tests/git-panel-gitignore-static.test.mjs +104 -0
- package/tests/git-workflow-preferences.test.mjs +8 -0
- package/tests/guided-git-publication-backend-static.test.mjs +40 -0
- package/tests/http-endpoints-harness.test.mjs +490 -3
- package/tests/interaction-state-stability-static.test.mjs +254 -0
- package/tests/mobile-continuity-tablet-static.test.mjs +55 -0
- package/tests/mobile-foundation-static.test.mjs +69 -0
- package/tests/mobile-phone-experience-static.test.mjs +65 -0
- package/tests/mobile-shell-state.test.mjs +69 -0
- package/tests/mobile-static.test.mjs +300 -43
- package/tests/mobile-transcript-cache-characterization.test.mjs +34 -0
- package/tests/npm-command.test.mjs +64 -1
- package/tests/open-issue-wizard-static.test.mjs +2 -1
- package/tests/queue-edit-reorder-static.test.mjs +9 -1
- package/tests/queue-mutation-contract.test.mjs +22 -0
- package/tests/service-worker-lifecycle.test.mjs +120 -0
- package/tests/side-panel-resize-static.test.mjs +8 -1
- package/tests/sse-backpressure-harness.test.mjs +98 -0
- package/tests/streaming-ui-coupling.test.mjs +7 -1
- package/tests/subagent-gate-visibility.test.mjs +18 -2
- package/tests/subagent-launch-slot-state.test.mjs +32 -0
- package/tests/subagent-launch-slots-static.test.mjs +8 -2
- package/tests/subagents-helper.test.mjs +90 -0
- package/tests/terminal-tab-workspace-static.test.mjs +1 -1
- package/tests/update-commands.test.mjs +4 -0
- package/tests/workspace-files-live-updates-static.test.mjs +76 -0
- package/tests/workspace-files-live-watcher.test.mjs +95 -0
- package/webui-rpc-helper.mjs +175 -3
|
@@ -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, mkdir, mkdtemp, readFile, rename, rm, stat, symlink, writeFile } from "node:fs/promises";
|
|
4
|
+
import { chmod, link, mkdir, mkdtemp, readFile, 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";
|
|
@@ -228,6 +228,26 @@ try {
|
|
|
228
228
|
assert.equal(health.body.piRunning, true, "fake pi RPC process should be attached and running");
|
|
229
229
|
assert.match(health.body.piVersion, /^\d+\.\d+\.\d+/, "health metadata should expose the installed Pi version");
|
|
230
230
|
|
|
231
|
+
const initialInterfacePreferences = await request("127.0.0.1", "/api/interface-preferences");
|
|
232
|
+
assert.equal(initialInterfacePreferences.status, 200);
|
|
233
|
+
assert.equal(initialInterfacePreferences.body?.data?.preferences?.sidePanelWidth, null, "a user without a saved width should receive the default preference");
|
|
234
|
+
assert.equal(Object.hasOwn(initialInterfacePreferences.body?.data || {}, "path"), false, "preference responses must not disclose the user's settings-file path");
|
|
235
|
+
const savedInterfacePreferences = await request("127.0.0.1", "/api/interface-preferences", {
|
|
236
|
+
method: "PUT",
|
|
237
|
+
body: { sidePanelWidth: 612.4 },
|
|
238
|
+
});
|
|
239
|
+
assert.equal(savedInterfacePreferences.status, 200);
|
|
240
|
+
assert.equal(savedInterfacePreferences.body?.data?.preferences?.sidePanelWidth, 612, "saved side-panel widths should be normalized to whole pixels");
|
|
241
|
+
assert.equal(JSON.parse(await readFile(settingsFile, "utf8")).interfacePreferences?.sidePanelWidth, 612, "the side-panel width should be saved in the private user settings file");
|
|
242
|
+
const reloadedInterfacePreferences = await request("127.0.0.1", "/api/interface-preferences");
|
|
243
|
+
assert.equal(reloadedInterfacePreferences.body?.data?.preferences?.sidePanelWidth, 612, "the saved width should survive subsequent user preference reads");
|
|
244
|
+
const invalidInterfacePreferences = await request("127.0.0.1", "/api/interface-preferences", {
|
|
245
|
+
method: "PUT",
|
|
246
|
+
body: { sidePanelWidth: 100 },
|
|
247
|
+
});
|
|
248
|
+
assert.equal(invalidInterfacePreferences.status, 400, "out-of-range side-panel widths should be rejected");
|
|
249
|
+
assert.equal((await request("127.0.0.1", "/api/interface-preferences")).body?.data?.preferences?.sidePanelWidth, 612, "invalid saves must preserve the last valid user width");
|
|
250
|
+
|
|
231
251
|
// Workflow policy setup is server-scoped: missing policy reads as canonical
|
|
232
252
|
// deny-default state without creating PI_CODING_AGENT_DIR or its policy file.
|
|
233
253
|
const missingWorkflowPolicy = await request("127.0.0.1", "/api/workflow-policy");
|
|
@@ -391,6 +411,26 @@ try {
|
|
|
391
411
|
const tabId = tabList[0].id;
|
|
392
412
|
assert.ok(tabId, "tab should have an id");
|
|
393
413
|
|
|
414
|
+
const dedupTabResponse = await request("127.0.0.1", "/api/tabs", { method: "POST", body: { cwd, title: "mobile-request-dedup" } });
|
|
415
|
+
assert.equal(dedupTabResponse.status, 201, "mobile request deduplication test tab should open");
|
|
416
|
+
const dedupTabId = dedupTabResponse.body?.data?.tab?.id;
|
|
417
|
+
const requestId = "mobile_request_1234567890";
|
|
418
|
+
const requestBody = { tab: dedupTabId, message: "mobile request dedup fixture", requestId };
|
|
419
|
+
const [firstPrompt, duplicatePrompt] = await Promise.all([
|
|
420
|
+
request("127.0.0.1", "/api/prompt", { method: "POST", body: requestBody }),
|
|
421
|
+
request("127.0.0.1", "/api/prompt", { method: "POST", body: requestBody }),
|
|
422
|
+
]);
|
|
423
|
+
assert.equal(firstPrompt.status, 200, "the first browser-identified prompt should dispatch");
|
|
424
|
+
assert.equal(duplicatePrompt.status, 200, "a known browser request should return the retained result");
|
|
425
|
+
const duplicateReuse = await request("127.0.0.1", "/api/prompt", { method: "POST", body: { ...requestBody, message: "different prompt" } });
|
|
426
|
+
assert.equal(duplicateReuse.status, 409, "a request ID cannot be reused for a different mutation");
|
|
427
|
+
const dedupCommands = (await readJsonLines(fakePiCommandLog)).filter((entry) => entry.direction === "command" && entry.message === "mobile request dedup fixture");
|
|
428
|
+
assert.equal(dedupCommands.length, 1, "duplicate browser prompt identities must reach Pi exactly once");
|
|
429
|
+
const dedupTabs = await request("127.0.0.1", "/api/tabs");
|
|
430
|
+
const dedupActivity = dedupTabs.body?.data?.tabs?.find((tab) => tab.id === dedupTabId)?.activity;
|
|
431
|
+
assert.match(dedupActivity?.runId || "", /^[0-9a-f-]{36}$/i, "active parent work must expose a server-issued opaque run ID");
|
|
432
|
+
assert.equal((await request("127.0.0.1", "/api/tabs/close", { method: "POST", body: { ids: [dedupTabId] } })).status, 200, "mobile request deduplication test tab should close");
|
|
433
|
+
|
|
394
434
|
const runtimeQueueBefore = { steering: ["runtime steering"], followUp: ["runtime first", "runtime second", "runtime third"] };
|
|
395
435
|
const runtimeQueueEdit = await waitForSseEvent(
|
|
396
436
|
tabId,
|
|
@@ -442,6 +482,19 @@ try {
|
|
|
442
482
|
assert.equal(runtimeQueueMove.status, 200, "runtime queue moves should use final zero-based indices");
|
|
443
483
|
assert.deepEqual(runtimeQueueMove.body?.data?.queue?.followUp, ["runtime second", "runtime third", "runtime edited"]);
|
|
444
484
|
|
|
485
|
+
const runtimeQueueDelete = await request("127.0.0.1", "/api/queue/mutate", {
|
|
486
|
+
method: "POST",
|
|
487
|
+
body: {
|
|
488
|
+
tab: tabId,
|
|
489
|
+
source: "pi-runtime",
|
|
490
|
+
kind: "followUp",
|
|
491
|
+
expected: { steering: ["runtime steering"], followUp: ["runtime second", "runtime third", "runtime edited"] },
|
|
492
|
+
operation: { type: "delete", index: 1, expectedText: "runtime third" },
|
|
493
|
+
},
|
|
494
|
+
});
|
|
495
|
+
assert.equal(runtimeQueueDelete.status, 200, "runtime queue deletion should remove the selected follow-up");
|
|
496
|
+
assert.deepEqual(runtimeQueueDelete.body?.data?.queue?.followUp, ["runtime second", "runtime edited"]);
|
|
497
|
+
|
|
445
498
|
const invalidRuntimeQueueMutation = await request("127.0.0.1", "/api/queue/mutate", {
|
|
446
499
|
method: "POST",
|
|
447
500
|
body: { tab: tabId, source: "pi-runtime", kind: "steering", expected: { steering: [], followUp: [] }, operation: { type: "edit", index: 0, expectedText: "x", text: "y" } },
|
|
@@ -702,6 +755,17 @@ try {
|
|
|
702
755
|
assert.equal(subagentOutputResponse.body?.data?.agent?.currentToolArgs, "README.md", "subagent output should include current tool state");
|
|
703
756
|
assert.equal(subagentOutputResponse.body?.data?.agent?.model, "anthropic/claude-opus-4-8:high", "subagent output should preserve the effective model");
|
|
704
757
|
assert.equal(subagentOutputResponse.body?.data?.agent?.thinking, "high", "subagent output should preserve the effective reasoning effort");
|
|
758
|
+
assert.deepEqual(subagentOutputResponse.body?.data?.agent?.telemetry, {
|
|
759
|
+
promptInjectionTokens: 1234,
|
|
760
|
+
inputTokens: 300,
|
|
761
|
+
outputTokens: 100,
|
|
762
|
+
tokenSpeed: 20,
|
|
763
|
+
contextTokens: 240,
|
|
764
|
+
contextWindow: 200_000,
|
|
765
|
+
model: "anthropic/claude-opus-4-8:high",
|
|
766
|
+
effort: "high",
|
|
767
|
+
}, "selected output should preserve only the normalized additive telemetry contract");
|
|
768
|
+
assert.equal(Object.hasOwn(subagentOutputResponse.body?.data?.agent?.telemetry || {}, "rawSessionPayload"), false, "selected output must not leak raw child-session/custom payloads");
|
|
705
769
|
assert.deepEqual(subagentOutputResponse.body?.data?.agent?.transcript, [
|
|
706
770
|
{
|
|
707
771
|
role: "assistant",
|
|
@@ -835,6 +899,29 @@ try {
|
|
|
835
899
|
assert.equal(state.status, 200);
|
|
836
900
|
assert.equal(state.body?.data?.model?.provider, "fake", "state should come from the fake pi RPC");
|
|
837
901
|
|
|
902
|
+
const newSessionTitleTab = await request("127.0.0.1", "/api/tabs", { method: "POST", body: { cwd } });
|
|
903
|
+
assert.equal(newSessionTitleTab.status, 201, `new-session title test tab should open: ${newSessionTitleTab.body?.error || ""}`);
|
|
904
|
+
const newSessionTitleTabId = newSessionTitleTab.body?.data?.tab?.id;
|
|
905
|
+
const defaultNewSessionTabTitle = newSessionTitleTab.body?.data?.tab?.title;
|
|
906
|
+
assert.ok(newSessionTitleTabId && defaultNewSessionTabTitle, "new-session title test tab should include default metadata");
|
|
907
|
+
const autoNamedTab = await request("127.0.0.1", "/api/prompt", {
|
|
908
|
+
method: "POST",
|
|
909
|
+
body: { tab: newSessionTitleTabId, message: "verify new session terminal title refresh" },
|
|
910
|
+
});
|
|
911
|
+
assert.equal(autoNamedTab.status, 200, "the title test prompt should be accepted");
|
|
912
|
+
assert.notEqual(autoNamedTab.body?.tab?.title, defaultNewSessionTabTitle, "the first prompt should auto-name the test tab");
|
|
913
|
+
assert.equal(autoNamedTab.body?.tab?.titleSource, "auto", "the generated title should be marked automatic");
|
|
914
|
+
const freshSession = await request("127.0.0.1", "/api/new-session", {
|
|
915
|
+
method: "POST",
|
|
916
|
+
body: { tab: newSessionTitleTabId },
|
|
917
|
+
});
|
|
918
|
+
assert.equal(freshSession.status, 200, `new session should succeed: ${freshSession.body?.error || ""}`);
|
|
919
|
+
assert.equal(freshSession.body?.tab?.title, defaultNewSessionTabTitle, "new-session responses should immediately reset automatic terminal-tab titles");
|
|
920
|
+
assert.equal(freshSession.body?.tab?.titleSource, "default", "a reset title should be eligible for the new session's first-prompt naming");
|
|
921
|
+
assert.equal(freshSession.body?.tab?.conversationStarted, false, "the new session should reset conversation-title tracking");
|
|
922
|
+
const closeNewSessionTitleTab = await request("127.0.0.1", "/api/tabs/close", { method: "POST", body: { ids: [newSessionTitleTabId] } });
|
|
923
|
+
assert.equal(closeNewSessionTitleTab.status, 200, "new-session title test tab should close before later endpoint checks");
|
|
924
|
+
|
|
838
925
|
const forkSourceTab = await request("127.0.0.1", "/api/tabs", { method: "POST", body: { cwd, title: "fork-running-source" } });
|
|
839
926
|
assert.equal(forkSourceTab.status, 201, `fork source tab should open: ${forkSourceTab.body?.error || ""}`);
|
|
840
927
|
const forkSourceTabId = forkSourceTab.body?.data?.tab?.id;
|
|
@@ -921,6 +1008,39 @@ try {
|
|
|
921
1008
|
assert.equal(gitMain.status, 200);
|
|
922
1009
|
assert.equal(gitMain.body?.ok, true, "main branch endpoint should rename the branch");
|
|
923
1010
|
|
|
1011
|
+
const bypassPublish = await request("127.0.0.1", `/api/git-workflow/publish?tab=${encodeURIComponent(tabId)}`);
|
|
1012
|
+
assert.equal(bypassPublish.status, 405, "GET /api/git-workflow/publish should be refused with 405");
|
|
1013
|
+
|
|
1014
|
+
const pushWithoutRemote = await request("127.0.0.1", "/api/git-workflow/push", { method: "POST", body: { tab: tabId } });
|
|
1015
|
+
assert.equal(pushWithoutRemote.status, 200);
|
|
1016
|
+
assert.equal(pushWithoutRemote.body?.ok, false, "push without a configured destination should fail closed");
|
|
1017
|
+
assert.equal(pushWithoutRemote.body?.code, "NO_REMOTE", "remote-less push should have a stable recovery code");
|
|
1018
|
+
assert.match(String(pushWithoutRemote.body?.hint || ""), /publish this repository|add a Git remote/i);
|
|
1019
|
+
assert.match(String(pushWithoutRemote.body?.data?.stderr || ""), /No configured push destination/i, "classified failures should preserve process output");
|
|
1020
|
+
|
|
1021
|
+
const unconfirmedPublish = await request("127.0.0.1", "/api/git-workflow/publish", {
|
|
1022
|
+
method: "POST",
|
|
1023
|
+
body: { tab: tabId, repoName: "pi-webui-http-harness", visibility: "private" },
|
|
1024
|
+
});
|
|
1025
|
+
assert.equal(unconfirmedPublish.status, 200);
|
|
1026
|
+
assert.equal(unconfirmedPublish.body?.ok, false, "publication should require exact server-side confirmation");
|
|
1027
|
+
assert.match(String(unconfirmedPublish.body?.error || ""), /confirmed: true/);
|
|
1028
|
+
|
|
1029
|
+
const invalidVisibilityPublish = await request("127.0.0.1", "/api/git-workflow/publish", {
|
|
1030
|
+
method: "POST",
|
|
1031
|
+
body: { tab: tabId, repoName: "pi-webui-http-harness", visibility: "internal", confirmed: true },
|
|
1032
|
+
});
|
|
1033
|
+
assert.equal(invalidVisibilityPublish.body?.ok, false, "publication should reject visibility outside public/private");
|
|
1034
|
+
assert.match(String(invalidVisibilityPublish.body?.error || ""), /visibility must be 'public' or 'private'/);
|
|
1035
|
+
|
|
1036
|
+
const invalidNamePublish = await request("127.0.0.1", "/api/git-workflow/publish", {
|
|
1037
|
+
method: "POST",
|
|
1038
|
+
body: { tab: tabId, repoName: "invalid repository name", visibility: "public", confirmed: true },
|
|
1039
|
+
});
|
|
1040
|
+
assert.equal(invalidNamePublish.body?.ok, false, "publication should reuse GitHub repository-name validation");
|
|
1041
|
+
assert.match(String(invalidNamePublish.body?.error || ""), /Invalid GitHub repository name/);
|
|
1042
|
+
assert.equal(runGitFixture(["remote"], cwd, "guarded publication requests must not configure a remote"), "");
|
|
1043
|
+
|
|
924
1044
|
const initialWorktrees = await request("127.0.0.1", `/api/git-worktrees?tab=${encodeURIComponent(tabId)}`);
|
|
925
1045
|
assert.equal(initialWorktrees.status, 200);
|
|
926
1046
|
assert.equal(initialWorktrees.body?.ok, true, "worktree list endpoint should return data for a git repository");
|
|
@@ -1095,12 +1215,156 @@ try {
|
|
|
1095
1215
|
await writeFile(path.join(remoteWork, "incoming.txt"), "base\nremote one\nremote two\n");
|
|
1096
1216
|
runGitFixture(["commit", "-am", "remote two"], remoteWork, "remote worktree should commit second incoming change");
|
|
1097
1217
|
runGitFixture(["push", "origin", "main"], remoteWork, "remote worktree should push incoming commits");
|
|
1098
|
-
|
|
1218
|
+
|
|
1219
|
+
const remoteOnlySwitchBranch = "feature/remote-only-switch";
|
|
1220
|
+
runGitFixture(["switch", "-c", remoteOnlySwitchBranch], remoteWork, "remote worktree should create the switch fixture branch");
|
|
1221
|
+
await writeFile(path.join(remoteWork, "remote-switch.txt"), "switch fixture\n");
|
|
1222
|
+
runGitFixture(["add", "remote-switch.txt"], remoteWork, "remote switch fixture should stage its marker");
|
|
1223
|
+
runGitFixture(["commit", "-m", "remote switch fixture"], remoteWork, "remote switch fixture should commit its marker");
|
|
1224
|
+
runGitFixture(["push", "-u", "origin", remoteOnlySwitchBranch], remoteWork, "remote switch fixture should push its branch");
|
|
1225
|
+
runGitFixture(["switch", "main"], remoteWork, "remote worktree should return to main after the switch fixture");
|
|
1226
|
+
|
|
1227
|
+
const remoteOnlyWorktreeBranch = "feature/remote-only-worktree";
|
|
1228
|
+
runGitFixture(["switch", "-c", remoteOnlyWorktreeBranch], remoteWork, "remote worktree should create the worktree fixture branch");
|
|
1229
|
+
await writeFile(path.join(remoteWork, "remote-worktree.txt"), "worktree fixture\n");
|
|
1230
|
+
runGitFixture(["add", "remote-worktree.txt"], remoteWork, "remote worktree fixture should stage its marker");
|
|
1231
|
+
runGitFixture(["commit", "-m", "remote worktree fixture"], remoteWork, "remote worktree fixture should commit its marker");
|
|
1232
|
+
runGitFixture(["push", "-u", "origin", remoteOnlyWorktreeBranch], remoteWork, "remote worktree fixture should push its branch");
|
|
1233
|
+
runGitFixture(["switch", "main"], remoteWork, "remote worktree should return to main after the worktree fixture");
|
|
1234
|
+
|
|
1235
|
+
const remoteOnlyCreateBranch = "feature/remote-only-create";
|
|
1236
|
+
runGitFixture(["branch", remoteOnlyCreateBranch], remoteWork, "remote worktree should create the local-create compatibility fixture branch");
|
|
1237
|
+
runGitFixture(["push", "origin", remoteOnlyCreateBranch], remoteWork, "remote create fixture should push its branch");
|
|
1238
|
+
const staleRemoteBranch = "feature/remote-only-stale";
|
|
1239
|
+
runGitFixture(["branch", staleRemoteBranch], remoteWork, "remote worktree should create the stale fixture branch");
|
|
1240
|
+
runGitFixture(["push", "origin", staleRemoteBranch], remoteWork, "remote stale fixture should push its branch");
|
|
1241
|
+
|
|
1242
|
+
runGitFixture(["remote", "add", "mirror", remoteBare], localRepo, "local repo should add a second configured remote for exact-ref coverage");
|
|
1243
|
+
runGitFixture(["remote", "add", "team/mirror", remoteBare], localRepo, "local repo should add a slash-named remote for exact local-name derivation coverage");
|
|
1099
1244
|
|
|
1100
1245
|
const remoteTab = await request("127.0.0.1", "/api/tabs", { method: "POST", body: { cwd: localRepo, title: "remote-behind-fixture" } });
|
|
1101
1246
|
assert.equal(remoteTab.status, 201);
|
|
1102
1247
|
const remoteTabId = remoteTab.body?.data?.tab?.id;
|
|
1103
1248
|
assert.ok(remoteTabId, "remote fixture tab should have an id");
|
|
1249
|
+
|
|
1250
|
+
const fetchedRemoteBranches = await request("127.0.0.1", "/api/git-fetch", { method: "POST", body: { tab: remoteTabId }, timeoutMs: 20_000 });
|
|
1251
|
+
assert.equal(fetchedRemoteBranches.status, 200);
|
|
1252
|
+
assert.equal(fetchedRemoteBranches.body?.ok, true, `git fetch --prune should reveal remote-only branches: ${fetchedRemoteBranches.body?.error || ""}`);
|
|
1253
|
+
runGitFixture(["fetch", "mirror"], localRepo, "remote fixture should fetch the second remote for exact-ref collision coverage");
|
|
1254
|
+
runGitFixture(["fetch", "team/mirror"], localRepo, "remote fixture should fetch the slash-named remote for prefix matching coverage");
|
|
1255
|
+
runGitFixture(["symbolic-ref", "refs/remotes/origin/HEAD", "refs/remotes/origin/main"], localRepo, "remote fixture should create a symbolic remote HEAD alias");
|
|
1256
|
+
runGitFixture(["branch", "origin/main", "main"], localRepo, "remote fixture should create a local ref that makes refname:short ambiguous");
|
|
1257
|
+
|
|
1258
|
+
const listedRemoteBranches = await request("127.0.0.1", `/api/git-branches?tab=${encodeURIComponent(remoteTabId)}`);
|
|
1259
|
+
assert.equal(listedRemoteBranches.status, 200);
|
|
1260
|
+
assert.equal(listedRemoteBranches.body?.ok, true, "branch listing should include fetched remote-only branches");
|
|
1261
|
+
const branchRecords = listedRemoteBranches.body?.data?.branches || [];
|
|
1262
|
+
const originRemoteSwitch = branchRecords.find((branch) => branch.remote === true && branch.remoteRef === `origin/${remoteOnlySwitchBranch}`);
|
|
1263
|
+
assert.deepEqual(originRemoteSwitch, {
|
|
1264
|
+
name: remoteOnlySwitchBranch,
|
|
1265
|
+
current: false,
|
|
1266
|
+
remote: true,
|
|
1267
|
+
remoteRef: `origin/${remoteOnlySwitchBranch}`,
|
|
1268
|
+
remoteName: "origin",
|
|
1269
|
+
displayName: `origin/${remoteOnlySwitchBranch}`,
|
|
1270
|
+
}, "remote-only rows should carry explicit local and exact remote metadata");
|
|
1271
|
+
const sameNameRemoteRefs = branchRecords
|
|
1272
|
+
.filter((branch) => branch.remote === true && branch.name === remoteOnlySwitchBranch)
|
|
1273
|
+
.map((branch) => branch.remoteRef)
|
|
1274
|
+
.sort();
|
|
1275
|
+
assert.deepEqual(sameNameRemoteRefs, [`mirror/${remoteOnlySwitchBranch}`, `origin/${remoteOnlySwitchBranch}`, `team/mirror/${remoteOnlySwitchBranch}`], "same-name remote-only branches should remain distinct by exact ref even when a remote name contains a slash");
|
|
1276
|
+
assert.equal(branchRecords.some((branch) => branch.remote === true && branch.remoteRef === "origin/HEAD"), false, "symbolic remote HEAD aliases must not be listed");
|
|
1277
|
+
assert.equal(branchRecords.some((branch) => branch.remote === true && branch.name === "main"), false, "a local branch should hide same-named remote rows");
|
|
1278
|
+
assert.ok(branchRecords.some((branch) => branch.remote !== true && branch.name === "origin/main"), "local branch names must not change when refname shortening would be ambiguous");
|
|
1279
|
+
assert.equal(listedRemoteBranches.body?.data?.remoteBranchesTruncated, false, "complete remote branch output should not be marked truncated");
|
|
1280
|
+
|
|
1281
|
+
const implicitRemoteSwitch = await request("127.0.0.1", "/api/git-branch", {
|
|
1282
|
+
method: "POST",
|
|
1283
|
+
body: { tab: remoteTabId, branch: remoteOnlySwitchBranch },
|
|
1284
|
+
});
|
|
1285
|
+
assert.equal(implicitRemoteSwitch.body?.ok, false, "remote-only names without an exact remoteRef must not trigger Git DWIM tracking creation");
|
|
1286
|
+
assert.match(String(implicitRemoteSwitch.body?.error || ""), /Unknown local git branch/, "implicit remote selection should retain the local-only API guard");
|
|
1287
|
+
assert.equal(runGitFixture(["branch", "--list", remoteOnlySwitchBranch], localRepo, "implicit remote switch should not create a local branch"), "");
|
|
1288
|
+
|
|
1289
|
+
const localCreateOverRemote = await request("127.0.0.1", "/api/git-branch", {
|
|
1290
|
+
method: "POST",
|
|
1291
|
+
body: { tab: remoteTabId, branch: remoteOnlyCreateBranch, create: true },
|
|
1292
|
+
timeoutMs: 20_000,
|
|
1293
|
+
});
|
|
1294
|
+
assert.equal(localCreateOverRemote.body?.ok, true, "explicit local branch creation should remain available when a same-named remote-only branch exists");
|
|
1295
|
+
assert.equal(runGitFixture(["branch", "--show-current"], localRepo, "local create compatibility path should switch to its new branch"), remoteOnlyCreateBranch);
|
|
1296
|
+
const createdUpstream = spawnSync("git", ["rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{upstream}"], { cwd: localRepo, encoding: "utf8" });
|
|
1297
|
+
assert.notEqual(createdUpstream.status, 0, "explicit local creation should not silently track the same-named remote branch");
|
|
1298
|
+
runGitFixture(["switch", "main"], localRepo, "local repo should return to main after local-create compatibility coverage");
|
|
1299
|
+
|
|
1300
|
+
runGitFixture(["push", "origin", "--delete", staleRemoteBranch], remoteWork, "remote fixture should delete the stale branch upstream");
|
|
1301
|
+
const prunedRemoteBranches = await request("127.0.0.1", "/api/git-fetch", { method: "POST", body: { tab: remoteTabId }, timeoutMs: 20_000 });
|
|
1302
|
+
assert.equal(prunedRemoteBranches.body?.ok, true, "git fetch --prune should remove the deleted origin tracking ref");
|
|
1303
|
+
const staleRemoteSwitch = await request("127.0.0.1", "/api/git-branch", {
|
|
1304
|
+
method: "POST",
|
|
1305
|
+
body: { tab: remoteTabId, branch: staleRemoteBranch, remoteRef: `origin/${staleRemoteBranch}` },
|
|
1306
|
+
});
|
|
1307
|
+
assert.equal(staleRemoteSwitch.body?.ok, false, "acting on a remote ref removed by prune must fail closed");
|
|
1308
|
+
assert.match(String(staleRemoteSwitch.body?.error || ""), /Unknown remote git branch/, "stale remote actions should explain that the advertised ref no longer exists");
|
|
1309
|
+
assert.equal(runGitFixture(["branch", "--list", staleRemoteBranch], localRepo, "stale remote action should not create a local branch"), "");
|
|
1310
|
+
|
|
1311
|
+
const mismatchedRemoteSwitch = await request("127.0.0.1", "/api/git-branch", {
|
|
1312
|
+
method: "POST",
|
|
1313
|
+
body: { tab: remoteTabId, branch: remoteOnlySwitchBranch, remoteRef: `origin/${remoteOnlyWorktreeBranch}` },
|
|
1314
|
+
});
|
|
1315
|
+
assert.equal(mismatchedRemoteSwitch.status, 200);
|
|
1316
|
+
assert.equal(mismatchedRemoteSwitch.body?.ok, false, "a remote ref must match its submitted local branch name");
|
|
1317
|
+
assert.equal(runGitFixture(["branch", "--list", remoteOnlySwitchBranch], localRepo, "mismatched remote switch should not create a local branch"), "");
|
|
1318
|
+
|
|
1319
|
+
const switchedRemoteBranch = await request("127.0.0.1", "/api/git-branch", {
|
|
1320
|
+
method: "POST",
|
|
1321
|
+
body: { tab: remoteTabId, branch: remoteOnlySwitchBranch, remoteRef: `origin/${remoteOnlySwitchBranch}` },
|
|
1322
|
+
timeoutMs: 20_000,
|
|
1323
|
+
});
|
|
1324
|
+
assert.equal(switchedRemoteBranch.status, 200);
|
|
1325
|
+
assert.equal(switchedRemoteBranch.body?.ok, true, `remote-only switch should create a tracking branch: ${switchedRemoteBranch.body?.error || ""}`);
|
|
1326
|
+
assert.equal(runGitFixture(["branch", "--show-current"], localRepo, "remote-only switch should remain attached"), remoteOnlySwitchBranch);
|
|
1327
|
+
assert.equal(runGitFixture(["rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{upstream}"], localRepo, "remote-only switch should configure its upstream"), `origin/${remoteOnlySwitchBranch}`);
|
|
1328
|
+
|
|
1329
|
+
const collisionRemoteSwitch = await request("127.0.0.1", "/api/git-branch", {
|
|
1330
|
+
method: "POST",
|
|
1331
|
+
body: { tab: remoteTabId, branch: remoteOnlySwitchBranch, remoteRef: `mirror/${remoteOnlySwitchBranch}` },
|
|
1332
|
+
});
|
|
1333
|
+
assert.equal(collisionRemoteSwitch.status, 200);
|
|
1334
|
+
assert.equal(collisionRemoteSwitch.body?.ok, false, "a newly materialized local branch should reject a same-name remote selection");
|
|
1335
|
+
assert.equal(runGitFixture(["rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{upstream}"], localRepo, "collision rejection must preserve the original upstream"), `origin/${remoteOnlySwitchBranch}`);
|
|
1336
|
+
|
|
1337
|
+
const switchedBackToMain = await request("127.0.0.1", "/api/git-branch", { method: "POST", body: { tab: remoteTabId, branch: "main" }, timeoutMs: 20_000 });
|
|
1338
|
+
assert.equal(switchedBackToMain.status, 200);
|
|
1339
|
+
assert.equal(switchedBackToMain.body?.ok, true, "local branch switching should remain unchanged after remote switching");
|
|
1340
|
+
|
|
1341
|
+
const mismatchedRemoteWorktree = await request("127.0.0.1", "/api/git-worktrees", {
|
|
1342
|
+
method: "POST",
|
|
1343
|
+
body: { tab: remoteTabId, branchName: remoteOnlyWorktreeBranch, remoteRef: `origin/${remoteOnlySwitchBranch}`, sessionMode: "empty", openTab: true },
|
|
1344
|
+
timeoutMs: 20_000,
|
|
1345
|
+
});
|
|
1346
|
+
assert.equal(mismatchedRemoteWorktree.status, 200);
|
|
1347
|
+
assert.equal(mismatchedRemoteWorktree.body?.ok, false, "a worktree remote ref must match its submitted local branch name");
|
|
1348
|
+
assert.equal(runGitFixture(["branch", "--list", remoteOnlyWorktreeBranch], localRepo, "mismatched remote worktree should not create a local branch"), "");
|
|
1349
|
+
|
|
1350
|
+
const remoteTrackingWorktree = await request("127.0.0.1", "/api/git-worktrees", {
|
|
1351
|
+
method: "POST",
|
|
1352
|
+
body: { tab: remoteTabId, branchName: remoteOnlyWorktreeBranch, remoteRef: `team/mirror/${remoteOnlyWorktreeBranch}`, sessionMode: "empty", openTab: true },
|
|
1353
|
+
timeoutMs: 20_000,
|
|
1354
|
+
});
|
|
1355
|
+
assert.equal(remoteTrackingWorktree.status, 200);
|
|
1356
|
+
assert.equal(remoteTrackingWorktree.body?.ok, true, `remote-only worktree should create a tracking branch: ${remoteTrackingWorktree.body?.error || ""}`);
|
|
1357
|
+
const remoteTrackingWorktreePath = remoteTrackingWorktree.body?.data?.worktree?.path || remoteTrackingWorktree.body?.data?.path;
|
|
1358
|
+
const remoteTrackingWorktreeTabId = remoteTrackingWorktree.body?.data?.tab?.id;
|
|
1359
|
+
assert.ok(remoteTrackingWorktreePath, "remote-only worktree response should include its path");
|
|
1360
|
+
assert.ok(remoteTrackingWorktreeTabId, "remote-only worktree should open a tab");
|
|
1361
|
+
assert.equal(runGitFixture(["branch", "--show-current"], remoteTrackingWorktreePath, "remote-only worktree should remain attached"), remoteOnlyWorktreeBranch);
|
|
1362
|
+
assert.equal(runGitFixture(["rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{upstream}"], remoteTrackingWorktreePath, "remote-only worktree should configure its upstream"), `team/mirror/${remoteOnlyWorktreeBranch}`);
|
|
1363
|
+
const closeRemoteTrackingWorktreeTab = await request("127.0.0.1", "/api/tabs/close", { method: "POST", body: { ids: [remoteTrackingWorktreeTabId] }, timeoutMs: 10_000 });
|
|
1364
|
+
assert.equal(closeRemoteTrackingWorktreeTab.body?.ok, true, "remote-only worktree tab should close before cleanup");
|
|
1365
|
+
const removeRemoteTrackingWorktree = await request("127.0.0.1", "/api/git-worktrees", { method: "DELETE", body: { tab: remoteTabId, path: remoteTrackingWorktreePath, confirmed: true }, timeoutMs: 20_000 });
|
|
1366
|
+
assert.equal(removeRemoteTrackingWorktree.body?.ok, true, "remote-only tracking worktree should be removable after the tab closes");
|
|
1367
|
+
|
|
1104
1368
|
const incomingChanges = await request("127.0.0.1", `/api/git-changes?tab=${encodeURIComponent(remoteTabId)}`);
|
|
1105
1369
|
assert.equal(incomingChanges.status, 200);
|
|
1106
1370
|
assert.equal(incomingChanges.body?.ok, true, "git changes endpoint should load a fetched-behind repo");
|
|
@@ -1200,6 +1464,165 @@ try {
|
|
|
1200
1464
|
assert.ok(id, `${title} tab should have an id`);
|
|
1201
1465
|
return id;
|
|
1202
1466
|
};
|
|
1467
|
+
const addToGitignore = (tab, targetPath, kind) => request("127.0.0.1", "/api/git-changes/add-to-gitignore", {
|
|
1468
|
+
method: "POST",
|
|
1469
|
+
body: { tab, path: targetPath, kind },
|
|
1470
|
+
});
|
|
1471
|
+
|
|
1472
|
+
// Add-to-gitignore mutation: literal entries, idempotence, line endings, validation, and target safety.
|
|
1473
|
+
const gitignoreRepo = await makeFixtureRepo("add-to-gitignore");
|
|
1474
|
+
const gitignoreTab = await openFixtureTab(gitignoreRepo, "add-to-gitignore-fixture");
|
|
1475
|
+
await mkdir(path.join(gitignoreRepo, "generated"), { recursive: true });
|
|
1476
|
+
await writeFile(path.join(gitignoreRepo, "generated", "output.log"), "generated\n");
|
|
1477
|
+
await mkdir(path.join(gitignoreRepo, "build"), { recursive: true });
|
|
1478
|
+
await writeFile(path.join(gitignoreRepo, "build", "bundle.js"), "bundle\n");
|
|
1479
|
+
const indexBeforeGitignore = runGitFixture(["diff", "--cached", "--raw"], gitignoreRepo, "gitignore fixture should start with an unchanged index");
|
|
1480
|
+
|
|
1481
|
+
const addIgnoredFile = await addToGitignore(gitignoreTab, "generated/output.log", "file");
|
|
1482
|
+
assert.equal(addIgnoredFile.status, 200);
|
|
1483
|
+
assert.equal(addIgnoredFile.body?.ok, true, `adding a file to .gitignore should succeed: ${addIgnoredFile.body?.error || ""}`);
|
|
1484
|
+
assert.deepEqual({
|
|
1485
|
+
root: addIgnoredFile.body?.data?.root,
|
|
1486
|
+
path: addIgnoredFile.body?.data?.path,
|
|
1487
|
+
kind: addIgnoredFile.body?.data?.kind,
|
|
1488
|
+
entry: addIgnoredFile.body?.data?.entry,
|
|
1489
|
+
added: addIgnoredFile.body?.data?.added,
|
|
1490
|
+
}, {
|
|
1491
|
+
root: gitignoreRepo,
|
|
1492
|
+
path: "generated/output.log",
|
|
1493
|
+
kind: "file",
|
|
1494
|
+
entry: "/generated/output.log",
|
|
1495
|
+
added: true,
|
|
1496
|
+
}, "file mutations should return the approved normalized contract");
|
|
1497
|
+
assert.equal((await readFile(path.join(gitignoreRepo, ".gitignore"), "utf8")), "/generated/output.log\n", "a missing root .gitignore should be created with one LF-terminated entry");
|
|
1498
|
+
assert.equal(addIgnoredFile.body?.data?.changes?.untracked?.some((entry) => entry.path === ".gitignore"), true, "the mutation response should contain refreshed Git status including .gitignore");
|
|
1499
|
+
assert.equal(addIgnoredFile.body?.data?.changes?.untracked?.some((entry) => entry.path === "generated/output.log"), false, "the refreshed snapshot should no longer list the newly ignored file");
|
|
1500
|
+
|
|
1501
|
+
const bytesBeforeRepeat = await readFile(path.join(gitignoreRepo, ".gitignore"));
|
|
1502
|
+
const repeatIgnoredFile = await addToGitignore(gitignoreTab, "generated/output.log", "file");
|
|
1503
|
+
assert.equal(repeatIgnoredFile.body?.data?.added, false, "an exact repeated entry should report a no-op");
|
|
1504
|
+
assert.deepEqual(await readFile(path.join(gitignoreRepo, ".gitignore")), bytesBeforeRepeat, "an exact repeated entry must be byte-idempotent");
|
|
1505
|
+
|
|
1506
|
+
const addIgnoredFolder = await addToGitignore(gitignoreTab, "build", "folder");
|
|
1507
|
+
assert.equal(addIgnoredFolder.body?.data?.entry, "/build/", "folder entries should receive exactly one trailing slash");
|
|
1508
|
+
assert.equal(await readFile(path.join(gitignoreRepo, ".gitignore"), "utf8"), "/generated/output.log\n/build/\n", "folder entries should append without rewriting existing content");
|
|
1509
|
+
|
|
1510
|
+
const concurrentResults = await Promise.all([
|
|
1511
|
+
addToGitignore(gitignoreTab, "concurrent/cache.bin", "file"),
|
|
1512
|
+
addToGitignore(gitignoreTab, "concurrent/cache.bin", "file"),
|
|
1513
|
+
]);
|
|
1514
|
+
assert.deepEqual(concurrentResults.map((result) => result.body?.data?.added).sort(), [false, true], "per-repository serialization should add one copy under concurrent requests");
|
|
1515
|
+
assert.equal((await readFile(path.join(gitignoreRepo, ".gitignore"), "utf8")).split("/concurrent/cache.bin").length - 1, 1, "serialized concurrent requests should leave one exact line");
|
|
1516
|
+
|
|
1517
|
+
const normalizedSeparators = await addToGitignore(gitignoreTab, "nested\\windows.log", "file");
|
|
1518
|
+
assert.equal(normalizedSeparators.body?.data?.path, "nested/windows.log", "backslash separators should normalize to repository-style slashes");
|
|
1519
|
+
assert.equal(normalizedSeparators.body?.data?.entry, "/nested/windows.log");
|
|
1520
|
+
|
|
1521
|
+
await writeFile(path.join(gitignoreRepo, "file.txt"), "tracked modification\n");
|
|
1522
|
+
const addTrackedFile = await addToGitignore(gitignoreTab, "file.txt", "file");
|
|
1523
|
+
assert.equal(addTrackedFile.body?.data?.added, true, "a tracked path may receive an ignore entry");
|
|
1524
|
+
assert.equal(runGitFixture(["ls-files", "--error-unmatch", "--", "file.txt"], gitignoreRepo, "tracked file must remain in the index"), "file.txt", "adding a tracked path to .gitignore must not untrack it");
|
|
1525
|
+
assert.match(addTrackedFile.body?.data?.changes?.status || "", /(^|\n) M file\.txt(?=\n|$)/, "the refreshed snapshot should keep a modified tracked file visible after adding its ignore entry");
|
|
1526
|
+
|
|
1527
|
+
assert.equal(runGitFixture(["diff", "--cached", "--raw"], gitignoreRepo, "gitignore mutation must not change the index"), indexBeforeGitignore, "add-to-gitignore must not stage any files");
|
|
1528
|
+
assert.equal(runGitFixture(["ls-files", "--stage", "--", ".gitignore"], gitignoreRepo, "gitignore mutation must leave .gitignore untracked"), "", ".gitignore must remain unstaged and untracked");
|
|
1529
|
+
|
|
1530
|
+
const lfRepo = await makeFixtureRepo("gitignore-lf");
|
|
1531
|
+
const lfTab = await openFixtureTab(lfRepo, "gitignore-lf-fixture");
|
|
1532
|
+
await writeFile(path.join(lfRepo, ".gitignore"), "# existing\n", "utf8");
|
|
1533
|
+
assert.equal((await addToGitignore(lfTab, "lf-output.txt", "file")).body?.data?.added, true);
|
|
1534
|
+
assert.equal(await readFile(path.join(lfRepo, ".gitignore"), "utf8"), "# existing\n/lf-output.txt\n", "LF files should retain LF when appending");
|
|
1535
|
+
|
|
1536
|
+
const noFinalNewlineRepo = await makeFixtureRepo("gitignore-no-final-newline");
|
|
1537
|
+
const noFinalNewlineTab = await openFixtureTab(noFinalNewlineRepo, "gitignore-no-final-newline-fixture");
|
|
1538
|
+
await writeFile(path.join(noFinalNewlineRepo, ".gitignore"), "# existing", "utf8");
|
|
1539
|
+
await addToGitignore(noFinalNewlineTab, "separated.txt", "file");
|
|
1540
|
+
assert.equal(await readFile(path.join(noFinalNewlineRepo, ".gitignore"), "utf8"), "# existing\n/separated.txt\n", "append should add a separator when existing content has no final newline");
|
|
1541
|
+
|
|
1542
|
+
const crlfRepo = await makeFixtureRepo("gitignore-crlf");
|
|
1543
|
+
const crlfTab = await openFixtureTab(crlfRepo, "gitignore-crlf-fixture");
|
|
1544
|
+
await writeFile(path.join(crlfRepo, ".gitignore"), Buffer.from("# existing\r\n", "utf8"));
|
|
1545
|
+
await addToGitignore(crlfTab, "crlf-output.txt", "file");
|
|
1546
|
+
assert.deepEqual(await readFile(path.join(crlfRepo, ".gitignore")), Buffer.from("# existing\r\n/crlf-output.txt\r\n", "utf8"), "CRLF files should retain CRLF when appending");
|
|
1547
|
+
|
|
1548
|
+
const literalRepo = await makeFixtureRepo("gitignore-literal-pattern");
|
|
1549
|
+
const literalTab = await openFixtureTab(literalRepo, "gitignore-literal-pattern-fixture");
|
|
1550
|
+
const literalPath = "literal [x] *?.txt";
|
|
1551
|
+
const addLiteral = await addToGitignore(literalTab, literalPath, "file");
|
|
1552
|
+
assert.equal(addLiteral.body?.data?.entry, "/literal\\ \\[x\\]\\ \\*\\?.txt", "spaces and Git pattern metacharacters should be escaped literally");
|
|
1553
|
+
assert.equal(await readFile(path.join(literalRepo, ".gitignore"), "utf8"), "/literal\\ \\[x\\]\\ \\*\\?.txt\n");
|
|
1554
|
+
const intendedLiteralCheck = spawnSync("git", ["check-ignore", "-q", "--no-index", "--", literalPath], { cwd: literalRepo });
|
|
1555
|
+
assert.equal(intendedLiteralCheck.status, 0, "the escaped entry should ignore the intended special-character path");
|
|
1556
|
+
const broaderLiteralCheck = spawnSync("git", ["check-ignore", "-q", "--no-index", "--", "literal x anything.txt"], { cwd: literalRepo });
|
|
1557
|
+
assert.notEqual(broaderLiteralCheck.status, 0, "the escaped entry must not broaden into wildcard or character-class matching");
|
|
1558
|
+
|
|
1559
|
+
const outsideMarker = path.join(gitFixturesRoot, "outside-gitignore-marker.txt");
|
|
1560
|
+
await writeFile(outsideMarker, "outside unchanged\n");
|
|
1561
|
+
const validationBytesBefore = await readFile(path.join(gitignoreRepo, ".gitignore"));
|
|
1562
|
+
const rejectedGitignoreInputs = [
|
|
1563
|
+
{ path: "", kind: "file", label: "empty path" },
|
|
1564
|
+
{ path: ".", kind: "folder", label: "repository root" },
|
|
1565
|
+
{ path: "/absolute.txt", kind: "file", label: "POSIX absolute path" },
|
|
1566
|
+
{ path: "C:\\absolute.txt", kind: "file", label: "Windows absolute path" },
|
|
1567
|
+
{ path: "../outside-gitignore-marker.txt", kind: "file", label: "traversal" },
|
|
1568
|
+
{ path: "nested/../outside.txt", kind: "file", label: "embedded traversal" },
|
|
1569
|
+
{ path: "bad\npath.txt", kind: "file", label: "newline control character" },
|
|
1570
|
+
{ path: "bad\0path.txt", kind: "file", label: "NUL control character" },
|
|
1571
|
+
{ path: "valid.txt", kind: "directory", label: "invalid kind" },
|
|
1572
|
+
{ path: "valid.txt", kind: "", label: "empty kind" },
|
|
1573
|
+
];
|
|
1574
|
+
for (const invalid of rejectedGitignoreInputs) {
|
|
1575
|
+
const rejected = await addToGitignore(gitignoreTab, invalid.path, invalid.kind);
|
|
1576
|
+
assert.equal(rejected.status, 400, `${invalid.label} should be rejected`);
|
|
1577
|
+
assert.equal(rejected.body?.ok, false, `${invalid.label} should return a structured failure`);
|
|
1578
|
+
}
|
|
1579
|
+
assert.deepEqual(await readFile(path.join(gitignoreRepo, ".gitignore")), validationBytesBefore, "validation failures must leave .gitignore byte-for-byte unchanged");
|
|
1580
|
+
assert.equal(await readFile(outsideMarker, "utf8"), "outside unchanged\n", "traversal attempts must not write outside the repository");
|
|
1581
|
+
|
|
1582
|
+
const unsafeRepo = await makeFixtureRepo("gitignore-unsafe-target");
|
|
1583
|
+
const unsafeTab = await openFixtureTab(unsafeRepo, "gitignore-unsafe-target-fixture");
|
|
1584
|
+
const unsafeGitignore = path.join(unsafeRepo, ".gitignore");
|
|
1585
|
+
await mkdir(unsafeGitignore);
|
|
1586
|
+
const directoryTarget = await addToGitignore(unsafeTab, "blocked.txt", "file");
|
|
1587
|
+
assert.equal(directoryTarget.status, 409, "a non-regular root .gitignore target should fail closed");
|
|
1588
|
+
await rm(unsafeGitignore, { recursive: true, force: true });
|
|
1589
|
+
|
|
1590
|
+
const hardlinkTarget = path.join(gitFixturesRoot, "outside-hardlink-target.txt");
|
|
1591
|
+
await writeFile(hardlinkTarget, "hard-link target unchanged\n");
|
|
1592
|
+
let hardlinkSupported = true;
|
|
1593
|
+
try {
|
|
1594
|
+
await link(hardlinkTarget, unsafeGitignore);
|
|
1595
|
+
} catch (error) {
|
|
1596
|
+
if (error?.code === "EPERM" || error?.code === "EACCES" || error?.code === "ENOSYS" || error?.code === "EXDEV") hardlinkSupported = false;
|
|
1597
|
+
else throw error;
|
|
1598
|
+
}
|
|
1599
|
+
if (hardlinkSupported) {
|
|
1600
|
+
const hardlinkResponse = await addToGitignore(unsafeTab, "blocked.txt", "file");
|
|
1601
|
+
assert.equal(hardlinkResponse.status, 409, "a root .gitignore hard link should fail closed");
|
|
1602
|
+
assert.equal(await readFile(hardlinkTarget, "utf8"), "hard-link target unchanged\n", "a rejected .gitignore hard link must not modify its outside target");
|
|
1603
|
+
await rm(unsafeGitignore, { force: true });
|
|
1604
|
+
}
|
|
1605
|
+
|
|
1606
|
+
const symlinkTarget = path.join(gitFixturesRoot, "outside-symlink-target.txt");
|
|
1607
|
+
await writeFile(symlinkTarget, "symlink target unchanged\n");
|
|
1608
|
+
let symlinkSupported = true;
|
|
1609
|
+
try {
|
|
1610
|
+
await symlink(symlinkTarget, unsafeGitignore, "file");
|
|
1611
|
+
} catch (error) {
|
|
1612
|
+
if (error?.code === "EPERM" || error?.code === "EACCES" || error?.code === "ENOSYS") symlinkSupported = false;
|
|
1613
|
+
else throw error;
|
|
1614
|
+
}
|
|
1615
|
+
if (symlinkSupported) {
|
|
1616
|
+
const symlinkResponse = await addToGitignore(unsafeTab, "blocked.txt", "file");
|
|
1617
|
+
assert.equal(symlinkResponse.status, 409, "a root .gitignore symlink should fail closed");
|
|
1618
|
+
assert.equal(await readFile(symlinkTarget, "utf8"), "symlink target unchanged\n", "a rejected .gitignore symlink must not be followed");
|
|
1619
|
+
await rm(unsafeGitignore, { force: true });
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1622
|
+
await writeFile(unsafeGitignore, Buffer.alloc(5 * 1024 * 1024 + 1, 0x23));
|
|
1623
|
+
const oversizedResponse = await addToGitignore(unsafeTab, "blocked.txt", "file");
|
|
1624
|
+
assert.equal(oversizedResponse.status, 409, "an oversized root .gitignore should be rejected as an unsafe server-side file state before it is read into memory");
|
|
1625
|
+
assert.equal((await stat(unsafeGitignore)).size, 5 * 1024 * 1024 + 1, "oversized refusal must leave .gitignore unchanged");
|
|
1203
1626
|
|
|
1204
1627
|
// File-scoped Git diff endpoint: staged, unstaged, untracked, empty, deleted, and rejected inputs.
|
|
1205
1628
|
const fileDiffRepo = await makeFixtureRepo("file-diff");
|
|
@@ -1623,7 +2046,7 @@ try {
|
|
|
1623
2046
|
const pruneConfirmed = await request("127.0.0.1", "/api/git-worktrees/prune", { method: "POST", body: { tab: undoTab, confirmed: true }, timeoutMs: 20_000 });
|
|
1624
2047
|
assert.equal(pruneConfirmed.body?.ok, true, `confirmed prune should succeed: ${pruneConfirmed.body?.error || ""}`);
|
|
1625
2048
|
|
|
1626
|
-
const closeGitActionTabs = await request("127.0.0.1", "/api/tabs/close", { method: "POST", body: { ids: [stagingTab, truncationTab, mergeTab, abortTab, rebaseTab, bisectTab, stashTab, undoTab] }, timeoutMs: 10_000 });
|
|
2049
|
+
const closeGitActionTabs = await request("127.0.0.1", "/api/tabs/close", { method: "POST", body: { ids: [gitignoreTab, lfTab, noFinalNewlineTab, crlfTab, literalTab, unsafeTab, fileDiffTab, stagingTab, truncationTab, mergeTab, abortTab, rebaseTab, bisectTab, stashTab, undoTab] }, timeoutMs: 10_000 });
|
|
1627
2050
|
assert.equal(closeGitActionTabs.status, 200, "git action fixture tabs should close");
|
|
1628
2051
|
await rmWithRetry(gitFixturesRoot);
|
|
1629
2052
|
|
|
@@ -2345,6 +2768,70 @@ try {
|
|
|
2345
2768
|
const closeFilesTab = await request("127.0.0.1", "/api/tabs/close", { method: "POST", body: { ids: [filesTabId] }, timeoutMs: 10_000 });
|
|
2346
2769
|
assert.equal(closeFilesTab.status, 200, "file fixture tab should close after scoped file checks");
|
|
2347
2770
|
|
|
2771
|
+
// Codex subscription Fast mode: exact status is extension-owned and every mutation must be
|
|
2772
|
+
// idle, explicit, tab-scoped, and confirmed by the extension status event.
|
|
2773
|
+
const initialCodexFastMode = await request("127.0.0.1", `/api/codex-fast-mode?tab=${encodeURIComponent(tabId)}`);
|
|
2774
|
+
assert.equal(initialCodexFastMode.status, 200);
|
|
2775
|
+
assert.equal(initialCodexFastMode.body?.data?.available, true, "fake /fast-mode command should make Codex Fast mode available");
|
|
2776
|
+
assert.equal(initialCodexFastMode.body?.data?.statusKnown, false, "server must not infer Fast mode before the extension publishes status");
|
|
2777
|
+
|
|
2778
|
+
const invalidCodexFastMode = await request("127.0.0.1", "/api/codex-fast-mode", {
|
|
2779
|
+
method: "PUT",
|
|
2780
|
+
body: { enabled: "yes", tab: tabId },
|
|
2781
|
+
});
|
|
2782
|
+
assert.equal(invalidCodexFastMode.status, 400, "Codex Fast mode should require an explicit boolean");
|
|
2783
|
+
|
|
2784
|
+
const codexFastModeOn = await request("127.0.0.1", "/api/codex-fast-mode", {
|
|
2785
|
+
method: "PUT",
|
|
2786
|
+
body: { enabled: true, tab: tabId },
|
|
2787
|
+
});
|
|
2788
|
+
assert.equal(codexFastModeOn.status, 200, `Codex Fast mode on should succeed: ${codexFastModeOn.body?.error || ""}`);
|
|
2789
|
+
assert.equal(codexFastModeOn.body?.data?.statusKnown, true);
|
|
2790
|
+
assert.equal(codexFastModeOn.body?.data?.enabled, true, "PUT should return only extension-confirmed on state");
|
|
2791
|
+
|
|
2792
|
+
const rejectNextCodexFastMode = await request("127.0.0.1", "/api/prompt", {
|
|
2793
|
+
method: "POST",
|
|
2794
|
+
body: { message: "fixture reject next codex fast mode mutation", tab: tabId },
|
|
2795
|
+
});
|
|
2796
|
+
assert.equal(rejectNextCodexFastMode.status, 200);
|
|
2797
|
+
const rejectedCodexFastModeOff = await request("127.0.0.1", "/api/codex-fast-mode", {
|
|
2798
|
+
method: "PUT",
|
|
2799
|
+
body: { enabled: false, tab: tabId },
|
|
2800
|
+
timeoutMs: 5_000,
|
|
2801
|
+
});
|
|
2802
|
+
assert.equal(rejectedCodexFastModeOff.status, 409, "RPC success without matching extension status should fail closed");
|
|
2803
|
+
assert.match(String(rejectedCodexFastModeOff.body?.error || ""), /did not confirm off/i);
|
|
2804
|
+
const codexFastModeStillOn = await request("127.0.0.1", `/api/codex-fast-mode?tab=${encodeURIComponent(tabId)}`);
|
|
2805
|
+
assert.equal(codexFastModeStillOn.body?.data?.enabled, true, "a rejected mutation must not become optimistic off state");
|
|
2806
|
+
|
|
2807
|
+
const busyFixturePrompt = await request("127.0.0.1", "/api/prompt", {
|
|
2808
|
+
method: "POST",
|
|
2809
|
+
body: { message: "voice test slow", tab: tabId },
|
|
2810
|
+
});
|
|
2811
|
+
assert.equal(busyFixturePrompt.status, 200);
|
|
2812
|
+
await delay(80);
|
|
2813
|
+
const busyCodexFastModeOff = await request("127.0.0.1", "/api/codex-fast-mode", {
|
|
2814
|
+
method: "PUT",
|
|
2815
|
+
body: { enabled: false, tab: tabId },
|
|
2816
|
+
});
|
|
2817
|
+
assert.equal(busyCodexFastModeOff.status, 409, "Codex Fast mode changes should be rejected during a running turn");
|
|
2818
|
+
assert.match(String(busyCodexFastModeOff.body?.error || ""), /busy|running turn/i);
|
|
2819
|
+
let settledCodexFastMode;
|
|
2820
|
+
for (let attempt = 0; attempt < 40; attempt += 1) {
|
|
2821
|
+
settledCodexFastMode = await request("127.0.0.1", `/api/codex-fast-mode?tab=${encodeURIComponent(tabId)}`);
|
|
2822
|
+
if (settledCodexFastMode.body?.data?.busy === false) break;
|
|
2823
|
+
await delay(150);
|
|
2824
|
+
}
|
|
2825
|
+
assert.equal(settledCodexFastMode?.body?.data?.busy, false, "fake running turn should settle before the retry");
|
|
2826
|
+
|
|
2827
|
+
const codexFastModeOff = await request("127.0.0.1", "/api/codex-fast-mode", {
|
|
2828
|
+
method: "PUT",
|
|
2829
|
+
body: { enabled: false, tab: tabId },
|
|
2830
|
+
});
|
|
2831
|
+
assert.equal(codexFastModeOff.status, 200, `Codex Fast mode off should succeed after the tab settles: ${codexFastModeOff.body?.error || ""}`);
|
|
2832
|
+
assert.equal(codexFastModeOff.body?.data?.enabled, false);
|
|
2833
|
+
assert.equal(codexFastModeOff.body?.data?.statusKnown, true, "off response should be extension-confirmed");
|
|
2834
|
+
|
|
2348
2835
|
// Natural Conversation shell: /talk availability drives per-tab status and safety guards.
|
|
2349
2836
|
const conversationFeature = await request("127.0.0.1", `/api/features/natural-conversation?tab=${encodeURIComponent(tabId)}`);
|
|
2350
2837
|
assert.equal(conversationFeature.status, 200);
|