test: cover session-end message.role path, getExecCommand non-string args, and legacy hooks format

Round 80: Three previously untested conditional branches:
- session-end.js: entry.message?.role === 'user' third OR condition
  (fires when type is not 'user' but message.role is)
- package-manager.js: getExecCommand with truthy non-string args
  (typeof check short-circuits, value still appended via ternary)
- validate-hooks.js: legacy array format parsing path (lines 115-135)
  with 'Hook N' error labels instead of 'EventType[N]'
This commit is contained in:
Affaan Mustafa
2026-02-13 10:39:35 -08:00
parent 9dccdb9068
commit 2573cbb7b0
3 changed files with 83 additions and 0 deletions

View File

@@ -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++;
// Summary
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
process.exit(failed > 0 ? 1 : 0);