1616 * 7. Valid path that is exactly the git root is accepted
1717 */
1818
19- import { describe , expect , test } from "bun:test" ;
19+ import { afterEach , describe , expect , test } from "bun:test" ;
2020import { type ExecSyncOptionsWithStringEncoding , execFileSync } from "node:child_process" ;
21- import { mkdtempSync , writeFileSync } from "node:fs" ;
22- import { tmpdir } from "node:os" ;
21+ import { writeFileSync } from "node:fs" ;
2322import { join } from "node:path" ;
2423
2524import { isStrictlyUnderGitTop , resolvePathForRepo } from "../repo-paths.js" ;
2625import { registerBatchCommitTool } from "./batch-commit-tool.js" ;
2726import { spawnGitAsync } from "./git.js" ;
28- import { captureTool } from "./test-harness.js" ;
27+ import { captureTool , cleanupTmpPaths , mkTmpDir } from "./test-harness.js" ;
28+
29+ afterEach ( cleanupTmpPaths ) ;
2930
3031// ---------------------------------------------------------------------------
3132// Mirrors the SHA extraction regex from batch-commit-tool.ts
@@ -57,7 +58,7 @@ function gitCmd(cwd: string, ...args: string[]): string {
5758}
5859
5960function makeRepo ( ) : string {
60- const dir = mkdtempSync ( join ( tmpdir ( ) , "mcp-batch-commit-test-" ) ) ;
61+ const dir = mkTmpDir ( "mcp-batch-commit-test-" ) ;
6162 gitCmd ( dir , "init" , "-b" , "main" ) ;
6263 gitCmd ( dir , "config" , "user.email" , "test@example.com" ) ;
6364 gitCmd ( dir , "config" , "user.name" , "Test User" ) ;
@@ -71,10 +72,10 @@ function makeRepo(): string {
7172 * `remote` is a bare repo used as `origin`.
7273 */
7374function makeRepoWithUpstream ( ) : { work : string ; remote : string } {
74- const remote = mkdtempSync ( join ( tmpdir ( ) , "mcp-batch-commit-remote-" ) ) ;
75+ const remote = mkTmpDir ( "mcp-batch-commit-remote-" ) ;
7576 gitCmd ( remote , "init" , "--bare" , "-b" , "main" ) ;
7677
77- const work = mkdtempSync ( join ( tmpdir ( ) , "mcp-batch-commit-work-" ) ) ;
78+ const work = mkTmpDir ( "mcp-batch-commit-work-" ) ;
7879 gitCmd ( work , "init" , "-b" , "main" ) ;
7980 gitCmd ( work , "config" , "user.email" , "test@example.com" ) ;
8081 gitCmd ( work , "config" , "user.name" , "Test User" ) ;
@@ -124,27 +125,27 @@ describe("extractSha", () => {
124125
125126describe ( "path escape detection" , ( ) => {
126127 test ( "dotdot path that escapes root is rejected" , ( ) => {
127- const gitTop = mkdtempSync ( join ( tmpdir ( ) , "mcp-top-" ) ) ;
128+ const gitTop = mkTmpDir ( "mcp-top-" ) ;
128129 const rel = "../../etc/passwd" ;
129130 const abs = resolvePathForRepo ( rel , gitTop ) ;
130131 expect ( isStrictlyUnderGitTop ( abs , gitTop ) ) . toBe ( false ) ;
131132 } ) ;
132133
133134 test ( "normal nested path is accepted" , ( ) => {
134- const gitTop = mkdtempSync ( join ( tmpdir ( ) , "mcp-top-" ) ) ;
135+ const gitTop = mkTmpDir ( "mcp-top-" ) ;
135136 const rel = "src/foo.ts" ;
136137 const abs = resolvePathForRepo ( rel , gitTop ) ;
137138 expect ( isStrictlyUnderGitTop ( abs , gitTop ) ) . toBe ( true ) ;
138139 } ) ;
139140
140141 test ( "absolute path outside root is rejected" , ( ) => {
141- const gitTop = mkdtempSync ( join ( tmpdir ( ) , "mcp-top-" ) ) ;
142- const outside = mkdtempSync ( join ( tmpdir ( ) , "mcp-other-" ) ) ;
142+ const gitTop = mkTmpDir ( "mcp-top-" ) ;
143+ const outside = mkTmpDir ( "mcp-other-" ) ;
143144 expect ( isStrictlyUnderGitTop ( outside , gitTop ) ) . toBe ( false ) ;
144145 } ) ;
145146
146147 test ( "path equal to git root is accepted" , ( ) => {
147- const gitTop = mkdtempSync ( join ( tmpdir ( ) , "mcp-top-" ) ) ;
148+ const gitTop = mkTmpDir ( "mcp-top-" ) ;
148149 expect ( isStrictlyUnderGitTop ( gitTop , gitTop ) ) . toBe ( true ) ;
149150 } ) ;
150151} ) ;
@@ -297,7 +298,7 @@ describe("batch_commit execute handler", () => {
297298 } ) ;
298299
299300 test ( "non-git workspaceRoot → not_a_git_repository error" , async ( ) => {
300- const plain = mkdtempSync ( join ( tmpdir ( ) , "mcp-plain-" ) ) ;
301+ const plain = mkTmpDir ( "mcp-plain-" ) ;
301302
302303 const run = captureTool ( registerBatchCommitTool ) ;
303304 const text = await run ( {
0 commit comments