Open History to see the last commit
1import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
2import * as NodeServices from "@effect/platform-node/NodeServices";
3import { assert, it } from "@effect/vitest";
4import { ProjectId, type ProjectTrackedFolder } from "@t3tools/contracts";
5import * as HostProcess from "@t3tools/shared/HostProcess";
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 ProjectStore from "../orchestration-v2/ProjectStore.ts";
13import * as SqlitePersistence from "../persistence/Sqlite.ts";
14import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
15import * as TaskFolderStore from "./TaskFolderStore.ts";
16import * as WorkspaceFolders from "./WorkspaceFolders.ts";
17β
18const projectId = ProjectId.make("project:workspace-folders");
19β
20const layerFor = (project?: {
21 readonly workspaceRoot: string;
22 readonly trackedFolders: ReadonlyArray<ProjectTrackedFolder>;
23}) =>
24 WorkspaceFolders.layer.pipe(
25 Layer.provide(
26 Layer.mock(ProjectStore.ProjectStoreV2)({
27 get: () =>
28 project === undefined
29 ? Effect.succeedNone
30 : Effect.succeedSome({
31 projectId,
32 title: "Project",
33 hasCustomTitle: false,
34 defaultModelSelection: null,
35 defaultThreadEnvMode: null,
36 autoPull: false,
37 faviconPath: null,
38 projectIcon: null,
39 scripts: [],
40 pinnedAt: null,
41 archivedAt: null,
42 createdAt: "2026-06-21T00:00:00.000Z",
43 updatedAt: "2026-06-21T00:00:00.000Z",
44 deletedAt: null,
45 ...project,
46 }),
47 }),
48 ),
49 Layer.provideMerge(TaskFolderStore.layer.pipe(Layer.provide(SqlitePersistence.layerMemory))),
50 Layer.provideMerge(
51 GitVcsDriver.layer.pipe(
52 Layer.provide(ServerConfig.layerTest(process.cwd(), { prefix: "t3-workspace-folders-" })),
53 Layer.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
54 ),
55 ),
56 );
57β
58/** A real repository at `folder`, with one commit unless `unborn`. */
59const gitRepository = Effect.fnUntraced(function* (folder: string, unborn = false) {
60 const fileSystem = yield* FileSystem.FileSystem;
61 const git = yield* GitVcsDriver.GitVcsDriver;
62 const run = (...args: ReadonlyArray<string>) =>
63 git.execute({ operation: "workspace-folders-test", cwd: folder, args });
64 yield* fileSystem.makeDirectory(folder, { recursive: true });
65 yield* run("init", "-b", "main");
66 if (unborn) return;
67 yield* run(
68 "-c",
69 "user.name=Workspace folders",
70 "-c",
71 "user.email=workspace-folders@example.test",
72 "commit",
73 "--allow-empty",
74 "-m",
75 "initial",
76 );
77});
78β
79// Resolved, so a symlinked temp directory does not show up as a second spelling of each path.
80const makeTempDir = Effect.gen(function* () {
81 const fileSystem = yield* FileSystem.FileSystem;
82 return yield* fileSystem.realPath(
83 yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3code-workspace-folders-" }),
84 );
85});
86β
87it("matches reopened submodule sections by their decoded, case-sensitive names", () => {
88 const gitmodules = String.raw`
89[submodule.Legacy] path = stale
90[SUBMODULE "le\gacy"] path = real
91[submodule "Legacy"] path = another
92`;
93 assert.deepEqual(WorkspaceFolders.parseGitmodulesPaths(gitmodules), ["real", "another"]);
94});
95β
96it.layer(NodeServices.layer)("WorkspaceFolders", (it) => {
97 it.effect("scans child repositories and the folders a code-workspace file lists", () =>
98 Effect.gen(function* () {
99 const fileSystem = yield* FileSystem.FileSystem;
100 const path = yield* Path.Path;
101 const tmp = yield* makeTempDir;
102 const root = path.join(tmp, "wrapper");
103 const outside = path.join(tmp, "outside");
104 // Labels are cut at 128 UTF-16 units; an emoji across the cut is left out whole.
105 const cut = `${"a".repeat(127)}π`;
106 const fits = `${"b".repeat(126)}π`;
107 const padded = `${" ".repeat(127)}π`;
108 for (const folder of [
109 ".git",
110 `${cut}/.git`,
111 `${fits}/.git`,
112 `${padded}/.git`,
113 "api/.git",
114 "web/.git",
115 "unrelated/.git",
116 "sub/.git",
117 "libs/hash/.git",
118 "libs/semi/.git",
119 "libs/a#b/.git",
120 "libs/cont/.git",
121 "libs/inline/.git",
122 "extra/repo/.git",
123 "extra/joined/.git",
124 " notes",
125 "notes",
126 "src/svc/.git",
127 "tree",
128 ".hidden/.git",
129 "node_modules/.git",
130 "../outside/.git",
131 ]) {
132 yield* fileSystem.makeDirectory(path.join(root, folder), { recursive: true });
133 }
134 if (!(yield* HostProcess.isWindows)) {
135 yield* fileSystem.makeDirectory(path.join(root, "trailing "), { recursive: true });
136 }
137 yield* fileSystem.symlink(outside, path.join(root, "linked"));
138 yield* fileSystem.symlink(root, path.join(root, "self"));
139 // A worktree of `api`: its history is that repository's.
140 yield* fileSystem.writeFileString(
141 path.join(root, "tree", ".git"),
142 `gitdir: ${path.join(root, "api", ".git", "worktrees", "tree")}\n`,
143 );
144 // Read as Git reads it: comments, quotes, escapes and keys outside `submodule` sections.
145 yield* fileSystem.writeFileString(
146 path.join(root, ".gitmodules"),
147 [
148 "[include]",
149 "\tpath = extra/repo",
150 '[submodule "sub"]',
151 "\tpath = unrelated",
152 "\tpath = sub",
153 "\turl = https://example.test/sub.git",
154 '[submodule "hash"]',
155 "\tpath = libs/hash # pinned",
156 '[submodule "semi"]',
157 "\tpath = libs/semi ; pinned",
158 '[submodule "quoted"]',
159 '\tpath = "libs/a#b"',
160 '[submodule "cont"]',
161 "\tpath = libs/\\",
162 "cont",
163 '[submodule "inline"] path = libs/inline',
164 '[submodule "joined"]',
165 "\turl = https://example.test/joined.git\\",
166 "\tpath = extra/joined",
167 "",
168 ].join("\n"),
169 );
170 yield* fileSystem.writeFileString(
171 path.join(root, "team.code-workspace"),
172 `{
173 // Editors write comments and trailing commas here.
174 "folders": [
175 // Entries that lead nowhere take none of the room the real ones need.
176 ${Array.from({ length: 130 }, (_, index) => `{ "path": "gone-${index}" },`).join("")}
177 { "path": "api", "name": "API" },
178 { "path": " notes", "name": "Intended" },
179 { "path": "notes ", "name": "TrailingSpace" },
180 { "path": "notes" },
181 { "path": "trailing /", "name": "TrailingSlash" },
182 { "path": "../outside" },
183 { "path": "gone" },
184 { "path": "." },
185 ],
186 }`,
187 );
188β
189 const workspaceFolders = yield* WorkspaceFolders.WorkspaceFolders;
190 assert.deepEqual(yield* workspaceFolders.scan({ workspaceRoot: `${root}${path.sep}` }), {
191 workspaceRoot: root,
192 isGitRepository: true,
193 codeWorkspaceFile: path.join(root, "team.code-workspace"),
194 folders: [
195 {
196 path: path.join(root, "api"),
197 name: "API",
198 isGitRepository: true,
199 source: "code-workspace",
200 },
201 {
202 path: path.join(root, " notes"),
203 name: "Intended",
204 isGitRepository: false,
205 source: "code-workspace",
206 },
207 {
208 path: path.join(root, "notes"),
209 name: "notes",
210 isGitRepository: false,
211 source: "code-workspace",
212 },
213 { path: outside, name: "outside", isGitRepository: true, source: "code-workspace" },
214 { path: path.join(root, padded), name: "π", isGitRepository: true, source: "child" },
215 {
216 path: path.join(root, cut),
217 name: "a".repeat(127),
218 isGitRepository: true,
219 source: "child",
220 },
221 { path: path.join(root, fits), name: fits, isGitRepository: true, source: "child" },
222 // One level below a plain folder is looked into.
223 {
224 path: path.join(root, "extra", "joined"),
225 name: "joined",
226 isGitRepository: true,
227 source: "child",
228 },
229 {
230 path: path.join(root, "extra", "repo"),
231 name: "repo",
232 isGitRepository: true,
233 source: "child",
234 },
235 {
236 path: path.join(root, "src", "svc"),
237 name: "svc",
238 isGitRepository: true,
239 source: "child",
240 },
241 {
242 path: path.join(root, "unrelated"),
243 name: "unrelated",
244 isGitRepository: true,
245 source: "child",
246 },
247 { path: path.join(root, "web"), name: "web", isGitRepository: true, source: "child" },
248 ],
249 });
250 assert.equal(
251 (yield* workspaceFolders.scan({ workspaceRoot: path.join(root, "gone") }).pipe(Effect.flip))
252 ._tag,
253 "WorkspaceFoldersError",
254 );
255 }).pipe(Effect.provide(layerFor())),
256 );
257β
258 it.effect("finds the repositories inside a project folder from disk each time", () =>
259 Effect.gen(function* () {
260 const fileSystem = yield* FileSystem.FileSystem;
261 const path = yield* Path.Path;
262 const tmp = yield* makeTempDir;
263 const workspaceRoot = path.join(tmp, "wrapper");
264 const outside = path.join(tmp, "outside");
265 const repository = (name: string) => path.join(workspaceRoot, "src", name);
266 for (const folder of ["src/api/.git", "src/notes", "docs/.git", "vendor/big/.git", "tree"]) {
267 yield* fileSystem.makeDirectory(path.join(workspaceRoot, folder), { recursive: true });
268 }
269 // A worktree of `docs` follows that repository, even when a workspace file lists it.
270 yield* fileSystem.writeFileString(
271 path.join(workspaceRoot, "tree", ".git"),
272 `gitdir: ${path.join(workspaceRoot, "docs", ".git", "worktrees", "tree")}\n`,
273 );
274 yield* fileSystem.writeFileString(
275 path.join(workspaceRoot, "team.code-workspace"),
276 JSON.stringify({ folders: [{ path: "tree" }] }),
277 );
278 yield* fileSystem.makeDirectory(path.join(outside, ".git"), { recursive: true });
279 // A link to a repository elsewhere is not inside the project.
280 yield* fileSystem.symlink(outside, path.join(workspaceRoot, "linked"));
281 yield* fileSystem.writeFileString(
282 path.join(workspaceRoot, "t3.json"),
283 JSON.stringify({ ignoreRepositories: ["vendor/big"] }),
284 );
285 // The stored list is only trusted for what someone added.
286 const trackedFolders = [
287 { path: path.join(workspaceRoot, "gone"), name: "gone", discovered: true },
288 { path: outside, name: "Outside" },
289 ];
290β
291 yield* Effect.gen(function* () {
292 const workspaceFolders = yield* WorkspaceFolders.WorkspaceFolders;
293 const listed = Effect.map(workspaceFolders.list({ projectId }), ({ folders }) =>
294 folders.map((folder) => [folder.name, folder.path]),
295 );
296 assert.deepEqual(yield* listed, [
297 ["docs", path.join(workspaceRoot, "docs")],
298 ["api", repository("api")],
299 ["Outside", outside],
300 ]);
301 yield* fileSystem.makeDirectory(path.join(repository("web"), ".git"), { recursive: true });
302 yield* fileSystem.remove(repository("api"), { recursive: true });
303 assert.deepEqual(yield* listed, [
304 ["docs", path.join(workspaceRoot, "docs")],
305 ["web", repository("web")],
306 ["Outside", outside],
307 ]);
308 }).pipe(Effect.provide(layerFor({ workspaceRoot, trackedFolders })));
309 }),
310 );
311β
312 it.effect("does not walk a project's folders when t3.json ignores the whole project", () =>
313 Effect.gen(function* () {
314 const fileSystem = yield* FileSystem.FileSystem;
315 const path = yield* Path.Path;
316 const workspaceRoot = yield* makeTempDir;
317 for (const folder of ["api/.git", "src/web/.git", "notes"]) {
318 yield* fileSystem.makeDirectory(path.join(workspaceRoot, folder), { recursive: true });
319 }
320 yield* fileSystem.writeFileString(
321 path.join(workspaceRoot, "t3.json"),
322 JSON.stringify({ ignoreRepositories: ["."] }),
323 );
324 const probed: Array<string> = [];
325 const counting = FileSystem.FileSystem.of({
326 ...fileSystem,
327 readDirectory: (target, options) => {
328 probed.push(target);
329 return fileSystem.readDirectory(target, options);
330 },
331 stat: (target) => {
332 probed.push(target);
333 return fileSystem.stat(target);
334 },
335 });
336β
337 const found = yield* WorkspaceFolders.discoverFolders(workspaceRoot).pipe(
338 Effect.provideService(FileSystem.FileSystem, counting),
339 );
340β
341 assert.deepEqual(found, []);
342 assert.deepEqual(
343 probed.filter((target) => target !== workspaceRoot),
344 [],
345 );
346 }),
347 );
348β
349 it.effect("keeps the folders someone added when a project holds more than fit", () =>
350 Effect.gen(function* () {
351 const fileSystem = yield* FileSystem.FileSystem;
352 const path = yield* Path.Path;
353 const tmp = yield* makeTempDir;
354 const workspaceRoot = path.join(tmp, "wrapper");
355 const outside = path.join(tmp, "outside");
356 const longName = "r".repeat(200);
357 yield* Effect.forEach(
358 [longName, ...Array.from({ length: 130 }, (_, index) => `s${index}`)],
359 (name) =>
360 fileSystem.makeDirectory(path.join(workspaceRoot, "src", name, ".git"), {
361 recursive: true,
362 }),
363 { discard: true },
364 );
365 yield* fileSystem.makeDirectory(outside, { recursive: true });
366β
367 yield* Effect.gen(function* () {
368 const workspaceFolders = yield* WorkspaceFolders.WorkspaceFolders;
369 const { folders } = yield* workspaceFolders.list({ projectId });
370 assert.equal(folders.length, 128);
371 assert.deepEqual(
372 [folders[0]!.name, folders[0]!.path],
373 ["r".repeat(128), path.join(workspaceRoot, "src", longName)],
374 );
375 assert.deepEqual([folders.at(-1)!.name, folders.at(-1)!.path], ["Outside", outside]);
376 }).pipe(
377 Effect.provide(
378 layerFor({ workspaceRoot, trackedFolders: [{ path: outside, name: "Outside" }] }),
379 ),
380 );
381 }),
382 );
383β
384 it.effect("reports each tracked folder's state and grants a thread the ones outside", () =>
385 Effect.gen(function* () {
386 const fileSystem = yield* FileSystem.FileSystem;
387 const path = yield* Path.Path;
388 const tmp = yield* makeTempDir;
389 const workspaceRoot = path.join(tmp, "app");
390 const folder = (name: string, ...segments: ReadonlyArray<string>) => ({
391 name,
392 path: path.join(tmp, ...segments),
393 });
394 const inside = folder("web", "app", "packages", "web");
395 const repository = folder("api", "api");
396 const missing = folder("gone", "gone");
397 const linked = folder("shared", "app", "linked");
398 const shared = path.join(tmp, "shared");
399 const worktree = path.join(tmp, "tree");
400 // `lib` is checked out with a submodule of its own; `docs` was never initialized. A path
401 // listed twice is one submodule. Git reads config keys in any case, so `PATH` declares one.
402 // `ext` is a symlink out of the repository, so what it leads to is no submodule of it.
403 const gitmodules =
404 '[submodule "lib"]\n\tpath = vendor/lib\n[submodule "docs"]\n\tpath = docs\n[submodule "again"]\n\tpath = vendor/lib\n[submodule "out"]\n\tpath = ext/x\n';
405 for (const root of [workspaceRoot, worktree]) {
406 yield* fileSystem.makeDirectory(path.join(root, "vendor", "lib", "deep", ".git"), {
407 recursive: true,
408 });
409 yield* fileSystem.makeDirectory(path.join(root, "docs"), { recursive: true });
410 yield* fileSystem.writeFileString(path.join(root, "vendor", "lib", ".git"), "gitdir: x\n");
411 yield* fileSystem.writeFileString(path.join(root, ".gitmodules"), gitmodules);
412 yield* fileSystem.writeFileString(
413 path.join(root, "vendor", "lib", ".gitmodules"),
414 '[submodule "deep"]\n\tPATH = deep\n',
415 );
416 }
417 for (const directory of [inside.path, shared]) {
418 yield* fileSystem.makeDirectory(directory, { recursive: true });
419 }
420 yield* fileSystem.symlink(shared, linked.path);
421 yield* fileSystem.makeDirectory(path.join(tmp, "elsewhere", "x", ".git"), {
422 recursive: true,
423 });
424 yield* fileSystem.symlink(path.join(tmp, "elsewhere"), path.join(workspaceRoot, "ext"));
425β
426 yield* Effect.gen(function* () {
427 yield* gitRepository(repository.path);
428 const workspaceFolders = yield* WorkspaceFolders.WorkspaceFolders;
429 assert.deepEqual(yield* workspaceFolders.list({ projectId }), {
430 folders: [
431 { ...inside, state: "plain" },
432 { ...repository, state: "git" },
433 { ...missing, state: "missing" },
434 { ...linked, state: "plain" },
435 ],
436 });
437 assert.deepEqual(yield* workspaceFolders.forThread({ projectId, worktreePath: null }), {
438 folders: [
439 { ...inside, isGitRepository: false },
440 { ...repository, isGitRepository: true },
441 { ...linked, isGitRepository: false },
442 ],
443 // A symlink inside the project folder still leads outside it.
444 extraRoots: [repository.path, linked.path, shared],
445 });
446 assert.deepEqual(yield* workspaceFolders.forThread({ projectId, worktreePath: worktree }), {
447 folders: [],
448 extraRoots: [],
449 });
450 const { folders } = yield* workspaceFolders.forThread({ projectId, worktreePath: null });
451 assert.deepEqual(
452 yield* workspaceFolders.submodules({ projectId, worktreePath: null, folders }),
453 [
454 { name: "lib", path: path.join(workspaceRoot, "vendor", "lib"), isGitRepository: true },
455 {
456 name: "deep",
457 path: path.join(workspaceRoot, "vendor", "lib", "deep"),
458 isGitRepository: true,
459 },
460 ],
461 );
462 // A worktree reaches its own submodules, named by where the project folder has them.
463 assert.deepEqual(
464 yield* workspaceFolders.submodules({ projectId, worktreePath: worktree, folders: [] }),
465 [
466 {
467 name: "lib",
468 path: path.join(worktree, "vendor", "lib"),
469 isGitRepository: true,
470 repositoryPath: path.join(workspaceRoot, "vendor", "lib"),
471 },
472 {
473 name: "deep",
474 path: path.join(worktree, "vendor", "lib", "deep"),
475 isGitRepository: true,
476 repositoryPath: path.join(workspaceRoot, "vendor", "lib", "deep"),
477 },
478 ],
479 );
480 }).pipe(
481 Effect.provide(
482 layerFor({ workspaceRoot, trackedFolders: [inside, repository, missing, linked] }),
483 ),
484 );
485 }),
486 );
487 it.effect("marks a tracked repository that has no commit yet", () =>
488 Effect.gen(function* () {
489 const fileSystem = yield* FileSystem.FileSystem;
490 const path = yield* Path.Path;
491 const workspaceRoot = yield* makeTempDir;
492 const api = { name: "api", path: path.join(workspaceRoot, "api"), discovered: true };
493 // Git cannot read it, which says nothing about its commits.
494 const broken = { name: "broken", path: path.join(workspaceRoot, "broken"), discovered: true };
495 yield* fileSystem.makeDirectory(path.join(broken.path, ".git"), { recursive: true });
496 const scratch = {
497 name: "scratch",
498 path: path.join(workspaceRoot, "scratch"),
499 discovered: true,
500 };
501β
502 yield* Effect.gen(function* () {
503 yield* gitRepository(api.path);
504 yield* gitRepository(scratch.path, true);
505 const workspaceFolders = yield* WorkspaceFolders.WorkspaceFolders;
506 assert.deepEqual(yield* workspaceFolders.list({ projectId }), {
507 folders: [
508 { ...api, state: "git" },
509 { ...broken, state: "git" },
510 { ...scratch, state: "git", hasCommits: false },
511 ],
512 });
513 }).pipe(Effect.provide(layerFor({ workspaceRoot, trackedFolders: [] })));
514 }),
515 );
516β
517 it.effect("gives a task folder thread its worktrees, never the checkouts they came from", () =>
518 Effect.gen(function* () {
519 const fileSystem = yield* FileSystem.FileSystem;
520 const path = yield* Path.Path;
521 const tmp = yield* makeTempDir;
522 const ctx = path.join(tmp, "x", "ctx");
523 const app = path.join(tmp, "x", "app");
524 const lib = path.join(ctx, "vendor", "lib");
525 // The worktrees directory is reached through a symlink, as on a machine that moved it.
526 const realWorktrees = path.join(tmp, "disk", "worktrees");
527 const worktrees = path.join(tmp, "worktrees");
528 const taskRoot = path.join(worktrees, "x", "feature-0123");
529 for (const directory of [
530 lib,
531 app,
532 path.join(realWorktrees, "x", "feature-0123", "ctx", "vendor", "lib"),
533 path.join(realWorktrees, "x", "feature-0123", "app"),
534 path.join(realWorktrees, "x", "single"),
535 ]) {
536 yield* fileSystem.makeDirectory(directory, { recursive: true });
537 }
538 yield* fileSystem.symlink(realWorktrees, worktrees);
539 const trackedFolders = [
540 { name: "app", path: app },
541 { name: "lib", path: lib },
542 ];
543β
544 yield* Effect.gen(function* () {
545 const taskFolders = yield* TaskFolderStore.TaskFolderStore;
546 const workspaceFolders = yield* WorkspaceFolders.WorkspaceFolders;
547 const taskFolder = {
548 root: taskRoot,
549 projectId,
550 projectRoot: ctx,
551 anchor: path.join(tmp, "x"),
552 projectPath: path.join(taskRoot, "ctx"),
553 projectIsWorktree: true,
554 repositories: [
555 { repositoryPath: app, worktreePath: path.join(taskRoot, "app"), name: "app" },
556 {
557 repositoryPath: lib,
558 worktreePath: path.join(taskRoot, "ctx", "vendor", "lib"),
559 name: "lib",
560 },
561 ],
562 };
563 yield* taskFolders.put(taskFolder);
564 const expected = {
565 folders: [
566 {
567 name: "app",
568 path: path.join(taskRoot, "app"),
569 isGitRepository: true,
570 repositoryPath: app,
571 },
572 {
573 name: "lib",
574 path: path.join(taskRoot, "ctx", "vendor", "lib"),
575 isGitRepository: true,
576 repositoryPath: lib,
577 },
578 ],
579 // Only the sibling lies outside the thread's folder, under both of its spellings.
580 extraRoots: [
581 path.join(taskRoot, "app"),
582 path.join(realWorktrees, "x", "feature-0123", "app"),
583 ],
584 };
585 // The thread stores the path as named; a sandbox or Git may hand back the resolved one.
586 for (const worktreePath of [
587 path.join(taskRoot, "ctx"),
588 path.join(realWorktrees, "x", "feature-0123", "ctx"),
589 ]) {
590 assert.deepEqual(
591 yield* workspaceFolders.forThread({ projectId, worktreePath }),
592 expected,
593 );
594 }
595 assert.deepEqual(
596 yield* taskFolders.findContaining(
597 path.join(realWorktrees, "x", "feature-0123", "app", "src"),
598 ),
599 taskFolder,
600 );
601 // A single worktree beside it is no task folder.
602 assert.deepEqual(
603 yield* workspaceFolders.forThread({
604 projectId,
605 worktreePath: path.join(worktrees, "x", "single"),
606 }),
607 { folders: [], extraRoots: [] },
608 );
609 }).pipe(Effect.provide(layerFor({ workspaceRoot: ctx, trackedFolders })));
610 }),
611 );
612 it.effect("gives a task folder thread the tracked repositories checked out in it later", () =>
613 Effect.gen(function* () {
614 const fileSystem = yield* FileSystem.FileSystem;
615 const path = yield* Path.Path;
616 const tmp = yield* makeTempDir;
617 const project = path.join(tmp, "project");
618 const taskRoot = path.join(tmp, "worktrees", "feature");
619 for (const name of ["web", "backend", "mobile"]) {
620 yield* fileSystem.makeDirectory(path.join(project, name, ".git"), { recursive: true });
621 }
622 yield* fileSystem.makeDirectory(path.join(taskRoot, "web"), { recursive: true });
623 yield* fileSystem.makeDirectory(path.join(taskRoot, "mobile"), { recursive: true });
624 // A linked worktree keeps `.git` as a file; `mobile` was never checked out.
625 yield* fileSystem.writeFileString(path.join(taskRoot, "web", ".git"), "gitdir: elsewhere\n");
626β
627 yield* Effect.gen(function* () {
628 const taskFolders = yield* TaskFolderStore.TaskFolderStore;
629 const workspaceFolders = yield* WorkspaceFolders.WorkspaceFolders;
630 yield* taskFolders.put({
631 root: taskRoot,
632 projectId,
633 projectRoot: project,
634 anchor: project,
635 projectPath: taskRoot,
636 projectIsWorktree: true,
637 repositories: [],
638 });
639 assert.deepEqual(yield* workspaceFolders.forThread({ projectId, worktreePath: taskRoot }), {
640 folders: [
641 {
642 name: "web",
643 path: path.join(taskRoot, "web"),
644 isGitRepository: true,
645 repositoryPath: path.join(project, "web"),
646 },
647 ],
648 extraRoots: [],
649 });
650 }).pipe(Effect.provide(layerFor({ workspaceRoot: project, trackedFolders: [] })));
651 }),
652 );
653});