Skip to content

Conversation

@josecelano
Copy link
Member

📋 Overview

Refactor src/bin/e2e_provision_and_destroy_tests.rs to be a "real" E2E test that executes the CLI as a black box, similar to tests/e2e_create_command.rs.

Closes #199

🎯 Goals

  • Decouple the test from internal implementation details.
  • Test the public CLI interface for provisioning and destruction.
  • Ensure consistent testing patterns.

⚙️ Changes

Key Changes

  1. Move ProcessRunner to shared location:

    • Moved tests/support/process_runner.rssrc/testing/black_box/process_runner.rs
    • Added run_provision_command method to ProcessRunner
    • Updated src/testing/mod.rs to expose black_box module
    • Updated tests/support/mod.rs to re-export ProcessRunner from src/testing/black_box (backward compatibility)
  2. Refactored Binary:

    • Removed TestContext usage
    • Removed direct command_handlers imports
    • Uses ProcessRunner to execute CLI commands:
      • create environment --env-file <generated-config>
      • provision e2e-provision
      • destroy e2e-provision
    • Kept verify_required_dependencies
    • Kept preflight cleanup (from testing module)
    • Verifies success via exit codes only

Design Decisions

  1. Dynamic Config Generation: Static fixture files don't work because Ansible runs from the build directory, requiring absolute paths for SSH keys. Config is generated at runtime with absolute SSH key paths.

  2. Minimal Code Movement: Only moved ProcessRunner to src/testing/black_box/ since it's shared between src/bin/ and tests/. Kept TempWorkspace and assertions in tests/support/ (local to tests).

  3. Exit Code Verification Only: Trust CLI exit codes for now. Future enhancement: use list command to verify environment state.

✅ Checklist

  • Pre-commit checks pass: ./scripts/pre-commit.sh
  • E2E tests pass locally (run twice to verify cleanup)
  • No direct calls to command_handlers for logic execution
  • CI workflow test-e2e-provision.yml passes

📁 Files Changed

  • src/bin/e2e_provision_and_destroy_tests.rs - Major refactor to use black-box CLI execution
  • src/testing/black_box/mod.rs - New module for black-box testing utilities
  • src/testing/black_box/process_runner.rs - Moved from tests/support/
  • src/testing/mod.rs - Expose black_box module
  • tests/support/mod.rs - Re-export ProcessRunner for backward compatibility
  • docs/issues/199-refactor-e2e-provision-and-destroy-tests.md - Updated implementation notes
  • .gitignore - Ignore runtime-generated E2E config file
  • cspell.json - Added project-specific terms

- Refactor e2e_provision_and_destroy_tests to execute CLI commands via ProcessRunner
  instead of directly calling application layer command handlers
- Move ProcessRunner from tests/support/ to src/testing/black_box/ for sharing
  between src/bin/ and tests/
- Add run_provision_command method to ProcessRunner
- Generate environment config at runtime with absolute SSH key paths
  (required because Ansible runs from build directory)
- Add envs/ to .gitignore and cspell ignorePaths for generated E2E config files
- Re-export ProcessRunner from tests/support/ to minimize test code changes
- Update issue documentation with completed acceptance criteria
@josecelano josecelano self-assigned this Nov 26, 2025
- Change function parameter from 'keep' to 'destroy' for clearer intent
- Default behavior (destroy=true) now comes first in the if/else
- Rename 'keep' to 'destroy_on_failure' in provision_infrastructure for consistency
@josecelano
Copy link
Member Author

ACK cc9a1a7

@josecelano josecelano merged commit c166e70 into main Nov 26, 2025
34 checks passed
josecelano added a commit that referenced this pull request Nov 26, 2025
…tests

0e3ab51 refactor: [#200] introduce E2eTestRunner abstraction (Jose Celano)
4056432 refactor: [#200] extract configure_services to shared task (Jose Celano)
612577e refactor: [#200] extract validate_deployment to shared task (Jose Celano)
28e9253 refactor: [#200] extract destroy_infrastructure to shared task (Jose Celano)
e453527 refactor: [#200] extract provision_infrastructure to shared task (Jose Celano)
265c5be refactor: [#200] extract create_environment to shared task (Jose Celano)
a24faa4 refactor: [#200] extract generate_environment_config to shared task (Jose Celano)
7407c8b refactor: [#200] extract run_preflight_cleanup to shared task (Jose Celano)
1df7ff1 refactor: [#200] reorganize E2E testing modules (Jose Celano)
959b4f5 refactor: [#200] extract verify_required_dependencies to shared task (Jose Celano)
0a8076f refactor: [#200] move black_box module inside e2e module (Jose Celano)
898a86d refactor: [#200] use black-box CLI execution in E2E full tests (Jose Celano)

Pull request description:

  ## Summary

  Refactors `e2e_tests_full.rs` to use black-box CLI execution via `ProcessRunner`, following the same pattern established in issue #199.

  ## Changes

  - **Remove internal imports**: Eliminated `TestContext` and direct `command_handlers` imports
  - **Use ProcessRunner**: All CLI commands (create, provision, configure, test, destroy) now execute through `ProcessRunner`
  - **Extend ProcessRunner**: Added `run_configure_command` and `run_test_command` methods
  - **Dynamic config generation**: Generate environment config at runtime with absolute SSH key paths (required because Ansible runs from build directory)
  - **Consistent pattern**: Applied same black-box testing approach from issue #199

  ## Testing

  - ✅ Pre-commit checks pass
  - ✅ E2E full tests pass (ran twice to verify cleanup works)

  ## Related

  - Closes #200
  - Follows pattern from #199 / PR #201

ACKs for top commit:
  josecelano:
    ACK 0e3ab51

Tree-SHA512: 39eaa5b3210396db8d27cbd74cae44f818d03d46481e32573457719ce827a186f196b4e2c4194c25f40e8e0c8b63b4b44979f572f2549081be6647fb35bcfd7a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor e2e_provision_and_destroy_tests to use black-box CLI execution

2 participants