fix(admin): raise AdminError instead of sys.exit; add admin test suite#228
Open
rylinjames wants to merge 1 commit into
Open
fix(admin): raise AdminError instead of sys.exit; add admin test suite#228rylinjames wants to merge 1 commit into
rylinjames wants to merge 1 commit into
Conversation
Audit §3.10 A1/A2/A3/A5 — admin/ had zero tests because the library called sys.exit(2) directly, so nothing could be tested without subprocess harnesses. - _client.py: get_admin_token / admin_request now raise AdminError(exit_code=2) instead of writing to stderr + sys.exit. Each command's main() catches it, prints the message, and returns the code — CLI behavior (exit 2 on failure) is preserved, but the functions are now unit-testable and library-usable. - A2: an unsupported HTTP method was `raise ValueError` INSIDE the network try-block, so a programmer error got reported as "Could not reach worker". Now validated up front; the network except is narrowed to httpx.HTTPError. - A3: warn when the admin bearer token would be sent over cleartext http:// to a non-local host (the token is otherwise leaked silently). - A5: validate --max-seats >= 1 (issue) and --limit >= 1 (list). - A4: renamed the `license` local that shadowed the builtin to `lic`. Added tests/test_admin.py (14 cases): token presence, unsupported-method ≠ network error, 401/4xx/network wrapping, insecure-endpoint warning (and no warning for localhost), and each command's main() success + AdminError exit codes + arg validation. ruff clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Audit §3.10 (admin A1/A2/A3/A5) — admin/ had zero tests because the library called
sys.exit(2)directly, so nothing could be exercised without subprocess harnesses.Changes
get_admin_token/admin_requestnow raiseAdminError(exit_code=2)instead ofstderr.write+sys.exit. Each command'smain()catches it, prints the message, and returns the code — CLI exit-2-on-failure behavior is preserved, but the functions are now unit-testable and usable as a library.raise ValueErrorinside the networktry, so a programmer error got reported as "Could not reach worker". Now validated up front; the networkexceptis narrowed tohttpx.HTTPError.http://to a non-local host (otherwise the token leaks silently).--max-seats >= 1and--limit >= 1. A4: renamed thelicenselocal that shadowed the builtin.Tests
tests/test_admin.py— 14 cases: token presence; unsupported-method ≠ network error; 401 / 4xx / network-error wrapping; insecure-endpoint warning (and no warning for localhost); each command'smain()success +AdminErrorexit codes + arg validation.ruffclean.🤖 Generated with Claude Code