forked from torrust/torrust-demo
-
Notifications
You must be signed in to change notification settings - Fork 1
refactor: [#14] Phase 2.3 - Three-Layer Testing Architecture & Documentation Improvements #19
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ell-utils.sh - Extract general helper functions to scripts/shell-utils.sh for project-wide reuse: * test_http_endpoint() - HTTP endpoint testing with content validation * retry_with_timeout() - Configurable retry logic with custom parameters * time_operation() - Operation timing with automatic duration logging - Keep project-specific functions in tests/test-e2e.sh: * get_vm_ip() - Specific to torrust-tracker-demo VM name * ssh_to_vm() - Specific to torrust user and VM configuration - Benefits achieved: * Reduced code duplication across the project * Centralized common patterns for better maintainability * Standardized error handling and logging * Better separation of concerns between test logic and utilities - Quality assurance: * All code passes ShellCheck linting * End-to-end test passes (2m 42s execution time) * Functions maintain backward compatibility * Enhanced documentation and usage examples This refactoring eliminates duplicate code patterns while creating reusable utilities that can benefit other scripts in the infrastructure and application directories.
…mpose deployment - Move log_section function from duplicated implementations to scripts/shell-utils.sh - Remove duplicates from tests/test-e2e.sh, infrastructure/tests/test-ci.sh, infrastructure/tests/test-local.sh - Add vm_exec_with_timeout function to deploy-app.sh for robust long-running SSH commands - Split Docker Compose pull and up commands for better progress feedback and error isolation - Remove deprecated --include-deps flag from docker compose pull (now default behavior) - Add 10-minute timeout for Docker image pulls to prevent deployment hangs - Validate E2E and deployment workflows with refactored code - All CI tests and deployment health checks pass
- Replace Docker-based detection with multi-layered approach: 1. Primary: Official cloud-init status command 2. Secondary: Custom completion marker file 3. Tertiary: System service readiness checks - Add completion marker creation at end of cloud-init setup - Update E2E tests to use robust detection method - Update deployment scripts with same detection logic - Remove dependency on specific software for completion detection This makes cloud-init detection more reliable and future-proof, working regardless of command order or installed software.
…ayers - Restructure Makefile into clear hierarchical layers (infra-, app-, vm-, test-, dev-) - Rename commands for better clarity: test -> test-e2e, test-syntax -> lint - Remove backward compatibility for legacy commands (apply, destroy, ssh, etc.) - Update help output with grouped commands by layer for better discoverability - Update all scripts, tests, and documentation to use new command structure - Implement twelve-factor app deployment workflow separation - Infrastructure provisioning: make infra-apply (platform setup) - Application deployment: make app-deploy (Build + Release + Run stages) - VM access and debugging: make vm-ssh, vm-console, vm-status - Testing: make test-e2e (comprehensive), make lint (syntax), make test-unit - Development workflows: make dev-deploy, make dev-test, make dev-clean Updated files: - Makefile: Complete restructure with new command organization - CI workflow: Updated to use make infra-test-ci - Documentation: Updated all references to use new command names - Test scripts: Updated to use new infra/app health check commands - E2E test: Updated to use make lint instead of make test-syntax This refactoring improves command discoverability, follows twelve-factor app principles, and provides clear separation between infrastructure and application concerns while maintaining all existing functionality.
- Align table columns properly for Testing and Validation commands - Improve readability of command reference table
…ture - Refactor infrastructure/tests/test-ci.sh to only test infrastructure concerns - Remove global 'make lint' calls from infrastructure layer - Create new application/tests/test-ci.sh for application-only testing - Create new tests/test-ci.sh for project-wide orchestration - Update Makefile with proper layer separation (infra-test-ci, app-test-ci, test-ci) - Update GitHub workflow to use 'make test-ci' for complete validation - Fix application tests to be CI-friendly (optional environment files) - Add comprehensive documentation in .github/copilot-instructions.md - Document three-layer testing architecture with clear boundaries - Add AI assistant guidelines to prevent future violations Testing Hierarchy: - make test-ci: Project-wide orchestrator (global + infra + app) - make infra-test-ci: Infrastructure layer only - make app-test-ci: Application layer only Prevents mixing concerns like calling global commands from layer-specific tests.
Add comprehensive table of contents to .github/copilot-instructions.md for improved navigation through the contributor guide. The TOC includes: - Project overview and repository structure - Development workflow and command reference - Conventions, standards, and testing architecture - Getting started guides for different user types - AI assistant guidelines and restrictions Benefits: - Improves navigation for this comprehensive guide - Makes the document more accessible to contributors - Maintains visual consistency with emoji headings - Enhances professional appearance of documentation
…ctory structure The GitHub Actions CI was failing because the application/config/templates directory wasn't being tracked by Git (empty directories are not tracked). The application unit tests expect this directory to exist. Fixes failing workflow: - application/tests/test-unit-application.sh checks for 'config' directory - Empty directories are not preserved during git checkout - Added .gitkeep to ensure directory structure is maintained This resolves the CI failure: 'Required application path missing: config'
The test was incorrectly expecting the configure-env.sh script to fail when called without parameters, but the script is designed to use sensible defaults ('local' environment). Changes: - Fixed test logic to expect success when script uses defaults - Replaced warning message with proper success validation - Added proper error handling when script actually fails This eliminates the CI warning: '[WARNING] Script should handle missing parameters gracefully' The script DOES handle missing parameters gracefully by using defaults, so the test should validate this behavior correctly.
ACK 0a36bbc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🎯 Overview
This PR completes Phase 2.3 of the twelve-factor app refactoring initiative (#14), implementing a strict three-layer testing architecture and comprehensive documentation improvements to ensure maintainable separation of concerns.
🚀 Key Achievements
✅ Three-Layer Testing Architecture Implementation
Implemented strict separation of testing concerns across three layers to prevent future mixing of concerns and improve maintainability:
1. Project-Wide/Global Layer (
tests/
folder)make test-ci
2. Infrastructure Layer (
infrastructure/
folder)make infra-test-ci
3. Application Layer (
application/
folder)make app-test-ci
✅ Enhanced Documentation & Contributor Experience
.github/copilot-instructions.md
for improved navigation✅ Shell Utilities Consolidation
scripts/shell-utils.sh
log_section
function across all scripts✅ Makefile Organization
📁 Files Changed
Core Architecture Files
Makefile
: Refactored test targets for three-layer architecturetests/test-ci.sh
: New project-wide orchestrator for global concernsinfrastructure/tests/test-ci.sh
: Refactored to focus only on infrastructure concernsapplication/tests/test-ci.sh
: New application-layer CI test scriptDocumentation & Guidelines
.github/copilot-instructions.md
: Added TOC and enhanced AI assistant guidelinesdocs/refactoring/
: Added comprehensive refactoring documentationtests/README.md
: Updated to reflect three-layer architectureUtilities & Scripts
scripts/shell-utils.sh
: Consolidated utility functions with sudo cache management🔧 Benefits Delivered
Maintainable Architecture
Enhanced Developer Experience
Future-Proof Foundation
🧪 Testing & Validation
Complete CI Validation
make test-ci # ✅ All project-wide tests pass ├── Global concerns (syntax, structure, Makefile) ✅ ├── make infra-test-ci (Infrastructure layer only) ✅ └── make app-test-ci (Application layer only) ✅
Layer Separation Validation
Documentation Quality
🔗 Relationship to Issue #14
This PR addresses Phase 2.3 objectives from the twelve-factor refactoring plan:
Next Phase: Configuration management system implementation (template-based configurations)
🔍 Review Focus Areas
Testing Architecture
make test-ci
properly orchestrates all layersDocumentation Quality
Code Quality
Ready for Review ✅ | All CI Tests Pass ✅ | Documentation Complete ✅