Skip to content

test(growth): count the work of three linear-scan tests instead of timing it (#1454) - #1502

Merged
antonwolfy merged 1 commit into
intel:mainfrom
antonwolfy:test/count-linear-scan-work
Dec 1, 2026
Merged

antonwolfy merged 1 commit into
intel:mainfrom
antonwolfy:test/count-linear-scan-work

Conversation

@antonwolfy

Copy link
Copy Markdown
Contributor

Summary

#1454 asks to count the work of the linear-scan tests that bound a CPU-time ratio (tests.growth_timing.growth, GROWTH_LIMIT 8), the form that failed on a busy runner in #1071 and #1235 (assert 8.296 < 8, assert 67.6 < 64), where tests/work_count.py can see the scan. On main after #1455, git grep -n 'growth(' dokimi/tests lists 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 the old bound what is counted now a quadratic form counts
test_repo_environment.py::test_npm_hook_of_many_options_is_linear ratio of inspect_repo over 1250 and 20000 -npm options < 8 the words risks._subcommand is handed 255.4 (a rescan of the options per option)
test_repo_environment.py::test_unclosed_heredocs_are_linear ratio of risks._segments over 2500 and 40000 unclosed heredoc starts < 8 the characters risks._HEREDOC_START is handed 280.4 (a search per start)
test_context_prefilter_shell.py::test_the_heredoc_scan_takes_linear_time_in_the_lines_with_a_heredoc_sign ratio of _without_heredoc_bodies over 375 and 6000 lines < 8 the characters prefilter._heredoc_words is handed (the line and the continued lines before it) 254.2 (the lines before it kept for every line)

Linear work counts 16 against WORK_LIMIT 24. No flake of these three was reproduced here: the old tests pass on main at normal load, so the change removes the exposure rather than a failure I could show. The other sites keep growth, each for a reason read in the code:

  • one regex call, which a count cannot see: test_repo_environment.py (the network-exec script pattern, the setup.cfg/build.gradle/pom.xml readers, the Makefile rules, the rm/git clean/tsc/pom patterns);
  • one library call, shlex, inside a line over the cap: test_unbalanced_quote_in_hook_completes_quickly (the _tokens cap is already counted by test_an_overlong_quoted_line_is_never_handed_to_shlex);
  • a loop in a method with no module-level call to wrap: test_heredoc_scopes.py (_ArithmeticReader._closes builds its parenthesis pairs with re.finditer once), test_context_prefilter_arithmetic.py (_blank_arithmetic is str.find in one function), test_repo_budget.py (_strip_code_spans indexes lists built from three regex passes), and the call-chain case of test_repo_events_bash.py (the mover walk in shell_functions.define is local sets; its unclosed-definitions case is the input test_each_function_body_is_read_once_however_many_are_unclosed counts already).

test_blank_inline.py and test_context_shell.py are left to #1499, because open PRs #1439 and #1450 change them. The single-regex files the issue lists, and every other growth( 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_linear counts risks._subcommand and keeps the check of the hook capability note; test_unclosed_heredocs_are_linear counts risks._HEREDOC_START over risks._segments. The imports gain risks and tests.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_sign counts prefilter._heredoc_words and keeps the check that the kept text ends with cat <<EOF\nmake ci-local.
  • No change under dokimi/dokimi/, to tests/work_count.py or to tests/growth_timing.py. dokimi/docs/ does not name work_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_linear counts the same input as the first assertion of test_heredoc_starts_are_scanned_once_whatever_their_number in test_repo_environment_work.py.

Testing

On Linux, at 8b2f431e (on main bac7f7ec):

  • 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-latest and test-seeds, the conda-forge job, the Atheris fuzz, the intel-ci matrix jobs, the semgrep org check). 32113 tests passed, 27 skipped.
  • Mutants, each run on a copy of the committed tree: a rescan of the options per option fails test_npm_hook_of_many_options_is_linear with 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 fails test_unclosed_heredocs_are_linear with 280.4; keeping every earlier line in prior fails 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 to hooks at fails the note check, and one that no longer drops the heredoc body fails the endswith check.
  • The old timed tests on 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 failed each), 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.
  • The converted tests pass here with check_test_narrowing.py, check_test_timing.py, check_comment_blocks.py and check_duplicates.py.
  • Not run: the other Python versions (3.11, 3.12, 3.14), and CI's merge commit.

Open questions

None.

Revert

A plain revert restores the three timed tests. Nothing is stored.

Checklist

  • Tests added/updated and pytest passes
  • ruff, mypy, and schema checks pass
  • Docs updated (or N/A) — see the docs-drift checklist in CONTRIBUTING.md
  • Self-reviewed per "Before opening a PR" in AGENTS.md
  • Each new raise/exit and test names the doc, contract or issue it traces to
  • No ad-hoc run artifacts committed
  • New files carry the SPDX license header (or are exempt in .github/.licenserc.yaml)

…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>

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.

🟢 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

@exai-bot

exai-bot commented Dec 1, 2026 •

Copy link
Copy Markdown

✅ OpenCodeReview: Review complete: 0 finding(s) across 2 selected item(s).

CI at 8b2f431: 19 passing, 3 skipped.

Review details
  • Commit reviewed: 8b2f431 against merge base bac7f7e
  • Coverage: 2 files in 1 groups
  • Engine: OpenCodeReview v1.13.5-exai.4.8f73eada, us.openai.gpt-6.1-sol
  • Usage: 49k tokens (27k from cache), 7s
  • Tool calls: 9 (6 file_read, 2 code_search, 1 ci_status)
  • small change set: 2 files

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.30%. Comparing base (bac7f7e) to head (8b2f431).
⚠️ Report is 1 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

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     

see 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@napetrov napetrov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@antonwolfy
antonwolfy merged commit 17b9234 into intel:main Dec 1, 2026
22 checks passed
@antonwolfy
antonwolfy deleted the test/count-linear-scan-work branch December 1, 2026 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky-by-construction: timed linear-scan tests that could count the work instead

5 participants