文件内容
resources/run_tests.js
#!/usr/bin/env node
'use strict';
const fs = require('fs');
const path = require('path');
const { handlePrompt } = require('./index');
async function main() {
const filePath = path.join(__dirname, 'test_prompts.json');
const tests = JSON.parse(fs.readFileSync(filePath, 'utf8'));
let failed = 0;
for (const test of tests) {
const result = await handlePrompt(test.prompt, { noCall: true });
const errors = [];
if (result.status !== test.expectedStatus) {
errors.push(`status expected ${test.expectedStatus}, got ${result.status}`);
}
if (test.expectedVoiceType && result.voiceType !== test.expectedVoiceType) {
errors.push(`voiceType expected ${test.expectedVoiceType}, got ${result.voiceType}`);
}
if (test.workflowIncludes && result.agentProfile) {
for (const fragment of test.workflowIncludes) {
if (!result.agentProfile.workflow.includes(fragment)) {
errors.push(`workflow missing ${fragment}`);
}
}
}
if (errors.length) {
failed += 1;
console.error(`FAIL ${test.name}: ${errors.join('; ')}`);
console.error(result.message);
} else {
console.log(`PASS ${test.name}`);
}
}
if (failed) process.exit(1);
}
main().catch((error) => {
console.error(error.stack || error.message);
process.exit(1);
});