From 39fe300fd039e49d37ba27523646ddf844f28a1a Mon Sep 17 00:00:00 2001 From: Vyncint Ng <115854244+vyncint@users.noreply.github.com> Date: Wed, 2 Dec 2026 19:39:46 +0700 Subject: [PATCH 1/6] ci(snippets): compile Rust blocks fenced with tildes CommonMark and GitHub open a fenced code block with three or more tildes as well as backticks, but the snippet gate's extraction read backticks alone. A ~~~rust block in SKILL.md or README.md was neither compiled nor refused, so a broken one passed the gate that README and the skill say compiles every Rust block. A fence is now a run of three or more of either character, closed only by a run of the same character at least as long, so a backtick line inside a ~~~text example is content, and the reverse. ~~~rust is compiled and ~~~rust,no_run fails by name, as the backtick forms do. The selftest gains the three cases from the issue, each of which failed before the change; it passes under gawk, mawk and busybox awk. Closes #860 Signed-off-by: Vyncint Ng <115854244+vyncint@users.noreply.github.com> --- .github/scripts/check-skill-snippets.sh | 33 ++++++++++++++++--------- CHANGELOG.md | 7 ++++++ CONTRIBUTING.md | 2 +- tools/snippet-gate-selftest/run.sh | 28 +++++++++++++++++++++ 4 files changed, 57 insertions(+), 13 deletions(-) diff --git a/.github/scripts/check-skill-snippets.sh b/.github/scripts/check-skill-snippets.sh index 727ba141..31434dee 100755 --- a/.github/scripts/check-skill-snippets.sh +++ b/.github/scripts/check-skill-snippets.sh @@ -20,7 +20,8 @@ # Any other Rust tag fails rather than being skipped, and so does a fence the # extraction cannot place: this matched only an unindented, bare ```rust, so a # broken ```rust,no_run block or one indented under a list item passed (#657). -# A tag is skipped only by saying ,ignore. +# A tag is skipped only by saying ,ignore. All of this holds for a fence of +# tildes too: ~~~rust is compiled and ~~~rust,no_run fails (#860). # # Compiles, does not run: the stub `myapp` here is `fn main() {}`, and the # recipes' runtime claims are exercised against a real application when the @@ -73,21 +74,26 @@ EOF # written. Fails, naming the line, on a Rust tag that is neither `rust` nor # `rust,ignore`, and on a fence left open at the end. # -# A fence is any run of three or more backticks at any indentation, closed -# by a run at least as long with nothing after it, as CommonMark has it. The -# content of a non-Rust fence is passed over, so a ```rust line inside a -# ```text example opens nothing. A block indented under a list item has -# that indentation removed. No regex intervals: BSD awk lacks them. +# A fence is any run of three or more backticks or three or more tildes at +# any indentation, closed by a run of the same character at least as long +# with nothing after it, as CommonMark has it. GitHub renders ~~~rust as +# Rust, and reading backticks alone left such a block neither compiled nor +# refused (#860). The content of a non-Rust fence is passed over, so a +# ```rust line inside a ```text or ~~~text example opens nothing, and a +# fence of the other character inside a block is content. A block indented +# under a list item has that indentation removed. No regex intervals: BSD +# awk lacks them. extract() { awk -v dir="$2" -v short="${2#"$tmp"/}" -v index_file="$tmp/index" ' - function fence_len(s, n) { n = 0; while (substr(s, n + 1, 1) == "`") n++; return n } + function run_len(s, c, n) { n = 0; while (substr(s, n + 1, 1) == c) n++; return n } { match($0, /^[ \t]*/) lead = RLENGTH rest = substr($0, lead + 1) - ticks = fence_len(rest) + ch = substr(rest, 1, 1) + ticks = (ch == "`" || ch == "~") ? run_len(rest, ch) : 0 } - infence && ticks >= flen && rest ~ /^`+[ \t]*$/ { + infence && ch == fch && ticks >= flen && substr(rest, ticks + 1) ~ /^[ \t]*$/ { if (out != "") close(out) infence = 0; out = ""; next } @@ -102,14 +108,17 @@ extract() { ticks >= 3 { info = substr(rest, ticks + 1) sub(/^[ \t]+/, "", info); sub(/[ \t]+$/, "", info) - if (index(info, "`") > 0) next # an inline code span, not a fence - infence = 1; flen = ticks; findent = lead; out = ""; opened = NR + # A backtick in a backtick fence'"'"'s info string makes it an inline + # code span; a tilde fence'"'"'s info string may hold anything. + if (ch == "`" && index(info, "`") > 0) next + infence = 1; fch = ch; flen = ticks; findent = lead; out = ""; opened = NR lang = tolower(info); sub(/[ ,{].*$/, "", lang) if (lang != "rust" && lang != "rs") next tag = tolower(info); gsub(/[ \t]/, "", tag) if (tag == "rust,ignore") next if (tag != "rust") { - printf "::error file=%s,line=%d::```%s is neither ```rust (compiled) nor ```rust,ignore (skipped)\n", FILENAME, NR, info > "/dev/stderr" + f = ch ch ch + printf "::error file=%s,line=%d::%s%s is neither %srust (compiled) nor %srust,ignore (skipped)\n", FILENAME, NR, f, info, f, f > "/dev/stderr" bad = 1 next } diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c779ded..2ddc1019 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -142,6 +142,13 @@ reads that marker. first 200 bytes and a hash of the whole, as the library cuts the names it writes to `TERMLENS_ARTIFACT_DIR` (#773). The summary shows it whole. (#808) +- The snippet gate compiles a Rust block fenced with tildes. CommonMark + and GitHub take `~~~rust` as a fence as they take three backticks, but + the gate read backticks alone, so a `~~~rust` block in the skill or the + README was neither compiled nor refused, and a broken one passed. It is + compiled now, `~~~rust,no_run` fails by name as `rust,no_run` does, and + a fence closes only on its own character, so a backtick line inside a + `~~~text` example opens nothing. (#860) ## [0.11.11] - 2026-11-25 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 90a4f6ab..6f8130a5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -78,7 +78,7 @@ tools/dco-gate-selftest/run.sh # …and the DCO gate, i tools/preflight-selftest/run.sh # …and the runner accounts for each gate it runs, failures included tools/report-action-selftest/run.sh # …and the report action writes its summary past a directory it cannot read, a fence, a newline or CR in a name, a relative artifact directory, screens past 1 MiB, or a pair it cannot read tools/gates-listed-selftest/run.sh # …and the gates-listed gate, named, quoted and folded gates included -tools/snippet-gate-selftest/run.sh # …and the snippet gate reads indented and variant-tagged Rust blocks +tools/snippet-gate-selftest/run.sh # …and the snippet gate reads indented, tilde-fenced and variant-tagged Rust blocks tools/release-notes-selftest/run.sh # …and the release notes carry the link definitions their section uses .github/scripts/check-semver.sh 0.11.11 # …and the public API is compatible with the last published release ``` diff --git a/tools/snippet-gate-selftest/run.sh b/tools/snippet-gate-selftest/run.sh index 26099ffc..a64c06a7 100755 --- a/tools/snippet-gate-selftest/run.sh +++ b/tools/snippet-gate-selftest/run.sh @@ -16,6 +16,9 @@ # - ```rust,ignore is skipped, and a ```rust line inside a ````text # example opens nothing # - a fence left open fails rather than swallowing the rest of the file +# - a fence of tildes is a fence too (#860): ~~~rust is extracted, +# ~~~rust,no_run fails by name, and a ```rust line inside a ~~~text +# example opens nothing, since only the opening character closes it # - a README block without #[test] is wrapped as the body of a function # with `t` and `screen` in scope; one with #[test] is left whole # - the repository's own SKILL.md and README.md extract cleanly @@ -77,6 +80,8 @@ refuses "a \`\`\`rs block fails by name" '```rs is neither' \ '```rs' 'fn f() {}' '```' refuses "a fence left open fails" 'never closed' \ '```rust' '#[test] fn t() {}' '```' '' '```text' 'the rest of the file' +refuses "a ~~~rust,no_run block fails by name" '~~~rust,no_run is neither' \ + '~~~rust,no_run' 'fn broken() -> u8 { "not a u8" }' '~~~' # `extracts