Open History to see the last commit
1import { describe, expect, it } from 'vitest'
2import {
3 HARNESSES,
4 PROVIDERS,
5 buildTriagePrompt,
6 isHarness,
7 isProvider,
8 missingEnv,
9 parseIssueUrl,
10 parseVerdict,
11} from './sandbox-triage'
12
13describe('parseIssueUrl', () => {
14 it('extracts repo + issue number', () => {
15 expect(parseIssueUrl('https://github.com/TanStack/ai/issues/123')).toEqual({
16 repo: 'TanStack/ai',
17 issueNumber: 123,
18 })
19 })
20
21 it('tolerates a trailing slash, query, and hash', () => {
22 expect(parseIssueUrl('https://github.com/a/b/issues/7/?x=1#note')).toEqual({
23 repo: 'a/b',
24 issueNumber: 7,
25 })
26 })
27
28 it('throws on a pull-request URL', () => {
29 expect(() => parseIssueUrl('https://github.com/a/b/pull/7')).toThrow(
30 /issue url/i,
31 )
32 })
33
34 it('throws on a non-github / malformed URL', () => {
35 expect(() => parseIssueUrl('not a url')).toThrow(/issue url/i)
36 })
37})
38
39describe('parseVerdict', () => {
40 it('reads the first VERDICT line, case-insensitive', () => {
41 expect(parseVerdict('VERDICT: relevant\n\n## Summary')).toBe('relevant')
42 expect(parseVerdict('verdict: Not-Relevant ')).toBe('not-relevant')
43 expect(parseVerdict('Verdict: UNCERTAIN')).toBe('uncertain')
44 })
45
46 it('returns null when absent or unrecognized', () => {
47 expect(parseVerdict('## Summary\nno verdict here')).toBeNull()
48 expect(parseVerdict('VERDICT: maybe')).toBeNull()
49 })
50})
51
52describe('registries', () => {
53 it('has 5 harnesses and 4 providers with labels + required env arrays', () => {
54 expect(Object.keys(HARNESSES).sort()).toEqual([
55 'acp',
56 'claude-code',
57 'codex',
58 'grok',
59 'opencode',
60 ])
61 expect(Object.keys(PROVIDERS).sort()).toEqual([
62 'daytona',
63 'docker',
64 'local',
65 'vercel',
66 ])
67 for (const spec of Object.values(HARNESSES)) {
68 expect(typeof spec.label).toBe('string')
69 expect(Array.isArray(spec.requiredEnv)).toBe(true)
70 }
71 })
72
73 it('guards narrow unknown picker values', () => {
74 expect(isHarness('codex')).toBe(true)
75 expect(isHarness('nope')).toBe(false)
76 expect(isProvider('docker')).toBe(true)
77 expect(isProvider(42)).toBe(false)
78 })
79
80 it('missingEnv skips harness keys when authMode is host', () => {
81 delete process.env.XAI_API_KEY
82 delete process.env.GROK_API_KEY
83 expect(missingEnv('grok', 'docker', 'host')).not.toContain('XAI_API_KEY')
84 expect(missingEnv('grok', 'local', 'api-key')).toContain(
85 'XAI_API_KEY (or GROK_API_KEY)',
86 )
87 })
88
89 it('missingEnv requires harness keys when authMode is omitted', () => {
90 delete process.env.XAI_API_KEY
91 delete process.env.GROK_API_KEY
92 expect(missingEnv('grok', 'local')).toContain(
93 'XAI_API_KEY (or GROK_API_KEY)',
94 )
95 })
96
97 it('missingEnv reports unset required vars', () => {
98 delete process.env.ANTHROPIC_API_KEY
99 delete process.env.DAYTONA_API_KEY
100 expect(missingEnv('claude-code', 'docker')).toContain('ANTHROPIC_API_KEY')
101 expect(missingEnv('claude-code', 'daytona')).toEqual(
102 expect.arrayContaining(['ANTHROPIC_API_KEY', 'DAYTONA_API_KEY']),
103 )
104 process.env.ANTHROPIC_API_KEY = 'x'
105 expect(missingEnv('claude-code', 'docker')).toEqual([])
106 })
107})
108
109describe('buildTriagePrompt', () => {
110 it('includes the issue + the required VERDICT-line instruction', () => {
111 const prompt = buildTriagePrompt(
112 { number: 9, title: 'Boom', body: 'crashes on save', url: 'u' },
113 'a/b',
114 )
115 expect(prompt).toContain('#9')
116 expect(prompt).toContain('crashes on save')
117 expect(prompt).toMatch(/VERDICT:/)
118 expect(prompt).toMatch(/relevant \| not-relevant \| uncertain/)
119 })
120})