Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions domains/integrations/openspec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ function isCommandAvailable(command: string): boolean {
}

async function ensureOpenSpecCli(
scope: InstallScope,
projectPath: string,
shouldInstall = true,
): Promise<'ready' | 'missing' | 'failed'> {
Expand All @@ -168,10 +167,9 @@ async function ensureOpenSpecCli(
const label = alreadyInstalled ? 'Upgrading' : 'Installing';
console.warn(` ${label} OpenSpec CLI...`);
try {
const npmArgs =
scope === 'global'
? ['install', '-g', '@fission-ai/openspec@latest']
: ['install', '@fission-ai/openspec@latest'];
// OpenSpec is invoked as a PATH command below; keep the CLI install global
// regardless of Comet's project/global skill installation scope.
const npmArgs = ['install', '-g', '@fission-ai/openspec@latest'];
execFileSync(getNpmExecutable(), npmArgs, {
cwd: projectPath,
stdio: 'inherit',
Expand Down Expand Up @@ -315,7 +313,7 @@ async function installOpenSpec(
shouldInstallCli = true,
mirrorOpenCodePlatformIds: string[] = [],
): Promise<'installed' | 'failed' | 'skipped'> {
const cliStatus = await ensureOpenSpecCli(scope, projectPath, shouldInstallCli);
const cliStatus = await ensureOpenSpecCli(projectPath, shouldInstallCli);
if (cliStatus === 'failed') {
console.error(
` OpenSpec CLI not available. Install manually: npm install -g @fission-ai/openspec@latest`,
Expand Down
20 changes: 20 additions & 0 deletions test/domains/integrations/openspec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,26 @@ describe('openspec', () => {
expect(mockedExecFileSync).toHaveBeenCalledTimes(4);
});

it('installs the OpenSpec CLI globally for project scope to avoid project node_modules', async () => {
mockedExecFileSync.mockReturnValueOnce(Buffer.from('/usr/bin/openspec'));
mockedExecFileSync.mockReturnValueOnce(Buffer.from('upgraded'));
mockedExecFileSync.mockReturnValueOnce(Buffer.from('/usr/bin/openspec'));
mockedExecFileSync.mockReturnValueOnce(Buffer.from('ok'));

const { getNpmExecutable, installOpenSpec } =
await import('../../../domains/integrations/openspec.js');
const result = await installOpenSpec('/tmp/test', ['claude'], 'project');

expect(result).toBe('installed');
const npmCall = mockedExecFileSync.mock.calls.find(
([command, args]) =>
command === getNpmExecutable() &&
Array.isArray(args) &&
args.includes('@fission-ai/openspec@latest'),
);
expect(npmCall?.[1]).toEqual(['install', '-g', '@fission-ai/openspec@latest']);
});

it('returns failed when openspec CLI is not available', async () => {
mockedExecFileSync.mockImplementationOnce(() => {
throw new Error('not found');
Expand Down
Loading