@firstpick/pi-package-webui 0.6.4 → 0.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -207,12 +207,64 @@ function handleWebuiHelperPrompt(command, base) {
207
207
  case "skills-state":
208
208
  respondHelper({ requestId, ok: true, data: { skills: [] } });
209
209
  return true;
210
+ case "subagent-output":
211
+ respondHelper({
212
+ requestId,
213
+ ok: true,
214
+ data: {
215
+ version: 1,
216
+ runId: request.payload?.runId || "fixture-run",
217
+ source: "async",
218
+ mode: "parallel",
219
+ startedAt: Date.now() - 3000,
220
+ updatedAt: Date.now(),
221
+ agent: {
222
+ id: request.payload?.agentId || "fixture-run:0",
223
+ name: String(request.payload?.agentId || "").endsWith(":1") ? "scout" : "reviewer",
224
+ index: String(request.payload?.agentId || "").endsWith(":1") ? 1 : 0,
225
+ status: "running",
226
+ currentTool: "read",
227
+ currentToolArgs: "README.md",
228
+ recentTools: [{ tool: "grep", args: "Subagents", endMs: Date.now() - 200 }],
229
+ recentOutput: ["Inspecting current implementation", "Waiting for the next tool result"],
230
+ turnCount: 2,
231
+ toolCount: 3,
232
+ tokens: 420,
233
+ },
234
+ },
235
+ });
236
+ return true;
210
237
  default:
211
238
  respondHelper({ requestId, ok: false, error: `Unknown webui-helper action: ${String(request.action || "")}` });
212
239
  return true;
213
240
  }
214
241
  }
215
242
 
243
+ function handleSubagentFixturePrompt(command, base) {
244
+ const message = String(command.message || "").trim();
245
+ if (message !== "fixture subagents running" && message !== "fixture subagents clear") return false;
246
+ const runs = message.endsWith("clear") ? [] : [{
247
+ id: "fixture-run",
248
+ source: "async",
249
+ mode: "parallel",
250
+ status: "running",
251
+ startedAt: Date.now() - 2500,
252
+ agents: [
253
+ { id: "fixture-run:0", name: "reviewer", status: "running", index: 0, currentTool: "read", nested: false },
254
+ { id: "fixture-run:1", name: "scout", status: "running", index: 1, nested: false },
255
+ ],
256
+ }];
257
+ respond({ ...base, data: { output: "fake subagent status emitted" } });
258
+ emitEvent({
259
+ type: "extension_ui_request",
260
+ id: randomUUID(),
261
+ method: "setStatus",
262
+ statusKey: "webui-subagents",
263
+ statusText: `PI_WEBUI_SUBAGENTS_V1 ${JSON.stringify({ version: 1, available: true, updatedAt: Date.now(), runs })}`,
264
+ });
265
+ return true;
266
+ }
267
+
216
268
  function handleTalkPrompt(command, base) {
217
269
  const message = String(command.message || "").trim();
218
270
  const match = message.match(/^\/(talk|voice|conversation)(?:\s+(\S+))?/i);
@@ -315,6 +367,7 @@ rl.on("line", (line) => {
315
367
  }
316
368
  case "prompt":
317
369
  if (handleWebuiHelperPrompt(command, base)) return;
370
+ if (handleSubagentFixturePrompt(command, base)) return;
318
371
  if (handleTalkPrompt(command, base)) return;
319
372
  if (handleVoiceScriptPrompt(command, base)) return;
320
373
  respond({ ...base, data: { output: "fake prompt accepted" } });
@@ -0,0 +1,67 @@
1
+ import assert from "node:assert/strict";
2
+ import { mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises";
3
+ import { tmpdir } from "node:os";
4
+ import path from "node:path";
5
+ import {
6
+ GIT_WORKFLOW_SETUP_VERSION,
7
+ gitWorkflowPreferencesSummary,
8
+ isGitWorkflowSetupComplete,
9
+ readGitWorkflowPreferences,
10
+ readWebuiSettings,
11
+ supportedGitWorkflowThinkingLevels,
12
+ writeGitWorkflowPreferences,
13
+ } from "../lib/git-workflow-preferences.mjs";
14
+
15
+ assert.deepEqual(supportedGitWorkflowThinkingLevels({ reasoning: false }), ["off"]);
16
+ assert.deepEqual(
17
+ supportedGitWorkflowThinkingLevels({ reasoning: true }),
18
+ ["off", "minimal", "low", "medium", "high"],
19
+ "models without an explicit map should expose standard levels but not opt-in extended levels",
20
+ );
21
+ assert.deepEqual(
22
+ supportedGitWorkflowThinkingLevels({ reasoning: true, thinkingLevelMap: { minimal: null, xhigh: null, max: "max" } }),
23
+ ["off", "low", "medium", "high", "max"],
24
+ "null map entries should be hidden while explicit extended levels remain available",
25
+ );
26
+
27
+ const root = await mkdtemp(path.join(tmpdir(), "pi-webui-git-preferences-"));
28
+ const settingsFile = path.join(root, "settings.json");
29
+
30
+ try {
31
+ await writeFile(settingsFile, `${JSON.stringify({ version: 1, remoteAuthEnabled: true }, null, 2)}\n`, "utf8");
32
+ const migrated = await readWebuiSettings(settingsFile);
33
+ assert.equal(migrated.version, 2);
34
+ assert.equal(migrated.remoteAuthEnabled, true, "legacy Remote PIN state should survive schema migration");
35
+ assert.equal(isGitWorkflowSetupComplete(migrated.gitWorkflow), false);
36
+ assert.equal(migrated.gitWorkflow.stagingPolicy, "review");
37
+ assert.equal(migrated.gitWorkflow.generation.thinkingLevel, "low");
38
+
39
+ const saved = await writeGitWorkflowPreferences({
40
+ generation: { provider: "fake", modelId: "fake-model", thinkingLevel: "off", unavailablePolicy: "ask" },
41
+ commit: { language: "de", defaultVariant: "long", scope: "required" },
42
+ stagingPolicy: "preserve",
43
+ deliveryMode: "pr-worktree",
44
+ verificationPolicy: "none",
45
+ }, settingsFile);
46
+ assert.equal(saved.setupVersion, GIT_WORKFLOW_SETUP_VERSION);
47
+ assert.equal(isGitWorkflowSetupComplete(saved), true);
48
+ assert.equal(saved.commit.language, "de");
49
+ assert.equal(saved.commit.defaultVariant, "long");
50
+ assert.equal(saved.stagingPolicy, "preserve");
51
+
52
+ const partiallyUpdated = await writeGitWorkflowPreferences({ deliveryMode: "current" }, settingsFile);
53
+ assert.equal(partiallyUpdated.generation.modelId, "fake-model", "partial updates should preserve the selected model");
54
+ assert.equal(partiallyUpdated.commit.language, "de", "partial updates should preserve nested commit preferences");
55
+ assert.equal(partiallyUpdated.deliveryMode, "current");
56
+
57
+ const persisted = JSON.parse(await readFile(settingsFile, "utf8"));
58
+ assert.equal(persisted.version, 2);
59
+ assert.equal(persisted.remoteAuthEnabled, true);
60
+ assert.equal(persisted.gitWorkflow.generation.provider, "fake");
61
+ assert.match(gitWorkflowPreferencesSummary(await readGitWorkflowPreferences(settingsFile)), /fake\/fake-model/);
62
+ if (process.platform !== "win32") assert.equal((await stat(settingsFile)).mode & 0o777, 0o600);
63
+
64
+ console.log("git-workflow-preferences.test.mjs passed");
65
+ } finally {
66
+ await rm(root, { recursive: true, force: true });
67
+ }
@@ -53,6 +53,10 @@ async function rmWithRetry(target) {
53
53
  throw lastError;
54
54
  }
55
55
 
56
+ async function pathExists(target) {
57
+ return !!(await stat(target).catch(() => null));
58
+ }
59
+
56
60
  function runGitFixture(args, cwd, message) {
57
61
  const result = spawnSync("git", args, {
58
62
  cwd,
@@ -213,6 +217,34 @@ try {
213
217
  const tabId = tabList[0].id;
214
218
  assert.ok(tabId, "tab should have an id");
215
219
 
220
+ const subagentFixtureStart = await request("127.0.0.1", "/api/prompt", { method: "POST", body: { tab: tabId, message: "fixture subagents running" } });
221
+ assert.equal(subagentFixtureStart.status, 200, "subagent fixture status should be accepted");
222
+ let subagentsResponse;
223
+ for (let attempt = 0; attempt < 20; attempt++) {
224
+ subagentsResponse = await request("127.0.0.1", "/api/subagents");
225
+ if (subagentsResponse.body?.data?.totalAgents === 2) break;
226
+ await delay(50);
227
+ }
228
+ assert.equal(subagentsResponse?.status, 200, "subagent overview endpoint should respond");
229
+ assert.equal(subagentsResponse.body?.data?.totalAgents, 2, "subagent overview should count all running agents");
230
+ assert.equal(subagentsResponse.body?.data?.tabs?.[0]?.tabId, tabId, "subagent overview should group agents under their terminal tab");
231
+ assert.deepEqual(subagentsResponse.body?.data?.tabs?.[0]?.runs?.[0]?.agents?.map((agent) => agent.name), ["reviewer", "scout"], "subagent overview should preserve agent order within the session run");
232
+ const subagentOutputResponse = await request("127.0.0.1", `/api/subagents/output?tab=${encodeURIComponent(tabId)}&run=${encodeURIComponent("fixture-run")}&agent=${encodeURIComponent("fixture-run:0")}`);
233
+ assert.equal(subagentOutputResponse.status, 200, "running subagent output endpoint should respond");
234
+ assert.equal(subagentOutputResponse.body?.data?.agent?.name, "reviewer", "subagent output should target the selected child agent");
235
+ assert.deepEqual(subagentOutputResponse.body?.data?.agent?.recentOutput, ["Inspecting current implementation", "Waiting for the next tool result"], "subagent output should preserve bounded live output lines");
236
+ assert.equal(subagentOutputResponse.body?.data?.agent?.currentToolArgs, "README.md", "subagent output should include current tool state");
237
+ const unknownSubagentOutput = await request("127.0.0.1", `/api/subagents/output?tab=${encodeURIComponent(tabId)}&run=missing&agent=missing`);
238
+ assert.equal(unknownSubagentOutput.status, 404, "subagent output endpoint should reject untracked selections");
239
+ const subagentFixtureClear = await request("127.0.0.1", "/api/prompt", { method: "POST", body: { tab: tabId, message: "fixture subagents clear" } });
240
+ assert.equal(subagentFixtureClear.status, 200, "subagent fixture clear should be accepted");
241
+ for (let attempt = 0; attempt < 20; attempt++) {
242
+ subagentsResponse = await request("127.0.0.1", "/api/subagents");
243
+ if (subagentsResponse.body?.data?.totalAgents === 0) break;
244
+ await delay(50);
245
+ }
246
+ assert.equal(subagentsResponse.body?.data?.totalAgents, 0, "completed subagents should disappear from the running overview");
247
+
216
248
  const state = await request("127.0.0.1", `/api/state?tab=${encodeURIComponent(tabId)}`);
217
249
  assert.equal(state.status, 200);
218
250
  assert.equal(state.body?.data?.model?.provider, "fake", "state should come from the fake pi RPC");
@@ -280,6 +312,21 @@ try {
280
312
  assert.equal(gitReadmeAgain.body?.data?.readme?.created, false);
281
313
  assert.equal(gitReadmeAgain.body?.data?.gitignore?.created, false);
282
314
 
315
+ const bypassCommit = await request("127.0.0.1", `/api/git-workflow/initial-commit?tab=${encodeURIComponent(tabId)}`);
316
+ assert.equal(bypassCommit.status, 405, "GET on a mutating git workflow path should be refused with 405");
317
+ assert.equal(bypassCommit.body?.ok, false, "GET bypass refusal should carry ok: false");
318
+ const headAfterBypass = spawnSync("git", ["rev-parse", "HEAD"], { cwd, encoding: "utf8" });
319
+ assert.notEqual(headAfterBypass.status, 0, "GET bypass attempt must not create a commit");
320
+
321
+ const bypassPush = await request("127.0.0.1", `/api/git-workflow/push?tab=${encodeURIComponent(tabId)}`);
322
+ assert.equal(bypassPush.status, 405, "GET /api/git-workflow/push should be refused with 405");
323
+
324
+ const bypassAdd = await request("127.0.0.1", `/api/git-workflow/add?tab=${encodeURIComponent(tabId)}`);
325
+ assert.equal(bypassAdd.status, 405, "GET /api/git-workflow/add should be refused with 405");
326
+
327
+ const postReadonly = await request("127.0.0.1", "/api/git-workflow/default-commit-message", { method: "POST", body: { tab: tabId } });
328
+ assert.equal(postReadonly.status, 405, "POST on a read-only git workflow path should be refused with 405");
329
+
283
330
  const gitCommit = await request("127.0.0.1", "/api/git-workflow/initial-commit", { method: "POST", body: { tab: tabId } });
284
331
  assert.equal(gitCommit.status, 200);
285
332
  assert.equal(gitCommit.body?.ok, true, "initial commit endpoint should commit the staged README.md");
@@ -500,6 +547,305 @@ try {
500
547
  assert.equal(multipleDefault.status, 200);
501
548
  assert.equal(multipleDefault.body?.ok, true, "default commit message endpoint should still return ok when no default is available");
502
549
  assert.equal(multipleDefault.body?.data?.message, "", "multiple staged files should not get a default commit message");
550
+
551
+ // ---- Git action endpoints: staging, operations, stash, fetch/divergence, undo, tags, prune ----
552
+
553
+ const gitFixturesRoot = await mkdtemp(path.join(tmpdir(), "pi-webui-git-actions-"));
554
+ const makeFixtureRepo = async (name) => {
555
+ const dir = path.join(gitFixturesRoot, name);
556
+ await mkdir(dir, { recursive: true });
557
+ runGitFixture(["init", "-b", "main", dir], gitFixturesRoot, `${name} fixture should initialize`);
558
+ runGitFixture(["config", "user.name", "Pi WebUI Test"], dir, `${name} fixture should set user name`);
559
+ runGitFixture(["config", "user.email", "pi-webui-test@example.invalid"], dir, `${name} fixture should set user email`);
560
+ await writeFile(path.join(dir, "file.txt"), "base\n");
561
+ runGitFixture(["add", "file.txt"], dir, `${name} fixture should stage base`);
562
+ runGitFixture(["commit", "-m", "base"], dir, `${name} fixture should commit base`);
563
+ return dir;
564
+ };
565
+ const openFixtureTab = async (dir, title) => {
566
+ const created = await request("127.0.0.1", "/api/tabs", { method: "POST", body: { cwd: dir, title } });
567
+ assert.equal(created.status, 201, `${title} tab should open`);
568
+ const id = created.body?.data?.tab?.id;
569
+ assert.ok(id, `${title} tab should have an id`);
570
+ return id;
571
+ };
572
+
573
+ // Staging endpoints
574
+ const stagingRepo = await makeFixtureRepo("staging");
575
+ const stagingTab = await openFixtureTab(stagingRepo, "staging-fixture");
576
+ await writeFile(path.join(stagingRepo, "file.txt"), "modified\n");
577
+ await writeFile(path.join(stagingRepo, "loose.txt"), "loose\n");
578
+
579
+ const stageFile = await request("127.0.0.1", "/api/git-changes/stage-file", { method: "POST", body: { tab: stagingTab, path: "file.txt" } });
580
+ assert.equal(stageFile.status, 200);
581
+ assert.equal(stageFile.body?.ok, true, "stage-file endpoint should stage a modified file");
582
+ assert.equal(stageFile.body?.data?.changes?.summary?.staged, 1, "stage-file should report one staged file afterwards");
583
+
584
+ const unstageFile = await request("127.0.0.1", "/api/git-changes/unstage-file", { method: "POST", body: { tab: stagingTab, path: "file.txt" } });
585
+ assert.equal(unstageFile.status, 200);
586
+ assert.equal(unstageFile.body?.ok, true, "unstage-file endpoint should unstage the file");
587
+ assert.equal(unstageFile.body?.data?.changes?.summary?.staged, 0, "unstage-file should report zero staged files afterwards");
588
+
589
+ const discardUnconfirmed = await request("127.0.0.1", "/api/git-changes/discard-file", { method: "POST", body: { tab: stagingTab, path: "file.txt" } });
590
+ assert.equal(discardUnconfirmed.status, 409, "discard-file without confirmed: true should be refused");
591
+ const discardConfirmed = await request("127.0.0.1", "/api/git-changes/discard-file", { method: "POST", body: { tab: stagingTab, path: "file.txt", confirmed: true } });
592
+ assert.equal(discardConfirmed.status, 200);
593
+ assert.equal(discardConfirmed.body?.ok, true, "confirmed discard-file should restore the file");
594
+ assert.equal(await readFile(path.join(stagingRepo, "file.txt"), "utf8"), "base\n", "discard-file should restore committed content");
595
+
596
+ const escapeStage = await request("127.0.0.1", "/api/git-changes/stage-file", { method: "POST", body: { tab: stagingTab, path: "../outside.txt" } });
597
+ assert.equal(escapeStage.body?.ok, false, "stage-file must reject paths escaping the repository root");
598
+
599
+ const deleteTracked = await request("127.0.0.1", "/api/git-changes/delete-untracked", { method: "POST", body: { tab: stagingTab, path: "file.txt", confirmed: true } });
600
+ assert.equal(deleteTracked.status, 409, "delete-untracked must refuse tracked files");
601
+ const deleteUnconfirmed = await request("127.0.0.1", "/api/git-changes/delete-untracked", { method: "POST", body: { tab: stagingTab, path: "loose.txt" } });
602
+ assert.equal(deleteUnconfirmed.status, 409, "delete-untracked without confirmed: true should be refused");
603
+ const deleteConfirmed = await request("127.0.0.1", "/api/git-changes/delete-untracked", { method: "POST", body: { tab: stagingTab, path: "loose.txt", confirmed: true } });
604
+ assert.equal(deleteConfirmed.status, 200);
605
+ assert.equal(deleteConfirmed.body?.ok, true, "confirmed delete-untracked should delete the file");
606
+ assert.equal(await readFile(path.join(stagingRepo, "loose.txt"), "utf8").then(() => true, () => false), false, "delete-untracked should remove the file from disk");
607
+
608
+ // Diff truncation transparency: a diff larger than the 500KB cap must be flagged.
609
+ const truncationRepo = await makeFixtureRepo("diff-truncation");
610
+ const truncationTab = await openFixtureTab(truncationRepo, "diff-truncation-fixture");
611
+ const bigLines = Array.from({ length: 24_000 }, (_, index) => `line ${index} ${"x".repeat(24)}`).join("\n");
612
+ await writeFile(path.join(truncationRepo, "big.txt"), `${bigLines}\n`);
613
+ runGitFixture(["add", "big.txt"], truncationRepo, "truncation fixture should stage the big file");
614
+ runGitFixture(["commit", "-m", "big base"], truncationRepo, "truncation fixture should commit the big file");
615
+ const flipped = Array.from({ length: 24_000 }, (_, index) => `LINE ${index} ${"y".repeat(24)}`).join("\n");
616
+ await writeFile(path.join(truncationRepo, "big.txt"), `${flipped}\n`);
617
+ const truncatedChanges = await request("127.0.0.1", `/api/git-changes?tab=${encodeURIComponent(truncationTab)}`, { timeoutMs: 20_000 });
618
+ assert.equal(truncatedChanges.body?.ok, true, "git changes should load the oversized diff repo");
619
+ const unstagedSection = (truncatedChanges.body?.data?.sections || []).find((section) => section.key === "unstaged");
620
+ assert.ok(unstagedSection, "unstaged section should exist for the oversized diff");
621
+ assert.equal(unstagedSection.truncated, true, "oversized diffs must carry a structured truncated flag");
622
+ assert.ok(Number(unstagedSection.capBytes) > 0, "truncated sections must report the cap size");
623
+ const stagedSection = (truncatedChanges.body?.data?.sections || []).find((section) => section.key === "staged");
624
+ assert.equal(stagedSection?.truncated, false, "small diffs must not be flagged as truncated");
625
+
626
+ // Merge conflict lifecycle
627
+ const makeConflictRepo = async (name) => {
628
+ const dir = await makeFixtureRepo(name);
629
+ runGitFixture(["checkout", "-b", "side"], dir, `${name} fixture should branch`);
630
+ await writeFile(path.join(dir, "file.txt"), "side\n");
631
+ runGitFixture(["commit", "-am", "side"], dir, `${name} fixture should commit side`);
632
+ runGitFixture(["checkout", "main"], dir, `${name} fixture should return to main`);
633
+ await writeFile(path.join(dir, "file.txt"), "main\n");
634
+ runGitFixture(["commit", "-am", "main"], dir, `${name} fixture should commit main`);
635
+ const merge = spawnSync("git", ["merge", "side"], { cwd: dir, encoding: "utf8" });
636
+ assert.notEqual(merge.status, 0, `${name} fixture merge should conflict`);
637
+ return dir;
638
+ };
639
+
640
+ const mergeRepo = await makeConflictRepo("merge-conflict");
641
+ const mergeTab = await openFixtureTab(mergeRepo, "merge-conflict-fixture");
642
+ const operationSnapshot = await request("127.0.0.1", `/api/git-operation?tab=${encodeURIComponent(mergeTab)}`);
643
+ assert.equal(operationSnapshot.status, 200);
644
+ assert.equal(operationSnapshot.body?.ok, true, "operation endpoint should read a merging repo");
645
+ assert.equal(operationSnapshot.body?.data?.operation, "merge");
646
+ assert.equal(operationSnapshot.body?.data?.canContinue, false, "merge with conflicts must not be continuable");
647
+ assert.equal(operationSnapshot.body?.data?.conflicts?.[0]?.path, "file.txt");
648
+ assert.equal(operationSnapshot.body?.data?.conflicts?.[0]?.status, "UU");
649
+ assert.equal(operationSnapshot.body?.data?.conflicts?.[0]?.preview?.hasMarkers, true, "conflict preview should detect conflict markers");
650
+
651
+ const continueBlocked = await request("127.0.0.1", "/api/git-operation/continue", { method: "POST", body: { tab: mergeTab } });
652
+ assert.equal(continueBlocked.status, 200);
653
+ assert.equal(continueBlocked.body?.ok, false, "continue with unmerged paths must fail");
654
+ assert.equal(continueBlocked.body?.code, "UNMERGED_PATHS");
655
+
656
+ await writeFile(path.join(mergeRepo, "file.txt"), "resolved\n");
657
+ const markResolved = await request("127.0.0.1", "/api/git-operation/stage-file", { method: "POST", body: { tab: mergeTab, path: "file.txt" } });
658
+ assert.equal(markResolved.status, 200);
659
+ assert.equal(markResolved.body?.ok, true, "operation stage-file should mark the conflict as resolved");
660
+ assert.equal(markResolved.body?.data?.operation?.canContinue, true, "after staging the only conflict, continue should be possible");
661
+
662
+ const continueMerge = await request("127.0.0.1", "/api/git-operation/continue", { method: "POST", body: { tab: mergeTab }, timeoutMs: 20_000 });
663
+ assert.equal(continueMerge.status, 200);
664
+ assert.equal(continueMerge.body?.ok, true, `continue should commit the resolved merge: ${continueMerge.body?.error || ""}`);
665
+ assert.equal(continueMerge.body?.data?.operation?.operation, null, "after continuing, no operation should remain");
666
+
667
+ const abortRepo = await makeConflictRepo("merge-abort");
668
+ const abortTab = await openFixtureTab(abortRepo, "merge-abort-fixture");
669
+ const abortUnconfirmed = await request("127.0.0.1", "/api/git-operation/abort", { method: "POST", body: { tab: abortTab } });
670
+ assert.equal(abortUnconfirmed.status, 409, "abort without confirmed: true should be refused");
671
+ const abortConfirmed = await request("127.0.0.1", "/api/git-operation/abort", { method: "POST", body: { tab: abortTab, confirmed: true }, timeoutMs: 20_000 });
672
+ assert.equal(abortConfirmed.status, 200);
673
+ assert.equal(abortConfirmed.body?.ok, true, "confirmed abort should stop the merge");
674
+ assert.equal(abortConfirmed.body?.data?.operation?.operation, null, "after aborting, no operation should remain");
675
+ assert.equal(await readFile(path.join(abortRepo, "file.txt"), "utf8"), "main\n", "abort should restore the pre-merge content");
676
+
677
+ // Rebase lifecycle: skip support + abort
678
+ const rebaseRepo = await makeFixtureRepo("rebase-conflict");
679
+ runGitFixture(["checkout", "-b", "side"], rebaseRepo, "rebase fixture should branch");
680
+ await writeFile(path.join(rebaseRepo, "file.txt"), "side\n");
681
+ runGitFixture(["commit", "-am", "side"], rebaseRepo, "rebase fixture should commit side");
682
+ runGitFixture(["checkout", "main"], rebaseRepo, "rebase fixture should return to main");
683
+ await writeFile(path.join(rebaseRepo, "file.txt"), "main\n");
684
+ runGitFixture(["commit", "-am", "main"], rebaseRepo, "rebase fixture should commit main");
685
+ runGitFixture(["checkout", "side"], rebaseRepo, "rebase fixture should return to side");
686
+ const rebaseStart = spawnSync("git", ["rebase", "main"], { cwd: rebaseRepo, encoding: "utf8" });
687
+ assert.notEqual(rebaseStart.status, 0, "rebase fixture should conflict");
688
+ const rebaseTab = await openFixtureTab(rebaseRepo, "rebase-conflict-fixture");
689
+ const rebaseSnapshot = await request("127.0.0.1", `/api/git-operation?tab=${encodeURIComponent(rebaseTab)}`);
690
+ assert.equal(rebaseSnapshot.body?.data?.operation, "rebase");
691
+ assert.equal(rebaseSnapshot.body?.data?.canSkip, true, "rebase should support skip");
692
+ const rebaseAbort = await request("127.0.0.1", "/api/git-operation/abort", { method: "POST", body: { tab: rebaseTab, confirmed: true }, timeoutMs: 20_000 });
693
+ assert.equal(rebaseAbort.body?.ok, true, "confirmed rebase abort should succeed");
694
+
695
+ // Bisect lifecycle
696
+ const bisectRepo = await makeFixtureRepo("bisect");
697
+ runGitFixture(["bisect", "start"], bisectRepo, "bisect fixture should start");
698
+ const bisectTab = await openFixtureTab(bisectRepo, "bisect-fixture");
699
+ const bisectSnapshot = await request("127.0.0.1", `/api/git-operation?tab=${encodeURIComponent(bisectTab)}`);
700
+ assert.equal(bisectSnapshot.body?.data?.operation, "bisect");
701
+ const bisectInvalid = await request("127.0.0.1", "/api/git-operation/bisect", { method: "POST", body: { tab: bisectTab, verdict: "evil" } });
702
+ assert.equal(bisectInvalid.status, 400, "invalid bisect verdicts must be rejected");
703
+ const bisectResetUnconfirmed = await request("127.0.0.1", "/api/git-operation/bisect", { method: "POST", body: { tab: bisectTab, verdict: "reset" } });
704
+ assert.equal(bisectResetUnconfirmed.status, 409, "bisect reset without confirmed: true should be refused");
705
+ const bisectReset = await request("127.0.0.1", "/api/git-operation/bisect", { method: "POST", body: { tab: bisectTab, verdict: "reset", confirmed: true }, timeoutMs: 20_000 });
706
+ assert.equal(bisectReset.body?.ok, true, "confirmed bisect reset should succeed");
707
+ assert.equal(bisectReset.body?.data?.operation?.operation, null, "after reset, no bisect should remain");
708
+
709
+ // Stash lifecycle
710
+ const stashRepo = await makeFixtureRepo("stash");
711
+ const stashTab = await openFixtureTab(stashRepo, "stash-fixture");
712
+ await writeFile(path.join(stashRepo, "file.txt"), "stash me\n");
713
+ await writeFile(path.join(stashRepo, "new-file.txt"), "untracked\n");
714
+ const stashSave = await request("127.0.0.1", "/api/git-stash/save", { method: "POST", body: { tab: stashTab, includeUntracked: true, message: "harness stash" } });
715
+ assert.equal(stashSave.status, 200);
716
+ assert.equal(stashSave.body?.ok, true, `stash save should succeed: ${stashSave.body?.error || ""}`);
717
+ assert.equal(stashSave.body?.data?.stashes?.length, 1, "stash save should leave one stash entry");
718
+
719
+ const stashList = await request("127.0.0.1", `/api/git-stash?tab=${encodeURIComponent(stashTab)}`);
720
+ assert.equal(stashList.body?.ok, true);
721
+ assert.equal(stashList.body?.data?.stashes?.[0]?.ref, "stash@{0}");
722
+ assert.match(stashList.body?.data?.stashes?.[0]?.subject || "", /harness stash/);
723
+
724
+ const stashShow = await request("127.0.0.1", `/api/git-stash/show?ref=${encodeURIComponent("stash@{0}")}&tab=${encodeURIComponent(stashTab)}`);
725
+ assert.equal(stashShow.body?.ok, true, "stash show should return a preview");
726
+ assert.match(stashShow.body?.data?.stat || "", /file\.txt/, "stash preview should mention the stashed file");
727
+
728
+ const stashBadRef = await request("127.0.0.1", `/api/git-stash/show?ref=${encodeURIComponent("stash@{0}; rm -rf /")}&tab=${encodeURIComponent(stashTab)}`);
729
+ assert.equal(stashBadRef.status, 400, "malformed stash refs must be rejected");
730
+
731
+ const stashApply = await request("127.0.0.1", "/api/git-stash/apply", { method: "POST", body: { tab: stashTab, ref: "stash@{0}" } });
732
+ assert.equal(stashApply.body?.ok, true, `stash apply should succeed: ${stashApply.body?.error || ""}`);
733
+ assert.equal(await readFile(path.join(stashRepo, "file.txt"), "utf8"), "stash me\n", "stash apply should restore the stashed content");
734
+
735
+ const stashDropUnconfirmed = await request("127.0.0.1", "/api/git-stash/drop", { method: "POST", body: { tab: stashTab, ref: "stash@{0}" } });
736
+ assert.equal(stashDropUnconfirmed.status, 409, "stash drop without confirmed: true should be refused");
737
+ const stashDrop = await request("127.0.0.1", "/api/git-stash/drop", { method: "POST", body: { tab: stashTab, ref: "stash@{0}", confirmed: true } });
738
+ assert.equal(stashDrop.body?.ok, true, "confirmed stash drop should succeed");
739
+ assert.equal(stashDrop.body?.data?.stashes?.length, 0, "dropping the only stash should empty the list");
740
+
741
+ // Fetch, divergence classification, integrate, push classification
742
+ await writeFile(path.join(remoteWork, "incoming.txt"), "base\nremote one\nremote two\nremote three\n");
743
+ runGitFixture(["commit", "-am", "remote three"], remoteWork, "remote worktree should commit third incoming change");
744
+ runGitFixture(["push", "origin", "main"], remoteWork, "remote worktree should push the third commit");
745
+ await writeFile(path.join(localRepo, "local-only.txt"), "local\n");
746
+ runGitFixture(["add", "local-only.txt"], localRepo, "local repo should stage local divergence");
747
+ runGitFixture(["commit", "-m", "local divergence"], localRepo, "local repo should commit local divergence");
748
+
749
+ const fetchResult = await request("127.0.0.1", "/api/git-fetch", { method: "POST", body: { tab: remoteTabId }, timeoutMs: 30_000 });
750
+ assert.equal(fetchResult.status, 200);
751
+ assert.equal(fetchResult.body?.ok, true, `fetch endpoint should fetch from the bare origin: ${fetchResult.body?.error || ""}`);
752
+ assert.equal(fetchResult.body?.data?.changes?.summary?.behind, 1, "fetch should reveal the remote commit");
753
+ assert.equal(fetchResult.body?.data?.changes?.remote?.diverged, true, "fetch should reveal divergence");
754
+ assert.equal(fetchResult.body?.data?.changes?.remote?.canPull, false, "diverged branches must not offer one-click pull");
755
+
756
+ const divergedPull = await request("127.0.0.1", "/api/git-changes/pull", { method: "POST", body: { tab: remoteTabId }, timeoutMs: 30_000 });
757
+ assert.equal(divergedPull.body?.ok, false, "ff-only pull must fail on diverged branches");
758
+ assert.equal(divergedPull.body?.code, "DIVERGED", "diverged pull failures should be classified");
759
+ assert.ok(divergedPull.body?.hint, "diverged pull failures should carry a hint");
760
+
761
+ const integrateUnconfirmed = await request("127.0.0.1", "/api/git-changes/integrate", { method: "POST", body: { tab: remoteTabId, mode: "merge" } });
762
+ assert.equal(integrateUnconfirmed.status, 409, "integrate without confirmed: true should be refused");
763
+ const integrateMerge = await request("127.0.0.1", "/api/git-changes/integrate", { method: "POST", body: { tab: remoteTabId, mode: "merge", confirmed: true }, timeoutMs: 30_000 });
764
+ assert.equal(integrateMerge.body?.ok, true, `confirmed merge integrate should succeed: ${integrateMerge.body?.error || ""}`);
765
+ assert.equal(integrateMerge.body?.data?.changes?.summary?.behind, 0, "after integrating, nothing should remain behind");
766
+
767
+ const pushDiverged = await request("127.0.0.1", "/api/git-workflow/push", { method: "POST", body: { tab: remoteTabId }, timeoutMs: 30_000 });
768
+ assert.equal(pushDiverged.body?.ok, true, `push should succeed after integration: ${pushDiverged.body?.error || ""}`);
769
+ assert.equal(pushDiverged.body?.data?.branch, "main");
770
+ assert.equal(pushDiverged.body?.data?.protectedBranch, true, "pushing main should be flagged as a protected branch");
771
+
772
+ // Undo guards: pushed commits must not be undoable
773
+ const undoPushedState = await request("127.0.0.1", `/api/git-undo?tab=${encodeURIComponent(remoteTabId)}`);
774
+ assert.equal(undoPushedState.body?.ok, true);
775
+ assert.equal(undoPushedState.body?.data?.canUndoLastCommit, false, "a pushed HEAD must not be undoable");
776
+ const undoPushed = await request("127.0.0.1", "/api/git-undo/last-commit", { method: "POST", body: { tab: remoteTabId, confirmed: true } });
777
+ assert.equal(undoPushed.status, 409, "undoing a pushed commit must be refused");
778
+
779
+ // Undo/amend on an unpushed repo
780
+ const undoRepo = await makeFixtureRepo("undo");
781
+ const undoTab = await openFixtureTab(undoRepo, "undo-fixture");
782
+ await writeFile(path.join(undoRepo, "file.txt"), "second\n");
783
+ runGitFixture(["commit", "-am", "second"], undoRepo, "undo fixture should commit a second change");
784
+
785
+ const undoState = await request("127.0.0.1", `/api/git-undo?tab=${encodeURIComponent(undoTab)}`);
786
+ assert.equal(undoState.body?.ok, true);
787
+ assert.equal(undoState.body?.data?.canUndoLastCommit, true, "an unpushed commit with a parent should be undoable");
788
+ assert.equal(undoState.body?.data?.lastCommit?.subject, "second");
789
+
790
+ const undoUnconfirmed = await request("127.0.0.1", "/api/git-undo/last-commit", { method: "POST", body: { tab: undoTab } });
791
+ assert.equal(undoUnconfirmed.status, 409, "undo without confirmed: true should be refused");
792
+ const undoConfirmed = await request("127.0.0.1", "/api/git-undo/last-commit", { method: "POST", body: { tab: undoTab, confirmed: true } });
793
+ assert.equal(undoConfirmed.body?.ok, true, `confirmed undo should soft-reset: ${undoConfirmed.body?.error || ""}`);
794
+ assert.equal(undoConfirmed.body?.data?.restoreCommand, "git reset --soft ORIG_HEAD");
795
+ assert.equal(undoConfirmed.body?.data?.changes?.summary?.staged, 1, "soft reset should keep the change staged");
796
+ assert.equal(runGitFixture(["log", "-1", "--format=%s"], undoRepo, "undo fixture should read HEAD subject"), "base", "undo should move HEAD back to the base commit");
797
+
798
+ const undoNoParent = await request("127.0.0.1", "/api/git-undo/last-commit", { method: "POST", body: { tab: undoTab, confirmed: true } });
799
+ assert.equal(undoNoParent.status, 409, "undoing the root commit must be refused");
800
+
801
+ const amendWithStaged = await request("127.0.0.1", "/api/git-undo/amend-message", { method: "POST", body: { tab: undoTab, confirmed: true, message: "nope" } });
802
+ assert.equal(amendWithStaged.status, 409, "amending with staged changes must be refused");
803
+ runGitFixture(["commit", "-m", "second again"], undoRepo, "undo fixture should re-commit the staged change");
804
+ const amendUnconfirmed = await request("127.0.0.1", "/api/git-undo/amend-message", { method: "POST", body: { tab: undoTab, message: "amended subject" } });
805
+ assert.equal(amendUnconfirmed.status, 409, "amend without confirmed: true should be refused");
806
+ const amendConfirmed = await request("127.0.0.1", "/api/git-undo/amend-message", { method: "POST", body: { tab: undoTab, confirmed: true, message: "amended subject" } });
807
+ assert.equal(amendConfirmed.body?.ok, true, `confirmed amend should rewrite the message: ${amendConfirmed.body?.error || ""}`);
808
+ assert.equal(runGitFixture(["log", "-1", "--format=%s"], undoRepo, "undo fixture should read amended subject"), "amended subject");
809
+
810
+ const reflog = await request("127.0.0.1", `/api/git-reflog?tab=${encodeURIComponent(undoTab)}`);
811
+ assert.equal(reflog.body?.ok, true, "reflog endpoint should return entries");
812
+ assert.ok((reflog.body?.data?.entries || []).length >= 3, "reflog should include the undo/amend history");
813
+ assert.match(reflog.body?.data?.entries?.[0]?.selector || "", /^HEAD@\{0\}$/);
814
+
815
+ // Tags
816
+ const tagInvalid = await request("127.0.0.1", "/api/git-tags/create", { method: "POST", body: { tab: undoTab, confirmed: true, name: "bad tag" } });
817
+ assert.equal(tagInvalid.status, 400, "invalid tag names must be rejected");
818
+ const tagUnconfirmed = await request("127.0.0.1", "/api/git-tags/create", { method: "POST", body: { tab: undoTab, name: "v0.0.1-harness", message: "harness tag" } });
819
+ assert.equal(tagUnconfirmed.status, 409, "tag creation without confirmed: true should be refused");
820
+ const tagCreate = await request("127.0.0.1", "/api/git-tags/create", { method: "POST", body: { tab: undoTab, confirmed: true, name: "v0.0.1-harness", message: "harness tag" } });
821
+ assert.equal(tagCreate.body?.ok, true, `confirmed tag creation should succeed: ${tagCreate.body?.error || ""}`);
822
+ const tagList = await request("127.0.0.1", `/api/git-tags?tab=${encodeURIComponent(undoTab)}`);
823
+ assert.equal(tagList.body?.ok, true);
824
+ const createdTag = (tagList.body?.data?.tags || []).find((tag) => tag.name === "v0.0.1-harness");
825
+ assert.ok(createdTag, "created tag should appear in the tag list");
826
+ assert.equal(createdTag.annotated, true, "created tag should be annotated");
827
+ assert.equal(createdTag.atHead, true, "created tag should point at HEAD");
828
+
829
+ // Signing diagnostics + submodule status (read-only)
830
+ const signing = await request("127.0.0.1", `/api/git-signing?tab=${encodeURIComponent(undoTab)}`);
831
+ assert.equal(signing.body?.ok, true, "signing diagnostics should load");
832
+ assert.equal(signing.body?.data?.mismatch, false, "fixture repo should not report a signing mismatch");
833
+ const submodules = await request("127.0.0.1", `/api/git-submodules?tab=${encodeURIComponent(undoTab)}`);
834
+ assert.equal(submodules.body?.ok, true, "submodule status should load");
835
+ assert.equal(submodules.body?.data?.hasSubmodules, false, "fixture repo has no submodules");
836
+
837
+ // Worktree prune (dry run + confirmed)
838
+ const pruneDryRun = await request("127.0.0.1", `/api/git-worktrees/prune?tab=${encodeURIComponent(undoTab)}`);
839
+ assert.equal(pruneDryRun.body?.ok, true, "prune dry run should load");
840
+ assert.equal(pruneDryRun.body?.data?.dryRun, true);
841
+ const pruneUnconfirmed = await request("127.0.0.1", "/api/git-worktrees/prune", { method: "POST", body: { tab: undoTab } });
842
+ assert.equal(pruneUnconfirmed.status, 409, "prune without confirmed: true should be refused");
843
+ const pruneConfirmed = await request("127.0.0.1", "/api/git-worktrees/prune", { method: "POST", body: { tab: undoTab, confirmed: true }, timeoutMs: 20_000 });
844
+ assert.equal(pruneConfirmed.body?.ok, true, `confirmed prune should succeed: ${pruneConfirmed.body?.error || ""}`);
845
+
846
+ 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 });
847
+ assert.equal(closeGitActionTabs.status, 200, "git action fixture tabs should close");
848
+ await rmWithRetry(gitFixturesRoot);
503
849
  } else {
504
850
  console.log("http-endpoints-harness: git not available; skipping git init workflow endpoint checks");
505
851
  }
@@ -756,6 +1102,12 @@ try {
756
1102
  const binaryRelative = "files-fixture/binary.bin";
757
1103
  const noDefaultRelative = "files-fixture/no-default.piunknown";
758
1104
  const largeRelative = "files-fixture/large.txt";
1105
+ const movableFileRelative = "files-fixture/move-me.txt";
1106
+ const movedFileRelative = "files-fixture/docs/moved-file.txt";
1107
+ const movableDirectoryRelative = "files-fixture/move-dir";
1108
+ const movedDirectoryRelative = "files-fixture/docs/move-dir";
1109
+ const deleteFileRelative = "files-fixture/delete-me.txt";
1110
+ const deleteDirectoryRelative = "files-fixture/delete-dir";
759
1111
  const depthEightFileRelative = "deep-search/f1/f2/f3/f4/f5/f6/depth-eight-file.txt";
760
1112
  const depthEightDirectoryRelative = "deep-search/d1/d2/d3/d4/d5/d6/depth-eight-dir";
761
1113
  const depthNineFileRelative = "deep-search/t1/t2/t3/t4/t5/t6/t7/too-deep-file.txt";
@@ -770,6 +1122,12 @@ try {
770
1122
  await writeFile(path.join(cwd, depthNineFileRelative), "depth 9 search fixture\n", "utf8");
771
1123
  await writeFile(path.join(cwd, binaryRelative), Buffer.from([0, 1, 2, 3]));
772
1124
  await writeFile(path.join(cwd, largeRelative), Buffer.alloc(2 * 1024 * 1024 + 1, 0x61));
1125
+ await writeFile(path.join(cwd, movableFileRelative), "move me\n", "utf8");
1126
+ await mkdir(path.join(cwd, movableDirectoryRelative), { recursive: true });
1127
+ await writeFile(path.join(cwd, movableDirectoryRelative, "nested.txt"), "nested move\n", "utf8");
1128
+ await writeFile(path.join(cwd, deleteFileRelative), "delete me\n", "utf8");
1129
+ await mkdir(path.join(cwd, deleteDirectoryRelative), { recursive: true });
1130
+ await writeFile(path.join(cwd, deleteDirectoryRelative, "nested.txt"), "nested delete\n", "utf8");
773
1131
 
774
1132
  const fileTree = await request("127.0.0.1", `/api/files?tab=${encodeURIComponent(tabId)}&path=${encodeURIComponent("files-fixture")}`);
775
1133
  assert.equal(fileTree.status, 200, `file tree endpoint should list workspace directories: ${fileTree.body?.error || ""}`);
@@ -846,6 +1204,40 @@ try {
846
1204
  assert.equal(savedFile.status, 200, `file save should succeed from localhost: ${savedFile.body?.error || ""}`);
847
1205
  assert.equal(await readFile(path.join(cwd, viewerRelative), "utf8"), "updated from WebUI\n", "file save endpoint should write UTF-8 text content");
848
1206
 
1207
+ const moveUnconfirmed = await request("127.0.0.1", "/api/files/move", { method: "POST", body: { tab: tabId, path: movableFileRelative, toPath: movedFileRelative } });
1208
+ assert.equal(moveUnconfirmed.status, 409, "file moves require explicit confirmation");
1209
+
1210
+ const moveFile = await request("127.0.0.1", "/api/files/move", { method: "POST", body: { tab: tabId, path: movableFileRelative, toPath: movedFileRelative, confirmed: true } });
1211
+ assert.equal(moveFile.status, 200, `file move should succeed from localhost: ${moveFile.body?.error || ""}`);
1212
+ assert.equal(moveFile.body?.data?.destination, movedFileRelative, "move endpoint should report the new relative file path");
1213
+ assert.equal(await readFile(path.join(cwd, movedFileRelative), "utf8"), "move me\n", "move endpoint should relocate file contents");
1214
+ assert.equal(await pathExists(path.join(cwd, movableFileRelative)), false, "move endpoint should remove the original file path");
1215
+
1216
+ const moveDirectory = await request("127.0.0.1", "/api/files/move", { method: "POST", body: { tab: tabId, path: movableDirectoryRelative, toPath: "files-fixture/docs", confirmed: true } });
1217
+ assert.equal(moveDirectory.status, 200, `directory move should succeed from localhost: ${moveDirectory.body?.error || ""}`);
1218
+ assert.equal(moveDirectory.body?.data?.destination, movedDirectoryRelative, "moving to an existing directory should place the source under that directory");
1219
+ assert.equal(await readFile(path.join(cwd, movedDirectoryRelative, "nested.txt"), "utf8"), "nested move\n", "move endpoint should relocate directory contents");
1220
+ assert.equal(await pathExists(path.join(cwd, movableDirectoryRelative)), false, "directory move endpoint should remove the original directory path");
1221
+
1222
+ const moveExistingDestination = await request("127.0.0.1", "/api/files/move", { method: "POST", body: { tab: tabId, path: movedFileRelative, toPath: markdownRelative, confirmed: true } });
1223
+ assert.equal(moveExistingDestination.status, 409, "move endpoint should refuse to overwrite an existing destination");
1224
+
1225
+ const deleteUnconfirmed = await request("127.0.0.1", "/api/files", { method: "DELETE", body: { tab: tabId, path: deleteFileRelative } });
1226
+ assert.equal(deleteUnconfirmed.status, 409, "file deletes require explicit confirmation");
1227
+
1228
+ const deleteFile = await request("127.0.0.1", "/api/files", { method: "DELETE", body: { tab: tabId, path: deleteFileRelative, confirmed: true } });
1229
+ assert.equal(deleteFile.status, 200, `file delete should succeed from localhost: ${deleteFile.body?.error || ""}`);
1230
+ assert.equal(deleteFile.body?.data?.deleted, true, "delete endpoint should report successful file deletion");
1231
+ assert.equal(await pathExists(path.join(cwd, deleteFileRelative)), false, "delete endpoint should remove regular files");
1232
+
1233
+ const deleteDirectory = await request("127.0.0.1", "/api/files", { method: "DELETE", body: { tab: tabId, path: deleteDirectoryRelative, confirmed: true } });
1234
+ assert.equal(deleteDirectory.status, 200, `directory delete should succeed from localhost: ${deleteDirectory.body?.error || ""}`);
1235
+ assert.equal(deleteDirectory.body?.data?.type, "directory", "delete endpoint should report directory deletions");
1236
+ assert.equal(await pathExists(path.join(cwd, deleteDirectoryRelative)), false, "delete endpoint should remove directories recursively");
1237
+
1238
+ const deleteWorkspaceRoot = await request("127.0.0.1", "/api/files", { method: "DELETE", body: { tab: tabId, path: "", confirmed: true } });
1239
+ assert.equal(deleteWorkspaceRoot.status, 400, "delete endpoint must refuse deleting the active workspace root");
1240
+
849
1241
  const binaryContent = await request("127.0.0.1", `/api/files/content?tab=${encodeURIComponent(tabId)}&path=${encodeURIComponent(binaryRelative)}`);
850
1242
  assert.equal(binaryContent.status, 415, "binary files should be rejected by the WebUI file viewer");
851
1243
  assert.match(String(binaryContent.body?.error || ""), /binary/i);
@@ -862,6 +1254,12 @@ try {
862
1254
  assert.equal(outsideAbsolute.status, 403, "absolute paths outside the active tab cwd should be rejected");
863
1255
  assert.match(String(outsideAbsolute.body?.error || ""), /active tab working directory/i);
864
1256
 
1257
+ const outsideDelete = await request("127.0.0.1", "/api/files", { method: "DELETE", body: { tab: tabId, path: outsideFile, confirmed: true } });
1258
+ assert.equal(outsideDelete.status, 403, "delete endpoint should reject absolute paths outside the active tab cwd");
1259
+
1260
+ const outsideMoveDestination = await request("127.0.0.1", "/api/files/move", { method: "POST", body: { tab: tabId, path: movedFileRelative, toPath: outsideFile, confirmed: true } });
1261
+ assert.equal(outsideMoveDestination.status, 403, "move endpoint should reject destinations outside the active tab cwd");
1262
+
865
1263
  const symlinkPath = path.join(filesRoot, "outside-link.txt");
866
1264
  try {
867
1265
  await symlink(outsideFile, symlinkPath);
@@ -935,6 +1333,14 @@ try {
935
1333
  assert.equal(blockedFileSave.status, 409, "file edits should be blocked while Natural Conversation is active");
936
1334
  assert.equal(blockedFileSave.body?.error, "file edits are blocked");
937
1335
 
1336
+ const blockedFileDelete = await request("127.0.0.1", "/api/files", { method: "DELETE", body: { tab: tabId, path: viewerRelative, confirmed: true } });
1337
+ assert.equal(blockedFileDelete.status, 409, "file deletes should be blocked while Natural Conversation is active");
1338
+ assert.match(String(blockedFileDelete.body?.error || ""), /file deletion is blocked/i);
1339
+
1340
+ const blockedFileMove = await request("127.0.0.1", "/api/files/move", { method: "POST", body: { tab: tabId, path: viewerRelative, toPath: "files-fixture/blocked-move.txt", confirmed: true } });
1341
+ assert.equal(blockedFileMove.status, 409, "file moves should be blocked while Natural Conversation is active");
1342
+ assert.match(String(blockedFileMove.body?.error || ""), /file moves are blocked/i);
1343
+
938
1344
  const allowedConversationPrompt = await request("127.0.0.1", "/api/prompt", { method: "POST", body: { message: "Explain the current repo briefly", tab: tabId } });
939
1345
  assert.equal(allowedConversationPrompt.status, 200, "ordinary prompts remain allowed while Natural Conversation is active");
940
1346
 
@@ -1025,6 +1431,18 @@ try {
1025
1431
  });
1026
1432
  assert.equal(remoteFileOpenDefault.status, 403, "opening files in the default editor must be localhost-only");
1027
1433
 
1434
+ const remoteFileDelete = await request(lan, "/api/files", {
1435
+ method: "DELETE",
1436
+ body: { tab: tabId, path: viewerRelative, confirmed: true },
1437
+ });
1438
+ assert.equal(remoteFileDelete.status, 403, "file deletes must be localhost-only");
1439
+
1440
+ const remoteFileMove = await request(lan, "/api/files/move", {
1441
+ method: "POST",
1442
+ body: { tab: tabId, path: viewerRelative, toPath: "files-fixture/remote-move.txt", confirmed: true },
1443
+ });
1444
+ assert.equal(remoteFileMove.status, 403, "file moves must be localhost-only");
1445
+
1028
1446
  const remoteExport = await request(lan, "/api/prompt", {
1029
1447
  method: "POST",
1030
1448
  body: { message: "/export", tab: tabId },