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

GitActionsControl.logic.test.ts

1,017 lines26.7 KB

1import type { GitStatusResult } from "@t3tools/contracts";
2import { assert, describe, it } from "vitest";
3import {
4 buildGitActionProgressStages,
5 buildMenuItems,
6 requiresDefaultBranchConfirmation,
7 resolveAutoFeatureBranchName,
8 resolveDefaultBranchActionDialogCopy,
9 resolveQuickAction,
10 summarizeGitResult,
11} from "./GitActionsControl.logic";
12​
13function status(overrides: Partial<GitStatusResult> = {}): GitStatusResult {
14 return {
15 branch: "feature/test",
16 hasWorkingTreeChanges: false,
17 workingTree: {
18 files: [],
19 insertions: 0,
20 deletions: 0,
21 },
22 hasUpstream: true,
23 aheadCount: 0,
24 behindCount: 0,
25 pr: null,
26 ...overrides,
27 };
29​
30describe("when: branch is clean and has an open PR", () => {
31 it("resolveQuickAction opens the existing PR", () => {
32 const quick = resolveQuickAction(
33 status({
34 pr: {
35 number: 10,
36 title: "Open PR",
37 url: "https://example.com/pr/10",
38 baseBranch: "main",
39 headBranch: "feature/test",
40 state: "open",
41 },
42 }),
43 false,
44 );
45 assert.deepInclude(quick, { kind: "open_pr", label: "View PR", disabled: false });
46 });
47​
48 it("buildMenuItems disables commit/push and enables open PR", () => {
49 const items = buildMenuItems(
50 status({
51 pr: {
52 number: 11,
53 title: "Existing PR",
54 url: "https://example.com/pr/11",
55 baseBranch: "main",
56 headBranch: "feature/test",
57 state: "open",
58 },
59 }),
60 false,
61 );
62 assert.deepEqual(items, [
63 {
64 id: "commit",
65 label: "Commit",
66 disabled: true,
67 icon: "commit",
68 kind: "open_dialog",
69 dialogAction: "commit",
70 },
71 {
72 id: "push",
73 label: "Push",
74 disabled: true,
75 icon: "push",
76 kind: "open_dialog",
77 dialogAction: "push",
78 },
79 {
80 id: "pr",
81 label: "View PR",
82 disabled: false,
83 icon: "pr",
84 kind: "open_pr",
85 },
86 ]);
87 });
88});
89​
90describe("when: actions are busy", () => {
91 it("resolveQuickAction returns running disabled state", () => {
92 const quick = resolveQuickAction(status(), true);
93 assert.deepInclude(quick, {
94 kind: "show_hint",
95 label: "Commit",
96 disabled: true,
97 hint: "Git action in progress.",
98 });
99 });
100​
101 it("buildMenuItems disables all actions", () => {
102 const items = buildMenuItems(status(), true);
103 assert.deepEqual(items, [
104 {
105 id: "commit",
106 label: "Commit",
107 disabled: true,
108 icon: "commit",
109 kind: "open_dialog",
110 dialogAction: "commit",
111 },
112 {
113 id: "push",
114 label: "Push",
115 disabled: true,
116 icon: "push",
117 kind: "open_dialog",
118 dialogAction: "push",
119 },
120 {
121 id: "pr",
122 label: "Create PR",
123 disabled: true,
124 icon: "pr",
125 kind: "open_dialog",
126 dialogAction: "create_pr",
127 },
128 ]);
129 });
130});
131​
132describe("when: git status is unavailable", () => {
133 it("resolveQuickAction returns unavailable disabled state", () => {
134 const quick = resolveQuickAction(null, false);
135 assert.deepInclude(quick, {
136 kind: "show_hint",
137 label: "Commit",
138 disabled: true,
139 hint: "Git status is unavailable.",
140 });
141 });
142​
143 it("buildMenuItems returns no menu items", () => {
144 const items = buildMenuItems(null, false);
145 assert.deepEqual(items, []);
146 });
147});
148​
149describe("when: branch is clean, ahead, and has an open PR", () => {
150 it("resolveQuickAction prefers push", () => {
151 const quick = resolveQuickAction(
152 status({
153 aheadCount: 3,
154 pr: {
155 number: 13,
156 title: "Open PR",
157 url: "https://example.com/pr/13",
158 baseBranch: "main",
159 headBranch: "feature/test",
160 state: "open",
161 },
162 }),
163 false,
164 );
165 assert.deepInclude(quick, { kind: "run_action", action: "commit_push", label: "Push" });
166 });
167​
168 it("buildMenuItems enables push and keeps open PR available", () => {
169 const items = buildMenuItems(
170 status({
171 aheadCount: 2,
172 pr: {
173 number: 12,
174 title: "Existing PR",
175 url: "https://example.com/pr/12",
176 baseBranch: "main",
177 headBranch: "feature/test",
178 state: "open",
179 },
180 }),
181 false,
182 );
183 assert.deepEqual(items, [
184 {
185 id: "commit",
186 label: "Commit",
187 disabled: true,
188 icon: "commit",
189 kind: "open_dialog",
190 dialogAction: "commit",
191 },
192 {
193 id: "push",
194 label: "Push",
195 disabled: false,
196 icon: "push",
197 kind: "open_dialog",
198 dialogAction: "push",
199 },
200 {
201 id: "pr",
202 label: "View PR",
203 disabled: false,
204 icon: "pr",
205 kind: "open_pr",
206 },
207 ]);
208 });
209});
210​
211describe("when: branch is clean, ahead, and has no open PR", () => {
212 it("resolveQuickAction pushes and creates a PR", () => {
213 const quick = resolveQuickAction(status({ aheadCount: 2, pr: null }), false);
214 assert.deepInclude(quick, {
215 kind: "run_action",
216 action: "commit_push_pr",
217 label: "Push & create PR",
218 });
219 });
220​
221 it("buildMenuItems enables push and create PR, with commit disabled", () => {
222 const items = buildMenuItems(status({ aheadCount: 2, pr: null }), false);
223 assert.deepEqual(items, [
224 {
225 id: "commit",
226 label: "Commit",
227 disabled: true,
228 icon: "commit",
229 kind: "open_dialog",
230 dialogAction: "commit",
231 },
232 {
233 id: "push",
234 label: "Push",
235 disabled: false,
236 icon: "push",
237 kind: "open_dialog",
238 dialogAction: "push",
239 },
240 {
241 id: "pr",
242 label: "Create PR",
243 disabled: false,
244 icon: "pr",
245 kind: "open_dialog",
246 dialogAction: "create_pr",
247 },
248 ]);
249 });
250});
251​
252describe("when: branch is clean, up to date, and has no open PR", () => {
253 it("resolveQuickAction returns disabled no-action state", () => {
254 const quick = resolveQuickAction(
255 status({ aheadCount: 0, behindCount: 0, hasWorkingTreeChanges: false, pr: null }),
256 false,
257 );
258 assert.deepInclude(quick, { kind: "show_hint", label: "Commit", disabled: true });
259 });
260​
261 it("buildMenuItems disables commit, push, and create PR", () => {
262 const items = buildMenuItems(status({ aheadCount: 0, behindCount: 0, pr: null }), false);
263 assert.deepEqual(items, [
264 {
265 id: "commit",
266 label: "Commit",
267 disabled: true,
268 icon: "commit",
269 kind: "open_dialog",
270 dialogAction: "commit",
271 },
272 {
273 id: "push",
274 label: "Push",
275 disabled: true,
276 icon: "push",
277 kind: "open_dialog",
278 dialogAction: "push",
279 },
280 {
281 id: "pr",
282 label: "Create PR",
283 disabled: true,
284 icon: "pr",
285 kind: "open_dialog",
286 dialogAction: "create_pr",
287 },
288 ]);
289 });
290});
291​
292describe("when: branch is behind upstream", () => {
293 it("resolveQuickAction returns pull", () => {
294 const quick = resolveQuickAction(status({ behindCount: 2 }), false);
295 assert.deepInclude(quick, { kind: "run_pull", label: "Pull", disabled: false });
296 });
297​
298 it("buildMenuItems disables push and create PR", () => {
299 const items = buildMenuItems(status({ behindCount: 1, pr: null }), false);
300 assert.deepEqual(items, [
301 {
302 id: "commit",
303 label: "Commit",
304 disabled: true,
305 icon: "commit",
306 kind: "open_dialog",
307 dialogAction: "commit",
308 },
309 {
310 id: "push",
311 label: "Push",
312 disabled: true,
313 icon: "push",
314 kind: "open_dialog",
315 dialogAction: "push",
316 },
317 {
318 id: "pr",
319 label: "Create PR",
320 disabled: true,
321 icon: "pr",
322 kind: "open_dialog",
323 dialogAction: "create_pr",
324 },
325 ]);
326 });
327});
328​
329describe("when: branch has diverged from upstream", () => {
330 it("resolveQuickAction returns a disabled sync hint", () => {
331 const quick = resolveQuickAction(status({ aheadCount: 2, behindCount: 1 }), false);
332 assert.deepEqual(quick, {
333 label: "Sync branch",
334 disabled: true,
335 kind: "show_hint",
336 hint: "Branch has diverged from upstream. Rebase/merge first.",
337 });
338 });
339});
340​
341describe("when: working tree has local changes", () => {
342 it("resolveQuickAction returns commit, push, and create PR", () => {
343 const quick = resolveQuickAction(status({ hasWorkingTreeChanges: true }), false);
344 assert.deepInclude(quick, {
345 kind: "run_action",
346 action: "commit_push_pr",
347 label: "Commit, push & PR",
348 });
349 });
350​
351 it("resolveQuickAction falls back to commit when no origin remote exists", () => {
352 const quick = resolveQuickAction(
353 status({ hasWorkingTreeChanges: true, hasUpstream: false }),
354 false,
355 false,
356 false,
357 );
358 assert.deepInclude(quick, {
359 kind: "run_action",
360 action: "commit",
361 label: "Commit",
362 disabled: false,
363 });
364 });
365​
366 it("resolveQuickAction returns commit and push when open PR exists", () => {
367 const quick = resolveQuickAction(
368 status({
369 hasWorkingTreeChanges: true,
370 pr: {
371 number: 16,
372 title: "Existing PR",
373 url: "https://example.com/pr/16",
374 baseBranch: "main",
375 headBranch: "feature/test",
376 state: "open",
377 },
378 }),
379 false,
380 );
381 assert.deepInclude(quick, {
382 kind: "run_action",
383 action: "commit_push",
384 label: "Commit & push",
385 });
386 });
387​
388 it("buildMenuItems enables commit and disables push and PR", () => {
389 const items = buildMenuItems(status({ hasWorkingTreeChanges: true }), false);
390 assert.deepEqual(items, [
391 {
392 id: "commit",
393 label: "Commit",
394 disabled: false,
395 icon: "commit",
396 kind: "open_dialog",
397 dialogAction: "commit",
398 },
399 {
400 id: "push",
401 label: "Push",
402 disabled: true,
403 icon: "push",
404 kind: "open_dialog",
405 dialogAction: "push",
406 },
407 {
408 id: "pr",
409 label: "Create PR",
410 disabled: true,
411 icon: "pr",
412 kind: "open_dialog",
413 dialogAction: "create_pr",
414 },
415 ]);
416 });
417});
418​
419describe("when: on default branch without open PR", () => {
420 it("resolveQuickAction returns commit and push when local changes exist", () => {
421 const quick = resolveQuickAction(
422 status({ branch: "main", hasWorkingTreeChanges: true }),
423 false,
424 true,
425 );
426 assert.deepInclude(quick, {
427 kind: "run_action",
428 action: "commit_push",
429 label: "Commit & push",
430 disabled: false,
431 });
432 });
433​
434 it("resolveQuickAction returns push when branch is ahead", () => {
435 const quick = resolveQuickAction(
436 status({ branch: "main", aheadCount: 2, pr: null }),
437 false,
438 true,
439 );
440 assert.deepInclude(quick, {
441 kind: "run_action",
442 action: "commit_push",
443 label: "Push",
444 disabled: false,
445 });
446 });
447});
448​
449describe("when: working tree has local changes and branch is behind upstream", () => {
450 it("resolveQuickAction still prefers commit, push, and create PR", () => {
451 const quick = resolveQuickAction(
452 status({ hasWorkingTreeChanges: true, behindCount: 1 }),
453 false,
454 );
455 assert.deepInclude(quick, {
456 kind: "run_action",
457 action: "commit_push_pr",
458 label: "Commit, push & PR",
459 });
460 });
461​
462 it("buildMenuItems enables commit and keeps push and PR disabled", () => {
463 const items = buildMenuItems(status({ hasWorkingTreeChanges: true, behindCount: 2 }), false);
464 assert.deepEqual(items, [
465 {
466 id: "commit",
467 label: "Commit",
468 disabled: false,
469 icon: "commit",
470 kind: "open_dialog",
471 dialogAction: "commit",
472 },
473 {
474 id: "push",
475 label: "Push",
476 disabled: true,
477 icon: "push",
478 kind: "open_dialog",
479 dialogAction: "push",
480 },
481 {
482 id: "pr",
483 label: "Create PR",
484 disabled: true,
485 icon: "pr",
486 kind: "open_dialog",
487 dialogAction: "create_pr",
488 },
489 ]);
490 });
491});
492​
493describe("when: HEAD is detached and there are no local changes", () => {
494 it("resolveQuickAction shows detached head hint", () => {
495 const quick = resolveQuickAction(
496 status({ branch: null, hasWorkingTreeChanges: false, hasUpstream: false }),
497 false,
498 );
499 assert.deepInclude(quick, { kind: "show_hint", label: "Commit", disabled: true });
500 });
501​
502 it("buildMenuItems keeps commit, push, and PR disabled", () => {
503 const items = buildMenuItems(status({ branch: null, hasWorkingTreeChanges: false }), false);
504 assert.deepEqual(items, [
505 {
506 id: "commit",
507 label: "Commit",
508 disabled: true,
509 icon: "commit",
510 kind: "open_dialog",
511 dialogAction: "commit",
512 },
513 {
514 id: "push",
515 label: "Push",
516 disabled: true,
517 icon: "push",
518 kind: "open_dialog",
519 dialogAction: "push",
520 },
521 {
522 id: "pr",
523 label: "Create PR",
524 disabled: true,
525 icon: "pr",
526 kind: "open_dialog",
527 dialogAction: "create_pr",
528 },
529 ]);
530 });
531});
532​
533describe("when: branch has no upstream configured", () => {
534 it("resolveQuickAction is disabled when clean, no upstream, and no local commits are ahead", () => {
535 const quick = resolveQuickAction(
536 status({ hasUpstream: false, pr: null, aheadCount: 0 }),
537 false,
538 );
539 assert.deepInclude(quick, {
540 kind: "show_hint",
541 label: "Push",
542 hint: "No local commits to push.",
543 disabled: true,
544 });
545 });
546​
547 it("resolveQuickAction opens PR when clean, no upstream, no local commits are ahead, and PR exists", () => {
548 const quick = resolveQuickAction(
549 status({
550 hasUpstream: false,
551 aheadCount: 0,
552 pr: {
553 number: 14,
554 title: "Existing PR",
555 url: "https://example.com/pr/14",
556 baseBranch: "main",
557 headBranch: "feature/test",
558 state: "open",
559 },
560 }),
561 false,
562 );
563 assert.deepInclude(quick, {
564 kind: "open_pr",
565 label: "View PR",
566 disabled: false,
567 });
568 });
569​
570 it("resolveQuickAction runs push when clean, no upstream, and local commits are ahead", () => {
571 const quick = resolveQuickAction(
572 status({
573 hasUpstream: false,
574 aheadCount: 1,
575 pr: {
576 number: 15,
577 title: "Existing PR",
578 url: "https://example.com/pr/15",
579 baseBranch: "main",
580 headBranch: "feature/test",
581 state: "open",
582 },
583 }),
584 false,
585 );
586 assert.deepInclude(quick, {
587 kind: "run_action",
588 action: "commit_push",
589 label: "Push",
590 disabled: false,
591 });
592 });
593​
594 it("buildMenuItems disables push and create PR when no commits are ahead", () => {
595 const items = buildMenuItems(status({ hasUpstream: false, pr: null, aheadCount: 0 }), false);
596 assert.deepEqual(items, [
597 {
598 id: "commit",
599 label: "Commit",
600 disabled: true,
601 icon: "commit",
602 kind: "open_dialog",
603 dialogAction: "commit",
604 },
605 {
606 id: "push",
607 label: "Push",
608 disabled: true,
609 icon: "push",
610 kind: "open_dialog",
611 dialogAction: "push",
612 },
613 {
614 id: "pr",
615 label: "Create PR",
616 disabled: true,
617 icon: "pr",
618 kind: "open_dialog",
619 dialogAction: "create_pr",
620 },
621 ]);
622 });
623​
624 it("resolveQuickAction runs push and create PR when no upstream and commits are ahead", () => {
625 const quick = resolveQuickAction(
626 status({
627 hasUpstream: false,
628 aheadCount: 2,
629 pr: null,
630 }),
631 false,
632 );
633 assert.deepInclude(quick, {
634 kind: "run_action",
635 action: "commit_push_pr",
636 label: "Push & create PR",
637 disabled: false,
638 });
639 });
640​
641 it("resolveQuickAction disables push-and-pr flows when no origin remote exists", () => {
642 const quick = resolveQuickAction(
643 status({
644 hasUpstream: false,
645 aheadCount: 2,
646 pr: null,
647 }),
648 false,
649 false,
650 false,
651 );
652 assert.deepEqual(quick, {
653 kind: "show_hint",
654 label: "Push",
655 hint: 'Add an "origin" remote before pushing or creating a PR.',
656 disabled: true,
657 });
658 });
659​
660 it("buildMenuItems enables create PR when no upstream and commits are ahead", () => {
661 const items = buildMenuItems(status({ hasUpstream: false, pr: null, aheadCount: 2 }), false);
662 assert.deepEqual(items, [
663 {
664 id: "commit",
665 label: "Commit",
666 disabled: true,
667 icon: "commit",
668 kind: "open_dialog",
669 dialogAction: "commit",
670 },
671 {
672 id: "push",
673 label: "Push",
674 disabled: false,
675 icon: "push",
676 kind: "open_dialog",
677 dialogAction: "push",
678 },
679 {
680 id: "pr",
681 label: "Create PR",
682 disabled: false,
683 icon: "pr",
684 kind: "open_dialog",
685 dialogAction: "create_pr",
686 },
687 ]);
688 });
689​
690 it("buildMenuItems disables push and create PR when no origin remote exists", () => {
691 const items = buildMenuItems(
692 status({ hasUpstream: false, pr: null, aheadCount: 2 }),
693 false,
694 false,
695 );
696 assert.deepEqual(items, [
697 {
698 id: "commit",
699 label: "Commit",
700 disabled: true,
701 icon: "commit",
702 kind: "open_dialog",
703 dialogAction: "commit",
704 },
705 {
706 id: "push",
707 label: "Push",
708 disabled: true,
709 icon: "push",
710 kind: "open_dialog",
711 dialogAction: "push",
712 },
713 {
714 id: "pr",
715 label: "Create PR",
716 disabled: true,
717 icon: "pr",
718 kind: "open_dialog",
719 dialogAction: "create_pr",
720 },
721 ]);
722 });
723​
724 it("resolveQuickAction is disabled on default branch when no upstream exists and no commits are ahead", () => {
725 const quick = resolveQuickAction(
726 status({
727 branch: "main",
728 hasUpstream: false,
729 aheadCount: 0,
730 pr: null,
731 }),
732 false,
733 true,
734 );
735 assert.deepInclude(quick, {
736 kind: "show_hint",
737 label: "Push",
738 hint: "No local commits to push.",
739 disabled: true,
740 });
741 });
742​
743 it("resolveQuickAction uses push-only on default branch when no upstream exists and commits are ahead", () => {
744 const quick = resolveQuickAction(
745 status({
746 branch: "main",
747 hasUpstream: false,
748 aheadCount: 1,
749 pr: null,
750 }),
751 false,
752 true,
753 );
754 assert.deepInclude(quick, {
755 kind: "run_action",
756 action: "commit_push",
757 label: "Push",
758 disabled: false,
759 });
760 });
761​
762 it("buildMenuItems still disables push and create PR when branch is behind", () => {
763 const items = buildMenuItems(
764 status({
765 hasUpstream: false,
766 behindCount: 1,
767 aheadCount: 0,
768 pr: null,
769 }),
770 false,
771 );
772 assert.deepEqual(items, [
773 {
774 id: "commit",
775 label: "Commit",
776 disabled: true,
777 icon: "commit",
778 kind: "open_dialog",
779 dialogAction: "commit",
780 },
781 {
782 id: "push",
783 label: "Push",
784 disabled: true,
785 icon: "push",
786 kind: "open_dialog",
787 dialogAction: "push",
788 },
789 {
790 id: "pr",
791 label: "Create PR",
792 disabled: true,
793 icon: "pr",
794 kind: "open_dialog",
795 dialogAction: "create_pr",
796 },
797 ]);
798 });
799});
800​
801describe("requiresDefaultBranchConfirmation", () => {
802 it("requires confirmation for push actions on default branch", () => {
803 assert.isFalse(requiresDefaultBranchConfirmation("commit", true));
804 assert.isTrue(requiresDefaultBranchConfirmation("commit_push", true));
805 assert.isTrue(requiresDefaultBranchConfirmation("commit_push_pr", true));
806 assert.isFalse(requiresDefaultBranchConfirmation("commit_push", false));
807 });
808});
809​
810describe("resolveDefaultBranchActionDialogCopy", () => {
811 it("uses push-only copy when pushing without a commit", () => {
812 const copy = resolveDefaultBranchActionDialogCopy({
813 action: "commit_push",
814 branchName: "main",
815 includesCommit: false,
816 });
817​
818 assert.deepEqual(copy, {
819 title: "Push to default branch?",
820 description:
821 'This action will push local commits on "main". You can continue on this branch or create a feature branch and run the same action there.',
822 continueLabel: "Push to main",
823 });
824 });
825​
826 it("uses push-and-pr copy when creating a PR without a commit", () => {
827 const copy = resolveDefaultBranchActionDialogCopy({
828 action: "commit_push_pr",
829 branchName: "main",
830 includesCommit: false,
831 });
832​
833 assert.deepEqual(copy, {
834 title: "Push & create PR from default branch?",
835 description:
836 'This action will push local commits and create a PR on "main". You can continue on this branch or create a feature branch and run the same action there.',
837 continueLabel: "Push & create PR",
838 });
839 });
840​
841 it("keeps commit copy when the action includes a commit", () => {
842 const copy = resolveDefaultBranchActionDialogCopy({
843 action: "commit_push_pr",
844 branchName: "main",
845 includesCommit: true,
846 });
847​
848 assert.deepEqual(copy, {
849 title: "Commit, push & create PR from default branch?",
850 description:
851 'This action will commit, push, and create a PR on "main". You can continue on this branch or create a feature branch and run the same action there.',
852 continueLabel: "Commit, push & create PR",
853 });
854 });
855});
856​
857describe("buildGitActionProgressStages", () => {
858 it("shows only push progress when push-only is forced", () => {
859 const stages = buildGitActionProgressStages({
860 action: "commit_push",
861 hasCustomCommitMessage: false,
862 hasWorkingTreeChanges: true,
863 forcePushOnly: true,
864 pushTarget: "origin/feature/test",
865 });
866 assert.deepEqual(stages, ["Pushing to origin/feature/test..."]);
867 });
868​
869 it("skips commit stages for create-pr flow when push-only is forced", () => {
870 const stages = buildGitActionProgressStages({
871 action: "commit_push_pr",
872 hasCustomCommitMessage: false,
873 hasWorkingTreeChanges: true,
874 forcePushOnly: true,
875 pushTarget: "origin/feature/test",
876 });
877 assert.deepEqual(stages, ["Pushing to origin/feature/test...", "Creating PR..."]);
878 });
879​
880 it("includes commit stages for commit+push when working tree is dirty", () => {
881 const stages = buildGitActionProgressStages({
882 action: "commit_push",
883 hasCustomCommitMessage: false,
884 hasWorkingTreeChanges: true,
885 pushTarget: "origin/feature/test",
886 });
887 assert.deepEqual(stages, [
888 "Generating commit message...",
889 "Committing...",
890 "Pushing to origin/feature/test...",
891 ]);
892 });
893});
894​
895describe("summarizeGitResult", () => {
896 it("returns commit-focused toast for commit action", () => {
897 const result = summarizeGitResult({
898 action: "commit",
899 branch: { status: "skipped_not_requested" },
900 commit: {
901 status: "created",
902 commitSha: "0123456789abcdef",
903 subject: "feat: add optimistic UI for git action button",
904 },
905 push: { status: "skipped_not_requested" },
906 pr: { status: "skipped_not_requested" },
907 });
908​
909 assert.deepEqual(result, {
910 title: "Committed 0123456",
911 description: "feat: add optimistic UI for git action button",
912 });
913 });
914​
915 it("returns push-focused toast for push action", () => {
916 const result = summarizeGitResult({
917 action: "commit_push",
918 branch: { status: "skipped_not_requested" },
919 commit: {
920 status: "created",
921 commitSha: "abcdef0123456789",
922 subject: "fix: tighten quick action tooltip hover handling",
923 },
924 push: {
925 status: "pushed",
926 branch: "foo",
927 upstreamBranch: "origin/foo",
928 },
929 pr: { status: "skipped_not_requested" },
930 });
931​
932 assert.deepEqual(result, {
933 title: "Pushed abcdef0 to origin/foo",
934 description: "fix: tighten quick action tooltip hover handling",
935 });
936 });
937​
938 it("returns PR-focused toast for created PR action", () => {
939 const result = summarizeGitResult({
940 action: "commit_push_pr",
941 branch: { status: "skipped_not_requested" },
942 commit: {
943 status: "created",
944 commitSha: "89abcdef01234567",
945 subject: "feat: ship github shortcuts",
946 },
947 push: {
948 status: "pushed",
949 branch: "foo",
950 },
951 pr: {
952 status: "created",
953 number: 42,
954 title: "feat: ship github shortcuts and improve PR CTA in success toast",
955 },
956 });
957​
958 assert.deepEqual(result, {
959 title: "Created PR #42",
960 description: "feat: ship github shortcuts and improve PR CTA in success toast",
961 });
962 });
963​
964 it("truncates long description text", () => {
965 const result = summarizeGitResult({
966 action: "commit_push_pr",
967 branch: { status: "skipped_not_requested" },
968 commit: {
969 status: "created",
970 commitSha: "89abcdef01234567",
971 subject: "short subject",
972 },
973 push: { status: "pushed", branch: "foo" },
974 pr: {
975 status: "created",
976 number: 99,
977 title:
978 "feat: this title is intentionally extremely long so we can validate that toast descriptions are truncated with an ellipsis suffix",
979 },
980 });
981​
982 assert.deepEqual(result, {
983 title: "Created PR #99",
984 description: "feat: this title is intentionally extremely long so we can validate t...",
985 });
986 });
987});
988​
989describe("resolveAutoFeatureBranchName", () => {
990 it("uses semantic preferred branch names when available", () => {
991 const branch = resolveAutoFeatureBranchName(["main", "feature/other"], "fix toast copy");
992 assert.equal(branch, "feature/fix-toast-copy");
993 });
994​
995 it("normalizes preferred names that already include a branch namespace", () => {
996 const branch = resolveAutoFeatureBranchName(["main"], "feature/refine-toolbar-actions");
997 assert.equal(branch, "feature/refine-toolbar-actions");
998 });
999​
1000 it("increments suffix when the preferred branch name already exists", () => {
1001 const branch = resolveAutoFeatureBranchName(
1002 ["main", "feature/fix-toast-copy", "feature/fix-toast-copy-2"],
1003 "fix toast copy",
1004 );
1005 assert.equal(branch, "feature/fix-toast-copy-3");
1006 });
1007​
1008 it("treats existing branch names as case-insensitive for collision checks", () => {
1009 const branch = resolveAutoFeatureBranchName(["Feature/Ticket-1"], "feature/ticket-1");
1010 assert.equal(branch, "feature/ticket-1-2");
1011 });
1012​
1013 it("falls back to feature/update when no preferred name is provided", () => {
1014 const branch = resolveAutoFeatureBranchName(["main"]);
1015 assert.equal(branch, "feature/update");
1016 });
1017});