Repository navigation
test(growth): count the work of three linear-scan tests instead of timing it (#1454) - #1502
Conversation
…ming it (intel#1454) test_npm_hook_of_many_options_is_linear, test_unclosed_heredocs_are_linear and test_the_heredoc_scan_takes_linear_time_in_the_lines_with_a_heredoc_sign bounded a CPU-time ratio at GROWTH_LIMIT, the form that failed on a busy runner in intel#1071 and intel#1235. Each now counts the work with tests/work_count.py: the words `_subcommand` is handed per hook command, the characters the `_HEREDOC_START` scan reads over unclosed heredocs, and the characters `_heredoc_words` is handed (a line and the continued lines before it) per line. Each must grow less than WORK_LIMIT for 16x the input, where a re-scan per option, start or line counts 256. The results the old tests checked stay (the hook capability note, the kept text after the heredoc body). The other `growth(` sites of tests/test_repo_environment.py, test_heredoc_scopes.py, test_repo_budget.py, test_repo_events_bash.py and test_context_prefilter_arithmetic.py stay timed: each scans in one regex or library call, or in a loop with no module-level call to wrap, which a count cannot see. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues require changes.
No open issues 🎉
What changed in this PR
0 new findings; nothing to fix.
This tests-only PR addresses #1454 by replacing CPU-time ratios in three linear-scan tests with deterministic work counts, reducing exposure to runner-load fluctuations without changing production code.
Changes:
- Count words processed by the npm hook parser and characters scanned for unclosed heredocs.
- Count characters passed to the shell prefilter’s heredoc scanner while preserving existing output assertions.
- Leave other timing-based tests unchanged, with follow-up work tracked separately.
| File | Description |
|---|---|
dokimi/tests/test_repo_environment.py |
Converts npm-option and unclosed-heredoc growth tests to work counts. |
dokimi/tests/test_context_prefilter_shell.py |
Converts heredoc-scan growth testing to character counts and shares counting imports. |
Review effort: Balanced
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 2 selected item(s). CI at Review details
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1502 +/- ##
==========================================
- Coverage 96.31% 96.30% -0.02%
==========================================
Files 515 515
Lines 68952 68952
Branches 11936 11936
==========================================
- Hits 66413 66401 -12
- Misses 1564 1568 +4
- Partials 975 983 +8 🚀 New features to boost your workflow:
|
napetrov
left a comment
There was a problem hiding this comment.
Change class: LOCAL (head 8b2f431)
- Contract: none
- Responsibility: none
- Dependency: none
- Review depth: skim: local change, check diff + tests
- Coverage gaps: none
Checked all three counter targets against their implementations, the 16× scaling and the result assertions. The counters cover input passed to those functions and patterns. CI passed; I did not rerun the timing workloads locally.
Summary
#1454 asks to count the work of the linear-scan tests that bound a CPU-time ratio (
tests.growth_timing.growth,GROWTH_LIMIT8), the form that failed on a busy runner in #1071 and #1235 (assert 8.296 < 8,assert 67.6 < 64), wheretests/work_count.pycan see the scan. Onmainafter #1455,git grep -n 'growth(' dokimi/testslists 30 files (the issue says 29). I read each site and the function it calls. Three scan in a Python loop over a module-level function or pattern that a count can wrap, and are converted here:test_repo_environment.py::test_npm_hook_of_many_options_is_linearinspect_repoover 1250 and 20000-npmoptions < 8risks._subcommandis handedtest_repo_environment.py::test_unclosed_heredocs_are_linearrisks._segmentsover 2500 and 40000 unclosed heredoc starts < 8risks._HEREDOC_STARTis handedtest_context_prefilter_shell.py::test_the_heredoc_scan_takes_linear_time_in_the_lines_with_a_heredoc_sign_without_heredoc_bodiesover 375 and 6000 lines < 8prefilter._heredoc_wordsis handed (the line and the continued lines before it)Linear work counts 16 against
WORK_LIMIT24. No flake of these three was reproduced here: the old tests pass onmainat normal load, so the change removes the exposure rather than a failure I could show. The other sites keepgrowth, each for a reason read in the code:test_repo_environment.py(thenetwork-execscript pattern, thesetup.cfg/build.gradle/pom.xmlreaders, the Makefile rules, therm/git clean/tsc/pompatterns);shlex, inside a line over the cap:test_unbalanced_quote_in_hook_completes_quickly(the_tokenscap is already counted bytest_an_overlong_quoted_line_is_never_handed_to_shlex);test_heredoc_scopes.py(_ArithmeticReader._closesbuilds its parenthesis pairs withre.finditeronce),test_context_prefilter_arithmetic.py(_blank_arithmeticisstr.findin one function),test_repo_budget.py(_strip_code_spansindexes lists built from three regex passes), and the call-chain case oftest_repo_events_bash.py(the mover walk inshell_functions.defineis local sets; its unclosed-definitions case is the inputtest_each_function_body_is_read_once_however_many_are_unclosedcounts already).test_blank_inline.pyandtest_context_shell.pyare left to #1499, because open PRs #1439 and #1450 change them. The single-regex files the issue lists, and every othergrowth(site I read, are in #1500; the sites there that a count can see are in #1501. This closes #1454 because each site it names that stays timed has one of those follow-ups.Closes #1454
Changes
tests/test_repo_environment.py:test_npm_hook_of_many_options_is_linearcountsrisks._subcommandand keeps the check of the hook capability note;test_unclosed_heredocs_are_linearcountsrisks._HEREDOC_STARToverrisks._segments. The imports gainrisksandtests.work_count; the file stays at its 1271-line baseline.tests/test_context_prefilter_shell.py:test_the_heredoc_scan_takes_linear_time_in_the_lines_with_a_heredoc_signcountsprefilter._heredoc_wordsand keeps the check that the kept text ends withcat <<EOF\nmake ci-local.dokimi/dokimi/, totests/work_count.pyor totests/growth_timing.py.dokimi/docs/does not namework_count, so no doc changes. No changelog fragment: tests only.Risk
None for users: tests only. The three tests no longer use time, so they cannot fail on a busy runner; they count what the code is handed, so a change of the code that hands those functions a different size (for example the open PRs #1328, #1443 and #1446, which change
risks.py) moves the counts by a constant, not by the factor of 16 the bound allows 1.5x for.test_unclosed_heredocs_are_linearcounts the same input as the first assertion oftest_heredoc_starts_are_scanned_once_whatever_their_numberintest_repo_environment_work.py.Testing
On Linux, at
8b2f431e(onmainbac7f7ec):make ci-local: 0 failed, 38 passed, 16 skipped (the catalog smoke that needs docker and network, the mutation-diff and cli-surface PR-comment packaging,test-latestandtest-seeds, theconda-forgejob, the Atheris fuzz, theintel-cimatrix jobs, the semgrep org check). 32113 tests passed, 27 skipped.test_npm_hook_of_many_options_is_linearwith 255.4 against 24 (run at 400 and 6400 options, since the quadratic form at the test's own size takes minutes); a search per heredoc start failstest_unclosed_heredocs_are_linearwith 280.4; keeping every earlier line inpriorfails the prefilter test with 254.2. The npm and prefilter counts are a constant under 256 (the command word, the heredoc tail). A copy that renames the capability note tohooks atfails the note check, and one that no longer drops the heredoc body fails theendswithcheck.main: all pass at normal load. With the quadratic form of the first two applied they fail only by pytest's 60 s timeout (1 failedeach), not by the ratio. With the third's quadratic form applied, the old timed prefilter test still passes (1 passed), where the converted test counts 254.2. I found no load that fails an old test unmutated, so the original flake is not reproduced.check_test_narrowing.py,check_test_timing.py,check_comment_blocks.pyandcheck_duplicates.py.Open questions
None.
Revert
A plain revert restores the three timed tests. Nothing is stored.
Checklist
pytestpassesruff,mypy, and schema checks passAGENTS.mdraise/exit and test names the doc, contract or issue it traces to.github/.licenserc.yaml)