The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.
test: cover deleteSession catch, pre-compact and session-end main().catch
Affaan Mustafa723e69a62159
diff --git a/tests/hooks/hooks.test.js b/tests/hooks/hooks.test.jsindex cc44d17dd..193bb4801 100644--- a/tests/hooks/hooks.test.js+++ b/tests/hooks/hooks.test.js@@ -3173,6 +3173,46 @@ async function runTests() {`stderr should contain [SessionStart] Error:, got: ${result.stderr}`);})) passed++; else failed++;+ // ── Round 75: pre-compact.js main().catch handler ──+ console.log('\nRound 75: pre-compact.js (main catch — unrecoverable error):');++ if (await asyncTest('pre-compact exits 0 with error message when HOME is non-directory', async () => {+ if (process.platform === 'win32') {+ console.log(' (skipped — /dev/null not available on Windows)');+ return;+ }+ // HOME=/dev/null makes ensureDir(sessionsDir) throw ENOTDIR,+ // which propagates to main().catch — the top-level error boundary+ const result = await runScript(path.join(scriptsDir, 'pre-compact.js'), '', {+ HOME: '/dev/null',+ USERPROFILE: '/dev/null'+ });+ assert.strictEqual(result.code, 0,+ `Should exit 0 (don't block on errors), got ${result.code}`);+ assert.ok(result.stderr.includes('[PreCompact] Error:'),+ `stderr should contain [PreCompact] Error:, got: ${result.stderr}`);+ })) passed++; else failed++;++ // ── Round 75: session-end.js main().catch handler ──+ console.log('\nRound 75: session-end.js (main catch — unrecoverable error):');++ if (await asyncTest('session-end exits 0 with error message when HOME is non-directory', async () => {+ if (process.platform === 'win32') {+ console.log(' (skipped — /dev/null not available on Windows)');+ return;+ }+ // HOME=/dev/null makes ensureDir(sessionsDir) throw ENOTDIR inside main(),+ // which propagates to runMain().catch — the top-level error boundary+ const result = await runScript(path.join(scriptsDir, 'session-end.js'), '{}', {+ HOME: '/dev/null',+ USERPROFILE: '/dev/null'+ });+ assert.strictEqual(result.code, 0,+ `Should exit 0 (don't block on errors), got ${result.code}`);+ assert.ok(result.stderr.includes('[SessionEnd] Error:'),+ `stderr should contain [SessionEnd] Error:, got: ${result.stderr}`);+ })) 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 93fcc44d8..102d252b9 100644--- a/tests/lib/session-manager.test.js+++ b/tests/lib/session-manager.test.js@@ -1207,6 +1207,29 @@ src/main.ts}})) passed++; else failed++;+ // ── Round 75: deleteSession catch — unlinkSync throws on read-only dir ──+ console.log('\nRound 75: deleteSession (unlink failure in read-only dir):');++ if (test('deleteSession returns false when file exists but directory is read-only', () => {+ if (process.platform === 'win32' || process.getuid?.() === 0) {+ console.log(' (skipped — chmod ineffective on Windows/root)');+ return;+ }+ const tmpDir = path.join(os.tmpdir(), `sm-del-ro-${Date.now()}`);+ fs.mkdirSync(tmpDir, { recursive: true });+ const sessionFile = path.join(tmpDir, 'test-session.tmp');+ fs.writeFileSync(sessionFile, 'session content');+ try {+ // Make directory read-only so unlinkSync throws EACCES+ fs.chmodSync(tmpDir, 0o555);+ const result = sessionManager.deleteSession(sessionFile);+ assert.strictEqual(result, false, 'Should return false when unlinkSync fails');+ } finally {+ try { fs.chmodSync(tmpDir, 0o755); } catch { /* best-effort */ }+ fs.rmSync(tmpDir, { recursive: true, force: true });+ }+ })) passed++; else failed++;+// Summaryconsole.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);process.exit(failed > 0 ? 1 : 0);