Open History to see the last commit
1// @effect-diagnostics nodeBuiltinImport:off - FileSystem cannot create a FIFO.
2import * as NodeChildProcess from "node:child_process";
3
4import * as NodeServices from "@effect/platform-node/NodeServices";
5import { it, describe, expect } from "@effect/vitest";
6import * as Effect from "effect/Effect";
7import * as FileSystem from "effect/FileSystem";
8import * as Layer from "effect/Layer";
9import * as Path from "effect/Path";
10
11import * as ServerConfig from "../config.ts";
12import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts";
13import * as VcsProcess from "../vcs/VcsProcess.ts";
14import * as KnownWorkspaces from "./KnownWorkspaces.ts";
15import * as WorkspaceEntries from "./WorkspaceEntries.ts";
16import * as WorkspaceFileSystem from "./WorkspaceFileSystem.ts";
17import * as WorkspacePaths from "./WorkspacePaths.ts";
18import * as HostProcess from "@t3tools/shared/HostProcess";
19import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
20
21// Temp folders count as known workspaces unless named as unknown.
22const UNKNOWN_WORKSPACE_PREFIX = "t3code-unknown-workspace-";
23const layerKnownWorkspacesTest = Layer.mock(KnownWorkspaces.KnownWorkspaces)({
24 assertContains: (cwd) =>
25 cwd.includes(UNKNOWN_WORKSPACE_PREFIX)
26 ? Effect.fail(new KnownWorkspaces.UnknownWorkspaceError({ cwd }))
27 : Effect.void,
28});
29
30const layerProject = WorkspaceFileSystem.layer.pipe(
31 Layer.provide(layerKnownWorkspacesTest),
32 Layer.provide(WorkspacePaths.layer),
33 Layer.provide(WorkspaceEntries.layer.pipe(Layer.provide(WorkspacePaths.layer))),
34);
35
36const layerTest = Layer.empty.pipe(
37 Layer.provideMerge(layerProject),
38 Layer.provideMerge(WorkspaceEntries.layer.pipe(Layer.provide(WorkspacePaths.layer))),
39 Layer.provideMerge(WorkspacePaths.layer),
40 Layer.provideMerge(VcsDriverRegistry.layer.pipe(Layer.provide(VcsProcess.layer))),
41 Layer.provide(
42 ServerConfig.ServerConfig.layerTest(process.cwd(), {
43 prefix: "t3-workspace-files-test-",
44 }),
45 ),
46 Layer.provideMerge(NodeServices.layer),
47);
48
49const makeTempDir = Effect.gen(function* () {
50 const fileSystem = yield* FileSystem.FileSystem;
51 return yield* fileSystem.makeTempDirectoryScoped({
52 prefix: "t3code-workspace-files-",
53 });
54});
55
56const writeTextFile = Effect.fn("writeTextFile")(function* (
57 cwd: string,
58 relativePath: string,
59 contents = "",
60) {
61 const fileSystem = yield* FileSystem.FileSystem;
62 const path = yield* Path.Path;
63 const absolutePath = path.join(cwd, relativePath);
64 yield* fileSystem
65 .makeDirectory(path.dirname(absolutePath), { recursive: true })
66 .pipe(Effect.orDie);
67 yield* fileSystem.writeFileString(absolutePath, contents).pipe(Effect.orDie);
68});
69
70it.layer(layerTest, { excludeTestServices: true })("WorkspaceFileSystemLive", (it) => {
71 describe("getMetadata", () => {
72 it.effect(
73 "reports actual kinds for extensionless files, dotfiles, and dotted directories",
74 () =>
75 Effect.gen(function* () {
76 const service = yield* WorkspaceFileSystem.WorkspaceFileSystem;
77 const fs = yield* FileSystem.FileSystem;
78 const path = yield* Path.Path;
79 const cwd = yield* makeTempDir;
80 yield* writeTextFile(cwd, "custom-name", "hello");
81 yield* writeTextFile(cwd, ".npmrc", "registry=test");
82 yield* fs.makeDirectory(path.join(cwd, "folder.ts"));
83 const file = path.join(cwd, "custom-name");
84 const result = yield* service.getMetadata({
85 paths: [
86 file,
87 path.join(cwd, ".npmrc"),
88 path.join(cwd, "folder.ts"),
89 file,
90 path.join(cwd, "missing"),
91 "relative-path",
92 ],
93 });
94 expect(result.entries).toEqual([
95 { kind: "file", byteLength: 5 },
96 { kind: "file", byteLength: 13 },
97 { kind: "directory" },
98 { kind: "file", byteLength: 5 },
99 null,
100 null,
101 ]);
102 }),
103 );
104
105 it.effect("detects an extensionless script and image without returning their contents", () =>
106 Effect.gen(function* () {
107 const service = yield* WorkspaceFileSystem.WorkspaceFileSystem;
108 const fs = yield* FileSystem.FileSystem;
109 const path = yield* Path.Path;
110 const cwd = yield* makeTempDir;
111 const script = "#!/usr/bin/env python3\nprint('hello')\n";
112 yield* writeTextFile(cwd, "run", script);
113 const image = path.join(cwd, "image");
114 yield* fs.writeFile(
115 image,
116 new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]),
117 );
118 expect(
119 (yield* service.getMetadata({ paths: [path.join(cwd, "run"), image] })).entries,
120 ).toEqual([
121 { kind: "file", byteLength: script.length, mimeType: "text/x-python" },
122 { kind: "file", byteLength: 8, mimeType: "image/png" },
123 ]);
124 }),
125 );
126 });
127
128 describe("readFile", () => {
129 it.effect("reads host files outside the workspace root by absolute path", () =>
130 Effect.gen(function* () {
131 const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
132 const path = yield* Path.Path;
133 const cwd = yield* makeTempDir;
134 const outsideDir = yield* makeTempDir;
135 yield* writeTextFile(outsideDir, "cleanup-report.md", "# Report\n");
136 const absolutePath = path.join(outsideDir, "cleanup-report.md");
137
138 const result = yield* workspaceFileSystem.readFile({
139 cwd,
140 relativePath: absolutePath,
141 });
142
143 expect(result).toEqual({
144 relativePath: absolutePath,
145 contents: "# Report\n",
146 byteLength: 9,
147 truncated: false,
148 });
149 }),
150 );
151
152 it.effect("reads ~/ paths from the server home outside the workspace", () =>
153 Effect.gen(function* () {
154 const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
155 const cwd = yield* makeTempDir;
156 const home = yield* makeTempDir;
157 yield* writeTextFile(home, ".claude/CLAUDE.md", "# Notes\n");
158 yield* writeTextFile(cwd, "~/.claude/CLAUDE.md", "Workspace decoy\n");
159
160 const result = yield* workspaceFileSystem
161 .readFile({ cwd, relativePath: "~/.claude/CLAUDE.md" })
162 .pipe(Effect.provideService(HostProcess.HomeDirectory, home));
163
164 expect(result).toEqual({
165 relativePath: "~/.claude/CLAUDE.md",
166 contents: "# Notes\n",
167 byteLength: 8,
168 truncated: false,
169 });
170 }),
171 );
172
173 it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")(
174 "rejects a FIFO without blocking on open",
175 () =>
176 Effect.gen(function* () {
177 const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
178 const path = yield* Path.Path;
179 const cwd = yield* makeTempDir;
180 const outsideDir = yield* makeTempDir;
181 const fifoPath = path.join(outsideDir, "pipe");
182 yield* Effect.promise(
183 () =>
184 new Promise<void>((resolve, reject) =>
185 NodeChildProcess.execFile("mkfifo", [fifoPath], (error) =>
186 error ? reject(error) : resolve(),
187 ),
188 ),
189 );
190
191 const error = yield* workspaceFileSystem
192 .readFile({ cwd, relativePath: fifoPath })
193 .pipe(Effect.flip);
194
195 expect(error).toBeInstanceOf(WorkspaceFileSystem.WorkspacePathNotFileError);
196 expect((yield* workspaceFileSystem.getMetadata({ paths: [fifoPath] })).entries).toEqual([
197 { kind: "other" },
198 ]);
199 }),
200 );
201
202 it.effect.skipIf(!symlinksSupported)(
203 "rejects symlinks that resolve outside the workspace root",
204 () =>
205 Effect.gen(function* () {
206 const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
207 const fileSystem = yield* FileSystem.FileSystem;
208 const path = yield* Path.Path;
209 const cwd = yield* makeTempDir;
210 const outsideDir = yield* makeTempDir;
211 yield* writeTextFile(outsideDir, "secret.txt", "outside\n");
212 yield* fileSystem.symlink(
213 path.join(outsideDir, "secret.txt"),
214 path.join(cwd, "linked-secret.txt"),
215 );
216
217 const error = yield* workspaceFileSystem
218 .readFile({ cwd, relativePath: "linked-secret.txt" })
219 .pipe(Effect.flip);
220 const resolvedWorkspaceRoot = yield* fileSystem.realPath(cwd);
221 const resolvedPath = yield* fileSystem.realPath(path.join(outsideDir, "secret.txt"));
222
223 expect(error).toBeInstanceOf(WorkspaceFileSystem.WorkspaceFilePathEscapeError);
224 expect(error).toMatchObject({
225 workspaceRoot: cwd,
226 relativePath: "linked-secret.txt",
227 resolvedWorkspaceRoot,
228 resolvedPath,
229 });
230 expect("cause" in error).toBe(false);
231
232 yield* fileSystem.symlink(outsideDir, path.join(cwd, "linked-dir"));
233 const missingChildError = yield* workspaceFileSystem
234 .readFile(
235 Object.assign(
236 { cwd, relativePath: "linked-dir/missing/t3.json" },
237 { allowMissing: true },
238 ),
239 )
240 .pipe(Effect.flip);
241 expect(missingChildError).toBeInstanceOf(
242 WorkspaceFileSystem.WorkspaceFilePathEscapeError,
243 );
244 }),
245 );
246
247 it.effect("rejects binary files without leaking their contents into the error", () =>
248 Effect.gen(function* () {
249 const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
250 const fileSystem = yield* FileSystem.FileSystem;
251 const path = yield* Path.Path;
252 const cwd = yield* makeTempDir;
253 const absolutePath = path.join(cwd, "asset.bin");
254 yield* fileSystem.writeFile(absolutePath, Uint8Array.from([0x61, 0, 0x62]));
255
256 const error = yield* workspaceFileSystem
257 .readFile({ cwd, relativePath: "asset.bin" })
258 .pipe(Effect.flip);
259 const resolvedPath = yield* fileSystem.realPath(absolutePath);
260
261 expect(error).toBeInstanceOf(WorkspaceFileSystem.WorkspaceBinaryFileError);
262 expect(error).toMatchObject({
263 workspaceRoot: cwd,
264 relativePath: "asset.bin",
265 resolvedPath,
266 });
267 expect("cause" in error).toBe(false);
268 expect("contents" in error).toBe(false);
269 }),
270 );
271 });
272
273 describe("writeFile", () => {
274 it.effect("rejects writes outside a known workspace", () =>
275 Effect.gen(function* () {
276 const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
277 const fileSystem = yield* FileSystem.FileSystem;
278 const cwd = yield* fileSystem.makeTempDirectoryScoped({
279 prefix: UNKNOWN_WORKSPACE_PREFIX,
280 });
281
282 const error = yield* workspaceFileSystem
283 .writeFile({ cwd, relativePath: "plan.md", contents: "# nope\n" })
284 .pipe(Effect.flip);
285
286 expect(error).toBeInstanceOf(KnownWorkspaces.UnknownWorkspaceError);
287 expect(yield* fileSystem.readDirectory(cwd)).toEqual([]);
288 }),
289 );
290
291 it.effect("rejects writes by absolute path", () =>
292 Effect.gen(function* () {
293 const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
294 const path = yield* Path.Path;
295 const cwd = yield* makeTempDir;
296 const outsideDir = yield* makeTempDir;
297 const absolutePath = path.join(outsideDir, "cleanup-report.md");
298
299 const error = yield* workspaceFileSystem
300 .writeFile({ cwd, relativePath: absolutePath, contents: "# Edited\n" })
301 .pipe(Effect.flip);
302
303 expect(error).toBeInstanceOf(WorkspacePaths.WorkspacePathOutsideRootError);
304 }),
305 );
306
307 it.effect("invalidates workspace entry search cache after writes", () =>
308 Effect.gen(function* () {
309 const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries;
310 const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
311 const cwd = yield* makeTempDir;
312 yield* writeTextFile(cwd, "src/existing.ts", "export {};\n");
313
314 const beforeWrite = yield* workspaceEntries.list({ cwd });
315 expect(beforeWrite.entries.some((entry) => entry.path === "plans/effect-rpc.md")).toBe(
316 false,
317 );
318
319 yield* workspaceFileSystem.writeFile({
320 cwd,
321 relativePath: "plans/effect-rpc.md",
322 contents: "# Plan\n",
323 });
324
325 const afterWrite = yield* workspaceEntries.list({ cwd });
326 expect(afterWrite.entries).toEqual(
327 expect.arrayContaining([expect.objectContaining({ path: "plans/effect-rpc.md" })]),
328 );
329 expect(afterWrite.truncated).toBe(false);
330 }),
331 );
332
333 it.effect("rejects writes outside the workspace root", () =>
334 Effect.gen(function* () {
335 const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
336 const cwd = yield* makeTempDir;
337 const path = yield* Path.Path;
338 const fileSystem = yield* FileSystem.FileSystem;
339
340 const error = yield* workspaceFileSystem
341 .writeFile({
342 cwd,
343 relativePath: "../escape.md",
344 contents: "# nope\n",
345 })
346 .pipe(Effect.flip);
347
348 expect(error.message).toContain(
349 "Workspace file path must be relative to the project root: ../escape.md",
350 );
351
352 const escapedPath = path.resolve(cwd, "..", "escape.md");
353 const escapedStat = yield* fileSystem
354 .stat(escapedPath)
355 .pipe(Effect.orElseSucceed(() => null));
356 expect(escapedStat).toBeNull();
357 }),
358 );
359
360 it.effect.skipIf(!symlinksSupported)(
361 "rejects writes through symlinks that resolve outside the workspace root",
362 () =>
363 Effect.gen(function* () {
364 const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
365 const fileSystem = yield* FileSystem.FileSystem;
366 const path = yield* Path.Path;
367 const cwd = yield* makeTempDir;
368 const outsideDir = yield* makeTempDir;
369 yield* writeTextFile(outsideDir, "existing.md", "outside\n");
370 yield* fileSystem.symlink(outsideDir, path.join(cwd, "linked-dir"));
371 yield* fileSystem.symlink(
372 path.join(outsideDir, "existing.md"),
373 path.join(cwd, "linked-file.md"),
374 );
375 yield* fileSystem.symlink(
376 path.join(outsideDir, "missing.md"),
377 path.join(cwd, "dangling.md"),
378 );
379
380 for (const relativePath of [
381 "linked-dir/new.md",
382 "linked-dir/nested/new.md",
383 "linked-file.md",
384 ]) {
385 const error = yield* workspaceFileSystem
386 .writeFile({ cwd, relativePath, contents: "# nope\n" })
387 .pipe(Effect.flip);
388 expect(error).toBeInstanceOf(WorkspaceFileSystem.WorkspaceFilePathEscapeError);
389 }
390 const danglingError = yield* workspaceFileSystem
391 .writeFile({ cwd, relativePath: "dangling.md", contents: "# nope\n" })
392 .pipe(Effect.flip);
393 expect(danglingError).toBeInstanceOf(
394 WorkspaceFileSystem.WorkspaceFileSystemOperationError,
395 );
396 expect(danglingError).toMatchObject({ operation: "realpath-target" });
397
398 expect((yield* fileSystem.readDirectory(outsideDir)).toSorted()).toEqual(["existing.md"]);
399 expect(yield* fileSystem.readFileString(path.join(outsideDir, "existing.md"))).toBe(
400 "outside\n",
401 );
402 }),
403 );
404
405 it.effect.skipIf(!symlinksSupported)(
406 "writes through symlinks that stay inside the workspace root",
407 () =>
408 Effect.gen(function* () {
409 const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
410 const fileSystem = yield* FileSystem.FileSystem;
411 const path = yield* Path.Path;
412 const parentDir = yield* makeTempDir;
413 const cwd = path.join(parentDir, "workspace");
414 const cwdAlias = path.join(parentDir, "workspace-alias");
415 yield* writeTextFile(cwd, "docs/README.md", "old\n");
416 yield* fileSystem.symlink(path.join(cwd, "docs"), path.join(cwd, "docs-alias"));
417 yield* fileSystem.symlink("docs/README.md", path.join(cwd, "README.md"));
418 yield* fileSystem.symlink(cwd, cwdAlias);
419
420 yield* workspaceFileSystem.writeFile({
421 cwd,
422 relativePath: "docs-alias/plans/plan.md",
423 contents: "# Plan\n",
424 });
425 yield* workspaceFileSystem.writeFile({
426 cwd,
427 relativePath: "README.md",
428 contents: "new\n",
429 });
430 yield* workspaceFileSystem.writeFile({
431 cwd: cwdAlias,
432 relativePath: "notes.md",
433 contents: "notes\n",
434 });
435 // `..` after a link in cwd is resolved by name, as for the relative path.
436 yield* fileSystem.symlink(path.join(cwd, "docs/plans"), path.join(cwd, "plans-alias"));
437 yield* workspaceFileSystem.writeFile({
438 cwd: `${path.join(cwd, "plans-alias")}${path.sep}..`,
439 relativePath: "dotdot.md",
440 contents: "dotdot\n",
441 });
442
443 expect(yield* fileSystem.readFileString(path.join(cwd, "docs/plans/plan.md"))).toBe(
444 "# Plan\n",
445 );
446 expect(yield* fileSystem.readFileString(path.join(cwd, "docs/README.md"))).toBe("new\n");
447 expect(yield* fileSystem.readLink(path.join(cwd, "README.md"))).toBe("docs/README.md");
448 expect(yield* fileSystem.readFileString(path.join(cwd, "notes.md"))).toBe("notes\n");
449 expect(yield* fileSystem.readFileString(path.join(cwd, "dotdot.md"))).toBe("dotdot\n");
450 }),
451 );
452
453 // On Windows `\` is a separator, so the name cannot exist there.
454 it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")(
455 "keeps a backslash in a file name as part of the name",
456 () =>
457 Effect.gen(function* () {
458 const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
459 const fileSystem = yield* FileSystem.FileSystem;
460 const cwd = yield* makeTempDir;
461 yield* writeTextFile(cwd, "a\\b.md", "old\n");
462
463 yield* workspaceFileSystem.writeFile({ cwd, relativePath: "a\\b.md", contents: "new\n" });
464
465 expect(
466 (yield* workspaceFileSystem.readFile({ cwd, relativePath: "a\\b.md" })).contents,
467 ).toBe("new\n");
468 expect(yield* fileSystem.readDirectory(cwd)).toEqual(["a\\b.md"]);
469 }),
470 );
471
472 it.effect("refuses writes into git's own folders", () =>
473 Effect.gen(function* () {
474 const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
475 const fileSystem = yield* FileSystem.FileSystem;
476 const path = yield* Path.Path;
477 const cwd = yield* makeTempDir;
478 yield* writeTextFile(cwd, ".git/config", "[core]\n");
479 // A bare repository named `.bare`, and a linked worktree's git folder inside it.
480 yield* writeTextFile(cwd, ".bare/HEAD", "ref: refs/heads/main\n");
481 yield* writeTextFile(cwd, ".bare/objects/info/packs");
482 yield* writeTextFile(cwd, ".bare/refs/heads/main");
483 yield* writeTextFile(cwd, ".bare/hooks/pre-push.sample");
484 // Only a linked worktree's `.git` file ends the upward check, not any `.git` folder.
485 yield* fileSystem.makeDirectory(path.join(cwd, ".bare/hooks/.git"));
486 yield* writeTextFile(cwd, ".bare/worktrees/main/HEAD", "ref: refs/heads/main\n");
487 yield* writeTextFile(cwd, ".bare/worktrees/main/commondir", "../..\n");
488 if (symlinksSupported) yield* fileSystem.symlink(".git", path.join(cwd, "docs"));
489
490 for (const [folder, relativePath] of [
491 [cwd, ".git/config"],
492 [cwd, ".git/hooks/pre-commit"],
493 [cwd, "sub/.git"],
494 [cwd, ".GIT/config"],
495 [cwd, ".gıt/config"],
496 [cwd, ".git. /config"],
497 [cwd, ".git::$INDEX_ALLOCATION/config"],
498 [cwd, "GIT~1/config"],
499 [path.join(cwd, ".git"), "config"],
500 [cwd, ".bare/config"],
501 [path.join(cwd, ".bare"), "hooks/post-checkout"],
502 [path.join(cwd, ".bare/hooks"), "post-checkout"],
503 [path.join(cwd, ".bare/worktrees/main"), "commondir"],
504 ...(symlinksSupported ? [[cwd, "docs/config"] as const] : []),
505 ] as const) {
506 const error = yield* workspaceFileSystem
507 .writeFile({ cwd: folder, relativePath, contents: "[core]\n\tfsmonitor = x\n" })
508 .pipe(Effect.flip);
509 expect(error).toBeInstanceOf(WorkspaceFileSystem.WorkspaceFilePathEscapeError);
510 }
511
512 expect(yield* fileSystem.readFileString(path.join(cwd, ".git/config"))).toBe("[core]\n");
513 expect(yield* fileSystem.exists(path.join(cwd, ".bare/config"))).toBe(false);
514 expect((yield* fileSystem.readDirectory(path.join(cwd, ".bare/hooks"))).toSorted()).toEqual(
515 [".git", "pre-push.sample"],
516 );
517 expect(yield* fileSystem.exists(path.join(cwd, "sub"))).toBe(false);
518 expect(
519 yield* fileSystem.readFileString(path.join(cwd, ".bare/worktrees/main/commondir")),
520 ).toBe("../..\n");
521 }),
522 );
523
524 it.effect.skipIf(!symlinksSupported)(
525 "refuses writes through a git config that links to a file outside git's folders",
526 () =>
527 Effect.gen(function* () {
528 const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
529 const fileSystem = yield* FileSystem.FileSystem;
530 const path = yield* Path.Path;
531 const cwd = yield* makeTempDir;
532 yield* writeTextFile(cwd, "shared/config", "[core]\n");
533 yield* fileSystem.makeDirectory(path.join(cwd, ".git"));
534 yield* fileSystem.symlink("../shared/config", path.join(cwd, ".git/config"));
535
536 const error = yield* workspaceFileSystem
537 .writeFile({ cwd, relativePath: ".git/config", contents: "[core]\n\tfsmonitor = x\n" })
538 .pipe(Effect.flip);
539
540 expect(error).toBeInstanceOf(WorkspaceFileSystem.WorkspaceFilePathEscapeError);
541 expect(yield* fileSystem.readFileString(path.join(cwd, "shared/config"))).toBe(
542 "[core]\n",
543 );
544 }),
545 );
546
547 it.effect("writes files that sit beside git's folders", () =>
548 Effect.gen(function* () {
549 const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
550 const fileSystem = yield* FileSystem.FileSystem;
551 const path = yield* Path.Path;
552 const parentDir = yield* makeTempDir;
553 // A bare repository with a worktree checked out inside it.
554 const bare = path.join(parentDir, "repo.git");
555 yield* writeTextFile(bare, "HEAD", "ref: refs/heads/main\n");
556 yield* writeTextFile(bare, "objects/info/packs");
557 yield* writeTextFile(bare, "refs/heads/main");
558 yield* writeTextFile(bare, "main/.git", `gitdir: ${path.join(bare, "worktrees/main")}\n`);
559
560 for (const [cwd, relativePath] of [
561 [path.join(bare, "main"), ".gitignore"],
562 [path.join(bare, "main"), ".gitattributes"],
563 [path.join(bare, "main"), ".github/workflows/ci.yml"],
564 [path.join(bare, "main"), "vendor/lib.git/README.md"],
565 [path.join(bare, "main/.github"), "CODEOWNERS"],
566 [bare, "main/plan.md"],
567 ] as const) {
568 yield* workspaceFileSystem.writeFile({ cwd, relativePath, contents: "ok\n" });
569 expect(yield* fileSystem.readFileString(path.join(cwd, relativePath))).toBe("ok\n");
570 }
571 }),
572 );
573 });
574});