mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-04-09 02:43:29 +08:00
test: add 3 tests for suggest-compact, session-aliases, typecheck (Round 64)
- suggest-compact: 'default' session ID fallback when CLAUDE_SESSION_ID empty - session-aliases: loadAliases backfills missing version and metadata fields - post-edit-typecheck: valid JSON without tool_input passes through unchanged Total: 797 tests, all passing
This commit is contained in:
@@ -2999,6 +2999,19 @@ async function runTests() {
|
|||||||
'Should pass through data unchanged when tool_input is absent');
|
'Should pass through data unchanged when tool_input is absent');
|
||||||
})) passed++; else failed++;
|
})) passed++; else failed++;
|
||||||
|
|
||||||
|
// ── Round 64: post-edit-typecheck.js valid JSON without tool_input ──
|
||||||
|
console.log('\nRound 64: post-edit-typecheck.js (valid JSON without tool_input):');
|
||||||
|
|
||||||
|
if (await asyncTest('skips typecheck when JSON has no tool_input field', async () => {
|
||||||
|
const stdinJson = JSON.stringify({ result: 'ok', metadata: { action: 'test' } });
|
||||||
|
const result = await runScript(path.join(scriptsDir, 'post-edit-typecheck.js'), stdinJson);
|
||||||
|
|
||||||
|
assert.strictEqual(result.code, 0, 'Should exit 0 for JSON without tool_input');
|
||||||
|
// input.tool_input?.file_path is undefined → skips TS check → passes through
|
||||||
|
assert.strictEqual(result.stdout, stdinJson,
|
||||||
|
'Should pass through data unchanged when tool_input is absent');
|
||||||
|
})) passed++; else failed++;
|
||||||
|
|
||||||
// Summary
|
// Summary
|
||||||
console.log('\n=== Test Results ===');
|
console.log('\n=== Test Results ===');
|
||||||
console.log(`Passed: ${passed}`);
|
console.log(`Passed: ${passed}`);
|
||||||
|
|||||||
@@ -318,6 +318,30 @@ function runTests() {
|
|||||||
cleanupCounter();
|
cleanupCounter();
|
||||||
})) passed++; else failed++;
|
})) passed++; else failed++;
|
||||||
|
|
||||||
|
// ── Round 64: default session ID fallback ──
|
||||||
|
console.log('\nDefault session ID fallback (Round 64):');
|
||||||
|
|
||||||
|
if (test('uses "default" session ID when CLAUDE_SESSION_ID is empty', () => {
|
||||||
|
const defaultCounterFile = getCounterFilePath('default');
|
||||||
|
try { fs.unlinkSync(defaultCounterFile); } catch {}
|
||||||
|
try {
|
||||||
|
// Pass empty CLAUDE_SESSION_ID — falsy, so script uses 'default'
|
||||||
|
const env = { ...process.env, CLAUDE_SESSION_ID: '' };
|
||||||
|
const result = spawnSync('node', [compactScript], {
|
||||||
|
encoding: 'utf8',
|
||||||
|
input: '{}',
|
||||||
|
timeout: 10000,
|
||||||
|
env,
|
||||||
|
});
|
||||||
|
assert.strictEqual(result.status || 0, 0, 'Should exit 0');
|
||||||
|
assert.ok(fs.existsSync(defaultCounterFile), 'Counter file should use "default" session ID');
|
||||||
|
const count = parseInt(fs.readFileSync(defaultCounterFile, 'utf8').trim(), 10);
|
||||||
|
assert.strictEqual(count, 1, 'Counter should be 1 for first run with default session');
|
||||||
|
} finally {
|
||||||
|
try { fs.unlinkSync(defaultCounterFile); } catch {}
|
||||||
|
}
|
||||||
|
})) passed++; else failed++;
|
||||||
|
|
||||||
// Summary
|
// Summary
|
||||||
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
|
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
|
||||||
process.exit(failed > 0 ? 1 : 0);
|
process.exit(failed > 0 ? 1 : 0);
|
||||||
|
|||||||
@@ -896,6 +896,37 @@ function runTests() {
|
|||||||
}
|
}
|
||||||
})) passed++; else failed++;
|
})) passed++; else failed++;
|
||||||
|
|
||||||
|
// ── Round 64: loadAliases backfills missing version and metadata ──
|
||||||
|
console.log('\nRound 64: loadAliases version/metadata backfill:');
|
||||||
|
|
||||||
|
if (test('loadAliases backfills missing version and metadata fields', () => {
|
||||||
|
resetAliases();
|
||||||
|
const aliasesPath = aliases.getAliasesPath();
|
||||||
|
// Write a file with valid aliases but NO version and NO metadata
|
||||||
|
fs.writeFileSync(aliasesPath, JSON.stringify({
|
||||||
|
aliases: {
|
||||||
|
'backfill-test': {
|
||||||
|
sessionPath: '/sessions/backfill',
|
||||||
|
createdAt: '2026-01-15T00:00:00.000Z',
|
||||||
|
updatedAt: '2026-01-15T00:00:00.000Z',
|
||||||
|
title: 'Backfill Test'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
const data = aliases.loadAliases();
|
||||||
|
// Version should be backfilled to ALIAS_VERSION ('1.0')
|
||||||
|
assert.strictEqual(data.version, '1.0', 'Should backfill missing version to 1.0');
|
||||||
|
// Metadata should be backfilled with totalCount from aliases
|
||||||
|
assert.ok(data.metadata, 'Should backfill missing metadata object');
|
||||||
|
assert.strictEqual(data.metadata.totalCount, 1, 'Metadata totalCount should match alias count');
|
||||||
|
assert.ok(data.metadata.lastUpdated, 'Metadata should have lastUpdated');
|
||||||
|
// Alias data should be preserved
|
||||||
|
assert.ok(data.aliases['backfill-test'], 'Alias data should be preserved');
|
||||||
|
assert.strictEqual(data.aliases['backfill-test'].sessionPath, '/sessions/backfill');
|
||||||
|
resetAliases();
|
||||||
|
})) passed++; else failed++;
|
||||||
|
|
||||||
// Summary
|
// Summary
|
||||||
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
|
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
|
||||||
process.exit(failed > 0 ? 1 : 0);
|
process.exit(failed > 0 ? 1 : 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user