|
| 1 | +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' |
| 2 | +import { autoResolveAgent } from '../../src/cli/agent-prompt.ts' |
| 3 | + |
| 4 | +const detection = vi.hoisted(() => ({ |
| 5 | + configAgent: undefined as string | undefined, |
| 6 | + envAgent: null as string | null, |
| 7 | + installedAgents: [] as string[], |
| 8 | + projectAgents: [] as string[], |
| 9 | +})) |
| 10 | + |
| 11 | +vi.mock('../../src/agent/index.ts', () => ({ |
| 12 | + agents: {}, |
| 13 | + detectEnvAgent: () => detection.envAgent, |
| 14 | + detectInstalledAgents: () => detection.installedAgents, |
| 15 | + detectProjectAgents: () => detection.projectAgents, |
| 16 | + detectTargetAgent: () => detection.envAgent |
| 17 | + ?? (detection.projectAgents.length === 1 ? detection.projectAgents[0] : null), |
| 18 | +})) |
| 19 | + |
| 20 | +vi.mock('../../src/core/config.ts', () => ({ |
| 21 | + readConfig: () => ({ agent: detection.configAgent }), |
| 22 | + updateConfig: vi.fn(), |
| 23 | +})) |
| 24 | + |
| 25 | +describe('autoResolveAgent', () => { |
| 26 | + const originalNoAgent = process.env.SKILLD_NO_AGENT |
| 27 | + |
| 28 | + beforeEach(() => { |
| 29 | + detection.configAgent = undefined |
| 30 | + detection.envAgent = null |
| 31 | + detection.installedAgents = [] |
| 32 | + detection.projectAgents = [] |
| 33 | + delete process.env.SKILLD_NO_AGENT |
| 34 | + }) |
| 35 | + |
| 36 | + afterEach(() => { |
| 37 | + if (originalNoAgent === undefined) |
| 38 | + delete process.env.SKILLD_NO_AGENT |
| 39 | + else |
| 40 | + process.env.SKILLD_NO_AGENT = originalNoAgent |
| 41 | + }) |
| 42 | + |
| 43 | + it('prefers the saved config over a single project marker', () => { |
| 44 | + detection.configAgent = 'claude-code' |
| 45 | + detection.projectAgents = ['cursor'] |
| 46 | + |
| 47 | + expect(autoResolveAgent()).toBe('claude-code') |
| 48 | + }) |
| 49 | +}) |
0 commit comments