|
1 | | -import type { GitBranch } from "@t3tools/contracts"; |
| 1 | +import { EnvironmentId, type GitBranch } from "@t3tools/contracts"; |
2 | 2 | import { describe, expect, it } from "vitest"; |
3 | 3 | import { |
4 | 4 | dedupeRemoteBranchesWithLocalMatches, |
5 | 5 | deriveLocalBranchNameFromRemoteRef, |
| 6 | + resolveEnvironmentOptionLabel, |
6 | 7 | resolveBranchSelectionTarget, |
| 8 | + resolveCurrentWorkspaceLabel, |
7 | 9 | resolveDraftEnvModeAfterBranchChange, |
| 10 | + resolveEffectiveEnvMode, |
| 11 | + resolveEnvModeLabel, |
8 | 12 | resolveBranchToolbarValue, |
9 | 13 | shouldIncludeBranchPickerItem, |
10 | 14 | } from "./BranchToolbar.logic"; |
11 | 15 |
|
| 16 | +const localEnvironmentId = EnvironmentId.makeUnsafe("environment-local"); |
| 17 | +const remoteEnvironmentId = EnvironmentId.makeUnsafe("environment-remote"); |
| 18 | + |
12 | 19 | describe("resolveDraftEnvModeAfterBranchChange", () => { |
13 | 20 | it("switches to local mode when returning from an existing worktree to the main worktree", () => { |
14 | 21 | expect( |
@@ -76,6 +83,80 @@ describe("resolveBranchToolbarValue", () => { |
76 | 83 | }); |
77 | 84 | }); |
78 | 85 |
|
| 86 | +describe("resolveEnvironmentOptionLabel", () => { |
| 87 | + it("prefers the primary environment's machine label", () => { |
| 88 | + expect( |
| 89 | + resolveEnvironmentOptionLabel({ |
| 90 | + isPrimary: true, |
| 91 | + environmentId: localEnvironmentId, |
| 92 | + runtimeLabel: "Julius's Mac mini", |
| 93 | + savedLabel: "Local environment", |
| 94 | + }), |
| 95 | + ).toBe("Julius's Mac mini"); |
| 96 | + }); |
| 97 | + |
| 98 | + it("falls back to 'This device' for generic primary labels", () => { |
| 99 | + expect( |
| 100 | + resolveEnvironmentOptionLabel({ |
| 101 | + isPrimary: true, |
| 102 | + environmentId: localEnvironmentId, |
| 103 | + runtimeLabel: "Local environment", |
| 104 | + savedLabel: "Local", |
| 105 | + }), |
| 106 | + ).toBe("This device"); |
| 107 | + }); |
| 108 | + |
| 109 | + it("keeps configured labels for non-primary environments", () => { |
| 110 | + expect( |
| 111 | + resolveEnvironmentOptionLabel({ |
| 112 | + isPrimary: false, |
| 113 | + environmentId: remoteEnvironmentId, |
| 114 | + runtimeLabel: null, |
| 115 | + savedLabel: "Build box", |
| 116 | + }), |
| 117 | + ).toBe("Build box"); |
| 118 | + }); |
| 119 | +}); |
| 120 | + |
| 121 | +describe("resolveEffectiveEnvMode", () => { |
| 122 | + it("treats draft threads already attached to a worktree as current-checkout mode", () => { |
| 123 | + expect( |
| 124 | + resolveEffectiveEnvMode({ |
| 125 | + activeWorktreePath: "/repo/.t3/worktrees/feature-a", |
| 126 | + hasServerThread: false, |
| 127 | + draftThreadEnvMode: "worktree", |
| 128 | + }), |
| 129 | + ).toBe("local"); |
| 130 | + }); |
| 131 | + |
| 132 | + it("keeps explicit new-worktree mode for draft threads without a worktree path", () => { |
| 133 | + expect( |
| 134 | + resolveEffectiveEnvMode({ |
| 135 | + activeWorktreePath: null, |
| 136 | + hasServerThread: false, |
| 137 | + draftThreadEnvMode: "worktree", |
| 138 | + }), |
| 139 | + ).toBe("worktree"); |
| 140 | + }); |
| 141 | +}); |
| 142 | + |
| 143 | +describe("resolveEnvModeLabel", () => { |
| 144 | + it("uses explicit workspace labels", () => { |
| 145 | + expect(resolveEnvModeLabel("local")).toBe("Current checkout"); |
| 146 | + expect(resolveEnvModeLabel("worktree")).toBe("New worktree"); |
| 147 | + }); |
| 148 | +}); |
| 149 | + |
| 150 | +describe("resolveCurrentWorkspaceLabel", () => { |
| 151 | + it("describes the main repo checkout when no worktree path is active", () => { |
| 152 | + expect(resolveCurrentWorkspaceLabel(null)).toBe("Current checkout"); |
| 153 | + }); |
| 154 | + |
| 155 | + it("describes the active checkout as a worktree when one is attached", () => { |
| 156 | + expect(resolveCurrentWorkspaceLabel("/repo/.t3/worktrees/feature-a")).toBe("Current worktree"); |
| 157 | + }); |
| 158 | +}); |
| 159 | + |
79 | 160 | describe("deriveLocalBranchNameFromRemoteRef", () => { |
80 | 161 | it("strips the remote prefix from a remote ref", () => { |
81 | 162 | expect(deriveLocalBranchNameFromRemoteRef("origin/feature/demo")).toBe("feature/demo"); |
|
0 commit comments