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

GitActionsControl.logic.test.ts

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