From 0ab69035a019f43fdbd8899fbd16e6b872bde963 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 20 Jan 2026 07:58:49 +0000 Subject: [PATCH 1/7] Initial plan From 6f198d3a2b0aa3ade461354011c045073c12aa6c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 20 Jan 2026 08:02:24 +0000 Subject: [PATCH 2/7] Simplify test by replacing brittle parsing with fixtures file Co-authored-by: PrabothCharith <91902549+PrabothCharith@users.noreply.github.com> --- package-lock.json | 4 +- test/fixtures/package-managers.json | 1 + test/pm-test.mjs | 73 ++--------------------------- 3 files changed, 7 insertions(+), 71 deletions(-) create mode 100644 test/fixtures/package-managers.json diff --git a/package-lock.json b/package-lock.json index b8875e5..f4f3601 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "nxt-gen-cli", - "version": "2.1.3", + "version": "2.1.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "nxt-gen-cli", - "version": "2.1.3", + "version": "2.1.4", "license": "MIT", "dependencies": { "boxen": "^8.0.1", diff --git a/test/fixtures/package-managers.json b/test/fixtures/package-managers.json new file mode 100644 index 0000000..4f380a8 --- /dev/null +++ b/test/fixtures/package-managers.json @@ -0,0 +1 @@ +["npm", "pnpm", "yarn", "bun"] diff --git a/test/pm-test.mjs b/test/pm-test.mjs index f7e3306..390cb51 100755 --- a/test/pm-test.mjs +++ b/test/pm-test.mjs @@ -11,80 +11,15 @@ import { fileURLToPath } from 'url'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); -// Import PACKAGE_MANAGERS constant from compiled pm.js or fallback to reading source +// Import PACKAGE_MANAGERS constant from compiled pm.js or fallback to test fixtures let PACKAGE_MANAGERS; try { const pmModule = await import('../dist/lib/pm.js'); PACKAGE_MANAGERS = pmModule.PACKAGE_MANAGERS; } catch { - // Fallback: read from source file if dist not available - try { - const pmSourcePath = path.join(__dirname, '..', 'src', 'lib', 'pm.ts'); - const pmSource = fs.readFileSync(pmSourcePath, 'utf-8'); - - // Locate the PACKAGE_MANAGERS declaration - const declIndex = pmSource.indexOf('export const PACKAGE_MANAGERS'); - if (declIndex === -1) { - throw new Error('Could not find PACKAGE_MANAGERS constant'); - } - - // Find the start of the array literal (`[`) after the equals sign - const equalsIndex = pmSource.indexOf('=', declIndex); - if (equalsIndex === -1) { - throw new Error('Could not find assignment for PACKAGE_MANAGERS'); - } - - const bracketStart = pmSource.indexOf('[', equalsIndex); - if (bracketStart === -1) { - throw new Error('Could not find opening bracket for PACKAGE_MANAGERS array'); - } - - // Walk forward to find the matching closing bracket, accounting for nested brackets - let depth = 0; - let bracketEnd = -1; - for (let i = bracketStart; i < pmSource.length; i++) { - const ch = pmSource[i]; - if (ch === '[') { - depth++; - } else if (ch === ']') { - depth--; - if (depth === 0) { - bracketEnd = i; - break; - } - } - } - - if (bracketEnd === -1) { - throw new Error('Could not find closing bracket for PACKAGE_MANAGERS array'); - } - - const arrayContent = pmSource.slice(bracketStart + 1, bracketEnd); - - // Remove line and block comments to avoid confusing the string matcher - const withoutComments = arrayContent - .replace(/\/\/.*$/gm, '') - .replace(/\/\*[\s\S]*?\*\//g, ''); - - // Match all string and template literals inside the array - const stringLiteralRegex = /(['"`])((?:\\.|(?!\1).)*)\1/g; - const values = []; - let match; - while ((match = stringLiteralRegex.exec(withoutComments)) !== null) { - values.push(match[2]); - } - - if (values.length === 0) { - throw new Error('Could not parse package manager values'); - } - - PACKAGE_MANAGERS = values; - } catch (error) { - console.error(' ✗ Could not load PACKAGE_MANAGERS constant'); - console.error(` Error: ${error.message}`); - console.error(' Please run "npm run build" first'); - process.exit(1); - } + // Fallback: load from test fixtures file + const fixturesPath = path.join(__dirname, 'fixtures', 'package-managers.json'); + PACKAGE_MANAGERS = JSON.parse(fs.readFileSync(fixturesPath, 'utf-8')); } console.log('='.repeat(60)); From 218238581b1c71c41a4ef46e5c4eccc4d0ad0112 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 20 Jan 2026 08:04:09 +0000 Subject: [PATCH 3/7] Add error handling to fixtures fallback Co-authored-by: PrabothCharith <91902549+PrabothCharith@users.noreply.github.com> --- test/pm-test.mjs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/pm-test.mjs b/test/pm-test.mjs index 390cb51..6935a10 100755 --- a/test/pm-test.mjs +++ b/test/pm-test.mjs @@ -18,8 +18,15 @@ try { PACKAGE_MANAGERS = pmModule.PACKAGE_MANAGERS; } catch { // Fallback: load from test fixtures file - const fixturesPath = path.join(__dirname, 'fixtures', 'package-managers.json'); - PACKAGE_MANAGERS = JSON.parse(fs.readFileSync(fixturesPath, 'utf-8')); + try { + const fixturesPath = path.join(__dirname, 'fixtures', 'package-managers.json'); + PACKAGE_MANAGERS = JSON.parse(fs.readFileSync(fixturesPath, 'utf-8')); + } catch (error) { + console.error(' ✗ Could not load PACKAGE_MANAGERS constant'); + console.error(` Error: ${error.message}`); + console.error(' Please run "npm run build" or check test/fixtures/package-managers.json'); + process.exit(1); + } } console.log('='.repeat(60)); From 87cda63a40b33cc744fe35a3b7073e7f0ad156a9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 20 Jan 2026 08:05:10 +0000 Subject: [PATCH 4/7] Add documentation for test fixtures Co-authored-by: PrabothCharith <91902549+PrabothCharith@users.noreply.github.com> --- test/fixtures/README.md | 9 +++++++++ test/fixtures/package-managers.json | 7 ++++++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/README.md diff --git a/test/fixtures/README.md b/test/fixtures/README.md new file mode 100644 index 0000000..4c3a7a1 --- /dev/null +++ b/test/fixtures/README.md @@ -0,0 +1,9 @@ +# Test Fixtures + +This directory contains test fixture files used by the test suite. + +## package-managers.json + +Contains the list of supported package managers for testing purposes. This file should be kept in sync with the `PACKAGE_MANAGERS` constant in `src/lib/pm.ts`. + +**Note**: This file is used as a fallback when the compiled `dist/lib/pm.js` is not available. Update this file whenever the list of supported package managers changes in the source code. diff --git a/test/fixtures/package-managers.json b/test/fixtures/package-managers.json index 4f380a8..7206684 100644 --- a/test/fixtures/package-managers.json +++ b/test/fixtures/package-managers.json @@ -1 +1,6 @@ -["npm", "pnpm", "yarn", "bun"] +[ + "npm", + "pnpm", + "yarn", + "bun" +] From 500c551033c5a616b082e627e1cc91e6cbc798fe Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 20 Jan 2026 08:06:58 +0000 Subject: [PATCH 5/7] Add automated validation for fixtures sync Co-authored-by: PrabothCharith <91902549+PrabothCharith@users.noreply.github.com> --- test/fixtures/README.md | 2 +- test/pm-test.mjs | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/test/fixtures/README.md b/test/fixtures/README.md index 4c3a7a1..a42088b 100644 --- a/test/fixtures/README.md +++ b/test/fixtures/README.md @@ -6,4 +6,4 @@ This directory contains test fixture files used by the test suite. Contains the list of supported package managers for testing purposes. This file should be kept in sync with the `PACKAGE_MANAGERS` constant in `src/lib/pm.ts`. -**Note**: This file is used as a fallback when the compiled `dist/lib/pm.js` is not available. Update this file whenever the list of supported package managers changes in the source code. +**Note**: This file is used as a fallback when the compiled `dist/lib/pm.js` is not available. The test suite includes an automatic validation check (Test 5) that will fail if this file becomes out of sync with the source code, ensuring you'll be notified if an update is needed. diff --git a/test/pm-test.mjs b/test/pm-test.mjs index 6935a10..0e423b1 100755 --- a/test/pm-test.mjs +++ b/test/pm-test.mjs @@ -93,6 +93,43 @@ try { process.exit(1); } +// Test 5: Validate fixtures are in sync with source +console.log('\n✓ Test 5: Fixtures Validation'); +try { + const fixturesPath = path.join(__dirname, 'fixtures', 'package-managers.json'); + const fixturesData = JSON.parse(fs.readFileSync(fixturesPath, 'utf-8')); + + const pmPath = path.join(__dirname, '..', 'src', 'lib', 'pm.ts'); + const pmContent = fs.readFileSync(pmPath, 'utf-8'); + + // Extract PACKAGE_MANAGERS values from source for comparison + const match = pmContent.match(/export const PACKAGE_MANAGERS[^=]*=\s*\[(.*?)\]/s); + if (!match) { + console.error(' ✗ Could not parse PACKAGE_MANAGERS from source'); + process.exit(1); + } + + const sourceValues = match[1] + .split(',') + .map(v => v.trim()) + .filter(v => v) + .map(v => v.replace(/["'`]/g, '')); + + const fixturesMatch = JSON.stringify(fixturesData.sort()) === JSON.stringify(sourceValues.sort()); + if (fixturesMatch) { + console.log(' ✓ Fixtures file is in sync with source'); + } else { + console.error(' ✗ Fixtures file is out of sync with source'); + console.error(` Source: [${sourceValues.join(', ')}]`); + console.error(` Fixtures: [${fixturesData.join(', ')}]`); + process.exit(1); + } +} catch (error) { + console.error(' ✗ Failed to validate fixtures'); + console.error(` Error: ${error.message}`); + process.exit(1); +} + console.log('\n' + '='.repeat(60)); console.log('✓ All package manager tests passed!'); console.log('='.repeat(60)); From b73557ea218da63816b5acb3592cd1830f25f791 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 20 Jan 2026 08:07:51 +0000 Subject: [PATCH 6/7] Improve validation robustness and add clarifying comments Co-authored-by: PrabothCharith <91902549+PrabothCharith@users.noreply.github.com> --- test/pm-test.mjs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/test/pm-test.mjs b/test/pm-test.mjs index 0e423b1..f528abe 100755 --- a/test/pm-test.mjs +++ b/test/pm-test.mjs @@ -103,17 +103,27 @@ try { const pmContent = fs.readFileSync(pmPath, 'utf-8'); // Extract PACKAGE_MANAGERS values from source for comparison - const match = pmContent.match(/export const PACKAGE_MANAGERS[^=]*=\s*\[(.*?)\]/s); + // Note: This is a simple regex-based check for a constant array of string literals. + // It's sufficient for validating sync but not a full TypeScript parser. + const match = pmContent.match(/export const PACKAGE_MANAGERS[^=]*=\s*\[(.*?)\]\s*[;,]?/s); if (!match) { console.error(' ✗ Could not parse PACKAGE_MANAGERS from source'); process.exit(1); } + // Parse array values, handling both single and double quotes const sourceValues = match[1] .split(',') .map(v => v.trim()) .filter(v => v) - .map(v => v.replace(/["'`]/g, '')); + .map(v => v.replace(/^["']|["']$/g, '')) + .filter(v => v); // Remove any empty strings + + // Ensure both are arrays of strings before comparing + if (!Array.isArray(fixturesData) || !fixturesData.every(v => typeof v === 'string')) { + console.error(' ✗ Fixtures must be an array of strings'); + process.exit(1); + } const fixturesMatch = JSON.stringify(fixturesData.sort()) === JSON.stringify(sourceValues.sort()); if (fixturesMatch) { From aa16b11a75d81da47724854d7f9f8f044b7f280d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 20 Jan 2026 08:09:13 +0000 Subject: [PATCH 7/7] Simplify regex and remove redundant filtering Co-authored-by: PrabothCharith <91902549+PrabothCharith@users.noreply.github.com> --- test/pm-test.mjs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/pm-test.mjs b/test/pm-test.mjs index f528abe..2b2f319 100755 --- a/test/pm-test.mjs +++ b/test/pm-test.mjs @@ -105,7 +105,7 @@ try { // Extract PACKAGE_MANAGERS values from source for comparison // Note: This is a simple regex-based check for a constant array of string literals. // It's sufficient for validating sync but not a full TypeScript parser. - const match = pmContent.match(/export const PACKAGE_MANAGERS[^=]*=\s*\[(.*?)\]\s*[;,]?/s); + const match = pmContent.match(/export const PACKAGE_MANAGERS[^=]*=\s*\[(.*?)\]/s); if (!match) { console.error(' ✗ Could not parse PACKAGE_MANAGERS from source'); process.exit(1); @@ -116,8 +116,7 @@ try { .split(',') .map(v => v.trim()) .filter(v => v) - .map(v => v.replace(/^["']|["']$/g, '')) - .filter(v => v); // Remove any empty strings + .map(v => v.replace(/^['"]|['"]$/g, '')); // Ensure both are arrays of strings before comparing if (!Array.isArray(fixturesData) || !fixturesData.every(v => typeof v === 'string')) {