ci: support shard annotations in checks + endpoint (pageKey inference)
All checks were successful
CI / build-and-anchors (push) Successful in 1m58s
SMOKE / smoke (push) Successful in 13s

This commit is contained in:
2026-02-27 13:13:31 +01:00
parent 8ad960dc69
commit 210f621487
4 changed files with 86 additions and 31 deletions

View File

@@ -117,7 +117,7 @@ async function walk(dir) {
function inferExpectedFromRel(relNoExt) {
const parts = relNoExt.split("/").filter(Boolean);
const last = parts.at(-1) || "";
const isShard = /^p-\d+-/i.test(last);
const isShard = parts.length > 1 && /^p-\d+-/i.test(last); // ✅ durcissement
const pageKey = isShard ? parts.slice(0, -1).join("/") : relNoExt;
const paraId = isShard ? last : null;
return { isShard, pageKey, paraId };
@@ -141,7 +141,6 @@ function validateAndNormalizeDoc(doc, relFile, expectedPageKey, expectedParaId)
}
if (expectedParaId) {
// invariant shard : exactement 1 clé, celle du filename
const keys = Object.keys(doc.paras || {}).map(String);
assert(
keys.includes(expectedParaId),
@@ -165,15 +164,14 @@ async function main() {
const files = await walk(ANNO_ROOT);
for (const fp of files) {
const rel = normPath(path.relative(ANNO_ROOT, fp)); // e.g. archicrat-ia/chapitre-4/p-11-...
const relNoExt = rel.replace(/\.ya?ml$/i, ""); // no ext
const rel = normPath(path.relative(ANNO_ROOT, fp));
const relNoExt = rel.replace(/\.ya?ml$/i, "");
const { isShard, pageKey, paraId } = inferExpectedFromRel(relNoExt);
try {
const raw = await fs.readFile(fp, "utf8");
const doc = YAML.parse(raw) || {};
// ignore non schema:1
if (!isObj(doc) || doc.schema !== 1) continue;
validateAndNormalizeDoc(
@@ -209,7 +207,6 @@ async function main() {
}
}
// sort paras per page
for (const [pageKey, pg] of Object.entries(pages)) {
const keys = Object.keys(pg.paras || {});
keys.sort((a, b) => {
@@ -235,7 +232,6 @@ async function main() {
errors,
};
// CI behaviour: if ANY error => fail build
if (errors.length) {
throw new Error(`${errors[0].file}: ${errors[0].error}`);
}