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

GitActionsControl.logic.test.ts

1,133 lines29.6 KB

1import type { VcsStatusResult } 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<VcsStatusResult> = {}): VcsStatusResult {
15 return {
16 isRepo: true,
17 hasPrimaryRemote: true,
18 isDefaultRef: false,
19 refName: "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 };
33​
34describe("when: ref 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 baseRef: "main",
43 headRef: "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 baseRef: "main",
60 headRef: "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: ref 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 baseRef: "main",
163 headRef: "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 baseRef: "main",
181 headRef: "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: ref 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: source control provider uses merge requests", () => {
257 it("uses GitLab MR terminology in quick actions and menu items", () => {
258 const gitlabStatus = status({
259 aheadCount: 2,
260 sourceControlProvider: {
261 kind: "gitlab",
262 name: "GitLab",
263 baseUrl: "https://gitlab.com",
264 },
265 });
266​
267 const quick = resolveQuickAction(gitlabStatus, false);
268 const items = buildMenuItems(gitlabStatus, false);
269​
270 assert.deepInclude(quick, {
271 kind: "run_action",
272 action: "create_pr",
273 label: "Push & create MR",
274 });
275 assert.deepInclude(items[2], {
276 id: "pr",
277 label: "Create MR",
278 });
279 });
280});
281​
282describe("when: ref is clean, up to date, and has no open PR", () => {
283 it("enables create PR when synced with upstream but ahead of default", () => {
284 const syncedFeature = status({
285 aheadCount: 0,
286 behindCount: 0,
287 aheadOfDefaultCount: 1,
288 pr: null,
289 });
290​
291 const quick = resolveQuickAction(syncedFeature, false);
292 assert.deepInclude(quick, {
293 label: "Create PR",
294 disabled: false,
295 kind: "run_action",
296 action: "create_pr",
297 });
298​
299 const items = buildMenuItems(syncedFeature, false);
300 assert.equal(items.find((item) => item.id === "pr")?.disabled, false);
301 });
302​
303 it("resolveQuickAction returns disabled no-action state", () => {
304 const quick = resolveQuickAction(
305 status({ aheadCount: 0, behindCount: 0, hasWorkingTreeChanges: false, pr: null }),
306 false,
307 );
308 assert.deepInclude(quick, { kind: "show_hint", label: "Commit", disabled: true });
309 });
310​
311 it("buildMenuItems disables commit, push, and create PR", () => {
312 const items = buildMenuItems(status({ aheadCount: 0, behindCount: 0, pr: null }), false);
313 assert.deepEqual(items, [
314 {
315 id: "commit",
316 label: "Commit",
317 disabled: true,
318 icon: "commit",
319 kind: "open_dialog",
320 dialogAction: "commit",
321 },
322 {
323 id: "push",
324 label: "Push",
325 disabled: true,
326 icon: "push",
327 kind: "open_dialog",
328 dialogAction: "push",
329 },
330 {
331 id: "pr",
332 label: "Create PR",
333 disabled: true,
334 icon: "pr",
335 kind: "open_dialog",
336 dialogAction: "create_pr",
337 },
338 ]);
339 });
340});
341​
342describe("when: ref is behind upstream", () => {
343 it("resolveQuickAction returns pull", () => {
344 const quick = resolveQuickAction(status({ behindCount: 2 }), false);
345 assert.deepInclude(quick, { kind: "run_pull", label: "Pull", disabled: false });
346 });
347​
348 it("buildMenuItems disables push and create PR", () => {
349 const items = buildMenuItems(status({ behindCount: 1, pr: null }), false);
350 assert.deepEqual(items, [
351 {
352 id: "commit",
353 label: "Commit",
354 disabled: true,
355 icon: "commit",
356 kind: "open_dialog",
357 dialogAction: "commit",
358 },
359 {
360 id: "push",
361 label: "Push",
362 disabled: true,
363 icon: "push",
364 kind: "open_dialog",
365 dialogAction: "push",
366 },
367 {
368 id: "pr",
369 label: "Create PR",
370 disabled: true,
371 icon: "pr",
372 kind: "open_dialog",
373 dialogAction: "create_pr",
374 },
375 ]);
376 });
377});
378​
379describe("when: ref has diverged from upstream", () => {
380 it("resolveQuickAction returns a disabled sync hint", () => {
381 const quick = resolveQuickAction(status({ aheadCount: 2, behindCount: 1 }), false);
382 assert.deepEqual(quick, {
383 label: "Sync ref",
384 disabled: true,
385 kind: "show_hint",
386 hint: "Branch has diverged from upstream. Rebase/merge first.",
387 });
388 });
389});
390​
391describe("when: working tree has local changes", () => {
392 it("resolveQuickAction returns commit, push, and create PR", () => {
393 const quick = resolveQuickAction(status({ hasWorkingTreeChanges: true }), false);
394 assert.deepInclude(quick, {
395 kind: "run_action",
396 action: "commit_push_pr",
397 label: "Commit, push & PR",
398 });
399 });
400​
401 it("resolveQuickAction falls back to commit when no origin remote exists", () => {
402 const quick = resolveQuickAction(
403 status({ hasWorkingTreeChanges: true, hasUpstream: false }),
404 false,
405 false,
406 false,
407 );
408 assert.deepInclude(quick, {
409 kind: "run_action",
410 action: "commit",
411 label: "Commit",
412 disabled: false,
413 });
414 });
415​
416 it("resolveQuickAction returns commit and push when open PR exists", () => {
417 const quick = resolveQuickAction(
418 status({
419 hasWorkingTreeChanges: true,
420 pr: {
421 number: 16,
422 title: "Existing PR",
423 url: "https://example.com/pr/16",
424 baseRef: "main",
425 headRef: "feature/test",
426 state: "open",
427 },
428 }),
429 false,
430 );
431 assert.deepInclude(quick, {
432 kind: "run_action",
433 action: "commit_push",
434 label: "Commit & push",
435 });
436 });
437​
438 it("buildMenuItems enables commit and disables push and PR", () => {
439 const items = buildMenuItems(status({ hasWorkingTreeChanges: true }), false);
440 assert.deepEqual(items, [
441 {
442 id: "commit",
443 label: "Commit",
444 disabled: false,
445 icon: "commit",
446 kind: "open_dialog",
447 dialogAction: "commit",
448 },
449 {
450 id: "push",
451 label: "Push",
452 disabled: true,
453 icon: "push",
454 kind: "open_dialog",
455 dialogAction: "push",
456 },
457 {
458 id: "pr",
459 label: "Create PR",
460 disabled: true,
461 icon: "pr",
462 kind: "open_dialog",
463 dialogAction: "create_pr",
464 },
465 ]);
466 });
467​
468 it("buildMenuItems enables push for ahead commits while local changes remain uncommitted", () => {
469 const items = buildMenuItems(
470 status({
471 refName: "feature/test",
472 hasWorkingTreeChanges: true,
473 aheadCount: 1,
474 workingTree: {
475 files: [{ path: ".vercel/project.json", insertions: 1, deletions: 0 }],
476 insertions: 1,
477 deletions: 0,
478 },
479 }),
480 false,
481 );
482 assert.deepEqual(items, [
483 {
484 id: "commit",
485 label: "Commit",
486 disabled: false,
487 icon: "commit",
488 kind: "open_dialog",
489 dialogAction: "commit",
490 },
491 {
492 id: "push",
493 label: "Push",
494 disabled: false,
495 icon: "push",
496 kind: "open_dialog",
497 dialogAction: "push",
498 },
499 {
500 id: "pr",
501 label: "Create PR",
502 disabled: true,
503 icon: "pr",
504 kind: "open_dialog",
505 dialogAction: "create_pr",
506 },
507 ]);
508 });
509});
510​
511describe("when: on default ref without open PR", () => {
512 it("resolveQuickAction returns commit and push when local changes exist", () => {
513 const quick = resolveQuickAction(
514 status({ refName: "main", hasWorkingTreeChanges: true }),
515 false,
516 true,
517 );
518 assert.deepInclude(quick, {
519 kind: "run_action",
520 action: "commit_push",
521 label: "Commit & push",
522 disabled: false,
523 });
524 });
525​
526 it("resolveQuickAction returns push when ref is ahead", () => {
527 const quick = resolveQuickAction(
528 status({ refName: "main", aheadCount: 2, pr: null }),
529 false,
530 true,
531 );
532 assert.deepInclude(quick, {
533 kind: "run_action",
534 action: "commit_push",
535 label: "Push",
536 disabled: false,
537 });
538 });
539});
540​
541describe("when: working tree has local changes and ref is behind upstream", () => {
542 it("resolveQuickAction still prefers commit, push, and create PR", () => {
543 const quick = resolveQuickAction(
544 status({ hasWorkingTreeChanges: true, behindCount: 1 }),
545 false,
546 );
547 assert.deepInclude(quick, {
548 kind: "run_action",
549 action: "commit_push_pr",
550 label: "Commit, push & PR",
551 });
552 });
553​
554 it("buildMenuItems enables commit and keeps push and PR disabled", () => {
555 const items = buildMenuItems(status({ hasWorkingTreeChanges: true, behindCount: 2 }), false);
556 assert.deepEqual(items, [
557 {
558 id: "commit",
559 label: "Commit",
560 disabled: false,
561 icon: "commit",
562 kind: "open_dialog",
563 dialogAction: "commit",
564 },
565 {
566 id: "push",
567 label: "Push",
568 disabled: true,
569 icon: "push",
570 kind: "open_dialog",
571 dialogAction: "push",
572 },
573 {
574 id: "pr",
575 label: "Create PR",
576 disabled: true,
577 icon: "pr",
578 kind: "open_dialog",
579 dialogAction: "create_pr",
580 },
581 ]);
582 });
583});
584​
585describe("when: HEAD is detached and there are no local changes", () => {
586 it("resolveQuickAction shows detached head hint", () => {
587 const quick = resolveQuickAction(
588 status({ refName: null, hasWorkingTreeChanges: false, hasUpstream: false }),
589 false,
590 );
591 assert.deepInclude(quick, { kind: "show_hint", label: "Commit", disabled: true });
592 });
593​
594 it("buildMenuItems keeps commit, push, and PR disabled", () => {
595 const items = buildMenuItems(status({ refName: null, hasWorkingTreeChanges: false }), false);
596 assert.deepEqual(items, [
597 {
598 id: "commit",
599 label: "Commit",
600 disabled: true,
601 icon: "commit",
602 kind: "open_dialog",
603 dialogAction: "commit",
604 },
605 {
606 id: "push",
607 label: "Push",
608 disabled: true,
609 icon: "push",
610 kind: "open_dialog",
611 dialogAction: "push",
612 },
613 {
614 id: "pr",
615 label: "Create PR",
616 disabled: true,
617 icon: "pr",
618 kind: "open_dialog",
619 dialogAction: "create_pr",
620 },
621 ]);
622 });
623});
624​
625describe("when: ref has no upstream configured", () => {
626 it("resolveQuickAction is disabled when clean, no upstream, and no local commits are ahead", () => {
627 const quick = resolveQuickAction(
628 status({ hasUpstream: false, pr: null, aheadCount: 0 }),
629 false,
630 );
631 assert.deepInclude(quick, {
632 kind: "show_hint",
633 label: "Push",
634 hint: "No local commits to push.",
635 disabled: true,
636 });
637 });
638​
639 it("resolveQuickAction opens PR when clean, no upstream, no local commits are ahead, and PR exists", () => {
640 const quick = resolveQuickAction(
641 status({
642 hasUpstream: false,
643 aheadCount: 0,
644 pr: {
645 number: 14,
646 title: "Existing PR",
647 url: "https://example.com/pr/14",
648 baseRef: "main",
649 headRef: "feature/test",
650 state: "open",
651 },
652 }),
653 false,
654 );
655 assert.deepInclude(quick, {
656 kind: "open_pr",
657 label: "View PR",
658 disabled: false,
659 });
660 });
661​
662 it("resolveQuickAction runs push when clean, no upstream, and local commits are ahead", () => {
663 const quick = resolveQuickAction(
664 status({
665 hasUpstream: false,
666 aheadCount: 1,
667 pr: {
668 number: 15,
669 title: "Existing PR",
670 url: "https://example.com/pr/15",
671 baseRef: "main",
672 headRef: "feature/test",
673 state: "open",
674 },
675 }),
676 false,
677 );
678 assert.deepInclude(quick, {
679 kind: "run_action",
680 action: "push",
681 label: "Push",
682 disabled: false,
683 });
684 });
685​
686 it("buildMenuItems disables push and create PR when no commits are ahead", () => {
687 const items = buildMenuItems(status({ hasUpstream: false, pr: null, aheadCount: 0 }), false);
688 assert.deepEqual(items, [
689 {
690 id: "commit",
691 label: "Commit",
692 disabled: true,
693 icon: "commit",
694 kind: "open_dialog",
695 dialogAction: "commit",
696 },
697 {
698 id: "push",
699 label: "Push",
700 disabled: true,
701 icon: "push",
702 kind: "open_dialog",
703 dialogAction: "push",
704 },
705 {
706 id: "pr",
707 label: "Create PR",
708 disabled: true,
709 icon: "pr",
710 kind: "open_dialog",
711 dialogAction: "create_pr",
712 },
713 ]);
714 });
715​
716 it("resolveQuickAction runs push and create PR when no upstream and commits are ahead", () => {
717 const quick = resolveQuickAction(
718 status({
719 hasUpstream: false,
720 aheadCount: 2,
721 pr: null,
722 }),
723 false,
724 );
725 assert.deepInclude(quick, {
726 kind: "run_action",
727 action: "create_pr",
728 label: "Push & create PR",
729 disabled: false,
730 });
731 });
732​
733 it("resolveQuickAction publishes when no origin remote exists", () => {
734 const quick = resolveQuickAction(
735 status({
736 hasUpstream: false,
737 aheadCount: 2,
738 pr: null,
739 }),
740 false,
741 false,
742 false,
743 );
744 assert.deepEqual(quick, {
745 kind: "open_publish",
746 label: "Publish repository",
747 disabled: false,
748 });
749 });
750​
751 it("buildMenuItems enables create PR when no upstream and commits are ahead", () => {
752 const items = buildMenuItems(status({ hasUpstream: false, pr: null, aheadCount: 2 }), false);
753 assert.deepEqual(items, [
754 {
755 id: "commit",
756 label: "Commit",
757 disabled: true,
758 icon: "commit",
759 kind: "open_dialog",
760 dialogAction: "commit",
761 },
762 {
763 id: "push",
764 label: "Push",
765 disabled: false,
766 icon: "push",
767 kind: "open_dialog",
768 dialogAction: "push",
769 },
770 {
771 id: "pr",
772 label: "Create PR",
773 disabled: false,
774 icon: "pr",
775 kind: "open_dialog",
776 dialogAction: "create_pr",
777 },
778 ]);
779 });
780​
781 it("buildMenuItems hides push and create PR when no origin remote exists", () => {
782 const items = buildMenuItems(
783 status({ hasUpstream: false, pr: null, aheadCount: 2 }),
784 false,
785 false,
786 );
787 assert.deepEqual(items, [
788 {
789 id: "commit",
790 label: "Commit",
791 disabled: true,
792 icon: "commit",
793 kind: "open_dialog",
794 dialogAction: "commit",
795 },
796 ]);
797 });
798​
799 it("resolveQuickAction is disabled on default ref when no upstream exists and no commits are ahead", () => {
800 const quick = resolveQuickAction(
801 status({
802 refName: "main",
803 hasUpstream: false,
804 aheadCount: 0,
805 pr: null,
806 }),
807 false,
808 true,
809 );
810 assert.deepInclude(quick, {
811 kind: "show_hint",
812 label: "Push",
813 hint: "No local commits to push.",
814 disabled: true,
815 });
816 });
817​
818 it("resolveQuickAction uses push-only on default ref when no upstream exists and commits are ahead", () => {
819 const quick = resolveQuickAction(
820 status({
821 refName: "main",
822 hasUpstream: false,
823 aheadCount: 1,
824 pr: null,
825 }),
826 false,
827 true,
828 );
829 assert.deepInclude(quick, {
830 kind: "run_action",
831 action: "commit_push",
832 label: "Push",
833 disabled: false,
834 });
835 });
836​
837 it("buildMenuItems still disables push and create PR when ref is behind", () => {
838 const items = buildMenuItems(
839 status({
840 hasUpstream: false,
841 behindCount: 1,
842 aheadCount: 0,
843 pr: null,
844 }),
845 false,
846 );
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: true,
860 icon: "push",
861 kind: "open_dialog",
862 dialogAction: "push",
863 },
864 {
865 id: "pr",
866 label: "Create PR",
867 disabled: true,
868 icon: "pr",
869 kind: "open_dialog",
870 dialogAction: "create_pr",
871 },
872 ]);
873 });
874});
875​
876describe("requiresDefaultBranchConfirmation", () => {
877 it("requires confirmation for push actions on default ref", () => {
878 assert.isFalse(requiresDefaultBranchConfirmation("commit", true));
879 assert.isTrue(requiresDefaultBranchConfirmation("push", true));
880 assert.isTrue(requiresDefaultBranchConfirmation("create_pr", true));
881 assert.isTrue(requiresDefaultBranchConfirmation("commit_push", true));
882 assert.isTrue(requiresDefaultBranchConfirmation("commit_push_pr", true));
883 assert.isFalse(requiresDefaultBranchConfirmation("commit_push", false));
884 assert.isFalse(requiresDefaultBranchConfirmation("push", false));
885 });
886});
887​
888describe("resolveDefaultBranchActionDialogCopy", () => {
889 it("uses push-only copy when pushing without a commit", () => {
890 const copy = resolveDefaultBranchActionDialogCopy({
891 action: "commit_push",
892 branchName: "main",
893 includesCommit: false,
894 });
895​
896 assert.deepEqual(copy, {
897 title: "Push to default ref?",
898 description:
899 '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.',
900 continueLabel: "Push to main",
901 });
902 });
903​
904 it("uses push-and-pr copy when creating a PR without a commit", () => {
905 const copy = resolveDefaultBranchActionDialogCopy({
906 action: "commit_push_pr",
907 branchName: "main",
908 includesCommit: false,
909 });
910​
911 assert.deepEqual(copy, {
912 title: "Push & create PR from default ref?",
913 description:
914 '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.',
915 continueLabel: "Push & create PR",
916 });
917 });
918​
919 it("keeps commit copy when the action includes a commit", () => {
920 const copy = resolveDefaultBranchActionDialogCopy({
921 action: "commit_push_pr",
922 branchName: "main",
923 includesCommit: true,
924 });
925​
926 assert.deepEqual(copy, {
927 title: "Commit, push & create PR from default ref?",
928 description:
929 '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.',
930 continueLabel: "Commit, push & create PR",
931 });
932 });
933});
934​
935describe("buildGitActionProgressStages", () => {
936 it("shows only push progress for explicit push actions", () => {
937 const stages = buildGitActionProgressStages({
938 action: "push",
939 hasCustomCommitMessage: false,
940 hasWorkingTreeChanges: false,
941 pushTarget: "origin/feature/test",
942 });
943 assert.deepEqual(stages, ["Pushing to origin/feature/test..."]);
944 });
945​
946 it("shows push and PR progress for create-pr actions that still need a push", () => {
947 const stages = buildGitActionProgressStages({
948 action: "create_pr",
949 hasCustomCommitMessage: false,
950 hasWorkingTreeChanges: false,
951 pushTarget: "origin/feature/test",
952 shouldPushBeforePr: true,
953 });
954 assert.deepEqual(stages, [
955 "Pushing to origin/feature/test...",
956 "Preparing PR...",
957 "Generating PR content...",
958 "Creating pull request...",
959 ]);
960 });
961​
962 it("shows only PR progress when create-pr can skip the push", () => {
963 const stages = buildGitActionProgressStages({
964 action: "create_pr",
965 hasCustomCommitMessage: false,
966 hasWorkingTreeChanges: false,
967 shouldPushBeforePr: false,
968 });
969 assert.deepEqual(stages, [
970 "Preparing PR...",
971 "Generating PR content...",
972 "Creating pull request...",
973 ]);
974 });
975​
976 it("includes commit stages for commit+push when working tree is dirty", () => {
977 const stages = buildGitActionProgressStages({
978 action: "commit_push",
979 hasCustomCommitMessage: false,
980 hasWorkingTreeChanges: true,
981 pushTarget: "origin/feature/test",
982 });
983 assert.deepEqual(stages, [
984 "Generating commit message...",
985 "Committing...",
986 "Pushing to origin/feature/test...",
987 ]);
988 });
989​
990 it("includes granular PR stages for commit+push+PR actions", () => {
991 const stages = buildGitActionProgressStages({
992 action: "commit_push_pr",
993 hasCustomCommitMessage: true,
994 hasWorkingTreeChanges: true,
995 pushTarget: "origin/feature/test",
996 });
997 assert.deepEqual(stages, [
998 "Committing...",
999 "Pushing to origin/feature/test...",
1000 "Preparing PR...",
1001 "Generating PR content...",
1002 "Creating pull request...",
1003 ]);
1004 });
1005});
1006​
1007describe("resolveThreadBranchUpdate", () => {
1008 it("returns a branch update when the action created a new branch", () => {
1009 const update = resolveThreadBranchUpdate({
1010 action: "commit_push_pr",
1011 branch: {
1012 status: "created",
1013 name: "feature/fix-toast-copy",
1014 },
1015 commit: {
1016 status: "created",
1017 commitSha: "89abcdef01234567",
1018 subject: "feat: add ref sync",
1019 },
1020 push: { status: "pushed", branch: "feature/fix-toast-copy" },
1021 pr: { status: "skipped_not_requested" },
1022 toast: {
1023 title: "Pushed 89abcde to origin/feature/fix-toast-copy",
1024 cta: { kind: "none" },
1025 },
1026 });
1027​
1028 assert.deepEqual(update, {
1029 branch: "feature/fix-toast-copy",
1030 });
1031 });
1032​
1033 it("returns null when the action stayed on the existing branch", () => {
1034 const update = resolveThreadBranchUpdate({
1035 action: "commit_push",
1036 branch: {
1037 status: "skipped_not_requested",
1038 },
1039 commit: {
1040 status: "created",
1041 commitSha: "89abcdef01234567",
1042 subject: "feat: add ref sync",
1043 },
1044 push: { status: "pushed", branch: "feature/fix-toast-copy" },
1045 pr: { status: "skipped_not_requested" },
1046 toast: {
1047 title: "Pushed 89abcde to origin/feature/fix-toast-copy",
1048 cta: { kind: "none" },
1049 },
1050 });
1051​
1052 assert.equal(update, null);
1053 });
1054});
1055​
1056describe("resolveLiveThreadBranchUpdate", () => {
1057 it("returns a branch update when live git status differs from stored thread metadata", () => {
1058 const update = resolveLiveThreadBranchUpdate({
1059 threadBranch: "feature/old-ref",
1060 gitStatus: status({ refName: "effect-atom" }),
1061 });
1062​
1063 assert.deepEqual(update, {
1064 branch: "effect-atom",
1065 });
1066 });
1067​
1068 it("returns null when live git status is unavailable", () => {
1069 const update = resolveLiveThreadBranchUpdate({
1070 threadBranch: "feature/old-ref",
1071 gitStatus: null,
1072 });
1073​
1074 assert.equal(update, null);
1075 });
1076​
1077 it("returns null when the stored thread ref already matches git status", () => {
1078 const update = resolveLiveThreadBranchUpdate({
1079 threadBranch: "effect-atom",
1080 gitStatus: status({ refName: "effect-atom" }),
1081 });
1082​
1083 assert.equal(update, null);
1084 });
1085​
1086 it("returns null when git status is detached HEAD but the thread already has a ref", () => {
1087 const update = resolveLiveThreadBranchUpdate({
1088 threadBranch: "effect-atom",
1089 gitStatus: status({ refName: null }),
1090 });
1091​
1092 assert.equal(update, null);
1093 });
1094​
1095 it("does not regress a semantic thread ref back to a temporary worktree ref", () => {
1096 const update = resolveLiveThreadBranchUpdate({
1097 threadBranch: "t3code/github-query-rate-limit",
1098 gitStatus: status({ refName: "t3code/bda76797" }),
1099 });
1100​
1101 assert.equal(update, null);
1102 });
1103});
1104​
1105describe("resolveAutoFeatureBranchName", () => {
1106 it("uses semantic preferred ref names when available", () => {
1107 const ref = resolveAutoFeatureBranchName(["main", "feature/other"], "fix toast copy");
1108 assert.equal(ref, "feature/fix-toast-copy");
1109 });
1110​
1111 it("normalizes preferred names that already include a ref namespace", () => {
1112 const ref = resolveAutoFeatureBranchName(["main"], "feature/refine-toolbar-actions");
1113 assert.equal(ref, "feature/refine-toolbar-actions");
1114 });
1115​
1116 it("increments suffix when the preferred ref name already exists", () => {
1117 const ref = resolveAutoFeatureBranchName(
1118 ["main", "feature/fix-toast-copy", "feature/fix-toast-copy-2"],
1119 "fix toast copy",
1120 );
1121 assert.equal(ref, "feature/fix-toast-copy-3");
1122 });
1123​
1124 it("treats existing ref names as case-insensitive for collision checks", () => {
1125 const ref = resolveAutoFeatureBranchName(["Feature/Ticket-1"], "feature/ticket-1");
1126 assert.equal(ref, "feature/ticket-1-2");
1127 });
1128​
1129 it("falls back to feature/update when no preferred name is provided", () => {
1130 const ref = resolveAutoFeatureBranchName(["main"]);
1131 assert.equal(ref, "feature/update");
1132 });
1133});