Skip to content

test: the near-duplicate scale test counts pairs, and the code-span growth test times longer calls (#916, #947) - #951

Merged
antonwolfy merged 3 commits into
intel:mainfrom
antonwolfy:test/growth-bounds
Nov 19, 2026
Merged

antonwolfy merged 3 commits into
intel:mainfrom
antonwolfy:test/growth-bounds

Conversation

@antonwolfy

Copy link
Copy Markdown
Contributor

Summary

Two tests bounded work by something a slow runner changes.

Issue On main today
#916 test_scale_of_5000_skills_is_a_few_seconds times _near_duplicates over 5000 skills with time.perf_counter() and asserts elapsed < 10.0, so a stalled runner fails it with no change in the code: with time.perf_counter jumping 11 s between its two reads, the old body fails assert 11.0 < 10.0. The fix the issue suggests, a CPU-time ratio under GROWTH_LIMIT from 1250 to 5000 skills, does not hold: over 12 runs the ratio is 9.04 to 9.58 (limit 8). The prefix filter keeps the pass from comparing every pair, but it is not linear: it reaches the Jaccard check for 18166 pairs at 1250 skills and 283510 at 5000, about 2.3% of all pairs at both sizes, so the count grows 15.6x for 4x the skills.
#947 test_code_span_stripping_is_linear_on_backtick_runs failed once on CI with a ratio of 8.7 against 8. It does not fail here: about 7,000 ratios at n=1000, idle and with up to 64 parallel runs on 8 cores, are 3.0 to 3.6 for a run of backticks and 3.9 to 4.5 for the other two shapes. The cause on CI is not known. The shortest sample, a run of 1000 backticks, is a call of about 10 µs, a few steps of the clock, which is the most likely place for noise to move a ratio.

For #916 the test now counts the pairs that reach _jaccard on the 5000-skill corpus (a count does not change on a slow runner) and asserts fewer than 5% of all pairs, and that the near-copies are still found. The issue's other option, the absolute bound in time.process_time(), is not taken: it still pins an absolute number to the runner's speed. A pass over every pair compares 11,226,932 pairs (90%), so the bound has a margin of 2x over what the filter does today and 18x under brute force.

For #947 the test grows from n=5000 instead of 1000, so the shortest call lasts 50 µs and the others about 2 ms, and takes the best of 15 samples instead of 5 (reps=15). The limit stays 8. Counting work instead of time is not possible here: _strip_code_spans is linear in Python, but the regex backtracking it replaced runs inside the regex engine, where no count sees it. As the cause is not reproduced, this is a hardening; it is not shown to remove the flake.

The pass is still quadratic in the pairs it compares, only with a constant of about 1/43. That is tracked in #950.

Closes #916

Closes #947

Changes

  • tests/test_near_duplicate_blocking.py: test_scale_of_5000_skills_is_a_few_seconds becomes test_the_pass_compares_few_of_the_pairs_of_5000_skills; it patches validate._jaccard to count calls, asserts under 5% of the pairs, and asserts findings exist. The time import and the timing print go. The dense-corpus equivalence tests are unchanged. The first commit carries a Test-narrowed: line, since the check reads a renamed test as removed. A second commit wraps the module docstring line the first one lengthened.
  • tests/test_repo_budget.py: test_code_span_stripping_is_linear_on_backtick_runs passes 5_000, reps=15 to growth(); the three behaviour asserts are unchanged.
  • No package code and no changelog fragment.

Risk

None for users: only tests change. A quadratic _strip_code_spans now takes minutes at n=5000, so it fails on the 60 s timeout in CI before it fails on the ratio (see Testing).

Testing

On Linux, at 04b47c18 (on main 2ab246c):

  • make ci-local: 36 passed, 0 failed, 14 skipped (steps that need a tool or runner this machine lacks, such as semgrep, micromamba, the Python 3.11, 3.12 and 3.14 legs, and the PR-only jobs). 23691 tests passed, 19 skipped.
  • test_scale_of_5000_skills_is_a_few_seconds bounds the near-duplicate pass by wall-clock time #916: with time.perf_counter jumping 11 s per read, the old test body on main fails (1 failed, assert 11.0 < 10.0); the new test under the same stalled perf_counter and process_time passes (1 passed). The CPU-time ratio the issue suggested would have been 9.04 to 9.58 over 12 runs, above the limit of 8. Mutant: _near_duplicates iterating every later skill instead of the candidates fails assert len(compared) < 0.05 * (5000 * 4999 // 2) with 11226932 compared.
  • Flaky on CI: tests/test_repo_budget.py::test_code_span_stripping_is_linear_on_backtick_runs #947: on main's code the test passed in every run, so there is no failing run to show. Simulation of a busy runner (extra CPU time added to growth() samples through its clock= argument; a simulation, not a reproduction): one hit on one sample leaves the ratio at about 4.1 for both the old call (n=1000, 5 reps) and the new one (n=5000, 15 reps), since the best sample discards it; when each 4n sample is hit with probability 0.6 and each n sample with 0.15, 16 of 150 trials of the old call and 1 of 150 of the new one reach a ratio of 8. Mutant: a _strip_code_spans that finds each run's closer with a scan of all later runs fails assert ratio < GROWTH_LIMIT with 16.5 when the timeout is off, and on the 60 s pytest-timeout under the default settings.
  • Merged together with test/ctrl-c-events on main 2ab246c: pytest -n auto 23691 passed, 19 skipped, mypy clean, ruff check clean.
  • Not run: the Python 3.11, 3.12 and 3.14 legs, the CI runner on which Flaky on CI: tests/test_repo_budget.py::test_code_span_stripping_is_linear_on_backtick_runs #947 failed.

Open questions

None.

Revert

A plain revert restores the two old 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)

…not seconds (intel#916)

test_scale_of_5000_skills_is_a_few_seconds timed _near_duplicates with time.perf_counter() and asserted under 10 s, so a stalled or busy runner could fail it with no change in the code.

A CPU-time ratio of growth() from 1250 to 5000 skills does not hold either: the pass takes 9.0 to 9.6 times as long at 5000 skills as at 1250 (limit 8), because the prefix filter cuts the pairs compared to about 2.3% of all pairs but does not make their number linear (18166 compared at 1250 skills, 283510 at 5000). The test now counts the pairs that reach the Jaccard check on the 5000-skill corpus and asserts fewer than 5% of all pairs (a brute-force pass compares about 90%), and that the near-copies are still found.

Test-narrowed: test_scale_of_5000_skills_is_a_few_seconds is replaced by test_the_pass_compares_few_of_the_pairs_of_5000_skills, which asserts the work of the same pass on the same corpus instead of the seconds it took, and that the near-copies are found
Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
… clock (intel#947)

test_code_span_stripping_is_linear_on_backtick_runs failed once on CI with a growth ratio of 8.7 against the limit of 8. It was not reproduced on Linux in about 7,000 ratios, idle or with 64 parallel runs on 8 cores (3.0 to 3.6 for the backtick run, 3.9 to 4.5 for the other two shapes). The shortest sample, a run of 1000 backticks, is a call of about 10 µs, a few steps of the clock, so one hiccup moves its ratio a long way.

The test now grows from 5000, so the shortest call lasts 50 µs and the others about 2 ms, and takes the best of 15 samples instead of 5. The limit is unchanged, and a quadratic scan still fails it.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
…'s line length (intel#916)

The docstring line the intel#916 commit edited was one 150-character line; it is wrapped at the file's usual width again, with the same words.

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 2 selected item(s).

CI at 04b47c1: 24 passing, 2 skipped.

Review details
  • Commit reviewed: 04b47c1 against merge base 2ab246c
  • Coverage: 2 files in 1 groups
  • Engine: OpenCodeReview v1.13.5-exai.4.8f73eada, us.openai.gpt-6.1-sol
  • Usage: 65k tokens (45k from cache), 10s
  • Tool calls: 7 (4 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 95.84%. Comparing base (2ab246c) to head (04b47c1).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #951   +/-   ##
=======================================
  Coverage   95.84%   95.84%           
=======================================
  Files         442      442           
  Lines       58843    58843           
  Branches    10148    10148           
=======================================
+ Hits        56397    56401    +4     
+ Misses       1521     1518    -3     
+ Partials      925      924    -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.

@vlad-perevezentsev vlad-perevezentsev 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.

LGTM

I checked 04b47c1. Both tests now measure something a slow runner does not change: the near-duplicate test counts _jaccard calls instead of seconds, and the code-span test times calls long enough for the clock.

Merge: safe now: it merges cleanly into current main, 1 commit behind. #958 also touches test_repo_budget.py but does not conflict with it.

What I ran, at 04b47c1:

  • make ci-local --offline: 0 failed, 25 passed, 20 skipped (network, matrix and other-platform jobs).

Checked, no issues

  • The count is real: _near_duplicates calls _jaccard by its module-global name (validate.py:647), so the monkeypatch sees every compared pair. An all-pairs pass would compare 100% and fail the 5% bound, and the findings assertion stops a pass that compares nothing from passing.
  • Growth timing: growth(..., 5_000, reps=15) matches the signature in tests/growth_timing.py; the ratio bound is unchanged.

@antonwolfy
antonwolfy merged commit ad5715f into intel:main Nov 19, 2026
26 checks passed
@antonwolfy
antonwolfy deleted the test/growth-bounds branch November 19, 2026 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants