Repository navigation
fix(swarm): import subprocess so the QA stage can run the generated tests - #3
Merged
Merged
Conversation
…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]>
Owner
|
Thanksss a lot @KiloMusician for spotting the missing |
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.
Problem
Stage 7 of
swarm_pipeline.pycallssubprocess.run(...)to run the generated unit tests, but the module never importssubprocess. TheNameErroris swallowed by the surroundingexcept Exception, so on currentmain(51c772e) every run that has a provider ends inFAILED: QA Test Runner Errorat stage 7, and stages 8 to 10 (security, DevOps, tech lead) can never run.I confirmed it on a copy of
main:subprocessis 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).-p test_api.py).unittest discover -s testsalso 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.FAILED: QA No Tests Ran), as is output with noRan N testssummary, so the gate cannot pass vacuously; the number of tests that ran is logged.tests/test_swarm_qa_stage.py, with fakes forsubprocess.runandcouncil.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 reportsQA Unit Tests Failed; an exit 0 withRan 0 testsis a failure; a runner that cannot start reportsQA Test Runner Error.Verification
python -I -m unittest discover -s testson head1ca7a12: Windows 11 / Python 3.13: 17 tests, OK. Linux (Ubuntu, Python 3.12): 17 tests, OK. The new tests fail onmain(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.