@@ -1314,3 +1314,36 @@ describe("Issue #636: legacy settings.json rewrite quotes spaced paths", () => {
13141314 } ,
13151315 ) ;
13161316} ) ;
1317+
1318+ // ═══════════════════════════════════════════════════════════════════════
1319+ // PreToolUse import cost (#1261) — keep the session-db bundle off the
1320+ // per-tool-call path
1321+ // ═══════════════════════════════════════════════════════════════════════
1322+
1323+ describe ( "PreToolUse input helpers skip the session-db bundle (#1261)" , ( ) => {
1324+ const HOOKS_DIR = join ( __dirname , ".." , ".." , "hooks" ) ;
1325+ const INPUT_PATH = join ( HOOKS_DIR , "session-input.mjs" ) ;
1326+ const HELPERS_PATH = join ( HOOKS_DIR , "session-helpers.mjs" ) ;
1327+
1328+ test ( "pretooluse.mjs does not import session-helpers.mjs" , ( ) => {
1329+ const source = readFileSync ( HOOK_PATH , "utf-8" ) ;
1330+ expect ( source ) . not . toContain ( "session-helpers.mjs" ) ;
1331+ expect ( source ) . toContain ( "./session-input.mjs" ) ;
1332+ } ) ;
1333+
1334+ test ( "session-input.mjs imports only node: built-ins" , ( ) => {
1335+ const source = readFileSync ( INPUT_PATH , "utf-8" ) ;
1336+ const specifiers = [ ...source . matchAll ( / f r o m \s + [ " ' ] ( [ ^ " ' ] + ) [ " ' ] | i m p o r t \( \s * [ " ' ] ( [ ^ " ' ] + ) [ " ' ] / g) ]
1337+ . map ( ( match ) => match [ 1 ] ?? match [ 2 ] ) ;
1338+ expect ( specifiers . length ) . toBeGreaterThan ( 0 ) ;
1339+ expect ( specifiers . every ( ( specifier ) => specifier . startsWith ( "node:" ) ) ) . toBe ( true ) ;
1340+ } ) ;
1341+
1342+ test ( "session-helpers.mjs re-exports the same input helpers" , async ( ) => {
1343+ const input = await import ( pathToFileURL ( INPUT_PATH ) . href ) ;
1344+ const helpers = await import ( pathToFileURL ( HELPERS_PATH ) . href ) ;
1345+ for ( const name of [ "resolveConfigDir" , "parseStdin" , "getProjectDir" , "getInputProjectDir" , "getSessionId" ] ) {
1346+ expect ( helpers [ name ] ) . toBe ( input [ name ] ) ;
1347+ }
1348+ } ) ;
1349+ } ) ;
0 commit comments