Skip to content

test(highlight): keep the long-string fixture below the lexer timeout - #340

Merged
umputun merged 1 commit into
masterfrom
highlight-test-timing
Aug 28, 2026
Merged

test(highlight): keep the long-string fixture below the lexer timeout#340
umputun merged 1 commit into
masterfrom
highlight-test-timing

Conversation

@umputun

@umputun umputun commented Aug 28, 2026

Copy link
Copy Markdown
Owner

TestHighlighter_LongQuotedStringUsesStringColor is flaky on CI. It failed on one run of #338 and passed on a second run of the same commit.

cause: chroma sets a fixed 250ms MatchTimeout on every lexer rule, which app/highlight/highlight.go already documents as a ceiling the backtracking cap cannot lift. The test matched a 40,000-character string against it, so it was really asserting that the machine finishes that match inside 250ms. Measured here: 7.4ms plain but 147.6ms under -race, which is how CI runs it. That is 1.7x headroom on hardware faster than a GitHub runner. When it goes over, the string rule loses and the body is repainted by whichever rule matches next, which is the wrong colour in the failure log.

fix: 20,000 characters instead of 40,000. Sweeping sizes with the cap reverted to the pre-fix 100,000 shows 15,000 still passing and 17,000 already failing, which matches the slot arithmetic in that same comment, so 20,000 is comfortably above the old cap and still fails without the fix. It costs about 78ms under -race, roughly 3x headroom instead of 1.7x.

the input is smaller, the test is not weaker: reverting the cap to 100,000 in a scratch tree makes the 20,000 case fail by receiving chroma.Error, so it pins the same regression it always did. The comment now records both facts, the regression it catches and why the number cannot be raised back.

keep the input above regexp2's old backtracking cap while leaving
headroom below Chroma's fixed 250ms rule timeout under the race
detector.
Copilot AI lite review requested due to automatic review settings August 28, 2026 19:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@umputun
umputun merged commit e3eb732 into master Aug 28, 2026
5 checks passed
@umputun
umputun deleted the highlight-test-timing branch August 28, 2026 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants