From b9a38b2680035372948c20ca31fdd679c9697d76 Mon Sep 17 00:00:00 2001 From: Affaan Mustafa Date: Fri, 13 Feb 2026 14:05:24 -0800 Subject: [PATCH] test: add Round 92 tests for object pattern, UNC path, and empty packageManager - Test countInFile returns 0 for object pattern type (non-string non-RegExp) - Test getSessionStats treats Windows UNC path as content (not file path) - Test detectFromPackageJson returns null for empty string packageManager field Total tests: 836 --- tests/lib/package-manager.test.js | 16 ++++++++++++++++ tests/lib/session-manager.test.js | 13 +++++++++++++ tests/lib/utils.test.js | 17 +++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/tests/lib/package-manager.test.js b/tests/lib/package-manager.test.js index 22a94324..2aca8cfc 100644 --- a/tests/lib/package-manager.test.js +++ b/tests/lib/package-manager.test.js @@ -1396,6 +1396,22 @@ function runTests() { cleanupTestDir(testDir); })) passed++; else failed++; + // ── Round 92: detectFromPackageJson with empty string packageManager ── + console.log('\nRound 92: detectFromPackageJson (empty string packageManager):'); + + if (test('detectFromPackageJson returns null for empty string packageManager field', () => { + // package-manager.js line 114: if (pkg.packageManager) — empty string "" is falsy, + // so the if block is skipped entirely. Function returns null without attempting split. + // This is distinct from Round 91's whitespace test (" " is truthy and enters the if). + const testDir = createTestDir(); + fs.writeFileSync( + path.join(testDir, 'package.json'), + JSON.stringify({ name: 'test', packageManager: '' })); + const result = pm.detectFromPackageJson(testDir); + assert.strictEqual(result, null, 'Empty string packageManager should return null (falsy)'); + cleanupTestDir(testDir); + })) passed++; else failed++; + // Summary console.log('\n=== Test Results ==='); console.log(`Passed: ${passed}`); diff --git a/tests/lib/session-manager.test.js b/tests/lib/session-manager.test.js index 0e0962d5..6e83cc6c 100644 --- a/tests/lib/session-manager.test.js +++ b/tests/lib/session-manager.test.js @@ -1461,6 +1461,19 @@ src/main.ts assert.strictEqual(stats.totalItems, 0, 'Non-existent path should have 0 items'); })) passed++; else failed++; + // ── Round 92: getSessionStats with UNC path treated as content ── + console.log('\nRound 92: getSessionStats (Windows UNC path):'); + + if (test('getSessionStats treats UNC path as content (not recognized as file path)', () => { + // session-manager.js line 163-166: The path heuristic checks for Unix paths + // (starts with /) and Windows drive-letter paths (/^[A-Za-z]:[/\\]/). UNC paths + // (\\server\share\file.tmp) don't match either pattern, so the function treats + // the string as pre-read content rather than a file path to read. + const stats = sessionManager.getSessionStats('\\\\server\\share\\session.tmp'); + assert.strictEqual(stats.lineCount, 1, + 'UNC path should be treated as single-line content (not a recognized path)'); + })) 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 72ece4c7..515f6383 100644 --- a/tests/lib/utils.test.js +++ b/tests/lib/utils.test.js @@ -1231,6 +1231,23 @@ function runTests() { } })) passed++; else failed++; + // ── Round 92: countInFile with object pattern type ── + console.log('\nRound 92: countInFile (non-string non-RegExp pattern):'); + + if (test('countInFile returns 0 for object pattern (neither string nor RegExp)', () => { + // utils.js line 443-444: The else branch returns 0 when pattern is + // not instanceof RegExp and typeof !== 'string'. An object like {invalid: true} + // triggers this early return without throwing. + const testFile = path.join(utils.getTempDir(), `utils-test-obj-pattern-${Date.now()}.txt`); + try { + utils.writeFile(testFile, 'some test content to match against'); + const count = utils.countInFile(testFile, { invalid: 'object' }); + assert.strictEqual(count, 0, 'Object pattern should return 0'); + } finally { + try { fs.unlinkSync(testFile); } catch { /* best-effort */ } + } + })) passed++; else failed++; + // Summary console.log('\n=== Test Results ==='); console.log(`Passed: ${passed}`);