Skip to content

test(repo): scan tests bound CPU growth, not wall-clock time - #917

Merged
antonwolfy merged 1 commit into
intel:mainfrom
antonwolfy:test/scan-cpu-growth
Nov 18, 2026
Merged

antonwolfy merged 1 commit into
intel:mainfrom
antonwolfy:test/scan-cpu-growth

Conversation

@antonwolfy

Copy link
Copy Markdown
Contributor

Summary

Seventeen tests that run a scan or a regex on a pathological input asserted time.monotonic() - start < N or time.perf_counter() - start < N. A stalled or busy runner fails the bound with no change in the code under test: the failure #882 showed (7 s against a bound of 5), and the one #505 fixed for the heredoc parser with tests/growth_timing.py. Those tests now take the CPU-time ratio from n to 4n with growth(...) and assert ratio < GROWTH_LIMIT, as test_code_span_stripping_is_linear_on_backtick_runs does. The sixteen sites the issue lists (line numbers moved on main) are converted, plus the scope_pairs test in test_novelty_ground_symbols.py, which is the same kind of scan and is not on the issue's list.

File Tests converted
test_catalog_command_checks.py test_repeated_sudo_flags_before_a_missing_shell_do_not_backtrack, test_tab_separated_sudo_flags_before_a_missing_shell_do_not_backtrack, test_a_long_run_of_tab_dash_tokens_does_not_backtrack
test_catalog_no_frontmatter.py test_a_long_run_of_backticks_is_searched_in_linear_time
test_catalog_online.py test_a_long_line_with_hash_comments_and_no_install_is_read_in_linear_time
test_catalog_spec_checks.py test_allowed_tools_quotes_that_alternate_with_parens_are_read_in_linear_time
test_catalog_validate_scripts.py test_a_repeated_run_of_words_is_checked_in_linear_time, test_a_command_sub_in_quotes_repeated_unclosed_is_read_in_linear_time
test_context_prefilter_shell.py test_the_heredoc_scan_takes_linear_time_in_the_lines_with_a_heredoc_sign
test_repo_events_bash.py test_many_unclosed_definitions_or_a_long_call_chain_walk_in_linear_time
test_repo_l0.py test_a_branch_filter_with_many_stars_matches_in_linear_time
test_repo_l0_gitignore.py test_many_stars_do_not_backtrack
test_repo_security_rules.py test_an_execve_with_cut_strings_is_matched_in_linear_time, test_a_home_operator_with_no_closing_brace_is_matched_in_linear_time, test_git_global_options_are_matched_in_linear_time
test_task_format_detect.py test_a_flood_of_unclosed_field_specs_is_scanned_in_linear_time
test_novelty_ground_symbols.py test_a_long_answer_with_many_mentions_is_scanned_in_linear_time

Two wall-clock bounds of the same kind are not converted: test_near_duplicate_blocking.py:209 times the near-duplicate pass over a 5000-skill corpus with a fresh load per call, which is a scale benchmark and needs its own design; it is tracked in #916. The tests that wait for a child or a deadline, and the ones that bound a regex timeout guard, stay as the issue says.

Closes #889

Changes

  • Each listed test builds its input as a function of a size k and calls growth(lambda k: partial(fn, make_input(k)), n); the input shapes and every functional assertion (what the scan returns) are unchanged, and the time bound is ratio < GROWTH_LIMIT.
  • n is chosen per test. Where the broken scan was exponential or of high polynomial degree (the sudo flags, the -c flags of git, the cut strings of an execve line, the stars of a glob, the $( and << runs), 4n is at or below the old size so that a broken scan still ends in seconds and fails by its ratio, not by the pytest timeout. For the others, 4n is the old size.
  • test_a_repeated_run_of_words_is_checked_in_linear_time now parametrizes a shape function and an n (ids heredoc-tab, assignment-open, shopt-flags) instead of (run, count), because the third case grew the run, not the count. test_a_command_sub_in_quotes_repeated_unclosed_is_read_in_linear_time takes n of 4 and 750 in place of the counts 40 and 3000. The two shell_walk cases of test_repo_events_bash.py have ids unclosed-definitions and call-chain.
  • The FieldSpec flood is written to a file per size, so the call at n and the call at 4n do not read the same file.
  • No change under dokimi/dokimi/, so no changelog fragment.

Risk

None for users: only tests change. A test passes or fails on the growth of its own CPU time now, so a slow runner no longer fails it. Where the old bound was an absolute time, the new one cannot see a scan that is slow but linear. test_git_global_options_are_matched_in_linear_time is run at 8 and 32 repeats of -c; #688 tracks that the git -c scan is quadratic in the repeats, and that size does not show it. The change touches tests/test_repo_l0.py near line 600 and its imports; the open PR #898 changes lines 138-146 of the same file, so the hunks do not overlap.

Testing

On Linux, at 5615981 (on main d4023b9):

  • make ci-local: 36 passed, 0 failed, 14 skipped (the catalog smoke that needs docker and network, the pinned Claude Code install, the conda-forge, fuzz and semgrep steps, and the matrix and deploy jobs that need a runner). 23534 tests passed, 19 skipped; the diff has no source lines, so changed-line coverage has nothing to measure.
  • The old wall-clock tests on main, one file per pytest process pinned to one CPU that shares it with 60 busy loops (python -c 'while True: pass'): three bounds fail with assert <elapsed> < <bound>, 4.9 s against 2 in test_many_unclosed_definitions_or_a_long_call_chain_walk_in_linear_time (1 failed, 435 passed), 3.7 s against 1.0 in test_a_home_operator_with_no_closing_brace_is_matched_in_linear_time (1 failed, 65 passed) and 8.6 s against 5.0 in test_a_long_answer_with_many_mentions_is_scanned_in_linear_time (1 failed, 84 passed). The other nine files pass under it, as they did under 4 and 30 busy loops, where the first two fail with 30 and none with 4.
  • The same load against the converted tests at 5615981: all twelve files pass (97, 91, 123, 23, 174, 38, 436, 248, 29, 66, 75 and 85 tests, none failed), since the ratio counts CPU time, which the busy loops do not inflate.
  • Mutants: each converted test fails by its ratio (assert <ratio> < 8), not by the 60 s timeout. A restored backtracking pattern or an algorithm swapped back fails with ratios of 43 and 1852 (sudo flags, 24 and 32 tokens), 17074 (glob stars in gitignore), 8174 (branch filter matched by re), 29872 (execve cut strings), 15.5 (${HOME: operator with its value unbounded), 29999 (git -c flags that may be taken as the value) and 16.1 (FieldSpec( arguments [^)]* unbounded). For the scanners that are linear by construction, a per-position rescan of the input injected into the entry function fails with ratios of 10.0 to 15.4 (command_findings of command_checks.py, no_frontmatter_message, extract_packages, _unknown_tools, _shell_options, _without_heredoc_bodies, shell_walk, scope_pairs), and an injected exponential in _shell_options with 437 (<<! runs) and 28927 ("$( runs at n=4).
  • Not run: the matrix legs on Python 3.11, 3.12 and 3.14, and CI's merge commit.

Open questions

None.

Revert

A plain revert restores the wall-clock bounds. 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 raise or exit is added; the converted tests do not name Tests bound the CPU work of a scan by wall-clock time #889 themselves, the commit does]
  • No ad-hoc run artifacts committed
  • New files carry the SPDX license header (or are exempt in .github/.licenserc.yaml) [no new file]

Sixteen tests around pathological scan inputs (a run of backticks, unclosed openers, sudo flags, stars in a glob, a flood of FieldSpec( and others) asserted `time.monotonic() - start < N` or the perf_counter form. On a stalled or busy runner the wall clock passes the bound with no change in the code, the class of intel#882.

Each now takes `growth(lambda k: partial(fn, make_input(k)), n)` from `tests/growth_timing.py` and asserts `ratio < GROWTH_LIMIT`: the CPU-time ratio of the call at 4n to the call at n, about 4 for linear work and 16 or more for quadratic or exponential work. The input shapes and every functional assertion stay; the shape is now a function of the size k. Where the scan was exponential or of high polynomial degree when broken, n is small enough that the broken scan still ends in seconds at 4n.

The same conversion applies to the scope_pairs test in test_novelty_ground_symbols.py, which the issue did not list. Tests that wait for a child or bound a regex timeout guard keep their wall-clock bounds.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@exai-bot

exai-bot commented Nov 18, 2026 •

Copy link
Copy Markdown

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

CI at 5615981: 24 passing, 2 skipped.

Review details
  • Commit reviewed: 5615981 against merge base d4023b9
  • Coverage: 12 files in 5 groups
  • Engine: OpenCodeReview v1.13.5-exai.4.8f73eada, us.openai.gpt-6.1-sol
  • Usage: 288k tokens (198k from cache), 20s
  • Tool calls: 30 (20 file_read, 6 code_search, 2 ci_status, 2 local_check_results)
  • Catalog validation and checks: 5 files
  • Repository events, L0, and security rules: 4 files
  • Context shell prefiltering: 1 file
  • Novelty symbol grounding: 1 file
  • Task format detection: 1 file

@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 95.83%. Comparing base (d4023b9) to head (5615981).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #917      +/-   ##
==========================================
- Coverage   95.83%   95.83%   -0.01%     
==========================================
  Files         442      442              
  Lines       58788    58788              
  Branches    10146    10146              
==========================================
- Hits        56342    56340       -2     
- Misses       1521     1522       +1     
- Partials      925      926       +1     

see 1 file with indirect coverage changes

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

@vchamarthi vchamarthi 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.

🟢 Approved · reviewed 5615981

Next: nothing required from @antonwolfy.

Verified on 5615981: ✅ changed tests: 1481 passed, pass on main too · ✅ full suite with main merged in: 23545 passed · ✅ merges onto main

3 checks behind it, each with its evidence
Area What holds How
Changed tests The twelve changed test files pass on the head: 1481 passed, 4 skipped, 0 failed tests on the head
Whole ci The whole local CI passes with main merged in: 23545 passed, 0 failed, no step newly failing full suite, main merged in
Merge The PR merges onto current main with no conflict merge onto main

@antonwolfy
antonwolfy merged commit 96dc26c into intel:main Nov 18, 2026
26 checks passed
@antonwolfy
antonwolfy deleted the test/scan-cpu-growth branch November 18, 2026 20:45
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.

Tests bound the CPU work of a scan by wall-clock time

4 participants