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

GitActionsControl.logic.test.ts

1,248 lines33.1 KB

1import type { VcsStatusResult } from "@t3tools/contracts";
2import { assert, describe, it } from "vite-plus/test";
3import {
4 buildGitActionProgressStages,
5 buildMenuItems,
6 formatGitActionElapsed,
7 requiresDefaultBranchConfirmation,
8 resolveAutoFeatureBranchName,
9 resolveDefaultBranchActionDialogCopy,
10 resolveGitActionProgressPresentation,
11 resolveGitActionResultToastTiming,
12 resolveLiveThreadBranchUpdate,
13 resolveQuickAction,
14 resolveThreadBranchUpdate,
15 resolveThreadBranchMetadataPatch,
16} from "./GitActionsControl.logic";
17​
18function status(overrides: Partial<VcsStatusResult> = {}): VcsStatusResult {
19 return {
20 isRepo: true,
21 hasPrimaryRemote: true,
22 isDefaultRef: false,
23 refName: "feature/test",
24 hasWorkingTreeChanges: false,
25 workingTree: {
26 files: [],
27 insertions: 0,
28 deletions: 0,
29 },
30 hasUpstream: true,
31 aheadCount: 0,
32 behindCount: 0,
33 pr: null,
34 ...overrides,
35 };
37​
38describe("git action progress presentation", () => {
39 it("keeps the phase on the first row and hook output on the second", () => {
40 assert.deepEqual(
41 resolveGitActionProgressPresentation({
42 isRunning: true,
43 operation: "run_change_request",
44 currentLabel: "Running pre-commit...",
45 lastOutputLine: "Checking formatting and lint rules",
46 phaseStartedAtMs: 1_000,
47 hookStartedAtMs: 2_000,
48 }),
49 {
50 status: "Running pre-commit...",
51 output: "Checking formatting and lint rules",
52 startedAtMs: 2_000,
53 },
54 );
55 });
56​
57 it("omits empty output and supplies a brief startup label", () => {
58 assert.deepEqual(
59 resolveGitActionProgressPresentation({
60 isRunning: true,
61 operation: "run_change_request",
62 currentLabel: "Running source control action",
63 lastOutputLine: " ",
64 phaseStartedAtMs: 1_000,
65 hookStartedAtMs: null,
66 }),
67 {
68 status: "Starting source control action...",
69 output: null,
70 startedAtMs: 1_000,
71 },
72 );
73 });
74​
75 it("presents pull progress inline without a second row", () => {
76 assert.deepEqual(
77 resolveGitActionProgressPresentation({
78 isRunning: true,
79 operation: "pull",
80 currentLabel: "Pulling latest changes...",
81 lastOutputLine: null,
82 phaseStartedAtMs: 1_000,
83 hookStartedAtMs: null,
84 }),
85 {
86 status: "Pulling latest changes...",
87 output: null,
88 startedAtMs: 1_000,
89 },
90 );
91 });
92​
93 it("does not present unrelated or completed actions", () => {
94 const input = {
95 isRunning: true,
96 operation: "publish_repository",
97 currentLabel: "Publishing repository",
98 lastOutputLine: null,
99 phaseStartedAtMs: 1_000,
100 hookStartedAtMs: null,
101 };
102​
103 assert.isNull(resolveGitActionProgressPresentation(input));
104 assert.isNull(resolveGitActionProgressPresentation({ ...input, isRunning: false }));
105 });
106​
107 it("formats compact elapsed time without allowing negative values", () => {
108 assert.isNull(formatGitActionElapsed(null, 10_000));
109 assert.equal(formatGitActionElapsed(10_000, 9_000), "0s");
110 assert.equal(formatGitActionElapsed(10_000, 14_900), "4s");
111 assert.equal(formatGitActionElapsed(10_000, 75_000), "1m 5s");
112 });
113});
114​
115describe("git action result toast timing", () => {
116 it("keeps errors sticky and dismisses successes after visible time", () => {
117 assert.deepEqual(resolveGitActionResultToastTiming("error"), {
118 timeout: 0,
119 dismissAfterVisibleMs: null,
120 });
121 assert.deepEqual(resolveGitActionResultToastTiming("success"), {
122 timeout: 0,
123 dismissAfterVisibleMs: 10_000,
124 });
125 });
126});
127​
128describe("when: ref is clean and has an open PR", () => {
129 it("resolveQuickAction opens the existing PR", () => {
130 const quick = resolveQuickAction(
131 status({
132 pr: {
133 number: 10,
134 title: "Open PR",
135 url: "https://example.com/pr/10",
136 baseRef: "main",
137 headRef: "feature/test",
138 state: "open",
139 },
140 }),
141 false,
142 );
143 assert.deepInclude(quick, { kind: "open_pr", label: "View PR", disabled: false });
144 });
145​
146 it("buildMenuItems disables commit/push and enables open PR", () => {
147 const items = buildMenuItems(
148 status({
149 pr: {
150 number: 11,
151 title: "Existing PR",
152 url: "https://example.com/pr/11",
153 baseRef: "main",
154 headRef: "feature/test",
155 state: "open",
156 },
157 }),
158 false,
159 );
160 assert.deepEqual(items, [
161 {
162 id: "commit",
163 label: "Commit",
164 disabled: true,
165 icon: "commit",
166 kind: "open_dialog",
167 dialogAction: "commit",
168 },
169 {
170 id: "push",
171 label: "Push",
172 disabled: true,
173 icon: "push",
174 kind: "open_dialog",
175 dialogAction: "push",
176 },
177 {
178 id: "pr",
179 label: "View PR",
180 disabled: false,
181 icon: "pr",
182 kind: "open_pr",
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 keeps open PR available", () => {
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 id: "pr",
300 label: "View PR",
301 disabled: false,
302 icon: "pr",
303 kind: "open_pr",
304 },
305 ]);
306 });
307});
308​
309describe("when: ref is clean, ahead, and has no open PR", () => {
310 it("resolveQuickAction pushes and creates a PR", () => {
311 const quick = resolveQuickAction(status({ aheadCount: 2, pr: null }), false);
312 assert.deepInclude(quick, {
313 kind: "run_action",
314 action: "create_pr",
315 label: "Push & create PR",
316 });
317 });
318​
319 it("buildMenuItems enables push and create PR, with commit disabled", () => {
320 const items = buildMenuItems(status({ aheadCount: 2, pr: null }), false);
321 assert.deepEqual(items, [
322 {
323 id: "commit",
324 label: "Commit",
325 disabled: true,
326 icon: "commit",
327 kind: "open_dialog",
328 dialogAction: "commit",
329 },
330 {
331 id: "push",
332 label: "Push",
333 disabled: false,
334 icon: "push",
335 kind: "open_dialog",
336 dialogAction: "push",
337 },
338 {
339 id: "pr",
340 label: "Create PR",
341 disabled: false,
342 icon: "pr",
343 kind: "open_dialog",
344 dialogAction: "create_pr",
345 },
346 ]);
347 });
348});
349​
350describe("when: source control provider uses merge requests", () => {
351 it("uses GitLab MR terminology in quick actions and menu items", () => {
352 const gitlabStatus = status({
353 aheadCount: 2,
354 sourceControlProvider: {
355 kind: "gitlab",
356 name: "GitLab",
357 baseUrl: "https://gitlab.com",
358 },
359 });
360​
361 const quick = resolveQuickAction(gitlabStatus, false);
362 const items = buildMenuItems(gitlabStatus, false);
363​
364 assert.deepInclude(quick, {
365 kind: "run_action",
366 action: "create_pr",
367 label: "Push & create MR",
368 });
369 assert.deepInclude(items[2], {
370 id: "pr",
371 label: "Create MR",
372 });
373 });
374});
375​
376describe("when: ref is clean, up to date, and has no open PR", () => {
377 it("enables create PR when synced with upstream but ahead of default", () => {
378 const syncedFeature = status({
379 aheadCount: 0,
380 behindCount: 0,
381 aheadOfDefaultCount: 1,
382 pr: null,
383 });
384​
385 const quick = resolveQuickAction(syncedFeature, false);
386 assert.deepInclude(quick, {
387 label: "Create PR",
388 disabled: false,
389 kind: "run_action",
390 action: "create_pr",
391 });
392​
393 const items = buildMenuItems(syncedFeature, false);
394 assert.equal(items.find((item) => item.id === "pr")?.disabled, false);
395 });
396​
397 it("resolveQuickAction returns disabled no-action state", () => {
398 const quick = resolveQuickAction(
399 status({ aheadCount: 0, behindCount: 0, hasWorkingTreeChanges: false, pr: null }),
400 false,
401 );
402 assert.deepInclude(quick, { kind: "show_hint", label: "Commit", disabled: true });
403 });
404​
405 it("buildMenuItems disables commit, push, and create PR", () => {
406 const items = buildMenuItems(status({ aheadCount: 0, behindCount: 0, pr: null }), false);
407 assert.deepEqual(items, [
408 {
409 id: "commit",
410 label: "Commit",
411 disabled: true,
412 icon: "commit",
413 kind: "open_dialog",
414 dialogAction: "commit",
415 },
416 {
417 id: "push",
418 label: "Push",
419 disabled: true,
420 icon: "push",
421 kind: "open_dialog",
422 dialogAction: "push",
423 },
424 {
425 id: "pr",
426 label: "Create PR",
427 disabled: true,
428 icon: "pr",
429 kind: "open_dialog",
430 dialogAction: "create_pr",
431 },
432 ]);
433 });
434});
435​
436describe("when: ref is behind upstream", () => {
437 it("resolveQuickAction returns pull", () => {
438 const quick = resolveQuickAction(status({ behindCount: 2 }), false);
439 assert.deepInclude(quick, { kind: "run_pull", label: "Pull", disabled: false });
440 });
441​
442 it("buildMenuItems disables push and create PR", () => {
443 const items = buildMenuItems(status({ behindCount: 1, pr: null }), false);
444 assert.deepEqual(items, [
445 {
446 id: "commit",
447 label: "Commit",
448 disabled: true,
449 icon: "commit",
450 kind: "open_dialog",
451 dialogAction: "commit",
452 },
453 {
454 id: "push",
455 label: "Push",
456 disabled: true,
457 icon: "push",
458 kind: "open_dialog",
459 dialogAction: "push",
460 },
461 {
462 id: "pr",
463 label: "Create PR",
464 disabled: true,
465 icon: "pr",
466 kind: "open_dialog",
467 dialogAction: "create_pr",
468 },
469 ]);
470 });
471});
472​
473describe("when: ref has diverged from upstream", () => {
474 it("resolveQuickAction returns a disabled sync hint", () => {
475 const quick = resolveQuickAction(status({ aheadCount: 2, behindCount: 1 }), false);
476 assert.deepEqual(quick, {
477 label: "Sync ref",
478 disabled: true,
479 kind: "show_hint",
480 hint: "Branch has diverged from upstream. Rebase/merge first.",
481 });
482 });
483});
484​
485describe("when: working tree has local changes", () => {
486 it("resolveQuickAction returns commit, push, and create PR", () => {
487 const quick = resolveQuickAction(status({ hasWorkingTreeChanges: true }), false);
488 assert.deepInclude(quick, {
489 kind: "run_action",
490 action: "commit_push_pr",
491 label: "Commit, push & PR",
492 });
493 });
494​
495 it("resolveQuickAction falls back to commit when no origin remote exists", () => {
496 const quick = resolveQuickAction(
497 status({ hasWorkingTreeChanges: true, hasUpstream: false }),
498 false,
499 false,
500 false,
501 );
502 assert.deepInclude(quick, {
503 kind: "run_action",
504 action: "commit",
505 label: "Commit",
506 disabled: false,
507 });
508 });
509​
510 it("resolveQuickAction returns commit and push when open PR exists", () => {
511 const quick = resolveQuickAction(
512 status({
513 hasWorkingTreeChanges: true,
514 pr: {
515 number: 16,
516 title: "Existing PR",
517 url: "https://example.com/pr/16",
518 baseRef: "main",
519 headRef: "feature/test",
520 state: "open",
521 },
522 }),
523 false,
524 );
525 assert.deepInclude(quick, {
526 kind: "run_action",
527 action: "commit_push",
528 label: "Commit & push",
529 });
530 });
531​
532 it("buildMenuItems enables commit and disables push and PR", () => {
533 const items = buildMenuItems(status({ hasWorkingTreeChanges: true }), false);
534 assert.deepEqual(items, [
535 {
536 id: "commit",
537 label: "Commit",
538 disabled: false,
539 icon: "commit",
540 kind: "open_dialog",
541 dialogAction: "commit",
542 },
543 {
544 id: "push",
545 label: "Push",
546 disabled: true,
547 icon: "push",
548 kind: "open_dialog",
549 dialogAction: "push",
550 },
551 {
552 id: "pr",
553 label: "Create PR",
554 disabled: true,
555 icon: "pr",
556 kind: "open_dialog",
557 dialogAction: "create_pr",
558 },
559 ]);
560 });
561​
562 it("buildMenuItems enables push for ahead commits while local changes remain uncommitted", () => {
563 const items = buildMenuItems(
564 status({
565 refName: "feature/test",
566 hasWorkingTreeChanges: true,
567 aheadCount: 1,
568 workingTree: {
569 files: [{ path: ".vercel/project.json", insertions: 1, deletions: 0 }],
570 insertions: 1,
571 deletions: 0,
572 },
573 }),
574 false,
575 );
576 assert.deepEqual(items, [
577 {
578 id: "commit",
579 label: "Commit",
580 disabled: false,
581 icon: "commit",
582 kind: "open_dialog",
583 dialogAction: "commit",
584 },
585 {
586 id: "push",
587 label: "Push",
588 disabled: false,
589 icon: "push",
590 kind: "open_dialog",
591 dialogAction: "push",
592 },
593 {
594 id: "pr",
595 label: "Create PR",
596 disabled: true,
597 icon: "pr",
598 kind: "open_dialog",
599 dialogAction: "create_pr",
600 },
601 ]);
602 });
603});
604​
605describe("when: on default ref without open PR", () => {
606 it("resolveQuickAction returns commit and push when local changes exist", () => {
607 const quick = resolveQuickAction(
608 status({ refName: "main", hasWorkingTreeChanges: true }),
609 false,
610 true,
611 );
612 assert.deepInclude(quick, {
613 kind: "run_action",
614 action: "commit_push",
615 label: "Commit & push",
616 disabled: false,
617 });
618 });
619​
620 it("resolveQuickAction returns push when ref is ahead", () => {
621 const quick = resolveQuickAction(
622 status({ refName: "main", aheadCount: 2, pr: null }),
623 false,
624 true,
625 );
626 assert.deepInclude(quick, {
627 kind: "run_action",
628 action: "commit_push",
629 label: "Push",
630 disabled: false,
631 });
632 });
633});
634​
635describe("when: working tree has local changes and ref is behind upstream", () => {
636 it("resolveQuickAction still prefers commit, push, and create PR", () => {
637 const quick = resolveQuickAction(
638 status({ hasWorkingTreeChanges: true, behindCount: 1 }),
639 false,
640 );
641 assert.deepInclude(quick, {
642 kind: "run_action",
643 action: "commit_push_pr",
644 label: "Commit, push & PR",
645 });
646 });
647​
648 it("buildMenuItems enables commit and keeps push and PR disabled", () => {
649 const items = buildMenuItems(status({ hasWorkingTreeChanges: true, behindCount: 2 }), false);
650 assert.deepEqual(items, [
651 {
652 id: "commit",
653 label: "Commit",
654 disabled: false,
655 icon: "commit",
656 kind: "open_dialog",
657 dialogAction: "commit",
658 },
659 {
660 id: "push",
661 label: "Push",
662 disabled: true,
663 icon: "push",
664 kind: "open_dialog",
665 dialogAction: "push",
666 },
667 {
668 id: "pr",
669 label: "Create PR",
670 disabled: true,
671 icon: "pr",
672 kind: "open_dialog",
673 dialogAction: "create_pr",
674 },
675 ]);
676 });
677});
678​
679describe("when: HEAD is detached and there are no local changes", () => {
680 it("resolveQuickAction shows detached head hint", () => {
681 const quick = resolveQuickAction(
682 status({ refName: null, hasWorkingTreeChanges: false, hasUpstream: false }),
683 false,
684 );
685 assert.deepInclude(quick, { kind: "show_hint", label: "Commit", disabled: true });
686 });
687​
688 it("buildMenuItems keeps commit, push, and PR disabled", () => {
689 const items = buildMenuItems(status({ refName: null, hasWorkingTreeChanges: false }), false);
690 assert.deepEqual(items, [
691 {
692 id: "commit",
693 label: "Commit",
694 disabled: true,
695 icon: "commit",
696 kind: "open_dialog",
697 dialogAction: "commit",
698 },
699 {
700 id: "push",
701 label: "Push",
702 disabled: true,
703 icon: "push",
704 kind: "open_dialog",
705 dialogAction: "push",
706 },
707 {
708 id: "pr",
709 label: "Create PR",
710 disabled: true,
711 icon: "pr",
712 kind: "open_dialog",
713 dialogAction: "create_pr",
714 },
715 ]);
716 });
717});
718​
719describe("when: ref has no upstream configured", () => {
720 it("resolveQuickAction is disabled when clean, no upstream, and no local commits are ahead", () => {
721 const quick = resolveQuickAction(
722 status({ hasUpstream: false, pr: null, aheadCount: 0 }),
723 false,
724 );
725 assert.deepInclude(quick, {
726 kind: "show_hint",
727 label: "Push",
728 hint: "No local commits to push.",
729 disabled: true,
730 });
731 });
732​
733 it("resolveQuickAction opens PR when clean, no upstream, no local commits are ahead, and PR exists", () => {
734 const quick = resolveQuickAction(
735 status({
736 hasUpstream: false,
737 aheadCount: 0,
738 pr: {
739 number: 14,
740 title: "Existing PR",
741 url: "https://example.com/pr/14",
742 baseRef: "main",
743 headRef: "feature/test",
744 state: "open",
745 },
746 }),
747 false,
748 );
749 assert.deepInclude(quick, {
750 kind: "open_pr",
751 label: "View PR",
752 disabled: false,
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("buildGitActionProgressStages", () => {
1030 it("shows only push progress for explicit push actions", () => {
1031 const stages = buildGitActionProgressStages({
1032 action: "push",
1033 hasCustomCommitMessage: false,
1034 hasWorkingTreeChanges: false,
1035 pushTarget: "origin/feature/test",
1036 });
1037 assert.deepEqual(stages, ["Pushing to origin/feature/test..."]);
1038 });
1039​
1040 it("shows push and PR progress for create-pr actions that still need a push", () => {
1041 const stages = buildGitActionProgressStages({
1042 action: "create_pr",
1043 hasCustomCommitMessage: false,
1044 hasWorkingTreeChanges: false,
1045 pushTarget: "origin/feature/test",
1046 shouldPushBeforePr: true,
1047 });
1048 assert.deepEqual(stages, [
1049 "Pushing to origin/feature/test...",
1050 "Preparing PR...",
1051 "Generating PR content...",
1052 "Creating pull request...",
1053 ]);
1054 });
1055​
1056 it("shows only PR progress when create-pr can skip the push", () => {
1057 const stages = buildGitActionProgressStages({
1058 action: "create_pr",
1059 hasCustomCommitMessage: false,
1060 hasWorkingTreeChanges: false,
1061 shouldPushBeforePr: false,
1062 });
1063 assert.deepEqual(stages, [
1064 "Preparing PR...",
1065 "Generating PR content...",
1066 "Creating pull request...",
1067 ]);
1068 });
1069​
1070 it("includes commit stages for commit+push when working tree is dirty", () => {
1071 const stages = buildGitActionProgressStages({
1072 action: "commit_push",
1073 hasCustomCommitMessage: false,
1074 hasWorkingTreeChanges: true,
1075 pushTarget: "origin/feature/test",
1076 });
1077 assert.deepEqual(stages, [
1078 "Generating commit message...",
1079 "Committing...",
1080 "Pushing to origin/feature/test...",
1081 ]);
1082 });
1083​
1084 it("includes granular PR stages for commit+push+PR actions", () => {
1085 const stages = buildGitActionProgressStages({
1086 action: "commit_push_pr",
1087 hasCustomCommitMessage: true,
1088 hasWorkingTreeChanges: true,
1089 pushTarget: "origin/feature/test",
1090 });
1091 assert.deepEqual(stages, [
1092 "Committing...",
1093 "Pushing to origin/feature/test...",
1094 "Preparing PR...",
1095 "Generating PR content...",
1096 "Creating pull request...",
1097 ]);
1098 });
1099});
1100​
1101describe("resolveThreadBranchUpdate", () => {
1102 it("returns a branch update when the action created a new branch", () => {
1103 const update = resolveThreadBranchUpdate({
1104 action: "commit_push_pr",
1105 branch: {
1106 status: "created",
1107 name: "feature/fix-toast-copy",
1108 },
1109 commit: {
1110 status: "created",
1111 commitSha: "89abcdef01234567",
1112 subject: "feat: add ref sync",
1113 },
1114 push: { status: "pushed", branch: "feature/fix-toast-copy" },
1115 pr: { status: "skipped_not_requested" },
1116 toast: {
1117 title: "Pushed 89abcde to origin/feature/fix-toast-copy",
1118 cta: { kind: "none" },
1119 },
1120 });
1121​
1122 assert.deepEqual(update, {
1123 branch: "feature/fix-toast-copy",
1124 });
1125 });
1126​
1127 it("returns null when the action stayed on the existing branch", () => {
1128 const update = resolveThreadBranchUpdate({
1129 action: "commit_push",
1130 branch: {
1131 status: "skipped_not_requested",
1132 },
1133 commit: {
1134 status: "created",
1135 commitSha: "89abcdef01234567",
1136 subject: "feat: add ref sync",
1137 },
1138 push: { status: "pushed", branch: "feature/fix-toast-copy" },
1139 pr: { status: "skipped_not_requested" },
1140 toast: {
1141 title: "Pushed 89abcde to origin/feature/fix-toast-copy",
1142 cta: { kind: "none" },
1143 },
1144 });
1145​
1146 assert.equal(update, null);
1147 });
1148});
1149​
1150describe("resolveLiveThreadBranchUpdate", () => {
1151 it("returns a branch update when live git status differs from stored thread metadata", () => {
1152 const update = resolveLiveThreadBranchUpdate({
1153 threadBranch: "feature/old-ref",
1154 gitStatus: status({ refName: "effect-atom" }),
1155 });
1156​
1157 assert.deepEqual(update, {
1158 branch: "effect-atom",
1159 });
1160 });
1161​
1162 it("returns null when live git status is unavailable", () => {
1163 const update = resolveLiveThreadBranchUpdate({
1164 threadBranch: "feature/old-ref",
1165 gitStatus: null,
1166 });
1167​
1168 assert.equal(update, null);
1169 });
1170​
1171 it("returns null when the stored thread ref already matches git status", () => {
1172 const update = resolveLiveThreadBranchUpdate({
1173 threadBranch: "effect-atom",
1174 gitStatus: status({ refName: "effect-atom" }),
1175 });
1176​
1177 assert.equal(update, null);
1178 });
1179​
1180 it("returns null when git status is detached HEAD but the thread already has a ref", () => {
1181 const update = resolveLiveThreadBranchUpdate({
1182 threadBranch: "effect-atom",
1183 gitStatus: status({ refName: null }),
1184 });
1185​
1186 assert.equal(update, null);
1187 });
1188​
1189 it("does not regress a semantic thread ref back to a temporary worktree ref", () => {
1190 const update = resolveLiveThreadBranchUpdate({
1191 threadBranch: "t3code/github-query-rate-limit",
1192 gitStatus: status({ refName: "t3code/bda76797" }),
1193 });
1194​
1195 assert.equal(update, null);
1196 });
1197​
1198 it("allows a temporary worktree ref to reconcile to a semantic branch", () => {
1199 const update = resolveLiveThreadBranchUpdate({
1200 threadBranch: "t3code/a9628676",
1201 gitStatus: status({ refName: "feature/diff-panel-toggle" }),
1202 });
1203​
1204 assert.deepEqual(update, { branch: "feature/diff-panel-toggle" });
1205 });
1206});
1207​
1208describe("resolveThreadBranchMetadataPatch", () => {
1209 it("does not overwrite worktree metadata while reconciling a branch", () => {
1210 assert.deepEqual(
1211 resolveThreadBranchMetadataPatch("feature/current-ref", "feature/previous-ref"),
1213 branch: "feature/current-ref",
1214 expectedBranch: "feature/previous-ref",
1215 },
1216 );
1217 });
1218});
1219​
1220describe("resolveAutoFeatureBranchName", () => {
1221 it("uses semantic preferred ref names when available", () => {
1222 const ref = resolveAutoFeatureBranchName(["main", "feature/other"], "fix toast copy");
1223 assert.equal(ref, "feature/fix-toast-copy");
1224 });
1225​
1226 it("normalizes preferred names that already include a ref namespace", () => {
1227 const ref = resolveAutoFeatureBranchName(["main"], "feature/refine-toolbar-actions");
1228 assert.equal(ref, "feature/refine-toolbar-actions");
1229 });
1230​
1231 it("increments suffix when the preferred ref name already exists", () => {
1232 const ref = resolveAutoFeatureBranchName(
1233 ["main", "feature/fix-toast-copy", "feature/fix-toast-copy-2"],
1234 "fix toast copy",
1235 );
1236 assert.equal(ref, "feature/fix-toast-copy-3");
1237 });
1238​
1239 it("treats existing ref names as case-insensitive for collision checks", () => {
1240 const ref = resolveAutoFeatureBranchName(["Feature/Ticket-1"], "feature/ticket-1");
1241 assert.equal(ref, "feature/ticket-1-2");
1242 });
1243​
1244 it("falls back to feature/update when no preferred name is provided", () => {
1245 const ref = resolveAutoFeatureBranchName(["main"]);
1246 assert.equal(ref, "feature/update");
1247 });
1248});