Skip to content

Commit 376f6d7

Browse files
committed
test(hooks): pin PreToolUse off the session-db bundle (#1261)
1 parent 4621364 commit 376f6d7

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

‎tests/hooks/integration.test.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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(/from\s+["']([^"']+)["']|import\(\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

Comments
 (0)