From e413166c50e85fb205b988b5e78874b5a88ea4d2 Mon Sep 17 00:00:00 2001 From: haelyra <49814733+haelyra@users.noreply.github.com> Date: Mon, 16 Nov 2026 22:07:01 -0500 Subject: [PATCH] test(hooks): make context-gate tests portable to Windows (#3106) The hook proposes a correct absolute checkpoint path on Windows, but the tests located that line with /^\s+[/\\].*\.md$/, which only matches paths starting with a slash. Windows paths start with a drive letter (C:\...), so every case that read the proposed path saw undefined and failed. - Extract the proposed checkpoint as the indented line that ends in .md and satisfies path.isAbsolute, so POSIX and Windows paths both match. - Include the hook output in the "both fires should propose" assertion so a genuine decline is diagnosable from CI logs. - Write transcript fixtures into private fs.mkdtempSync directories instead of predictable names directly under os.tmpdir() (CodeQL js/insecure-temporary-file) in context-gate, context-gate-state and ecc-context-monitor tests. --- tests/hooks/context-gate-ownership.test.js | 12 +++++++++--- tests/hooks/context-gate.test.js | 20 ++++++++++++++++---- tests/hooks/ecc-context-monitor.test.js | 8 ++++---- tests/lib/context-gate-state.test.js | 12 +++++++++--- 4 files changed, 38 insertions(+), 14 deletions(-) diff --git a/tests/hooks/context-gate-ownership.test.js b/tests/hooks/context-gate-ownership.test.js index e77abd943..5e978fea8 100644 --- a/tests/hooks/context-gate-ownership.test.js +++ b/tests/hooks/context-gate-ownership.test.js @@ -54,6 +54,12 @@ function createSandbox() { return { root, resumeDir, transcript, env }; } +// The proposed checkpoint is the indented line that is an absolute .md path: +// "/..." on POSIX, "C:\\..." (or a UNC path) on Windows. +function isProposedPathLine(line) { + return /^\s+\S/.test(line) && line.endsWith('.md') && path.isAbsolute(line.trim()); +} + function fire(sandbox, extra = {}) { const input = { cwd: '/tmp/owner-a/project', session_id: 'mysess', transcript_path: sandbox.transcript, ...extra }; const result = spawnSync(process.execPath, [RUNNER, 'user-prompt:context-gate', 'scripts/hooks/context-gate.js', 'standard,strict'], { @@ -66,7 +72,7 @@ function fire(sandbox, extra = {}) { if (result.error) return { timeout: result.error.code }; const text = JSON.parse(result.stdout).hookSpecificOutput.additionalContext; const lines = text.split('\n'); - const target = lines.find(line => /^\s+[/\\].*\.md$/.test(line)); + const target = lines.find(isProposedPathLine); const marker = lines.find(line => line.includes('