( result: string, expectedContent: string | (string | RegExp)[] | null = null, testName = '', )
| 69 | |
| 70 | // Helper to validate model output and warn about unexpected content |
| 71 | export function validateModelOutput( |
| 72 | result: string, |
| 73 | expectedContent: string | (string | RegExp)[] | null = null, |
| 74 | testName = '', |
| 75 | ) { |
| 76 | // First, check if there's any output at all (this should fail the test if missing) |
| 77 | if (!result || result.trim().length === 0) { |
| 78 | throw new Error('Expected LLM to return some output'); |
| 79 | } |
| 80 | |
| 81 | // If expectedContent is provided, check for it and warn if missing |
| 82 | if (expectedContent) { |
| 83 | const contents = Array.isArray(expectedContent) |
| 84 | ? expectedContent |
| 85 | : [expectedContent]; |
| 86 | const missingContent = contents.filter((content) => { |
| 87 | if (typeof content === 'string') { |
| 88 | return !result.toLowerCase().includes(content.toLowerCase()); |
| 89 | } else if (content instanceof RegExp) { |
| 90 | return !content.test(result); |
| 91 | } |
| 92 | return false; |
| 93 | }); |
| 94 | |
| 95 | if (missingContent.length > 0) { |
| 96 | console.warn( |
| 97 | `Warning: LLM did not include expected content in response: ${missingContent.join(', ')}.`, |
| 98 | 'This is not ideal but not a test failure.', |
| 99 | ); |
| 100 | console.warn( |
| 101 | 'The tool was called successfully, which is the main requirement.', |
| 102 | ); |
| 103 | return false; |
| 104 | } else if (process.env.VERBOSE === 'true') { |
| 105 | console.log(`${testName}: Model output validated successfully.`); |
| 106 | } |
| 107 | return true; |
| 108 | } |
| 109 | |
| 110 | return true; |
| 111 | } |
| 112 | |
| 113 | export class TestRig { |
| 114 | bundlePath: string; |
no outgoing calls
no test coverage detected