From d3ab0faf52a02ff5a618f3ed7beb608b78752abd Mon Sep 17 00:00:00 2001 From: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com> Date: Mon, 2 Nov 2026 03:14:29 +0800 Subject: [PATCH] refactor(ci): parse readiness fences with a static expression (#8586) --- scripts/ci/pr-readiness.mjs | 8 ++++---- tests/boundary/filesystem/prReadiness.test.ts | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/scripts/ci/pr-readiness.mjs b/scripts/ci/pr-readiness.mjs index c1e8ba8b2c..3f53438156 100644 --- a/scripts/ci/pr-readiness.mjs +++ b/scripts/ci/pr-readiness.mjs @@ -60,11 +60,11 @@ function readinessLines(markdown) { let comment = false; for (const source of lines) { if (fence) { + const closing = /^ {0,3}(`+|~+)\s*$/u.exec(source); if ( - new RegExp( - `^ {0,3}${fence.character}{${fence.length},}\\s*$`, - "u", - ).test(source) + closing !== null && + closing[1][0] === fence.character && + closing[1].length >= fence.length ) fence = undefined; continue; diff --git a/tests/boundary/filesystem/prReadiness.test.ts b/tests/boundary/filesystem/prReadiness.test.ts index ead81379de..4d3e7273e2 100644 --- a/tests/boundary/filesystem/prReadiness.test.ts +++ b/tests/boundary/filesystem/prReadiness.test.ts @@ -180,6 +180,24 @@ describe("initial author declaration", () => { ); }); + it.each([ + ["longer backticks", "````markdown", "`````", "success"], + ["longer tildes", "~~~~markdown", "~~~~~", "success"], + ["indented closer with whitespace", "```", " ```` \t", "success"], + ["shorter backticks", "````", "```", "failure"], + ["shorter tildes", "~~~~", "~~~", "failure"], + ["different marker", "```", "~~~", "failure"], + ["mixed markers", "```", "``~", "failure"], + ["four-space indentation", "```", " ```", "failure"], + ["text after the closer", "~~~", "~~~ text", "failure"], + ])( + "keeps declarations hidden until a valid closing fence: %s", + (_name, opening, closing, state) => { + const body = `${opening}\n${readyBody}\n${closing}\n${readyBody}`; + expect(evaluateReadiness(makePull({ body }), template).state).toBe(state); + }, + ); + it("fails closed when the trusted template loses a declaration", () => { expect(() => evaluateReadiness(