mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-03-30 13:43:26 +08:00
test: round 100 — findFiles maxAge+recursive interaction, parseSessionMetadata ### truncation, cleanupAliases falsy coercion
- findFiles with both maxAge AND recursive combined (option interaction test) - parseSessionMetadata truncates item text at embedded ### due to lazy regex - cleanupAliases callback returning 0 (falsy non-boolean) removes alias via !0 coercion Total tests: 860
This commit is contained in:
@@ -1294,6 +1294,22 @@ function runTests() {
|
||||
'Alias data should be preserved');
|
||||
})) passed++; else failed++;
|
||||
|
||||
// ── Round 100: cleanupAliases callback returning falsy non-boolean 0 ──
|
||||
console.log('\nRound 100: cleanupAliases (callback returns 0 — falsy non-boolean coercion):');
|
||||
if (test('cleanupAliases removes alias when callback returns 0 (falsy coercion: !0 === true)', () => {
|
||||
resetAliases();
|
||||
aliases.setAlias('zero-test', '/sessions/some-session', '2026-01-15');
|
||||
// callback returns 0 (a falsy value) — !0 === true → alias is removed
|
||||
const result = aliases.cleanupAliases(() => 0);
|
||||
assert.strictEqual(result.removed, 1,
|
||||
'Alias should be removed because !0 === true (JavaScript falsy coercion)');
|
||||
assert.strictEqual(result.success, true,
|
||||
'Cleanup should succeed');
|
||||
const resolved = aliases.resolveAlias('zero-test');
|
||||
assert.strictEqual(resolved, null,
|
||||
'Alias should no longer exist after removal');
|
||||
})) passed++; else failed++;
|
||||
|
||||
// Summary
|
||||
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
|
||||
process.exit(failed > 0 ? 1 : 0);
|
||||
|
||||
@@ -1606,6 +1606,28 @@ src/main.ts
|
||||
'null path should be caught by try/catch and return false');
|
||||
})) passed++; else failed++;
|
||||
|
||||
// ── Round 100: parseSessionMetadata with ### inside item text (premature section termination) ──
|
||||
console.log('\nRound 100: parseSessionMetadata (### in item text — lazy regex truncation):');
|
||||
if (test('parseSessionMetadata truncates item text at embedded ### due to lazy regex lookahead', () => {
|
||||
const content = `# Session
|
||||
|
||||
### Completed
|
||||
- [x] Fix issue ### with parser
|
||||
- [x] Normal task
|
||||
|
||||
### In Progress
|
||||
- [ ] Debug output
|
||||
`;
|
||||
const meta = sessionManager.parseSessionMetadata(content);
|
||||
// The lazy regex ([\s\S]*?)(?=###|\n\n|$) terminates at the first ###
|
||||
// So the Completed section captures only "- [x] Fix issue " (before the inner ###)
|
||||
// The second item "- [x] Normal task" is lost because it's after the inner ###
|
||||
assert.strictEqual(meta.completed.length, 1,
|
||||
'Only 1 item extracted — second item is after the inner ### terminator');
|
||||
assert.strictEqual(meta.completed[0], 'Fix issue',
|
||||
'Item text truncated at embedded ### (lazy regex stops at first ### match)');
|
||||
})) passed++; else failed++;
|
||||
|
||||
// Summary
|
||||
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
|
||||
process.exit(failed > 0 ? 1 : 0);
|
||||
|
||||
@@ -1422,6 +1422,38 @@ function runTests() {
|
||||
}
|
||||
})) passed++; else failed++;
|
||||
|
||||
// ── Round 100: findFiles with both maxAge AND recursive (interaction test) ──
|
||||
console.log('\nRound 100: findFiles (maxAge + recursive combined — untested interaction):');
|
||||
if (test('findFiles with maxAge AND recursive filters age across subdirectories', () => {
|
||||
const tmpDir = fs.mkdtempSync(path.join(utils.getTempDir(), 'r100-maxage-recur-'));
|
||||
const subDir = path.join(tmpDir, 'nested');
|
||||
try {
|
||||
fs.mkdirSync(subDir);
|
||||
// Create files: one in root, one in subdirectory
|
||||
const rootFile = path.join(tmpDir, 'root.txt');
|
||||
const nestedFile = path.join(subDir, 'nested.txt');
|
||||
fs.writeFileSync(rootFile, 'root file');
|
||||
fs.writeFileSync(nestedFile, 'nested file');
|
||||
|
||||
// maxAge: 1 with recursive: true — both files are fresh (ageInDays ≈ 0)
|
||||
const results = utils.findFiles(tmpDir, '*.txt', { maxAge: 1, recursive: true });
|
||||
assert.strictEqual(results.length, 2,
|
||||
'Both root and nested files should match (fresh, maxAge: 1, recursive: true)');
|
||||
|
||||
// maxAge: -1 with recursive: true — no files should match (age always >= 0)
|
||||
const noResults = utils.findFiles(tmpDir, '*.txt', { maxAge: -1, recursive: true });
|
||||
assert.strictEqual(noResults.length, 0,
|
||||
'maxAge: -1 should exclude all files even in subdirectories');
|
||||
|
||||
// maxAge: 1 with recursive: false — only root file
|
||||
const rootOnly = utils.findFiles(tmpDir, '*.txt', { maxAge: 1, recursive: false });
|
||||
assert.strictEqual(rootOnly.length, 1,
|
||||
'recursive: false should only find root-level file');
|
||||
} finally {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
}
|
||||
})) passed++; else failed++;
|
||||
|
||||
// Summary
|
||||
console.log('\n=== Test Results ===');
|
||||
console.log(`Passed: ${passed}`);
|
||||
|
||||
Reference in New Issue
Block a user