Commit d8eeed7
committed
Merge #47: Update E2E full tests to use CreateCommandHandler and fix preflight cleanup
0f3f76a refactor: [#39] move cleanup_previous_test_data to preflight_cleanup module (Jose Celano)
0e7d5a0 fix: [#37] add data directory cleanup to E2E preflight (copilot-swe-agent[bot])
ce59c6a refactor: [#37] move create_environment_via_command to e2e tasks module (copilot-swe-agent[bot])
e5f2fb0 refactor: [#37] improve error handling in create_environment_via_command (copilot-swe-agent[bot])
4455c9b feat: [#37] update e2e-tests-full to use CreateCommandHandler (copilot-swe-agent[bot])
c0f248d Initial plan (copilot-swe-agent[bot])
Pull request description:
Subissue 5/7 of #34 - The E2E full test suite was creating environments directly via `Environment::new()` instead of exercising the new `CreateCommandHandler`, missing test coverage of the command layer. Additionally, the E2E preflight cleanup was not removing stale environment data from previous test runs, causing test failures.
## Changes
- **Created `run_create_command` task module**: New module in `src/testing/e2e/tasks/run_create_command.rs` that encapsulates environment creation using `CreateCommandHandler`, following the established pattern of other E2E tasks like `run_configure_command`
- **Replaced direct environment creation**: Main test flow in `e2e_tests_full.rs` now uses the task module instead of `Environment::new()`, exercising the complete command pattern workflow
- **Improved error handling**: Task module includes comprehensive error handling with `CreateTaskError` enum and `help()` method for detailed troubleshooting guidance
- **Consistent patterns**: Uses `RepositoryFactory` and `Clock` as parameters, and `"data"` as base directory, matching the pattern in `TestContext.create_repository()`
- **Added data directory cleanup**: New `cleanup_data_environment()` function in `src/testing/e2e/tasks/preflight_cleanup.rs` that removes `data/{environment_name}` directories from previous test runs, preventing "environment already exists" errors and ensuring proper test isolation
## Module Structure
The new task follows the same structure as other E2E tasks:
- Located in `src/testing/e2e/tasks/run_create_command.rs`
- Exported from `src/testing/e2e/tasks/mod.rs`
- Documented as an infrastructure-agnostic task
## Preflight Cleanup Enhancement
The preflight cleanup now includes data directory removal in addition to build and templates cleanup:
- **Container preflight** (`src/testing/e2e/tasks/container/preflight_cleanup.rs`): Calls `cleanup_data_environment()` before Docker cleanup
- **VM preflight** (`src/testing/e2e/tasks/virtual_machine/preflight_cleanup.rs`): Calls `cleanup_data_environment()` before OpenTofu/LXD cleanup
This ensures E2E tests always start with a clean slate, preventing failures from stale environment state left by interrupted previous test runs.
## Example
```rust
// Before: Direct construction bypassed command layer
let environment = Environment::new(environment_name, ssh_credentials, ssh_port);
// After: Exercises CreateCommandHandler via task module with full validation and persistence
let repository_factory = RepositoryFactory::new(Duration::from_secs(30));
let clock: Arc<dyn Clock> = Arc::new(SystemClock);
let environment = run_create_command(
&repository_factory,
clock,
"e2e-full",
ssh_private_key_path.to_string_lossy().to_string(),
ssh_public_key_path.to_string_lossy().to_string(),
"torrust",
DEFAULT_SSH_PORT,
)?;
```
The E2E test suite now validates the command handler end-to-end through a properly structured task module, ensuring repository persistence and configuration validation work correctly in real deployment scenarios while maintaining consistency with the existing E2E testing architecture. The enhanced preflight cleanup guarantees reliable test execution by removing all artifacts from previous runs.
- Fixes #39
<!-- START COPILOT CODING AGENT SUFFIX -->
<details>
<summary>Original prompt</summary>
>
> ----
>
> *This section details on the original issue you should resolve*
>
> <issue_title>[Subissue 5/7] Update E2E Full Tests to Use Create Command</issue_title>
> <issue_description>**Parent Epic**: #34 - Implement Create Environment Command
> **Depends On**: #36 - Application Layer Command
> **Estimated Time**: 1-2 hours
>
> ## Overview
>
> Update the `src/bin/e2e_tests_full.rs` to use the new create command handler instead of direct environment creation. This ensures the full E2E test exercises the complete create command functionality as part of the comprehensive test suite.
>
> ## Goals
>
> - [ ] Add new function to create environment using CreateCommand handler
> - [ ] Update e2e_tests_full.rs to use the new create command for environment creation
> - [ ] Maintain existing test flow while exercising create command logic
> - [ ] Ensure comprehensive test coverage of create command in full E2E context
> - [ ] Preserve existing test reliability and performance
>
> ## Implementation Summary
>
> - **Location**: `src/bin/e2e_tests_full.rs`
> - **Approach**: Add `create_environment_via_command()` function that uses CreateCommand handler
> - **Integration**: Replace direct environment creation with command-based creation
> - **Testing**: Not black-box like Subissue 4 - this uses the command handler directly
>
> ## Key Changes
>
> ```rust
> // Add function to create environment using CreateCommand
> async fn create_environment_via_command(context: &TestContext) -> Result<Environment<Created>> {
> let create_command = CreateCommand::new(context.environment_repository.clone());
>
> let config = EnvironmentCreationConfig {
> environment_name: context.environment_name.clone(),
> ssh_credentials: context.ssh_credentials.clone(),
> };
>
> create_command.execute(config)
> }
>
> // Replace direct environment creation in main test function
> let environment = create_environment_via_command(&context)
> .await
> .expect("Failed to create environment via command");
> ```
>
> ## Acceptance Criteria
>
> - [ ] E2E full tests use CreateCommand handler for environment creation
> - [ ] All existing E2E test functionality remains intact
> - [ ] Create command is properly exercised in comprehensive test suite
> - [ ] Test execution time and reliability maintained
> - [ ] Proper error handling and logging preserved
>
> For detailed specification, see: [docs/issues/epic-create-environment-command-subissue-5-update-e2e-full-tests.md](https://github.com/torrust/torrust-tracker-deployer/blob/main/docs/issues/epic-create-environment-command-subissue-5-update-e2e-full-tests.md)</issue_description>
>
> ## Comments on the Issue (you are @copilot in this section)
>
> <comments>
> </comments>
>
</details>
- Fixes #39
<!-- START COPILOT CODING AGENT TIPS -->
---
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs.
ACKs for top commit:
josecelano:
ACK 0f3f76a
Tree-SHA512: 6f4ce20948a363d73fdf63e57193556d8a0ac9bdb06d01a4c7563c4cd51d649b9d8c8a0c1dd582f21c98c0a1c55509b027035551a8083bfdb2070a95c24558b0File tree
6 files changed
+380
-19
lines changed- src
- bin
- testing/e2e/tasks
- container
- virtual_machine
6 files changed
+380
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
| 59 | + | |
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
62 | | - | |
63 | | - | |
| 63 | + | |
| 64 | + | |
64 | 65 | | |
65 | | - | |
| 66 | + | |
66 | 67 | | |
67 | 68 | | |
| 69 | + | |
68 | 70 | | |
| 71 | + | |
69 | 72 | | |
70 | 73 | | |
71 | 74 | | |
| |||
109 | 112 | | |
110 | 113 | | |
111 | 114 | | |
| 115 | + | |
112 | 116 | | |
113 | 117 | | |
114 | 118 | | |
| |||
127 | 131 | | |
128 | 132 | | |
129 | 133 | | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | 134 | | |
134 | 135 | | |
135 | 136 | | |
136 | 137 | | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | 138 | | |
144 | | - | |
145 | | - | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
146 | 159 | | |
147 | 160 | | |
148 | 161 | | |
149 | 162 | | |
150 | 163 | | |
151 | | - | |
152 | | - | |
| 164 | + | |
| 165 | + | |
153 | 166 | | |
154 | 167 | | |
155 | 168 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
47 | 51 | | |
48 | 52 | | |
49 | 53 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| 34 | + | |
33 | 35 | | |
34 | 36 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
51 | 145 | | |
52 | 146 | | |
53 | 147 | | |
| |||
192 | 286 | | |
193 | 287 | | |
194 | 288 | | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
0 commit comments