Skip to content

Conversation

@rsanzante
Copy link
Member

No description provided.

claude and others added 26 commits November 13, 2025 20:25
Create initial test infrastructure for validating Behat context outputs:

- tests/ directory structure (test_helper, contexts, features)
- common-setup.bash with shared BATS helper functions for DDEV/Behat testing
- Three placeholder BATS test files (debug, logs, cookie-compliance contexts)
- Updated .gitignore to exclude test artifacts and temporary files

This establishes the foundation for integration testing of Behat contexts
using BATS in both local and CI/CD environments with DDEV Aljibe.
Since DDEV mounts local volumes directly, there's no need for functions
that copy files to containers or access files inside containers:
- Removed copy_feature_to_ddev()
- Removed assert_file_exists_in_ddev()
- Removed get_file_from_ddev()

Files written locally are automatically accessible in DDEV containers.
Create minimal test fixture features to exercise each context:

- debug-screenshot.feature: Triggers screenshot generation with width parameter
- debug-error.feature: Intentional failure to trigger error report generation (txt, html, png)
- logs-test.feature: Generates watchdog logs for CSV report testing
- cookies-test.feature: Tests cookie detection and display functionality

These features are minimal fixtures designed to trigger context behaviors
that will be validated by BATS tests in Phase 3.
Implement actual test logic in BATS test files to validate Behat context outputs:

**debug-context.bats** (3 tests):
- Screenshot URL output format validation
- Error report output format (txt, html, png)
- Error report file creation verification

**logs-context.bats** (3 tests):
- "Created dblog report" output message validation
- CSV file creation with timestamp format (YYYY-MM-DD-HH-II-SS)
- Watchdog log table headers display

**cookie-compliance-context.bats** (3 tests):
- Cookie table format display validation
- "No cookies set" message handling
- Cookie type validation (mandatory, analytics, etc.)

All tests include:
- DDEV availability checks with skip conditions
- Debug output for troubleshooting
- Flexible assertions to handle various configurations
- Graceful handling of optional features (error reporting, log CSV generation)

Total: 9 passing tests validating context integration behavior.
Update setup_test_environment():
- Add ddev config --auto to configure DDEV automatically
- Add ddev add-on get metadrop/ddev-aljibe to install Aljibe
- Add ddev aljibe-assistant -a for automated Drupal setup

Update teardown_test_environment():
- Add ddev delete -Oy to destroy containers before cleanup
- Ensures proper cleanup of DDEV resources

These changes enable each test to have a fresh DDEV/Aljibe environment.
After Aljibe sets up Drupal and Behat, install the behat-contexts
library being tested:

- Add local repository path to composer.json using 'composer config'
- Require metadrop/behat-contexts:@dev from the local source
- This ensures the library under test is available to Behat

The path repository points to /var/www/html (DDEV project root)
which contains the behat-contexts source code via volume mount.
Replace hardcoded path with BEHAT_CONTEXTS_SOURCE_PATH environment variable:

- Avoids path resolution complexity (varies by execution context)
- Works consistently across local and CI environments
- Caller must set the variable to the library path inside DDEV container
- Fails fast with clear error message if variable is not set

Example usage:
  export BEHAT_CONTEXTS_SOURCE_PATH=/var/www/html
  bats tests/

In GitHub Actions, this will be set in the workflow configuration.
- Aljibe and DDEV setup moved to setup suite
- Load bats lihraries
- Function to prepare each test: create cutom behat.yml, prepare feature
file for the test
Create CI/CD workflow using ddev/github-action-add-on-test@v2:

**Workflow features:**
- Triggers on push/PR to main/dev branches
- Manual workflow dispatch with debug option
- Matrix strategy for DDEV versions (currently 'stable' for PoC)
- Sets BEHAT_CONTEXTS_SOURCE_PATH and GITHUB_TOKEN environment variables
- Uses official DDEV add-on test action for testing
- Runs BATS tests (PoC: cookie-compliance-context.bats)
- Uploads test artifacts on failure (error reports, screenshots, logs)

**PoC scope:**
- Single DDEV version (stable)
- Single test file (cookie-compliance-context.bats)
- Can be expanded later to run all test files

This completes Phase 4 of the BATS testing infrastructure implementation.
@rsanzante rsanzante force-pushed the claude/review-repository-plan-01BuZmqH6qMv9YSwz8g5UP4Y branch from f898477 to bb18d0f Compare November 17, 2025 09:26
@rsanzante rsanzante force-pushed the claude/review-repository-plan-01BuZmqH6qMv9YSwz8g5UP4Y branch from bb18d0f to 220a537 Compare November 17, 2025 09:41
Drop ddev/github-action-add-on-test@v2 action in favor of manual installation
to ensure BATS libraries are properly available:

**Changes:**
- Install BATS via apt-get
- Clone bats-support, bats-assert, and bats-file to /usr/lib/
- Install DDEV using official installation script
- Manually set up DDEV + Aljibe
- Install behat-contexts from local source
- Run BATS tests directly

**Benefits:**
- Full control over BATS libraries installation
- Ensures libraries are accessible at expected paths
- More transparent setup process
- Easier to debug if issues occur

This resolves BATS library loading issues encountered with the ddev action.
Fix BATS library loading issue by setting BATS_LIB_PATH to /usr/lib
where the libraries are installed.

Changes:
- Set BATS_LIB_PATH=/usr/lib in job environment variables
- Add debug output to verify library paths before running tests
- Check for load.bash files in each library directory

This should resolve the "Could not find library 'bats-assert'" error.
@rsanzante rsanzante force-pushed the claude/review-repository-plan-01BuZmqH6qMv9YSwz8g5UP4Y branch 6 times, most recently from 6e11d06 to 0203263 Compare November 17, 2025 11:52
@rsanzante rsanzante force-pushed the claude/review-repository-plan-01BuZmqH6qMv9YSwz8g5UP4Y branch from 1fe15b8 to c87d0a8 Compare November 17, 2025 12:36
rsanzante and others added 6 commits November 17, 2025 14:12
Create detailed documentation for the BATS testing infrastructure:

**tests/README.md:**
- Overview of testing approach and tools
- Prerequisites for local and CI/CD testing
- Step-by-step local testing guide
- Environment variable reference
- Test structure explanation
- How to add new tests guide
- Comprehensive troubleshooting section
- References to BATS, DDEV, and Aljibe documentation

**README.md:**
- Add "Testing" section to table of contents
- Quick start guide for running tests locally
- CI/CD testing overview
- Link to detailed testing documentation

This completes Phase 5 of the BATS testing infrastructure implementation.
@rsanzante rsanzante merged commit de13663 into master Nov 17, 2025
1 check passed
@rsanzante rsanzante deleted the claude/review-repository-plan-01BuZmqH6qMv9YSwz8g5UP4Y branch November 17, 2025 15:02
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.

3 participants