|
| 1 | +import assert from 'node:assert/strict'; |
| 2 | +import test from 'node:test'; |
| 3 | + |
| 4 | +import spawn from 'cross-spawn'; |
| 5 | + |
| 6 | +import { |
| 7 | + CursorProviderAuth, |
| 8 | + isCursorAgentInstalled, |
| 9 | +} from '@/modules/providers/list/cursor/cursor-auth.provider.js'; |
| 10 | + |
| 11 | +const probeResult = ( |
| 12 | + overrides: Record<string, unknown>, |
| 13 | +): ReturnType<typeof spawn.sync> => ({ |
| 14 | + pid: 123, |
| 15 | + output: [null, null, null], |
| 16 | + stdout: null, |
| 17 | + stderr: null, |
| 18 | + status: 0, |
| 19 | + signal: null, |
| 20 | + ...overrides, |
| 21 | +} as unknown as ReturnType<typeof spawn.sync>); |
| 22 | + |
| 23 | +const probe = (result: ReturnType<typeof spawn.sync>) => ( |
| 24 | + (() => result) as typeof spawn.sync |
| 25 | +); |
| 26 | + |
| 27 | +test('cursor installation probe accepts a successful version command', () => { |
| 28 | + assert.equal(isCursorAgentInstalled(probe(probeResult({ status: 0 }))), true); |
| 29 | +}); |
| 30 | + |
| 31 | +test('cursor installation probe rejects a non-zero version command', () => { |
| 32 | + assert.equal(isCursorAgentInstalled(probe(probeResult({ status: 1 }))), false); |
| 33 | +}); |
| 34 | + |
| 35 | +test('cursor installation probe rejects ENOENT and reports the provider as missing', async () => { |
| 36 | + const missing = Object.assign(new Error('spawnSync cursor-agent ENOENT'), { code: 'ENOENT' }); |
| 37 | + const runVersionProbe = probe(probeResult({ error: missing, status: null })); |
| 38 | + |
| 39 | + assert.equal(isCursorAgentInstalled(runVersionProbe), false); |
| 40 | + assert.deepEqual(await new CursorProviderAuth(runVersionProbe).getStatus(), { |
| 41 | + installed: false, |
| 42 | + provider: 'cursor', |
| 43 | + authenticated: false, |
| 44 | + email: null, |
| 45 | + method: null, |
| 46 | + error: 'Cursor CLI is not installed', |
| 47 | + }); |
| 48 | +}); |
0 commit comments