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

GitActionsControl.logic.test.ts

1,240 lines33.0 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", () => {
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​
388 it("resolveQuickAction returns disabled no-action state", () => {
389 const quick = resolveQuickAction(
390 status({ aheadCount: 0, behindCount: 0, hasWorkingTreeChanges: false, pr: null }),
391 false,
392 );
393 assert.deepInclude(quick, { kind: "show_hint", label: "Commit", disabled: true });
394 });
395​
396 it("buildMenuItems disables commit, push, and create PR", () => {
397 const items = buildMenuItems(status({ aheadCount: 0, behindCount: 0, pr: null }), false);
398 assert.deepEqual(items, [
399 {
400 id: "commit",
401 label: "Commit",
402 disabled: true,
403 icon: "commit",
404 kind: "open_dialog",
405 dialogAction: "commit",
406 },
407 {
408 id: "push",
409 label: "Push",
410 disabled: true,
411 icon: "push",
412 kind: "open_dialog",
413 dialogAction: "push",
414 },
415 {
416 id: "pr",
417 label: "Create PR",
418 disabled: true,
419 icon: "pr",
420 kind: "open_dialog",
421 dialogAction: "create_pr",
422 },
423 ]);
424 });
425});
426​
427describe("when: ref is behind upstream", () => {
428 it("resolveQuickAction returns pull", () => {
429 const quick = resolveQuickAction(status({ behindCount: 2 }), false);
430 assert.deepInclude(quick, { kind: "run_pull", label: "Pull", disabled: false });
431 });
432​
433 it("buildMenuItems disables push and create PR", () => {
434 const items = buildMenuItems(status({ behindCount: 1, pr: null }), false);
435 assert.deepEqual(items, [
436 {
437 id: "commit",
438 label: "Commit",
439 disabled: true,
440 icon: "commit",
441 kind: "open_dialog",
442 dialogAction: "commit",
443 },
444 {
445 id: "push",
446 label: "Push",
447 disabled: true,
448 icon: "push",
449 kind: "open_dialog",
450 dialogAction: "push",
451 },
452 {
453 id: "pr",
454 label: "Create PR",
455 disabled: true,
456 icon: "pr",
457 kind: "open_dialog",
458 dialogAction: "create_pr",
459 },
460 ]);
461 });
462});
463​
464describe("when: ref has diverged from upstream", () => {
465 it("resolveQuickAction returns a disabled sync hint", () => {
466 const quick = resolveQuickAction(status({ aheadCount: 2, behindCount: 1 }), false);
467 assert.deepEqual(quick, {
468 label: "Sync ref",
469 disabled: true,
470 kind: "show_hint",
471 hint: "Branch has diverged from upstream. Rebase/merge first.",
472 });
473 });
474});
475​
476describe("when: working tree has local changes", () => {
477 it("resolveQuickAction returns commit, push, and create PR", () => {
478 const quick = resolveQuickAction(status({ hasWorkingTreeChanges: true }), false);
479 assert.deepInclude(quick, {
480 kind: "run_action",
481 action: "commit_push_pr",
482 label: "Commit, push & PR",
483 });
484 });
485​
486 it("resolveQuickAction falls back to commit when no origin remote exists", () => {
487 const quick = resolveQuickAction(
488 status({ hasWorkingTreeChanges: true, hasUpstream: false }),
489 false,
490 false,
491 false,
492 );
493 assert.deepInclude(quick, {
494 kind: "run_action",
495 action: "commit",
496 label: "Commit",
497 disabled: false,
498 });
499 });
500​
501 it("resolveQuickAction returns commit and push when open PR exists", () => {
502 const quick = resolveQuickAction(
503 status({
504 hasWorkingTreeChanges: true,
505 pr: {
506 number: 16,
507 title: "Existing PR",
508 url: "https://example.com/pr/16",
509 baseRef: "main",
510 headRef: "feature/test",
511 state: "open",
512 },
513 }),
514 false,
515 );
516 assert.deepInclude(quick, {
517 kind: "run_action",
518 action: "commit_push",
519 label: "Commit & push",
520 });
521 });
522​
523 it("buildMenuItems enables commit and disables push and PR", () => {
524 const items = buildMenuItems(status({ hasWorkingTreeChanges: true }), false);
525 assert.deepEqual(items, [
526 {
527 id: "commit",
528 label: "Commit",
529 disabled: false,
530 icon: "commit",
531 kind: "open_dialog",
532 dialogAction: "commit",
533 },
534 {
535 id: "push",
536 label: "Push",
537 disabled: true,
538 icon: "push",
539 kind: "open_dialog",
540 dialogAction: "push",
541 },
542 {
543 id: "pr",
544 label: "Create PR",
545 disabled: true,
546 icon: "pr",
547 kind: "open_dialog",
548 dialogAction: "create_pr",
549 },
550 ]);
551 });
552​
553 it("buildMenuItems enables push for ahead commits while local changes remain uncommitted", () => {
554 const items = buildMenuItems(
555 status({
556 refName: "feature/test",
557 hasWorkingTreeChanges: true,
558 aheadCount: 1,
559 workingTree: {
560 files: [{ path: ".vercel/project.json", insertions: 1, deletions: 0 }],
561 insertions: 1,
562 deletions: 0,
563 },
564 }),
565 false,
566 );
567 assert.deepEqual(items, [
568 {
569 id: "commit",
570 label: "Commit",
571 disabled: false,
572 icon: "commit",
573 kind: "open_dialog",
574 dialogAction: "commit",
575 },
576 {
577 id: "push",
578 label: "Push",
579 disabled: false,
580 icon: "push",
581 kind: "open_dialog",
582 dialogAction: "push",
583 },
584 {
585 id: "pr",
586 label: "Create PR",
587 disabled: true,
588 icon: "pr",
589 kind: "open_dialog",
590 dialogAction: "create_pr",
591 },
592 ]);
593 });
594});
595​
596describe("when: on default ref without open PR", () => {
597 it("resolveQuickAction returns commit and push when local changes exist", () => {
598 const quick = resolveQuickAction(
599 status({ refName: "main", hasWorkingTreeChanges: true }),
600 false,
601 true,
602 );
603 assert.deepInclude(quick, {
604 kind: "run_action",
605 action: "commit_push",
606 label: "Commit & push",
607 disabled: false,
608 });
609 });
610​
611 it("resolveQuickAction returns push when ref is ahead", () => {
612 const quick = resolveQuickAction(
613 status({ refName: "main", aheadCount: 2, pr: null }),
614 false,
615 true,
616 );
617 assert.deepInclude(quick, {
618 kind: "run_action",
619 action: "commit_push",
620 label: "Push",
621 disabled: false,
622 });
623 });
624});
625​
626describe("when: working tree has local changes and ref is behind upstream", () => {
627 it("resolveQuickAction still prefers commit, push, and create PR", () => {
628 const quick = resolveQuickAction(
629 status({ hasWorkingTreeChanges: true, behindCount: 1 }),
630 false,
631 );
632 assert.deepInclude(quick, {
633 kind: "run_action",
634 action: "commit_push_pr",
635 label: "Commit, push & PR",
636 });
637 });
638​
639 it("buildMenuItems enables commit and keeps push and PR disabled", () => {
640 const items = buildMenuItems(status({ hasWorkingTreeChanges: true, behindCount: 2 }), false);
641 assert.deepEqual(items, [
642 {
643 id: "commit",
644 label: "Commit",
645 disabled: false,
646 icon: "commit",
647 kind: "open_dialog",
648 dialogAction: "commit",
649 },
650 {
651 id: "push",
652 label: "Push",
653 disabled: true,
654 icon: "push",
655 kind: "open_dialog",
656 dialogAction: "push",
657 },
658 {
659 id: "pr",
660 label: "Create PR",
661 disabled: true,
662 icon: "pr",
663 kind: "open_dialog",
664 dialogAction: "create_pr",
665 },
666 ]);
667 });
668});
669​
670describe("when: HEAD is detached and there are no local changes", () => {
671 it("resolveQuickAction shows detached head hint", () => {
672 const quick = resolveQuickAction(
673 status({ refName: null, hasWorkingTreeChanges: false, hasUpstream: false }),
674 false,
675 );
676 assert.deepInclude(quick, { kind: "show_hint", label: "Commit", disabled: true });
677 });
678​
679 it("buildMenuItems keeps commit, push, and PR disabled", () => {
680 const items = buildMenuItems(status({ refName: null, hasWorkingTreeChanges: false }), false);
681 assert.deepEqual(items, [
682 {
683 id: "commit",
684 label: "Commit",
685 disabled: true,
686 icon: "commit",
687 kind: "open_dialog",
688 dialogAction: "commit",
689 },
690 {
691 id: "push",
692 label: "Push",
693 disabled: true,
694 icon: "push",
695 kind: "open_dialog",
696 dialogAction: "push",
697 },
698 {
699 id: "pr",
700 label: "Create PR",
701 disabled: true,
702 icon: "pr",
703 kind: "open_dialog",
704 dialogAction: "create_pr",
705 },
706 ]);
707 });
708});
709​
710describe("when: ref has no upstream configured", () => {
711 it("resolveQuickAction is disabled when clean, no upstream, and no local commits are ahead", () => {
712 const quick = resolveQuickAction(
713 status({ hasUpstream: false, pr: null, aheadCount: 0 }),
714 false,
715 );
716 assert.deepInclude(quick, {
717 kind: "show_hint",
718 label: "Push",
719 hint: "No local commits to push.",
720 disabled: true,
721 });
722 });
723​
724 it("resolveQuickAction rests disabled when clean, no upstream, no local commits are ahead, and PR exists", () => {
725 const quick = resolveQuickAction(
726 status({
727 hasUpstream: false,
728 aheadCount: 0,
729 pr: {
730 number: 14,
731 title: "Existing PR",
732 url: "https://example.com/pr/14",
733 baseRef: "main",
734 headRef: "feature/test",
735 state: "open",
736 },
737 }),
738 false,
739 );
740 assert.deepInclude(quick, {
741 kind: "show_hint",
742 label: "Commit",
743 disabled: true,
744 hint: "Branch is up to date. No action needed.",
745 });
746 });
747​
748 it("resolveQuickAction runs push when clean, no upstream, and local commits are ahead", () => {
749 const quick = resolveQuickAction(
750 status({
751 hasUpstream: false,
752 aheadCount: 1,
753 pr: {
754 number: 15,
755 title: "Existing PR",
756 url: "https://example.com/pr/15",
757 baseRef: "main",
758 headRef: "feature/test",
759 state: "open",
760 },
761 }),
762 false,
763 );
764 assert.deepInclude(quick, {
765 kind: "run_action",
766 action: "push",
767 label: "Push",
768 disabled: false,
769 });
770 });
771​
772 it("buildMenuItems disables push and create PR when no commits are ahead", () => {
773 const items = buildMenuItems(status({ hasUpstream: false, pr: null, aheadCount: 0 }), false);
774 assert.deepEqual(items, [
775 {
776 id: "commit",
777 label: "Commit",
778 disabled: true,
779 icon: "commit",
780 kind: "open_dialog",
781 dialogAction: "commit",
782 },
783 {
784 id: "push",
785 label: "Push",
786 disabled: true,
787 icon: "push",
788 kind: "open_dialog",
789 dialogAction: "push",
790 },
791 {
792 id: "pr",
793 label: "Create PR",
794 disabled: true,
795 icon: "pr",
796 kind: "open_dialog",
797 dialogAction: "create_pr",
798 },
799 ]);
800 });
801​
802 it("resolveQuickAction runs push and create PR when no upstream and commits are ahead", () => {
803 const quick = resolveQuickAction(
804 status({
805 hasUpstream: false,
806 aheadCount: 2,
807 pr: null,
808 }),
809 false,
810 );
811 assert.deepInclude(quick, {
812 kind: "run_action",
813 action: "create_pr",
814 label: "Push & create PR",
815 disabled: false,
816 });
817 });
818​
819 it("resolveQuickAction publishes when no origin remote exists", () => {
820 const quick = resolveQuickAction(
821 status({
822 hasUpstream: false,
823 aheadCount: 2,
824 pr: null,
825 }),
826 false,
827 false,
828 false,
829 );
830 assert.deepEqual(quick, {
831 kind: "open_publish",
832 label: "Publish repository",
833 disabled: false,
834 });
835 });
836​
837 it("buildMenuItems enables create PR when no upstream and commits are ahead", () => {
838 const items = buildMenuItems(status({ hasUpstream: false, pr: null, aheadCount: 2 }), false);
839 assert.deepEqual(items, [
840 {
841 id: "commit",
842 label: "Commit",
843 disabled: true,
844 icon: "commit",
845 kind: "open_dialog",
846 dialogAction: "commit",
847 },
848 {
849 id: "push",
850 label: "Push",
851 disabled: false,
852 icon: "push",
853 kind: "open_dialog",
854 dialogAction: "push",
855 },
856 {
857 id: "pr",
858 label: "Create PR",
859 disabled: false,
860 icon: "pr",
861 kind: "open_dialog",
862 dialogAction: "create_pr",
863 },
864 ]);
865 });
866​
867 it("buildMenuItems hides push and create PR when no origin remote exists", () => {
868 const items = buildMenuItems(
869 status({ hasUpstream: false, pr: null, aheadCount: 2 }),
870 false,
871 false,
872 );
873 assert.deepEqual(items, [
874 {
875 id: "commit",
876 label: "Commit",
877 disabled: true,
878 icon: "commit",
879 kind: "open_dialog",
880 dialogAction: "commit",
881 },
882 ]);
883 });
884​
885 it("resolveQuickAction is disabled on default ref when no upstream exists and no commits are ahead", () => {
886 const quick = resolveQuickAction(
887 status({
888 refName: "main",
889 hasUpstream: false,
890 aheadCount: 0,
891 pr: null,
892 }),
893 false,
894 true,
895 );
896 assert.deepInclude(quick, {
897 kind: "show_hint",
898 label: "Push",
899 hint: "No local commits to push.",
900 disabled: true,
901 });
902 });
903​
904 it("resolveQuickAction uses push-only on default ref when no upstream exists and commits are ahead", () => {
905 const quick = resolveQuickAction(
906 status({
907 refName: "main",
908 hasUpstream: false,
909 aheadCount: 1,
910 pr: null,
911 }),
912 false,
913 true,
914 );
915 assert.deepInclude(quick, {
916 kind: "run_action",
917 action: "commit_push",
918 label: "Push",
919 disabled: false,
920 });
921 });
922​
923 it("buildMenuItems still disables push and create PR when ref is behind", () => {
924 const items = buildMenuItems(
925 status({
926 hasUpstream: false,
927 behindCount: 1,
928 aheadCount: 0,
929 pr: null,
930 }),
931 false,
932 );
933 assert.deepEqual(items, [
934 {
935 id: "commit",
936 label: "Commit",
937 disabled: true,
938 icon: "commit",
939 kind: "open_dialog",
940 dialogAction: "commit",
941 },
942 {
943 id: "push",
944 label: "Push",
945 disabled: true,
946 icon: "push",
947 kind: "open_dialog",
948 dialogAction: "push",
949 },
950 {
951 id: "pr",
952 label: "Create PR",
953 disabled: true,
954 icon: "pr",
955 kind: "open_dialog",
956 dialogAction: "create_pr",
957 },
958 ]);
959 });
960});
961​
962describe("requiresDefaultBranchConfirmation", () => {
963 it("requires confirmation for push actions on default ref", () => {
964 assert.isFalse(requiresDefaultBranchConfirmation("commit", true));
965 assert.isTrue(requiresDefaultBranchConfirmation("push", true));
966 assert.isTrue(requiresDefaultBranchConfirmation("create_pr", true));
967 assert.isTrue(requiresDefaultBranchConfirmation("commit_push", true));
968 assert.isTrue(requiresDefaultBranchConfirmation("commit_push_pr", true));
969 assert.isFalse(requiresDefaultBranchConfirmation("commit_push", false));
970 assert.isFalse(requiresDefaultBranchConfirmation("push", false));
971 });
972});
973​
974describe("resolveDefaultBranchActionDialogCopy", () => {
975 it("uses push-only copy when pushing without a commit", () => {
976 const copy = resolveDefaultBranchActionDialogCopy({
977 action: "commit_push",
978 branchName: "main",
979 includesCommit: false,
980 });
981​
982 assert.deepEqual(copy, {
983 title: "Push to default ref?",
984 description:
985 '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.',
986 continueLabel: "Push to main",
987 });
988 });
989​
990 it("uses push-and-pr copy when creating a PR without a commit", () => {
991 const copy = resolveDefaultBranchActionDialogCopy({
992 action: "commit_push_pr",
993 branchName: "main",
994 includesCommit: false,
995 });
996​
997 assert.deepEqual(copy, {
998 title: "Push & create PR from default ref?",
999 description:
1000 '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.',
1001 continueLabel: "Push & create PR",
1002 });
1003 });
1004​
1005 it("keeps commit copy when the action includes a commit", () => {
1006 const copy = resolveDefaultBranchActionDialogCopy({
1007 action: "commit_push_pr",
1008 branchName: "main",
1009 includesCommit: true,
1010 });
1011​
1012 assert.deepEqual(copy, {
1013 title: "Commit, push & create PR from default ref?",
1014 description:
1015 '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.',
1016 continueLabel: "Commit, push & create PR",
1017 });
1018 });
1019});
1020​
1021describe("buildGitActionProgressStages", () => {
1022 it("shows only push progress for explicit push actions", () => {
1023 const stages = buildGitActionProgressStages({
1024 action: "push",
1025 hasCustomCommitMessage: false,
1026 hasWorkingTreeChanges: false,
1027 pushTarget: "origin/feature/test",
1028 });
1029 assert.deepEqual(stages, ["Pushing to origin/feature/test..."]);
1030 });
1031​
1032 it("shows push and PR progress for create-pr actions that still need a push", () => {
1033 const stages = buildGitActionProgressStages({
1034 action: "create_pr",
1035 hasCustomCommitMessage: false,
1036 hasWorkingTreeChanges: false,
1037 pushTarget: "origin/feature/test",
1038 shouldPushBeforePr: true,
1039 });
1040 assert.deepEqual(stages, [
1041 "Pushing to origin/feature/test...",
1042 "Preparing PR...",
1043 "Generating PR content...",
1044 "Creating pull request...",
1045 ]);
1046 });
1047​
1048 it("shows only PR progress when create-pr can skip the push", () => {
1049 const stages = buildGitActionProgressStages({
1050 action: "create_pr",
1051 hasCustomCommitMessage: false,
1052 hasWorkingTreeChanges: false,
1053 shouldPushBeforePr: false,
1054 });
1055 assert.deepEqual(stages, [
1056 "Preparing PR...",
1057 "Generating PR content...",
1058 "Creating pull request...",
1059 ]);
1060 });
1061​
1062 it("includes commit stages for commit+push when working tree is dirty", () => {
1063 const stages = buildGitActionProgressStages({
1064 action: "commit_push",
1065 hasCustomCommitMessage: false,
1066 hasWorkingTreeChanges: true,
1067 pushTarget: "origin/feature/test",
1068 });
1069 assert.deepEqual(stages, [
1070 "Generating commit message...",
1071 "Committing...",
1072 "Pushing to origin/feature/test...",
1073 ]);
1074 });
1075​
1076 it("includes granular PR stages for commit+push+PR actions", () => {
1077 const stages = buildGitActionProgressStages({
1078 action: "commit_push_pr",
1079 hasCustomCommitMessage: true,
1080 hasWorkingTreeChanges: true,
1081 pushTarget: "origin/feature/test",
1082 });
1083 assert.deepEqual(stages, [
1084 "Committing...",
1085 "Pushing to origin/feature/test...",
1086 "Preparing PR...",
1087 "Generating PR content...",
1088 "Creating pull request...",
1089 ]);
1090 });
1091});
1092​
1093describe("resolveThreadBranchUpdate", () => {
1094 it("returns a branch update when the action created a new branch", () => {
1095 const update = resolveThreadBranchUpdate({
1096 action: "commit_push_pr",
1097 branch: {
1098 status: "created",
1099 name: "feature/fix-toast-copy",
1100 },
1101 commit: {
1102 status: "created",
1103 commitSha: "89abcdef01234567",
1104 subject: "feat: add ref sync",
1105 },
1106 push: { status: "pushed", branch: "feature/fix-toast-copy" },
1107 pr: { status: "skipped_not_requested" },
1108 toast: {
1109 title: "Pushed 89abcde to origin/feature/fix-toast-copy",
1110 cta: { kind: "none" },
1111 },
1112 });
1113​
1114 assert.deepEqual(update, {
1115 branch: "feature/fix-toast-copy",
1116 });
1117 });
1118​
1119 it("returns null when the action stayed on the existing branch", () => {
1120 const update = resolveThreadBranchUpdate({
1121 action: "commit_push",
1122 branch: {
1123 status: "skipped_not_requested",
1124 },
1125 commit: {
1126 status: "created",
1127 commitSha: "89abcdef01234567",
1128 subject: "feat: add ref sync",
1129 },
1130 push: { status: "pushed", branch: "feature/fix-toast-copy" },
1131 pr: { status: "skipped_not_requested" },
1132 toast: {
1133 title: "Pushed 89abcde to origin/feature/fix-toast-copy",
1134 cta: { kind: "none" },
1135 },
1136 });
1137​
1138 assert.equal(update, null);
1139 });
1140});
1141​
1142describe("resolveLiveThreadBranchUpdate", () => {
1143 it("returns a branch update when live git status differs from stored thread metadata", () => {
1144 const update = resolveLiveThreadBranchUpdate({
1145 threadBranch: "feature/old-ref",
1146 gitStatus: status({ refName: "effect-atom" }),
1147 });
1148​
1149 assert.deepEqual(update, {
1150 branch: "effect-atom",
1151 });
1152 });
1153​
1154 it("returns null when live git status is unavailable", () => {
1155 const update = resolveLiveThreadBranchUpdate({
1156 threadBranch: "feature/old-ref",
1157 gitStatus: null,
1158 });
1159​
1160 assert.equal(update, null);
1161 });
1162​
1163 it("returns null when the stored thread ref already matches git status", () => {
1164 const update = resolveLiveThreadBranchUpdate({
1165 threadBranch: "effect-atom",
1166 gitStatus: status({ refName: "effect-atom" }),
1167 });
1168​
1169 assert.equal(update, null);
1170 });
1171​
1172 it("returns null when git status is detached HEAD but the thread already has a ref", () => {
1173 const update = resolveLiveThreadBranchUpdate({
1174 threadBranch: "effect-atom",
1175 gitStatus: status({ refName: null }),
1176 });
1177​
1178 assert.equal(update, null);
1179 });
1180​
1181 it("does not regress a semantic thread ref back to a temporary worktree ref", () => {
1182 const update = resolveLiveThreadBranchUpdate({
1183 threadBranch: "t3code/github-query-rate-limit",
1184 gitStatus: status({ refName: "t3code/bda76797" }),
1185 });
1186​
1187 assert.equal(update, null);
1188 });
1189​
1190 it("allows a temporary worktree ref to reconcile to a semantic branch", () => {
1191 const update = resolveLiveThreadBranchUpdate({
1192 threadBranch: "t3code/a9628676",
1193 gitStatus: status({ refName: "feature/diff-panel-toggle" }),
1194 });
1195​
1196 assert.deepEqual(update, { branch: "feature/diff-panel-toggle" });
1197 });
1198});
1199​
1200describe("resolveThreadBranchMetadataPatch", () => {
1201 it("does not overwrite worktree metadata while reconciling a branch", () => {
1202 assert.deepEqual(
1203 resolveThreadBranchMetadataPatch("feature/current-ref", "feature/previous-ref"),
1205 branch: "feature/current-ref",
1206 expectedBranch: "feature/previous-ref",
1207 },
1208 );
1209 });
1210});
1211​
1212describe("resolveAutoFeatureBranchName", () => {
1213 it("uses semantic preferred ref names when available", () => {
1214 const ref = resolveAutoFeatureBranchName(["main", "feature/other"], "fix toast copy");
1215 assert.equal(ref, "feature/fix-toast-copy");
1216 });
1217​
1218 it("normalizes preferred names that already include a ref namespace", () => {
1219 const ref = resolveAutoFeatureBranchName(["main"], "feature/refine-toolbar-actions");
1220 assert.equal(ref, "feature/refine-toolbar-actions");
1221 });
1222​
1223 it("increments suffix when the preferred ref name already exists", () => {
1224 const ref = resolveAutoFeatureBranchName(
1225 ["main", "feature/fix-toast-copy", "feature/fix-toast-copy-2"],
1226 "fix toast copy",
1227 );
1228 assert.equal(ref, "feature/fix-toast-copy-3");
1229 });
1230​
1231 it("treats existing ref names as case-insensitive for collision checks", () => {
1232 const ref = resolveAutoFeatureBranchName(["Feature/Ticket-1"], "feature/ticket-1");
1233 assert.equal(ref, "feature/ticket-1-2");
1234 });
1235​
1236 it("falls back to feature/update when no preferred name is provided", () => {
1237 const ref = resolveAutoFeatureBranchName(["main"]);
1238 assert.equal(ref, "feature/update");
1239 });
1240});