From 14dfe4d1109a4c76695523f6d46252090530af72 Mon Sep 17 00:00:00 2001 From: Affaan Mustafa Date: Fri, 13 Feb 2026 14:02:41 -0800 Subject: [PATCH] test: add Round 91 tests for empty action pattern, whitespace PM, and mixed separators - Test getCommandPattern('') produces valid regex for empty action string - Test detectFromPackageJson returns null for whitespace-only packageManager - Test getSessionStats treats mixed Windows path separators as file path Total tests: 833 --- tests/lib/package-manager.test.js | 33 +++++++++++++++++++++++++++++++ tests/lib/session-manager.test.js | 13 ++++++++++++ 2 files changed, 46 insertions(+) diff --git a/tests/lib/package-manager.test.js b/tests/lib/package-manager.test.js index 1dc70d5f..22a94324 100644 --- a/tests/lib/package-manager.test.js +++ b/tests/lib/package-manager.test.js @@ -1363,6 +1363,39 @@ function runTests() { cleanupTestDir(testDir); })) passed++; else failed++; + // ── Round 91: getCommandPattern with empty action string ── + console.log('\nRound 91: getCommandPattern (empty action):'); + + if (test('getCommandPattern with empty string returns valid regex pattern', () => { + // package-manager.js line 401-409: Empty action falls to the else branch. + // escapeRegex('') returns '', producing patterns like 'npm run ', 'yarn '. + // The resulting combined regex should be compilable (not throw). + const pattern = pm.getCommandPattern(''); + assert.ok(typeof pattern === 'string', 'Should return a string'); + assert.ok(pattern.length > 0, 'Should return non-empty pattern'); + // Verify the pattern compiles without error + const regex = new RegExp(pattern); + assert.ok(regex instanceof RegExp, 'Pattern should compile to valid RegExp'); + // The pattern should match package manager commands with trailing space + assert.ok(regex.test('npm run '), 'Should match "npm run " with trailing space'); + assert.ok(regex.test('yarn '), 'Should match "yarn " with trailing space'); + })) passed++; else failed++; + + // ── Round 91: detectFromPackageJson with whitespace-only packageManager ── + console.log('\nRound 91: detectFromPackageJson (whitespace-only packageManager):'); + + if (test('detectFromPackageJson returns null for whitespace-only packageManager field', () => { + // package-manager.js line 114-119: " " is truthy, so enters the if block. + // " ".split('@')[0] = " " which doesn't match any PACKAGE_MANAGERS key. + const testDir = createTestDir(); + fs.writeFileSync( + path.join(testDir, 'package.json'), + JSON.stringify({ packageManager: ' ' })); + const result = pm.detectFromPackageJson(testDir); + assert.strictEqual(result, null, 'Whitespace-only packageManager should return null'); + 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 b1704e80..0e0962d5 100644 --- a/tests/lib/session-manager.test.js +++ b/tests/lib/session-manager.test.js @@ -1448,6 +1448,19 @@ src/main.ts } })) passed++; else failed++; + // ── Round 91: getSessionStats with mixed Windows path separators ── + console.log('\nRound 91: getSessionStats (mixed Windows path separators):'); + + if (test('getSessionStats treats mixed Windows separators as a file path', () => { + // session-manager.js line 166: regex /^[A-Za-z]:[/\\]/ checks only the + // character right after the colon. Mixed separators like C:\Users/Mixed\session.tmp + // should still match because the first separator (\) satisfies the regex. + const stats = sessionManager.getSessionStats('C:\\Users/Mixed\\session.tmp'); + assert.strictEqual(stats.lineCount, 0, + 'Mixed separators should be treated as path (file does not exist → lineCount 0)'); + assert.strictEqual(stats.totalItems, 0, 'Non-existent path should have 0 items'); + })) passed++; else failed++; + // Summary console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`); process.exit(failed > 0 ? 1 : 0);