refactor(ci): parse readiness fences with a static expression (#8586)

This commit is contained in:
gensokyo-dev authored and GitHub committed 2026-11-02 03:14:29 +08:00
1 parent 6d60db1951
commit d3ab0faf52
2 files changed
+22 -4

No files matched your search

+4 -4
View File
@@ -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;
@@ -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(