Repository navigation
test(markdown): bound the parser's searches by count, not by CPU time - #2393
Merged
Merged
Conversation
The elapsed CPU ratio occasionally crossed its bound under shared-runner load even after clock and sampling tuning. Count display-math indexOf searches directly, and bound inline closer work by the characters scanned while rejecting the old unbounded token regex. Fail-first restored the pre-optimization paths: display math failed at 3202 searches against a 3201 cap, and inline parsing attempted one forbidden unbounded search. The current parser passed 10/10 full markdown.test.ts runs, 48 tests each, plus bun run check fast. Co-authored-by: sisyphus-dev-ai <[email protected]>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 33 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Owner
Author
|
Merging b67a3ba. Test-only: src/lib/markdown.test.ts bounds the parser's worst-case searches by counting them instead of timing CPU, so a loaded runner cannot fail it. Diff read by the merge pass; no CodeRabbit review needed. |
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.
Found by the flake-hunt lane:
src/lib/markdown.test.ts"text no one wrote by hand > looks once for the end of a formula that never closes" and "... looks once for what closes a bracket, an inline formula or an underscore" failed in Fast checks twice in the 417 CI runs from 2026-10-28 03:26Z to 2026-10-29 18:22Z. Each time thelinear()CPU-time ratio came out just over its bound (30.7 and 33.7 against< 30), after #1974 and #2101 had already tuned the clock and the sampling. A rerun passed.Cause (test flake)
Both tests proved the parser linear by timing it: a small and a 10x input, comparing thread CPU time. CPU time still moves with load (allocation and GC on the test's own thread), so a linear parser could cross the bound on a busy runner. Raising the bound or taking more samples would make it rarer, not load-independent.
Change
The two tests now count the work they bound, instead of timing it. Their output assertions stay.
indexOf("\\]")search reads, from its start position to the match or the end, must stay within the text's length plus a few per line. One search per opener over the rest of the text is quadratic in characters, even when it makes no more calls.Both spies wrap the real
String.prototypemethods and are restored infinally. Other tests in the file still uselinear(); they are left as they are.Proof
\[line. The new check fails it, with 28791 characters read against a cap of 22404.bun run check fastok.Test-only.
Reviews
indexOfcalls, not characters. It now sums the span each search reads.