Repository navigation
docs(tests): warn that a styled inline snapshot bakes a feature into it - #3920
Conversation
`tests/CLAUDE.md` directs a test checking formatted output to an inline snapshot without noting that a snapshot of styled output also pins `syntax-highlighting`, a default feature. Following the rule on highlighted output in #3908 merged green and took `main`'s nightly `feature-powerset` job red, since that job is the only one running the combination without the feature and it is skipped on a src/-only PR. Add the caveat to the section that gave the instruction, with the per-configuration shape #3916 uses, plus the `nightly` label knob for verifying such a fix on its own PR.
worktrunk-bot
left a comment
There was a problem hiding this comment.
Two factual errors in the added text, both in the part that carries the explanation's weight.
feature-powerset is not the only job that runs that combination. ci.yaml's feature-check job (step "Binary builds without syntax-highlighting") runs cargo check --bin wt --no-default-features --features cli on every PR, unconditionally. The reason it doesn't catch a feature-dependent snapshot is that cargo check never compiles #[cfg(test)] code — which is exactly the distinction nightly.yaml's own job comment draws ("the check step strips dev-deps, so #[cfg(test)] code is invisible to it"), and which the PR body quotes. As written, an author who greps the workflows finds a green feature-check on the precise combination the doc says nothing runs, and concludes either that the doc is wrong or that their snapshot is already covered. Fixing this costs a clause and makes the section's claim survive a grep.
cargo insta test --accept cannot fill both arms. Under any one feature configuration only one arm of the #[cfg] pair compiles, so a single --accept fills that arm and leaves the other sitting at @"". Filling the pair takes two runs — cargo insta test --accept, then the same command with --no-default-features --features cli --bin wt (I checked: cargo insta test forwards --no-default-features, -F/--features, and --bin). The repro line offers cargo test …, which surfaces the failure but doesn't fill anything. Someone following this section literally ends up with a half-filled pair and reproduces the exact nightly red the section exists to prevent, which makes this the more consequential of the two.
Otherwise the claims check out: default = ["cli", "syntax-highlighting"], the nightly gate really does OR the label against the Cargo/toolchain paths filter, md_help is a module of the wt bin so --bin wt is the right target, and "colour" matches existing spelling in src/.
feature-check does run --no-default-features --features cli on every PR; what lets a styled snapshot through is cargo check not compiling #[cfg(test)] code. And one --accept fills only the arm that compiles, so the pair needs two runs.
tests/CLAUDE.mdtells a test that checks formatted output to use an inline snapshot, and says nothing about the fact that a snapshot of styled output also bakes thesyntax-highlightingfeature into the expectation. Following that rule on highlighted output is what tookmain's nightly red overnight: #3908's second commit converted threecontainschecks onrender_markdown_in_helpto inline snapshots, one of them covering a trailingconsoleblock, merged green, andfeature-powersetfailed on the next cron (run 32935569443). This adds the caveat to the section that gave the instruction, with the per-configuration shape #3916 uses to fix that test. Docs only —pre-commit run --files tests/CLAUDE.mdpasses.Why here, and the full chain
The chain
fix(help): treat an HTML comment inside a code block as content, test asserted with threecontainscallstests/CLAUDE.md→ Inline snapshots over multi-assert and pushes8a141861a, converting them to inline snapshots. One captures the trailingconsolefence's rendering, which undersyntax-highlightingisESC[2mESC[0mESC[2mESC[34mwtESC[0mnightlycron one4238e83:feature-powersetred —test md_help::tests::test_html_comment_inside_a_code_block_is_content ... FAILEDThe self-review's reasoning was right on its own terms — the
containsversion proves the comment line survived but says nothing about how it renders, which is what #3908 decides. What it missed is the axis on which "how it renders" is not a constant.Why the required checks can't catch it
syntax-highlightingis a default feature, sotest (linux|macos|windows),fast-checksandcode-coverageall build with it on.ci'sfeature-checkjob doescargo check --bin wt --no-default-features --features clion every PR, butcargo checknever compiles#[cfg(test)]code, so the snapshot is never built there. The only job that runs the tests on that combination isfeature-powersetinnightly, andnightly's gate runs on a PR only when the diff touches Cargo/toolchain/nix paths or the PR carries thenightlylabel — so asrc/-only PR never sees it. The red is structurally deferred to the next cron onmain, i.e. after the merge.nightly.yaml's own job comment already names the failure mode — "a snapshot baking feature-dependent output, only surfaces when tests are built and run per combo" — but that text is in the workflow, not in the file an author of a unit test reads.Why the caveat and not a gate
Gating the whole assertion on
#[cfg(feature = "syntax-highlighting")]would compile the test out of the one combination that catches this class of bug. The pair form keeps the assertion on both sides and is what the repo already does elsewhere (src/styling/format.rsuses#[cfg(all(test, feature = "syntax-highlighting"))]for a module whose subject is the highlighting; here the colouring is incidental, so the test stays and only the expectation splits).The last paragraph — apply the
nightlylabel to a PR fixing afeature-powersetfailure — is the other half of the same incident: #3916's ownfeature-powersetwas skipped until the label went on at 06:32Z, after which it ran green on2b734bb8. Nightly's header comment calls the label "the iteration knob for fixes targeting nightly-only failures"; nothing undertests/said so.Gate assessment
mainred. 1 occurrence, no prior sighting of this shape in the tracking log (#3691). Blast radius was small and it was self-caught within hours, which is why the proposed change is two paragraphs rather than a process.nightly.yamlandCargo.toml, neither of which a unit-test author has reason to open.