Cover run_script and the log stream to restore coverage headroom - #20
Merged
Merged
Conversation
…adroom The coverage gate is `fail_under = 40` and main sat at exactly 40.00%, so any change that adds statements without tests tips it under. Dependabot #15, which touches only web/ files, failed its Python job at 39.95% for precisely that reason: the log-stream rewrite and the secret-key resolver added statements to api/server.py without adding tests for them. Rather than lower the gate, cover the two pieces that had none. run_script is the subprocess wrapper behind every management endpoint, and had no direct coverage: endpoints that call it mock it out wholesale, so the not-found path, the exception path and the timeout handling were never exercised. The timeout is the part worth testing, since it is what stops a real-sized backup being reported as a failure. The WebSocket log stream had none either. These tests pin the behaviour the rewrite is for: one follower process no matter how many clients subscribe, every line fanned out to every subscriber in order, blank lines dropped, the follower stopping when the last client leaves, the child process reaped on the way out, and a clear error rather than a crash when Docker is absent. The disconnect test covers why it uses discard rather than remove: a disconnect can arrive for a session already dropped, and that must not raise. Coverage 40.00% -> 41.98%, tests 193 -> 221. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The changes are test-only and appear consistent with the current api/server.py behavior while directly addressing the described coverage regression risk.
Review effort: Lite
Findings: None
What changed in this PR
This pull request adds direct unit tests for two previously untested Python components in api/server.py—the run_script subprocess wrapper and the WebSocket-based log streaming follower—to restore and increase overall Python coverage headroom above the 40% gate.
Changes:
- Add a dedicated test suite for
run_script, covering not-found, timeout, exception, argument forwarding, and working-directory behavior. - Add a dedicated test suite for the WebSocket log stream utilities, covering tail retrieval, single-follower behavior, fan-out semantics, blank-line dropping, Docker-missing handling, and safe disconnect cleanup.
| File | Description |
|---|---|
tests/api/test_run_script.py |
Adds coverage for run_script timeout/error/argv/cwd behavior. |
tests/api/test_log_streaming.py |
Adds coverage for the SocketIO log tail + shared follower fan-out and disconnect semantics. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Why
The coverage gate is
fail_under = 40andmainsits at exactly 40.00%. That is a knife edge: any change adding statements without tests tips it under, and run-to-run variation alone can decide it.Dependabot #15 hit this. It touches only
web/files, yet its Python job failed:The cause is mine: the log-stream rewrite and the secret-key resolver in #17 added statements to
api/server.pywithout adding tests for them.Lowering the gate would hide that. This covers the two pieces that had none instead.
What is covered
run_scriptis the subprocess wrapper behind every management endpoint and had no direct coverage, because endpoints that call it mock it out wholesale. The not-found path, the exception path and the timeout handling were never exercised. The timeout matters most: it is what stops a real-sized backup being reported as a failure.The WebSocket log stream had none either. These tests pin the behaviour the rewrite exists for:
discard, notremove, because a disconnect can arrive for an already-dropped session and must not raiseResult
Nearly two points of headroom, from real tests rather than a threshold change.
Note
test_performance.py::test_status_endpoint_performanceis timing-based and wobbles under-n auto, passing 3/3 in isolation but occasionally exceeding its 300ms budget under parallel load. Pre-existing, not addressed here.🤖 Generated with Claude Code