mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-04-07 17:53:32 +08:00
test: add 10 tests for birthtime fallback, stdin error, alias rollback (Round 33)
Cover createdTime/birthtime fallback in session-manager, readStdinJson error event settled-flag guard in utils, renameAlias rollback on naming conflict in session-aliases, and saveAliases backup preservation on serialization failure. Total: 713 tests.
This commit is contained in:
@@ -1009,6 +1009,67 @@ src/main.ts
|
||||
assert.ok(true, 'Old format handled without crash');
|
||||
})) passed++; else failed++;
|
||||
|
||||
// ── Round 33: birthtime / createdTime fallback ──
|
||||
console.log('\ncreatedTime fallback (Round 33):');
|
||||
|
||||
// Use HOME override approach (consistent with existing getAllSessions tests)
|
||||
const r33Home = path.join(os.tmpdir(), `ecc-r33-birthtime-${Date.now()}`);
|
||||
const r33SessionsDir = path.join(r33Home, '.claude', 'sessions');
|
||||
fs.mkdirSync(r33SessionsDir, { recursive: true });
|
||||
const r33OrigHome = process.env.HOME;
|
||||
const r33OrigProfile = process.env.USERPROFILE;
|
||||
process.env.HOME = r33Home;
|
||||
process.env.USERPROFILE = r33Home;
|
||||
|
||||
const r33Filename = '2026-02-13-r33birth-session.tmp';
|
||||
const r33FilePath = path.join(r33SessionsDir, r33Filename);
|
||||
fs.writeFileSync(r33FilePath, '{"type":"test"}');
|
||||
|
||||
if (test('getAllSessions returns createdTime from birthtime when available', () => {
|
||||
const result = sessionManager.getAllSessions({ limit: 100 });
|
||||
assert.ok(result.sessions.length > 0, 'Should find the test session');
|
||||
const session = result.sessions[0];
|
||||
assert.ok(session.createdTime instanceof Date, 'createdTime should be a Date');
|
||||
// birthtime should be populated on macOS/Windows — createdTime should match it
|
||||
const stats = fs.statSync(r33FilePath);
|
||||
if (stats.birthtime && stats.birthtime.getTime() > 0) {
|
||||
assert.strictEqual(
|
||||
session.createdTime.getTime(),
|
||||
stats.birthtime.getTime(),
|
||||
'createdTime should match birthtime when available'
|
||||
);
|
||||
}
|
||||
})) passed++; else failed++;
|
||||
|
||||
if (test('getSessionById returns createdTime field', () => {
|
||||
const session = sessionManager.getSessionById('r33birth');
|
||||
assert.ok(session, 'Should find the session');
|
||||
assert.ok(session.createdTime instanceof Date, 'createdTime should be a Date');
|
||||
assert.ok(session.createdTime.getTime() > 0, 'createdTime should be non-zero');
|
||||
})) passed++; else failed++;
|
||||
|
||||
if (test('createdTime falls back to ctime when birthtime is epoch-zero', () => {
|
||||
// This tests the || fallback logic: stats.birthtime || stats.ctime
|
||||
// On some FS, birthtime may be epoch 0 (falsy as a Date number comparison
|
||||
// but truthy as a Date object). The fallback is defensive.
|
||||
const stats = fs.statSync(r33FilePath);
|
||||
// Both birthtime and ctime should be valid Dates on any modern OS
|
||||
assert.ok(stats.ctime instanceof Date, 'ctime should exist');
|
||||
// The fallback expression `birthtime || ctime` should always produce a valid Date
|
||||
const fallbackResult = stats.birthtime || stats.ctime;
|
||||
assert.ok(fallbackResult instanceof Date, 'Fallback should produce a Date');
|
||||
assert.ok(fallbackResult.getTime() > 0, 'Fallback date should be non-zero');
|
||||
})) passed++; else failed++;
|
||||
|
||||
// Cleanup Round 33 HOME override
|
||||
process.env.HOME = r33OrigHome;
|
||||
if (r33OrigProfile !== undefined) {
|
||||
process.env.USERPROFILE = r33OrigProfile;
|
||||
} else {
|
||||
delete process.env.USERPROFILE;
|
||||
}
|
||||
try { fs.rmSync(r33Home, { recursive: true, force: true }); } catch {}
|
||||
|
||||
// Summary
|
||||
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
|
||||
process.exit(failed > 0 ? 1 : 0);
|
||||
|
||||
Reference in New Issue
Block a user