test(aihr): tighten demo question verification

This commit is contained in:
2026-07-10 00:19:48 +08:00
parent baf27a5de9
commit b26c2258cf
2 changed files with 17 additions and 1 deletions
+16
View File
@@ -11,6 +11,7 @@ const args = new Map(process.argv.slice(2).map((arg) => {
}));
const baseUrl = args.get('base-url') || process.env.AIHR_BASE_URL || 'https://wygj-api.localhost';
const verbose = args.has('verbose');
const parsedBaseUrl = new URL(baseUrl);
if (parsedBaseUrl.protocol === 'https:' && parsedBaseUrl.hostname.endsWith('.localhost') && !process.env.NODE_EXTRA_CA_CERTS) {
// ponytail: local portless CA is not visible to Node fetch; only relax TLS for .localhost dev verification.
@@ -18,6 +19,7 @@ if (parsedBaseUrl.protocol === 'https:' && parsedBaseUrl.hostname.endsWith('.loc
}
const file = path.resolve(root, args.get('file') || 'docs/20260708/发布会演示候选题单.md');
const prefixes = (args.get('prefix') || 'Q').split(',').map((item) => item.trim()).filter(Boolean);
const ids = new Set((args.get('ids') || '').split(',').map((item) => item.trim()).filter(Boolean));
const limit = Number(args.get('limit') || 0);
function readEnv(filePath) {
@@ -130,6 +132,7 @@ function parseQuestions(markdown) {
if (!line.startsWith('|')) continue;
const cells = line.split('|').slice(1, -1).map((cell) => cell.trim());
if (cells.length < 5 || !/^[A-Z]\d+$/u.test(cells[0])) continue;
if (ids.size && !ids.has(cells[0])) continue;
if (!prefixes.some((prefix) => cells[0].startsWith(prefix))) continue;
rows.push({
id: cells[0],
@@ -150,6 +153,13 @@ function hasExpectedSource(result, expectedSources) {
return expectedSources.some((source) => haystack.includes(source.replace(/\s+/g, ' ').trim()));
}
function evidenceTitles(result) {
return [
...(result.docs || []).map((item) => item.title || item.docName || item.name || ''),
...(result.snippets || []).map((item) => item.title || item.docName || item.name || '')
].filter(Boolean);
}
const questions = parseQuestions(fs.readFileSync(file, 'utf8'));
if (!questions.length) {
console.error(`FAIL: no questions found in ${file} for prefix ${prefixes.join(',')}`);
@@ -187,8 +197,14 @@ for (const item of questions) {
if (!sourceOk) {
warned += 1;
console.log(`WARN ${item.id} ${item.scene}: answered, but top evidence missed listed source`);
if (verbose) {
console.log(` evidence: ${evidenceTitles(data).join(' | ') || '-'}`);
}
} else {
console.log(`OK ${item.id} ${item.scene}`);
if (verbose) {
console.log(` evidence: ${evidenceTitles(data).join(' | ') || '-'}`);
}
}
}