Skip to content

Commit 83bca6a

Browse files
AlbinoGeekclaude
andcommitted
test(harness): extract shared gitInitMain helper
Move duplicated gitInitMain function to test-harness.ts and update roots.test.ts and git-parity-tool.test.ts to use shared implementation. Both files had identical definitions. Eliminates 6 lines of duplication. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
1 parent 4117a9e commit 83bca6a

3 files changed

Lines changed: 8 additions & 24 deletions

File tree

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,10 @@ import { mkdirSync, writeFileSync } from "node:fs";
77
import { join } from "node:path";
88

99
import { registerGitParityTool } from "./git-parity-tool.js";
10-
import {
11-
captureTool,
12-
cleanupTmpPaths,
13-
gitCmd,
14-
mkTmpDir,
15-
writeTestGitConfig,
16-
} from "./test-harness.js";
10+
import { captureTool, cleanupTmpPaths, gitCmd, gitInitMain, mkTmpDir } from "./test-harness.js";
1711

1812
afterEach(cleanupTmpPaths);
1913

20-
function gitInitMain(dir: string): void {
21-
gitCmd(dir, "init", "-b", "main");
22-
writeTestGitConfig(dir);
23-
}
24-
2514
function commitFile(dir: string, filename: string, content: string): string {
2615
writeFileSync(join(dir, filename), content);
2716
gitCmd(dir, "add", filename);

src/server/roots.test.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,10 @@ import { join } from "node:path";
1212

1313
import { registerGitInventoryTool } from "./git-inventory-tool.js";
1414
import { registerGitStatusTool } from "./git-status-tool.js";
15-
import {
16-
captureTool,
17-
cleanupTmpPaths,
18-
gitCmd,
19-
mkTmpDir,
20-
writeTestGitConfig,
21-
} from "./test-harness.js";
15+
import { captureTool, cleanupTmpPaths, gitInitMain, mkTmpDir } from "./test-harness.js";
2216

2317
afterEach(cleanupTmpPaths);
2418

25-
function gitInitMain(dir: string): void {
26-
gitCmd(dir, "init", "-b", "main");
27-
writeTestGitConfig(dir);
28-
}
29-
3019
describe("workspace root resolution", () => {
3120
test("omitting workspaceRoot falls back to process.cwd() (which is a git repo in CI)", async () => {
3221
// process.cwd() during tests is the project root — a valid git repo.

src/server/test-harness.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@ export function makeRepoWithUpstream(
193193
return { work, remote };
194194
}
195195

196+
/** Initialize a git repo with main branch and test config. */
197+
export function gitInitMain(dir: string): void {
198+
gitCmd(dir, "init", "-b", "main");
199+
writeTestGitConfig(dir);
200+
}
201+
196202
/** Add a commit to a repo with specified file content. */
197203
export function addCommit(dir: string, file: string, content: string, message: string): void {
198204
writeFileSync(join(dir, file), content);

0 commit comments

Comments
 (0)