test(fold): assert the duplicate-title fold behaviour instead of its spelling - #564
Merged
Conversation
…spelling
`foldKeys.test.ts` matched markdown.ts for `/h\.id = \w+\.id/` and
`removeAttribute("id")`. Both are claims about how the promotion is
written, not that it works, and the file already shipped with the two
failure modes that come with that:
* Extract the four lines into a `promoteAnchorId(h)` helper — same
behaviour, every existing test still passing — and the assertion goes
red. Measured, not argued.
* Nothing in it looked at whether the promoted ids stay unique, which
is the whole point of taking the id off the anchor.
`processMarkdownHtml` is an exported function in `.ts` and the suite
already has a DOM shim (`renderProtocolDom.ts`, used by
foldStatePerDocument and five others), so the behaviour can just be run.
The document under test now contains the collision the feature exists
for — two sections both titled "Setup" — and the check is that collapsing
the first leaves the second open. Keyed by text, as it was before the
promotion, `new Set(['setup'])` folds the whole document.
Deleting the promotion turns both new tests red. The helper-extraction
refactor above leaves them green.
One source-shape assertion is kept, and says why in place: the preview's
`foldableHeader.id || textContent` lives in a Svelte component this
runner cannot import, and the keying convention is a contract between
producer and consumers rather than an internal call site.
Also drops `findRefocus.test.ts` (#560, mine). It pinned
`findBar?.focusInput()` — an internal call, free to rename, and green if
the focus call stops working. By the criterion in the pull request
template it should not have been written.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This was referenced Aug 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this is
The first slice of converting source-shape assertions into behaviour tests, following #563. Two test files change; no source file does.
foldKeys.test.ts— rewritten to runprocessMarkdownHtmlinstead of matching markdown.ts with regexes.findRefocus.test.ts— deleted.Mechanism
The old file asserted
/h\.id = \w+\.id/andremoveAttribute("id")against markdown.ts. That is a claim about how the promotion is spelled, and it fails in both directions:Both rows were measured, not reasoned about. The refactor in the right-hand column is four lines moved into
function promoteAnchorId(h)aboveprocessMarkdownHtml; the whole suite stays green and the old assertion still goes red, because the text it was looking for moved.The old file also could not see the part that matters. It checked that an id gets assigned, never that the ids stay unique afterwards — which is the reason the anchor gives its own up rather than sharing it.
None of this needed new infrastructure.
processMarkdownHtmlis exported from.ts, andrenderProtocolDom.ts(the suite's DOM shim, already used byfoldStatePerDocument,exportRichContent,diagramCacheand three more) supplies the DOM it wants. The test document now contains the collision the feature exists for — two sections both titledSetup— and asserts that collapsing the first leaves the second open. Before the promotion, keyed bytextContent,new Set(['setup'])collapsed both.Scope
foldableHeader.id || foldableHeader.textContentlives in a Svelte component this runner cannot import, and it is a contract between the producer and its consumers rather than an internal call site.findRefocus.test.tscame in with fix(find): re-focus the preview find bar on a repeated Cmd/Ctrl+F #560 and was mine. It pinnedfindBar?.focusInput()— an internal call, free to rename, and green if the focus stops working. By the criterion docs: name the two kinds of test in scripts/, and ask which one a PR added #563 adds to the template it should not have been written; deleting it is cheaper than defending it.package.json/Cargo.toml, a duplicated implementation) and should stay as they are.Tests
The two behaviour tests are the fix check for themselves: delete the promotion block from
markdown.tsand both go red; restore it and they pass. Ran both directions.Verification
Not verified: nothing here reaches a browser, so the shim's fidelity to real
classList/querySelectorbehaviour is taken on the same trust the five existing shim-based test files already take it on.🤖 Generated with Claude Code