Skip to content

Enhancement | CLI tests for project init/create with golden files - #388

Merged
diego-ojeda-binbash merged 1 commit into
masterfrom
feature/project-cli-tests
Nov 27, 2026
Merged

diego-ojeda-binbash merged 1 commit into
masterfrom
feature/project-cli-tests

Conversation

@diego-ojeda-binbash

@diego-ojeda-binbash diego-ojeda-binbash commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

What?

  • CLI tests for project (tests/test_modules/test_project_cli.py, 9 new), on a snapshot of the real project template:
    • project init: clones the template, runs git init, drops project.yaml. A second run updates the template (checkout master + pull) and keeps the user's project.yaml.
    • project create, with project.yaml filled the way the ref-arch integration test does:
      • Golden files (tests/project_template/golden/): the list of the 56 files it creates (symlinks included) and the 8 it renders from templates, verbatim. Every copied file must be identical to the template.
      • Every created .tf/.tfvars parses as HCL.
      • Every created layer passes validate-layout. The base-tf-backend layers fail on purpose and point to --skip-validation, since their backend block stays commented out until their first apply.
      • With tofu installed, tofu fmt -check -recursive passes on the result (skipped where tofu isn't installed, e.g. the unit_tests job).
    • project create before init, and a second project create: exit 1, and nothing changes.
    • Malformed config.tf file when first creating backend layer #321 regression test: the first tofu init --skip-validation of a new backend layer reaches tofu with its -backend-config. It passes on master, so Malformed config.tf file when first creating backend layer #321 is already fixed.
  • 2 fixes in leverage/modules/project.py:
  • tests/project_template/: snapshot of le-tf-infra-aws-template@e369df9 (template/ and le-resources/, verbatim). snapshot.py refreshes it, and UPDATE_GOLDEN=1 poetry run pytest tests/test_modules/test_project_cli.py regenerates the golden files; review that diff, it is what project create generates.

Why?

H7 in #346, project part: CliRunner tests for project init/create, always asserting exit_code, plus golden files of the project create output. It waited for #334, merged now.

Checked that the golden files catch output changes: rendering with trim_blocks or putting the regional layers in another directory fails them.

Not covered

tofu validate on the created project: it needs providers and modules downloaded, so it doesn't fit the unit tests. It could be a bats test in the integration job, in a follow-up.

Checks

  • Unit tests: 465 passed (tofu fmt -check test included, tofu installed locally)
  • ruff, black, mypy: clean

References

🤖 Generated with Claude Code

- tests/test_modules/test_project_cli.py: `project init` (clone, git init,
  project.yaml; a second run updates the template and keeps project.yaml) and
  `project create` on a snapshot of the real template, with project.yaml
  filled as CI does. Golden files hold the list of created files and the
  rendered ones verbatim; copied files must match the template. Every created
  .tf/.tfvars parses, every layer passes validate-layout (backend layers stop
  and point to --skip-validation, by design), and with tofu installed
  `tofu fmt -check` passes.
- Regression test for #321: the first `tofu init --skip-validation` of a new
  backend layer reaches tofu with its backend config.
- project create exited 0 without project.yaml and on an already created
  project; it now exits 1.
- The template source of the render functions was a default argument frozen
  at import time; it is resolved at call time now, like the destination.
- tests/project_template/: snapshot of le-tf-infra-aws-template@e369df9,
  snapshot.py to refresh it, UPDATE_GOLDEN=1 to regenerate the golden files.

Closes #321

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 38 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ba2f5908-b848-40cf-915a-097a3702a0a9
Commits

Reviewing files that changed from the base of the PR and between 26ff462 and c6f6380.

Files selected for processing: 79

  • leverage/modules/project.py
  • tests/project_template/golden/files.txt
  • tests/project_template/golden/rendered/build.env
  • tests/project_template/golden/rendered/config/common.tfvars
  • tests/project_template/golden/rendered/management/config/backend.tfvars
  • tests/project_template/golden/rendered/management/global/organizations/locals.tf
  • tests/project_template/golden/rendered/management/global/sso/locals.tf
  • tests/project_template/golden/rendered/security/config/backend.tfvars
  • tests/project_template/golden/rendered/shared/config/backend.tfvars
  • tests/project_template/golden/rendered/shared/us-east-1/base-network/locals.tf
  • tests/project_template/le-tf-infra-aws-template/SOURCE
  • tests/project_template/le-tf-infra-aws-template/le-resources/project.yaml
  • tests/project_template/le-tf-infra-aws-template/le-resources/utils.jinja
  • tests/project_template/le-tf-infra-aws-template/template/.gitignore
  • tests/project_template/le-tf-infra-aws-template/template/build.env.template
  • tests/project_template/le-tf-infra-aws-template/template/config/common-variables.tf
  • tests/project_template/le-tf-infra-aws-template/template/config/common.tfvars.template
  • tests/project_template/le-tf-infra-aws-template/template/management/config/account.tfvars
  • tests/project_template/le-tf-infra-aws-template/template/management/config/backend.tfvars.template
  • tests/project_template/le-tf-infra-aws-template/template/management/global/organizations/accounts.tf
  • tests/project_template/le-tf-infra-aws-template/template/management/global/organizations/common-variables.tf
  • tests/project_template/le-tf-infra-aws-template/template/management/global/organizations/config.tf
  • tests/project_template/le-tf-infra-aws-template/template/management/global/organizations/locals.tf.template
  • tests/project_template/le-tf-infra-aws-template/template/management/global/organizations/organization.tf
  • tests/project_template/le-tf-infra-aws-template/template/management/global/organizations/organizational_units.tf
  • tests/project_template/le-tf-infra-aws-template/template/management/global/organizations/policies_scp.tf
  • tests/project_template/le-tf-infra-aws-template/template/management/global/organizations/policy_scp_attachments.tf
  • tests/project_template/le-tf-infra-aws-template/template/management/global/organizations/variables.tf
  • tests/project_template/le-tf-infra-aws-template/template/management/global/sso/account_assignments.tf
  • tests/project_template/le-tf-infra-aws-template/template/management/global/sso/common-variables.tf
  • tests/project_template/le-tf-infra-aws-template/template/management/global/sso/config.tf
  • tests/project_template/le-tf-infra-aws-template/template/management/global/sso/locals.tf.template
  • tests/project_template/le-tf-infra-aws-template/template/management/global/sso/permission_sets.tf
  • tests/project_template/le-tf-infra-aws-template/template/management/global/sso/policies.tf
  • tests/project_template/le-tf-infra-aws-template/template/management/global/sso/users_groups.tf
  • tests/project_template/le-tf-infra-aws-template/template/management/global/sso/variables.tf
  • tests/project_template/le-tf-infra-aws-template/template/management/primary_region/base-tf-backend/common-variables.tf
  • tests/project_template/le-tf-infra-aws-template/template/management/primary_region/base-tf-backend/config.tf
  • tests/project_template/le-tf-infra-aws-template/template/management/primary_region/base-tf-backend/locals.tf
  • tests/project_template/le-tf-infra-aws-template/template/management/primary_region/base-tf-backend/main.tf
  • tests/project_template/le-tf-infra-aws-template/template/management/primary_region/base-tf-backend/variables.tf
  • tests/project_template/le-tf-infra-aws-template/template/management/primary_region/security-base/account.tf
  • tests/project_template/le-tf-infra-aws-template/template/management/primary_region/security-base/common-variables.tf
  • tests/project_template/le-tf-infra-aws-template/template/management/primary_region/security-base/config.tf
  • tests/project_template/le-tf-infra-aws-template/template/management/primary_region/security-base/variables.tf
  • tests/project_template/le-tf-infra-aws-template/template/security/config/account.tfvars
  • tests/project_template/le-tf-infra-aws-template/template/security/config/backend.tfvars.template
  • tests/project_template/le-tf-infra-aws-template/template/security/primary_region/base-tf-backend/common-variables.tf
  • tests/project_template/le-tf-infra-aws-template/template/security/primary_region/base-tf-backend/config.tf
  • tests/project_template/le-tf-infra-aws-template/template/security/primary_region/base-tf-backend/locals.tf
  • tests/project_template/le-tf-infra-aws-template/template/security/primary_region/base-tf-backend/main.tf
  • tests/project_template/le-tf-infra-aws-template/template/security/primary_region/base-tf-backend/variables.tf
  • tests/project_template/le-tf-infra-aws-template/template/security/primary_region/security-base/account.tf
  • tests/project_template/le-tf-infra-aws-template/template/security/primary_region/security-base/common-variables.tf
  • tests/project_template/le-tf-infra-aws-template/template/security/primary_region/security-base/config.tf
  • tests/project_template/le-tf-infra-aws-template/template/security/primary_region/security-base/iam_access_analizer.tf
  • tests/project_template/le-tf-infra-aws-template/template/security/primary_region/security-base/locals.tf
  • tests/project_template/le-tf-infra-aws-template/template/security/primary_region/security-base/variables.tf
  • tests/project_template/le-tf-infra-aws-template/template/shared/config/account.tfvars
  • tests/project_template/le-tf-infra-aws-template/template/shared/config/backend.tfvars.template
  • tests/project_template/le-tf-infra-aws-template/template/shared/primary_region/base-network/account.tf
  • tests/project_template/le-tf-infra-aws-template/template/shared/primary_region/base-network/common-variables.tf
  • tests/project_template/le-tf-infra-aws-template/template/shared/primary_region/base-network/config.tf
  • tests/project_template/le-tf-infra-aws-template/template/shared/primary_region/base-network/locals.tf.template
  • tests/project_template/le-tf-infra-aws-template/template/shared/primary_region/base-network/network.tf
  • tests/project_template/le-tf-infra-aws-template/template/shared/primary_region/base-network/network_vpc_flow_logs.tf
  • tests/project_template/le-tf-infra-aws-template/template/shared/primary_region/base-network/outputs.tf
  • tests/project_template/le-tf-infra-aws-template/template/shared/primary_region/base-network/variables.tf
  • tests/project_template/le-tf-infra-aws-template/template/shared/primary_region/base-tf-backend/common-variables.tf
  • tests/project_template/le-tf-infra-aws-template/template/shared/primary_region/base-tf-backend/config.tf
  • tests/project_template/le-tf-infra-aws-template/template/shared/primary_region/base-tf-backend/locals.tf
  • tests/project_template/le-tf-infra-aws-template/template/shared/primary_region/base-tf-backend/main.tf
  • tests/project_template/le-tf-infra-aws-template/template/shared/primary_region/base-tf-backend/variables.tf
  • tests/project_template/le-tf-infra-aws-template/template/shared/primary_region/security-base/account.tf
  • tests/project_template/le-tf-infra-aws-template/template/shared/primary_region/security-base/common-variables.tf
  • tests/project_template/le-tf-infra-aws-template/template/shared/primary_region/security-base/config.tf
  • tests/project_template/le-tf-infra-aws-template/template/shared/primary_region/security-base/variables.tf
  • tests/project_template/snapshot.py
  • tests/test_modules/test_project_cli.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions github-actions Bot added enhancement New feature or request minor labels Nov 27, 2026
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 46002380050

Coverage increased (+2.4%) to 84.827%

Details

  • Coverage increased (+2.4%) from the base build.
  • Patch coverage: 2 uncovered changes across 1 file (9 of 11 lines covered, 81.82%).
  • 20 coverage regressions across 1 file.

Uncovered Changes

File Changed Covered %
leverage/modules/project.py 11 9 81.82%

Coverage Regressions

20 previously-covered lines in 1 file lost coverage.

File Lines Losing Coverage Coverage
modules/project.py 20 89.46%

Coverage Stats

Coverage Status
Relevant Lines: 4450
Covered Lines: 3858
Line Coverage: 86.7%
Relevant Branches: 1284
Covered Branches: 1006
Branch Coverage: 78.35%
Branches in Coverage %: Yes
Coverage Strength: 0.87 hits per line

💛 - Coveralls

@diego-ojeda-binbash

Copy link
Copy Markdown
Contributor Author

@claude review

@diego-ojeda-binbash
diego-ojeda-binbash merged commit c826830 into master Nov 27, 2026
30 checks passed
@diego-ojeda-binbash
diego-ojeda-binbash deleted the feature/project-cli-tests branch November 27, 2026 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request minor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Malformed config.tf file when first creating backend layer

3 participants