Skip to content

Commit 58d1f02

Browse files
committed
test(server): speed up git fixture setup
Avoid repeated git config subprocesses in integration fixtures by writing the minimal local test config directly after git init.
1 parent 5aec1a2 commit 58d1f02

13 files changed

Lines changed: 48 additions & 55 deletions

src/server/batch-commit-tool.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { join } from "node:path";
2424
import { isStrictlyUnderGitTop, resolvePathForRepo } from "../repo-paths.js";
2525
import { registerBatchCommitTool } from "./batch-commit-tool.js";
2626
import { spawnGitAsync } from "./git.js";
27-
import { captureTool, cleanupTmpPaths, mkTmpDir } from "./test-harness.js";
27+
import { captureTool, cleanupTmpPaths, mkTmpDir, writeTestGitConfig } from "./test-harness.js";
2828

2929
afterEach(cleanupTmpPaths);
3030

@@ -60,8 +60,7 @@ function gitCmd(cwd: string, ...args: string[]): string {
6060
function makeRepo(): string {
6161
const dir = mkTmpDir("mcp-batch-commit-test-");
6262
gitCmd(dir, "init", "-b", "main");
63-
gitCmd(dir, "config", "user.email", "test@example.com");
64-
gitCmd(dir, "config", "user.name", "Test User");
63+
writeTestGitConfig(dir);
6564
return dir;
6665
}
6766

@@ -77,8 +76,7 @@ function makeRepoWithUpstream(): { work: string; remote: string } {
7776

7877
const work = mkTmpDir("mcp-batch-commit-work-");
7978
gitCmd(work, "init", "-b", "main");
80-
gitCmd(work, "config", "user.email", "test@example.com");
81-
gitCmd(work, "config", "user.name", "Test User");
79+
writeTestGitConfig(work);
8280
gitCmd(work, "remote", "add", "origin", remote);
8381

8482
// Seed a commit and set upstream so `@{u}` resolves.

src/server/git-cherry-pick-tool.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { existsSync, writeFileSync } from "node:fs";
88
import { join } from "node:path";
99

1010
import { registerGitCherryPickTool } from "./git-cherry-pick-tool.js";
11-
import { captureTool, cleanupTmpPaths, mkTmpDir } from "./test-harness.js";
11+
import { captureTool, cleanupTmpPaths, mkTmpDir, writeTestGitConfig } from "./test-harness.js";
1212

1313
afterEach(cleanupTmpPaths);
1414

@@ -32,9 +32,7 @@ function gitCmd(cwd: string, ...args: string[]): string {
3232
function makeRepo(): string {
3333
const dir = mkTmpDir("mcp-cherry-pick-test-");
3434
gitCmd(dir, "init", "-b", "main");
35-
gitCmd(dir, "config", "user.email", "test@example.com");
36-
gitCmd(dir, "config", "user.name", "Test User");
37-
gitCmd(dir, "config", "commit.gpgsign", "false");
35+
writeTestGitConfig(dir);
3836
writeFileSync(join(dir, "seed.txt"), "seed\n");
3937
gitCmd(dir, "add", "seed.txt");
4038
gitCmd(dir, "commit", "-m", "chore: seed");

src/server/git-diff-summary-tool.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { writeFileSync } from "node:fs";
2020
import { join, matchesGlob } from "node:path";
2121
import { isSafeGitUpstreamToken, spawnGitAsync } from "./git.js";
2222
import { registerGitDiffSummaryTool } from "./git-diff-summary-tool.js";
23-
import { captureTool, cleanupTmpPaths, mkTmpDir } from "./test-harness.js";
23+
import { captureTool, cleanupTmpPaths, mkTmpDir, writeTestGitConfig } from "./test-harness.js";
2424

2525
afterEach(cleanupTmpPaths);
2626

@@ -155,8 +155,7 @@ function gitCmd(cwd: string, ...args: string[]): string {
155155
function makeRepo(): string {
156156
const dir = mkTmpDir("mcp-git-diff-test-");
157157
gitCmd(dir, "init", "-b", "main");
158-
gitCmd(dir, "config", "user.email", "test@example.com");
159-
gitCmd(dir, "config", "user.name", "Test User");
158+
writeTestGitConfig(dir);
160159
return dir;
161160
}
162161

src/server/git-log-tool.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { join } from "node:path";
2424

2525
import { gitTopLevel, spawnGitAsync } from "./git.js";
2626
import { registerGitLogTool } from "./git-log-tool.js";
27-
import { captureTool, cleanupTmpPaths, mkTmpDir } from "./test-harness.js";
27+
import { captureTool, cleanupTmpPaths, mkTmpDir, writeTestGitConfig } from "./test-harness.js";
2828

2929
afterEach(cleanupTmpPaths);
3030

@@ -65,8 +65,7 @@ function gitCmd(cwd: string, ...args: string[]): string {
6565
function makeRepo(): string {
6666
const dir = mkTmpDir("mcp-git-log-test-");
6767
gitCmd(dir, "init", "-b", "main");
68-
gitCmd(dir, "config", "user.email", "test@example.com");
69-
gitCmd(dir, "config", "user.name", "Test User");
68+
writeTestGitConfig(dir);
7069
return dir;
7170
}
7271

src/server/git-merge-tool.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ import { tmpdir } from "node:os";
1212
import { join } from "node:path";
1313

1414
import { registerGitMergeTool } from "./git-merge-tool.js";
15-
import { captureTool, cleanupTmpPaths, mkTmpDir, trackTmpPath } from "./test-harness.js";
15+
import {
16+
captureTool,
17+
cleanupTmpPaths,
18+
mkTmpDir,
19+
trackTmpPath,
20+
writeTestGitConfig,
21+
} from "./test-harness.js";
1622

1723
afterEach(cleanupTmpPaths);
1824

@@ -40,9 +46,7 @@ function gitCmd(cwd: string, ...args: string[]): string {
4046
function makeRepo(): string {
4147
const dir = mkTmpDir("mcp-git-merge-test-");
4248
gitCmd(dir, "init", "-b", "main");
43-
gitCmd(dir, "config", "user.email", "test@example.com");
44-
gitCmd(dir, "config", "user.name", "Test User");
45-
gitCmd(dir, "config", "commit.gpgsign", "false");
49+
writeTestGitConfig(dir);
4650
// Seed so HEAD exists.
4751
writeFileSync(join(dir, "seed.txt"), "seed\n");
4852
gitCmd(dir, "add", "seed.txt");

src/server/git-parity-tool.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ import { mkdirSync, writeFileSync } from "node:fs";
88
import { join } from "node:path";
99

1010
import { registerGitParityTool } from "./git-parity-tool.js";
11-
import { captureTool, cleanupTmpPaths, mkTmpDir } from "./test-harness.js";
11+
import { captureTool, cleanupTmpPaths, mkTmpDir, writeTestGitConfig } from "./test-harness.js";
1212

1313
afterEach(cleanupTmpPaths);
1414

1515
function gitInitMain(dir: string): void {
1616
execFileSync("git", ["init", "-b", "main"], { cwd: dir, stdio: "ignore" });
17-
execFileSync("git", ["config", "user.email", "t@example.com"], { cwd: dir, stdio: "ignore" });
18-
execFileSync("git", ["config", "user.name", "t"], { cwd: dir, stdio: "ignore" });
17+
writeTestGitConfig(dir);
1918
}
2019

2120
function commitFile(dir: string, filename: string, content: string): string {

src/server/git-push-tool.test.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { writeFileSync } from "node:fs";
88
import { join } from "node:path";
99

1010
import { registerGitPushTool } from "./git-push-tool.js";
11-
import { captureTool, cleanupTmpPaths, mkTmpDir } from "./test-harness.js";
11+
import { captureTool, cleanupTmpPaths, mkTmpDir, writeTestGitConfig } from "./test-harness.js";
1212

1313
afterEach(cleanupTmpPaths);
1414

@@ -33,9 +33,7 @@ function makeRepoWithRemote(): { dir: string; remote: string } {
3333
const dir = mkTmpDir("mcp-git-push-test-");
3434
const remote = mkTmpDir("mcp-git-push-remote-");
3535
gitCmd(dir, "init", "-b", "main");
36-
gitCmd(dir, "config", "user.email", "test@example.com");
37-
gitCmd(dir, "config", "user.name", "Test User");
38-
gitCmd(dir, "config", "commit.gpgsign", "false");
36+
writeTestGitConfig(dir);
3937
writeFileSync(join(dir, "base.ts"), "const b = 0;\n");
4038
gitCmd(dir, "add", "base.ts");
4139
gitCmd(dir, "commit", "-m", "chore: base");
@@ -79,9 +77,7 @@ describe("git_push", () => {
7977
const dir = mkTmpDir("mcp-git-push-set-upstream-");
8078
const remote = mkTmpDir("mcp-git-push-set-upstream-remote-");
8179
gitCmd(dir, "init", "-b", "feature/new");
82-
gitCmd(dir, "config", "user.email", "test@example.com");
83-
gitCmd(dir, "config", "user.name", "Test User");
84-
gitCmd(dir, "config", "commit.gpgsign", "false");
80+
writeTestGitConfig(dir);
8581
writeFileSync(join(dir, "base.ts"), "const b = 0;\n");
8682
gitCmd(dir, "add", "base.ts");
8783
gitCmd(dir, "commit", "-m", "chore: base");
@@ -115,9 +111,7 @@ describe("git_push", () => {
115111
test("push_no_upstream when no tracking configured", async () => {
116112
const dir = mkTmpDir("mcp-git-push-no-upstream-");
117113
gitCmd(dir, "init", "-b", "main");
118-
gitCmd(dir, "config", "user.email", "test@example.com");
119-
gitCmd(dir, "config", "user.name", "Test User");
120-
gitCmd(dir, "config", "commit.gpgsign", "false");
114+
writeTestGitConfig(dir);
121115
writeFileSync(join(dir, "base.ts"), "const b = 0;\n");
122116
gitCmd(dir, "add", "base.ts");
123117
gitCmd(dir, "commit", "-m", "chore: base");
@@ -132,9 +126,7 @@ describe("git_push", () => {
132126
test("push_detached_head when HEAD is detached", async () => {
133127
const dir = mkTmpDir("mcp-git-push-detached-");
134128
gitCmd(dir, "init", "-b", "main");
135-
gitCmd(dir, "config", "user.email", "test@example.com");
136-
gitCmd(dir, "config", "user.name", "Test User");
137-
gitCmd(dir, "config", "commit.gpgsign", "false");
129+
writeTestGitConfig(dir);
138130
writeFileSync(join(dir, "base.ts"), "const b = 0;\n");
139131
gitCmd(dir, "add", "base.ts");
140132
gitCmd(dir, "commit", "-m", "chore: base");

src/server/git-reset-soft-tool.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { writeFileSync } from "node:fs";
88
import { join } from "node:path";
99

1010
import { registerGitResetSoftTool } from "./git-reset-soft-tool.js";
11-
import { captureTool, cleanupTmpPaths, mkTmpDir } from "./test-harness.js";
11+
import { captureTool, cleanupTmpPaths, mkTmpDir, writeTestGitConfig } from "./test-harness.js";
1212

1313
afterEach(cleanupTmpPaths);
1414

@@ -32,9 +32,7 @@ function gitCmd(cwd: string, ...args: string[]): string {
3232
function makeRepo(): string {
3333
const dir = mkTmpDir("mcp-git-reset-soft-test-");
3434
gitCmd(dir, "init", "-b", "main");
35-
gitCmd(dir, "config", "user.email", "test@example.com");
36-
gitCmd(dir, "config", "user.name", "Test User");
37-
gitCmd(dir, "config", "commit.gpgsign", "false");
35+
writeTestGitConfig(dir);
3836
writeFileSync(join(dir, "base.ts"), "const b = 0;\n");
3937
gitCmd(dir, "add", "base.ts");
4038
gitCmd(dir, "commit", "-m", "chore: base");

src/server/git-utils.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
isSafeGitUpstreamToken,
2222
parseGitSubmodulePaths,
2323
} from "./git.js";
24-
import { cleanupTmpPaths, mkTmpDir } from "./test-harness.js";
24+
import { cleanupTmpPaths, mkTmpDir, writeTestGitConfig } from "./test-harness.js";
2525

2626
afterEach(cleanupTmpPaths);
2727

@@ -45,9 +45,7 @@ function gitCmd(cwd: string, ...args: string[]): string {
4545
function makeRepo(): string {
4646
const dir = mkTmpDir("mcp-git-utils-test-");
4747
gitCmd(dir, "init", "-b", "main");
48-
gitCmd(dir, "config", "user.email", "test@example.com");
49-
gitCmd(dir, "config", "user.name", "Test User");
50-
gitCmd(dir, "config", "commit.gpgsign", "false");
48+
writeTestGitConfig(dir);
5149
writeFileSync(join(dir, "base.ts"), "const b = 0;\n");
5250
gitCmd(dir, "add", "base.ts");
5351
gitCmd(dir, "commit", "-m", "chore: base");

src/server/git-worktree-tool.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ import {
1212
registerGitWorktreeListTool,
1313
registerGitWorktreeRemoveTool,
1414
} from "./git-worktree-tool.js";
15-
import { captureTool, cleanupTmpPaths, mkTmpDir, trackTmpPath } from "./test-harness.js";
15+
import {
16+
captureTool,
17+
cleanupTmpPaths,
18+
mkTmpDir,
19+
trackTmpPath,
20+
writeTestGitConfig,
21+
} from "./test-harness.js";
1622

1723
afterEach(cleanupTmpPaths);
1824

@@ -36,9 +42,7 @@ function gitCmd(cwd: string, ...args: string[]): string {
3642
function makeRepo(): string {
3743
const dir = mkTmpDir("mcp-git-worktree-test-");
3844
gitCmd(dir, "init", "-b", "main");
39-
gitCmd(dir, "config", "user.email", "test@example.com");
40-
gitCmd(dir, "config", "user.name", "Test User");
41-
gitCmd(dir, "config", "commit.gpgsign", "false");
45+
writeTestGitConfig(dir);
4246
writeFileSync(join(dir, "base.ts"), "const b = 0;\n");
4347
gitCmd(dir, "add", "base.ts");
4448
gitCmd(dir, "commit", "-m", "chore: base");

0 commit comments

Comments
 (0)