fix(notes): narrow complete archive triplets

This commit is contained in:
Tianyi Cui
2026-07-26 23:17:20 +08:00
parent 32ae16fa59
commit f18fb32e2c

View File

@@ -126,27 +126,28 @@ export function validateArchiveArtifacts(artifacts: ReadonlyMap<string, Buffer>)
const sourcePath = `${key}.md` const sourcePath = `${key}.md`
const zhPath = `${key}.zh.md` const zhPath = `${key}.zh.md`
const metaPath = `${key}.i18n.yaml` const metaPath = `${key}.i18n.yaml`
const { source, zh, meta } = triplet
const missing = [ const missing = [
triplet.source === undefined ? sourcePath : undefined, source === undefined ? sourcePath : undefined,
triplet.zh === undefined ? zhPath : undefined, zh === undefined ? zhPath : undefined,
triplet.meta === undefined ? metaPath : undefined, meta === undefined ? metaPath : undefined,
].filter((path): path is string => path !== undefined) ].filter((path): path is string => path !== undefined)
if (missing.length > 0) { if (source === undefined || zh === undefined || meta === undefined) {
errors.push(`${key}: incomplete archived triplet; missing ${missing.join(', ')}`) errors.push(`${key}: incomplete archived triplet; missing ${missing.join(', ')}`)
continue continue
} }
const sourceBase = basename(key) const sourceBase = basename(key)
errors.push(...validateHeader(sourcePath, triplet.source, sourceBase, false)) errors.push(...validateHeader(sourcePath, source, sourceBase, false))
errors.push(...validateHeader(zhPath, triplet.zh, sourceBase, true)) errors.push(...validateHeader(zhPath, zh, sourceBase, true))
const sourceDate = /^Archived: (\d{4}-\d{2}-\d{2})$/m.exec(triplet.source.toString('utf8'))?.[1] const sourceDate = /^Archived: (\d{4}-\d{2}-\d{2})$/m.exec(source.toString('utf8'))?.[1]
const zhDate = /^Archived: (\d{4}-\d{2}-\d{2})$/m.exec(triplet.zh.toString('utf8'))?.[1] const zhDate = /^Archived: (\d{4}-\d{2}-\d{2})$/m.exec(zh.toString('utf8'))?.[1]
if (sourceDate !== undefined && zhDate !== undefined && sourceDate !== zhDate) { if (sourceDate !== undefined && zhDate !== undefined && sourceDate !== zhDate) {
errors.push(`${key}: English and Chinese archive dates differ (${sourceDate} vs ${zhDate})`) errors.push(`${key}: English and Chinese archive dates differ (${sourceDate} vs ${zhDate})`)
} }
const meta = pairMeta(triplet.meta.toString('utf8')) const pair = pairMeta(meta.toString('utf8'))
if (meta === undefined || meta.size !== 2 if (pair === undefined || pair.size !== 2
|| meta.get(`${sourceBase}.md`) !== gitBlobHash(triplet.source) || pair.get(`${sourceBase}.md`) !== gitBlobHash(source)
|| meta.get(`${sourceBase}.zh.md`) !== gitBlobHash(triplet.zh)) { || pair.get(`${sourceBase}.zh.md`) !== gitBlobHash(zh)) {
errors.push(`${metaPath}: consistency record must contain the current Git blob hashes of both archived sides`) errors.push(`${metaPath}: consistency record must contain the current Git blob hashes of both archived sides`)
} }
} }