From 0659b08d0bb5de266371e3e98c72807b3ae2d92f Mon Sep 17 00:00:00 2001 From: David Garcia Ruiz Date: Thu, 17 Jul 2025 19:48:34 +0200 Subject: [PATCH 1/3] docs: add local testing instructions and new test coverage script --- README.md | 18 ++++++++++++++++++ scripts/test_with_coverage.sh | 30 ++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100755 scripts/test_with_coverage.sh diff --git a/README.md b/README.md index 4d6e966..25d10f6 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,23 @@ The setup script will: - Initialize Husky for git hooks (if present) - Add `.fvm/` to `.gitignore` if needed +## Testing + +### Local Testing + +Run tests with coverage locally: + +```bash +# Using the provided script (recommended) +./scripts/test_with_coverage.sh + +# Or manually +fvm flutter test --coverage +lcov --summary coverage/lcov.info +genhtml coverage/lcov.info -o coverage/html +open coverage/html/index.html +``` + ## Contributing Contributions are welcome! Please: @@ -38,6 +55,7 @@ Contributions are welcome! Please: - Follow the existing code style and patterns - Write clear commit messages (Commitlint and Husky are enabled) - Add or update tests for new features or bug fixes +- Ensure all tests pass before submitting a pull request - Open a pull request with a clear description ## License diff --git a/scripts/test_with_coverage.sh b/scripts/test_with_coverage.sh new file mode 100755 index 0000000..4815d16 --- /dev/null +++ b/scripts/test_with_coverage.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Flutter Policy Engine - Test with Coverage Script +# This script runs all tests and generates coverage reports + +set -e # Exit on any error + +echo "๐Ÿงช Running Flutter tests with coverage..." + +# Run tests with coverage +fvm flutter test --coverage + +echo "๐Ÿ“Š Generating coverage summary..." +lcov --summary coverage/lcov.info + +echo "๐ŸŒ Generating HTML coverage report..." +genhtml coverage/lcov.info -o coverage/html + +echo "โœ… Coverage report generated successfully!" +echo "๐Ÿ“ HTML report available at: coverage/html/index.html" + +# Open the coverage report in browser (macOS) +if [[ "$OSTYPE" == "darwin"* ]]; then + echo "๐Ÿ”— Opening coverage report in browser..." + open coverage/html/index.html +else + echo "๐Ÿ“– To view the coverage report, open: coverage/html/index.html" +fi + +echo "๐ŸŽ‰ Test coverage process completed!" \ No newline at end of file From d5b67a9f78b59c4046a395036e79036e878095ed Mon Sep 17 00:00:00 2001 From: David Garcia Ruiz Date: Thu, 17 Jul 2025 19:53:01 +0200 Subject: [PATCH 2/3] ci: add GitHub Actions workflow for Flutter tests and coverage --- .github/workflows/test.yml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..b8d3c1b --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,33 @@ +name: Flutter Tests & Coverage + +on: + push: + branches: [main, develop] + pull_request: + branches: [main, develop] + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Flutter + uses: subosito/flutter-action@v2 + with: + flutter-version: "3.29.3" + channel: "stable" + + - name: Install dependencies + run: flutter pub get + + - name: Verify formatting + run: dart format --set-exit-if-changed . + + - name: Analyze project source + run: flutter analyze + + - name: Run tests with coverage + run: flutter test --coverage From b52cfa75320bb25bb0545b006e0f1ede6bf01934 Mon Sep 17 00:00:00 2001 From: David Garcia Ruiz Date: Thu, 17 Jul 2025 20:30:41 +0200 Subject: [PATCH 3/3] ci: update Flutter workflow to specify architecture and add validation for merge source branch --- .github/workflows/test.yml | 2 +- .github/workflows/validate-resource.yml | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/validate-resource.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b8d3c1b..1fd7a83 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,7 +18,7 @@ jobs: uses: subosito/flutter-action@v2 with: flutter-version: "3.29.3" - channel: "stable" + architecture: "x64" - name: Install dependencies run: flutter pub get diff --git a/.github/workflows/validate-resource.yml b/.github/workflows/validate-resource.yml new file mode 100644 index 0000000..21ab3ed --- /dev/null +++ b/.github/workflows/validate-resource.yml @@ -0,0 +1,15 @@ +name: Validate merge source +on: + pull_request: + branches: [main] + +jobs: + validate: + runs-on: ubuntu-latest + steps: + - name: Check source branch + run: | + if [ "${{ github.head_ref }}" != "develop" ]; then + echo "Error: Only develop branch can merge to main" + exit 1 + fi