Template
feat(tools): 站外官方依据登记表 external-sources.json 与校验
This commit is contained in:
@@ -14,6 +14,8 @@
|
||||
* 8. **依据真实性**:`依据` 中的 documentId 必须已登记于 tools/doc-ids.json 且 verified=true
|
||||
* 9. **依据引文**:被本次改动触及的规则条目,其 `依据` 必须附原文引文且**引文能在该文档中命中**
|
||||
* —— 把"依据是否支持结论"从不可验证的判断降级为字符串命中
|
||||
* 10. **站外官方依据**:`- **官方变更公告(站外)**` 类条目里的 URL 必须登记于 tools/external-sources.json
|
||||
* (未登记 = 报错;核实日期超 365 天 = 提示;登记后无规则引用 = 提示)
|
||||
*
|
||||
* 用法:
|
||||
* node tools/check-rules-index.mjs # 结构校验(快,供日常/门禁)
|
||||
@@ -173,6 +175,9 @@ for (const name of files) {
|
||||
}
|
||||
|
||||
/* ---------- 第二遍:引用解析 / URL / 退役编号 ---------- */
|
||||
/** 站外官方依据的合法落点:`- **官方变更公告(站外)**:… <URL>`(USE-007 允许的例外)。 */
|
||||
const EXTERNAL_LABEL_RE = /^\s*-\s*\*\*[^*]{0,24}(变更公告|发布说明|站外|外部公告)/;
|
||||
const externalCitations = []; // { loc, url }
|
||||
for (const [rel, text] of rawText) {
|
||||
let inFence = false;
|
||||
text.split(/\r?\n/).forEach((line, idx) => {
|
||||
@@ -181,7 +186,10 @@ for (const [rel, text] of rawText) {
|
||||
// 代码块内的 URL 属示例数据(如 'https://example.com'),不按引用判定
|
||||
if (/https?:\/\//.test(line) && !inFence) {
|
||||
if (/依据/.test(line)) errors.push(`[web URL] ${loc} 依据行含 web URL(USE-007 禁止)`);
|
||||
else warnings.push(`[示例 URL] ${loc} 非依据行出现 URL(请确认非引用)`);
|
||||
else if (EXTERNAL_LABEL_RE.test(line)) {
|
||||
const u = line.match(/https?:\/\/[^\s<>"'))】]+/);
|
||||
externalCitations.push({ loc, url: u ? u[0] : '' });
|
||||
} else warnings.push(`[示例 URL] ${loc} 非依据行出现 URL(请确认非引用)`);
|
||||
}
|
||||
if (/^\s*retired\s*:/.test(line)) return; // frontmatter 的退役声明本身不是引用
|
||||
for (const m of line.matchAll(/\b([A-Z]{2,6})-(\d{3})\b/g)) {
|
||||
@@ -195,6 +203,53 @@ for (const [rel, text] of rawText) {
|
||||
});
|
||||
}
|
||||
|
||||
/* ---------- 站外官方依据:必须登记于 tools/external-sources.json ---------- */
|
||||
const EXTERNAL_PATH = join(ROOT, 'tools', 'external-sources.json');
|
||||
const EXTERNAL_MAX_AGE_DAYS = 365;
|
||||
let externalRegistry = {};
|
||||
if (existsSync(EXTERNAL_PATH)) {
|
||||
try {
|
||||
const parsed = JSON.parse(readFileSync(EXTERNAL_PATH, 'utf8'));
|
||||
externalRegistry = parsed.sources || {};
|
||||
} catch (e) {
|
||||
errors.push(`[外部来源] tools/external-sources.json 解析失败:${e.message}`);
|
||||
}
|
||||
} else if (externalCitations.length) {
|
||||
errors.push('[外部来源] tools/external-sources.json 不存在——站外官方依据必须登记(title / claims / verifiedAt)');
|
||||
}
|
||||
const citedExternal = new Set();
|
||||
/** 登记键不含 URL 锚点(锚点只用于定位小节,见 external-sources.json 的 _readme)。 */
|
||||
const normalizeExternal = u => u.replace(/[,。;、))】\]/.!?]+$/, '').replace(/#.*$/, '');
|
||||
for (const c of externalCitations) {
|
||||
if (!c.url) {
|
||||
errors.push(`[外部来源] ${c.loc} 官方公告行里没找到 URL`);
|
||||
continue;
|
||||
}
|
||||
const key = normalizeExternal(c.url);
|
||||
citedExternal.add(key);
|
||||
const rec = externalRegistry[key] || externalRegistry[c.url.replace(/[,。;、))】\]/.!?]+$/, '')];
|
||||
if (!rec) {
|
||||
errors.push(`[外部来源] ${c.loc} 站外官方依据未登记:${key}`
|
||||
+ ' → 在 tools/external-sources.json 登记 title / claims / verifiedAt');
|
||||
continue;
|
||||
}
|
||||
if (!rec.title || !Array.isArray(rec.claims) || !rec.claims.length) {
|
||||
errors.push(`[外部来源] ${c.loc} 登记项缺少 title 或 claims:${key}`);
|
||||
}
|
||||
const ts = Date.parse(rec.verifiedAt || '');
|
||||
if (!rec.verifiedAt || Number.isNaN(ts)) {
|
||||
errors.push(`[外部来源] ${c.loc} 登记项缺少合法 verifiedAt(YYYY-MM-DD):${key}`);
|
||||
} else if ((Date.now() - ts) / 86400000 > EXTERNAL_MAX_AGE_DAYS) {
|
||||
warnings.push(`[外部来源] ${c.loc} 核实日期已 ${Math.floor((Date.now() - ts) / 86400000)} 天未更新`
|
||||
+ `(${rec.verifiedAt})→ 核对公告是否仍有效后改 verifiedAt:${key}`);
|
||||
}
|
||||
}
|
||||
for (const url of Object.keys(externalRegistry)) {
|
||||
if (!citedExternal.has(normalizeExternal(url))) {
|
||||
warnings.push(`[外部来源] 已登记但没有任何规则引用,可考虑移除:${url}`);
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------- 依据真实性:documentId 必须在已核验白名单内 ---------- */
|
||||
const DOC_MAP_PATH = join(ROOT, 'tools', 'doc-ids.json');
|
||||
if (!existsSync(DOC_MAP_PATH)) {
|
||||
@@ -505,7 +560,8 @@ if (!existsSync(agentsPath)) {
|
||||
}
|
||||
|
||||
/* ---------- 汇总 ---------- */
|
||||
console.log(`扫描 ${files.length} 份文档,已定义规则 ${defined.size} 条,登记前缀 ${PREFIXES.size} 个。`);
|
||||
console.log(`扫描 ${files.length} 份文档,已定义规则 ${defined.size} 条,登记前缀 ${PREFIXES.size} 个`
|
||||
+ `,站外官方依据 ${externalCitations.length} 处(已登记 ${citedExternal.size} 个来源)。`);
|
||||
if (DIFF_MODE || ALL_MODE) {
|
||||
console.log(`证据校验:引文命中 ${verifiedQuotes} 条、术语对账通过 ${verifiedTerms} 条、术语显式豁免 ${exemptedTerms} 项`
|
||||
+ `${DIFF_MODE ? `;跳过未改动条目 ${legacyNoQuote} 条(存量渐进回填中)` : ''}。`);
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"_readme": [
|
||||
"站外官方依据登记表(本文件受版本控制,与 rules/ 同源)。",
|
||||
"用途:当某条规则的官方出处只存在于站外(变更公告 / release notes / 开发者站点文档页),",
|
||||
"而 devecocli 本地文档库没有对应 documentId 时,不允许把 URL 塞进 `**依据**`(USE-007 禁止),",
|
||||
"改在条目内单独写一行 `- **官方变更公告(站外)**:<标题>… <URL>`,并在此登记该 URL。",
|
||||
"校验:tools/check-rules-index.mjs 会检查(1)规则里出现的站外 URL 必须在此登记(未登记=错误),",
|
||||
"(2)verifiedAt 超过 365 天=提示重新核对,(3)登记了但没有规则引用=提示可移除。",
|
||||
"字段:title 公告/文档标题;claims 该出处支撑的具体结论(供复核);",
|
||||
"verifiedAt 人工核实日期 YYYY-MM-DD;verifiedBy 核实方式(谁/何种证据);note 可选备注。"
|
||||
],
|
||||
"sources": {
|
||||
"https://developer.huawei.com/consumer/cn/doc/doccenter-release-notes/changelogs-for-all-apps-7003": {
|
||||
"title": "针对所有应用的变更——沉浸光感新增生效约束",
|
||||
"claims": [
|
||||
"沉浸光感仅对受支持区域生效(如导航栏、TabBar、Navigation 标题栏等系统装饰区域),内容区使用不会真正生效",
|
||||
"该约束起始 API 26.0.0,且只作用于 target ≥ 26.0.0 的应用",
|
||||
"7.0.0.105 SP6 起 Button 组件不再支持沉浸光感"
|
||||
],
|
||||
"verifiedAt": "2026-10-31",
|
||||
"verifiedBy": "用户提供公告链接(见会话 m01102);仓库内探针记录 Trace/entry/src/main/ets/components/SmartFab.ets 头部注释(五轮探针 + target 版本对照)",
|
||||
"note": "本地 devecocli 文档库不收录 release notes,故无 documentId 可引;锚点 #section126372211 指向具体小节,登记时以去锚点的 URL 为键。"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user