import fs from "node:fs"; import path from "node:path"; export const DOCX_REAL_WORLD_CORPUS = Object.freeze([ { id: "changqing-tender-requirements", label: "长庆油田智能健康技术服务招标技术要求", markdownPath: "tmp/长庆油田智能健康技术服务招标技术要求.md", requiredFeatures: ["inline-code", "table-math-alignment"] }, { id: "health-data-schema", label: "运动健康类和营养饮食数据结构升级", markdownPath: "tmp/运动健康类和营养饮食数据数据结构升级.md", requiredFeatures: ["json-code-indentation"], codeIndentationProbe: { rootLine: "{", nestedLineIncludes: '"heart_rate_daily"', minimumIndentPt: 4 } }, { id: "m4n-table-design", label: "M4N 全量表设计模块化讲解", markdownPath: "tmp/数据中台项目周报_2026_W30_附件_M4N全量表设计模块化讲解.md", requiredFeatures: ["mermaid", "long-document"] } ]); export function resolveDocxRealWorldCorpus(repositoryDirectory) { return DOCX_REAL_WORLD_CORPUS.map((entry) => ({ ...entry, absoluteMarkdownPath: path.resolve( repositoryDirectory, entry.markdownPath ), byteLength: fs.existsSync(path.resolve(repositoryDirectory, entry.markdownPath)) ? fs.statSync(path.resolve(repositoryDirectory, entry.markdownPath)).size : 0 })); } export function sortDocxRealWorldCorpusBySize(repositoryDirectory) { return resolveDocxRealWorldCorpus(repositoryDirectory).sort( (first, second) => first.byteLength - second.byteLength || first.id.localeCompare(second.id, "en") ); } export function validateDocxRealWorldCorpus(repositoryDirectory) { const corpus = sortDocxRealWorldCorpusBySize(repositoryDirectory); const failures = []; for (const entry of corpus) { if (!fs.existsSync(entry.absoluteMarkdownPath)) { failures.push(`${entry.id} 缺少 Markdown:${entry.markdownPath}`); continue; } const source = fs.readFileSync(entry.absoluteMarkdownPath, "utf8"); if (!source.trim()) { failures.push(`${entry.id} Markdown 为空`); } if ( entry.requiredFeatures.includes("json-code-indentation") && !/```json\s*[\s\S]*?\n[\t ]+\S/gu.test(source) ) { failures.push(`${entry.id} 缺少带缩进的 JSON 围栏探针`); } if ( entry.requiredFeatures.includes("inline-code") && !/(^|[^`])`[^`\n]+`([^`]|$)/mu.test(source) ) { failures.push(`${entry.id} 缺少行内代码探针`); } if ( entry.requiredFeatures.includes("table-math-alignment") && !/^\|.*\$[^$]+\$.*\|/mu.test(source) ) { failures.push(`${entry.id} 缺少表格公式对齐探针`); } } return { corpus, failures }; } export function summarizeDocxReleaseGateMatrix({ baselineCaseCount, corpusCaseCounts }) { const corpusCaseCount = Object.values(corpusCaseCounts).reduce( (sum, value) => sum + value, 0 ); return { baselineCaseCount, corpusDocumentCount: Object.keys(corpusCaseCounts).length, corpusCaseCounts, corpusCaseCount, totalCaseCount: baselineCaseCount + corpusCaseCount }; }