From d2c1281e97a5de25cd2b032255359d3fe8a47b47 Mon Sep 17 00:00:00 2001 From: Affaan Mustafa Date: Fri, 13 Feb 2026 15:49:06 -0800 Subject: [PATCH] =?UTF-8?q?test:=20round=20100=20=E2=80=94=20findFiles=20m?= =?UTF-8?q?axAge+recursive=20interaction,=20parseSessionMetadata=20###=20t?= =?UTF-8?q?runcation,=20cleanupAliases=20falsy=20coercion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- tests/lib/session-aliases.test.js | 16 ++++++++++++++++ tests/lib/session-manager.test.js | 22 +++++++++++++++++++++ tests/lib/utils.test.js | 32 +++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) diff --git a/tests/lib/session-aliases.test.js b/tests/lib/session-aliases.test.js index bc7b912b..fb84b888 100644 --- a/tests/lib/session-aliases.test.js +++ b/tests/lib/session-aliases.test.js @@ -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); diff --git a/tests/lib/session-manager.test.js b/tests/lib/session-manager.test.js index a5100a15..3957f0c2 100644 --- a/tests/lib/session-manager.test.js +++ b/tests/lib/session-manager.test.js @@ -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); diff --git a/tests/lib/utils.test.js b/tests/lib/utils.test.js index c386406d..8ac9c532 100644 --- a/tests/lib/utils.test.js +++ b/tests/lib/utils.test.js @@ -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}`);