fix(serve): coerce --reload CLI string to bool via env()#110
Open
bedus-creation wants to merge 2 commits into
Open
fix(serve): coerce --reload CLI string to bool via env()#110bedus-creation wants to merge 2 commits into
bedus-creation wants to merge 2 commits into
Conversation
When Cleo passes --reload=False/True as a string, the old code forwarded the raw string to uvicorn, which treated any non-empty string as truthy. Now the string is coerced with _env(cli_reload, cli_reload) from fastapi_startkit.environment, which maps "False"/"false" → False and "True"/"true" → True before passing the value to uvicorn. Adds tests/fastapi/test_serve_command.py covering: - None option falls back to fastapi config value - "False" → False - "True" → True - "false" (lowercase) → False Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace hand-rolled unittest.mock approach (patching option() and calling handle() directly) with CommandTester.execute() so Cleo drives the full command path naturally. External dependencies (uvicorn.run, Config.get, is_app_exist) are still patched; option() is no longer patched. Co-Authored-By: Claude Sonnet 4.6 <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
--reload=Falsepassed on the CLI was forwarded to uvicorn as the string"False". Uvicorn treats any non-empty string as truthy, so--reload=Falseactually enabled reloading instead of disabling it.env as _envfromfastapi_startkit.environmentand coerce the CLI string with_env(cli_reload, cli_reload)before passing it to uvicorn. This maps"False"/"false"→Falseand"True"/"true"→Trueusing the existing casting logic inenv().Files changed
fastapi_startkit/src/fastapi_startkit/fastapi/commands/serve_command.py— importenv as _env, replace one-liner with two-liner that coerces the stringfastapi_startkit/tests/fastapi/test_serve_command.py— new test fileTest plan
uv run pytest tests/fastapi/ -v)test_reload_none_falls_back_to_cfg_reload_true—Nonefalls back to configTruetest_reload_none_falls_back_to_cfg_reload_false—Nonefalls back to configFalsetest_reload_string_False_becomes_bool_false—"False"→Falsetest_reload_string_True_becomes_bool_true—"True"→Truetest_reload_string_false_lowercase_becomes_bool_false—"false"→False🤖 Generated with Claude Code