diff --git a/scripts/validate-changelog-frontmatter.mjs b/scripts/validate-changelog-frontmatter.mjs index 5f2ebac8..fcaa1214 100644 --- a/scripts/validate-changelog-frontmatter.mjs +++ b/scripts/validate-changelog-frontmatter.mjs @@ -110,6 +110,15 @@ function sectionByPrefix(body, prefix, level = 2) { return lines.slice(start + 1, end).join('\n'); } +// --verbose 时把逐端点命中行打到 stdout。默认 false ⇒ 输出与加它之前逐字节相同。 +// 为什么需要它:本校验器的端点解析结果原本只在「清单与详情对不上」时才进 errors, +// 成功路径零输出,于是「每个端点都被校验过」这件事无法取证(#7439 AC-19)。 +let VERBOSE_ENDPOINTS = false; + +export function setVerboseEndpoints(on) { + VERBOSE_ENDPOINTS = Boolean(on); +} + function apiEndpointKey(method, endpointPath) { return `${method.trim().toUpperCase()} ${endpointPath.trim()}`; } @@ -166,6 +175,12 @@ function validateApiTemplate(file, metadata, body) { ); const detailMatches = [...detailSection.matchAll(detailPattern)]; const detailed = detailMatches.map((match) => apiEndpointKey(match[1], match[2])); + if (VERBOSE_ENDPOINTS) { + detailMatches.forEach((match, index) => { + console.log(`[endpoint] ${file} #${index + 1} ${match[1]} ${match[2].trim()}`); + }); + console.log(`[endpoint-count] ${file} ${detailMatches.length}`); + } if (detailMatches.length === 0) { errors.push(ruleError( 'E_API_TEMPLATE', @@ -477,6 +492,11 @@ export function runFilesValidation(files, root = process.cwd()) { } export function main(argv = process.argv.slice(2)) { + // --verbose 可出现在任意位置;剔除后再走原有解析,避免打乱 argv[0] === '--files' 的判断。 + if (argv.includes('--verbose')) { + setVerboseEndpoints(true); + argv = argv.filter((item) => item !== '--verbose'); + } try { if (argv[0] === '--files') { const files = argv.slice(1).flatMap((item) => item.split(',')).filter(Boolean);