Repository navigation
test(repo): scan tests bound CPU growth, not wall-clock time - #917
Merged
Merged
Conversation
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>
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 12 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 #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 🚀 New features to boost your workflow:
|
vchamarthi
approved these changes
Nov 18, 2026
vchamarthi
left a comment
Contributor
There was a problem hiding this comment.
🟢 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 |
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.
Summary
Seventeen tests that run a scan or a regex on a pathological input asserted
time.monotonic() - start < Nortime.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 withtests/growth_timing.py. Those tests now take the CPU-time ratio from n to 4n withgrowth(...)and assertratio < GROWTH_LIMIT, astest_code_span_stripping_is_linear_on_backtick_runsdoes. The sixteen sites the issue lists (line numbers moved onmain) are converted, plus thescope_pairstest intest_novelty_ground_symbols.py, which is the same kind of scan and is not on the issue's list.test_catalog_command_checks.pytest_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_backtracktest_catalog_no_frontmatter.pytest_a_long_run_of_backticks_is_searched_in_linear_timetest_catalog_online.pytest_a_long_line_with_hash_comments_and_no_install_is_read_in_linear_timetest_catalog_spec_checks.pytest_allowed_tools_quotes_that_alternate_with_parens_are_read_in_linear_timetest_catalog_validate_scripts.pytest_a_repeated_run_of_words_is_checked_in_linear_time,test_a_command_sub_in_quotes_repeated_unclosed_is_read_in_linear_timetest_context_prefilter_shell.pytest_the_heredoc_scan_takes_linear_time_in_the_lines_with_a_heredoc_signtest_repo_events_bash.pytest_many_unclosed_definitions_or_a_long_call_chain_walk_in_linear_timetest_repo_l0.pytest_a_branch_filter_with_many_stars_matches_in_linear_timetest_repo_l0_gitignore.pytest_many_stars_do_not_backtracktest_repo_security_rules.pytest_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_timetest_task_format_detect.pytest_a_flood_of_unclosed_field_specs_is_scanned_in_linear_timetest_novelty_ground_symbols.pytest_a_long_answer_with_many_mentions_is_scanned_in_linear_timeTwo wall-clock bounds of the same kind are not converted:
test_near_duplicate_blocking.py:209times 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
kand callsgrowth(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 isratio < GROWTH_LIMIT.nis chosen per test. Where the broken scan was exponential or of high polynomial degree (the sudo flags, the-cflags ofgit, the cut strings of anexecveline, the stars of a glob, the$(and<<runs),4nis 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,4nis the old size.test_a_repeated_run_of_words_is_checked_in_linear_timenow parametrizes a shape function and ann(idsheredoc-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_timetakesnof 4 and 750 in place of the counts 40 and 3000. The twoshell_walkcases oftest_repo_events_bash.pyhave idsunclosed-definitionsandcall-chain.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_timeis run at 8 and 32 repeats of-c; #688 tracks that thegit -cscan is quadratic in the repeats, and that size does not show it. The change touchestests/test_repo_l0.pynear 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(onmaind4023b9):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.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 withassert <elapsed> < <bound>, 4.9 s against 2 intest_many_unclosed_definitions_or_a_long_call_chain_walk_in_linear_time(1 failed, 435 passed), 3.7 s against 1.0 intest_a_home_operator_with_no_closing_brace_is_matched_in_linear_time(1 failed, 65 passed) and 8.6 s against 5.0 intest_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.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.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 byre), 29872 (execvecut strings), 15.5 (${HOME:operator with its value unbounded), 29999 (git -cflags 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_findingsofcommand_checks.py,no_frontmatter_message,extract_packages,_unknown_tools,_shell_options,_without_heredoc_bodies,shell_walk,scope_pairs), and an injected exponential in_shell_optionswith 437 (<<!runs) and 28927 ("$(runs at n=4).Open questions
None.
Revert
A plain revert restores the wall-clock bounds. Nothing is stored.
Checklist
pytestpassesruff,mypy, and schema checks passAGENTS.mdraise/exit and test names the doc, contract or issue it traces to [noraiseor 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].github/.licenserc.yaml) [no new file]