refactor: consolidate tests, convert comments to English, fix linting #52
Workflow file for this run
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
| name: CI | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| env: | |
| CARGO_TERM_COLOR: always | |
| jobs: | |
| # Quick checks first (fastest feedback) | |
| check: | |
| name: Check & Lint | |
| runs-on: ubuntu-latest | |
| outputs: | |
| cache-key: ${{ steps.cache-key.outputs.key }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| toolchain: stable | |
| components: rustfmt, clippy | |
| - name: Generate cache key | |
| id: cache-key | |
| run: echo "key=cargo-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}" >> $GITHUB_OUTPUT | |
| - name: Cache cargo | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cargo/bin/ | |
| ~/.cargo/registry/index/ | |
| ~/.cargo/registry/cache/ | |
| ~/.cargo/git/db/ | |
| target/ | |
| key: ${{ steps.cache-key.outputs.key }} | |
| restore-keys: | | |
| cargo-${{ runner.os }}- | |
| - name: Check | |
| run: cargo check --all-features | |
| - name: Format | |
| run: cargo fmt -- --check | |
| - name: Clippy | |
| run: cargo clippy --all-features -- -D warnings | |
| # Core tests (shared by matrix) | |
| test: | |
| name: Test (${{ matrix.os }}) | |
| runs-on: ${{ matrix.os }} | |
| needs: check | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest, macos-latest] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Restore cache | |
| uses: actions/cache/restore@v4 | |
| with: | |
| path: | | |
| ~/.cargo/bin/ | |
| ~/.cargo/registry/index/ | |
| ~/.cargo/registry/cache/ | |
| ~/.cargo/git/db/ | |
| target/ | |
| key: ${{ needs.check.outputs.cache-key }} | |
| restore-keys: | | |
| cargo-${{ runner.os }}- | |
| - name: Configure git | |
| run: | | |
| git config --global user.name "Test User" | |
| git config --global user.email "[email protected]" | |
| git config --global init.defaultBranch main | |
| - name: Run tests | |
| run: cargo test --tests -- --test-threads=1 | |
| env: | |
| RUST_BACKTRACE: 1 | |
| CI: true | |
| # Build (only on Ubuntu for artifacts) | |
| build: | |
| name: Build | |
| runs-on: ubuntu-latest | |
| needs: check | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Restore cache | |
| uses: actions/cache/restore@v4 | |
| with: | |
| path: | | |
| ~/.cargo/bin/ | |
| ~/.cargo/registry/index/ | |
| ~/.cargo/registry/cache/ | |
| ~/.cargo/git/db/ | |
| target/ | |
| key: ${{ needs.check.outputs.cache-key }} | |
| restore-keys: | | |
| cargo-${{ runner.os }}- | |
| - name: Build release | |
| run: cargo build --release --all-features | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: gw-ubuntu | |
| path: target/release/gw | |
| # Coverage and detailed analysis (only on PR and main pushes) | |
| coverage: | |
| name: Coverage & Analysis | |
| runs-on: ubuntu-latest | |
| needs: [check, test] | |
| if: github.event_name == 'pull_request' || github.ref == 'refs/heads/main' | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Restore cache | |
| uses: actions/cache/restore@v4 | |
| with: | |
| path: | | |
| ~/.cargo/bin/ | |
| ~/.cargo/registry/index/ | |
| ~/.cargo/registry/cache/ | |
| ~/.cargo/git/db/ | |
| target/ | |
| key: ${{ needs.check.outputs.cache-key }} | |
| restore-keys: | | |
| cargo-${{ runner.os }}- | |
| - name: Install cargo-tarpaulin | |
| run: cargo install cargo-tarpaulin --locked | |
| - name: Configure git | |
| run: | | |
| git config --global user.name "Test User" | |
| git config --global user.email "[email protected]" | |
| git config --global init.defaultBranch main | |
| - name: Generate coverage | |
| run: | | |
| cargo tarpaulin --out xml --output-dir coverage --all-features --bins --tests --timeout 180 --verbose | |
| - name: Analyze test results | |
| id: analysis | |
| run: | | |
| # Coverage calculation | |
| COVERAGE=$(python3 -c " | |
| import xml.etree.ElementTree as ET | |
| try: | |
| tree = ET.parse('coverage/cobertura.xml') | |
| root = tree.getroot() | |
| line_rate = float(root.get('line-rate', 0)) | |
| coverage_percent = line_rate * 100 | |
| print(f'{coverage_percent:.1f}') | |
| except: | |
| print('0.0') | |
| ") | |
| # Test category analysis | |
| TOTAL_TESTS=$(cargo test --bins --tests 2>&1 | grep "test result:" | sed 's/.*ok\. \([0-9][0-9]*\) passed.*/\1/' | awk '{sum += $1} END {print sum ? sum : 0}') | |
| SECURITY_TESTS=$(cargo test --test security_critical_test --test unified_validation_comprehensive_test 2>&1 | grep "test result:" | sed 's/.*ok\. \([0-9][0-9]*\) passed.*/\1/' | awk '{sum += $1} END {print sum ? sum : 0}') | |
| WORKTREE_TESTS=$(cargo test --test unified_worktree_creation_comprehensive_test --test unified_remove_worktree_test --test unified_rename_worktree_test 2>&1 | grep "test result:" | sed 's/.*ok\. \([0-9][0-9]*\) passed.*/\1/' | awk '{sum += $1} END {print sum ? sum : 0}') | |
| GIT_TESTS=$(cargo test --test unified_git_comprehensive_test 2>&1 | grep "test result:" | sed 's/.*ok\. \([0-9][0-9]*\) passed.*/\1/' | awk '{sum += $1} END {print sum ? sum : 0}') | |
| # Count test files dynamically | |
| TOTAL_TEST_FILES=$(find tests/ -name "*.rs" -type f | wc -l | tr -d ' ') | |
| UNIFIED_TEST_FILES=$(find tests/ -name "unified_*.rs" -type f | wc -l | tr -d ' ') | |
| # Calculate reduction percentage | |
| REDUCTION_PERCENT=$(echo "scale=1; ($UNIFIED_TEST_FILES / $TOTAL_TEST_FILES) * 100" | bc -l) | |
| REDUCTION_PERCENT=${REDUCTION_PERCENT%.*} # Remove decimal part | |
| echo "coverage=${COVERAGE}" >> $GITHUB_OUTPUT | |
| echo "total_tests=${TOTAL_TESTS}" >> $GITHUB_OUTPUT | |
| echo "security_tests=${SECURITY_TESTS}" >> $GITHUB_OUTPUT | |
| echo "worktree_tests=${WORKTREE_TESTS}" >> $GITHUB_OUTPUT | |
| echo "git_tests=${GIT_TESTS}" >> $GITHUB_OUTPUT | |
| echo "total_test_files=${TOTAL_TEST_FILES}" >> $GITHUB_OUTPUT | |
| echo "unified_test_files=${UNIFIED_TEST_FILES}" >> $GITHUB_OUTPUT | |
| echo "reduction_percent=${REDUCTION_PERCENT}" >> $GITHUB_OUTPUT | |
| - name: Comment PR with results | |
| if: github.event_name == 'pull_request' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const coverage = '${{ steps.analysis.outputs.coverage }}'; | |
| const totalTests = '${{ steps.analysis.outputs.total_tests }}'; | |
| const securityTests = '${{ steps.analysis.outputs.security_tests }}'; | |
| const worktreeTests = '${{ steps.analysis.outputs.worktree_tests }}'; | |
| const gitTests = '${{ steps.analysis.outputs.git_tests }}'; | |
| const totalTestFiles = '${{ steps.analysis.outputs.total_test_files }}'; | |
| const unifiedTestFiles = '${{ steps.analysis.outputs.unified_test_files }}'; | |
| const reductionPercent = '${{ steps.analysis.outputs.reduction_percent }}'; | |
| const comment = `## 📊 CI Results | |
| **✅ All Checks Passed** | |
| ### 📋 Coverage & Testing | |
| - **Coverage**: ${coverage}% | |
| - **Total Tests**: ${totalTests} | |
| - **Security Tests**: ${securityTests} | |
| - **Worktree Tests**: ${worktreeTests} | |
| - **Git Operations**: ${gitTests} | |
| ### 🎯 Quality Metrics | |
| ${coverage >= 70 ? '✅' : coverage >= 50 ? '⚠️' : '❌'} Coverage: ${coverage}% | |
| ✅ Linting: All clippy warnings resolved | |
| ✅ Formatting: Code properly formatted | |
| ✅ Security: Comprehensive protection validated | |
| ### 🚀 Build Status | |
| - **Ubuntu**: ✅ Passed | |
| - **macOS**: ✅ Passed | |
| - **Artifacts**: ✅ Generated | |
| ### 📦 Test Suite Optimization | |
| - **Test Files**: ${totalTestFiles} total (${unifiedTestFiles} unified) | |
| - **Structure**: Consolidated and comprehensive test coverage | |
| - **Efficiency**: ${reductionPercent}% of files are unified tests`; | |
| github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: comment | |
| }); | |
| # Security-focused tests (separate job for clarity) | |
| security: | |
| name: Security Validation | |
| runs-on: ubuntu-latest | |
| needs: [check, test] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Restore cache | |
| uses: actions/cache/restore@v4 | |
| with: | |
| path: | | |
| ~/.cargo/bin/ | |
| ~/.cargo/registry/index/ | |
| ~/.cargo/registry/cache/ | |
| ~/.cargo/git/db/ | |
| target/ | |
| key: ${{ needs.check.outputs.cache-key }} | |
| restore-keys: | | |
| cargo-${{ runner.os }}- | |
| - name: Configure git | |
| run: | | |
| git config --global user.name "Test User" | |
| git config --global user.email "[email protected]" | |
| git config --global init.defaultBranch main | |
| - name: Run security tests | |
| run: | | |
| echo "🔒 Running security validation..." | |
| cargo test --test security_critical_test --verbose | |
| cargo test --test unified_validation_comprehensive_test --verbose | |
| echo "✅ Security tests completed successfully" |