-
Notifications
You must be signed in to change notification settings - Fork 0
Update E2E full tests to use CreateCommandHandler and fix preflight cleanup #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Add create_environment_via_command() function that uses CreateCommandHandler - Replace direct Environment::new() with command-based creation - Update imports to include CreateCommandHandler and related types - Maintain existing test flow while exercising create command logic - Ensure proper validation and repository persistence through command pattern Co-authored-by: josecelano <[email protected]>
- Replace expect() with anyhow::Context for better error messages - Extract repository timeout constant (30 seconds) - Use .context() instead of .map_err() to preserve error chain - Add descriptive context messages for error scenarios Co-authored-by: josecelano <[email protected]>
josecelano
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot It looks good but move the new function "create_environment_via_command" to src/testing/e2e/tasks where we have other tasks for E2E testing like:
- src/testing/e2e/tasks/run_configure_command.rs
Besides, you do not need to calculate the working directory. Take a look at the "run_configure_command.rs" module. You can use the TestContext to access test context information.
- Create new module src/testing/e2e/tasks/run_create_command.rs - Move environment creation logic to dedicated task module - Accept RepositoryFactory and Clock as parameters instead of calculating directory - Use "data" as base directory following TestContext pattern - Remove local function from e2e_tests_full.rs - Update imports and call site to use new task module - Add comprehensive error handling with help() method - Follow same pattern as run_configure_command.rs Co-authored-by: josecelano <[email protected]>
Done! Moved to The function accepts Commit: ce59c6a |
|
Hi @copilot — quick code review / automation note for PR #47. SummaryI ran a quick local analysis of the E2E preflight cleanup and found that the current preflight flow cleans the Where I looked
Why this is a problem
Suggested fix (high-level)Add an explicit data/env cleanup step in the preflight flow. Two safe approaches: A) Remove the test environment data directory(s) directly in preflight
B) (Safer / more semantically correct) Invoke the existing production destroy flow
Concrete minimal code snippet (Option A) to add to // new helper
pub fn cleanup_data_environment(test_context: &TestContext) -> Result<(), PreflightCleanupError> {
use std::path::Path;
let data_dir = Path::new("data").join(test_context.environment.instance_name().as_str());
if !data_dir.exists() {
tracing::info!(operation = "data_directory_cleanup", status = "clean", path = %data_dir.display(), "Data directory doesn't exist, skipping cleanup");
return Ok(());
}
tracing::info!(operation = "data_directory_cleanup", path = %data_dir.display(), "Cleaning data directory for previous test environment");
std::fs::remove_dir_all(&data_dir).map_err(|e| PreflightCleanupError::ResourceConflicts {
details: format!("Failed to clean data directory '{}': {}", data_dir.display(), e),
})?;
tracing::info!(operation = "data_directory_cleanup", status = "success", path = %data_dir.display(), "Data directory cleaned successfully");
Ok(())
}Then call
Placement: run data cleanup after templates/build cleanup and before any provider-specific destroy logic. Notes about using the production
|
- Add cleanup_data_environment() helper to preflight_cleanup.rs
- Clean data/{environment_name} directory before E2E test runs
- Call from both container and VM preflight cleanup functions
- Prevents "environment already exists" errors from stale state
- Ensures proper test isolation by starting with clean data directory
- Follows same pattern as build and templates directory cleanup
Co-authored-by: josecelano <[email protected]>
Implemented! Added The function is now called from both:
This prevents "environment already exists" errors when previous test runs fail to clean up properly, ensuring reliable E2E test execution with proper isolation. Commit: 0e7d5a0 |
a32b76c to
533eda2
Compare
…module - Move cleanup_previous_test_data from e2e_tests_full.rs to preflight_cleanup.rs - Fix preflight cleanup ordering: clean data BEFORE CreateCommandHandler - Add TODO comment for future TestContext refactoring - Separate early data cleanup (no TestContext) from full preflight cleanup - Prevents 'environment already exists' errors by cleaning before repository check The current workaround requires two cleanup functions because TestContext needs an Environment, but we must clean data before creating the Environment. Future refactoring should separate Environment from TestContext for better design.
533eda2 to
0f3f76a
Compare
josecelano
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 0f3f76a
Subissue 5/7 of #34 - The E2E full test suite was creating environments directly via
Environment::new()instead of exercising the newCreateCommandHandler, 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
run_create_commandtask module: New module insrc/testing/e2e/tasks/run_create_command.rsthat encapsulates environment creation usingCreateCommandHandler, following the established pattern of other E2E tasks likerun_configure_commande2e_tests_full.rsnow uses the task module instead ofEnvironment::new(), exercising the complete command pattern workflowCreateTaskErrorenum andhelp()method for detailed troubleshooting guidanceRepositoryFactoryandClockas parameters, and"data"as base directory, matching the pattern inTestContext.create_repository()cleanup_data_environment()function insrc/testing/e2e/tasks/preflight_cleanup.rsthat removesdata/{environment_name}directories from previous test runs, preventing "environment already exists" errors and ensuring proper test isolationModule Structure
The new task follows the same structure as other E2E tasks:
src/testing/e2e/tasks/run_create_command.rssrc/testing/e2e/tasks/mod.rsPreflight Cleanup Enhancement
The preflight cleanup now includes data directory removal in addition to build and templates cleanup:
src/testing/e2e/tasks/container/preflight_cleanup.rs): Callscleanup_data_environment()before Docker cleanupsrc/testing/e2e/tasks/virtual_machine/preflight_cleanup.rs): Callscleanup_data_environment()before OpenTofu/LXD cleanupThis ensures E2E tests always start with a clean slate, preventing failures from stale environment state left by interrupted previous test runs.
Example
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.
Original prompt
💡 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 in the docs.