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) - 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/createon a snapshot of the real template, always assertingexit_code(Enhancement | CLI tests for project init/create with golden files #388). Golden files hold the 56 filesproject createmakes and the 8 it renders, verbatim; every created.tf/.tfvarsparses, every layer passesvalidate-layout(backend layers point to--skip-validation, by design), and with tofu installedtofu fmt -checkpasses. The Malformed config.tf file when first creating backend layer #321 regression test passes, so Malformed config.tf file when first creating backend layer #321 is closed. Fixed:project createexited 0 withoutproject.yamlor on a created project, and the render functions froze the template path at import. The goldenbuild.envshowed the template still rendersTERRAFORM_IMAGE_TAGand noTF_BINARY: Fix | build.env.template: drop TERRAFORM_IMAGE_TAG, add TF_BINARY le-tf-infra-aws-template#65. Not covered:tofu validateon the created project (needs providers; a bats follow-up) - 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) - Property-based tests (
hypothesis): 10 properties over task arguments, backend keys (format,-drvariant, legacy prefixes,init's key passingvalidate-layout), theconfig.tfround trip andbuild.envloading; ~0.6 s (Fix | Property-based tests (hypothesis) and the 4 bugs they found #386). They found and fixed 4 bugs:leverage run task[k=a=b]crashed on=inside a value;set_backend_keyoverwrote any other*keyattribute in the file (sse_customer_key, akeyinlocals), and the review added commented and nestedkeys (assume_role.tags); a layer named likeglobal-acceleratorwas taken for a region directory; andbase-/tools-were dropped from anywhere in a name, soinit --layerscould write a keyvalidate-layoutrejected. Coverage 80.6% - Contract tests with
le-tf-infra-aws: on every ref-arch layer,validate-layoutpasses, the keyinitwould write is accepted, the CLI finds the layer and passes common/account/backend tfvars to tofu, and every AWS profile resolves to a project account the way the SSO refresh does (Enhancement | Contract tests with the reference architecture (le-tf-infra-aws) #387). They run on a 13-layer snapshot (one per layout shape) inunit_tests, and on all 104 layers of the ref-arch's currentmasterin the new non-requiredcontract_tests_refarchjob (skipped on releases). They found a staleroot-administratorprofile inclient-vpnthat breaks SSO there: client-vpn uses the stale root-administrator profile, so SSO credential refresh fails on it le-tf-infra-aws#1347. The ref-arch keeps both backend key conventions (with and without the region directory);validate-layoutaccepts both - Security, static + lightweight threat model: ruff's
Srules (bandit) run in the requiredlintcheck; each accepted finding has anoqawith its reason.docs/threat-model.mdlists the secrets the CLI handles, 10 threats with their status, and a checklist for changes (Fix | Keep tokens and credentials private: file permissions, no locals in tracebacks, ruff S rules #389). It found and fixed 2 leaks: the SSO token, credentials files and MFA cache were written with the umask (0644, readable by other local users; seen on a real machine) and are now 0600 in 0700 directories, as the AWS CLI does; and logged tracebacks showed local variables, which in the credential code hold the token and the keys. Files written by older versions are tightened the next time the CLI writes them - Mutation testing (
mutmut), occasionally, not in CI:make mutationruns mutmut 3.8.1 onauth.pyandtf.pyin ~2 min; config in[tool.mutmut](Fix | Mutation testing (mutmut) on auth.py and tf.py, and the 2 bugs it found #390). First run: 665 of 825 mutants killed (80.6%), 157 of the 160 survivors inauth.py; now 734 of 819 (89.6%). The 85 left are log messages, option-name case, 1-minute boundaries and equivalent defaults (listed in Fix | Mutation testing (mutmut) on auth.py and tf.py, and the 2 bugs it found #390). It found and fixed 2 bugs: the layer's own profile was never recognized (the parser returns${var.profile}, the code compared withvar.profile), so SSO wroteprofile = var.profilecredentials under a name rebuilt from the role and MFA failed oneach.value.profile; and a short MFA code crashed with a traceback (botocore'sParamValidationErrorisn't aClientError). On macOS it needsno_proxy='*'(in the target). Rerun once per quarter or before a major release - Overlap between test types: per-test coverage (
--cov-context=test) found 27 groups of tests running exactly the same lines; read by hand, 25 pytest tests (495 → 470) and 4 bats lifecycle tests only re-checked what a kept test already checks:test_runner.py46 → 31,test_tfrunner.py14 → 8 (TFRunner.runonly forwards toRunner.run), thepytestertests ofget_root_pathand the plugin, and bats tests that never reach tofu (Chore | Remove tests that repeat others at the same level #391). No line or branch lost coverage (85% → 85%) and mutation testing keeps its 85 survivors. Gap covered:TFRunner.execdoesn't raise by default. The PR has a table of what each suite is for, and the overlaps kept on purpose - Update the docs:
docs/testing.mdexplains what each suite checks and doesn't, its CI job, where a new test goes (the cheapest level that catches the bug) and how to refresh the snapshots and golden files; README keeps the commands and links it; CLAUDE.md gets the guide and the testing rules, and two fixes (the coverage command measured the whole repo, the SSO token path was the old one); CONTRIBUTING's PR process no longer describes Docker-era rules; the PR template has a Tests section (Docs | Testing guide, and README, CLAUDE.md and CONTRIBUTING brought up to date #392). User docs: the backend key format,validate-layout's exit code and=inrunvalues, in Docs | Leverage CLI: backend key format, validate-layout exit code,=in task arguments le-ref-architecture-doc#257 - Closing review: the v1 analysis rerun with the same scope and method on
master@4218c9b, published as v2 (v1: 2026-11-09). H1–H8 closed; 225 → 470 pytest tests, 10 → 16 bats; branch coverage 66% → 85.5% (aws.py41 → 97%,auth.py59 → 98%,project.py32 → 90%); 0 → 7 required checks; 23 CLI bugs found and fixed. Left, by impact: the rest of BUG | AWS profile name is re-derived from the SSO permission set, breaking any account whose permission set is renamed #326 (cross-account literal profiles, stale-sso-sections,refresh help),credentials.pyat 63%,test_aws.pytaking 8 of the suite's ~16 s (v1: 1.9 s), OIDC (Enhancement | Use OIDC instead of static AWS keys in the ref-arch integration test #337),kubectl.pytest smells,tofu validateon a created project
Pending
Ordered by impact and effort:
Test-type review (2026-11-26)
A pass over a common catalog of ~45 test types (pre-merge, pre-release, rollout and production) to check which ones we already use and which ones are worth adding. The four new pending items above come from here.
Already in place: unit, functional/component (CliRunner), static analysis and lint (mypy, ruff, black), coverage with a floor (fail_under = 75), integration (bats with real tofu/terraform), config/compat (tofu/terraform version matrix + macOS), acceptance/E2E (ref-arch on real AWS per PR), smoke (the built wheel is installed and its version checked before publishing), regression (every fix adds its test; golden files are the H7 project part), and a partial canary (RCs on TestPyPI).
Worth adding, ranked by value for effort: golden files (already H7), property-based tests, contract tests with the ref-arch, static security + threat model, and mutation testing now and then.
Not worth it, and why:
- Rollout and production practices (canarying, traffic shaping, feature flags, A/B, real user monitoring, tracing, tap compare, shadowing, teeing, on-call): they assume a service that receives traffic. The CLI is a short-lived process on the user's machine; there is no traffic to split, mirror or watch.
- Monitoring, exception tracking and central logs: they would need telemetry leaving our clients' infrastructure environments. The trust and privacy cost is far higher than what we'd learn.
- Load, soak, performance, benchmark and profiling: a run's time is spent in tofu and AWS, not in the CLI. The only cheap exception is startup time (
python -X importtime), worth checking only if someone reports slowness. - Fuzzing and formal verification: the inputs are local files written by the user; property-based tests cover that risk at a fraction of the cost.
- Chaos and penetration testing: there is no network surface or infrastructure of our own; the threat model gives more for less.
- Usability and UI/UX tests: for a CLI these are the output and the error messages, which the golden files cover.
- AWS emulators (moto/Floci/LocalStack) only help 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)
Fix | Mutation testing (mutmut) on auth.py and tf.py, and the 2 bugs …
Chore | Remove tests that repeat others at the same level
Chore | Remove tests that repeat others at the same level (#391)
Docs | Testing guide, and README, CLAUDE.md and CONTRIBUTING brought …
diego-ojeda-binbash commentedon Nov 27, 2026
Done: every item is in Already done. The closing review reran the original analysis with the same method: report v2 (v1: 2026-11-09).
master: 0 → 7What's left is tracked in #394.