The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.
test: cover session-end message.role path, getExecCommand non-string args, and legacy hooks format
Affaan Mustafa2573cbb7b046
diff --git a/tests/ci/validators.test.js b/tests/ci/validators.test.jsindex ffc033a6c..a53e20723 100644--- a/tests/ci/validators.test.js+++ b/tests/ci/validators.test.js@@ -2053,6 +2053,31 @@ function runTests() {cleanupTestDir(testDir); cleanupTestDir(agentsDir); cleanupTestDir(skillsDir);})) passed++; else failed++;+ // ── Round 80: validate-hooks.js legacy array format (lines 115-135) ──+ console.log('\nRound 80: validate-hooks.js (legacy array format):');++ if (test('validates hooks in legacy array format (hooks is an array, not object)', () => {+ const testDir = createTestDir();+ // The legacy array format wraps hooks as { hooks: [...] } where the array+ // contains matcher objects directly. This exercises lines 115-135 of+ // validate-hooks.js which use "Hook ${i}" error labels instead of "${eventType}[${i}]".+ const hooksJson = JSON.stringify({+ hooks: [+ {+ matcher: 'Edit',+ hooks: [{ type: 'command', command: 'echo legacy test' }]+ }+ ]+ });+ fs.writeFileSync(path.join(testDir, 'hooks.json'), hooksJson);++ const result = runValidatorWithDir('validate-hooks', 'HOOKS_FILE', path.join(testDir, 'hooks.json'));+ assert.strictEqual(result.code, 0, 'Should pass on valid legacy array format');+ assert.ok(result.stdout.includes('Validated 1 hook'),+ `Should report 1 validated matcher, got: ${result.stdout}`);+ cleanupTestDir(testDir);+ })) passed++; else failed++;+// Summaryconsole.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.jsindex cc4a9cd54..278a14440 100644--- a/tests/hooks/hooks.test.js+++ b/tests/hooks/hooks.test.js@@ -3252,6 +3252,45 @@ async function runTests() {`stderr should contain [StrategicCompact] Error:, got: ${result.stderr}`);})) passed++; else failed++;+ // ── Round 80: session-end.js entry.message?.role === 'user' third OR condition ──+ console.log('\nRound 80: session-end.js (entry.message.role user — third OR condition):');++ if (await asyncTest('extracts user messages from entries where only message.role is user (not type or role)', async () => {+ const isoHome = path.join(os.tmpdir(), `ecc-msgrole-${Date.now()}`);+ const sessionsDir = path.join(isoHome, '.claude', 'sessions');+ fs.mkdirSync(sessionsDir, { recursive: true });++ const testDir = createTestDir();+ const transcriptPath = path.join(testDir, 'transcript.jsonl');+ // Entries where type is NOT 'user' and there is no direct role field,+ // but message.role IS 'user'. This exercises the third OR condition at+ // session-end.js line 48: entry.message?.role === 'user'+ const lines = [+ '{"type":"human","message":{"role":"user","content":"Refactor the auth module"}}',+ '{"type":"human","message":{"role":"assistant","content":"I will refactor it"}}',+ '{"type":"human","message":{"role":"user","content":"Add integration tests too"}}',+ ];+ fs.writeFileSync(transcriptPath, lines.join('\n'));+ const stdinJson = JSON.stringify({ transcript_path: transcriptPath });++ try {+ const result = await runScript(path.join(scriptsDir, 'session-end.js'), stdinJson, {+ HOME: isoHome, USERPROFILE: isoHome+ });+ assert.strictEqual(result.code, 0);++ const files = fs.readdirSync(sessionsDir).filter(f => f.endsWith('-session.tmp'));+ assert.ok(files.length > 0, 'Should create session file');+ const content = fs.readFileSync(path.join(sessionsDir, files[0]), 'utf8');+ // The third OR condition should fire for type:"human" + message.role:"user"+ assert.ok(content.includes('Refactor the auth module') || content.includes('auth'),+ `Session should include message extracted via message.role path. Got: ${content.substring(0, 300)}`);+ } finally {+ fs.rmSync(isoHome, { recursive: true, force: true });+ cleanupTestDir(testDir);+ }+ })) passed++; else failed++;+// Summaryconsole.log('\n=== Test Results ===');console.log(`Passed: ${passed}`);diff --git a/tests/lib/package-manager.test.js b/tests/lib/package-manager.test.jsindex 7a6be58c1..45c347e1e 100644--- a/tests/lib/package-manager.test.js+++ b/tests/lib/package-manager.test.js@@ -1331,6 +1331,25 @@ function runTests() {}})) passed++; else failed++;+ // ── Round 80: getExecCommand with truthy non-string args ──+ console.log('\nRound 80: getExecCommand (truthy non-string args):');++ if (test('getExecCommand with args=42 (truthy number) appends stringified value', () => {+ const originalEnv = process.env.CLAUDE_PACKAGE_MANAGER;+ try {+ process.env.CLAUDE_PACKAGE_MANAGER = 'npm';+ // args=42: truthy, so typeof check at line 334 short-circuits+ // (typeof 42 !== 'string'), skipping validation. Line 339:+ // 42 ? ' ' + 42 → ' 42' → appended.+ const cmd = pm.getExecCommand('prettier', 42);+ assert.ok(cmd.includes('prettier'), 'Should include binary name');+ assert.ok(cmd.includes('42'), 'Truthy number should be stringified and appended');+ } finally {+ if (originalEnv !== undefined) process.env.CLAUDE_PACKAGE_MANAGER = originalEnv;+ else delete process.env.CLAUDE_PACKAGE_MANAGER;+ }+ })) passed++; else failed++;+// Summaryconsole.log('\n=== Test Results ===');console.log(`Passed: ${passed}`);