@firstpick/pi-package-webui 0.6.4 → 0.6.5

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.
@@ -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,
@@ -280,6 +284,21 @@ try {
280
284
  assert.equal(gitReadmeAgain.body?.data?.readme?.created, false);
281
285
  assert.equal(gitReadmeAgain.body?.data?.gitignore?.created, false);
282
286
 
287
+ const bypassCommit = await request("127.0.0.1", `/api/git-workflow/initial-commit?tab=${encodeURIComponent(tabId)}`);
288
+ assert.equal(bypassCommit.status, 405, "GET on a mutating git workflow path should be refused with 405");
289
+ assert.equal(bypassCommit.body?.ok, false, "GET bypass refusal should carry ok: false");
290
+ const headAfterBypass = spawnSync("git", ["rev-parse", "HEAD"], { cwd, encoding: "utf8" });
291
+ assert.notEqual(headAfterBypass.status, 0, "GET bypass attempt must not create a commit");
292
+
293
+ const bypassPush = await request("127.0.0.1", `/api/git-workflow/push?tab=${encodeURIComponent(tabId)}`);
294
+ assert.equal(bypassPush.status, 405, "GET /api/git-workflow/push should be refused with 405");
295
+
296
+ const bypassAdd = await request("127.0.0.1", `/api/git-workflow/add?tab=${encodeURIComponent(tabId)}`);
297
+ assert.equal(bypassAdd.status, 405, "GET /api/git-workflow/add should be refused with 405");
298
+
299
+ const postReadonly = await request("127.0.0.1", "/api/git-workflow/default-commit-message", { method: "POST", body: { tab: tabId } });
300
+ assert.equal(postReadonly.status, 405, "POST on a read-only git workflow path should be refused with 405");
301
+
283
302
  const gitCommit = await request("127.0.0.1", "/api/git-workflow/initial-commit", { method: "POST", body: { tab: tabId } });
284
303
  assert.equal(gitCommit.status, 200);
285
304
  assert.equal(gitCommit.body?.ok, true, "initial commit endpoint should commit the staged README.md");
@@ -500,6 +519,305 @@ try {
500
519
  assert.equal(multipleDefault.status, 200);
501
520
  assert.equal(multipleDefault.body?.ok, true, "default commit message endpoint should still return ok when no default is available");
502
521
  assert.equal(multipleDefault.body?.data?.message, "", "multiple staged files should not get a default commit message");
522
+
523
+ // ---- Git action endpoints: staging, operations, stash, fetch/divergence, undo, tags, prune ----
524
+
525
+ const gitFixturesRoot = await mkdtemp(path.join(tmpdir(), "pi-webui-git-actions-"));
526
+ const makeFixtureRepo = async (name) => {
527
+ const dir = path.join(gitFixturesRoot, name);
528
+ await mkdir(dir, { recursive: true });
529
+ runGitFixture(["init", "-b", "main", dir], gitFixturesRoot, `${name} fixture should initialize`);
530
+ runGitFixture(["config", "user.name", "Pi WebUI Test"], dir, `${name} fixture should set user name`);
531
+ runGitFixture(["config", "user.email", "pi-webui-test@example.invalid"], dir, `${name} fixture should set user email`);
532
+ await writeFile(path.join(dir, "file.txt"), "base\n");
533
+ runGitFixture(["add", "file.txt"], dir, `${name} fixture should stage base`);
534
+ runGitFixture(["commit", "-m", "base"], dir, `${name} fixture should commit base`);
535
+ return dir;
536
+ };
537
+ const openFixtureTab = async (dir, title) => {
538
+ const created = await request("127.0.0.1", "/api/tabs", { method: "POST", body: { cwd: dir, title } });
539
+ assert.equal(created.status, 201, `${title} tab should open`);
540
+ const id = created.body?.data?.tab?.id;
541
+ assert.ok(id, `${title} tab should have an id`);
542
+ return id;
543
+ };
544
+
545
+ // Staging endpoints
546
+ const stagingRepo = await makeFixtureRepo("staging");
547
+ const stagingTab = await openFixtureTab(stagingRepo, "staging-fixture");
548
+ await writeFile(path.join(stagingRepo, "file.txt"), "modified\n");
549
+ await writeFile(path.join(stagingRepo, "loose.txt"), "loose\n");
550
+
551
+ const stageFile = await request("127.0.0.1", "/api/git-changes/stage-file", { method: "POST", body: { tab: stagingTab, path: "file.txt" } });
552
+ assert.equal(stageFile.status, 200);
553
+ assert.equal(stageFile.body?.ok, true, "stage-file endpoint should stage a modified file");
554
+ assert.equal(stageFile.body?.data?.changes?.summary?.staged, 1, "stage-file should report one staged file afterwards");
555
+
556
+ const unstageFile = await request("127.0.0.1", "/api/git-changes/unstage-file", { method: "POST", body: { tab: stagingTab, path: "file.txt" } });
557
+ assert.equal(unstageFile.status, 200);
558
+ assert.equal(unstageFile.body?.ok, true, "unstage-file endpoint should unstage the file");
559
+ assert.equal(unstageFile.body?.data?.changes?.summary?.staged, 0, "unstage-file should report zero staged files afterwards");
560
+
561
+ const discardUnconfirmed = await request("127.0.0.1", "/api/git-changes/discard-file", { method: "POST", body: { tab: stagingTab, path: "file.txt" } });
562
+ assert.equal(discardUnconfirmed.status, 409, "discard-file without confirmed: true should be refused");
563
+ const discardConfirmed = await request("127.0.0.1", "/api/git-changes/discard-file", { method: "POST", body: { tab: stagingTab, path: "file.txt", confirmed: true } });
564
+ assert.equal(discardConfirmed.status, 200);
565
+ assert.equal(discardConfirmed.body?.ok, true, "confirmed discard-file should restore the file");
566
+ assert.equal(await readFile(path.join(stagingRepo, "file.txt"), "utf8"), "base\n", "discard-file should restore committed content");
567
+
568
+ const escapeStage = await request("127.0.0.1", "/api/git-changes/stage-file", { method: "POST", body: { tab: stagingTab, path: "../outside.txt" } });
569
+ assert.equal(escapeStage.body?.ok, false, "stage-file must reject paths escaping the repository root");
570
+
571
+ const deleteTracked = await request("127.0.0.1", "/api/git-changes/delete-untracked", { method: "POST", body: { tab: stagingTab, path: "file.txt", confirmed: true } });
572
+ assert.equal(deleteTracked.status, 409, "delete-untracked must refuse tracked files");
573
+ const deleteUnconfirmed = await request("127.0.0.1", "/api/git-changes/delete-untracked", { method: "POST", body: { tab: stagingTab, path: "loose.txt" } });
574
+ assert.equal(deleteUnconfirmed.status, 409, "delete-untracked without confirmed: true should be refused");
575
+ const deleteConfirmed = await request("127.0.0.1", "/api/git-changes/delete-untracked", { method: "POST", body: { tab: stagingTab, path: "loose.txt", confirmed: true } });
576
+ assert.equal(deleteConfirmed.status, 200);
577
+ assert.equal(deleteConfirmed.body?.ok, true, "confirmed delete-untracked should delete the file");
578
+ assert.equal(await readFile(path.join(stagingRepo, "loose.txt"), "utf8").then(() => true, () => false), false, "delete-untracked should remove the file from disk");
579
+
580
+ // Diff truncation transparency: a diff larger than the 500KB cap must be flagged.
581
+ const truncationRepo = await makeFixtureRepo("diff-truncation");
582
+ const truncationTab = await openFixtureTab(truncationRepo, "diff-truncation-fixture");
583
+ const bigLines = Array.from({ length: 24_000 }, (_, index) => `line ${index} ${"x".repeat(24)}`).join("\n");
584
+ await writeFile(path.join(truncationRepo, "big.txt"), `${bigLines}\n`);
585
+ runGitFixture(["add", "big.txt"], truncationRepo, "truncation fixture should stage the big file");
586
+ runGitFixture(["commit", "-m", "big base"], truncationRepo, "truncation fixture should commit the big file");
587
+ const flipped = Array.from({ length: 24_000 }, (_, index) => `LINE ${index} ${"y".repeat(24)}`).join("\n");
588
+ await writeFile(path.join(truncationRepo, "big.txt"), `${flipped}\n`);
589
+ const truncatedChanges = await request("127.0.0.1", `/api/git-changes?tab=${encodeURIComponent(truncationTab)}`, { timeoutMs: 20_000 });
590
+ assert.equal(truncatedChanges.body?.ok, true, "git changes should load the oversized diff repo");
591
+ const unstagedSection = (truncatedChanges.body?.data?.sections || []).find((section) => section.key === "unstaged");
592
+ assert.ok(unstagedSection, "unstaged section should exist for the oversized diff");
593
+ assert.equal(unstagedSection.truncated, true, "oversized diffs must carry a structured truncated flag");
594
+ assert.ok(Number(unstagedSection.capBytes) > 0, "truncated sections must report the cap size");
595
+ const stagedSection = (truncatedChanges.body?.data?.sections || []).find((section) => section.key === "staged");
596
+ assert.equal(stagedSection?.truncated, false, "small diffs must not be flagged as truncated");
597
+
598
+ // Merge conflict lifecycle
599
+ const makeConflictRepo = async (name) => {
600
+ const dir = await makeFixtureRepo(name);
601
+ runGitFixture(["checkout", "-b", "side"], dir, `${name} fixture should branch`);
602
+ await writeFile(path.join(dir, "file.txt"), "side\n");
603
+ runGitFixture(["commit", "-am", "side"], dir, `${name} fixture should commit side`);
604
+ runGitFixture(["checkout", "main"], dir, `${name} fixture should return to main`);
605
+ await writeFile(path.join(dir, "file.txt"), "main\n");
606
+ runGitFixture(["commit", "-am", "main"], dir, `${name} fixture should commit main`);
607
+ const merge = spawnSync("git", ["merge", "side"], { cwd: dir, encoding: "utf8" });
608
+ assert.notEqual(merge.status, 0, `${name} fixture merge should conflict`);
609
+ return dir;
610
+ };
611
+
612
+ const mergeRepo = await makeConflictRepo("merge-conflict");
613
+ const mergeTab = await openFixtureTab(mergeRepo, "merge-conflict-fixture");
614
+ const operationSnapshot = await request("127.0.0.1", `/api/git-operation?tab=${encodeURIComponent(mergeTab)}`);
615
+ assert.equal(operationSnapshot.status, 200);
616
+ assert.equal(operationSnapshot.body?.ok, true, "operation endpoint should read a merging repo");
617
+ assert.equal(operationSnapshot.body?.data?.operation, "merge");
618
+ assert.equal(operationSnapshot.body?.data?.canContinue, false, "merge with conflicts must not be continuable");
619
+ assert.equal(operationSnapshot.body?.data?.conflicts?.[0]?.path, "file.txt");
620
+ assert.equal(operationSnapshot.body?.data?.conflicts?.[0]?.status, "UU");
621
+ assert.equal(operationSnapshot.body?.data?.conflicts?.[0]?.preview?.hasMarkers, true, "conflict preview should detect conflict markers");
622
+
623
+ const continueBlocked = await request("127.0.0.1", "/api/git-operation/continue", { method: "POST", body: { tab: mergeTab } });
624
+ assert.equal(continueBlocked.status, 200);
625
+ assert.equal(continueBlocked.body?.ok, false, "continue with unmerged paths must fail");
626
+ assert.equal(continueBlocked.body?.code, "UNMERGED_PATHS");
627
+
628
+ await writeFile(path.join(mergeRepo, "file.txt"), "resolved\n");
629
+ const markResolved = await request("127.0.0.1", "/api/git-operation/stage-file", { method: "POST", body: { tab: mergeTab, path: "file.txt" } });
630
+ assert.equal(markResolved.status, 200);
631
+ assert.equal(markResolved.body?.ok, true, "operation stage-file should mark the conflict as resolved");
632
+ assert.equal(markResolved.body?.data?.operation?.canContinue, true, "after staging the only conflict, continue should be possible");
633
+
634
+ const continueMerge = await request("127.0.0.1", "/api/git-operation/continue", { method: "POST", body: { tab: mergeTab }, timeoutMs: 20_000 });
635
+ assert.equal(continueMerge.status, 200);
636
+ assert.equal(continueMerge.body?.ok, true, `continue should commit the resolved merge: ${continueMerge.body?.error || ""}`);
637
+ assert.equal(continueMerge.body?.data?.operation?.operation, null, "after continuing, no operation should remain");
638
+
639
+ const abortRepo = await makeConflictRepo("merge-abort");
640
+ const abortTab = await openFixtureTab(abortRepo, "merge-abort-fixture");
641
+ const abortUnconfirmed = await request("127.0.0.1", "/api/git-operation/abort", { method: "POST", body: { tab: abortTab } });
642
+ assert.equal(abortUnconfirmed.status, 409, "abort without confirmed: true should be refused");
643
+ const abortConfirmed = await request("127.0.0.1", "/api/git-operation/abort", { method: "POST", body: { tab: abortTab, confirmed: true }, timeoutMs: 20_000 });
644
+ assert.equal(abortConfirmed.status, 200);
645
+ assert.equal(abortConfirmed.body?.ok, true, "confirmed abort should stop the merge");
646
+ assert.equal(abortConfirmed.body?.data?.operation?.operation, null, "after aborting, no operation should remain");
647
+ assert.equal(await readFile(path.join(abortRepo, "file.txt"), "utf8"), "main\n", "abort should restore the pre-merge content");
648
+
649
+ // Rebase lifecycle: skip support + abort
650
+ const rebaseRepo = await makeFixtureRepo("rebase-conflict");
651
+ runGitFixture(["checkout", "-b", "side"], rebaseRepo, "rebase fixture should branch");
652
+ await writeFile(path.join(rebaseRepo, "file.txt"), "side\n");
653
+ runGitFixture(["commit", "-am", "side"], rebaseRepo, "rebase fixture should commit side");
654
+ runGitFixture(["checkout", "main"], rebaseRepo, "rebase fixture should return to main");
655
+ await writeFile(path.join(rebaseRepo, "file.txt"), "main\n");
656
+ runGitFixture(["commit", "-am", "main"], rebaseRepo, "rebase fixture should commit main");
657
+ runGitFixture(["checkout", "side"], rebaseRepo, "rebase fixture should return to side");
658
+ const rebaseStart = spawnSync("git", ["rebase", "main"], { cwd: rebaseRepo, encoding: "utf8" });
659
+ assert.notEqual(rebaseStart.status, 0, "rebase fixture should conflict");
660
+ const rebaseTab = await openFixtureTab(rebaseRepo, "rebase-conflict-fixture");
661
+ const rebaseSnapshot = await request("127.0.0.1", `/api/git-operation?tab=${encodeURIComponent(rebaseTab)}`);
662
+ assert.equal(rebaseSnapshot.body?.data?.operation, "rebase");
663
+ assert.equal(rebaseSnapshot.body?.data?.canSkip, true, "rebase should support skip");
664
+ const rebaseAbort = await request("127.0.0.1", "/api/git-operation/abort", { method: "POST", body: { tab: rebaseTab, confirmed: true }, timeoutMs: 20_000 });
665
+ assert.equal(rebaseAbort.body?.ok, true, "confirmed rebase abort should succeed");
666
+
667
+ // Bisect lifecycle
668
+ const bisectRepo = await makeFixtureRepo("bisect");
669
+ runGitFixture(["bisect", "start"], bisectRepo, "bisect fixture should start");
670
+ const bisectTab = await openFixtureTab(bisectRepo, "bisect-fixture");
671
+ const bisectSnapshot = await request("127.0.0.1", `/api/git-operation?tab=${encodeURIComponent(bisectTab)}`);
672
+ assert.equal(bisectSnapshot.body?.data?.operation, "bisect");
673
+ const bisectInvalid = await request("127.0.0.1", "/api/git-operation/bisect", { method: "POST", body: { tab: bisectTab, verdict: "evil" } });
674
+ assert.equal(bisectInvalid.status, 400, "invalid bisect verdicts must be rejected");
675
+ const bisectResetUnconfirmed = await request("127.0.0.1", "/api/git-operation/bisect", { method: "POST", body: { tab: bisectTab, verdict: "reset" } });
676
+ assert.equal(bisectResetUnconfirmed.status, 409, "bisect reset without confirmed: true should be refused");
677
+ const bisectReset = await request("127.0.0.1", "/api/git-operation/bisect", { method: "POST", body: { tab: bisectTab, verdict: "reset", confirmed: true }, timeoutMs: 20_000 });
678
+ assert.equal(bisectReset.body?.ok, true, "confirmed bisect reset should succeed");
679
+ assert.equal(bisectReset.body?.data?.operation?.operation, null, "after reset, no bisect should remain");
680
+
681
+ // Stash lifecycle
682
+ const stashRepo = await makeFixtureRepo("stash");
683
+ const stashTab = await openFixtureTab(stashRepo, "stash-fixture");
684
+ await writeFile(path.join(stashRepo, "file.txt"), "stash me\n");
685
+ await writeFile(path.join(stashRepo, "new-file.txt"), "untracked\n");
686
+ const stashSave = await request("127.0.0.1", "/api/git-stash/save", { method: "POST", body: { tab: stashTab, includeUntracked: true, message: "harness stash" } });
687
+ assert.equal(stashSave.status, 200);
688
+ assert.equal(stashSave.body?.ok, true, `stash save should succeed: ${stashSave.body?.error || ""}`);
689
+ assert.equal(stashSave.body?.data?.stashes?.length, 1, "stash save should leave one stash entry");
690
+
691
+ const stashList = await request("127.0.0.1", `/api/git-stash?tab=${encodeURIComponent(stashTab)}`);
692
+ assert.equal(stashList.body?.ok, true);
693
+ assert.equal(stashList.body?.data?.stashes?.[0]?.ref, "stash@{0}");
694
+ assert.match(stashList.body?.data?.stashes?.[0]?.subject || "", /harness stash/);
695
+
696
+ const stashShow = await request("127.0.0.1", `/api/git-stash/show?ref=${encodeURIComponent("stash@{0}")}&tab=${encodeURIComponent(stashTab)}`);
697
+ assert.equal(stashShow.body?.ok, true, "stash show should return a preview");
698
+ assert.match(stashShow.body?.data?.stat || "", /file\.txt/, "stash preview should mention the stashed file");
699
+
700
+ const stashBadRef = await request("127.0.0.1", `/api/git-stash/show?ref=${encodeURIComponent("stash@{0}; rm -rf /")}&tab=${encodeURIComponent(stashTab)}`);
701
+ assert.equal(stashBadRef.status, 400, "malformed stash refs must be rejected");
702
+
703
+ const stashApply = await request("127.0.0.1", "/api/git-stash/apply", { method: "POST", body: { tab: stashTab, ref: "stash@{0}" } });
704
+ assert.equal(stashApply.body?.ok, true, `stash apply should succeed: ${stashApply.body?.error || ""}`);
705
+ assert.equal(await readFile(path.join(stashRepo, "file.txt"), "utf8"), "stash me\n", "stash apply should restore the stashed content");
706
+
707
+ const stashDropUnconfirmed = await request("127.0.0.1", "/api/git-stash/drop", { method: "POST", body: { tab: stashTab, ref: "stash@{0}" } });
708
+ assert.equal(stashDropUnconfirmed.status, 409, "stash drop without confirmed: true should be refused");
709
+ const stashDrop = await request("127.0.0.1", "/api/git-stash/drop", { method: "POST", body: { tab: stashTab, ref: "stash@{0}", confirmed: true } });
710
+ assert.equal(stashDrop.body?.ok, true, "confirmed stash drop should succeed");
711
+ assert.equal(stashDrop.body?.data?.stashes?.length, 0, "dropping the only stash should empty the list");
712
+
713
+ // Fetch, divergence classification, integrate, push classification
714
+ await writeFile(path.join(remoteWork, "incoming.txt"), "base\nremote one\nremote two\nremote three\n");
715
+ runGitFixture(["commit", "-am", "remote three"], remoteWork, "remote worktree should commit third incoming change");
716
+ runGitFixture(["push", "origin", "main"], remoteWork, "remote worktree should push the third commit");
717
+ await writeFile(path.join(localRepo, "local-only.txt"), "local\n");
718
+ runGitFixture(["add", "local-only.txt"], localRepo, "local repo should stage local divergence");
719
+ runGitFixture(["commit", "-m", "local divergence"], localRepo, "local repo should commit local divergence");
720
+
721
+ const fetchResult = await request("127.0.0.1", "/api/git-fetch", { method: "POST", body: { tab: remoteTabId }, timeoutMs: 30_000 });
722
+ assert.equal(fetchResult.status, 200);
723
+ assert.equal(fetchResult.body?.ok, true, `fetch endpoint should fetch from the bare origin: ${fetchResult.body?.error || ""}`);
724
+ assert.equal(fetchResult.body?.data?.changes?.summary?.behind, 1, "fetch should reveal the remote commit");
725
+ assert.equal(fetchResult.body?.data?.changes?.remote?.diverged, true, "fetch should reveal divergence");
726
+ assert.equal(fetchResult.body?.data?.changes?.remote?.canPull, false, "diverged branches must not offer one-click pull");
727
+
728
+ const divergedPull = await request("127.0.0.1", "/api/git-changes/pull", { method: "POST", body: { tab: remoteTabId }, timeoutMs: 30_000 });
729
+ assert.equal(divergedPull.body?.ok, false, "ff-only pull must fail on diverged branches");
730
+ assert.equal(divergedPull.body?.code, "DIVERGED", "diverged pull failures should be classified");
731
+ assert.ok(divergedPull.body?.hint, "diverged pull failures should carry a hint");
732
+
733
+ const integrateUnconfirmed = await request("127.0.0.1", "/api/git-changes/integrate", { method: "POST", body: { tab: remoteTabId, mode: "merge" } });
734
+ assert.equal(integrateUnconfirmed.status, 409, "integrate without confirmed: true should be refused");
735
+ const integrateMerge = await request("127.0.0.1", "/api/git-changes/integrate", { method: "POST", body: { tab: remoteTabId, mode: "merge", confirmed: true }, timeoutMs: 30_000 });
736
+ assert.equal(integrateMerge.body?.ok, true, `confirmed merge integrate should succeed: ${integrateMerge.body?.error || ""}`);
737
+ assert.equal(integrateMerge.body?.data?.changes?.summary?.behind, 0, "after integrating, nothing should remain behind");
738
+
739
+ const pushDiverged = await request("127.0.0.1", "/api/git-workflow/push", { method: "POST", body: { tab: remoteTabId }, timeoutMs: 30_000 });
740
+ assert.equal(pushDiverged.body?.ok, true, `push should succeed after integration: ${pushDiverged.body?.error || ""}`);
741
+ assert.equal(pushDiverged.body?.data?.branch, "main");
742
+ assert.equal(pushDiverged.body?.data?.protectedBranch, true, "pushing main should be flagged as a protected branch");
743
+
744
+ // Undo guards: pushed commits must not be undoable
745
+ const undoPushedState = await request("127.0.0.1", `/api/git-undo?tab=${encodeURIComponent(remoteTabId)}`);
746
+ assert.equal(undoPushedState.body?.ok, true);
747
+ assert.equal(undoPushedState.body?.data?.canUndoLastCommit, false, "a pushed HEAD must not be undoable");
748
+ const undoPushed = await request("127.0.0.1", "/api/git-undo/last-commit", { method: "POST", body: { tab: remoteTabId, confirmed: true } });
749
+ assert.equal(undoPushed.status, 409, "undoing a pushed commit must be refused");
750
+
751
+ // Undo/amend on an unpushed repo
752
+ const undoRepo = await makeFixtureRepo("undo");
753
+ const undoTab = await openFixtureTab(undoRepo, "undo-fixture");
754
+ await writeFile(path.join(undoRepo, "file.txt"), "second\n");
755
+ runGitFixture(["commit", "-am", "second"], undoRepo, "undo fixture should commit a second change");
756
+
757
+ const undoState = await request("127.0.0.1", `/api/git-undo?tab=${encodeURIComponent(undoTab)}`);
758
+ assert.equal(undoState.body?.ok, true);
759
+ assert.equal(undoState.body?.data?.canUndoLastCommit, true, "an unpushed commit with a parent should be undoable");
760
+ assert.equal(undoState.body?.data?.lastCommit?.subject, "second");
761
+
762
+ const undoUnconfirmed = await request("127.0.0.1", "/api/git-undo/last-commit", { method: "POST", body: { tab: undoTab } });
763
+ assert.equal(undoUnconfirmed.status, 409, "undo without confirmed: true should be refused");
764
+ const undoConfirmed = await request("127.0.0.1", "/api/git-undo/last-commit", { method: "POST", body: { tab: undoTab, confirmed: true } });
765
+ assert.equal(undoConfirmed.body?.ok, true, `confirmed undo should soft-reset: ${undoConfirmed.body?.error || ""}`);
766
+ assert.equal(undoConfirmed.body?.data?.restoreCommand, "git reset --soft ORIG_HEAD");
767
+ assert.equal(undoConfirmed.body?.data?.changes?.summary?.staged, 1, "soft reset should keep the change staged");
768
+ assert.equal(runGitFixture(["log", "-1", "--format=%s"], undoRepo, "undo fixture should read HEAD subject"), "base", "undo should move HEAD back to the base commit");
769
+
770
+ const undoNoParent = await request("127.0.0.1", "/api/git-undo/last-commit", { method: "POST", body: { tab: undoTab, confirmed: true } });
771
+ assert.equal(undoNoParent.status, 409, "undoing the root commit must be refused");
772
+
773
+ const amendWithStaged = await request("127.0.0.1", "/api/git-undo/amend-message", { method: "POST", body: { tab: undoTab, confirmed: true, message: "nope" } });
774
+ assert.equal(amendWithStaged.status, 409, "amending with staged changes must be refused");
775
+ runGitFixture(["commit", "-m", "second again"], undoRepo, "undo fixture should re-commit the staged change");
776
+ const amendUnconfirmed = await request("127.0.0.1", "/api/git-undo/amend-message", { method: "POST", body: { tab: undoTab, message: "amended subject" } });
777
+ assert.equal(amendUnconfirmed.status, 409, "amend without confirmed: true should be refused");
778
+ const amendConfirmed = await request("127.0.0.1", "/api/git-undo/amend-message", { method: "POST", body: { tab: undoTab, confirmed: true, message: "amended subject" } });
779
+ assert.equal(amendConfirmed.body?.ok, true, `confirmed amend should rewrite the message: ${amendConfirmed.body?.error || ""}`);
780
+ assert.equal(runGitFixture(["log", "-1", "--format=%s"], undoRepo, "undo fixture should read amended subject"), "amended subject");
781
+
782
+ const reflog = await request("127.0.0.1", `/api/git-reflog?tab=${encodeURIComponent(undoTab)}`);
783
+ assert.equal(reflog.body?.ok, true, "reflog endpoint should return entries");
784
+ assert.ok((reflog.body?.data?.entries || []).length >= 3, "reflog should include the undo/amend history");
785
+ assert.match(reflog.body?.data?.entries?.[0]?.selector || "", /^HEAD@\{0\}$/);
786
+
787
+ // Tags
788
+ const tagInvalid = await request("127.0.0.1", "/api/git-tags/create", { method: "POST", body: { tab: undoTab, confirmed: true, name: "bad tag" } });
789
+ assert.equal(tagInvalid.status, 400, "invalid tag names must be rejected");
790
+ 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" } });
791
+ assert.equal(tagUnconfirmed.status, 409, "tag creation without confirmed: true should be refused");
792
+ 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" } });
793
+ assert.equal(tagCreate.body?.ok, true, `confirmed tag creation should succeed: ${tagCreate.body?.error || ""}`);
794
+ const tagList = await request("127.0.0.1", `/api/git-tags?tab=${encodeURIComponent(undoTab)}`);
795
+ assert.equal(tagList.body?.ok, true);
796
+ const createdTag = (tagList.body?.data?.tags || []).find((tag) => tag.name === "v0.0.1-harness");
797
+ assert.ok(createdTag, "created tag should appear in the tag list");
798
+ assert.equal(createdTag.annotated, true, "created tag should be annotated");
799
+ assert.equal(createdTag.atHead, true, "created tag should point at HEAD");
800
+
801
+ // Signing diagnostics + submodule status (read-only)
802
+ const signing = await request("127.0.0.1", `/api/git-signing?tab=${encodeURIComponent(undoTab)}`);
803
+ assert.equal(signing.body?.ok, true, "signing diagnostics should load");
804
+ assert.equal(signing.body?.data?.mismatch, false, "fixture repo should not report a signing mismatch");
805
+ const submodules = await request("127.0.0.1", `/api/git-submodules?tab=${encodeURIComponent(undoTab)}`);
806
+ assert.equal(submodules.body?.ok, true, "submodule status should load");
807
+ assert.equal(submodules.body?.data?.hasSubmodules, false, "fixture repo has no submodules");
808
+
809
+ // Worktree prune (dry run + confirmed)
810
+ const pruneDryRun = await request("127.0.0.1", `/api/git-worktrees/prune?tab=${encodeURIComponent(undoTab)}`);
811
+ assert.equal(pruneDryRun.body?.ok, true, "prune dry run should load");
812
+ assert.equal(pruneDryRun.body?.data?.dryRun, true);
813
+ const pruneUnconfirmed = await request("127.0.0.1", "/api/git-worktrees/prune", { method: "POST", body: { tab: undoTab } });
814
+ assert.equal(pruneUnconfirmed.status, 409, "prune without confirmed: true should be refused");
815
+ const pruneConfirmed = await request("127.0.0.1", "/api/git-worktrees/prune", { method: "POST", body: { tab: undoTab, confirmed: true }, timeoutMs: 20_000 });
816
+ assert.equal(pruneConfirmed.body?.ok, true, `confirmed prune should succeed: ${pruneConfirmed.body?.error || ""}`);
817
+
818
+ 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 });
819
+ assert.equal(closeGitActionTabs.status, 200, "git action fixture tabs should close");
820
+ await rmWithRetry(gitFixturesRoot);
503
821
  } else {
504
822
  console.log("http-endpoints-harness: git not available; skipping git init workflow endpoint checks");
505
823
  }
@@ -756,6 +1074,12 @@ try {
756
1074
  const binaryRelative = "files-fixture/binary.bin";
757
1075
  const noDefaultRelative = "files-fixture/no-default.piunknown";
758
1076
  const largeRelative = "files-fixture/large.txt";
1077
+ const movableFileRelative = "files-fixture/move-me.txt";
1078
+ const movedFileRelative = "files-fixture/docs/moved-file.txt";
1079
+ const movableDirectoryRelative = "files-fixture/move-dir";
1080
+ const movedDirectoryRelative = "files-fixture/docs/move-dir";
1081
+ const deleteFileRelative = "files-fixture/delete-me.txt";
1082
+ const deleteDirectoryRelative = "files-fixture/delete-dir";
759
1083
  const depthEightFileRelative = "deep-search/f1/f2/f3/f4/f5/f6/depth-eight-file.txt";
760
1084
  const depthEightDirectoryRelative = "deep-search/d1/d2/d3/d4/d5/d6/depth-eight-dir";
761
1085
  const depthNineFileRelative = "deep-search/t1/t2/t3/t4/t5/t6/t7/too-deep-file.txt";
@@ -770,6 +1094,12 @@ try {
770
1094
  await writeFile(path.join(cwd, depthNineFileRelative), "depth 9 search fixture\n", "utf8");
771
1095
  await writeFile(path.join(cwd, binaryRelative), Buffer.from([0, 1, 2, 3]));
772
1096
  await writeFile(path.join(cwd, largeRelative), Buffer.alloc(2 * 1024 * 1024 + 1, 0x61));
1097
+ await writeFile(path.join(cwd, movableFileRelative), "move me\n", "utf8");
1098
+ await mkdir(path.join(cwd, movableDirectoryRelative), { recursive: true });
1099
+ await writeFile(path.join(cwd, movableDirectoryRelative, "nested.txt"), "nested move\n", "utf8");
1100
+ await writeFile(path.join(cwd, deleteFileRelative), "delete me\n", "utf8");
1101
+ await mkdir(path.join(cwd, deleteDirectoryRelative), { recursive: true });
1102
+ await writeFile(path.join(cwd, deleteDirectoryRelative, "nested.txt"), "nested delete\n", "utf8");
773
1103
 
774
1104
  const fileTree = await request("127.0.0.1", `/api/files?tab=${encodeURIComponent(tabId)}&path=${encodeURIComponent("files-fixture")}`);
775
1105
  assert.equal(fileTree.status, 200, `file tree endpoint should list workspace directories: ${fileTree.body?.error || ""}`);
@@ -846,6 +1176,40 @@ try {
846
1176
  assert.equal(savedFile.status, 200, `file save should succeed from localhost: ${savedFile.body?.error || ""}`);
847
1177
  assert.equal(await readFile(path.join(cwd, viewerRelative), "utf8"), "updated from WebUI\n", "file save endpoint should write UTF-8 text content");
848
1178
 
1179
+ const moveUnconfirmed = await request("127.0.0.1", "/api/files/move", { method: "POST", body: { tab: tabId, path: movableFileRelative, toPath: movedFileRelative } });
1180
+ assert.equal(moveUnconfirmed.status, 409, "file moves require explicit confirmation");
1181
+
1182
+ const moveFile = await request("127.0.0.1", "/api/files/move", { method: "POST", body: { tab: tabId, path: movableFileRelative, toPath: movedFileRelative, confirmed: true } });
1183
+ assert.equal(moveFile.status, 200, `file move should succeed from localhost: ${moveFile.body?.error || ""}`);
1184
+ assert.equal(moveFile.body?.data?.destination, movedFileRelative, "move endpoint should report the new relative file path");
1185
+ assert.equal(await readFile(path.join(cwd, movedFileRelative), "utf8"), "move me\n", "move endpoint should relocate file contents");
1186
+ assert.equal(await pathExists(path.join(cwd, movableFileRelative)), false, "move endpoint should remove the original file path");
1187
+
1188
+ const moveDirectory = await request("127.0.0.1", "/api/files/move", { method: "POST", body: { tab: tabId, path: movableDirectoryRelative, toPath: "files-fixture/docs", confirmed: true } });
1189
+ assert.equal(moveDirectory.status, 200, `directory move should succeed from localhost: ${moveDirectory.body?.error || ""}`);
1190
+ assert.equal(moveDirectory.body?.data?.destination, movedDirectoryRelative, "moving to an existing directory should place the source under that directory");
1191
+ assert.equal(await readFile(path.join(cwd, movedDirectoryRelative, "nested.txt"), "utf8"), "nested move\n", "move endpoint should relocate directory contents");
1192
+ assert.equal(await pathExists(path.join(cwd, movableDirectoryRelative)), false, "directory move endpoint should remove the original directory path");
1193
+
1194
+ const moveExistingDestination = await request("127.0.0.1", "/api/files/move", { method: "POST", body: { tab: tabId, path: movedFileRelative, toPath: markdownRelative, confirmed: true } });
1195
+ assert.equal(moveExistingDestination.status, 409, "move endpoint should refuse to overwrite an existing destination");
1196
+
1197
+ const deleteUnconfirmed = await request("127.0.0.1", "/api/files", { method: "DELETE", body: { tab: tabId, path: deleteFileRelative } });
1198
+ assert.equal(deleteUnconfirmed.status, 409, "file deletes require explicit confirmation");
1199
+
1200
+ const deleteFile = await request("127.0.0.1", "/api/files", { method: "DELETE", body: { tab: tabId, path: deleteFileRelative, confirmed: true } });
1201
+ assert.equal(deleteFile.status, 200, `file delete should succeed from localhost: ${deleteFile.body?.error || ""}`);
1202
+ assert.equal(deleteFile.body?.data?.deleted, true, "delete endpoint should report successful file deletion");
1203
+ assert.equal(await pathExists(path.join(cwd, deleteFileRelative)), false, "delete endpoint should remove regular files");
1204
+
1205
+ const deleteDirectory = await request("127.0.0.1", "/api/files", { method: "DELETE", body: { tab: tabId, path: deleteDirectoryRelative, confirmed: true } });
1206
+ assert.equal(deleteDirectory.status, 200, `directory delete should succeed from localhost: ${deleteDirectory.body?.error || ""}`);
1207
+ assert.equal(deleteDirectory.body?.data?.type, "directory", "delete endpoint should report directory deletions");
1208
+ assert.equal(await pathExists(path.join(cwd, deleteDirectoryRelative)), false, "delete endpoint should remove directories recursively");
1209
+
1210
+ const deleteWorkspaceRoot = await request("127.0.0.1", "/api/files", { method: "DELETE", body: { tab: tabId, path: "", confirmed: true } });
1211
+ assert.equal(deleteWorkspaceRoot.status, 400, "delete endpoint must refuse deleting the active workspace root");
1212
+
849
1213
  const binaryContent = await request("127.0.0.1", `/api/files/content?tab=${encodeURIComponent(tabId)}&path=${encodeURIComponent(binaryRelative)}`);
850
1214
  assert.equal(binaryContent.status, 415, "binary files should be rejected by the WebUI file viewer");
851
1215
  assert.match(String(binaryContent.body?.error || ""), /binary/i);
@@ -862,6 +1226,12 @@ try {
862
1226
  assert.equal(outsideAbsolute.status, 403, "absolute paths outside the active tab cwd should be rejected");
863
1227
  assert.match(String(outsideAbsolute.body?.error || ""), /active tab working directory/i);
864
1228
 
1229
+ const outsideDelete = await request("127.0.0.1", "/api/files", { method: "DELETE", body: { tab: tabId, path: outsideFile, confirmed: true } });
1230
+ assert.equal(outsideDelete.status, 403, "delete endpoint should reject absolute paths outside the active tab cwd");
1231
+
1232
+ const outsideMoveDestination = await request("127.0.0.1", "/api/files/move", { method: "POST", body: { tab: tabId, path: movedFileRelative, toPath: outsideFile, confirmed: true } });
1233
+ assert.equal(outsideMoveDestination.status, 403, "move endpoint should reject destinations outside the active tab cwd");
1234
+
865
1235
  const symlinkPath = path.join(filesRoot, "outside-link.txt");
866
1236
  try {
867
1237
  await symlink(outsideFile, symlinkPath);
@@ -935,6 +1305,14 @@ try {
935
1305
  assert.equal(blockedFileSave.status, 409, "file edits should be blocked while Natural Conversation is active");
936
1306
  assert.equal(blockedFileSave.body?.error, "file edits are blocked");
937
1307
 
1308
+ const blockedFileDelete = await request("127.0.0.1", "/api/files", { method: "DELETE", body: { tab: tabId, path: viewerRelative, confirmed: true } });
1309
+ assert.equal(blockedFileDelete.status, 409, "file deletes should be blocked while Natural Conversation is active");
1310
+ assert.match(String(blockedFileDelete.body?.error || ""), /file deletion is blocked/i);
1311
+
1312
+ 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 } });
1313
+ assert.equal(blockedFileMove.status, 409, "file moves should be blocked while Natural Conversation is active");
1314
+ assert.match(String(blockedFileMove.body?.error || ""), /file moves are blocked/i);
1315
+
938
1316
  const allowedConversationPrompt = await request("127.0.0.1", "/api/prompt", { method: "POST", body: { message: "Explain the current repo briefly", tab: tabId } });
939
1317
  assert.equal(allowedConversationPrompt.status, 200, "ordinary prompts remain allowed while Natural Conversation is active");
940
1318
 
@@ -1025,6 +1403,18 @@ try {
1025
1403
  });
1026
1404
  assert.equal(remoteFileOpenDefault.status, 403, "opening files in the default editor must be localhost-only");
1027
1405
 
1406
+ const remoteFileDelete = await request(lan, "/api/files", {
1407
+ method: "DELETE",
1408
+ body: { tab: tabId, path: viewerRelative, confirmed: true },
1409
+ });
1410
+ assert.equal(remoteFileDelete.status, 403, "file deletes must be localhost-only");
1411
+
1412
+ const remoteFileMove = await request(lan, "/api/files/move", {
1413
+ method: "POST",
1414
+ body: { tab: tabId, path: viewerRelative, toPath: "files-fixture/remote-move.txt", confirmed: true },
1415
+ });
1416
+ assert.equal(remoteFileMove.status, 403, "file moves must be localhost-only");
1417
+
1028
1418
  const remoteExport = await request(lan, "/api/prompt", {
1029
1419
  method: "POST",
1030
1420
  body: { message: "/export", tab: tabId },
@@ -261,6 +261,7 @@ assert.match(css, /\.message\.toolResult \.message-collapse\[open\] > \.message-
261
261
  assert.match(css, /\.tool-output-details\[open\] > \.tool-output-code \{[\s\S]*?max-height:\s*min\(34rem, 52dvh\);[\s\S]*?overflow:\s*auto/, "expanded live tool output should get an internal scrollbar");
262
262
  assert.match(css, /\.run-indicator-pulse \{[\s\S]*?animation:\s*run-indicator-pulse/, "active agent run indicator should have an animated pulse");
263
263
  assert.match(css, /\.optional-features-box \{[\s\S]*?display:\s*grid/, "optional features should render as a side-panel feature list");
264
+ assert.match(css, /\.optional-feature-section \{[\s\S]*?display:\s*grid[\s\S]*?\.optional-feature-section-list \{[\s\S]*?display:\s*grid/, "optional features should render grouped type subsections");
264
265
  assert.match(css, /\.btw-widget \{[\s\S]*?\.btw-widget-composer \{[\s\S]*?\.btw-transfer-action \{[\s\S]*?\.btw-live-widget \.release-npm-output-details\[open\] \.release-npm-terminal \{[\s\S]*?height:\s*clamp/, "/btw should render as a non-blocking release-style output widget with its own input and transfer action");
265
266
  assert.match(css, /\.prompt-list-controls \{[\s\S]*?display:\s*grid/, "Queue prompt-list controls should render as a side-panel control group");
266
267
  assert.match(css, /\.prompt-list-dialog \{[\s\S]*?width:\s*min\(58rem/, "prompt-list editor dialog should have a wider prompt-friendly layout");
@@ -595,6 +596,8 @@ assert.match(app, /const node = make\("details", "widget todo-widget"\)/, "todo-
595
596
  assert.match(app, /Optional feature detection intentionally checks loaded Pi capabilities/, "optional Web UI features should be detected through loaded capabilities, not package folders");
596
597
  assert.match(app, /function resetOptionalFeatureAvailability\(\)/, "optional feature state should reset across active-tab and reload boundaries");
597
598
  assert.match(app, /function renderOptionalFeaturePanel\(\)/, "side panel should render optional feature installed/enabled state");
599
+ assert.match(app, /const OPTIONAL_FEATURE_SECTIONS = \[[\s\S]*label: "Composer & commands"[\s\S]*label: "Workflows & releases"[\s\S]*label: "Safety & access"[\s\S]*label: "UI widgets & native parity"[\s\S]*label: "Conversation"/, "optional features should be grouped into five type subsections");
600
+ assert.match(app, /function renderOptionalFeatureSection\(section, features\)[\s\S]*optional-feature-section[\s\S]*optional-feature-section-title[\s\S]*optional-feature-section-list/, "optional feature panel should render subsection headers and lists");
598
601
  assert.match(app, /function setSidePanelSectionCollapsed\(record, collapsed/, "side panel sections should have explicit collapse/expand behavior");
599
602
  assert.match(
600
603
  app,