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

GitActionsControl.logic.test.ts

1,155 lines30.3 KB

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