Skip to content

Commit 4fa05b4

Browse files
committed
test(source-control): cover SSH alias grouping across checkouts
Two checkouts that reach github.com through different SSH aliases now refine to the same repository grouping key. Aliases for non-GitHub hosts keep their alias-based key, documenting the current GitHub-only scope.
1 parent 926641c commit 4fa05b4

1 file changed

Lines changed: 45 additions & 1 deletion

File tree

‎packages/source-control-github/src/server/GitHubSourceControlProvider.test.ts‎

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { SourceControlProviderKind } from "@t3tools/contracts";
1+
import {
2+
repositoryGroupingKeyOf,
3+
SourceControlProviderKind,
4+
type RepositoryIdentity,
5+
} from "@t3tools/contracts";
26
import * as HostProcess from "@t3tools/shared/HostProcess";
37
import { assert, describe, it } from "@effect/vitest";
48
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
12311235
}).pipe(Effect.provide(layer));
12321236
});
12331237

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+
12341278
it.effect("checks out the matching SSH alias remote instead of an unrelated origin", () => {
12351279
const { layer, git } = harness({
12361280
remotes: remotesOutput(

0 commit comments

Comments
 (0)