Repository navigation
Description
What
A critical review of the CLI's testing strategy (run on master @ 5dc5bd6, 2026-11-09). It covers which test types we use, where each one runs in the SDLC, and how coverage lines up with risk. It also proposes an action plan.
Full report (in Spanish, with diagrams): https://claude.ai/artifact/GAVjmZpM34E4LD3UVe9E95
Verdict
The test types we picked fit a CLI that wraps external binaries and AWS APIs: unit tests, in-process CLI tests, black-box bats and a real-AWS E2E. The problem was how we applied them:
- No check was required to merge, so the unit tests stayed red on
masterfrom Feat | Remove docker dependency #316 to Fix | Restore the unit test suite #322 (Apr–Sep 2026). - The PyPI release ran zero tests.
- The E2E ran in the wrong phase, with an obsolete matrix.
- The riskiest paths had the lowest coverage: SSO (
aws.py41%),project create(project.py32%), andplan/apply/--layers.
Overall branch coverage was 66%, across 225 pytest tests and 10 bats tests.
Already done
- H1:
unit_tests(3.9–3.13),lintandintegration_testsare now required checks onmaster - H2: the release is gated on the test suite and on the built wheel (Enhancement | Gate the PyPI release on the test suite and the built package #332)
- H3/H4: the ref-arch E2E was modernized: 15 → 2 runs, correct exit codes,
destroywithif: always(), and it also runs as a release gate (Enhancement | Modernize the ref-arch integration test #338, closes Enhancement | Modernize the ref-arch integration test (integration_tests_cli_refarch) #330; depends on Fix | Propagate the tofu/terraform exit code to the CLI #336) - The bats
TESTS_ROOTtypo was fixed (Fix | CI on Ubuntu 26.04: pin the Python 3.9 jobs, fix a bats typo #340) - H5: hermetic bats tests for the tofu/terraform layer lifecycle: local backend, no AWS,
init/plan/apply/output/destroyplus--layers, with tofu and terraform (Enhancement | Hermetic bats tests for the tofu/terraform layer lifecycle #347). No CLI change was needed: auth is already skipped when SSO and MFA are off. Checked in CI that they fail when the tfvars/backend injection breaks (DO NOT MERGE | Sabotage check for #347 #348) - H8: the bats tests also run on macOS and on older (tofu 1.10, terraform 1.12) and latest (tofu 1.13.9, terraform 1.17.2) releases, as non-required
integration_tests_compatchecks; the requiredintegration_testsis unchanged (Enhancement | Run the bats tests on macOS and on more tofu/terraform versions #349). $0: public repo, standard runners - H6/H7 for
aws:CliRunnertests foraws sso login/refresh/logout,configure ssoand the pass-through, with real boto3 clients underStubberand a fakeawsexecutable;aws.pybranch coverage 41% → 96% (Enhancement | CLI tests for leverage aws (sso login/refresh/logout, configure sso) + two fixes #351). They found and fixed 3 bugs:sso loginwithout a profile (regression from Feat | Remove docker dependency #316),configure ssocrashing on an organization without OUs, and theslow_downinterval (RFC 8628). Two more crashes,sso logoutwithout a token andconfigure ssowithoutproject_long, were fixed in Fix | Make aws sso logout idempotent, check project_long before configure sso logs in #352 (closes BUG | aws sso logout and configure sso crash with a traceback on missing token or project_long #350), which also keeps the aws tests from ever reaching the network - Lint:
ruff(pyflakes + pycodestyle errors) runs in the requiredlintcheck and in pre-commit;pylint2.8.3, which never ran and does not support 3.12+, is gone (Enhancement | Lint with ruff in CI and pre-commit, drop pylint #353).F541was ignored in_backend_config.pyuntil Fix/issue 317 multiple regressions #333 merged (dropped in Chore | Drop the F541 ignore now that #333 is merged #384) - H6 for
auth.py: tests with a realPathsHandlerand real files intmp_path, and realsso/stsclients underStubber, forcheck_sso_token, the per-layer refresh,refresh_all_accountsand MFA (which had no tests);auth.pycoverage 60% → 93% (Fix | SSO token expiry compared in UTC, MFA recognizes STS errors + auth.py tests with Stubber #354). They found and fixed 2 bugs: the SSO token expiry was compared with the local time instead of UTC (in UTC-3, expired tokens were accepted for 3 more hours), and MFA did not recognize the errors STS returns, so a user without permission was silently asked for the code 3 times - Types:
mypy1.19.1 (the last release that supports Python 3.9) checksleverage/in the requiredunit_testsjob, with a gradual config (annotated code only). The 52 errors it found are fixed:Runner.runoverloads, commands imported from their modules, and aget_option_valuehelper for ConfigUpdater values (Enhancement | Type check leverage/ with mypy (gradual) in CI #355). Next step when wanted:check_untyped_defs, module by module - Hygiene: coverage floor
fail_under = 75in CI (77% today),test_root_path.pyrewritten with real git instead of asserting a mock, 7 TFRunner env-var tests that repeatedtest_runner.pyremoved (Enhancement | Test hygiene: coverage floor, real-git root path tests, no duplicate TFRunner tests #357).unit/integrationmarkers dropped: the whole suite runs in ~12 s and bats already run apart. Found along the way: Bug | Any git error other than "not a git repository" makes every command crash with a TypeError #356 (any other git error crashes every command) and Enhancement | The Snyk PR check tests nothing; 51 open Dependabot alerts on poetry.lock #358 (the Snyk PR check tests nothing; 51 open Dependabot alerts)
Pending
Ordered by impact and effort:
- H7 (rest),
tfpart: exit code propagation and--layersordering were already covered; Fix | tf: init --layers backend key per layer, validate-layout exit code + error path tests #385 adds the error paths (--layerserrors, invalid layout, backend key,_make_layer_backend_key,validate-layout).tf.pycoverage 87% → 99%. It found and fixed 2 bugs:init --layersgave every new layer the same backend key, andvalidate-layoutexited 0 on failure - H7 (rest),
projectpart:CliRunnertests forproject init/create, always assertingexit_code, plus golden files for theproject createoutput andtofu fmt -check/validateon the result. Golden files would have caught Malformed config.tf file when first creating backend layer #321. Waits for Feature | Project create extra checks #334. ~half a day - After Fix/issue 317 multiple regressions #333 merges: dropped the
F541ignore forleverage/_backend_config.py;ruff check --fixturned its 11 placeholder-free f-strings into plain strings, with the error messages unchanged (Chore | Drop the F541 ignore now that #333 is merged #384) - Closing review: once the rest is done, rerun the analysis that produced the report (same scope and method) and publish it as a new version, to compare before and after (CI, coverage per module, bugs found) and to spot anything from the original report still pending. ~1 h
Not needed: performance/load tests and UI tests. An AWS emulator (moto/Floci/LocalStack) only helps in part: none of the ones we evaluated covers the SSO portal, sso-oidc or identitystore.
🤖 Generated with Claude Code
Activity
Enhancement | Hermetic bats tests for the tofu/terraform layer lifecy…
Enhancement | Run the bats tests on macOS and on more tofu/terraform …
Enhancement | CLI tests for leverage aws (sso login/refresh/logout, c…
Enhancement | Lint with ruff in CI and pre-commit, drop pylint (#353)