diff --git a/plugins/product-development/skills/product-development/scripts/open-questions.py b/plugins/product-development/skills/product-development/scripts/open-questions.py index 813d9ba..78493ec 100755 --- a/plugins/product-development/skills/product-development/scripts/open-questions.py +++ b/plugins/product-development/skills/product-development/scripts/open-questions.py @@ -321,10 +321,28 @@ def inline(match): def slug(heading): """A heading's anchor as GitHub generates it: from the rendered text, so link targets, HTML tags and emphasis markers drop out, while underscores - inside words stay.""" - text = re.sub(r"!?\[([^\]]*)\]\([^)]*\)", r"\1", heading.strip()) - text = re.sub(r"<[^>]+>", "", text) + inside words stay. A code span keeps its text as written.""" + + # Set each code span aside behind a placeholder, so the rules below see a + # link or emphasis that wraps code whole but never touch the code itself. + code = [] + + def hold(match): + code.append(match.group(2)) + return f"\x00{len(code) - 1}\x00" + + # An escaped backtick is text, not a code fence. A code span opens and + # closes with backtick runs of the same length. + text = heading.strip().replace("\\`", "\x01") + text = re.sub(r"(?", "", text) + # Only real tags: a letter or "/" right after "<", so a comparison such as + # "a < b and c > d" is text, not a tag. A tag goes whole, attributes and + # any backticks inside them included. + text = re.sub(r"]*)?/?>", "", text) text = re.sub(r"(?` and _care_/' "$B/roadmap.md" + sed -i.bak 's/roadmap.md#invitation-extension/roadmap.md#call-__init__-with-promiseresult-and-care/' "$B/open-questions.md" + rm "$B/roadmap.md.bak" "$B/open-questions.md.bak" + run "$OQ" index "$B" + [ "$status" -eq 0 ] || { echo "status $status: $output" >&2; return 1; } + run "$OQ" check "$B" + [ "$status" -eq 0 ] || { echo "status $status: $output" >&2; return 1; } + run "$OQ" blocking "$B" roadmap.md#call-__init__-with-promiseresult-and-care --level release + [ "$status" -eq 1 ] + [[ "$output" == *"open-questions.md#oq-2 release"* ]] +} + @test "a Blocks target naming a missing document fails the check" { sed -i.bak 's/| roadmap.md#invitation-extension |/| rollout-plan.md#invitation-extension |/' "$B/open-questions.md" rm "$B/open-questions.md.bak" @@ -978,3 +993,39 @@ expect_refused() { refute_grep -qF "skip features/FEATURE/" <<< "$text" done } + +@test "heading anchors match GitHub's for common heading shapes" { + run python3 -B - "$OQ" <<'PY' +import importlib.util, sys +spec = importlib.util.spec_from_file_location("oq", sys.argv[1]) +oq = importlib.util.module_from_spec(spec) +spec.loader.exec_module(oq) +cases = { + "Plain heading": "plain-heading", + "_em_ and __strong__": "em-and-strong", + "*em* and **strong**": "em-and-strong", + "[Docs](https://example.com)": "docs", + "snake_case": "snake_case", + "Enter": "enter", + "Call `__init__` with `Promise`": "call-__init__-with-promiseresult", + "``Promise``": "promiseresult", + "What if `count` < `min` or `count` > `max`?": "what-if-count--min-or-count--max", + "Keep a < b and c > d": "keep-a--b-and-c--d", + "A tagged word": "a-tagged-word", + "Run now": "run-now", + "Call _`run`_": "call-run", + "Call [`run`](guide.md)": "call-run", + "Step one": "step--one", + "Escaped \\`tick\\` stays": "escaped-tick-stays", + "Run ``a `b` c`` now": "run-a-b-c-now", + "Odd `a`` runs": "odd-a-runs", + "Use [`npm install`](https://example.com)": "use-npm-install", + "Use _the `cache` key_": "use-the-cache-key", + "Use __the `cache` key__": "use-the-cache-key", +} +bad = [(h, oq.slug(h), want) for h, want in cases.items() if oq.slug(h) != want] +print(bad) +sys.exit(1 if bad else 0) +PY + [ "$status" -eq 0 ] || { echo "$output" >&2; return 1; } +}