fix: box alignment in test runner, update metadata counts, add 18 tests

- Fix run-all.js box alignment (hardcoded spaces 1 char short, now using dynamic padEnd)
- Update .opencode/index.ts metadata (12→13 agents, 24→31 commands, 16→37 skills)
- Add commandExists edge case tests (empty, spaces, path separators, metacharacters)
- Add findFiles edge case tests (? wildcard, mtime sorting, maxAge filtering)
- Add ensureDir race condition and return value tests
- Add runCommand output trimming and failure tests
- Add pre-compact session annotation and compaction log timestamp tests
- Add check-console-log invalid JSON handling test
- Add replaceInFile capture group test
- Add readStdinJson Promise type check
This commit is contained in:
Affaan Mustafa
2026-02-13 01:36:42 -08:00
parent 3f651b7c3c
commit 37309d47b7
4 changed files with 238 additions and 16 deletions

View File

@@ -218,6 +218,13 @@ async function runTests() {
assert.strictEqual(result.code, 0);
})) passed++; else failed++;
if (await asyncTest('handles invalid JSON stdin gracefully', async () => {
const result = await runScript(path.join(scriptsDir, 'check-console-log.js'), 'not valid json');
assert.strictEqual(result.code, 0, 'Should exit 0 on invalid JSON');
// Should still pass through the data
assert.ok(result.stdout.includes('not valid json'), 'Should pass through invalid data');
})) passed++; else failed++;
// session-end.js tests
console.log('\nsession-end.js:');
@@ -283,6 +290,53 @@ async function runTests() {
assert.ok(fs.existsSync(logFile), 'Compaction log should exist');
})) passed++; else failed++;
if (await asyncTest('annotates active session file with compaction marker', async () => {
const isoHome = path.join(os.tmpdir(), `ecc-compact-annotate-${Date.now()}`);
const sessionsDir = path.join(isoHome, '.claude', 'sessions');
fs.mkdirSync(sessionsDir, { recursive: true });
// Create an active .tmp session file
const sessionFile = path.join(sessionsDir, '2026-02-11-test-session.tmp');
fs.writeFileSync(sessionFile, '# Session: 2026-02-11\n**Started:** 10:00\n');
try {
await runScript(path.join(scriptsDir, 'pre-compact.js'), '', {
HOME: isoHome, USERPROFILE: isoHome
});
const content = fs.readFileSync(sessionFile, 'utf8');
assert.ok(
content.includes('Compaction occurred'),
'Should annotate the session file with compaction marker'
);
} finally {
fs.rmSync(isoHome, { recursive: true, force: true });
}
})) passed++; else failed++;
if (await asyncTest('compaction log contains timestamp', async () => {
const isoHome = path.join(os.tmpdir(), `ecc-compact-ts-${Date.now()}`);
const sessionsDir = path.join(isoHome, '.claude', 'sessions');
fs.mkdirSync(sessionsDir, { recursive: true });
try {
await runScript(path.join(scriptsDir, 'pre-compact.js'), '', {
HOME: isoHome, USERPROFILE: isoHome
});
const logFile = path.join(sessionsDir, 'compaction-log.txt');
assert.ok(fs.existsSync(logFile), 'Compaction log should exist');
const content = fs.readFileSync(logFile, 'utf8');
// Should have a timestamp like [2026-02-11 14:30:00]
assert.ok(
/\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\]/.test(content),
`Log should contain timestamped entry, got: ${content.substring(0, 100)}`
);
} finally {
fs.rmSync(isoHome, { recursive: true, force: true });
}
})) passed++; else failed++;
// suggest-compact.js tests
console.log('\nsuggest-compact.js:');