fix(cli): don't sys.exit at import when OptionsAI is unavailable (#6)#25
Open
bradsmithmba wants to merge 1 commit into
Open
fix(cli): don't sys.exit at import when OptionsAI is unavailable (#6)#25bradsmithmba wants to merge 1 commit into
bradsmithmba wants to merge 1 commit into
Conversation
src/cli/main.py called sys.exit(1) at module scope when OptionsAI failed to import. Because sys.exit raises SystemExit, any module that merely imported src.cli.main aborted the whole process — pytest collection died with `INTERNALERROR: SystemExit: 1` and no tests ran. Capture the import failure instead and surface it at command execution time via get_options_ai(), preserving the original user-facing message and exit code 1 for actual CLI use while keeping the module safe to import. Before: `pytest tests/cli/` -> INTERNALERROR SystemExit, 0 collected. After: the module imports cleanly and the cli test suite collects. The remaining command-level failures depend on OptionsAI being constructable (blocked by cloudtrainerwork#1) and are unrelated to this change. Closes cloudtrainerwork#6 Co-Authored-By: Claude Opus 4.8 <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.
Summary
src/cli/main.pycalledsys.exit(1)at module scope whenOptionsAIfailed to import:sys.exitraisesSystemExit, so any module that merely importssrc.cli.mainterminates the entire process. Under pytest this aborts collection:Closes #6.
Fix
Capture the import error instead of exiting, and report it at command execution time inside
get_options_ai()— preserving the original user-facing message and exit code 1 for real CLI usage, while making the module safe to import:Testing
pytest tests/cli/collectionINTERNALERROR: SystemExit, 0 collectedimport src.cli.mainThe cli command tests now collect (9 pass, 19 fail). The 19 failures occur because the app-level
@app.callback()callsget_options_ai()on every invocation andOptionsAIcannot be constructed while the feature pipeline is broken — that is blocked by #1 and is not introduced by this change. They will pass once #1 lands.🤖 Generated with Claude Code