Skip to content

fix(swarm): import subprocess so the QA stage can run the generated tests - #3

Merged
Yoepan merged 3 commits into
Yoepan:mainfrom
KiloMusician:fix/swarm-qa-subprocess-import
Oct 25, 2026
Merged

Yoepan merged 3 commits into
Yoepan:mainfrom
KiloMusician:fix/swarm-qa-subprocess-import

Conversation

@KiloMusician

Copy link
Copy Markdown
Contributor

Problem

Stage 7 of swarm_pipeline.py calls subprocess.run(...) to run the generated unit tests, but the module never imports subprocess. The NameError is swallowed by the surrounding except Exception, so on current main (51c772e) every run that has a provider ends in FAILED: QA Test Runner Error at stage 7, and stages 8 to 10 (security, DevOps, tech lead) can never run.

I confirmed it on a copy of main: subprocess is used at line 457 and appears nowhere else in the file, and a complete mocked run (fake provider, no network) stops at stage 7 with that message. With the import added, the same run passes the runner.

Change

  • import subprocess (one line).
  • The runner now discovers only the file the QA stage generated (-p test_api.py). unittest discover -s tests also runs this repository's own tests, so "the generated tests passed" depended on unrelated tests and on how long they take against the 15 second timeout.
  • A run in which the runner reports zero tests (exit 0 on some Python versions, 5 on 3.13) is now a QA failure (FAILED: QA No Tests Ran), as is output with no Ran N tests summary, so the gate cannot pass vacuously; the number of tests that ran is logged.
  • Tests (tests/test_swarm_qa_stage.py, with fakes for subprocess.run and council.call_llm; no network, nothing generated is executed): a complete run passes the runner; the runner gets the documented command and timeout; a non-zero exit reports QA Unit Tests Failed; an exit 0 with Ran 0 tests is a failure; a runner that cannot start reports QA Test Runner Error.

Verification

python -I -m unittest discover -s tests on head 1ca7a12: Windows 11 / Python 3.13: 17 tests, OK. Linux (Ubuntu, Python 3.12): 17 tests, OK. The new tests fail on main (the missing import) and the zero-test tests fail on the commit before them.

For review

With the import in place the stage really does execute the model-generated tests, and whatever they import, in the project directory, as the code already intended and as main's CI/docs imply. Nothing sandboxes that (same environment, 15 s timeout that kills only the direct child); I did not change it. A follow-up could scrub the child's environment and run it with -I, if you want that.

Prepared with AI coding assistants (OpenAI GPT and Anthropic Claude) on behalf of @KiloMusician, who submits it. Commands and counts above were run on the head named. MIT licence untouched.

KiloMusician and others added 3 commits October 24, 2026 16:06
…ests

Stage 7 calls subprocess.run() to execute the generated unit tests, but
swarm_pipeline.py never imported subprocess. The NameError was swallowed
by the surrounding `except Exception`, so every run with a provider
ended in "FAILED: QA Test Runner Error" at stage 7 and stages 8-10 could
not run at all.

Add the missing import and cover the stage with tests: a complete run now
passes the runner, the runner is called with the documented command and
timeout, a non-zero exit reports "QA Unit Tests Failed", and a runner that
cannot start reports "QA Test Runner Error". The tests fake subprocess.run
and council.call_llm, so no network is used and nothing generated is run.

Note for review: with the import in place the stage really does execute
the model-generated tests (and whatever they import) in the project
directory, as the code already intended.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
`unittest discover -s tests` runs every test in tests/, not just the file
the QA stage generated. This repository keeps its own tests there, so the
verdict "the generated tests passed" also depended on unrelated tests
(and on how long they take against the 15 second timeout), and the stage
executed more code than the generated test it reports on.

Restrict discovery to the generated file with `-p test_api.py`.

The shared test fixture also silences the pipeline's stdout echo for every
test case instead of only inside run_swarm().

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The QA stage treated exit code 0 from `unittest discover` as "the generated
tests passed". unittest exits 0 for an empty discovery on Python 3.11 and
earlier and 5 ("NO TESTS RAN") on 3.12 and later, so a generated
tests/test_api.py with no unittest cases (pytest-style functions, say) was
reported as a failure on one interpreter and as "passed with zero
regressions" on another.

The stage now also reads the runner's "Ran N tests" summary from stderr and
stdout. Zero tests, or no summary line at all, fails the stage with
"FAILED: QA No Tests Ran" whatever the exit code and Python version are. The
number of tests that ran is logged. The log line announcing the run now names
the command that is actually executed (`unittest discover -s tests -p
test_api.py`), not `unittest discover tests`.

The shared test fixture's fake runner reports a one-test unittest summary by
default and can be given any output.

As before, this stage executes model-written tests, and whatever they
import, with the user's privileges and without a sandbox. A follow-up could
run the child with a scrubbed environment and `-I`.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@Yoepan
Yoepan merged commit f97a584 into Yoepan:main Oct 25, 2026
1 check passed
@Yoepan

Yoepan commented Oct 25, 2026

Copy link
Copy Markdown
Owner

Thanksss a lot @KiloMusician for spotting the missing subprocess import in the QA stage and adding comprehensive test coverage! Great catch that prevents the swarm pipeline from failing at Stage 7. Merging this now!

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.

2 participants