Skip to content

perf(tests): stub babysit gh reads and run check-affected suites in parallel - #10534

Merged
kyle-sexton merged 2 commits into
mainfrom
perf/test-lane-waste
Oct 27, 2026
Merged

kyle-sexton merged 2 commits into
mainfrom
perf/test-lane-waste

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

No related issue: test-lane waste found by measurement in this session (real gh calls from unit tests, serial suites in check-affected --tests).

Summary

  • The babysit-prs engine tests spawned real gh processes against repos/owner/repo, spending the shared token budget and depending on the network. They now spawn none.
  • scripts/check-affected.sh --tests ran the selected shell suites one at a time. It now takes --jobs N and runs them through the existing run-plugin-tests.sh job pool.

Fix

Real gh calls. Measured by running the suite with a PATH shim gh that logs its argv and the running test, then exits 1, plus a socket-connect probe:

Test file Tests gh spawns before after
test_babysit_verify_evidence.py (LaneRequiresAVerdict, LocalBabysitReadsNoVerdict) 4 5 0
test_babysit_merge.py (RefreshRefusesDependencyManagerPrs) 1 1 0
socket connects, whole suite 0 0
  • The verify-evidence calls all came from the Unattended harness in test_babysit_merge_unattended.py: its policy._get fake fell back to whatever policy._get was when run_main patched it, which is the real reader unless the test patched it first, so a manifest's head contents read reached gh. The fallback still delegates to a test's own outer patch (TheQueueSweepIsSharedPerRun uses one), and raises AssertionError instead of calling the real reader, as the harness's gh_json fake already does. with_contents catches it, so those tests still read the manifest as unreadable and score HIGH exactly as before (the shim and the old real call both failed the read).
  • The refresh author-check test let validate_current_candidate go on to refuse_standards_sync, which called gh api repos/owner/repo/pulls/476. It now patches that step to raise, and asserts the run got past the author check.

No suite-wide guard: the engine runs unittest discover, which has no shared hook (no conftest, and tests/__init__.py is not imported as a package), and a mock-based guard inside the readers would be swallowed by their own broad except. The PATH-shim run is the check; adding it as a lane would be a new mechanism.

check-affected --jobs. --jobs N (default $CHECK_AFFECTED_JOBS, else nproc - 1; an invalid env value falls back to 1, as check-changed-skills.sh does) is passed to affected-tests.sh --jobs, which already hands N > 1 to run-plugin-tests.sh --suites-from. That pool keeps run-plugin-tests-serial.txt suites off the parallel group, so no new pool. --uncommitted forwards it. The pre-push hook runs check-affected without --tests, so pushes are unchanged.

Timing. The shell-suite leg --jobs changes, on a frozen selection: the 48 *.test.sh suites affected-tests.sh selects for b914f852f7..HEAD, gh shim first on PATH, 24-core WSL host with load average 9 to 14 from other sessions.

Jobs Wall seconds Suites passed
1 (bash <suite> in turn, as affected-tests.sh runs them today) 1315 47 of 48 (surface.test.sh hit a Playwright click timeout)
3 445 48 of 48
8 274 48 of 48
24 275 48 of 48

Command: bash scripts/run-plugin-tests.sh --jobs N --suites-from <list>, the call affected-tests.sh --run --jobs N makes. From 8 jobs up, the wall time is the longest suite (plugins/planning/surface/surface-journey.test.sh, 290 s median in scripts/suite-seconds.txt). The same results at 3, 8 and 24 jobs show the selected suites don't depend on each other. The default is nproc - 1, not nproc: affected-tests.sh records 3 jobs as the ceiling on a 4-vCPU runner, and 4 failed there (#3694). This host gains nothing past 8 jobs. On this branch, scripts/check-affected.sh --tests --base 73b971b815 --no-fetch at the default (23 jobs) took 218 s end to end, rc 0.

Verification

  • plugins/source-control/skills/babysit-prs/scripts/engine.test.sh (the unittest suite, the pinned ruff and the wrapper checks) with the gh shim first on PATH: 3205 tests OK, ruff clean, 0 gh spawns.
  • Before the fix, under pytest with the shim and a socket probe: 3205 passed, 6 gh spawns, 0 connects. The unittest discover run above is the final revision.
  • scripts/check-affected.test.sh: PASS=75 FAIL=0, including a new case where --jobs 0 is a usage error.
  • scripts/check-affected.sh --tests on this branch with the shim: every lint check passed and every selected shell suite passed, with 0 gh spawns. tests is a SKIP only for the 8 babysit Python files, which engine.test.sh runs.

Related

🤖 Generated with Claude Code

kyle-sexton and others added 2 commits October 27, 2026 17:20
…arallel

The babysit-prs engine suite spawned 6 real gh processes across 5 tests
(repos/owner/repo reads), spending the shared token budget and depending on
the network. The Unattended harness's policy._get fake fell back to the real
reader when no test patch answered; it now raises there instead, so the four
manifest tests read the head as unreadable exactly as before, with no process. The refresh
author-check test stops at refuse_standards_sync instead of calling gh.

check-affected.sh --tests ran the selected shell suites one at a time.
It now takes --jobs N (default $CHECK_AFFECTED_JOBS, else cores - 1)
and hands it to affected-tests.sh, whose run-plugin-tests.sh job pool keeps
the serial-list suites off the parallel group.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kyle-sexton
kyle-sexton marked this pull request as ready for review October 27, 2026 22:36
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T22:38:19.701907Z 0c7e3e0 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 0c7e3e04085b511731ac6c225b390b47600a847f: 0 finding(s), 0 as inline comments.

Security review: no findings

I read the whole diff and the PR context. I did not run anything.

  • Trusted paths: none of the 5 changed files match a TRUSTED PATHS glob. The two babysit-prs files are under scripts/tests/, which the list does not cover. No trust control, merge hold, token scope or kill switch changes.
  • Manifests: no plugin.json or marketplace.json changes, so there is no manifest <field> line.
  • .changes/source-control/perf-test-lane-waste-2c4f4c8e.md: bump: none. Nothing a user runs changes.
  • test_babysit_merge.py and test_babysit_merge_unattended.py: these only add test mocks. The unattended harness now raises AssertionError on an unanswered policy._get instead of falling through to the real reader. No production code changes and no guard is weakened.
  • scripts/check-affected.sh: this adds --jobs N.
    • Both the $CHECK_AFFECTED_JOBS default and the --jobs value must match ^[1-9][0-9]*$. The env value falls back to 1 if it fails. The flag value fails with a usage error at scripts/check-affected.sh:130, before any use.
    • Only a validated integer reaches the forwarded arguments and the run_check description string. That leaves no injection path from the argument or the env var.
    • The arguments are quoted and passed as an array when the script re-runs itself in the snapshot checkout. The merge-base, snapshot and CHECK_DATA_ROOT handling is unchanged.
    • The pre-push hook runs without --tests, so it is unaffected.
  • scripts/check-affected.test.sh: this adds a --jobs 0 usage-error case.
  • Embedded instructions: the PR description contains none.

Spend: more concurrent local test suites in check-affected.sh --tests, which uses compute only. The change adds no billed resource.

critical-findings: 0

@github-actions

Copy link
Copy Markdown
Contributor

claude-review reviewed 0c7e3e04085b511731ac6c225b390b47600a847f: 0 finding(s), 0 as inline comments.

No blocking or advisory findings. I read the full diff and checked its call sites in the repository. I ran no tests, so the test results quoted in the PR description are author-claimed and unverified by me.

What I checked

  • Unattended harness (test_babysit_merge_unattended.py): _real_get has no remaining readers. The only uses of the new _outer_get are its assignment in run_main and the fallback in _get. The fallback still delegates to a test's own outer patch of policy._get, and it raises AssertionError instead of reaching the real reader.
  • Refresh test (test_babysit_merge.py): refresh_pr_branch.validate_current_candidate calls refuse_standards_sync directly after the dependency-manager check (refresh_pr_branch.py:93). Patching it to raise RuntimeError("past the author check") therefore stops the run just past the author check. The exact-message assertion is the stricter, correct replacement for the old assertNotIn.
  • check-affected.sh --jobs:
    • affected-tests.sh already takes --jobs N and validates it (lines 307-312 and 364). It hands N > 1 to run-plugin-tests.sh --suites-from and runs N = 1 sequentially (lines 1626-1642). The new forwarding matches that interface.
    • The CHECK_AFFECTED_JOBS env value falls back to 1 when invalid. The --jobs flag value is validated after parsing and is a usage error. This covers --jobs 0 and --jobs --tests, and the new test case covers --jobs 0.
    • The snapshot re-exec (line 194) forwards --jobs, and both affected-tests.sh call sites pass it.
  • Changelog fragment: bump: none fits a test-only and dev-tooling change.

Cost and trusted paths

  • No changed file matches a TRUSTED PATHS glob, and nothing changes a paid plan or billing setting, so there is no hold.
  • Spend: this change reduces use of the shared gh token budget. It adds no spend, apart from more parallel local test processes.
  • Closing issues: the PR names none, so there are no acceptance criteria to check.

@kyle-sexton
kyle-sexton added this pull request to the merge queue Oct 27, 2026
Merged via the queue into main with commit 432c915 Oct 27, 2026
75 checks passed
@kyle-sexton
kyle-sexton deleted the perf/test-lane-waste branch October 27, 2026 23:16
@github-actions

Copy link
Copy Markdown
Contributor

Post-merge mutation testing

Killed 0, survived 1, timeout 0, no coverage 0, invalid 0, not run 7.
Covered-code score 0%; mutation score 0%.

File Killed Survived Timeout No coverage Invalid Not run
scripts/check-affected.sh 0 1 0 0 0 7

Surviving mutants

Location Operator Disposition Cause
scripts/check-affected.sh:104 AOR unclassified unclassified

The run's summary has the full report.

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.

1 participant