Open History to see the last commit
1/**
2 * Test definitions for multi-adapter testing
3 *
4 * Follows the pattern from smoke-tests/adapters
5 */
6
7import type { AnyTextAdapter } from '@tanstack/ai'
8
9/**
10 * Result of a test run
11 */
12export interface TestOutcome {
13 passed: boolean
14 error?: string
15 ignored?: boolean
16}
17
18/**
19 * Definition for a test
20 */
21export interface TestDefinition {
22 /** 3-letter acronym identifier (uppercase) */
23 id: string
24 /** Human-readable name */
25 name: string
26 /** Brief description of what the test does */
27 description: string
28 /** Whether this test requires a real LLM adapter */
29 requiresAdapter: boolean
30 /** Function to run the test */
31 run: (
32 adapter: AnyTextAdapter | null,
33 verbose: boolean,
34 ) => Promise<TestOutcome>
35}
36
37/**
38 * Wrapper for the simulated test
39 */
40async function runSimulatedWrapper(
41 _adapter: AnyTextAdapter | null,
42 _verbose: boolean,
43): Promise<TestOutcome> {
44 const { runSimulatedTest } = await import('./simulated-test')
45 const result = await runSimulatedTest()
46 return {
47 passed: result.passed,
48 error: result.passed ? undefined : 'Simulated test failed',
49 }
50}
51
52/**
53 * Wrapper for the snippets live test
54 */
55async function runSnippetsLiveWrapper(
56 adapter: AnyTextAdapter | null,
57 verbose: boolean,
58): Promise<TestOutcome> {
59 if (!adapter) {
60 return { passed: false, error: 'No adapter provided' }
61 }
62
63 const { runLiveTest } = await import('./live-test')
64 const result = await runLiveTest({ adapter, verbose })
65 return {
66 passed: result.passed,
67 error: result.passed ? undefined : 'Snippets live test failed',
68 }
69}
70
71/**
72 * Wrapper for the structured output test
73 */
74async function runStructuredWrapper(
75 adapter: AnyTextAdapter | null,
76 verbose: boolean,
77): Promise<TestOutcome> {
78 if (!adapter) {
79 return { passed: false, error: 'No adapter provided' }
80 }
81
82 const { runStructuredOutputTest } = await import('./structured-output-test')
83 const result = await runStructuredOutputTest({ adapter, verbose })
84 return {
85 passed: result.passed,
86 error: result.passed ? undefined : 'Structured output test failed',
87 }
88}
89
90/**
91 * Wrapper for the ToolRegistry test
92 */
93async function runRegistryWrapper(
94 _adapter: AnyTextAdapter | null,
95 _verbose: boolean,
96): Promise<TestOutcome> {
97 const { runRegistryTest } = await import('./registry-test')
98 const result = await runRegistryTest()
99 return {
100 passed: result.passed,
101 error: result.passed ? undefined : 'ToolRegistry test failed',
102 }
103}
104
105/**
106 * Registry of all available tests
107 */
108export const TESTS: Array<TestDefinition> = [
109 {
110 id: 'SIM',
111 name: 'Simulated',
112 description:
113 'Deterministic test with mock adapter (snippet creation + reuse)',
114 requiresAdapter: false,
115 run: runSimulatedWrapper,
116 },
117 {
118 id: 'REG',
119 name: 'Registry',
120 description: 'Test ToolRegistry dynamic snippet registration mid-stream',
121 requiresAdapter: false,
122 run: runRegistryWrapper,
123 },
124 {
125 id: 'SNP',
126 name: 'Snippets Live',
127 description: 'Live test of snippet creation and direct snippet tool call',
128 requiresAdapter: true,
129 run: runSnippetsLiveWrapper,
130 },
131 {
132 id: 'STR',
133 name: 'Structured Output',
134 description: 'Test structured output with code mode',
135 requiresAdapter: true,
136 run: runStructuredWrapper,
137 },
138]
139
140/**
141 * Get test definition by ID (case-insensitive)
142 */
143export function getTest(id: string): TestDefinition | undefined {
144 return TESTS.find((t) => t.id.toLowerCase() === id.toLowerCase())
145}
146
147/**
148 * Get all test IDs
149 */
150export function getTestIds(): Array<string> {
151 return TESTS.map((t) => t.id)
152}
153
154/**
155 * Get all tests (no skip-by-default logic for snippets tests)
156 */
157export function getDefaultTests(): Array<TestDefinition> {
158 return TESTS
159}