Skip to content

Commit 2a1a90a

Browse files
fix(tests): fix CLI path resolution for integration tests
- Update test files to use correct dist/src/cli path - Fix package.json path resolution to work from both src and dist - Use localRequire/currentDirPath to avoid esbuild naming conflicts Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 47a0cc5 commit 2a1a90a

4 files changed

Lines changed: 24 additions & 7 deletions

File tree

src/__tests__/integration/cli-integration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import * as os from 'os';
1111

1212
// Use the built CLI
1313
const projectRoot = path.join(__dirname, '..', '..', '..');
14-
const cliPath = path.join(projectRoot, 'dist', 'cli', 'index.js');
14+
const cliPath = path.join(projectRoot, 'dist', 'src', 'cli', 'index.js');
1515

1616
describe('CLI Integration', () => {
1717
let testDir: string;

src/__tests__/integration/helpers/test-environment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class TestEnvironment {
6565
'db',
6666
'stackmemory.db'
6767
);
68-
this.cliPath = path.join(process.cwd(), 'dist', 'cli', 'index.js');
68+
this.cliPath = path.join(process.cwd(), 'dist', 'src', 'cli', 'index.js');
6969

7070
// Adapter will be created after directories are set up
7171
this.adapter = null as any; // Will be initialized in setup()

src/cli/commands/__tests__/integration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import * as os from 'os';
1010

1111
// Use the development CLI (built version)
1212
const projectRoot = path.join(__dirname, '..', '..', '..', '..');
13-
const cliPath = path.join(projectRoot, 'dist', 'cli', 'index.js');
13+
const cliPath = path.join(projectRoot, 'dist', 'src', 'cli', 'index.js');
1414
const cli = (cmd: string) => `node ${cliPath} ${cmd}`;
1515

1616
// NOTE: These tests have implementation dependencies

src/cli/index.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,28 @@ import { enableChromaDB } from '../core/config/storage-config.js';
6868
import { spawn } from 'child_process';
6969
import { homedir } from 'os';
7070

71-
// Read version from package.json
71+
// Read version from package.json - works from both src/ and dist/src/
7272
import { createRequire } from 'module';
73-
const require = createRequire(import.meta.url);
74-
const pkg = require('../../package.json');
75-
const VERSION = pkg.version;
73+
import { fileURLToPath } from 'url';
74+
import * as pathModule from 'path';
75+
const localRequire = createRequire(import.meta.url);
76+
const currentFilePath = fileURLToPath(import.meta.url);
77+
const currentDirPath = pathModule.dirname(currentFilePath);
78+
79+
// Find package.json by walking up directories
80+
function findPackageJson(): { version: string } {
81+
let dir = currentDirPath;
82+
for (let i = 0; i < 5; i++) {
83+
const pkgPath = pathModule.join(dir, 'package.json');
84+
try {
85+
return localRequire(pkgPath);
86+
} catch {
87+
dir = pathModule.dirname(dir);
88+
}
89+
}
90+
return { version: '0.0.0' };
91+
}
92+
const VERSION = findPackageJson().version;
7693

7794
// Check for updates on CLI startup
7895
UpdateChecker.checkForUpdates(VERSION, true).catch(() => {

0 commit comments

Comments
 (0)