@@ -75,6 +75,20 @@ function cleanupTestDir(testDir) {
7575 fs . rmSync ( testDir , { recursive : true , force : true } ) ;
7676}
7777
78+ function createCommandShim ( binDir , name , logFile ) {
79+ const shimPath = path . join ( binDir , name ) ;
80+ const script = `#!/bin/sh
81+ {
82+ printf '%s\n' "$(basename \"$0\")"
83+ for arg in "$@"; do
84+ printf '%s\n' "$arg"
85+ done
86+ } > ${ JSON . stringify ( logFile ) }
87+ ` ;
88+ fs . writeFileSync ( shimPath , script , { mode : 0o755 } ) ;
89+ return shimPath ;
90+ }
91+
7892// Test suite
7993async function runTests ( ) {
8094 console . log ( '\n=== Testing Hook Scripts ===\n' ) ;
@@ -701,6 +715,64 @@ async function runTests() {
701715 assert . ok ( result . stdout . includes ( 'tool_input' ) , 'Should pass through original data' ) ;
702716 } ) ) passed ++ ; else failed ++ ;
703717
718+ if ( await asyncTest ( 'uses CLAUDE_PACKAGE_MANAGER runner for formatter fallback' , async ( ) => {
719+ const testDir = createTestDir ( ) ;
720+ const binDir = path . join ( testDir , 'bin' ) ;
721+ const logFile = path . join ( testDir , 'pnpm.log' ) ;
722+ fs . mkdirSync ( binDir , { recursive : true } ) ;
723+ createCommandShim ( binDir , 'pnpm' , logFile ) ;
724+
725+ const testFile = path . join ( testDir , 'src' , 'example.ts' ) ;
726+ fs . mkdirSync ( path . dirname ( testFile ) , { recursive : true } ) ;
727+ fs . writeFileSync ( path . join ( testDir , 'package.json' ) , JSON . stringify ( { name : 'pm-env-test' } ) ) ;
728+ fs . writeFileSync ( path . join ( testDir , '.prettierrc' ) , '{}' ) ;
729+ fs . writeFileSync ( testFile , 'const answer=42;\n' ) ;
730+
731+ try {
732+ const stdinJson = JSON . stringify ( { tool_input : { file_path : testFile } } ) ;
733+ const result = await runScript ( path . join ( scriptsDir , 'post-edit-format.js' ) , stdinJson , {
734+ CLAUDE_PACKAGE_MANAGER : 'pnpm' ,
735+ PATH : `${ binDir } ${ path . delimiter } ${ process . env . PATH || '' } `
736+ } ) ;
737+
738+ assert . strictEqual ( result . code , 0 , 'Should exit 0 with pnpm fallback' ) ;
739+ const logLines = fs . readFileSync ( logFile , 'utf8' ) . trim ( ) . split ( '\n' ) ;
740+ assert . deepStrictEqual ( logLines , [ 'pnpm' , 'dlx' , 'prettier' , '--write' , testFile ] ) ;
741+ } finally {
742+ cleanupTestDir ( testDir ) ;
743+ }
744+ } ) ) passed ++ ; else failed ++ ;
745+
746+ if ( await asyncTest ( 'uses project package manager config for formatter fallback' , async ( ) => {
747+ const testDir = createTestDir ( ) ;
748+ const binDir = path . join ( testDir , 'bin' ) ;
749+ const logFile = path . join ( testDir , 'bunx.log' ) ;
750+ fs . mkdirSync ( binDir , { recursive : true } ) ;
751+ fs . mkdirSync ( path . join ( testDir , '.claude' ) , { recursive : true } ) ;
752+ createCommandShim ( binDir , 'bunx' , logFile ) ;
753+
754+ const testFile = path . join ( testDir , 'src' , 'example.ts' ) ;
755+ fs . mkdirSync ( path . dirname ( testFile ) , { recursive : true } ) ;
756+ fs . writeFileSync ( path . join ( testDir , 'package.json' ) , JSON . stringify ( { name : 'pm-project-test' } ) ) ;
757+ fs . writeFileSync ( path . join ( testDir , 'biome.json' ) , '{}' ) ;
758+ fs . writeFileSync ( path . join ( testDir , '.claude' , 'package-manager.json' ) , JSON . stringify ( { packageManager : 'bun' } ) ) ;
759+ fs . writeFileSync ( testFile , 'const answer=42;\n' ) ;
760+
761+ try {
762+ const stdinJson = JSON . stringify ( { tool_input : { file_path : testFile } } ) ;
763+ const result = await runScript ( path . join ( scriptsDir , 'post-edit-format.js' ) , stdinJson , {
764+ CLAUDE_PACKAGE_MANAGER : '' ,
765+ PATH : `${ binDir } ${ path . delimiter } ${ process . env . PATH || '' } `
766+ } ) ;
767+
768+ assert . strictEqual ( result . code , 0 , 'Should exit 0 with project-config fallback' ) ;
769+ const logLines = fs . readFileSync ( logFile , 'utf8' ) . trim ( ) . split ( '\n' ) ;
770+ assert . deepStrictEqual ( logLines , [ 'bunx' , '@biomejs/biome' , 'format' , '--write' , testFile ] ) ;
771+ } finally {
772+ cleanupTestDir ( testDir ) ;
773+ }
774+ } ) ) passed ++ ; else failed ++ ;
775+
704776 // post-edit-typecheck.js tests
705777 console . log ( '\npost-edit-typecheck.js:' ) ;
706778
0 commit comments