From e70d4d223755145583a29bb32876c659aa2b9738 Mon Sep 17 00:00:00 2001 From: Affaan Mustafa Date: Fri, 13 Feb 2026 12:49:53 -0800 Subject: [PATCH] test: add 3 tests for replaceInFile deletion, parseSessionMetadata null fields, countInFile zero matches (Round 88) - replaceInFile with empty replacement string verifies text deletion works - parseSessionMetadata asserts date/started/lastUpdated are null when fields absent - countInFile with valid file but non-matching pattern returns 0 Total: 824 tests --- tests/lib/session-manager.test.js | 16 +++++++++++++ tests/lib/utils.test.js | 37 +++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/tests/lib/session-manager.test.js b/tests/lib/session-manager.test.js index d96c3dc9..365afe1a 100644 --- a/tests/lib/session-manager.test.js +++ b/tests/lib/session-manager.test.js @@ -1385,6 +1385,22 @@ src/main.ts } })) passed++; else failed++; + // ── Round 88: parseSessionMetadata null date/started/lastUpdated fields ── + console.log('\nRound 88: parseSessionMetadata content lacking Date/Started/Updated fields:'); + if (test('parseSessionMetadata returns null for date, started, lastUpdated when fields absent', () => { + const content = '# Title Only\n\n### Notes for Next Session\nSome notes\n'; + const meta = sessionManager.parseSessionMetadata(content); + assert.strictEqual(meta.date, null, + 'date should be null when **Date:** field is absent'); + assert.strictEqual(meta.started, null, + 'started should be null when **Started:** field is absent'); + assert.strictEqual(meta.lastUpdated, null, + 'lastUpdated should be null when **Last Updated:** field is absent'); + // Confirm other fields still parse correctly + assert.strictEqual(meta.title, 'Title Only'); + assert.strictEqual(meta.notes, 'Some notes'); + })) 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 6029f2fa..72ece4c7 100644 --- a/tests/lib/utils.test.js +++ b/tests/lib/utils.test.js @@ -1194,6 +1194,43 @@ function runTests() { `At CWD=/ with no session ID, should use the fallback parameter. Got: "${result.stdout}"`); })) passed++; else failed++; + // ── Round 88: replaceInFile with empty replacement (deletion) ── + console.log('\nRound 88: replaceInFile with empty replacement string (deletion):'); + if (test('replaceInFile with empty string replacement deletes matched text', () => { + const tmpDir = path.join(utils.getTempDir(), `ecc-r88-replace-empty-${Date.now()}`); + fs.mkdirSync(tmpDir, { recursive: true }); + const tmpFile = path.join(tmpDir, 'delete-test.txt'); + try { + fs.writeFileSync(tmpFile, 'hello REMOVE_ME world'); + const result = utils.replaceInFile(tmpFile, 'REMOVE_ME ', ''); + assert.strictEqual(result, true, 'Should return true on successful replacement'); + const content = fs.readFileSync(tmpFile, 'utf8'); + assert.strictEqual(content, 'hello world', + 'Empty replacement should delete the matched text'); + } finally { + fs.rmSync(tmpDir, { recursive: true, force: true }); + } + })) passed++; else failed++; + + // ── Round 88: countInFile with valid file but zero matches ── + console.log('\nRound 88: countInFile with existing file but non-matching pattern:'); + if (test('countInFile returns 0 for valid file with no pattern matches', () => { + const tmpDir = path.join(utils.getTempDir(), `ecc-r88-count-zero-${Date.now()}`); + fs.mkdirSync(tmpDir, { recursive: true }); + const tmpFile = path.join(tmpDir, 'no-match.txt'); + try { + fs.writeFileSync(tmpFile, 'apple banana cherry'); + const count = utils.countInFile(tmpFile, 'ZZZZNOTHERE'); + assert.strictEqual(count, 0, + 'Should return 0 when regex matches nothing in existing file'); + const countRegex = utils.countInFile(tmpFile, /ZZZZNOTHERE/g); + assert.strictEqual(countRegex, 0, + 'Should return 0 for RegExp with no matches in existing file'); + } finally { + fs.rmSync(tmpDir, { recursive: true, force: true }); + } + })) passed++; else failed++; + // Summary console.log('\n=== Test Results ==='); console.log(`Passed: ${passed}`);