@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 519 lines 23.3 KB
Raw
1 // @effect-diagnostics nodeBuiltinImport:off - realpathSync.native resolves Windows 8.3 short names, which the Effect realPath does not.
2 import * as NodeFS from "node:fs";
3 import * as NodeServices from "@effect/platform-node/NodeServices";
4 import { expect, it } from "@effect/vitest";
5 import * as Effect from "effect/Effect";
6 import * as FileSystem from "effect/FileSystem";
7 import * as Path from "effect/Path";
8 import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
9 import * as HostProcess from "@t3tools/shared/HostProcess";
10 import { vi } from "vite-plus/test";
11
12 import * as ProcessRunner from "../processRunner.ts";
13 import { sourceControlDefinitions } from "../sourceControl/sourceControlDefinitions.ts";
14 import * as RepositoryIdentityResolver from "./RepositoryIdentityResolver.ts";
15
16 const normalizePathSeparators = (value: string) => value.replaceAll("\\", "/");
17 const normalizeResolvedPath = (value: string) => normalizePathSeparators(value);
18
19 // Windows forbids CR and LF in file names.
20 const lineBreakSuffixes = HostProcess.Platform.defaultValue() === "win32" ? [] : ["\r", "\n"];
21 const bareLayouts = [
22 "bare clone",
23 "dot-bare",
24 ...lineBreakSuffixes.map((suffix) => `bare clone${suffix}`),
25 ];
26
27 const git = (cwd: string, args: ReadonlyArray<string>) =>
28 Effect.gen(function* () {
29 const processRunner = yield* ProcessRunner.ProcessRunner;
30 return yield* processRunner.run({
31 command: "git",
32 args: ["-C", cwd, ...args],
33 });
34 }).pipe(Effect.provide(ProcessRunner.layer));
35
36 it.layer(NodeServices.layer)("RepositoryIdentityResolverLive", (it) => {
37 it.effect("normalizes equivalent GitHub remotes into a stable repository identity", () =>
38 Effect.gen(function* () {
39 const fileSystem = yield* FileSystem.FileSystem;
40 const path = yield* Path.Path;
41 const cwd = yield* fileSystem.makeTempDirectoryScoped({
42 prefix: "t3-repository-identity-test-",
43 });
44
45 yield* git(cwd, ["init"]);
46 yield* git(cwd, ["remote", "add", "origin", "git@github.com:T3Tools/t3code.git"]);
47
48 const resolver = yield* RepositoryIdentityResolver.RepositoryIdentityResolver;
49 const identity = yield* resolver.resolve(cwd);
50 // Native realpath matches git's long paths when Windows temp dirs use 8.3 names.
51 const resolvedIdentityRoot =
52 identity?.rootPath === undefined ? "" : NodeFS.realpathSync.native(identity.rootPath);
53 const resolvedCwd = NodeFS.realpathSync.native(cwd);
54
55 expect(identity).not.toBeNull();
56 expect(identity?.canonicalKey).toBe("github.com/t3tools/t3code");
57 expect(normalizeResolvedPath(resolvedIdentityRoot)).toBe(normalizeResolvedPath(resolvedCwd));
58 expect(identity?.displayName).toBe("T3Tools/t3code");
59 expect(identity?.provider).toBe("github");
60 expect(identity?.owner).toBe("T3Tools");
61 expect(identity?.name).toBe("t3code");
62 expect(yield* resolver.resolve(path.join(cwd, ".git"))).toBeNull();
63 }).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
64 );
65
66 it.effect("identifies the host of an SSH remote that leaves its user to ssh config", () =>
67 Effect.gen(function* () {
68 const fileSystem = yield* FileSystem.FileSystem;
69 const cwd = yield* fileSystem.makeTempDirectoryScoped({
70 prefix: "t3-repository-identity-userless-remote-test-",
71 });
72
73 yield* git(cwd, ["init"]);
74 yield* git(cwd, ["remote", "add", "origin", "github.com:T3Tools/t3code.git"]);
75
76 const resolver = yield* RepositoryIdentityResolver.RepositoryIdentityResolver;
77 const identity = yield* resolver.resolve(cwd);
78
79 expect(identity?.canonicalKey).toBe("github.com/t3tools/t3code");
80 expect(identity?.provider).toBe("github");
81 expect(identity?.displayName).toBe("T3Tools/t3code");
82 }).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
83 );
84
85 it.effect("keys a remote behind an SSH host alias by the host ssh config resolves it to", () =>
86 Effect.gen(function* () {
87 const fileSystem = yield* FileSystem.FileSystem;
88 const aliasDir = yield* fileSystem.makeTempDirectoryScoped({
89 prefix: "t3-repository-identity-ssh-alias-test-",
90 });
91 const plainDir = yield* fileSystem.makeTempDirectoryScoped({
92 prefix: "t3-repository-identity-ssh-plain-test-",
93 });
94
95 yield* git(aliasDir, ["init"]);
96 yield* git(aliasDir, ["remote", "add", "origin", "git@github.com-personal:owner/repo.git"]);
97 yield* git(plainDir, ["init"]);
98 yield* git(plainDir, ["remote", "add", "origin", "git@github.com:owner/repo.git"]);
99
100 const runner = yield* ProcessRunner.ProcessRunner;
101 // Stands in for `Host github.com-personal` / `HostName github.com` in ~/.ssh/config.
102 const resolver = yield* RepositoryIdentityResolver.make().pipe(
103 Effect.provideService(ProcessRunner.ProcessRunner, {
104 run: (input) =>
105 input.command === "ssh" && input.args.includes("-G")
106 ? Effect.succeed({
107 stdout: input.args.some((arg) => arg.includes("github.com-personal"))
108 ? "user git\nhostname github.com\nport 22\n"
109 : `hostname ${input.args.at(-1) ?? ""}\nport 22\n`,
110 stderr: "",
111 code: ChildProcessSpawner.ExitCode(0),
112 timedOut: false,
113 stdoutTruncated: false,
114 stderrTruncated: false,
115 stdoutInvalidUtf8: false,
116 stderrInvalidUtf8: false,
117 })
118 : runner.run(input),
119 }),
120 );
121
122 const aliasIdentity = yield* resolver.resolve(aliasDir);
123 const plainIdentity = yield* resolver.resolve(plainDir);
124
125 expect(plainIdentity?.canonicalKey).toBe("github.com/owner/repo");
126 expect(aliasIdentity?.canonicalKey).toBe(plainIdentity?.canonicalKey);
127 expect(aliasIdentity?.locator.remoteUrl).toBe("git@github.com-personal:owner/repo.git");
128 }).pipe(Effect.provide(ProcessRunner.layer)),
129 );
130
131 it.effect("keeps a literal .git in an Azure DevOps repository name", () =>
132 Effect.gen(function* () {
133 const fileSystem = yield* FileSystem.FileSystem;
134 const cwd = yield* fileSystem.makeTempDirectoryScoped({
135 prefix: "t3-repository-identity-azure-git-suffix-test-",
136 });
137
138 yield* git(cwd, ["init"]);
139 yield* git(cwd, [
140 "remote",
141 "add",
142 "origin",
143 "https://dev.azure.com/Acme/Platform/_git/Tool.git",
144 ]);
145
146 const resolver = yield* RepositoryIdentityResolver.RepositoryIdentityResolver;
147 const identity = yield* resolver.resolve(cwd);
148
149 expect(identity?.displayName).toBe("Acme/Platform/_git/Tool.git");
150 expect(identity?.name).toBe("Tool.git");
151 expect(sourceControlDefinitions.repositorySelector(identity)).toBe("Tool.git");
152 }).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
153 );
154
155 it.effect("resolves the fetch remote of a partial clone", () =>
156 Effect.gen(function* () {
157 const fileSystem = yield* FileSystem.FileSystem;
158 const cwd = yield* fileSystem.makeTempDirectoryScoped({
159 prefix: "t3-repository-identity-partial-clone-test-",
160 });
161
162 yield* git(cwd, ["init"]);
163 yield* git(cwd, ["remote", "add", "origin", "git@github.com:T3Tools/t3code.git"]);
164 yield* git(cwd, ["remote", "set-url", "--push", "origin", "git@github.com:T3Tools/push.git"]);
165 yield* git(cwd, ["config", "remote.origin.promisor", "true"]);
166 yield* git(cwd, ["config", "remote.origin.partialclonefilter", "blob:none"]);
167
168 const remotes = yield* git(cwd, ["remote", "-v"]);
169 expect(remotes.stdout).toContain("(fetch) [blob:none]");
170
171 const resolver = yield* RepositoryIdentityResolver.RepositoryIdentityResolver;
172 const identity = yield* resolver.resolve(cwd);
173 expect(identity?.canonicalKey).toBe("github.com/t3tools/t3code");
174 expect(identity?.locator.remoteUrl).toBe("git@github.com:T3Tools/t3code.git");
175 expect(identity?.locator.remoteName).toBe("origin");
176 }).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
177 );
178
179 it.effect("resolves a remote whose URL contains a space", () =>
180 Effect.gen(function* () {
181 const fileSystem = yield* FileSystem.FileSystem;
182 const cwd = yield* fileSystem.makeTempDirectoryScoped({
183 prefix: "t3-repository-identity-spaced-url-test-",
184 });
185
186 yield* git(cwd, ["init"]);
187 yield* git(cwd, ["remote", "add", "origin", "ssh://git@git.example.test/team repos/app.git"]);
188
189 const resolver = yield* RepositoryIdentityResolver.RepositoryIdentityResolver;
190 const identity = yield* resolver.resolve(cwd);
191 expect(identity?.locator.remoteUrl).toBe("ssh://git@git.example.test/team repos/app.git");
192 expect(identity?.locator.remoteName).toBe("origin");
193 }).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
194 );
195
196 it.effect.each(["repo", "repo ", ...lineBreakSuffixes.map((suffix) => `repo${suffix}`)])(
197 "returns the git top-level root path when resolving from a nested workspace in %j",
198 (rootName) =>
199 Effect.gen(function* () {
200 const fileSystem = yield* FileSystem.FileSystem;
201 const path = yield* Path.Path;
202 const tempDir = yield* fileSystem.makeTempDirectoryScoped({
203 prefix: "t3-repository-identity-nested-root-test-",
204 });
205 const repoRoot = path.join(tempDir, rootName);
206 const nestedWorkspace = path.join(repoRoot, "packages", "web");
207
208 yield* fileSystem.makeDirectory(nestedWorkspace, { recursive: true });
209 yield* git(repoRoot, ["init"]);
210 yield* git(repoRoot, ["remote", "add", "origin", "git@github.com:T3Tools/t3code.git"]);
211
212 const resolver = yield* RepositoryIdentityResolver.RepositoryIdentityResolver;
213 const identity = yield* resolver.resolve(nestedWorkspace);
214 const resolvedIdentityRoot =
215 identity?.rootPath === undefined ? "" : NodeFS.realpathSync.native(identity.rootPath);
216 const resolvedRepoRoot = NodeFS.realpathSync.native(repoRoot);
217
218 expect(identity).not.toBeNull();
219 expect(identity?.canonicalKey).toBe("github.com/t3tools/t3code");
220 expect(normalizeResolvedPath(resolvedIdentityRoot)).toBe(
221 normalizeResolvedPath(resolvedRepoRoot),
222 );
223 }).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
224 );
225
226 it.effect.each(bareLayouts)(
227 "resolves a %j to its Git directory and the same identity as a checkout",
228 (layout) =>
229 Effect.gen(function* () {
230 const fileSystem = yield* FileSystem.FileSystem;
231 const path = yield* Path.Path;
232 const checkout = yield* fileSystem.makeTempDirectoryScoped({
233 prefix: "t3-repository-identity-checkout-",
234 });
235 const parent = yield* fileSystem.makeTempDirectoryScoped({
236 prefix: "t3-repository-identity-bare-",
237 });
238 const root = path.join(parent, layout);
239 yield* fileSystem.makeDirectory(root);
240 const bareGitDir = layout === "dot-bare" ? path.join(root, ".bare") : root;
241
242 yield* git(checkout, ["init"]);
243 yield* git(checkout, ["remote", "add", "origin", "git@github.com:T3Tools/t3code.git"]);
244 yield* git(root, ["init", "--bare", bareGitDir]);
245 if (layout === "dot-bare") {
246 yield* fileSystem.writeFileString(path.join(root, ".git"), "gitdir: ./.bare\n");
247 }
248 yield* git(root, [
249 "--git-dir",
250 bareGitDir,
251 "remote",
252 "add",
253 "origin",
254 "https://github.com/T3Tools/t3code.git",
255 ]);
256
257 const resolver = yield* RepositoryIdentityResolver.RepositoryIdentityResolver;
258 const checkoutIdentity = yield* resolver.resolve(checkout);
259 expect(checkoutIdentity?.canonicalKey).toBe("github.com/t3tools/t3code");
260 const resolvedBareGitDir = NodeFS.realpathSync.native(bareGitDir);
261 const projectRoots = layout === "dot-bare" ? [root, bareGitDir] : [root];
262
263 for (const projectRoot of projectRoots) {
264 const identity = yield* resolver.resolve(projectRoot);
265 const resolvedIdentityRoot =
266 identity?.rootPath === undefined ? "" : NodeFS.realpathSync.native(identity.rootPath);
267
268 expect(identity).not.toBeNull();
269 expect(identity?.canonicalKey).toBe(checkoutIdentity?.canonicalKey);
270 expect(normalizeResolvedPath(resolvedIdentityRoot)).toBe(
271 normalizeResolvedPath(resolvedBareGitDir),
272 );
273 }
274
275 yield* git(root, ["--git-dir", bareGitDir, "remote", "remove", "origin"]);
276 for (const projectRoot of projectRoots) {
277 expect(yield* resolver.resolve(projectRoot, { refresh: true })).toBeNull();
278 }
279 }).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
280 );
281
282 it.effect(
283 "returns null for non-git, missing and no-remote folders, probing only what can exist",
284 () =>
285 Effect.gen(function* () {
286 const fileSystem = yield* FileSystem.FileSystem;
287 const path = yield* Path.Path;
288 const nonGitDir = yield* fileSystem.makeTempDirectoryScoped({
289 prefix: "t3-repository-identity-non-git-",
290 });
291 const gitDir = yield* fileSystem.makeTempDirectoryScoped({
292 prefix: "t3-repository-identity-no-remote-",
293 });
294
295 yield* git(gitDir, ["init"]);
296
297 const runner = yield* ProcessRunner.ProcessRunner;
298 const runs: Array<ReadonlyArray<string>> = [];
299 const resolver = yield* RepositoryIdentityResolver.make().pipe(
300 Effect.provideService(ProcessRunner.ProcessRunner, {
301 run: (input) =>
302 Effect.suspend(() => {
303 runs.push(input.args);
304 return runner.run(input);
305 }),
306 }),
307 );
308 const bareProbes = () =>
309 runs.filter((args) => args.some((arg) => arg.startsWith("--git-dir=")));
310
311 expect(yield* resolver.resolve(path.join(nonGitDir, "deleted"))).toBeNull();
312 expect(runs).toEqual([]);
313
314 expect(yield* resolver.resolve(nonGitDir)).toBeNull();
315 expect(bareProbes()).toEqual([]);
316
317 expect(yield* resolver.resolve(gitDir)).toBeNull();
318 }).pipe(Effect.provide(ProcessRunner.layer)),
319 );
320
321 it.effect("ignores local-path remotes such as GitButler's gb-local", () =>
322 Effect.gen(function* () {
323 const fileSystem = yield* FileSystem.FileSystem;
324 const localOnlyDir = yield* fileSystem.makeTempDirectoryScoped({
325 prefix: "t3-repository-identity-local-remote-",
326 });
327 const mixedDir = yield* fileSystem.makeTempDirectoryScoped({
328 prefix: "t3-repository-identity-mixed-remote-",
329 });
330
331 yield* git(localOnlyDir, ["init"]);
332 yield* git(localOnlyDir, ["remote", "add", "gb-local", "."]);
333 yield* git(localOnlyDir, ["remote", "add", "backup", "/srv/git/repo.git"]);
334 yield* git(localOnlyDir, ["remote", "add", "archive", "file:///srv/git/repo.git"]);
335 yield* git(mixedDir, ["init"]);
336 yield* git(mixedDir, ["remote", "add", "gb-local", "."]);
337 yield* git(mixedDir, ["remote", "add", "mirror", "git@github.com:T3Tools/t3code.git"]);
338
339 const resolver = yield* RepositoryIdentityResolver.RepositoryIdentityResolver;
340 expect(yield* resolver.resolve(localOnlyDir)).toBeNull();
341
342 const mixedIdentity = yield* resolver.resolve(mixedDir);
343 expect(mixedIdentity?.locator.remoteName).toBe("mirror");
344 expect(mixedIdentity?.canonicalKey).toBe("github.com/t3tools/t3code");
345 }).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
346 );
347
348 it.effect.each(["add", "replace"] as const)(
349 "refreshes the primary upstream after %s before cache expiry",
350 (change) =>
351 Effect.gen(function* () {
352 const fileSystem = yield* FileSystem.FileSystem;
353 const cwd = yield* fileSystem.makeTempDirectoryScoped({
354 prefix: "t3-repository-identity-upstream-test-",
355 });
356
357 yield* git(cwd, ["init"]);
358 yield* git(cwd, ["remote", "add", "origin", "git@github.com:julius/t3code.git"]);
359 if (change === "replace") {
360 yield* git(cwd, ["remote", "add", "upstream", "git@github.com:T3Tools/previous.git"]);
361 }
362
363 const resolver = yield* RepositoryIdentityResolver.RepositoryIdentityResolver;
364 const initialIdentity = yield* resolver.resolve(cwd);
365 expect(initialIdentity?.canonicalKey).toBe(
366 change === "add" ? "github.com/julius/t3code" : "github.com/t3tools/previous",
367 );
368
369 yield* git(cwd, [
370 "remote",
371 change === "add" ? "add" : "set-url",
372 "upstream",
373 "git@github.com:T3Tools/t3code.git",
374 ]);
375 expect(yield* resolver.resolve(cwd)).toEqual(initialIdentity);
376 const identity = yield* resolver.resolve(cwd, { refresh: true });
377
378 expect(identity).not.toBeNull();
379 expect(identity?.locator.remoteName).toBe("upstream");
380 expect(identity?.canonicalKey).toBe("github.com/t3tools/t3code");
381 expect(identity?.displayName).toBe("T3Tools/t3code");
382 expect(yield* resolver.resolve(cwd)).toEqual(identity);
383 }).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
384 );
385
386 it.effect("reports a fork's own remote as origin next to the upstream identity", () =>
387 Effect.gen(function* () {
388 const fileSystem = yield* FileSystem.FileSystem;
389 const cwd = yield* fileSystem.makeTempDirectoryScoped({
390 prefix: "t3-repository-identity-fork-test-",
391 });
392
393 yield* git(cwd, ["init"]);
394 yield* git(cwd, ["remote", "add", "origin", "git@github.com:julius/t3code-fork.git"]);
395 yield* git(cwd, ["remote", "add", "upstream", "git@github.com:T3Tools/t3code.git"]);
396
397 const resolver = yield* RepositoryIdentityResolver.RepositoryIdentityResolver;
398 const identity = yield* resolver.resolve(cwd);
399
400 expect(identity?.canonicalKey).toBe("github.com/t3tools/t3code");
401 expect(identity?.displayName).toBe("T3Tools/t3code");
402 expect(identity?.origin).toEqual({
403 canonicalKey: "github.com/julius/t3code-fork",
404 remoteUrl: "git@github.com:julius/t3code-fork.git",
405 displayName: "julius/t3code-fork",
406 });
407 }).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
408 );
409
410 it.effect("uses the fork as the identity when gh repo set-default points at it", () =>
411 Effect.gen(function* () {
412 const fileSystem = yield* FileSystem.FileSystem;
413 const cwd = yield* fileSystem.makeTempDirectoryScoped({
414 prefix: "t3-repository-identity-gh-default-test-",
415 });
416
417 yield* git(cwd, ["init"]);
418 yield* git(cwd, ["remote", "add", "origin", "git@github.com:julius/t3code-fork.git"]);
419 yield* git(cwd, ["remote", "add", "upstream", "git@github.com:T3Tools/t3code.git"]);
420 yield* git(cwd, ["config", "remote.origin.gh-resolved", "base"]);
421
422 const resolver = yield* RepositoryIdentityResolver.RepositoryIdentityResolver;
423 const identity = yield* resolver.resolve(cwd);
424
425 expect(identity?.canonicalKey).toBe("github.com/julius/t3code-fork");
426 expect(identity?.locator.remoteName).toBe("origin");
427 }).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
428 );
429
430 it.effect("follows an OWNER/REPO mark only to a remote that fetches that repository", () =>
431 Effect.gen(function* () {
432 const fileSystem = yield* FileSystem.FileSystem;
433 const cwd = yield* fileSystem.makeTempDirectoryScoped({
434 prefix: "t3-repository-identity-gh-parent-test-",
435 });
436 const resolver = yield* RepositoryIdentityResolver.RepositoryIdentityResolver;
437 const resolveFresh = () => resolver.resolve(cwd, { refresh: true });
438
439 yield* git(cwd, ["init"]);
440 yield* git(cwd, ["remote", "add", "fork", "https://github.com/julius/t3code-fork.git"]);
441 yield* git(cwd, ["remote", "add", "main", "https://github.com/T3Tools/t3code.git"]);
442 yield* git(cwd, ["remote", "add", "upstream", "https://github.com/other/t3code.git"]);
443 yield* git(cwd, ["config", "remote.fork.gh-resolved", "t3tools/t3code"]);
444 const parent = yield* resolveFresh();
445 expect(parent?.canonicalKey).toBe("github.com/t3tools/t3code");
446 expect(parent?.locator).toEqual({
447 source: "git-remote",
448 remoteName: "main",
449 remoteUrl: "https://github.com/T3Tools/t3code.git",
450 });
451
452 // No remote fetches the marked repository, and several marks leave gh's choice unknown.
453 yield* git(cwd, ["config", "remote.fork.gh-resolved", "someone/else"]);
454 expect((yield* resolveFresh())?.locator.remoteName).toBe("upstream");
455 yield* git(cwd, ["config", "remote.fork.gh-resolved", "base"]);
456 yield* git(cwd, ["config", "remote.main.gh-resolved", "base"]);
457 expect((yield* resolveFresh())?.locator.remoteName).toBe("upstream");
458
459 // The same path on another HTTPS port is a different server.
460 yield* git(cwd, ["config", "--unset", "remote.fork.gh-resolved"]);
461 yield* git(cwd, ["config", "--unset", "remote.main.gh-resolved"]);
462 yield* git(cwd, ["remote", "add", "backup", "https://ghe.example.com:9443/acme/web.git"]);
463 yield* git(cwd, ["remote", "add", "ghe-fork", "https://ghe.example.com:8443/me/web.git"]);
464 yield* git(cwd, ["remote", "add", "ghe-parent", "https://ghe.example.com:8443/acme/web.git"]);
465 yield* git(cwd, ["config", "remote.ghe-fork.gh-resolved", "acme/web"]);
466 expect((yield* resolveFresh())?.locator.remoteName).toBe("ghe-parent");
467 }).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
468 );
469
470 it.effect("reads the project's gh default when the server inherited GIT_DIR", () =>
471 Effect.gen(function* () {
472 const fileSystem = yield* FileSystem.FileSystem;
473 const path = yield* Path.Path;
474 const cwd = yield* fileSystem.makeTempDirectoryScoped({
475 prefix: "t3-repository-identity-gh-default-git-dir-",
476 });
477 const other = yield* fileSystem.makeTempDirectoryScoped({
478 prefix: "t3-repository-identity-inherited-git-dir-",
479 });
480
481 yield* git(cwd, ["init"]);
482 yield* git(cwd, ["remote", "add", "origin", "git@github.com:julius/t3code-fork.git"]);
483 yield* git(cwd, ["remote", "add", "upstream", "git@github.com:T3Tools/t3code.git"]);
484 yield* git(cwd, ["config", "remote.origin.gh-resolved", "base"]);
485 yield* git(other, ["init"]);
486 yield* git(other, ["config", "remote.upstream.gh-resolved", "base"]);
487
488 vi.stubEnv("GIT_DIR", path.join(other, ".git"));
489 yield* Effect.addFinalizer(() => Effect.sync(() => vi.unstubAllEnvs()));
490
491 const resolver = yield* RepositoryIdentityResolver.RepositoryIdentityResolver;
492 const identity = yield* resolver.resolve(cwd);
493
494 expect(identity?.canonicalKey).toBe("github.com/julius/t3code-fork");
495 expect(identity?.locator.remoteName).toBe("origin");
496 }).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
497 );
498
499 it.effect("uses the last remote path segment as the repository name for nested groups", () =>
500 Effect.gen(function* () {
501 const fileSystem = yield* FileSystem.FileSystem;
502 const cwd = yield* fileSystem.makeTempDirectoryScoped({
503 prefix: "t3-repository-identity-nested-group-test-",
504 });
505
506 yield* git(cwd, ["init"]);
507 yield* git(cwd, ["remote", "add", "origin", "git@gitlab.com:T3Tools/platform/t3code.git"]);
508
509 const resolver = yield* RepositoryIdentityResolver.RepositoryIdentityResolver;
510 const identity = yield* resolver.resolve(cwd);
511
512 expect(identity).not.toBeNull();
513 expect(identity?.canonicalKey).toBe("gitlab.com/t3tools/platform/t3code");
514 expect(identity?.displayName).toBe("T3Tools/platform/t3code");
515 expect(identity?.owner).toBe("T3Tools");
516 expect(identity?.name).toBe("t3code");
517 }).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
518 );
519 });