Open History to see the last commit
1import type { GitStatusResult } from "@t3tools/contracts";
2import { assert, describe, it } from "vitest";
3import {
4 buildGitActionProgressStages,
5 buildMenuItems,
6 requiresDefaultBranchConfirmation,
7 resolveAutoFeatureBranchName,
8 resolveDefaultBranchActionDialogCopy,
9 resolveLiveThreadBranchUpdate,
10 resolveQuickAction,
11 resolveThreadBranchUpdate,
12} from "./GitActionsControl.logic";
13
14function status(overrides: Partial<GitStatusResult> = {}): GitStatusResult {
15 return {
16 isRepo: true,
17 hasOriginRemote: true,
18 isDefaultBranch: false,
19 branch: "feature/test",
20 hasWorkingTreeChanges: false,
21 workingTree: {
22 files: [],
23 insertions: 0,
24 deletions: 0,
25 },
26 hasUpstream: true,
27 aheadCount: 0,
28 behindCount: 0,
29 pr: null,
30 ...overrides,
31 };
32}
33
34describe("when: branch is clean and has an open PR", () => {
35 it("resolveQuickAction opens the existing PR", () => {
36 const quick = resolveQuickAction(
37 status({
38 pr: {
39 number: 10,
40 title: "Open PR",
41 url: "https://example.com/pr/10",
42 baseBranch: "main",
43 headBranch: "feature/test",
44 state: "open",
45 },
46 }),
47 false,
48 );
49 assert.deepInclude(quick, { kind: "open_pr", label: "View PR", disabled: false });
50 });
51
52 it("buildMenuItems disables commit/push and enables open PR", () => {
53 const items = buildMenuItems(
54 status({
55 pr: {
56 number: 11,
57 title: "Existing PR",
58 url: "https://example.com/pr/11",
59 baseBranch: "main",
60 headBranch: "feature/test",
61 state: "open",
62 },
63 }),
64 false,
65 );
66 assert.deepEqual(items, [
67 {
68 id: "commit",
69 label: "Commit",
70 disabled: true,
71 icon: "commit",
72 kind: "open_dialog",
73 dialogAction: "commit",
74 },
75 {
76 id: "push",
77 label: "Push",
78 disabled: true,
79 icon: "push",
80 kind: "open_dialog",
81 dialogAction: "push",
82 },
83 {
84 id: "pr",
85 label: "View PR",
86 disabled: false,
87 icon: "pr",
88 kind: "open_pr",
89 },
90 ]);
91 });
92});
93
94describe("when: actions are busy", () => {
95 it("resolveQuickAction returns running disabled state", () => {
96 const quick = resolveQuickAction(status(), true);
97 assert.deepInclude(quick, {
98 kind: "show_hint",
99 label: "Commit",
100 disabled: true,
101 hint: "Git action in progress.",
102 });
103 });
104
105 it("buildMenuItems disables all actions", () => {
106 const items = buildMenuItems(status(), true);
107 assert.deepEqual(items, [
108 {
109 id: "commit",
110 label: "Commit",
111 disabled: true,
112 icon: "commit",
113 kind: "open_dialog",
114 dialogAction: "commit",
115 },
116 {
117 id: "push",
118 label: "Push",
119 disabled: true,
120 icon: "push",
121 kind: "open_dialog",
122 dialogAction: "push",
123 },
124 {
125 id: "pr",
126 label: "Create PR",
127 disabled: true,
128 icon: "pr",
129 kind: "open_dialog",
130 dialogAction: "create_pr",
131 },
132 ]);
133 });
134});
135
136describe("when: git status is unavailable", () => {
137 it("resolveQuickAction returns unavailable disabled state", () => {
138 const quick = resolveQuickAction(null, false);
139 assert.deepInclude(quick, {
140 kind: "show_hint",
141 label: "Commit",
142 disabled: true,
143 hint: "Git status is unavailable.",
144 });
145 });
146
147 it("buildMenuItems returns no menu items", () => {
148 const items = buildMenuItems(null, false);
149 assert.deepEqual(items, []);
150 });
151});
152
153describe("when: branch is clean, ahead, and has an open PR", () => {
154 it("resolveQuickAction prefers push", () => {
155 const quick = resolveQuickAction(
156 status({
157 aheadCount: 3,
158 pr: {
159 number: 13,
160 title: "Open PR",
161 url: "https://example.com/pr/13",
162 baseBranch: "main",
163 headBranch: "feature/test",
164 state: "open",
165 },
166 }),
167 false,
168 );
169 assert.deepInclude(quick, { kind: "run_action", action: "push", label: "Push" });
170 });
171
172 it("buildMenuItems enables push and keeps open PR available", () => {
173 const items = buildMenuItems(
174 status({
175 aheadCount: 2,
176 pr: {
177 number: 12,
178 title: "Existing PR",
179 url: "https://example.com/pr/12",
180 baseBranch: "main",
181 headBranch: "feature/test",
182 state: "open",
183 },
184 }),
185 false,
186 );
187 assert.deepEqual(items, [
188 {
189 id: "commit",
190 label: "Commit",
191 disabled: true,
192 icon: "commit",
193 kind: "open_dialog",
194 dialogAction: "commit",
195 },
196 {
197 id: "push",
198 label: "Push",
199 disabled: false,
200 icon: "push",
201 kind: "open_dialog",
202 dialogAction: "push",
203 },
204 {
205 id: "pr",
206 label: "View PR",
207 disabled: false,
208 icon: "pr",
209 kind: "open_pr",
210 },
211 ]);
212 });
213});
214
215describe("when: branch is clean, ahead, and has no open PR", () => {
216 it("resolveQuickAction pushes and creates a PR", () => {
217 const quick = resolveQuickAction(status({ aheadCount: 2, pr: null }), false);
218 assert.deepInclude(quick, {
219 kind: "run_action",
220 action: "create_pr",
221 label: "Push & create PR",
222 });
223 });
224
225 it("buildMenuItems enables push and create PR, with commit disabled", () => {
226 const items = buildMenuItems(status({ aheadCount: 2, pr: null }), false);
227 assert.deepEqual(items, [
228 {
229 id: "commit",
230 label: "Commit",
231 disabled: true,
232 icon: "commit",
233 kind: "open_dialog",
234 dialogAction: "commit",
235 },
236 {
237 id: "push",
238 label: "Push",
239 disabled: false,
240 icon: "push",
241 kind: "open_dialog",
242 dialogAction: "push",
243 },
244 {
245 id: "pr",
246 label: "Create PR",
247 disabled: false,
248 icon: "pr",
249 kind: "open_dialog",
250 dialogAction: "create_pr",
251 },
252 ]);
253 });
254});
255
256describe("when: branch is clean, up to date, and has no open PR", () => {
257 it("resolveQuickAction returns disabled no-action state", () => {
258 const quick = resolveQuickAction(
259 status({ aheadCount: 0, behindCount: 0, hasWorkingTreeChanges: false, pr: null }),
260 false,
261 );
262 assert.deepInclude(quick, { kind: "show_hint", label: "Commit", disabled: true });
263 });
264
265 it("buildMenuItems disables commit, push, and create PR", () => {
266 const items = buildMenuItems(status({ aheadCount: 0, behindCount: 0, pr: null }), false);
267 assert.deepEqual(items, [
268 {
269 id: "commit",
270 label: "Commit",
271 disabled: true,
272 icon: "commit",
273 kind: "open_dialog",
274 dialogAction: "commit",
275 },
276 {
277 id: "push",
278 label: "Push",
279 disabled: true,
280 icon: "push",
281 kind: "open_dialog",
282 dialogAction: "push",
283 },
284 {
285 id: "pr",
286 label: "Create PR",
287 disabled: true,
288 icon: "pr",
289 kind: "open_dialog",
290 dialogAction: "create_pr",
291 },
292 ]);
293 });
294});
295
296describe("when: branch is behind upstream", () => {
297 it("resolveQuickAction returns pull", () => {
298 const quick = resolveQuickAction(status({ behindCount: 2 }), false);
299 assert.deepInclude(quick, { kind: "run_pull", label: "Pull", disabled: false });
300 });
301
302 it("buildMenuItems disables push and create PR", () => {
303 const items = buildMenuItems(status({ behindCount: 1, pr: null }), false);
304 assert.deepEqual(items, [
305 {
306 id: "commit",
307 label: "Commit",
308 disabled: true,
309 icon: "commit",
310 kind: "open_dialog",
311 dialogAction: "commit",
312 },
313 {
314 id: "push",
315 label: "Push",
316 disabled: true,
317 icon: "push",
318 kind: "open_dialog",
319 dialogAction: "push",
320 },
321 {
322 id: "pr",
323 label: "Create PR",
324 disabled: true,
325 icon: "pr",
326 kind: "open_dialog",
327 dialogAction: "create_pr",
328 },
329 ]);
330 });
331});
332
333describe("when: branch has diverged from upstream", () => {
334 it("resolveQuickAction returns a disabled sync hint", () => {
335 const quick = resolveQuickAction(status({ aheadCount: 2, behindCount: 1 }), false);
336 assert.deepEqual(quick, {
337 label: "Sync branch",
338 disabled: true,
339 kind: "show_hint",
340 hint: "Branch has diverged from upstream. Rebase/merge first.",
341 });
342 });
343});
344
345describe("when: working tree has local changes", () => {
346 it("resolveQuickAction returns commit, push, and create PR", () => {
347 const quick = resolveQuickAction(status({ hasWorkingTreeChanges: true }), false);
348 assert.deepInclude(quick, {
349 kind: "run_action",
350 action: "commit_push_pr",
351 label: "Commit, push & PR",
352 });
353 });
354
355 it("resolveQuickAction falls back to commit when no origin remote exists", () => {
356 const quick = resolveQuickAction(
357 status({ hasWorkingTreeChanges: true, hasUpstream: false }),
358 false,
359 false,
360 false,
361 );
362 assert.deepInclude(quick, {
363 kind: "run_action",
364 action: "commit",
365 label: "Commit",
366 disabled: false,
367 });
368 });
369
370 it("resolveQuickAction returns commit and push when open PR exists", () => {
371 const quick = resolveQuickAction(
372 status({
373 hasWorkingTreeChanges: true,
374 pr: {
375 number: 16,
376 title: "Existing PR",
377 url: "https://example.com/pr/16",
378 baseBranch: "main",
379 headBranch: "feature/test",
380 state: "open",
381 },
382 }),
383 false,
384 );
385 assert.deepInclude(quick, {
386 kind: "run_action",
387 action: "commit_push",
388 label: "Commit & push",
389 });
390 });
391
392 it("buildMenuItems enables commit and disables push and PR", () => {
393 const items = buildMenuItems(status({ hasWorkingTreeChanges: true }), false);
394 assert.deepEqual(items, [
395 {
396 id: "commit",
397 label: "Commit",
398 disabled: false,
399 icon: "commit",
400 kind: "open_dialog",
401 dialogAction: "commit",
402 },
403 {
404 id: "push",
405 label: "Push",
406 disabled: true,
407 icon: "push",
408 kind: "open_dialog",
409 dialogAction: "push",
410 },
411 {
412 id: "pr",
413 label: "Create PR",
414 disabled: true,
415 icon: "pr",
416 kind: "open_dialog",
417 dialogAction: "create_pr",
418 },
419 ]);
420 });
421});
422
423describe("when: on default branch without open PR", () => {
424 it("resolveQuickAction returns commit and push when local changes exist", () => {
425 const quick = resolveQuickAction(
426 status({ branch: "main", hasWorkingTreeChanges: true }),
427 false,
428 true,
429 );
430 assert.deepInclude(quick, {
431 kind: "run_action",
432 action: "commit_push",
433 label: "Commit & push",
434 disabled: false,
435 });
436 });
437
438 it("resolveQuickAction returns push when branch is ahead", () => {
439 const quick = resolveQuickAction(
440 status({ branch: "main", aheadCount: 2, pr: null }),
441 false,
442 true,
443 );
444 assert.deepInclude(quick, {
445 kind: "run_action",
446 action: "commit_push",
447 label: "Push",
448 disabled: false,
449 });
450 });
451});
452
453describe("when: working tree has local changes and branch is behind upstream", () => {
454 it("resolveQuickAction still prefers commit, push, and create PR", () => {
455 const quick = resolveQuickAction(
456 status({ hasWorkingTreeChanges: true, behindCount: 1 }),
457 false,
458 );
459 assert.deepInclude(quick, {
460 kind: "run_action",
461 action: "commit_push_pr",
462 label: "Commit, push & PR",
463 });
464 });
465
466 it("buildMenuItems enables commit and keeps push and PR disabled", () => {
467 const items = buildMenuItems(status({ hasWorkingTreeChanges: true, behindCount: 2 }), false);
468 assert.deepEqual(items, [
469 {
470 id: "commit",
471 label: "Commit",
472 disabled: false,
473 icon: "commit",
474 kind: "open_dialog",
475 dialogAction: "commit",
476 },
477 {
478 id: "push",
479 label: "Push",
480 disabled: true,
481 icon: "push",
482 kind: "open_dialog",
483 dialogAction: "push",
484 },
485 {
486 id: "pr",
487 label: "Create PR",
488 disabled: true,
489 icon: "pr",
490 kind: "open_dialog",
491 dialogAction: "create_pr",
492 },
493 ]);
494 });
495});
496
497describe("when: HEAD is detached and there are no local changes", () => {
498 it("resolveQuickAction shows detached head hint", () => {
499 const quick = resolveQuickAction(
500 status({ branch: null, hasWorkingTreeChanges: false, hasUpstream: false }),
501 false,
502 );
503 assert.deepInclude(quick, { kind: "show_hint", label: "Commit", disabled: true });
504 });
505
506 it("buildMenuItems keeps commit, push, and PR disabled", () => {
507 const items = buildMenuItems(status({ branch: null, hasWorkingTreeChanges: false }), false);
508 assert.deepEqual(items, [
509 {
510 id: "commit",
511 label: "Commit",
512 disabled: true,
513 icon: "commit",
514 kind: "open_dialog",
515 dialogAction: "commit",
516 },
517 {
518 id: "push",
519 label: "Push",
520 disabled: true,
521 icon: "push",
522 kind: "open_dialog",
523 dialogAction: "push",
524 },
525 {
526 id: "pr",
527 label: "Create PR",
528 disabled: true,
529 icon: "pr",
530 kind: "open_dialog",
531 dialogAction: "create_pr",
532 },
533 ]);
534 });
535});
536
537describe("when: branch has no upstream configured", () => {
538 it("resolveQuickAction is disabled when clean, no upstream, and no local commits are ahead", () => {
539 const quick = resolveQuickAction(
540 status({ hasUpstream: false, pr: null, aheadCount: 0 }),
541 false,
542 );
543 assert.deepInclude(quick, {
544 kind: "show_hint",
545 label: "Push",
546 hint: "No local commits to push.",
547 disabled: true,
548 });
549 });
550
551 it("resolveQuickAction opens PR when clean, no upstream, no local commits are ahead, and PR exists", () => {
552 const quick = resolveQuickAction(
553 status({
554 hasUpstream: false,
555 aheadCount: 0,
556 pr: {
557 number: 14,
558 title: "Existing PR",
559 url: "https://example.com/pr/14",
560 baseBranch: "main",
561 headBranch: "feature/test",
562 state: "open",
563 },
564 }),
565 false,
566 );
567 assert.deepInclude(quick, {
568 kind: "open_pr",
569 label: "View PR",
570 disabled: false,
571 });
572 });
573
574 it("resolveQuickAction runs push when clean, no upstream, and local commits are ahead", () => {
575 const quick = resolveQuickAction(
576 status({
577 hasUpstream: false,
578 aheadCount: 1,
579 pr: {
580 number: 15,
581 title: "Existing PR",
582 url: "https://example.com/pr/15",
583 baseBranch: "main",
584 headBranch: "feature/test",
585 state: "open",
586 },
587 }),
588 false,
589 );
590 assert.deepInclude(quick, {
591 kind: "run_action",
592 action: "push",
593 label: "Push",
594 disabled: false,
595 });
596 });
597
598 it("buildMenuItems disables push and create PR when no commits are ahead", () => {
599 const items = buildMenuItems(status({ hasUpstream: false, pr: null, aheadCount: 0 }), false);
600 assert.deepEqual(items, [
601 {
602 id: "commit",
603 label: "Commit",
604 disabled: true,
605 icon: "commit",
606 kind: "open_dialog",
607 dialogAction: "commit",
608 },
609 {
610 id: "push",
611 label: "Push",
612 disabled: true,
613 icon: "push",
614 kind: "open_dialog",
615 dialogAction: "push",
616 },
617 {
618 id: "pr",
619 label: "Create PR",
620 disabled: true,
621 icon: "pr",
622 kind: "open_dialog",
623 dialogAction: "create_pr",
624 },
625 ]);
626 });
627
628 it("resolveQuickAction runs push and create PR when no upstream and commits are ahead", () => {
629 const quick = resolveQuickAction(
630 status({
631 hasUpstream: false,
632 aheadCount: 2,
633 pr: null,
634 }),
635 false,
636 );
637 assert.deepInclude(quick, {
638 kind: "run_action",
639 action: "create_pr",
640 label: "Push & create PR",
641 disabled: false,
642 });
643 });
644
645 it("resolveQuickAction disables push-and-pr flows when no origin remote exists", () => {
646 const quick = resolveQuickAction(
647 status({
648 hasUpstream: false,
649 aheadCount: 2,
650 pr: null,
651 }),
652 false,
653 false,
654 false,
655 );
656 assert.deepEqual(quick, {
657 kind: "show_hint",
658 label: "Push",
659 hint: 'Add an "origin" remote before pushing or creating a PR.',
660 disabled: true,
661 });
662 });
663
664 it("buildMenuItems enables create PR when no upstream and commits are ahead", () => {
665 const items = buildMenuItems(status({ hasUpstream: false, pr: null, aheadCount: 2 }), false);
666 assert.deepEqual(items, [
667 {
668 id: "commit",
669 label: "Commit",
670 disabled: true,
671 icon: "commit",
672 kind: "open_dialog",
673 dialogAction: "commit",
674 },
675 {
676 id: "push",
677 label: "Push",
678 disabled: false,
679 icon: "push",
680 kind: "open_dialog",
681 dialogAction: "push",
682 },
683 {
684 id: "pr",
685 label: "Create PR",
686 disabled: false,
687 icon: "pr",
688 kind: "open_dialog",
689 dialogAction: "create_pr",
690 },
691 ]);
692 });
693
694 it("buildMenuItems disables push and create PR when no origin remote exists", () => {
695 const items = buildMenuItems(
696 status({ hasUpstream: false, pr: null, aheadCount: 2 }),
697 false,
698 false,
699 );
700 assert.deepEqual(items, [
701 {
702 id: "commit",
703 label: "Commit",
704 disabled: true,
705 icon: "commit",
706 kind: "open_dialog",
707 dialogAction: "commit",
708 },
709 {
710 id: "push",
711 label: "Push",
712 disabled: true,
713 icon: "push",
714 kind: "open_dialog",
715 dialogAction: "push",
716 },
717 {
718 id: "pr",
719 label: "Create PR",
720 disabled: true,
721 icon: "pr",
722 kind: "open_dialog",
723 dialogAction: "create_pr",
724 },
725 ]);
726 });
727
728 it("resolveQuickAction is disabled on default branch when no upstream exists and no commits are ahead", () => {
729 const quick = resolveQuickAction(
730 status({
731 branch: "main",
732 hasUpstream: false,
733 aheadCount: 0,
734 pr: null,
735 }),
736 false,
737 true,
738 );
739 assert.deepInclude(quick, {
740 kind: "show_hint",
741 label: "Push",
742 hint: "No local commits to push.",
743 disabled: true,
744 });
745 });
746
747 it("resolveQuickAction uses push-only on default branch when no upstream exists and commits are ahead", () => {
748 const quick = resolveQuickAction(
749 status({
750 branch: "main",
751 hasUpstream: false,
752 aheadCount: 1,
753 pr: null,
754 }),
755 false,
756 true,
757 );
758 assert.deepInclude(quick, {
759 kind: "run_action",
760 action: "commit_push",
761 label: "Push",
762 disabled: false,
763 });
764 });
765
766 it("buildMenuItems still disables push and create PR when branch is behind", () => {
767 const items = buildMenuItems(
768 status({
769 hasUpstream: false,
770 behindCount: 1,
771 aheadCount: 0,
772 pr: null,
773 }),
774 false,
775 );
776 assert.deepEqual(items, [
777 {
778 id: "commit",
779 label: "Commit",
780 disabled: true,
781 icon: "commit",
782 kind: "open_dialog",
783 dialogAction: "commit",
784 },
785 {
786 id: "push",
787 label: "Push",
788 disabled: true,
789 icon: "push",
790 kind: "open_dialog",
791 dialogAction: "push",
792 },
793 {
794 id: "pr",
795 label: "Create PR",
796 disabled: true,
797 icon: "pr",
798 kind: "open_dialog",
799 dialogAction: "create_pr",
800 },
801 ]);
802 });
803});
804
805describe("requiresDefaultBranchConfirmation", () => {
806 it("requires confirmation for push actions on default branch", () => {
807 assert.isFalse(requiresDefaultBranchConfirmation("commit", true));
808 assert.isTrue(requiresDefaultBranchConfirmation("push", true));
809 assert.isTrue(requiresDefaultBranchConfirmation("create_pr", true));
810 assert.isTrue(requiresDefaultBranchConfirmation("commit_push", true));
811 assert.isTrue(requiresDefaultBranchConfirmation("commit_push_pr", true));
812 assert.isFalse(requiresDefaultBranchConfirmation("commit_push", false));
813 assert.isFalse(requiresDefaultBranchConfirmation("push", false));
814 });
815});
816
817describe("resolveDefaultBranchActionDialogCopy", () => {
818 it("uses push-only copy when pushing without a commit", () => {
819 const copy = resolveDefaultBranchActionDialogCopy({
820 action: "commit_push",
821 branchName: "main",
822 includesCommit: false,
823 });
824
825 assert.deepEqual(copy, {
826 title: "Push to default branch?",
827 description:
828 'This action will push local commits on "main". You can continue on this branch or create a feature branch and run the same action there.',
829 continueLabel: "Push to main",
830 });
831 });
832
833 it("uses push-and-pr copy when creating a PR without a commit", () => {
834 const copy = resolveDefaultBranchActionDialogCopy({
835 action: "commit_push_pr",
836 branchName: "main",
837 includesCommit: false,
838 });
839
840 assert.deepEqual(copy, {
841 title: "Push & create PR from default branch?",
842 description:
843 'This action will push local commits and create a PR on "main". You can continue on this branch or create a feature branch and run the same action there.',
844 continueLabel: "Push & create PR",
845 });
846 });
847
848 it("keeps commit copy when the action includes a commit", () => {
849 const copy = resolveDefaultBranchActionDialogCopy({
850 action: "commit_push_pr",
851 branchName: "main",
852 includesCommit: true,
853 });
854
855 assert.deepEqual(copy, {
856 title: "Commit, push & create PR from default branch?",
857 description:
858 'This action will commit, push, and create a PR on "main". You can continue on this branch or create a feature branch and run the same action there.',
859 continueLabel: "Commit, push & create PR",
860 });
861 });
862});
863
864describe("buildGitActionProgressStages", () => {
865 it("shows only push progress for explicit push actions", () => {
866 const stages = buildGitActionProgressStages({
867 action: "push",
868 hasCustomCommitMessage: false,
869 hasWorkingTreeChanges: false,
870 pushTarget: "origin/feature/test",
871 });
872 assert.deepEqual(stages, ["Pushing to origin/feature/test..."]);
873 });
874
875 it("shows push and PR progress for create-pr actions that still need a push", () => {
876 const stages = buildGitActionProgressStages({
877 action: "create_pr",
878 hasCustomCommitMessage: false,
879 hasWorkingTreeChanges: false,
880 pushTarget: "origin/feature/test",
881 shouldPushBeforePr: true,
882 });
883 assert.deepEqual(stages, [
884 "Pushing to origin/feature/test...",
885 "Preparing PR...",
886 "Generating PR content...",
887 "Creating GitHub pull request...",
888 ]);
889 });
890
891 it("shows only PR progress when create-pr can skip the push", () => {
892 const stages = buildGitActionProgressStages({
893 action: "create_pr",
894 hasCustomCommitMessage: false,
895 hasWorkingTreeChanges: false,
896 shouldPushBeforePr: false,
897 });
898 assert.deepEqual(stages, [
899 "Preparing PR...",
900 "Generating PR content...",
901 "Creating GitHub pull request...",
902 ]);
903 });
904
905 it("includes commit stages for commit+push when working tree is dirty", () => {
906 const stages = buildGitActionProgressStages({
907 action: "commit_push",
908 hasCustomCommitMessage: false,
909 hasWorkingTreeChanges: true,
910 pushTarget: "origin/feature/test",
911 });
912 assert.deepEqual(stages, [
913 "Generating commit message...",
914 "Committing...",
915 "Pushing to origin/feature/test...",
916 ]);
917 });
918
919 it("includes granular PR stages for commit+push+PR actions", () => {
920 const stages = buildGitActionProgressStages({
921 action: "commit_push_pr",
922 hasCustomCommitMessage: true,
923 hasWorkingTreeChanges: true,
924 pushTarget: "origin/feature/test",
925 });
926 assert.deepEqual(stages, [
927 "Committing...",
928 "Pushing to origin/feature/test...",
929 "Preparing PR...",
930 "Generating PR content...",
931 "Creating GitHub pull request...",
932 ]);
933 });
934});
935
936describe("resolveThreadBranchUpdate", () => {
937 it("returns a branch update when the action created a new branch", () => {
938 const update = resolveThreadBranchUpdate({
939 action: "commit_push_pr",
940 branch: {
941 status: "created",
942 name: "feature/fix-toast-copy",
943 },
944 commit: {
945 status: "created",
946 commitSha: "89abcdef01234567",
947 subject: "feat: add branch sync",
948 },
949 push: { status: "pushed", branch: "feature/fix-toast-copy" },
950 pr: { status: "skipped_not_requested" },
951 toast: {
952 title: "Pushed 89abcde to origin/feature/fix-toast-copy",
953 cta: { kind: "none" },
954 },
955 });
956
957 assert.deepEqual(update, {
958 branch: "feature/fix-toast-copy",
959 });
960 });
961
962 it("returns null when the action stayed on the existing branch", () => {
963 const update = resolveThreadBranchUpdate({
964 action: "commit_push",
965 branch: {
966 status: "skipped_not_requested",
967 },
968 commit: {
969 status: "created",
970 commitSha: "89abcdef01234567",
971 subject: "feat: add branch sync",
972 },
973 push: { status: "pushed", branch: "feature/fix-toast-copy" },
974 pr: { status: "skipped_not_requested" },
975 toast: {
976 title: "Pushed 89abcde to origin/feature/fix-toast-copy",
977 cta: { kind: "none" },
978 },
979 });
980
981 assert.equal(update, null);
982 });
983});
984
985describe("resolveLiveThreadBranchUpdate", () => {
986 it("returns a branch update when live git status differs from stored thread metadata", () => {
987 const update = resolveLiveThreadBranchUpdate({
988 threadBranch: "feature/old-branch",
989 gitStatus: status({ branch: "effect-atom" }),
990 });
991
992 assert.deepEqual(update, {
993 branch: "effect-atom",
994 });
995 });
996
997 it("returns null when live git status is unavailable", () => {
998 const update = resolveLiveThreadBranchUpdate({
999 threadBranch: "feature/old-branch",
1000 gitStatus: null,
1001 });
1002
1003 assert.equal(update, null);
1004 });
1005
1006 it("returns null when the stored thread branch already matches git status", () => {
1007 const update = resolveLiveThreadBranchUpdate({
1008 threadBranch: "effect-atom",
1009 gitStatus: status({ branch: "effect-atom" }),
1010 });
1011
1012 assert.equal(update, null);
1013 });
1014
1015 it("returns null when git status is detached HEAD but the thread already has a branch", () => {
1016 const update = resolveLiveThreadBranchUpdate({
1017 threadBranch: "effect-atom",
1018 gitStatus: status({ branch: null }),
1019 });
1020
1021 assert.equal(update, null);
1022 });
1023});
1024
1025describe("resolveAutoFeatureBranchName", () => {
1026 it("uses semantic preferred branch names when available", () => {
1027 const branch = resolveAutoFeatureBranchName(["main", "feature/other"], "fix toast copy");
1028 assert.equal(branch, "feature/fix-toast-copy");
1029 });
1030
1031 it("normalizes preferred names that already include a branch namespace", () => {
1032 const branch = resolveAutoFeatureBranchName(["main"], "feature/refine-toolbar-actions");
1033 assert.equal(branch, "feature/refine-toolbar-actions");
1034 });
1035
1036 it("increments suffix when the preferred branch name already exists", () => {
1037 const branch = resolveAutoFeatureBranchName(
1038 ["main", "feature/fix-toast-copy", "feature/fix-toast-copy-2"],
1039 "fix toast copy",
1040 );
1041 assert.equal(branch, "feature/fix-toast-copy-3");
1042 });
1043
1044 it("treats existing branch names as case-insensitive for collision checks", () => {
1045 const branch = resolveAutoFeatureBranchName(["Feature/Ticket-1"], "feature/ticket-1");
1046 assert.equal(branch, "feature/ticket-1-2");
1047 });
1048
1049 it("falls back to feature/update when no preferred name is provided", () => {
1050 const branch = resolveAutoFeatureBranchName(["main"]);
1051 assert.equal(branch, "feature/update");
1052 });
1053});