fix: propagate service start and stop failures - #208
Conversation
|
🎉 Thank you for your first pull request to KubeIntellect. Please read this one thing — it will look like something is broken, and it isn't:
While you wait, the things most likely to come up in review:
Contributors are credited in |
|
@Ryota-Di — first PR to this project, and it is green on all nine required checks. Welcome properly. 🎉 First, an apology for the delay that was not yours: your CI had never run. A first-time contributor's fork PR sits at I re-ran your red-green rather than taking your word for itYour claim was that the test fails before the fix and passes after. Verified independently, by putting $ pytest tests/test_no_unchecked_subprocess_success.py -k propagate_systemctl_failure
E Failed: DID NOT RAISE SystemExit
FAILED ...test_service_start_and_stop_propagate_systemctl_failure[start]
FAILED ...test_service_start_and_stop_propagate_systemctl_failure[stop]
2 failed
$ # with your fix restored
17 passed in 3.28sByte-for-byte what you reported. That matters more than it sounds: an accurate self-report is the thing that makes the next PR cheap to review. The part that shows you read the code rather than the issueAnyone can add You propagated the actual exit code — And you noticed the allowlist would rot. ("cli.py", "systemctl --user stop"): "as `service start`",
("cli.py", "systemctl --user status"): "as `service start`",Deleting the Your call to leave You also updated the documented server counts (5562 → 5564) in both Your row on the wallYou were added to the contributor table two days ago marked 🛠️, when you claimed the issue rather than when you delivered. Per the rule announced then, the row gets rewritten to describe this fix once it lands — from "stepped forward" to what you actually did. Merge decision is with the maintainer and I expect it to be yes. If you want another, #154 is close in spirit — count-drift gates that run per-PR and cannot see cross-PR drift, which is the gate you just satisfied, viewed from the other side. And entirely optionally: a ⭐ or a note anywhere about "a CLI that exited 0 when the service it started had refused to start" helps a one-maintainer project more than it looks — the repo currently has more forks than stars. It changes nothing about how your work is treated either way. Thank you for a genuinely well-made first contribution. 💙 |
…p-exit-code # Conflicts: # AGENTS.md # CONTRIBUTING.md
…ing back MSKazemi#208 fixes the defect and pins the code that is propagated. Two gaps were left either side of it. The success path had nothing holding it. `sys.exit(proc.returncode or 1)` — the shape a later cleanup reaches for — turns every successful `service start` into exit 1, and the whole suite stays green: the failure test asserts `code == 5`, and the AST scanner sees an assignment rather than a discarded call. Verified by injecting exactly that line; the new case fails and nothing else does. The other gap is the repair a future contributor will reach for. Deleting the `_REVIEWED` entries is what stops the discarded shape returning, but nothing stopped the entry being written back — which is what `_MUST_STAY_CHECKED` exists to forbid, and already does for `restart` and `disable`. Four tests, not two: `_MUST_STAY_CHECKED` is parametrized, so the two signatures also assert that `start` and `stop` still check their result. Count recollected 5578 -> 5584.
…thor's entry Ryota-Di's all-contributors entry was still `inflight`, the placeholder used while a pull request is open. The work has landed, so it becomes bug/code/test. The changelog entry says what the fix does not cover as well as what it does. `service status` and `service logs` still discard their return codes on purpose, and the reason is worth keeping next to the fix: `systemctl status` returns non-zero for a valid inactive unit, and `journalctl -f` returns non-zero when the operator presses Ctrl-C. Reading either as a failure would swap one wrong answer for another.
|
Merged — thank you, this was a real bug and a clean fix. Your change is on kubeintellect/v4/packages/kubeintellect-server/app/cli.py Lines 782 to 789 in a11425d What it fixes matters more than its size. The part I want to call out is the part you didn't change. Leaving Verified before merging, on the merged tree: ruff clean, mypy clean across 193 files, server suite 5560 passed, kq suite 749 passed, and the file-mode, syntax, encoding, roster and doc-claims gates all green. I confirmed your test genuinely fails on the unpatched code first ( Two things I added on top, so you know exactly what changed under your name:
I also merged Your all-contributors entry is updated from the in-flight placeholder to bug/code/test, and the changelog entry for the next release credits you by name. If you're looking for another one, the same class of bug is worth hunting elsewhere in Entirely optional, and the merge and the credit were the point either way: if the project is useful to you, a star or a mention helps other people find it. |
What & why
kubeintellect service startandkubeintellect service stopnow propagate a non-zero exit code when the underlyingsystemctlcommand fails.Previously,
subprocess.run(...)was called without inspecting its result, sosystemctlcould fail while the kubeintellect CLI still exited successfully with code 0.This PR:
systemctlreturn code forservice startandservice stopstart/stopcalls from_REVIEWED_REVIEWEDreasoning forstatusandlogsto explicitly address exit-code semanticsWhy
statusandlogsare unchangedI left
service statusandservice logsunchanged intentionally.For
status, a non-zerosystemctl statuscode can describe a valid queried state such as an inactive service, so it should not be blindly treated as failure of the status query itself.For
logs,journalctl -fis an interactive follow command whose normal lifecycle includes user interruption, so its eventual subprocess return code does not directly represent whether log viewing was successfully started.Their
_REVIEWEDentries now document these exit-code considerations rather than only noting that stdout/stderr are visible to the user.Testing
The regression test was first run against the unmodified implementation and failed as expected for both
startandstop:After the fix:
Additional validation:
I also ran the full server test suite locally. The remaining failures were unrelated to this change and specific to the local macOS environment: the demo GIF tests require a supported monospace font such as DejaVu Sans Mono, and three file-mode tests hit BSD
chmodbehavior.Closes #189.
Type of change
Scope
v4/(plus root-level test-count docs)v4/, or docs/typos in older versions).Checklist
triggers:anddetect:are two independent features — a test provesthe compiled
detect:predicate fires on a realistic event and does not fire on aneighbouring one. The counts and the schema check prove neither. (
kind:is the observationchannel —
Pod/Event/Node— never the Kubernetes object; useinvolved_kind:tonarrow the subject.)
uv run pytestpasses locallyuv run ruff check .passes locallyuv run mypy srcpasses locallyNotes for reviewers
The full server suite was run locally on macOS. The failures described above appear environment-specific; the tests directly covering this change, doc-claim validation, lint, and type checking pass locally.