-
-
Notifications
You must be signed in to change notification settings - Fork 10k
Expand file tree
/
Copy pathdetect-agent.test.ts
More file actions
65 lines (52 loc) · 1.83 KB
/
detect-agent.test.ts
File metadata and controls
65 lines (52 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { afterEach, describe, expect, it, vi } from 'vitest';
import { detectAgent } from './detect-agent';
describe('detectAgent', () => {
afterEach(() => {
vi.unstubAllEnvs();
});
it('detects claude via CLAUDECODE', () => {
vi.stubEnv('CLAUDECODE', '1');
expect(detectAgent()).toEqual({ name: 'claude' });
});
it('detects claude via CLAUDE_CODE', () => {
vi.stubEnv('CLAUDE_CODE', '1');
expect(detectAgent()).toEqual({ name: 'claude' });
});
it('detects gemini via GEMINI_CLI', () => {
vi.stubEnv('GEMINI_CLI', '1');
expect(detectAgent()).toEqual({ name: 'gemini' });
});
it('detects codex via CODEX_SANDBOX', () => {
vi.stubEnv('CODEX_SANDBOX', '1');
expect(detectAgent()).toEqual({ name: 'codex' });
});
it('detects codex via CODEX_THREAD_ID', () => {
vi.stubEnv('CODEX_THREAD_ID', '1');
expect(detectAgent()).toEqual({ name: 'codex' });
});
it('detects cursor via CURSOR_AGENT', () => {
vi.stubEnv('CURSOR_AGENT', '1');
expect(detectAgent()).toEqual({ name: 'cursor' });
});
it('detects opencode via OPENCODE', () => {
vi.stubEnv('OPENCODE', '1');
expect(detectAgent()).toEqual({ name: 'opencode' });
});
it('detects explicit agent via AI_AGENT env var', () => {
vi.stubEnv('AI_AGENT', 'copilot');
expect(detectAgent()).toEqual({ name: 'copilot' });
});
it('normalizes AI_AGENT to lowercase', () => {
vi.stubEnv('AI_AGENT', 'Copilot');
expect(detectAgent()).toEqual({ name: 'copilot' });
});
it('AI_AGENT takes precedence over other env vars', () => {
vi.stubEnv('AI_AGENT', 'copilot');
vi.stubEnv('CLAUDECODE', '1');
vi.stubEnv('GEMINI_CLI', '1');
expect(detectAgent()).toEqual({ name: 'copilot' });
});
it('returns undefined when there are no signals', () => {
expect(detectAgent()).toEqual(undefined);
});
});