Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

GitActionsControl.logic.test.ts

1,263 lines34.0 KB

1import { SourceControlProviderKind } from "@t3tools/contracts";
2import type { VcsStatusResult } from "@t3tools/contracts";
3import { assert, describe, it } from "vite-plus/test";
4import {
5 buildGitActionProgressStages,
6 buildMenuItems,
7 formatGitActionElapsed,
8 requiresDefaultBranchConfirmation,
9 resolveAutoFeatureBranchName,
10 resolveDefaultBranchActionDialogCopy,
11 resolveFeatureBranchUnavailableReason,
12 resolveGitActionProgressPresentation,
13 resolveGitActionResultToastTiming,
14 resolveLiveThreadBranchUpdate,
15 resolveQuickAction,
16 resolveThreadBranchUpdate,
17 resolveThreadBranchMetadataPatch,
18} from "./GitActionsControl.logic";
19​
20function status(overrides: Partial<VcsStatusResult> = {}): VcsStatusResult {
21 return {
22 isRepo: true,
23 hasPrimaryRemote: true,
24 isDefaultRef: false,
25 refName: "feature/test",
26 hasWorkingTreeChanges: false,
27 workingTree: {
28 files: [],
29 insertions: 0,
30 deletions: 0,
31 },
32 hasUpstream: true,
33 aheadCount: 0,
34 behindCount: 0,
35 pr: null,
36 ...overrides,
37 };
39​
40describe("git action progress presentation", () => {
41 it("keeps the phase on the first row and hook output on the second", () => {
42 assert.deepEqual(
43 resolveGitActionProgressPresentation({
44 isRunning: true,
45 operation: "run_change_request",
46 currentLabel: "Running pre-commit...",
47 lastOutputLine: "Checking formatting and lint rules",
48 phaseStartedAtMs: 1_000,
49 hookStartedAtMs: 2_000,
50 }),
51 {
52 status: "Running pre-commit...",
53 output: "Checking formatting and lint rules",
54 startedAtMs: 2_000,
55 },
56 );
57 });
58​
59 it("omits empty output and supplies a brief startup label", () => {
60 assert.deepEqual(
61 resolveGitActionProgressPresentation({
62 isRunning: true,
63 operation: "run_change_request",
64 currentLabel: "Running source control action",
65 lastOutputLine: " ",
66 phaseStartedAtMs: 1_000,
67 hookStartedAtMs: null,
68 }),
69 {
70 status: "Starting source control action...",
71 output: null,
72 startedAtMs: 1_000,
73 },
74 );
75 });
76​
77 it("presents pull progress inline without a second row", () => {
78 assert.deepEqual(
79 resolveGitActionProgressPresentation({
80 isRunning: true,
81 operation: "pull",
82 currentLabel: "Pulling latest changes...",
83 lastOutputLine: null,
84 phaseStartedAtMs: 1_000,
85 hookStartedAtMs: null,
86 }),
87 {
88 status: "Pulling latest changes...",
89 output: null,
90 startedAtMs: 1_000,
91 },
92 );
93 });
94​
95 it("does not present unrelated or completed actions", () => {
96 const input = {
97 isRunning: true,
98 operation: "publish_repository",
99 currentLabel: "Publishing repository",
100 lastOutputLine: null,
101 phaseStartedAtMs: 1_000,
102 hookStartedAtMs: null,
103 };
104​
105 assert.isNull(resolveGitActionProgressPresentation(input));
106 assert.isNull(resolveGitActionProgressPresentation({ ...input, isRunning: false }));
107 });
108​
109 it("formats compact elapsed time without allowing negative values", () => {
110 assert.isNull(formatGitActionElapsed(null, 10_000));
111 assert.equal(formatGitActionElapsed(10_000, 9_000), "0s");
112 assert.equal(formatGitActionElapsed(10_000, 14_900), "4s");
113 assert.equal(formatGitActionElapsed(10_000, 75_000), "1m 5s");
114 });
115});
116​
117describe("git action result toast timing", () => {
118 it("keeps errors sticky and dismisses successes after visible time", () => {
119 assert.deepEqual(resolveGitActionResultToastTiming("error"), {
120 timeout: 0,
121 dismissAfterVisibleMs: null,
122 });
123 assert.deepEqual(resolveGitActionResultToastTiming("success"), {
124 timeout: 0,
125 dismissAfterVisibleMs: 10_000,
126 });
127 });
128});
129​
130describe("when: ref is clean and has an open PR", () => {
131 it("resolveQuickAction rests in the disabled up-to-date state", () => {
132 const quick = resolveQuickAction(
133 status({
134 pr: {
135 number: 10,
136 title: "Open PR",
137 url: "https://example.com/pr/10",
138 baseRef: "main",
139 headRef: "feature/test",
140 state: "open",
141 },
142 }),
143 false,
144 );
145 assert.deepInclude(quick, {
146 kind: "show_hint",
147 label: "Commit",
148 disabled: true,
149 hint: "Branch is up to date. No action needed.",
150 });
151 });
152​
153 it("buildMenuItems disables commit/push and omits the PR entry", () => {
154 const items = buildMenuItems(
155 status({
156 pr: {
157 number: 11,
158 title: "Existing PR",
159 url: "https://example.com/pr/11",
160 baseRef: "main",
161 headRef: "feature/test",
162 state: "open",
163 },
164 }),
165 false,
166 );
167 assert.deepEqual(items, [
168 {
169 id: "commit",
170 label: "Commit",
171 disabled: true,
172 icon: "commit",
173 kind: "open_dialog",
174 dialogAction: "commit",
175 },
176 {
177 id: "push",
178 label: "Push",
179 disabled: true,
180 icon: "push",
181 kind: "open_dialog",
182 dialogAction: "push",
183 },
184 ]);
185 });
186});
187​
188describe("when: actions are busy", () => {
189 it("resolveQuickAction returns running disabled state", () => {
190 const quick = resolveQuickAction(status(), true);
191 assert.deepInclude(quick, {
192 kind: "show_hint",
193 label: "Commit",
194 disabled: true,
195 hint: "Git action in progress.",
196 });
197 });
198​
199 it("buildMenuItems disables all actions", () => {
200 const items = buildMenuItems(status(), true);
201 assert.deepEqual(items, [
202 {
203 id: "commit",
204 label: "Commit",
205 disabled: true,
206 icon: "commit",
207 kind: "open_dialog",
208 dialogAction: "commit",
209 },
210 {
211 id: "push",
212 label: "Push",
213 disabled: true,
214 icon: "push",
215 kind: "open_dialog",
216 dialogAction: "push",
217 },
218 {
219 id: "pr",
220 label: "Create PR",
221 disabled: true,
222 icon: "pr",
223 kind: "open_dialog",
224 dialogAction: "create_pr",
225 },
226 ]);
227 });
228});
229​
230describe("when: git status is unavailable", () => {
231 it("resolveQuickAction returns unavailable disabled state", () => {
232 const quick = resolveQuickAction(null, false);
233 assert.deepInclude(quick, {
234 kind: "show_hint",
235 label: "Commit",
236 disabled: true,
237 hint: "Git status is unavailable.",
238 });
239 });
240​
241 it("buildMenuItems returns no menu items", () => {
242 const items = buildMenuItems(null, false);
243 assert.deepEqual(items, []);
244 });
245});
246​
247describe("when: ref is clean, ahead, and has an open PR", () => {
248 it("resolveQuickAction prefers push", () => {
249 const quick = resolveQuickAction(
250 status({
251 aheadCount: 3,
252 pr: {
253 number: 13,
254 title: "Open PR",
255 url: "https://example.com/pr/13",
256 baseRef: "main",
257 headRef: "feature/test",
258 state: "open",
259 },
260 }),
261 false,
262 );
263 assert.deepInclude(quick, { kind: "run_action", action: "push", label: "Push" });
264 });
265​
266 it("buildMenuItems enables push and omits the PR entry", () => {
267 const items = buildMenuItems(
268 status({
269 aheadCount: 2,
270 pr: {
271 number: 12,
272 title: "Existing PR",
273 url: "https://example.com/pr/12",
274 baseRef: "main",
275 headRef: "feature/test",
276 state: "open",
277 },
278 }),
279 false,
280 );
281 assert.deepEqual(items, [
282 {
283 id: "commit",
284 label: "Commit",
285 disabled: true,
286 icon: "commit",
287 kind: "open_dialog",
288 dialogAction: "commit",
289 },
290 {
291 id: "push",
292 label: "Push",
293 disabled: false,
294 icon: "push",
295 kind: "open_dialog",
296 dialogAction: "push",
297 },
298 ]);
299 });
300});
301​
302describe("when: ref is clean, ahead, and has no open PR", () => {
303 it("resolveQuickAction pushes and creates a PR", () => {
304 const quick = resolveQuickAction(status({ aheadCount: 2, pr: null }), false);
305 assert.deepInclude(quick, {
306 kind: "run_action",
307 action: "create_pr",
308 label: "Push & create PR",
309 });
310 });
311​
312 it("buildMenuItems enables push and create PR, with commit disabled", () => {
313 const items = buildMenuItems(status({ aheadCount: 2, pr: null }), false);
314 assert.deepEqual(items, [
315 {
316 id: "commit",
317 label: "Commit",
318 disabled: true,
319 icon: "commit",
320 kind: "open_dialog",
321 dialogAction: "commit",
322 },
323 {
324 id: "push",
325 label: "Push",
326 disabled: false,
327 icon: "push",
328 kind: "open_dialog",
329 dialogAction: "push",
330 },
331 {
332 id: "pr",
333 label: "Create PR",
334 disabled: false,
335 icon: "pr",
336 kind: "open_dialog",
337 dialogAction: "create_pr",
338 },
339 ]);
340 });
341});
342​
343describe("when: source control provider uses merge requests", () => {
344 it("uses GitLab MR terminology in quick actions and menu items", () => {
345 const gitlabStatus = status({
346 aheadCount: 2,
347 sourceControlProvider: {
348 kind: SourceControlProviderKind.make("gitlab"),
349 name: "GitLab",
350 baseUrl: "https://gitlab.com",
351 },
352 });
353​
354 const quick = resolveQuickAction(gitlabStatus, false);
355 const items = buildMenuItems(gitlabStatus, false);
356​
357 assert.deepInclude(quick, {
358 kind: "run_action",
359 action: "create_pr",
360 label: "Push & create MR",
361 });
362 assert.deepInclude(items[2], {
363 id: "pr",
364 label: "Create MR",
365 });
366 });
367});
368​
369describe("when: ref is clean, up to date, and has no open PR", () => {
370 it("enables create PR when synced with upstream but ahead of default, even with local changes", () => {
371 const syncedFeature = status({
372 aheadCount: 0,
373 behindCount: 0,
374 aheadOfDefaultCount: 1,
375 pr: null,
376 });
377​
378 const quick = resolveQuickAction(syncedFeature, false);
379 assert.deepInclude(quick, {
380 label: "Create PR",
381 disabled: false,
382 kind: "run_action",
383 action: "create_pr",
384 });
385​
386 const items = buildMenuItems(syncedFeature, false);
387 assert.equal(items.find((item) => item.id === "pr")?.disabled, false);
388​
389 const dirtyFeature = { ...syncedFeature, hasWorkingTreeChanges: true };
390 assert.equal(
391 buildMenuItems(dirtyFeature, false).find((item) => item.id === "pr")?.disabled,
392 false,
393 );
394 });
395​
396 it("resolveQuickAction returns disabled no-action state", () => {
397 const quick = resolveQuickAction(
398 status({ aheadCount: 0, behindCount: 0, hasWorkingTreeChanges: false, pr: null }),
399 false,
400 );
401 assert.deepInclude(quick, { kind: "show_hint", label: "Commit", disabled: true });
402 });
403​
404 it("buildMenuItems disables commit, push, and create PR", () => {
405 const items = buildMenuItems(status({ aheadCount: 0, behindCount: 0, pr: null }), false);
406 assert.deepEqual(items, [
407 {
408 id: "commit",
409 label: "Commit",
410 disabled: true,
411 icon: "commit",
412 kind: "open_dialog",
413 dialogAction: "commit",
414 },
415 {
416 id: "push",
417 label: "Push",
418 disabled: true,
419 icon: "push",
420 kind: "open_dialog",
421 dialogAction: "push",
422 },
423 {
424 id: "pr",
425 label: "Create PR",
426 disabled: true,
427 icon: "pr",
428 kind: "open_dialog",
429 dialogAction: "create_pr",
430 },
431 ]);
432 });
433});
434​
435describe("when: ref is behind upstream", () => {
436 it("resolveQuickAction returns pull", () => {
437 const quick = resolveQuickAction(status({ behindCount: 2 }), false);
438 assert.deepInclude(quick, { kind: "run_pull", label: "Pull", disabled: false });
439 });
440​
441 it("buildMenuItems disables push and create PR", () => {
442 const items = buildMenuItems(status({ behindCount: 1, pr: null }), false);
443 assert.deepEqual(items, [
444 {
445 id: "commit",
446 label: "Commit",
447 disabled: true,
448 icon: "commit",
449 kind: "open_dialog",
450 dialogAction: "commit",
451 },
452 {
453 id: "push",
454 label: "Push",
455 disabled: true,
456 icon: "push",
457 kind: "open_dialog",
458 dialogAction: "push",
459 },
460 {
461 id: "pr",
462 label: "Create PR",
463 disabled: true,
464 icon: "pr",
465 kind: "open_dialog",
466 dialogAction: "create_pr",
467 },
468 ]);
469 });
470});
471​
472describe("when: ref has diverged from upstream", () => {
473 it("resolveQuickAction returns a disabled sync hint", () => {
474 const quick = resolveQuickAction(status({ aheadCount: 2, behindCount: 1 }), false);
475 assert.deepEqual(quick, {
476 label: "Sync ref",
477 disabled: true,
478 kind: "show_hint",
479 hint: "Branch has diverged from upstream. Rebase/merge first.",
480 });
481 });
482});
483​
484describe("when: working tree has local changes", () => {
485 it("resolveQuickAction returns commit, push, and create PR", () => {
486 const quick = resolveQuickAction(status({ hasWorkingTreeChanges: true }), false);
487 assert.deepInclude(quick, {
488 kind: "run_action",
489 action: "commit_push_pr",
490 label: "Commit, push & PR",
491 });
492 });
493​
494 it("resolveQuickAction falls back to commit when no origin remote exists", () => {
495 const quick = resolveQuickAction(
496 status({ hasWorkingTreeChanges: true, hasUpstream: false }),
497 false,
498 false,
499 false,
500 );
501 assert.deepInclude(quick, {
502 kind: "run_action",
503 action: "commit",
504 label: "Commit",
505 disabled: false,
506 });
507 });
508​
509 it("resolveQuickAction returns commit and push when open PR exists", () => {
510 const quick = resolveQuickAction(
511 status({
512 hasWorkingTreeChanges: true,
513 pr: {
514 number: 16,
515 title: "Existing PR",
516 url: "https://example.com/pr/16",
517 baseRef: "main",
518 headRef: "feature/test",
519 state: "open",
520 },
521 }),
522 false,
523 );
524 assert.deepInclude(quick, {
525 kind: "run_action",
526 action: "commit_push",
527 label: "Commit & push",
528 });
529 });
530​
531 it("buildMenuItems enables commit and disables push and PR", () => {
532 const items = buildMenuItems(status({ hasWorkingTreeChanges: true }), false);
533 assert.deepEqual(items, [
534 {
535 id: "commit",
536 label: "Commit",
537 disabled: false,
538 icon: "commit",
539 kind: "open_dialog",
540 dialogAction: "commit",
541 },
542 {
543 id: "push",
544 label: "Push",
545 disabled: true,
546 icon: "push",
547 kind: "open_dialog",
548 dialogAction: "push",
549 },
550 {
551 id: "pr",
552 label: "Create PR",
553 disabled: true,
554 icon: "pr",
555 kind: "open_dialog",
556 dialogAction: "create_pr",
557 },
558 ]);
559 });
560​
561 it("buildMenuItems enables push and create PR for ahead commits while local changes remain uncommitted", () => {
562 const items = buildMenuItems(
563 status({
564 refName: "feature/test",
565 hasWorkingTreeChanges: true,
566 aheadCount: 1,
567 workingTree: {
568 files: [{ path: ".vercel/project.json", insertions: 1, deletions: 0 }],
569 insertions: 1,
570 deletions: 0,
571 },
572 }),
573 false,
574 );
575 assert.deepEqual(items, [
576 {
577 id: "commit",
578 label: "Commit",
579 disabled: false,
580 icon: "commit",
581 kind: "open_dialog",
582 dialogAction: "commit",
583 },
584 {
585 id: "push",
586 label: "Push",
587 disabled: false,
588 icon: "push",
589 kind: "open_dialog",
590 dialogAction: "push",
591 },
592 {
593 id: "pr",
594 label: "Create PR",
595 disabled: false,
596 icon: "pr",
597 kind: "open_dialog",
598 dialogAction: "create_pr",
599 },
600 ]);
601 });
602});
603​
604describe("when: on default ref without open PR", () => {
605 it("resolveQuickAction returns commit and push when local changes exist", () => {
606 const quick = resolveQuickAction(
607 status({ refName: "main", hasWorkingTreeChanges: true }),
608 false,
609 true,
610 );
611 assert.deepInclude(quick, {
612 kind: "run_action",
613 action: "commit_push",
614 label: "Commit & push",
615 disabled: false,
616 });
617 });
618​
619 it("resolveQuickAction returns push when ref is ahead", () => {
620 const quick = resolveQuickAction(
621 status({ refName: "main", aheadCount: 2, pr: null }),
622 false,
623 true,
624 );
625 assert.deepInclude(quick, {
626 kind: "run_action",
627 action: "commit_push",
628 label: "Push",
629 disabled: false,
630 });
631 });
632});
633​
634describe("when: working tree has local changes and ref is behind upstream", () => {
635 it("resolveQuickAction still prefers commit, push, and create PR", () => {
636 const quick = resolveQuickAction(
637 status({ hasWorkingTreeChanges: true, behindCount: 1 }),
638 false,
639 );
640 assert.deepInclude(quick, {
641 kind: "run_action",
642 action: "commit_push_pr",
643 label: "Commit, push & PR",
644 });
645 });
646​
647 it("buildMenuItems enables commit and keeps push and PR disabled", () => {
648 const items = buildMenuItems(status({ hasWorkingTreeChanges: true, behindCount: 2 }), false);
649 assert.deepEqual(items, [
650 {
651 id: "commit",
652 label: "Commit",
653 disabled: false,
654 icon: "commit",
655 kind: "open_dialog",
656 dialogAction: "commit",
657 },
658 {
659 id: "push",
660 label: "Push",
661 disabled: true,
662 icon: "push",
663 kind: "open_dialog",
664 dialogAction: "push",
665 },
666 {
667 id: "pr",
668 label: "Create PR",
669 disabled: true,
670 icon: "pr",
671 kind: "open_dialog",
672 dialogAction: "create_pr",
673 },
674 ]);
675 });
676});
677​
678describe("when: HEAD is detached and there are no local changes", () => {
679 it("resolveQuickAction shows detached head hint", () => {
680 const quick = resolveQuickAction(
681 status({ refName: null, hasWorkingTreeChanges: false, hasUpstream: false }),
682 false,
683 );
684 assert.deepInclude(quick, { kind: "show_hint", label: "Commit", disabled: true });
685 });
686​
687 it("buildMenuItems keeps commit, push, and PR disabled", () => {
688 const items = buildMenuItems(status({ refName: null, hasWorkingTreeChanges: false }), false);
689 assert.deepEqual(items, [
690 {
691 id: "commit",
692 label: "Commit",
693 disabled: true,
694 icon: "commit",
695 kind: "open_dialog",
696 dialogAction: "commit",
697 },
698 {
699 id: "push",
700 label: "Push",
701 disabled: true,
702 icon: "push",
703 kind: "open_dialog",
704 dialogAction: "push",
705 },
706 {
707 id: "pr",
708 label: "Create PR",
709 disabled: true,
710 icon: "pr",
711 kind: "open_dialog",
712 dialogAction: "create_pr",
713 },
714 ]);
715 });
716});
717​
718describe("when: ref has no upstream configured", () => {
719 it("resolveQuickAction is disabled when clean, no upstream, and no local commits are ahead", () => {
720 const quick = resolveQuickAction(
721 status({ hasUpstream: false, pr: null, aheadCount: 0 }),
722 false,
723 );
724 assert.deepInclude(quick, {
725 kind: "show_hint",
726 label: "Push",
727 hint: "No local commits to push.",
728 disabled: true,
729 });
730 });
731​
732 it("resolveQuickAction rests disabled when clean, no upstream, no local commits are ahead, and PR exists", () => {
733 const quick = resolveQuickAction(
734 status({
735 hasUpstream: false,
736 aheadCount: 0,
737 pr: {
738 number: 14,
739 title: "Existing PR",
740 url: "https://example.com/pr/14",
741 baseRef: "main",
742 headRef: "feature/test",
743 state: "open",
744 },
745 }),
746 false,
747 );
748 assert.deepInclude(quick, {
749 kind: "show_hint",
750 label: "Commit",
751 disabled: true,
752 hint: "Branch is up to date. No action needed.",
753 });
754 });
755​
756 it("resolveQuickAction runs push when clean, no upstream, and local commits are ahead", () => {
757 const quick = resolveQuickAction(
758 status({
759 hasUpstream: false,
760 aheadCount: 1,
761 pr: {
762 number: 15,
763 title: "Existing PR",
764 url: "https://example.com/pr/15",
765 baseRef: "main",
766 headRef: "feature/test",
767 state: "open",
768 },
769 }),
770 false,
771 );
772 assert.deepInclude(quick, {
773 kind: "run_action",
774 action: "push",
775 label: "Push",
776 disabled: false,
777 });
778 });
779​
780 it("buildMenuItems disables push and create PR when no commits are ahead", () => {
781 const items = buildMenuItems(status({ hasUpstream: false, pr: null, aheadCount: 0 }), false);
782 assert.deepEqual(items, [
783 {
784 id: "commit",
785 label: "Commit",
786 disabled: true,
787 icon: "commit",
788 kind: "open_dialog",
789 dialogAction: "commit",
790 },
791 {
792 id: "push",
793 label: "Push",
794 disabled: true,
795 icon: "push",
796 kind: "open_dialog",
797 dialogAction: "push",
798 },
799 {
800 id: "pr",
801 label: "Create PR",
802 disabled: true,
803 icon: "pr",
804 kind: "open_dialog",
805 dialogAction: "create_pr",
806 },
807 ]);
808 });
809​
810 it("resolveQuickAction runs push and create PR when no upstream and commits are ahead", () => {
811 const quick = resolveQuickAction(
812 status({
813 hasUpstream: false,
814 aheadCount: 2,
815 pr: null,
816 }),
817 false,
818 );
819 assert.deepInclude(quick, {
820 kind: "run_action",
821 action: "create_pr",
822 label: "Push & create PR",
823 disabled: false,
824 });
825 });
826​
827 it("resolveQuickAction publishes when no origin remote exists", () => {
828 const quick = resolveQuickAction(
829 status({
830 hasUpstream: false,
831 aheadCount: 2,
832 pr: null,
833 }),
834 false,
835 false,
836 false,
837 );
838 assert.deepEqual(quick, {
839 kind: "open_publish",
840 label: "Publish repository",
841 disabled: false,
842 });
843 });
844​
845 it("buildMenuItems enables create PR when no upstream and commits are ahead", () => {
846 const items = buildMenuItems(status({ hasUpstream: false, pr: null, aheadCount: 2 }), false);
847 assert.deepEqual(items, [
848 {
849 id: "commit",
850 label: "Commit",
851 disabled: true,
852 icon: "commit",
853 kind: "open_dialog",
854 dialogAction: "commit",
855 },
856 {
857 id: "push",
858 label: "Push",
859 disabled: false,
860 icon: "push",
861 kind: "open_dialog",
862 dialogAction: "push",
863 },
864 {
865 id: "pr",
866 label: "Create PR",
867 disabled: false,
868 icon: "pr",
869 kind: "open_dialog",
870 dialogAction: "create_pr",
871 },
872 ]);
873 });
874​
875 it("buildMenuItems hides push and create PR when no origin remote exists", () => {
876 const items = buildMenuItems(
877 status({ hasUpstream: false, pr: null, aheadCount: 2 }),
878 false,
879 false,
880 );
881 assert.deepEqual(items, [
882 {
883 id: "commit",
884 label: "Commit",
885 disabled: true,
886 icon: "commit",
887 kind: "open_dialog",
888 dialogAction: "commit",
889 },
890 ]);
891 });
892​
893 it("resolveQuickAction is disabled on default ref when no upstream exists and no commits are ahead", () => {
894 const quick = resolveQuickAction(
895 status({
896 refName: "main",
897 hasUpstream: false,
898 aheadCount: 0,
899 pr: null,
900 }),
901 false,
902 true,
903 );
904 assert.deepInclude(quick, {
905 kind: "show_hint",
906 label: "Push",
907 hint: "No local commits to push.",
908 disabled: true,
909 });
910 });
911​
912 it("resolveQuickAction uses push-only on default ref when no upstream exists and commits are ahead", () => {
913 const quick = resolveQuickAction(
914 status({
915 refName: "main",
916 hasUpstream: false,
917 aheadCount: 1,
918 pr: null,
919 }),
920 false,
921 true,
922 );
923 assert.deepInclude(quick, {
924 kind: "run_action",
925 action: "commit_push",
926 label: "Push",
927 disabled: false,
928 });
929 });
930​
931 it("buildMenuItems still disables push and create PR when ref is behind", () => {
932 const items = buildMenuItems(
933 status({
934 hasUpstream: false,
935 behindCount: 1,
936 aheadCount: 0,
937 pr: null,
938 }),
939 false,
940 );
941 assert.deepEqual(items, [
942 {
943 id: "commit",
944 label: "Commit",
945 disabled: true,
946 icon: "commit",
947 kind: "open_dialog",
948 dialogAction: "commit",
949 },
950 {
951 id: "push",
952 label: "Push",
953 disabled: true,
954 icon: "push",
955 kind: "open_dialog",
956 dialogAction: "push",
957 },
958 {
959 id: "pr",
960 label: "Create PR",
961 disabled: true,
962 icon: "pr",
963 kind: "open_dialog",
964 dialogAction: "create_pr",
965 },
966 ]);
967 });
968});
969​
970describe("requiresDefaultBranchConfirmation", () => {
971 it("requires confirmation for push actions on default ref", () => {
972 assert.isFalse(requiresDefaultBranchConfirmation("commit", true));
973 assert.isTrue(requiresDefaultBranchConfirmation("push", true));
974 assert.isTrue(requiresDefaultBranchConfirmation("create_pr", true));
975 assert.isTrue(requiresDefaultBranchConfirmation("commit_push", true));
976 assert.isTrue(requiresDefaultBranchConfirmation("commit_push_pr", true));
977 assert.isFalse(requiresDefaultBranchConfirmation("commit_push", false));
978 assert.isFalse(requiresDefaultBranchConfirmation("push", false));
979 });
980});
981​
982describe("resolveDefaultBranchActionDialogCopy", () => {
983 it("uses push-only copy when pushing without a commit", () => {
984 const copy = resolveDefaultBranchActionDialogCopy({
985 action: "commit_push",
986 branchName: "main",
987 includesCommit: false,
988 });
989​
990 assert.deepEqual(copy, {
991 title: "Push to default ref?",
992 description:
993 'This action will push local commits on "main". You can continue on this ref or create a feature ref and run the same action there.',
994 continueLabel: "Push to main",
995 });
996 });
997​
998 it("uses push-and-pr copy when creating a PR without a commit", () => {
999 const copy = resolveDefaultBranchActionDialogCopy({
1000 action: "commit_push_pr",
1001 branchName: "main",
1002 includesCommit: false,
1003 });
1004​
1005 assert.deepEqual(copy, {
1006 title: "Push & create PR from default ref?",
1007 description:
1008 'This action will push local commits and create a pull request on "main". You can continue on this ref or create a feature ref and run the same action there.',
1009 continueLabel: "Push & create PR",
1010 });
1011 });
1012​
1013 it("keeps commit copy when the action includes a commit", () => {
1014 const copy = resolveDefaultBranchActionDialogCopy({
1015 action: "commit_push_pr",
1016 branchName: "main",
1017 includesCommit: true,
1018 });
1019​
1020 assert.deepEqual(copy, {
1021 title: "Commit, push & create PR from default ref?",
1022 description:
1023 'This action will commit, push, and create a pull request on "main". You can continue on this ref or create a feature ref and run the same action there.',
1024 continueLabel: "Commit, push & create PR",
1025 });
1026 });
1027});
1028​
1029describe("resolveFeatureBranchUnavailableReason", () => {
1030 it("blocks the feature branch when there is nothing to commit", () => {
1031 assert.equal(
1032 resolveFeatureBranchUnavailableReason({ branchName: "main", hasWorkingTreeChanges: false }),
1033 "There are no changes to commit, so a feature branch can't be named. Create a branch yourself or continue on main.",
1034 );
1035 });
1036​
1037 it("allows the feature branch when there are changes to commit", () => {
1038 assert.isNull(
1039 resolveFeatureBranchUnavailableReason({ branchName: "main", hasWorkingTreeChanges: true }),
1040 );
1041 });
1042});
1043​
1044describe("buildGitActionProgressStages", () => {
1045 it("shows only push progress for explicit push actions", () => {
1046 const stages = buildGitActionProgressStages({
1047 action: "push",
1048 hasCustomCommitMessage: false,
1049 hasWorkingTreeChanges: false,
1050 pushTarget: "origin/feature/test",
1051 });
1052 assert.deepEqual(stages, ["Pushing to origin/feature/test..."]);
1053 });
1054​
1055 it("shows push and PR progress for create-pr actions that still need a push", () => {
1056 const stages = buildGitActionProgressStages({
1057 action: "create_pr",
1058 hasCustomCommitMessage: false,
1059 hasWorkingTreeChanges: false,
1060 pushTarget: "origin/feature/test",
1061 shouldPushBeforePr: true,
1062 });
1063 assert.deepEqual(stages, [
1064 "Pushing to origin/feature/test...",
1065 "Preparing PR...",
1066 "Generating PR content...",
1067 "Creating pull request...",
1068 ]);
1069 });
1070​
1071 it("shows only PR progress when create-pr can skip the push", () => {
1072 const stages = buildGitActionProgressStages({
1073 action: "create_pr",
1074 hasCustomCommitMessage: false,
1075 hasWorkingTreeChanges: false,
1076 shouldPushBeforePr: false,
1077 });
1078 assert.deepEqual(stages, [
1079 "Preparing PR...",
1080 "Generating PR content...",
1081 "Creating pull request...",
1082 ]);
1083 });
1084​
1085 it("includes commit stages for commit+push when working tree is dirty", () => {
1086 const stages = buildGitActionProgressStages({
1087 action: "commit_push",
1088 hasCustomCommitMessage: false,
1089 hasWorkingTreeChanges: true,
1090 pushTarget: "origin/feature/test",
1091 });
1092 assert.deepEqual(stages, [
1093 "Generating commit message...",
1094 "Committing...",
1095 "Pushing to origin/feature/test...",
1096 ]);
1097 });
1098​
1099 it("includes granular PR stages for commit+push+PR actions", () => {
1100 const stages = buildGitActionProgressStages({
1101 action: "commit_push_pr",
1102 hasCustomCommitMessage: true,
1103 hasWorkingTreeChanges: true,
1104 pushTarget: "origin/feature/test",
1105 });
1106 assert.deepEqual(stages, [
1107 "Committing...",
1108 "Pushing to origin/feature/test...",
1109 "Preparing PR...",
1110 "Generating PR content...",
1111 "Creating pull request...",
1112 ]);
1113 });
1114});
1115​
1116describe("resolveThreadBranchUpdate", () => {
1117 it("returns a branch update when the action created a new branch", () => {
1118 const update = resolveThreadBranchUpdate({
1119 action: "commit_push_pr",
1120 branch: {
1121 status: "created",
1122 name: "feature/fix-toast-copy",
1123 },
1124 commit: {
1125 status: "created",
1126 commitSha: "89abcdef01234567",
1127 subject: "feat: add ref sync",
1128 },
1129 push: { status: "pushed", branch: "feature/fix-toast-copy" },
1130 pr: { status: "skipped_not_requested" },
1131 toast: {
1132 title: "Pushed 89abcde to origin/feature/fix-toast-copy",
1133 cta: { kind: "none" },
1134 },
1135 });
1136​
1137 assert.deepEqual(update, {
1138 branch: "feature/fix-toast-copy",
1139 });
1140 });
1141​
1142 it("returns null when the action stayed on the existing branch", () => {
1143 const update = resolveThreadBranchUpdate({
1144 action: "commit_push",
1145 branch: {
1146 status: "skipped_not_requested",
1147 },
1148 commit: {
1149 status: "created",
1150 commitSha: "89abcdef01234567",
1151 subject: "feat: add ref sync",
1152 },
1153 push: { status: "pushed", branch: "feature/fix-toast-copy" },
1154 pr: { status: "skipped_not_requested" },
1155 toast: {
1156 title: "Pushed 89abcde to origin/feature/fix-toast-copy",
1157 cta: { kind: "none" },
1158 },
1159 });
1160​
1161 assert.equal(update, null);
1162 });
1163});
1164​
1165describe("resolveLiveThreadBranchUpdate", () => {
1166 it("returns a branch update when live git status differs from stored thread metadata", () => {
1167 const update = resolveLiveThreadBranchUpdate({
1168 threadBranch: "feature/old-ref",
1169 gitStatus: status({ refName: "effect-atom" }),
1170 });
1171​
1172 assert.deepEqual(update, {
1173 branch: "effect-atom",
1174 });
1175 });
1176​
1177 it("returns null when live git status is unavailable", () => {
1178 const update = resolveLiveThreadBranchUpdate({
1179 threadBranch: "feature/old-ref",
1180 gitStatus: null,
1181 });
1182​
1183 assert.equal(update, null);
1184 });
1185​
1186 it("returns null when the stored thread ref already matches git status", () => {
1187 const update = resolveLiveThreadBranchUpdate({
1188 threadBranch: "effect-atom",
1189 gitStatus: status({ refName: "effect-atom" }),
1190 });
1191​
1192 assert.equal(update, null);
1193 });
1194​
1195 it("returns null when git status is detached HEAD but the thread already has a ref", () => {
1196 const update = resolveLiveThreadBranchUpdate({
1197 threadBranch: "effect-atom",
1198 gitStatus: status({ refName: null }),
1199 });
1200​
1201 assert.equal(update, null);
1202 });
1203​
1204 it("does not regress a semantic thread ref back to a temporary worktree ref", () => {
1205 const update = resolveLiveThreadBranchUpdate({
1206 threadBranch: "t3code/github-query-rate-limit",
1207 gitStatus: status({ refName: "t3code/bda76797" }),
1208 });
1209​
1210 assert.equal(update, null);
1211 });
1212​
1213 it("allows a temporary worktree ref to reconcile to a semantic branch", () => {
1214 const update = resolveLiveThreadBranchUpdate({
1215 threadBranch: "t3code/a9628676",
1216 gitStatus: status({ refName: "feature/diff-panel-toggle" }),
1217 });
1218​
1219 assert.deepEqual(update, { branch: "feature/diff-panel-toggle" });
1220 });
1221});
1222​
1223describe("resolveThreadBranchMetadataPatch", () => {
1224 it("does not overwrite worktree metadata while reconciling a branch", () => {
1225 assert.deepEqual(
1226 resolveThreadBranchMetadataPatch("feature/current-ref", "feature/previous-ref"),
1228 branch: "feature/current-ref",
1229 expectedBranch: "feature/previous-ref",
1230 },
1231 );
1232 });
1233});
1234​
1235describe("resolveAutoFeatureBranchName", () => {
1236 it("uses semantic preferred ref names when available", () => {
1237 const ref = resolveAutoFeatureBranchName(["main", "feature/other"], "fix toast copy");
1238 assert.equal(ref, "feature/fix-toast-copy");
1239 });
1240​
1241 it("normalizes preferred names that already include a ref namespace", () => {
1242 const ref = resolveAutoFeatureBranchName(["main"], "feature/refine-toolbar-actions");
1243 assert.equal(ref, "feature/refine-toolbar-actions");
1244 });
1245​
1246 it("increments suffix when the preferred ref name already exists", () => {
1247 const ref = resolveAutoFeatureBranchName(
1248 ["main", "feature/fix-toast-copy", "feature/fix-toast-copy-2"],
1249 "fix toast copy",
1250 );
1251 assert.equal(ref, "feature/fix-toast-copy-3");
1252 });
1253​
1254 it("treats existing ref names as case-insensitive for collision checks", () => {
1255 const ref = resolveAutoFeatureBranchName(["Feature/Ticket-1"], "feature/ticket-1");
1256 assert.equal(ref, "feature/ticket-1-2");
1257 });
1258​
1259 it("falls back to feature/update when no preferred name is provided", () => {
1260 const ref = resolveAutoFeatureBranchName(["main"]);
1261 assert.equal(ref, "feature/update");
1262 });
1263});