The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.
test: add 3 tests for subdirectory skip, TypeScript error detection, and entry.name fallback (Round 89)
Affaan Mustafa3ec59c48bcea
diff --git a/tests/hooks/hooks.test.js b/tests/hooks/hooks.test.jsindex 3f8c1022e..51bbd1448 100644--- a/tests/hooks/hooks.test.js+++ b/tests/hooks/hooks.test.js@@ -3481,6 +3481,87 @@ Some random content without the expected ### Context to Load sectionassert.ok(result.stdout.length > 0, 'Should still pass through truncated data');})) passed++; else failed++;+ // ── Round 89: post-edit-typecheck.js error detection path (relevantLines) ──+ console.log('\nRound 89: post-edit-typecheck.js (TypeScript error detection path):');++ if (await asyncTest('filters TypeScript errors to edited file when tsc reports errors', async () => {+ // post-edit-typecheck.js lines 60-85: when execFileSync('npx', ['tsc', ...]) throws,+ // the catch block filters error output by file path candidates and logs relevant lines.+ // All existing tests either have no tsconfig (tsc never runs) or valid TS (tsc succeeds).+ // This test creates a .ts file with a type error and a tsconfig.json.+ const testDir = createTestDir();+ fs.writeFileSync(path.join(testDir, 'tsconfig.json'), JSON.stringify({+ compilerOptions: { strict: true, noEmit: true }+ }));+ const testFile = path.join(testDir, 'broken.ts');+ // Intentional type error: assigning string to number+ fs.writeFileSync(testFile, 'const x: number = "not a number";\n');++ const stdinJson = JSON.stringify({ tool_input: { file_path: testFile } });+ const result = await runScript(path.join(scriptsDir, 'post-edit-typecheck.js'), stdinJson);++ // Core: script must exit 0 and pass through stdin data regardless+ assert.strictEqual(result.code, 0, 'Should exit 0 even when tsc finds errors');+ const parsed = JSON.parse(result.stdout);+ assert.strictEqual(parsed.tool_input.file_path, testFile,+ 'Should pass through original stdin data with file_path intact');++ // If tsc is available and ran, check that error output is filtered to this file+ if (result.stderr.includes('TypeScript errors in')) {+ assert.ok(result.stderr.includes('broken.ts'),+ `Should reference the edited file basename. Got: ${result.stderr}`);+ }+ // Either way, no crash and data passes through (verified above)+ cleanupTestDir(testDir);+ })) passed++; else failed++;++ // ── Round 89: extractSessionSummary entry.name + entry.input fallback paths ──+ console.log('\nRound 89: session-end.js (entry.name + entry.input fallback in extractSessionSummary):');++ if (await asyncTest('extracts tool name from entry.name and file path from entry.input (fallback format)', async () => {+ // session-end.js line 63: const toolName = entry.tool_name || entry.name || '';+ // session-end.js line 66: const filePath = entry.tool_input?.file_path || entry.input?.file_path || '';+ // All existing tests use tool_name + tool_input format. This tests the name + input fallback.+ const testDir = createTestDir();+ const transcriptPath = path.join(testDir, 'transcript.jsonl');++ const lines = [+ '{"type":"user","content":"Fix the auth module"}',+ // Tool entries using "name" + "input" instead of "tool_name" + "tool_input"+ '{"type":"tool_use","name":"Edit","input":{"file_path":"/src/auth.ts"}}',+ '{"type":"tool_use","name":"Write","input":{"file_path":"/src/new-helper.ts"}}',+ // Also include a tool with tool_name but entry.input (mixed format)+ '{"tool_name":"Read","input":{"file_path":"/src/config.ts"}}',+ ];+ fs.writeFileSync(transcriptPath, lines.join('\n'));++ const stdinJson = JSON.stringify({ transcript_path: transcriptPath });+ const result = await runScript(path.join(scriptsDir, 'session-end.js'), stdinJson, {+ HOME: testDir+ });+ assert.strictEqual(result.code, 0, 'Should exit 0');++ // Read the session file to verify tool names and file paths were extracted+ const claudeDir = path.join(testDir, '.claude', 'sessions');+ if (fs.existsSync(claudeDir)) {+ const files = fs.readdirSync(claudeDir).filter(f => f.endsWith('.tmp'));+ if (files.length > 0) {+ const content = fs.readFileSync(path.join(claudeDir, files[0]), 'utf8');+ // Tools from entry.name fallback+ assert.ok(content.includes('Edit'),+ `Should extract Edit tool from entry.name fallback. Got: ${content}`);+ assert.ok(content.includes('Write'),+ `Should extract Write tool from entry.name fallback. Got: ${content}`);+ // File paths from entry.input fallback+ assert.ok(content.includes('/src/auth.ts'),+ `Should extract file path from entry.input.file_path fallback. Got: ${content}`);+ assert.ok(content.includes('/src/new-helper.ts'),+ `Should extract Write file from entry.input.file_path fallback. Got: ${content}`);+ }+ }+ cleanupTestDir(testDir);+ })) passed++; else failed++;+// Summaryconsole.log('\n=== Test Results ===');console.log(`Passed: ${passed}`);diff --git a/tests/lib/session-manager.test.js b/tests/lib/session-manager.test.jsindex 365afe1a6..b1704e80a 100644--- a/tests/lib/session-manager.test.js+++ b/tests/lib/session-manager.test.js@@ -1401,6 +1401,53 @@ src/main.tsassert.strictEqual(meta.notes, 'Some notes');})) passed++; else failed++;+ // ── Round 89: getAllSessions skips subdirectories (!entry.isFile()) ──+ console.log('\nRound 89: getAllSessions (subdirectory skip):');++ if (test('getAllSessions skips subdirectories inside sessions dir', () => {+ // session-manager.js line 220: if (!entry.isFile() || ...) continue;+ // Existing tests create non-.tmp FILES to test filtering (e.g., notes.txt).+ // This test creates a DIRECTORY — entry.isFile() returns false, so it should be skipped.+ const isoHome = path.join(os.tmpdir(), `ecc-r89-subdir-skip-${Date.now()}`);+ const sessionsDir = path.join(isoHome, '.claude', 'sessions');+ fs.mkdirSync(sessionsDir, { recursive: true });++ // Create a real session file+ const realFile = '2026-02-11-abcd1234-session.tmp';+ fs.writeFileSync(path.join(sessionsDir, realFile), '# Test session');++ // Create a subdirectory inside sessions dir — should be skipped by !entry.isFile()+ const subdir = path.join(sessionsDir, 'some-nested-dir');+ fs.mkdirSync(subdir);++ // Also create a subdirectory whose name ends in .tmp — still not a file+ const tmpSubdir = path.join(sessionsDir, '2026-02-11-fakeid00-session.tmp');+ fs.mkdirSync(tmpSubdir);++ const origHome = process.env.HOME;+ const origUserProfile = process.env.USERPROFILE;+ process.env.HOME = isoHome;+ process.env.USERPROFILE = isoHome;+ try {+ delete require.cache[require.resolve('../../scripts/lib/session-manager')];+ delete require.cache[require.resolve('../../scripts/lib/utils')];+ const freshManager = require('../../scripts/lib/session-manager');+ const result = freshManager.getAllSessions({ limit: 100 });++ // Should find only the real file, not either subdirectory+ assert.strictEqual(result.total, 1,+ `Should find 1 session (the file), not subdirectories. Got ${result.total}`);+ assert.strictEqual(result.sessions[0].filename, realFile,+ `Should return the real file. Got: ${result.sessions[0].filename}`);+ } finally {+ process.env.HOME = origHome;+ process.env.USERPROFILE = origUserProfile;+ delete require.cache[require.resolve('../../scripts/lib/session-manager')];+ delete require.cache[require.resolve('../../scripts/lib/utils')];+ fs.rmSync(isoHome, { recursive: true, force: true });+ }+ })) passed++; else failed++;+// Summaryconsole.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);process.exit(failed > 0 ? 1 : 0);