From 8b2f431ee75612ec0c0719892f9762f752aaec6a Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Tue, 1 Dec 2026 13:59:08 +0000 Subject: [PATCH] test(growth): count the work of three linear-scan tests instead of timing it (#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 #1071 and #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 --- dokimi/tests/test_context_prefilter_shell.py | 16 +++++++--------- dokimi/tests/test_repo_environment.py | 20 ++++++++++---------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/dokimi/tests/test_context_prefilter_shell.py b/dokimi/tests/test_context_prefilter_shell.py index 7cd90f8870..0d7581e577 100644 --- a/dokimi/tests/test_context_prefilter_shell.py +++ b/dokimi/tests/test_context_prefilter_shell.py @@ -5,13 +5,12 @@ from __future__ import annotations -from functools import partial - import pytest +from dokimi.context import prefilter from dokimi.context.prefilter import _without_heredoc_bodies -from tests.growth_timing import GROWTH_LIMIT, growth from tests.test_context_prefilter import CI, _prompt, _report, _row, _session, _tool +from tests.work_count import WORK_LIMIT, count_calls, work_ratio def test_a_stop_word_only_rule_with_an_unmatchable_key_is_a_claim_that_is_not_measurable(): @@ -127,19 +126,18 @@ def test_a_quote_that_closes_on_a_later_line_hides_the_heredoc_sign_inside_it(): assert _row(_report([session]), CI)["acted"] == 1 -def test_the_heredoc_scan_takes_linear_time_in_the_lines_with_a_heredoc_sign(): +def test_the_heredoc_scan_takes_linear_time_in_the_lines_with_a_heredoc_sign(monkeypatch): + """The characters `_heredoc_words` reads (a line and the lines before it that a backslash continues) grow with the command: a re-scan per line was quadratic (counted, #1454).""" def command(k): return "\n".join([": <<< x"] * k + ["cat <