test: add comprehensive API endpoint tests #306
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: Feedback Loop Metrics | |
| on: | |
| push: | |
| branches: ["**"] | |
| pull_request: | |
| branches: ["**"] | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| issues: write | |
| jobs: | |
| collect-and-analyze: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 # Full history for git diff analysis | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.10' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Run tests with metrics collection | |
| run: | | |
| pytest tests/ -v --metrics-output=metrics_ci.json --enable-metrics || true | |
| continue-on-error: true | |
| - name: Analyze git diff for pattern violations | |
| if: github.event_name == 'pull_request' | |
| run: | | |
| python -m metrics.integrate analyze-commit \ | |
| --base=${{ github.event.pull_request.base.sha }} \ | |
| --head=${{ github.sha }} \ | |
| --output=commit_analysis.json || true | |
| continue-on-error: true | |
| - name: Analyze metrics and update patterns | |
| run: | | |
| python -m metrics.integrate analyze \ | |
| --metrics-file=metrics_ci.json \ | |
| --patterns-file=patterns.json || true | |
| continue-on-error: true | |
| - name: Generate pattern report | |
| run: | | |
| python -m metrics.integrate report \ | |
| --metrics-file=metrics_ci.json \ | |
| --format=markdown \ | |
| --output=pattern_report.md || true | |
| continue-on-error: true | |
| - name: Comment on PR with recommendations | |
| if: github.event_name == 'pull_request' && hashFiles('pattern_report.md') != '' | |
| uses: actions/github-script@v6 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| let report = ''; | |
| // Read pattern report | |
| if (fs.existsSync('pattern_report.md')) { | |
| report = fs.readFileSync('pattern_report.md', 'utf8'); | |
| } | |
| // Read commit analysis if available | |
| let commitAnalysis = ''; | |
| if (fs.existsSync('commit_analysis.json')) { | |
| const analysis = JSON.parse(fs.readFileSync('commit_analysis.json', 'utf8')); | |
| if (analysis.violations && analysis.violations.length > 0) { | |
| commitAnalysis = '\n## Pattern Violations Detected\n\n'; | |
| for (const violation of analysis.violations.slice(0, 5)) { | |
| commitAnalysis += `- **${violation.pattern}**: ${violation.description}\n`; | |
| commitAnalysis += ` - File: \`${violation.file}\`\n`; | |
| if (violation.suggestion) { | |
| commitAnalysis += ` - Suggestion: ${violation.suggestion}\n`; | |
| } | |
| commitAnalysis += '\n'; | |
| } | |
| } | |
| } | |
| const body = `## 🔄 Feedback Loop Analysis\n\n${commitAnalysis}\n${report}`; | |
| // Check if comment already exists | |
| const comments = await github.rest.issues.listComments({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| }); | |
| const existingComment = comments.data.find(comment => | |
| comment.body.includes('🔄 Feedback Loop Analysis') | |
| ); | |
| if (existingComment) { | |
| // Update existing comment | |
| await github.rest.issues.updateComment({ | |
| comment_id: existingComment.id, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: body | |
| }); | |
| } else { | |
| // Create new comment | |
| await github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: body | |
| }); | |
| } | |
| - name: Upload metrics artifacts | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: metrics-data | |
| path: | | |
| metrics_ci.json | |
| patterns.json | |
| pattern_report.md | |
| commit_analysis.json | |
| retention-days: 30 | |
| - name: Upload patterns to artifacts | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: pattern-library | |
| path: patterns.json | |
| retention-days: 90 |