From ad40bf3aad248cbe7fb3a96de9ef0e1677e6ef03 Mon Sep 17 00:00:00 2001 From: Affaan Mustafa Date: Fri, 13 Feb 2026 05:34:59 -0800 Subject: [PATCH] test: add env var fallback, console.log max matches, and format non-existent file tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Round 53: Adds 3 hook tests — validates evaluate-session.js falls back to CLAUDE_TRANSCRIPT_PATH env var when stdin JSON is invalid, post-edit-console-warn.js truncates output to max 5 matches, and post-edit-format.js passes through data when the target .tsx file doesn't exist. --- tests/hooks/evaluate-session.test.js | 26 ++++++++++++++++++++++ tests/hooks/hooks.test.js | 33 ++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/tests/hooks/evaluate-session.test.js b/tests/hooks/evaluate-session.test.js index 6c2bdeab..f5c7ddc6 100644 --- a/tests/hooks/evaluate-session.test.js +++ b/tests/hooks/evaluate-session.test.js @@ -258,6 +258,32 @@ function runTests() { assert.strictEqual(result.status, 0, 'Should exit 0 on empty stdin'); })) passed++; else failed++; + // ── Round 53: env var fallback path ── + console.log('\nRound 53: CLAUDE_TRANSCRIPT_PATH fallback:'); + + if (test('falls back to CLAUDE_TRANSCRIPT_PATH env var when stdin is invalid JSON', () => { + const testDir = createTestDir(); + const transcript = createTranscript(testDir, 15); + + const result = spawnSync('node', [evaluateScript], { + encoding: 'utf8', + input: 'invalid json {{{', + timeout: 10000, + env: { ...process.env, CLAUDE_TRANSCRIPT_PATH: transcript } + }); + + assert.strictEqual(result.status, 0, 'Should exit 0'); + assert.ok( + result.stderr.includes('15 messages'), + 'Should evaluate using env var fallback path' + ); + assert.ok( + result.stderr.includes('evaluate'), + 'Should indicate session evaluation' + ); + cleanupTestDir(testDir); + })) passed++; else failed++; + // Summary console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`); process.exit(failed > 0 ? 1 : 0); diff --git a/tests/hooks/hooks.test.js b/tests/hooks/hooks.test.js index 8329cb58..bff8fc0e 100644 --- a/tests/hooks/hooks.test.js +++ b/tests/hooks/hooks.test.js @@ -2680,6 +2680,39 @@ async function runTests() { } })) passed++; else failed++; + // ── Round 53: console-warn max matches and format non-existent file ── + console.log('\nRound 53: post-edit-console-warn.js (max matches truncation):'); + + if (await asyncTest('reports maximum 5 console.log matches per file', async () => { + const testDir = createTestDir(); + const testFile = path.join(testDir, 'many-logs.js'); + const lines = Array(7).fill(null).map((_, i) => + `console.log("debug line ${i + 1}");` + ); + fs.writeFileSync(testFile, lines.join('\n')); + + const stdinJson = JSON.stringify({ tool_input: { file_path: testFile } }); + const result = await runScript(path.join(scriptsDir, 'post-edit-console-warn.js'), stdinJson); + + assert.strictEqual(result.code, 0, 'Should exit 0'); + // Count line number reports in stderr (format: "N: console.log(...)") + const lineReports = (result.stderr.match(/^\d+:/gm) || []).length; + assert.strictEqual(lineReports, 5, `Should report max 5 matches, got ${lineReports}`); + cleanupTestDir(testDir); + })) passed++; else failed++; + + console.log('\nRound 53: post-edit-format.js (non-existent file):'); + + if (await asyncTest('passes through data for non-existent .tsx file path', async () => { + const stdinJson = JSON.stringify({ + tool_input: { file_path: '/nonexistent/path/file.tsx' } + }); + const result = await runScript(path.join(scriptsDir, 'post-edit-format.js'), stdinJson); + + assert.strictEqual(result.code, 0, 'Should exit 0 for non-existent file'); + assert.strictEqual(result.stdout, stdinJson, 'Should pass through stdin data unchanged'); + })) passed++; else failed++; + // Summary console.log('\n=== Test Results ==='); console.log(`Passed: ${passed}`);