|
| 1 | +name: "Showcase: Aimock E2E Tests" |
| 2 | + |
| 3 | +on: |
| 4 | + issue_comment: |
| 5 | + types: [created] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + slug: |
| 9 | + description: "Package slug to test (e.g. langgraph-python), or 'all'" |
| 10 | + required: false |
| 11 | + default: "langgraph-python" |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: read |
| 15 | + pull-requests: write |
| 16 | + issues: write |
| 17 | + |
| 18 | +jobs: |
| 19 | + aimock-e2e: |
| 20 | + # Only run on PR comments matching /test-aimock, or manual dispatch |
| 21 | + if: > |
| 22 | + github.event_name == 'workflow_dispatch' || |
| 23 | + (github.event.issue.pull_request && contains(github.event.comment.body, '/test-aimock')) |
| 24 | + runs-on: ubuntu-latest |
| 25 | + timeout-minutes: 15 |
| 26 | + |
| 27 | + steps: |
| 28 | + # For issue_comment events, we need to resolve the PR HEAD SHA ourselves |
| 29 | + # because the event payload doesn't include pull_request.head.sha |
| 30 | + - name: Resolve PR HEAD ref |
| 31 | + id: pr-ref |
| 32 | + if: github.event_name == 'issue_comment' |
| 33 | + uses: actions/github-script@v7 |
| 34 | + with: |
| 35 | + script: | |
| 36 | + const { data: pr } = await github.rest.pulls.get({ |
| 37 | + owner: context.repo.owner, |
| 38 | + repo: context.repo.repo, |
| 39 | + pull_number: context.issue.number, |
| 40 | + }); |
| 41 | + core.setOutput('ref', pr.head.sha); |
| 42 | + core.setOutput('pr_number', pr.number); |
| 43 | +
|
| 44 | + - uses: actions/checkout@v4 |
| 45 | + with: |
| 46 | + ref: ${{ steps.pr-ref.outputs.ref || github.sha }} |
| 47 | + |
| 48 | + - uses: actions/setup-node@v4 |
| 49 | + with: |
| 50 | + node-version: 22.x |
| 51 | + |
| 52 | + - uses: pnpm/action-setup@v4 |
| 53 | + with: |
| 54 | + version: "10.13.1" |
| 55 | + |
| 56 | + - name: Determine slug |
| 57 | + id: slug |
| 58 | + run: | |
| 59 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 60 | + echo "slug=${{ github.event.inputs.slug }}" >> "$GITHUB_OUTPUT" |
| 61 | + else |
| 62 | + COMMENT="${{ github.event.comment.body }}" |
| 63 | + SLUG=$(echo "$COMMENT" | grep -oP '/test-aimock\s+\K\S+' || echo "langgraph-python") |
| 64 | + echo "slug=$SLUG" >> "$GITHUB_OUTPUT" |
| 65 | + fi |
| 66 | +
|
| 67 | + - name: Detect package type |
| 68 | + id: pkg-type |
| 69 | + run: | |
| 70 | + SLUG="${{ steps.slug.outputs.slug }}" |
| 71 | + PKG_DIR="showcase/packages/$SLUG" |
| 72 | + if [ -f "$PKG_DIR/requirements.txt" ] || [ -f "$PKG_DIR/pyproject.toml" ]; then |
| 73 | + echo "has_python=true" >> "$GITHUB_OUTPUT" |
| 74 | + else |
| 75 | + echo "has_python=false" >> "$GITHUB_OUTPUT" |
| 76 | + fi |
| 77 | +
|
| 78 | + - name: Start aimock |
| 79 | + run: | |
| 80 | + npm install -g @copilotkit/aimock@latest |
| 81 | + npx aimock --port 4010 --host 127.0.0.1 --fixtures showcase/aimock/feature-parity.json --validate-on-load & |
| 82 | + # Wait for aimock to be ready |
| 83 | + for i in $(seq 1 20); do |
| 84 | + curl -sf http://localhost:4010/ > /dev/null 2>&1 && break |
| 85 | + sleep 1 |
| 86 | + done |
| 87 | + curl -sf http://localhost:4010/ || { echo "aimock failed to start"; exit 1; } |
| 88 | +
|
| 89 | + - name: Setup Python agent |
| 90 | + if: steps.pkg-type.outputs.has_python == 'true' |
| 91 | + uses: actions/setup-python@v5 |
| 92 | + with: |
| 93 | + python-version: "3.12" |
| 94 | + |
| 95 | + - name: Start Python agent |
| 96 | + if: steps.pkg-type.outputs.has_python == 'true' |
| 97 | + run: | |
| 98 | + SLUG="${{ steps.slug.outputs.slug }}" |
| 99 | + cd "showcase/packages/$SLUG" |
| 100 | + pip install -r requirements.txt |
| 101 | + OPENAI_BASE_URL=http://localhost:4010/v1 OPENAI_API_KEY=test-key python -m uvicorn agent:app --host 127.0.0.1 --port 8000 & |
| 102 | + # Wait for agent to be ready |
| 103 | + for i in $(seq 1 30); do |
| 104 | + curl -sf http://localhost:8000/health > /dev/null 2>&1 && break |
| 105 | + curl -sf http://localhost:8000/ > /dev/null 2>&1 && break |
| 106 | + sleep 2 |
| 107 | + done |
| 108 | +
|
| 109 | + - name: Install package dependencies |
| 110 | + run: | |
| 111 | + SLUG="${{ steps.slug.outputs.slug }}" |
| 112 | + cd "showcase/packages/$SLUG" |
| 113 | + pnpm install |
| 114 | +
|
| 115 | + - name: Start dev server |
| 116 | + run: | |
| 117 | + SLUG="${{ steps.slug.outputs.slug }}" |
| 118 | + cd "showcase/packages/$SLUG" |
| 119 | + OPENAI_BASE_URL=http://localhost:4010/v1 \ |
| 120 | + OPENAI_API_KEY=test-key \ |
| 121 | + AGENT_URL=http://localhost:8000 \ |
| 122 | + pnpm dev & |
| 123 | + # Wait for dev server |
| 124 | + for i in $(seq 1 30); do |
| 125 | + curl -sf http://localhost:3000 > /dev/null 2>&1 && break |
| 126 | + sleep 2 |
| 127 | + done |
| 128 | + curl -sf http://localhost:3000 || { echo "Dev server failed to start"; exit 1; } |
| 129 | +
|
| 130 | + - name: Install Playwright |
| 131 | + run: | |
| 132 | + cd "showcase/packages/${{ steps.slug.outputs.slug }}" |
| 133 | + npx playwright install chromium --with-deps |
| 134 | +
|
| 135 | + - name: Run Playwright tests |
| 136 | + run: | |
| 137 | + SLUG="${{ steps.slug.outputs.slug }}" |
| 138 | + cd "showcase/packages/$SLUG" |
| 139 | + BASE_URL=http://localhost:3000 npx playwright test --reporter=list |
| 140 | + env: |
| 141 | + CI: "true" |
| 142 | + OPENAI_BASE_URL: http://localhost:4010/v1 |
| 143 | + OPENAI_API_KEY: test-key |
| 144 | + |
| 145 | + - name: Upload test artifacts |
| 146 | + if: always() |
| 147 | + uses: actions/upload-artifact@v4 |
| 148 | + with: |
| 149 | + name: playwright-report-${{ steps.slug.outputs.slug }} |
| 150 | + path: showcase/packages/${{ steps.slug.outputs.slug }}/playwright-report/ |
| 151 | + retention-days: 7 |
| 152 | + if-no-files-found: ignore |
| 153 | + |
| 154 | + - name: Post result to PR |
| 155 | + if: github.event_name == 'issue_comment' && always() |
| 156 | + uses: actions/github-script@v7 |
| 157 | + with: |
| 158 | + script: | |
| 159 | + const status = '${{ job.status }}' === 'success' ? '✅' : '❌'; |
| 160 | + const slug = '${{ steps.slug.outputs.slug }}'; |
| 161 | + const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`; |
| 162 | + await github.rest.issues.createComment({ |
| 163 | + owner: context.repo.owner, |
| 164 | + repo: context.repo.repo, |
| 165 | + issue_number: context.issue.number, |
| 166 | + body: `${status} **Aimock E2E Tests** (\`${slug}\`): ${{ job.status }}\n\n[View run](${runUrl})` |
| 167 | + }); |
0 commit comments