From 4d016babbbd5c6b8c2049c04bca9714bdb15e30b Mon Sep 17 00:00:00 2001 From: Affaan Mustafa Date: Fri, 13 Feb 2026 15:54:02 -0800 Subject: [PATCH] =?UTF-8?q?test:=20round=20101=20=E2=80=94=20output()=20ci?= =?UTF-8?q?rcular=20crash,=20getSessionStats=20type=20confusion,=20appendS?= =?UTF-8?q?essionContent=20null?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - output() throws TypeError on circular reference object (JSON.stringify has no try/catch) - getSessionStats(123) throws TypeError (number reaches parseSessionMetadata, .match() fails) - appendSessionContent(null) returns false (TypeError caught by try/catch) Total tests: 863 --- tests/lib/session-manager.test.js | 20 ++++++++++++++++++++ tests/lib/utils.test.js | 13 +++++++++++++ 2 files changed, 33 insertions(+) diff --git a/tests/lib/session-manager.test.js b/tests/lib/session-manager.test.js index 3957f0c2..891be80a 100644 --- a/tests/lib/session-manager.test.js +++ b/tests/lib/session-manager.test.js @@ -1628,6 +1628,26 @@ src/main.ts 'Item text truncated at embedded ### (lazy regex stops at first ### match)'); })) passed++; else failed++; + // ── Round 101: getSessionStats with non-string input (number) throws TypeError ── + console.log('\nRound 101: getSessionStats (non-string input — type confusion crash):'); + if (test('getSessionStats(123) throws TypeError (number reaches parseSessionMetadata → .match() fails)', () => { + // typeof 123 === 'number' → looksLikePath = false → content = 123 + // parseSessionMetadata(123) → !123 is false → 123.match(...) → TypeError + assert.throws( + () => sessionManager.getSessionStats(123), + { name: 'TypeError' }, + 'Non-string input (number) should crash in parseSessionMetadata (.match not a function)' + ); + })) passed++; else failed++; + + // ── Round 101: appendSessionContent(null, 'content') returns false (error caught) ── + console.log('\nRound 101: appendSessionContent (null path — error handling):'); + if (test('appendSessionContent(null, content) returns false (TypeError caught by try/catch)', () => { + const result = sessionManager.appendSessionContent(null, 'some content'); + assert.strictEqual(result, false, + 'null path should cause fs.appendFileSync to throw TypeError, caught by try/catch'); + })) 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 8ac9c532..bf726175 100644 --- a/tests/lib/utils.test.js +++ b/tests/lib/utils.test.js @@ -1454,6 +1454,19 @@ function runTests() { } })) passed++; else failed++; + // ── Round 101: output() with circular reference object throws (no try/catch around JSON.stringify) ── + console.log('\nRound 101: output() (circular reference — JSON.stringify crash):'); + if (test('output() throws TypeError on circular reference object (JSON.stringify has no try/catch)', () => { + const circular = { a: 1 }; + circular.self = circular; // Creates circular reference + + assert.throws( + () => utils.output(circular), + { name: 'TypeError' }, + 'JSON.stringify of circular object should throw TypeError (no try/catch in output())' + ); + })) passed++; else failed++; + // Summary console.log('\n=== Test Results ==='); console.log(`Passed: ${passed}`);