diff --git a/.github/scripts/check-ci-gates-listed.sh b/.github/scripts/check-ci-gates-listed.sh index db2d3a12..784139be 100755 --- a/.github/scripts/check-ci-gates-listed.sh +++ b/.github/scripts/check-ci-gates-listed.sh @@ -1,8 +1,9 @@ #!/usr/bin/env bash # Every gate CI runs must appear in CONTRIBUTING.md §1's "run these before -# pushing" block. The paragraph under that block promises the workflow is -# the source of truth when the two disagree; this is what makes the promise -# hold. It also holds §7's "Required checks" list to the jobs +# pushing" block, with the toolchain and flags CI gives it, and every gate +# §1 lists must be one CI runs (#858). The paragraph under that block +# promises the workflow is the source of truth when the two disagree; this +# is what makes the promise hold. It also holds §7's "Required checks" list to the jobs # `required-green` needs, which drifted twice with nothing comparing them # (#509, #861). Usage: check-ci-gates-listed.sh [ci.yml] [CONTRIBUTING.md] set -euo pipefail @@ -28,17 +29,33 @@ plumbing=( # One record per `run:` key, separated by \037 (a tab is IFS whitespace, so # an empty name between two would vanish): kind (line or block), the step's -# name (empty when it has none), the line number, and for a single-line -# value the command with YAML's quoting and folding undone. A step's keys -# can come in any order, so a step is printed once it ends, when its name is +# name (empty when it has none), the line number, for a single-line value +# the command with YAML's quoting and folding undone, and then the step's +# RUSTUP_TOOLCHAIN, RUSTFLAGS and RUSTDOCFLAGS, from its own `env:` or the +# nearest enclosing one (the job's, the workflow's). A step's keys can come +# in any order, so a step is printed once it ends, when its name and env are # known. This is a reader for the YAML this repository writes, not a YAML # parser: flow mappings and anchors are not steps here. records="$(awk ' function indent(s) { match(s, /^ */); return RLENGTH } + # The value of env var `v` the step keyed at `k` sees: its own, or the + # nearest enclosing mapping'"'"'s. + function envof(k, v, j) { + for (j = k; j >= 0; j--) if ((j, v) in env) return env[j, v] + return "" + } function flush(k) { - if (has_run[k]) printf "%s\037%s\037%d\037%s\n", kind[k], name[k], line[k], value[k] + if (has_run[k]) printf "%s\037%s\037%d\037%s\037%s\037%s\037%s\n", kind[k], name[k], line[k], value[k], + envof(k, "RUSTUP_TOOLCHAIN"), envof(k, "RUSTFLAGS"), envof(k, "RUSTDOCFLAGS") has_run[k] = 0; name[k] = "" } + # A mapping that ended takes its env with it. + function drop_env(deeper_than, key, parts) { + for (key in env) { + split(key, parts, SUBSEP) + if (parts[1] + 0 > deeper_than) delete env[key] + } + } function unquote(v, q) { q = substr(v, 1, 1) if ((q == "\"" || q == "\047") && substr(v, length(v), 1) == q) { @@ -74,13 +91,30 @@ records="$(awk ' { # A line less indented than a pending step ends it. for (j in has_run) if (has_run[j] && ind < j + 0) flush(j) + drop_env(ind) + } + # An entry of an `env:` mapping: NAME: value. + env_k >= 0 && ind > env_k { + v = substr(raw, ind + 1) + if (match(v, /^[A-Za-z_][A-Za-z0-9_]*:/)) { + key = substr(v, 1, RLENGTH - 1) + v = substr(v, RLENGTH + 1); sub(/^[ \t]+/, "", v) + env[env_k, key] = unquote(decomment(v)) + } + next } + { env_k = -1 } match(raw, /^ *- /) { k = RLENGTH flush(k) + drop_env(k - 1) rest = substr(raw, k + 1) } !match(raw, /^ *- /) { k = ind; rest = substr(raw, ind + 1) } + rest ~ /^env:[ \t]*(#.*)?$/ { + env_k = k + next + } rest ~ /^name:/ { v = rest; sub(/^name:[ \t]*/, "", v) name[k] = unquote(decomment(v)) @@ -101,7 +135,7 @@ records="$(awk ' if (cont_k >= 0 && kind[cont_k] == "line") value[cont_k] = unquote(decomment(value[cont_k])) for (j in has_run) flush(j) } -' cont_k=-1 "$ci")" +' cont_k=-1 env_k=-1 "$ci")" is_plumbing() { local p @@ -111,9 +145,14 @@ is_plumbing() { return 1 } +# CI's msrv job sets RUSTUP_TOOLCHAIN from Cargo.toml's rust-version; §1 +# writes that toolchain out, as `cargo +1.85 …`. +root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" +msrv="$(sed -n 's/^rust-version *= *"\(.*\)"/\1/p' "$root/Cargo.toml" | head -1)" + status=0 ci_cmds="" -while IFS=$'\037' read -r kind name lineno cmd; do +while IFS=$'\037' read -r kind name lineno cmd toolchain rustflags rustdocflags; do [ -z "$kind" ] && continue if [ -n "$name" ] && is_plumbing "$name"; then continue @@ -125,8 +164,37 @@ while IFS=$'\037' read -r kind name lineno cmd; do continue fi cmd="$(sed -E 's/[[:space:]]+/ /g; s/^ //; s/ $//' <<<"$cmd")" + # What CI gives a cargo step is part of its gate, so §1 must say it too + # (#858): `RUSTDOCFLAGS='-D warnings'` is what makes the docs job fail on + # a broken intra-doc link, and the toolchain is what makes the msrv job a + # check of the MSRV. Both used to be stripped from §1 before comparing, + # so §1 could drop either and tools/preflight.sh then ran a weaker gate. + # RUSTDOCFLAGS is written only where rustdoc runs (`cargo doc`, + # `cargo rustdoc`, `cargo test`'s doctests), since the docs job's env + # reaches its script steps too, where it changes nothing. case "$cmd" in - "cargo "* | .github/scripts/* | tools/*) + "cargo "*) + case "$toolchain" in + "") ;; + '${{ steps.msrv.outputs.msrv }}') + cmd="cargo +$msrv ${cmd#cargo }" ;; + *'${{'*) + echo "::error::$where runs under RUSTUP_TOOLCHAIN=$toolchain, which $(basename "$0") cannot resolve to the toolchain CONTRIBUTING.md §1 must name" + status=1 ;; + *) + cmd="cargo +$toolchain ${cmd#cargo }" ;; + esac + sub="${cmd#cargo }" + case "$sub" in +*) sub="${sub#* }" ;; esac + case "$sub" in + doc | "doc "* | rustdoc | "rustdoc "* | test | "test "*) + [ -n "$rustdocflags" ] && cmd="RUSTDOCFLAGS='$rustdocflags' $cmd" ;; + esac + [ -n "$rustflags" ] && cmd="RUSTFLAGS='$rustflags' $cmd" + ;; + esac + case "$cmd" in + "cargo "* | "RUSTFLAGS="* | "RUSTDOCFLAGS="* | .github/scripts/* | tools/*) ci_cmds="$ci_cmds$cmd"$'\n' ;; *) echo "::error::$where runs \`$cmd\`, which is neither a gate (cargo …, .github/scripts/…, tools/…) nor a step in the plumbing list in $(basename "$0")" @@ -134,16 +202,13 @@ while IFS=$'\037' read -r kind name lineno cmd; do esac done <<<"$records" -cargo_count="$(grep -c '^cargo ' <<<"$ci_cmds" || true)" +cargo_count="$(grep -Ec "^(RUST[A-Z]*FLAGS='[^']*' )*cargo " <<<"$ci_cmds" || true)" script_count="$(grep -Ec '^(\.github/scripts/|tools/)' <<<"$ci_cmds" || true)" -# CONTRIBUTING §1: the shared extraction in extract-gates.sh (#368), plus -# the normalisations this comparison alone needs — the RUSTDOCFLAGS prefix -# and a `+toolchain` selector removed, because `cargo +1.85 check` in the -# doc is `cargo check` under RUSTUP_TOOLCHAIN in the workflow. -doc_cmds="$("$(dirname "${BASH_SOURCE[0]}")/extract-gates.sh" "$doc" \ - | sed -E -e "s/^RUSTDOCFLAGS='-D warnings' //" \ - -e 's/^cargo \+[^ ]+ /cargo /')" +# CONTRIBUTING §1: the shared extraction in extract-gates.sh (#368), as +# written. The CI side above carries the step's toolchain and flags, so the +# two compare whole (#858). +doc_cmds="$("$(dirname "${BASH_SOURCE[0]}")/extract-gates.sh" "$doc")" while IFS= read -r cmd; do [ -z "$cmd" ] && continue @@ -153,6 +218,29 @@ while IFS= read -r cmd; do fi done <<<"$ci_cmds" +# …and the other way: a gate §1 lists must be one CI runs, or §1 and +# tools/preflight.sh keep a gate CI dropped (#858). §1's setup lines are +# not gates; tools/preflight.sh skips the same ones. Two gates run in CI +# other than as a step of their own, and each is held to what runs it: the +# deny job uses cargo-deny's action, and the zizmor job runs zizmor inside +# its retry function, so that line must appear in ci.yml as written. +ci_code="$(grep -v '^[[:space:]]*#' "$ci")" +while IFS= read -r cmd; do + [ -z "$cmd" ] && continue + case "$cmd" in + "git clone "* | "cd "* | "cargo install "* | "cargo insta "*) continue ;; + esac + grep -Fxq -- "$cmd" <<<"$ci_cmds" && continue + case "$cmd" in + "cargo deny check") + grep -Fq 'uses: EmbarkStudios/cargo-deny-action@' <<<"$ci_code" && continue ;; + "pipx run zizmor"*) + grep -Fq -- "$cmd" <<<"$ci_code" && continue ;; + esac + echo "::error::CONTRIBUTING.md §1 lists \`$cmd\` but CI does not run it, or runs it with another toolchain or flags" + status=1 +done <<<"$doc_cmds" + # zizmor is pinned in the workflow; the doc must name the same pin. pin="$(grep -o 'zizmor==[0-9.]*' "$ci" | head -1 || true)" if [ -n "$pin" ] && ! grep -Fq -- "$pin" "$doc"; then 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/.github/scripts/check-unsafe-blocks.sh b/.github/scripts/check-unsafe-blocks.sh index 0df4daf1..92e927f9 100755 --- a/.github/scripts/check-unsafe-blocks.sh +++ b/.github/scripts/check-unsafe-blocks.sh @@ -1,18 +1,33 @@ #!/usr/bin/env bash -# .github/scripts/check-unsafe-blocks.sh — assert that the count of `unsafe {` -# blocks in the codebase matches the number documented in SECURITY.md (#706). +# .github/scripts/check-unsafe-blocks.sh — assert that the `unsafe` code in +# the crates is exactly the count of blocks SECURITY.md documents (#706). # # SECURITY.md promises that unsafe is confined to a specific, audited count # of blocks. This check ensures the documentation and implementation cannot -# drift when unsafe blocks are added or removed. +# drift when unsafe code is added or removed. # -# Usage: .github/scripts/check-unsafe-blocks.sh [SECURITY.md] +# What is counted is every `unsafe` keyword in the Rust sources, outside +# comments and string and character literals: one followed by `{` is a +# block, and any other (`unsafe impl`, `unsafe fn`, `unsafe trait`, +# `unsafe extern`, `#[unsafe(…)]`) is unsafe code that is not a block. +# SECURITY.md speaks of blocks alone, so the blocks must match its count and +# there must be no other. This counted lines holding `unsafe {`, so an +# `unsafe impl Send` passed at the old count, and two blocks on one line +# counted as one, so only a wrong count passed (#864). +# +# Usage: .github/scripts/check-unsafe-blocks.sh [SECURITY.md [SRC_DIR ...]] +# SRC_DIR defaults to crates/*/src; tools/unsafe-gate-selftest/ passes its +# own. set -euo pipefail root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" cd "$root" doc="${1:-SECURITY.md}" +[ "$#" -gt 0 ] && shift +if [ "$#" -eq 0 ]; then + set -- crates/*/src +fi if [ ! -f "$doc" ]; then echo "::error::document not found: $doc" >&2 @@ -47,12 +62,87 @@ PY exit 1 } -actual="$(grep -rn 'unsafe {' crates/*/src | wc -l | tr -d ' ')" +# One line per `unsafe` keyword: `block :` or `other :`. +sites="$(python3 - "$@" <<'PY' +import os, re, sys -if [ "$actual" -ne "$documented" ]; then - echo "::error::unsafe block count mismatch: $doc documents $documented, but crates/*/src contains $actual:" >&2 - grep -rn 'unsafe {' crates/*/src | sed 's/^/ /' >&2 - exit 1 +# A Rust lexer just deep enough to tell code from comments and literals: +# `// unsafe {` and "unsafe {" are not unsafe code, and a count that read +# them would let a real block hide behind such a mention. +CHAR = re.compile(r"'(?:\\(?:u\{[0-9a-fA-F_]+\}|x[0-9a-fA-F]{2}|.)|[^\\'\n])'") +RAW = re.compile(r'(?:br|cr|r)(#*)"') +WORD = re.compile(r"[A-Za-z_][A-Za-z0-9_]*") + +def blank(s): + return "".join(c if c == "\n" else " " for c in s) + +def code_only(src): + """`src` with every comment and literal blanked, its newlines kept.""" + out = [] + i, n = 0, len(src) + while i < n: + c = src[i] + if src.startswith("//", i): + j = src.find("\n", i) + j = n if j < 0 else j + elif src.startswith("/*", i): + # Block comments nest in Rust. + depth, j = 1, i + 2 + while j < n and depth: + if src.startswith("/*", j): + depth += 1; j += 2 + elif src.startswith("*/", j): + depth -= 1; j += 2 + else: + j += 1 + elif m := RAW.match(src, i): + close = '"' + m.group(1) + j = src.find(close, m.end()) + j = n if j < 0 else j + len(close) + elif c == '"': + j = i + 1 + while j < n and src[j] != '"': + j += 2 if src[j] == "\\" else 1 + j += 1 + elif c == "'" and (m := CHAR.match(src, i)): + j = m.end() + elif m := WORD.match(src, i): + # A whole identifier at once, so the `r` ending `bar"` cannot + # start a raw string; `b"…"` leaves `b` here and the string next. + out.append(m.group(0)); i = m.end() + continue + else: + out.append(c); i += 1 + continue + out.append(blank(src[i:j])); i = j + return "".join(out) + +files = [] +for top in sys.argv[1:]: + for d, _, names in os.walk(top): + files += [os.path.join(d, f) for f in names if f.endswith(".rs")] +for path in sorted(files): + code = code_only(open(path, encoding="utf-8").read()) + for m in re.finditer(r"\bunsafe\b(\s*\{)?", code): + line = code.count("\n", 0, m.start()) + 1 + print("block" if m.group(1) else "other", f"{path}:{line}") +PY +)" + +blocks="$(printf '%s\n' "$sites" | command grep -c '^block ' || true)" +others="$(printf '%s\n' "$sites" | command grep -c '^other ' || true)" + +status=0 +if [ "$others" -ne 0 ]; then + echo "::error::$doc counts unsafe blocks alone, but $* holds $others other unsafe item(s); remove them, or document them in $doc and count them in this gate:" >&2 + printf '%s\n' "$sites" | sed -n 's/^other / /p' >&2 + status=1 +fi +if [ "$blocks" -ne "$documented" ]; then + echo "::error::unsafe block count mismatch: $doc documents $documented, but $* contains $blocks:" >&2 + printf '%s\n' "$sites" | sed -n 's/^block / /p' >&2 + status=1 fi +[ "$status" -eq 0 ] || exit 1 -echo "unsafe blocks: $doc documents $documented, matching $actual in crates/*/src" +echo "unsafe blocks: $doc documents $documented, matching $blocks in $*, with no other unsafe code" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8c6e5bfd..fbcb7acf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -254,7 +254,8 @@ jobs: - run: tools/report-action-selftest/run.sh # …and the gates-listed gate itself (#657): a gate under a `name:`, # in quotes or in a folded block was invisible to it, so each is - # asserted to fail unlisted. + # asserted to fail unlisted; and so is §1 drift it passed (#858), a + # dropped `-D warnings`, a wrong `+toolchain`, a gate CI stopped running. - run: tools/gates-listed-selftest/run.sh # …and the snippet gate's extraction (#657): a ```rust,no_run block # or one indented under a list item was never compiled. Extraction @@ -264,6 +265,10 @@ jobs: # the foot definitions it names showed v0.11.0's `[Unsupported]` in # brackets on the GitHub Release. - run: tools/release-notes-selftest/run.sh + # …and the unsafe-count gate (#864): it counted lines holding + # `unsafe {`, so an `unsafe impl` passed at the documented count and + # two blocks on one line counted once. Python only, no toolchain. + - run: tools/unsafe-gate-selftest/run.sh # The emit fixture's documented steps against the ones it implements # (#318). It lives in this job because it needs no toolchain — it is # two greps and a `comm` — and the fixture is what almost every @@ -413,7 +418,7 @@ jobs: # Both must ship the licence texts their licences require (#863). - run: .github/scripts/check-package-contents.sh # The audited unsafe block count documented in SECURITY.md matches the - # codebase (#706). + # codebase (#706), and there is no unsafe code but those blocks (#864). - run: .github/scripts/check-unsafe-blocks.sh deny: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a791c123..16d4f3da 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -35,6 +35,14 @@ jobs: echo "::error::Tag v${tag} does not match crates/termlens version ${version}. Bump the version (docs/RELEASING.md) before tagging." exit 1 fi + # The GitHub Release's notes are this tag's CHANGELOG section, and + # github-release extracts it only after publish. A release PR that + # bumped the version without moving [Unreleased] published both + # crates, then failed there, with no Release and no install check of + # what crates.io now served (#857). A missing or empty section fails + # here instead, before anything is published. + - name: Check CHANGELOG.md has this tag's section + run: .github/scripts/extract-changelog.sh "$GITHUB_REF_NAME" > /dev/null # Re-run the exact CI gates (fmt, clippy, test matrix, msrv, docs, deny), # the semver gate included: ci.yml's `semver` job checks the tree against diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c779ded..0a89b85d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,25 @@ reads that marker. a payload that long, since deflate output for a picture is far smaller than the picture. A test that decoded such a payload should expect `Malformed`, or the application should send it unpadded. (#810) +- A sixel pixel decodes in the colour its register holds where the data + ends, as xterm draws it, not the colour it held when the pixel was + painted. xterm keeps each pixel's register and draws through the + registers as they stand, so a register redefined after painting + recolours everything it painted. `decode()` kept the earlier colour, so + `#1;2;100;0;0#1!3~#1;2;0;0;100!3~` decoded as three red columns and + three blue where xterm shows six blue, and one register could decode + in two colours, painted and filled. A test that expected the colour a + register had at the time it painted should expect its last colour. + (#842) +- The `regex` methods fold the pattern to NFC, as `contains`, `find` and + `mask_matching` fold a needle. Only the row was folded, so a pattern + holding decomposed text, such as `regex::escape` of a macOS file name + (`cafe` + U+0301), never matched the same text on screen: `matches` was + false, `wait_until_matches` timed out and `mask_matches` left the text in + the snapshot. A pattern that is not NFC is matched as a copy compiled + from its NFC form with the default options, so a `RegexBuilder` option + such as `case_insensitive` does not reach it; a test that built one + with a decomposed literal should give the flag inline, as `(?i)`. (#847) ### Fixed @@ -142,6 +161,39 @@ 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) +- The unsafe-count gate counts `unsafe` code rather than lines holding + `unsafe {`. An `unsafe impl Send` passed it at SECURITY.md's count of + nine blocks, and two blocks on one line counted once, so it passed only + when SECURITY.md was wrong. Every `unsafe` keyword outside comments and + literals is counted: one opening a block counts once, wherever it sits, + and an `unsafe impl`, `fn`, `trait` or `extern` fails the gate, since + SECURITY.md documents blocks alone and now says what is counted. A + selftest, `tools/unsafe-gate-selftest/run.sh`, holds both cases. (#864) +- The gates-listed check holds CONTRIBUTING §1 to what CI gives each + gate, and to the gates CI still runs. It removed `RUSTDOCFLAGS` and a + `+toolchain` from §1's lines before comparing them and only looked for + CI's gates in §1, so §1 could drop `-D warnings` from `cargo doc`, name + the wrong MSRV toolchain or list a gate CI no longer ran, and + `tools/preflight.sh` then ran that weaker list. It now reads a step's + `RUSTDOCFLAGS` and `RUSTUP_TOOLCHAIN` (the msrv job's as Cargo.toml's + `rust-version`) into the command, and fails a §1 gate CI does not run. + `tools/preflight.sh` skips whichever `+toolchain` §1 names when it is + not installed, not only 1.85. (#858) +- A release tag whose `CHANGELOG.md` has no section for its version, or an + empty one, fails in `release.yml`'s first job, before anything is + published. The notes were first extracted after both crates were on + crates.io, so such a tag published them and then failed, with no GitHub + Release and no check of what crates.io served. The release-notes + selftest in CI also extracts the workspace version's section, so a + release pull request that bumps the version without moving + `[Unreleased]` goes red. (#857) ## [0.11.11] - 2026-11-25 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 90a4f6ab..1825a0f9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -61,7 +61,7 @@ RUSTDOCFLAGS='-D warnings' cargo doc --no-deps --all-features .github/scripts/check-candidate-statement.sh # README, CHANGELOG and STABILITY state the candidate in the same words .github/scripts/check-report-pin.sh # the three report@v refs agree with the workspace version .github/scripts/check-package-contents.sh # neither published crate ships its tests/, which cannot pass outside the workspace, and both ship LICENSE-MIT and LICENSE-APACHE -.github/scripts/check-unsafe-blocks.sh # SECURITY.md's audited unsafe block count matches the codebase +.github/scripts/check-unsafe-blocks.sh # SECURITY.md's audited unsafe block count matches the codebase, and there is no other unsafe code .github/scripts/check-skill-snippets.sh # every Rust block in SKILL.md and README.md still compiles cargo deny check # cargo install cargo-deny pipx run zizmor==1.29.0 --persona=pedantic .github/ # workflow and action audit; needs GH_TOKEN for the online checks @@ -78,8 +78,9 @@ 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 +tools/unsafe-gate-selftest/run.sh # …and the unsafe gate counts two blocks on one line, and fails an `unsafe impl` .github/scripts/check-semver.sh 0.11.11 # …and the public API is compatible with the last published release ``` @@ -89,7 +90,10 @@ avoidable bad first experience. If it ever disagrees with [`.github/workflows/ci.yml`](.github/workflows/ci.yml), the workflow is the source of truth and this list is the bug — and the `gates-listed` CI job (`.github/scripts/check-ci-gates-listed.sh`) fails when the two disagree, -so the bug cannot sit here unnoticed again. The same job holds §7's list +so the bug cannot sit here unnoticed again. It compares each line whole, +with the toolchain and `RUSTDOCFLAGS` CI gives the step, and both ways: a +gate CI runs that is missing here fails it, and so does a gate listed here +that CI no longer runs. The same job holds §7's list of required checks to the jobs `required-green` needs. The integration tests spawn real PTYs and small fixture apps from diff --git a/SECURITY.md b/SECURITY.md index 120a4766..227466b3 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -37,7 +37,11 @@ What the project does continuously, enforced by required CI on every change: `-D warnings`, so a new block fails unless it carries that `#[allow]` as well: the attribute is what review has to see, not a count the lint keeps. The count above is held to the code by - `.github/scripts/check-unsafe-blocks.sh`. None touches memory the child + `.github/scripts/check-unsafe-blocks.sh`, which counts every `unsafe` + keyword in `crates/*/src` outside comments and string literals: each one + that opens a block counts once, two on a line count twice, and any other + (`unsafe impl`, `unsafe fn`, `unsafe trait`, `unsafe extern`) fails it, + since there is none (#864). None touches memory the child can influence. Everything on the parsing path is pure Rust: escape sequences from the child are parsed, never executed or evaluated. - **Dependency policy** (`cargo-deny` job): RUSTSEC advisories, yanked diff --git a/crates/termlens/src/graphics.rs b/crates/termlens/src/graphics.rs index 65e230f3..d1e37c1a 100644 --- a/crates/termlens/src/graphics.rs +++ b/crates/termlens/src/graphics.rs @@ -432,6 +432,11 @@ impl GraphicsPayload { /// Decoding is done here, on demand, and never as the bytes arrive: a /// test that only counts payloads should not pay for inflating them. /// + /// A sixel decodes in the colours its registers hold where its data + /// ends, as xterm draws it: a register redefined after painting + /// recolours every pixel painted with it, and the background filled + /// from register 0 (see [`Bitmap::pixel`]). + /// /// # Errors /// /// Returns [`DecodeError::NotCaptured`] when the payload exceeded the @@ -786,8 +791,10 @@ fn decode_chunked_base64(data: &[u8]) -> Option> { /// The format in one paragraph: optional raster attributes /// (`"Pan;Pad;Ph;Pv`) declare the size; `#n;2;r;g;b` defines colour register /// `n` in percent; `#n` selects it; a byte `?`..`~` paints the six pixels of -/// the current band whose bits it sets; `!` repeats the next such -/// byte; `$` returns to the left margin within the band; `-` ends the band. +/// the current band whose bits it sets with the selected register; +/// `!` repeats the next such byte; `$` returns to the left margin +/// within the band; `-` ends the band. Each pixel takes its register's +/// colour as the stream ends, not as it is painted (#842). /// /// `background` is the area the header's background select has filled /// with colour register 0 before anything is painted, `None` for none @@ -840,10 +847,16 @@ fn decode_sixel(data: &[u8], background: Option<(u32, u32)>) -> Result>> = Vec::new(); + // declare its size, and one that does can still overrun it. A pixel + // holds the register it was painted with, not that register's colour: + // xterm's `set_sixel` stores the register number (`graphics_sixel.c`) + // and `refresh_graphic` draws each pixel from the colour table as it + // stands (`graphics.c`), so a register redefined after painting + // repaints every pixel drawn with it. Resolving the colour at paint time + // decoded one register in two colours (#842). + let mut rows: Vec>> = Vec::new(); let mut band_top = 0usize; let mut x = 0usize; let mut width_seen = 0usize; @@ -909,7 +922,8 @@ fn decode_sixel(data: &[u8], background: Option<(u32, u32)>) -> Result {} } } - current = index; + // Below `MAX_SIXEL_REGISTERS`, refused above, so it fits. + current = index as u16; } b'!' => { at += 1; @@ -929,7 +943,7 @@ fn decode_sixel(data: &[u8], background: Option<(u32, u32)>) -> Result) -> Result { @@ -962,13 +976,13 @@ fn decode_sixel(data: &[u8], background: Option<(u32, u32)>) -> Result>>, + rows: &mut Vec>>, width_seen: &mut usize, band_top: usize, x: &mut usize, bits: u8, count: usize, - colour: [u8; 4], + register: u16, ) -> Result<(), DecodeError> { for _ in 0..count { // Checked every step rather than once against `count`: `!n` gives @@ -992,7 +1006,7 @@ fn decode_sixel(data: &[u8], background: Option<(u32, u32)>) -> Result) -> Result) -> Result registers[0], // Untouched: sixel has no alpha, so a pixel never @@ -2967,6 +2983,37 @@ mod tests { assert_eq!(bitmap.pixel(0, 0), Some([255, 0, 0, 255])); } + /// xterm keeps the register each pixel was painted with, not its colour, + /// and draws the image through the registers as the stream leaves them + /// (`set_sixel` in `graphics_sixel.c`, `refresh_graphic` in + /// `graphics.c`): a register redefined after painting repaints all of + /// it, and a painted pixel and the background fill drawn from one + /// register are never two colours (#842). + #[cfg(feature = "decode")] + #[test] + fn a_register_redefined_after_painting_draws_in_its_last_colour() { + const GREEN: [u8; 4] = [0, 255, 0, 255]; + const BLUE: [u8; 4] = [0, 0, 255, 255]; + let top = |bitmap: Bitmap| -> Vec<[u8; 4]> { + (0..bitmap.width()) + .map(|x| bitmap.pixel(x, 0).unwrap()) + .collect() + }; + // Register 1 paints three columns red, is redefined blue, and paints + // three more. + let redefined = sixel_under_header(b"0;1", b"#1;2;100;0;0#1!3~#1;2;0;0;100!3~") + .decode() + .expect("decodes"); + assert_eq!(top(redefined), [BLUE; 6]); + // Register 0 paints two columns red and is redefined green; the + // default background fills the other two columns of the 4x6 raster + // with it. + let background = sixel_under_header(b"0;0", b"\"1;1;4;6#0;2;100;0;0#0!2~#0;2;0;100;0") + .decode() + .expect("decodes"); + assert_eq!(top(background), [GREEN; 4]); + } + #[test] fn the_debug_rendering_stays_short_enough_for_a_log() { let payload = kitty_payload(b"a=T,f=32,o=z,s=954,v=133,i=7,c=106,r=7", &[b'A'; 4096]); diff --git a/crates/termlens/src/screen.rs b/crates/termlens/src/screen.rs index 5fcb6691..70cd02db 100644 --- a/crates/termlens/src/screen.rs +++ b/crates/termlens/src/screen.rs @@ -2465,6 +2465,14 @@ impl Screen { /// (a terminal has no row boundary a user reads across), and the column /// reported is a cell column, mapped back through wide characters exactly /// as [`find`](Self::find) does. +/// +/// The pattern is folded to NFC as well, as a needle is, so +/// `regex::escape` of decomposed text (the form macOS keeps file names in) +/// matches it on screen. A pattern that is not NFC already is matched as a +/// copy compiled from its NFC form with the default options: give flags +/// inline, as `(?i)`, rather than through `regex::RegexBuilder`, whose +/// options a `Regex` does not carry. A class that lists a base and a mark +/// apart, `[e\u{301}]`, folds into one character and changes meaning. #[cfg(feature = "regex")] #[cfg_attr(docsrs, doc(cfg(feature = "regex")))] impl Screen { @@ -2522,6 +2530,7 @@ impl Screen { /// If `fill` is not one column wide, as `mask_matching` does. #[must_use] pub fn mask_matches(&self, re: ®ex::Regex, fill: char) -> Screen { + let re = nfc_regex(re); self.masked_spans( |hay| re.find_iter(hay).map(|m| (m.start(), m.end())).collect(), fill, @@ -2533,6 +2542,7 @@ impl Screen { re: ®ex::Regex, mut visit: impl FnMut((u16, u16, String)) -> bool, ) { + let re = nfc_regex(re); for row in 0..self.rows { let (text, cols) = self.searchable_row(row); for m in re.find_iter(text.trim_end()) { @@ -2547,6 +2557,23 @@ impl Screen { } } +/// `re` as a pattern over NFC-folded rows: itself when its pattern is NFC +/// already, as every ASCII pattern is, and otherwise a copy compiled from +/// the pattern folded to NFC. The rows were folded and the pattern was not, +/// so `regex::escape("cafe\u{301}")` never matched the `cafe\u{301}` that +/// `contains` found on the same row (#847). Regex syntax is ASCII, so the +/// fold changes only the pattern's literals. A pattern whose fold does not +/// compile, which no NFC text of a valid pattern should be, is used as +/// written rather than refused. +#[cfg(feature = "regex")] +fn nfc_regex(re: ®ex::Regex) -> std::borrow::Cow<'_, regex::Regex> { + let pattern = re.as_str(); + if pattern.is_ascii() || unicode_normalization::is_nfc(pattern) { + return std::borrow::Cow::Borrowed(re); + } + regex::Regex::new(&nfc(pattern)).map_or(std::borrow::Cow::Borrowed(re), std::borrow::Cow::Owned) +} + /// `s` folded to NFC, the form a needle and the screen are compared in. fn nfc(s: &str) -> String { let mut out = String::with_capacity(s.len()); @@ -2938,6 +2965,29 @@ mod tests { assert_ne!(on_nfd.text(), on_nfc.text()); } + /// A pattern is compared in NFC too, so the regex methods agree with + /// `contains` and `mask_matching` in both directions (#847). + #[cfg(feature = "regex")] + #[test] + fn patterns_match_across_normalization_forms() { + let nfc = "caf\u{e9}"; + let nfd = "cafe\u{301}"; + for on in [nfc, nfd] { + let s = screen(10, 1, &[&format!("{on} ok")]); + for written in [nfc, nfd] { + let re = regex::Regex::new(®ex::escape(written)).unwrap(); + assert!(s.matches(&re), "{written:?} on {on:?}"); + assert_eq!(s.find_match(&re), Some((0, 0, nfc.to_owned()))); + assert_eq!(s.find_all_matches(&re).len(), 1); + assert_eq!( + s.mask_matches(&re, '#').row_text(0), + s.mask_matching(written, '#').row_text(0), + ); + assert_eq!(s.mask_matches(&re, '#').row_text(0).trim_end(), "#### ok"); + } + } + } + /// A mark with a precomposed form folds into its base: the screen is /// compared as `caf\u{e9}`, so it does not show `cafe`. #[test] diff --git a/crates/termlens/tests/graphics.rs b/crates/termlens/tests/graphics.rs index 8826e859..f6a24f6c 100644 --- a/crates/termlens/tests/graphics.rs +++ b/crates/termlens/tests/graphics.rs @@ -265,6 +265,38 @@ mod decoded { Ok(()) } + /// The colours across the top row of the sixel that `sh -c` prints. + #[cfg(unix)] + fn top_row(sixel: &str) -> termlens::Result> { + let mut t = Terminal::builder() + .timeout(Duration::from_secs(30)) + .args(["-c", &format!(r"printf '{sixel}X'; sleep 5")]) + .spawn("sh")?; + t.wait_until(|s| s.contains("X"))?; + let payload = t.screen().graphics().last().cloned().expect("a sixel"); + let bitmap = payload.decode().expect("it decodes"); + Ok((0..bitmap.width()) + .map(|x| bitmap.pixel(x, 0).unwrap()) + .collect()) + } + + /// xterm draws every pixel through the colour registers as the image + /// leaves them, so a register redefined after painting repaints what it + /// painted, and the background fill from register 0 matches the pixels + /// painted with it (#842). + #[cfg(unix)] + #[test] + fn a_register_draws_in_the_colour_it_ends_with() -> termlens::Result<()> { + let (green, blue) = ([0, 255, 0, 255], [0, 0, 255, 255]); + // Register 1 paints three columns red, is redefined blue, and paints three more. + let redefined = top_row(r"\033P0;1q#1;2;100;0;0#1!3~#1;2;0;0;100!3~\033\\")?; + // Register 0 paints two columns red and is redefined green; P2 = 0 fills + // the other two columns of the 4x6 raster with it. + let background = top_row(r#"\033P0;0q"1;1;4;6#0;2;100;0;0#0!2~#0;2;0;100;0\033\\"#)?; + assert_eq!((redefined, background), (vec![blue; 6], vec![green; 4])); + Ok(()) + } + #[test] #[cfg_attr( windows, diff --git a/crates/termlens/tests/search.rs b/crates/termlens/tests/search.rs index 8d9afa43..a56d1fe7 100644 --- a/crates/termlens/tests/search.rs +++ b/crates/termlens/tests/search.rs @@ -380,6 +380,32 @@ mod patterns { Ok(()) } + /// A pattern is folded to NFC, as a needle is, so `regex::escape` of + /// decomposed text (the form macOS keeps file names in) matches the + /// same text on screen (#847). Only the row was folded, so `contains` + /// found it while `matches` did not, a wait on it timed out, and + /// `mask_matches` left the text it was given to redact. + #[test] + fn a_pattern_in_nfd_matches_what_a_needle_in_nfd_finds() -> termlens::Result<()> { + let mut t = emit(&["cafe\u{301} ok", "--wait"])?; + t.wait_until(|s| s.contains("ok"))?; + let s = t.screen(); + let name = "cafe\u{301}"; + let re = Regex::new(®ex::escape(name)).unwrap(); + assert_eq!(s.find(name), Some((0, 0)), "{s}"); + assert!(s.matches(&re), "{s}"); + assert_eq!(s.find_match(&re), Some((0, 0, "caf\u{e9}".to_owned()))); + assert_eq!( + s.mask_matches(&re, '#').row_text(0), + s.mask_matching(name, '#').row_text(0) + ); + assert_eq!(s.mask_matches(&re, '#').row_text(0).trim_end(), "#### ok"); + t.wait_until_matches_for(&re, Duration::from_millis(500))?; + t.send(Key::Enter)?; + assert!(t.wait_exit()?.success()); + Ok(()) + } + /// A volatile field — this process's id — masked by shape, then /// snapshotted: the snapshot is stable across runs because the mask /// keeps the width whatever the number was. diff --git a/docs/LIMITATIONS.md b/docs/LIMITATIONS.md index e47f5436..f8adfb86 100644 --- a/docs/LIMITATIONS.md +++ b/docs/LIMITATIONS.md @@ -149,7 +149,10 @@ CHANGELOG entry. redefines it, and only `P2 = 1` leaves it transparent. A sixel without raster attributes is filled nowhere, as in xterm, where Windows Terminal fills to the edge of the screen. A JSON screen saved by a release before - 0.11.11 did not record `P2`, and its sixels decode as `P2 = 0`. + 0.11.11 did not record `P2`, and its sixels decode as `P2 = 0`. Every + pixel, painted or filled, decodes in its register's colour as the data + leaves it, as xterm draws it: a register redefined after painting + recolours what it painted. - **The cursor moves past an image as the declared terminal moves it**, and only as far as the escape says. A `Graphics::Kitty` terminal moves it for a placement whose size in cells is known: from `c=` and `r=`, or @@ -353,7 +356,8 @@ CHANGELOG entry. - Exotic grapheme clusters render as the vt100 crate renders them; the unicode-torture fixture pins the current behaviour. - **Needle matching is NFC, then substring, not grapheme matching.** - `contains`, `find` and `mask_matching` fold both sides to NFC, which + `contains`, `find` and `mask_matching` fold both sides to NFC, as the + `regex` methods fold the row and the pattern (#847), which joins a base and a mark only where Unicode has a precomposed character (`e` + U+0301 is `é`, so `contains("e")` misses it). Any other mark — U+0353, Thai and Devanagari vowel signs — stays a character of its diff --git a/docs/RELEASING.md b/docs/RELEASING.md index ab71fcfa..79fd8aff 100644 --- a/docs/RELEASING.md +++ b/docs/RELEASING.md @@ -155,7 +155,12 @@ commit it lands on, as above. Pushing the tag runs `release.yml`, which: -1. fails unless tag == `crates/termlens` version, +1. fails unless tag == `crates/termlens` version, and unless + `CHANGELOG.md` has a non-empty section for it + (`.github/scripts/extract-changelog.sh`), so release notes that cannot + be built stop the release before anything is published (#857); the + release-notes selftest in CI already fails a pull request whose + workspace version has no section, 2. re-runs the full CI gates (`workflow_call` into ci.yml) — the semver gate among them, against the last published release with the release type forced (`.github/scripts/check-semver.sh`); a tag push has no diff --git a/skills/termlens/SKILL.md b/skills/termlens/SKILL.md index 199f0cab..759dcffd 100644 --- a/skills/termlens/SKILL.md +++ b/skills/termlens/SKILL.md @@ -161,7 +161,8 @@ your test ── send(Key) · click · paste · resize ──▶ PTY └─ 12. **The grid is Unicode-aware; think in cells.** A double-width character (CJK, most emoji) occupies two cells: the leading one `is_wide()`, the next `is_wide_continuation()`. `find` reports real terminal columns. - `contains` and `find` fold both sides to NFC and search the **visible + `contains`, `find` and the `regex` methods fold both sides to NFC + (a pattern too: give its flags inline, `(?i)`) and search the **visible screen only** — text that scrolled off is in `full_text()` (and `locate` says which region holds a needle), and a line that wrapped is two rows, so a needle spanning the wrap is found by `logical_text()`, diff --git a/tools/gates-listed-selftest/run.sh b/tools/gates-listed-selftest/run.sh index a01d0728..4d0f28c4 100755 --- a/tools/gates-listed-selftest/run.sh +++ b/tools/gates-listed-selftest/run.sh @@ -16,6 +16,14 @@ # multi-line blocks are the named plumbing. Dropping a listed line from a # copy of CONTRIBUTING.md must fail, as it always did. # +# §1 must also say what CI gives a gate (#858). Each of these passed, and +# tools/preflight.sh then ran a weaker gate than CI's: +# +# - `RUSTDOCFLAGS='-D warnings'` dropped from §1's `cargo doc` lines +# - §1's MSRV checks on `+1.70`, or on no toolchain at all, where CI runs +# them under RUSTUP_TOOLCHAIN set to Cargo.toml's rust-version +# - a gate CI no longer runs, still listed in §1 +# # Usage: tools/gates-listed-selftest/run.sh set -euo pipefail @@ -85,6 +93,20 @@ expect "§7 naming a job required-green does not need fails" nonzero "$scratch/c sed 's/`commit-policy` (DCO/`commit-policy` and `nightly` (DCO/' "$doc" > "$scratch/CONTRIBUTING.md" expect "a name after commit-policy in §7 is not a job" zero "$ci" "$scratch/CONTRIBUTING.md" +# What CI gives a step is part of the gate (#858). +sed "s/^RUSTDOCFLAGS='-D warnings' cargo doc/cargo doc/" "$doc" > "$scratch/CONTRIBUTING.md" +expect "§1's cargo doc without RUSTDOCFLAGS fails" nonzero "$ci" "$scratch/CONTRIBUTING.md" +sed 's/^cargo +1\.85 check/cargo +1.70 check/' "$doc" > "$scratch/CONTRIBUTING.md" +expect "§1's MSRV checks on another toolchain fail" nonzero "$ci" "$scratch/CONTRIBUTING.md" +sed 's/^cargo +1\.85 check/cargo check/' "$doc" > "$scratch/CONTRIBUTING.md" +expect "§1's MSRV checks on no toolchain fail" nonzero "$ci" "$scratch/CONTRIBUTING.md" +with_step "a listed gate under a toolchain §1 does not name fails" nonzero \ + '- run: cargo fmt --all --check' ' env:' ' RUSTUP_TOOLCHAIN: nightly' +with_step "a listed gate with RUSTDOCFLAGS on the step passes" zero \ + '- run: cargo doc --no-deps' ' env:' " RUSTDOCFLAGS: '-D warnings'" +grep -Fv 'run: .github/scripts/check-unsafe-blocks.sh' "$ci" > "$scratch/ci.yml" +expect "a gate §1 lists and CI no longer runs fails" nonzero "$scratch/ci.yml" "$doc" + expect "this repository's ci.yml and CONTRIBUTING.md pass" zero "$ci" "$doc" if [ "$status" -eq 0 ]; then diff --git a/tools/preflight.sh b/tools/preflight.sh index c274918a..ce24eb4b 100755 --- a/tools/preflight.sh +++ b/tools/preflight.sh @@ -15,7 +15,7 @@ # for the reader, not gates, and are skipped below. # # A gate whose optional tooling is not installed is skipped by name, never -# failed: cargo-deny, cargo-semver-checks, pipx, the 1.85 toolchain, the +# failed: cargo-deny, cargo-semver-checks, pipx, the MSRV toolchain, the # Windows and illumos targets. `--fast` runs only the fmt, clippy and test gates, by # matching the documented command, so a fmt/clippy/test line added to §1 is # picked up without touching this script. @@ -76,9 +76,14 @@ skip_reason() { return 0 } ;; - "cargo +1.85 "*) - rustup_toolchain_has 1.85 || { - echo "toolchain 1.85 is not installed (rustup toolchain install 1.85)" + # Whatever toolchain §1 names, which gates-listed holds to Cargo.toml's + # rust-version (#858): a literal 1.85 here would have run the checks + # unguarded once an MSRV bump moved §1 on. + "cargo +"*) + tc="${1#cargo +}" + tc="${tc%% *}" + rustup_toolchain_has "$tc" || { + echo "toolchain $tc is not installed (rustup toolchain install $tc)" return 0 } ;; diff --git a/tools/release-notes-selftest/run.sh b/tools/release-notes-selftest/run.sh index 01f62d54..b409e673 100755 --- a/tools/release-notes-selftest/run.sh +++ b/tools/release-notes-selftest/run.sh @@ -35,6 +35,13 @@ # is a definition (#717). Such a line vanished from its notes and stood # in for the real definition in every other section's # +# The workspace version's section must exist and not be empty (#857): +# release.yml extracts it for the GitHub Release only after publishing both +# crates, so a release PR that bumped the version without moving +# [Unreleased] published and then failed. Checking it here turns that PR +# red; a fixture Cargo.toml at a version without a section, or with an +# empty one, must fail. +# # and then every section of the real CHANGELOG.md, both ways: the # definitions in its notes are exactly the ones its text names outside code, # out of those the file defines. That is computed here in Python, by @@ -315,6 +322,39 @@ expect "an empty [Unreleased] prints nothing" Unreleased zero "$scratch/empty.md expect "an empty numbered section fails" 0.0.1 nonzero expect "a missing section fails" 9.9.9 nonzero +# `workspace_section `: extract the section for +# the version in [workspace.package], as release.yml will for its tag. +workspace_section() { + ver="$(sed -n 's/^version *= *"\(.*\)"/\1/p' "$1" | head -1)" + [ -n "$ver" ] || { echo "no version in $1"; return 1; } + "$extract" "$ver" "$2" > /dev/null +} +# `section_case