From 233b3415579f42a1f859eaa63cafd2f998bde35f Mon Sep 17 00:00:00 2001 From: Affaan Mustafa Date: Fri, 13 Feb 2026 14:50:49 -0800 Subject: [PATCH] test: add 3 tests for alternation regex, double-negative clamping, and self-rename (Round 95) --- tests/lib/session-aliases.test.js | 22 ++++++++++++++++++++++ tests/lib/session-manager.test.js | 16 ++++++++++++++++ tests/lib/utils.test.js | 18 ++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/tests/lib/session-aliases.test.js b/tests/lib/session-aliases.test.js index f3a08842..bc7b912b 100644 --- a/tests/lib/session-aliases.test.js +++ b/tests/lib/session-aliases.test.js @@ -1272,6 +1272,28 @@ function runTests() { } })) passed++; else failed++; + // ── Round 95: renameAlias with same old and new name (self-rename) ── + console.log('\nRound 95: renameAlias (self-rename same name):'); + + if (test('renameAlias returns "already exists" error when renaming alias to itself', () => { + resetAliases(); + // Create an alias first + const created = aliases.setAlias('self-rename', '/path/session', 'Self Rename'); + assert.strictEqual(created.success, true, 'Setup: alias should be created'); + + // Attempt to rename to the same name + const result = aliases.renameAlias('self-rename', 'self-rename'); + assert.strictEqual(result.success, false, 'Renaming to itself should fail'); + assert.ok(result.error.includes('already exists'), + 'Error should indicate alias already exists (line 333-334 check)'); + + // Verify original alias is still intact + const resolved = aliases.resolveAlias('self-rename'); + assert.ok(resolved, 'Original alias should still exist after failed self-rename'); + assert.strictEqual(resolved.sessionPath, '/path/session', + 'Alias data should be preserved'); + })) 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 ff1c023d..3d808588 100644 --- a/tests/lib/session-manager.test.js +++ b/tests/lib/session-manager.test.js @@ -1488,6 +1488,22 @@ src/main.ts 'Content without session items should have 0 totalItems'); })) passed++; else failed++; + // ── Round 95: getAllSessions with both negative offset AND negative limit ── + console.log('\nRound 95: getAllSessions (both negative offset and negative limit):'); + + if (test('getAllSessions clamps both negative offset (to 0) and negative limit (to 1) simultaneously', () => { + const result = sessionManager.getAllSessions({ offset: -5, limit: -10 }); + // offset clamped: Math.max(0, Math.floor(-5)) → 0 + // limit clamped: Math.max(1, Math.floor(-10)) → 1 + // slice(0, 0+1) → first session only + assert.strictEqual(result.offset, 0, + 'Negative offset should be clamped to 0'); + assert.strictEqual(result.limit, 1, + 'Negative limit should be clamped to 1'); + assert.ok(result.sessions.length <= 1, + 'Should return at most 1 session (slice(0, 1))'); + })) 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 bfbc61bd..67c2d737 100644 --- a/tests/lib/utils.test.js +++ b/tests/lib/utils.test.js @@ -1282,6 +1282,24 @@ function runTests() { } })) passed++; else failed++; + // ── Round 95: countInFile with regex alternation (no g flag) ── + console.log('\nRound 95: countInFile (regex alternation without g flag):'); + + if (test('countInFile with /apple|banana/ (alternation, no g) counts all matches', () => { + const tmpDir = path.join(utils.getTempDir(), `ecc-r95-alternation-${Date.now()}`); + fs.mkdirSync(tmpDir, { recursive: true }); + const testFile = path.join(tmpDir, 'alternation.txt'); + try { + utils.writeFile(testFile, 'apple banana apple cherry banana apple'); + // /apple|banana/ has alternation but no g flag — countInFile should auto-append g + const count = utils.countInFile(testFile, /apple|banana/); + assert.strictEqual(count, 5, + 'Should find 3 apples + 2 bananas = 5 total (g flag auto-appended to alternation regex)'); + } finally { + fs.rmSync(tmpDir, { recursive: true, force: true }); + } + })) passed++; else failed++; + // Summary console.log('\n=== Test Results ==='); console.log(`Passed: ${passed}`);