@@ -7,6 +7,7 @@ import { collectDependencyPinViolations } from "../../scripts/check-dependency-p
77import { cleanupTempDirs , makeTempRepoRoot } from "../helpers/temp-repo.js" ;
88
99const tempDirs : string [ ] = [ ] ;
10+ const itUnix = process . platform === "win32" ? it . skip : it ;
1011
1112const nestedGitEnvKeys = [
1213 "GIT_ALTERNATE_OBJECT_DIRECTORIES" ,
@@ -41,17 +42,21 @@ function writeJson(filePath: string, value: unknown) {
4142 writeFileSync ( filePath , `${ JSON . stringify ( value , null , 2 ) } \n` , "utf8" ) ;
4243}
4344
44- function writeGitFixture ( binDir : string , body : string ) : void {
45- if ( process . platform === "win32" ) {
46- const fixturePath = path . join ( binDir , "git-fixture.mjs" ) ;
47- writeFileSync ( fixturePath , body ) ;
48- writeFileSync (
49- path . join ( binDir , "git.cmd" ) ,
50- `@echo off\r\n"${ process . execPath } " "${ fixturePath } " %*\r\n` ,
51- ) ;
52- return ;
53- }
54- writeFileSync ( path . join ( binDir , "git" ) , `#!${ process . execPath } \n${ body } ` , { mode : 0o755 } ) ;
45+ function stubHangingGit ( cwd : string , stalledSubcommand : "ls-files" | "show" ) {
46+ const binDir = path . join ( cwd , "fake-git-bin" ) ;
47+ mkdirSync ( binDir ) ;
48+ const fixture = `#!${ process . execPath }
49+ if (process.argv[2] === ${ JSON . stringify ( stalledSubcommand ) } ) {
50+ process.on("SIGTERM", () => {});
51+ setInterval(() => {}, 1_000);
52+ } else if (process.argv[2] === "ls-files") {
53+ process.stdout.write("package.json\\0");
54+ } else {
55+ process.exitCode = 1;
56+ }
57+ ` ;
58+ writeFileSync ( path . join ( binDir , "git" ) , fixture , { mode : 0o755 } ) ;
59+ vi . stubEnv ( "PATH" , `${ binDir } ${ path . delimiter } ${ process . env . PATH ?? "" } ` ) ;
5560}
5661
5762function makeRepo ( ) {
@@ -175,21 +180,30 @@ packageExtensions:
175180 expect ( collectDependencyPinViolations ( dir ) ) . toEqual ( [ ] ) ;
176181 } ) ;
177182
178- it ( "fails with an actionable timeout when git ls-files hangs" , ( ) => {
179- const tempDir = makeTempRepoRoot ( tempDirs , "openclaw-dependency-pins-timeout-" ) ;
180- const binDir = path . join ( tempDir , "bin" ) ;
181- mkdirSync ( binDir ) ;
182- writeGitFixture (
183- binDir ,
184- 'if (process.argv[2] === "ls-files") { setTimeout(() => {}, 10_000); }\nelse { process.exit(0); }\n' ,
185- ) ;
186- vi . stubEnv ( "PATH" , binDir ) ;
183+ itUnix ( "terminates a SIGTERM-resistant git ls-files at the dependency-pin timeout" , ( ) => {
184+ const dir = makeTempRepoRoot ( tempDirs , "openclaw-dependency-pins-ls-files-timeout-" ) ;
185+ stubHangingGit ( dir , "ls-files" ) ;
187186
188- expect ( ( ) => collectDependencyPinViolations ( tempDir , { gitTimeoutMs : 500 } ) ) . toThrow (
189- "dependency pin guard: git ls-files -z -- *package.json timed out after 500ms ." ,
187+ expect ( ( ) => collectDependencyPinViolations ( dir , { gitTimeoutMs : 200 } ) ) . toThrow (
188+ "dependency pin guard: git ls-files -z -- *package.json timed out after 200ms ." ,
190189 ) ;
191190 } ) ;
192191
192+ itUnix (
193+ "terminates a SIGTERM-resistant sparse-index git show at the dependency-pin timeout" ,
194+ ( ) => {
195+ const dir = makeRepo ( ) ;
196+ writeJson ( path . join ( dir , "package.json" ) , { } ) ;
197+ git ( dir , [ "add" , "package.json" ] ) ;
198+ rmSync ( path . join ( dir , "package.json" ) ) ;
199+ stubHangingGit ( dir , "show" ) ;
200+
201+ expect ( ( ) => collectDependencyPinViolations ( dir , { gitTimeoutMs : 200 } ) ) . toThrow (
202+ "dependency pin guard: git show :package.json timed out after 200ms." ,
203+ ) ;
204+ } ,
205+ ) ;
206+
193207 it ( "rejects floating workspace overrides and package extension dependencies" , ( ) => {
194208 const dir = makeRepo ( ) ;
195209 writeJson ( path . join ( dir , "package.json" ) , { } ) ;
0 commit comments