refactor(cli): convert beads verdict os.Exit calls to typed exit-error (ag-x22j #beads-exit-as-typed-error)#769
Merged
Conversation
…r (ag-x22j #beads-exit-as-typed-error) The `ao beads verify|lint|audit` commands called os.Exit(1) mid-RunE to signal a stale/flagged verdict. os.Exit skips deferred cleanup (temp files, lock release) and kills the test binary, leaving those verdict paths untestable. Introduce a typed *beadsExitError that the command returns (mirroring gateExitError/doctorExitError); Execute() maps it to the process exit code at the single root exit point. The returning RunE sets cmd.SilenceErrors so cobra emits no spurious "Error:" line, while genuine errors elsewhere in those commands still print normally. A nil-cmd guard keeps direct callers/tests safe. Adds beads_exit_test.go pinning the verdict contract (verify + lint stale -> *beadsExitError exit 1 + SilenceErrors; clean -> nil; nil-cmd no panic). Closes-scenario: ag-x22j#beads-exit-as-typed-error Bounded-context: BC5-Runtime Evidence: cli/cmd/ao/beads_exit_test.go
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.
What
ao beads verify|lint|auditused exit-code-as-verdict but signalled it by callingos.Exit(1)inside RunE.os.Exitskips deferred cleanup (temp files, lock release) and kills the test binary, so the verdict branches were untestable.This converts the 3 sites to return a typed
*beadsExitError, whichExecute()maps to the process exit code at the single root exit point — the established CLI idiom (mirrorsgateExitErrorinvalidate.goanddoctorExitErrorindoctor_surface.go).Sites converted
runBeadsVerify(beads.go) — stale citations → exit 1runBeadsLint(beads.go) — stale beads → exit 1runBeadsAudit(beads_audit_cluster.go) —--strict+ flagged → exit 1How
beadsExitError{code}type (Error()empty,ExitCode()), since the verdict text already went to stdout.cmd.SilenceErrors(nil-guarded) so cobra prints no spuriousError:line; genuine errors returned elsewhere in those commands still print normally.Execute()gains abeadsExitErrorbranch before the generic fallback.Evidence
cli/cmd/ao/beads_exit_test.go— pins the verdict contract: verify + lint stale →*beadsExitErrorexit 1 +SilenceErrors; clean → nil; nil-cmd no panic.cd cli && go build ./... && go vet ./cmd/ao/clean;gofmt -lclean.go test ./cmd/ao/→ 9314 passed.Bead
ag-x22j(P3, child of the Go idiomatic auditag-tcf0). No moreos.Exitoutsidemain/root in the beads command paths.Closes-scenario: ag-x22j#beads-exit-as-typed-error
Bounded-context: BC5-Runtime
Evidence: cli/cmd/ao/beads_exit_test.go