|
1 | | -import { SourceControlProviderKind } from "@t3tools/contracts"; |
| 1 | +import { |
| 2 | + repositoryGroupingKeyOf, |
| 3 | + SourceControlProviderKind, |
| 4 | + type RepositoryIdentity, |
| 5 | +} from "@t3tools/contracts"; |
2 | 6 | import * as HostProcess from "@t3tools/shared/HostProcess"; |
3 | 7 | import { assert, describe, it } from "@effect/vitest"; |
4 | 8 | import * as NodeServices from "@effect/platform-node/NodeServices"; |
@@ -1231,6 +1235,46 @@ it.effect("records the API host in repository identities while keeping the SSH l |
1231 | 1235 | }).pipe(Effect.provide(layer)); |
1232 | 1236 | }); |
1233 | 1237 |
|
| 1238 | +/** An identity as the resolver builds it before refinement: keyed by the raw SSH alias. */ |
| 1239 | +const aliasedIdentity = (alias: string, rootPath: string): RepositoryIdentity => ({ |
| 1240 | + canonicalKey: `${alias}/acme/web`, |
| 1241 | + provider: SourceControlProviderKind.make("unknown"), |
| 1242 | + rootPath, |
| 1243 | + displayName: "acme/web", |
| 1244 | + locator: { |
| 1245 | + source: "git-remote", |
| 1246 | + remoteName: "origin", |
| 1247 | + remoteUrl: `git@${alias}:acme/web.git`, |
| 1248 | + }, |
| 1249 | +}); |
| 1250 | + |
| 1251 | +it.effect("groups checkouts that reach github.com through different SSH aliases together", () => { |
| 1252 | + const { layer } = harness({ remotes: "", api: {}, sshHostname: "github.com" }); |
| 1253 | + return Effect.gen(function* () { |
| 1254 | + const provider = yield* GitHubSourceControlProvider.make; |
| 1255 | + const refine = (identity: RepositoryIdentity) => |
| 1256 | + provider.refineRepositoryIdentity!({ identity, resolveContext: () => Effect.die("unused") }); |
| 1257 | + const work = yield* refine(aliasedIdentity("github-work", "/work/web")); |
| 1258 | + const personal = yield* refine(aliasedIdentity("gh-personal", "/personal/web")); |
| 1259 | + assert.strictEqual(repositoryGroupingKeyOf(work), "github.com/acme/web"); |
| 1260 | + assert.strictEqual(repositoryGroupingKeyOf(personal), repositoryGroupingKeyOf(work)); |
| 1261 | + }).pipe(Effect.provide(layer)); |
| 1262 | +}); |
| 1263 | + |
| 1264 | +it.effect("leaves SSH aliases for non-GitHub hosts keyed by the alias", () => { |
| 1265 | + const { layer } = harness({ remotes: "", api: {}, sshHostname: "gitlab.example.com" }); |
| 1266 | + return Effect.gen(function* () { |
| 1267 | + const provider = yield* GitHubSourceControlProvider.make; |
| 1268 | + const identity = aliasedIdentity("gitlab-work", "/work/web"); |
| 1269 | + const refined = yield* provider.refineRepositoryIdentity!({ |
| 1270 | + identity, |
| 1271 | + resolveContext: () => Effect.die("unused"), |
| 1272 | + }); |
| 1273 | + assert.strictEqual(refined, identity); |
| 1274 | + assert.strictEqual(repositoryGroupingKeyOf(refined), "gitlab-work/acme/web"); |
| 1275 | + }).pipe(Effect.provide(layer)); |
| 1276 | +}); |
| 1277 | + |
1234 | 1278 | it.effect("checks out the matching SSH alias remote instead of an unrelated origin", () => { |
1235 | 1279 | const { layer, git } = harness({ |
1236 | 1280 | remotes: remotesOutput( |
|
0 commit comments