Skip to content

Commit e5b851c

Browse files
test(server): build fixture repos and ACP agents once per file
GitVcsDriverCore and GitManager copy a template repo instead of running git init and a first commit in each test. AcpAdapterV2 spawns a bundle of the mock agents built once per file instead of loading their TypeScript graph on every spawn, and stops waiting out real-clock teardown grace and agent timers it does not test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent db07d03 commit e5b851c

3 files changed

Lines changed: 240 additions & 291 deletions

File tree

‎apps/server/src/git/GitManager.test.ts‎

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -205,34 +205,55 @@ function runGit(
205205
});
206206
}
207207

208+
/** A committed repository and an empty bare remote, built once and copied into each test. */
209+
class GitFixtureTemplates extends Context.Service<
210+
GitFixtureTemplates,
211+
{ readonly repo: string; readonly bareRemote: string }
212+
>()("t3/git/GitManager.test/GitFixtureTemplates") {}
213+
214+
const layerGitFixtureTemplates = Layer.effect(
215+
GitFixtureTemplates,
216+
Effect.gen(function* () {
217+
const fs = yield* FileSystem.FileSystem;
218+
const repo = yield* makeTempDir("t3code-git-template-");
219+
// An empty template skips copying git's sample hooks into every test repository.
220+
yield* runGit(repo, ["init", "--initial-branch=main", "--template="]);
221+
yield* runGit(repo, ["config", "user.email", "[email protected]"]);
222+
yield* runGit(repo, ["config", "user.name", "Test User"]);
223+
// Override global autocrlf on Windows for LF assertions, including linked worktrees.
224+
yield* runGit(repo, ["config", "core.autocrlf", "false"]);
225+
yield* fs.writeFileString(NodePath.join(repo, "README.md"), "hello\n");
226+
yield* runGit(repo, ["add", "README.md"]);
227+
yield* runGit(repo, ["commit", "-m", "Initial commit"]);
228+
const bareRemote = yield* makeTempDir("t3code-git-remote-template-");
229+
yield* runGit(bareRemote, ["init", "--bare", "--template="]);
230+
yield* fs.makeDirectory(NodePath.join(bareRemote, "hooks"), { recursive: true });
231+
return { repo, bareRemote };
232+
}),
233+
);
234+
208235
function initRepo(
209236
cwd: string,
210-
): Effect.Effect<
211-
void,
212-
PlatformError.PlatformError | GitCommandError,
213-
FileSystem.FileSystem | Scope.Scope | GitVcsDriver.GitVcsDriver
214-
> {
237+
): Effect.Effect<void, PlatformError.PlatformError, FileSystem.FileSystem | GitFixtureTemplates> {
215238
return Effect.gen(function* () {
216239
const fs = yield* FileSystem.FileSystem;
217-
yield* runGit(cwd, ["init", "--initial-branch=main"]);
218-
yield* runGit(cwd, ["config", "user.email", "[email protected]"]);
219-
yield* runGit(cwd, ["config", "user.name", "Test User"]);
220-
// Override global autocrlf on Windows for LF assertions, including linked worktrees.
221-
yield* runGit(cwd, ["config", "core.autocrlf", "false"]);
222-
yield* fs.writeFileString(NodePath.join(cwd, "README.md"), "hello\n");
223-
yield* runGit(cwd, ["add", "README.md"]);
224-
yield* runGit(cwd, ["commit", "-m", "Initial commit"]);
240+
const templates = yield* GitFixtureTemplates;
241+
for (const entry of [".git", "README.md"]) {
242+
yield* fs.copy(NodePath.join(templates.repo, entry), NodePath.join(cwd, entry));
243+
}
225244
});
226245
}
227246

228247
function createBareRemote(): Effect.Effect<
229248
string,
230-
PlatformError.PlatformError | GitCommandError,
231-
FileSystem.FileSystem | Scope.Scope | GitVcsDriver.GitVcsDriver
249+
PlatformError.PlatformError,
250+
FileSystem.FileSystem | Scope.Scope | GitFixtureTemplates
232251
> {
233252
return Effect.gen(function* () {
253+
const fs = yield* FileSystem.FileSystem;
254+
const templates = yield* GitFixtureTemplates;
234255
const remoteDir = yield* makeTempDir("t3code-git-remote-");
235-
yield* runGit(remoteDir, ["init", "--bare"]);
256+
yield* fs.copy(templates.bareRemote, remoteDir, { overwrite: true });
236257
return remoteDir;
237258
});
238259
}
@@ -740,7 +761,8 @@ function makeManager(input?: {
740761

741762
const asThreadId = (threadId: string) => threadId as ThreadId;
742763

743-
const layerGitManagerTest = GitVcsDriver.layer.pipe(
764+
const layerGitManagerTest = layerGitFixtureTemplates.pipe(
765+
Layer.provideMerge(GitVcsDriver.layer),
744766
Layer.provide(ServerConfig.layerTest(process.cwd(), { prefix: "t3-git-manager-test-" })),
745767
Layer.provideMerge(VcsProcess.layer),
746768
Layer.provideMerge(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),

0 commit comments

Comments
 (0)