test: cover deleteSession catch, pre-compact and session-end main().catch

- session-manager: deleteSession returns false when dir is read-only (EACCES)
- pre-compact: main().catch handler when HOME is non-directory (ENOTDIR)
- session-end: main().catch handler when HOME is non-directory (ENOTDIR)

Total tests: 828 → 831
This commit is contained in:
Affaan Mustafa
2026-02-13 09:59:48 -08:00
parent 241c35a589
commit 723e69a621
2 changed files with 63 additions and 0 deletions

View File

@@ -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++;
// Summary
console.log('\n=== Test Results ===');
console.log(`Passed: ${passed}`);

View File

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