Repository navigation
fix: UI health check runtime fixes and rate limiting #906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
9c478d4
53dceb0
68d3fdd
d9ede9a
49b0e8c
44f05de
4de5246
07d06f8
a0bf7c6
f0e9e42
4328aaa
ed699c1
1d6cc62
cd08f08
08f2607
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,215 @@ | ||
| name: UI Tests | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main, PMOVES.AI-Edition-Hardened] | ||
| paths: | ||
| - 'pmoves/ui/**' | ||
| - '.github/workflows/ui-tests.yml' | ||
| pull_request: | ||
| branches: [main, PMOVES.AI-Edition-Hardened] | ||
| paths: | ||
| - 'pmoves/ui/**' | ||
| - '.github/workflows/ui-tests.yml' | ||
| workflow_dispatch: | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} | ||
|
|
||
| jobs: | ||
| lint: | ||
| name: Lint (ESLint) | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| steps: | ||
| - name: Harden Runner | ||
| uses: step-security/harden-runner@v2 | ||
| with: | ||
| egress-policy: audit | ||
|
|
||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
| cache: 'npm' | ||
| cache-dependency-path: pmoves/ui/package-lock.json | ||
|
|
||
| - name: Install dependencies | ||
| working-directory: pmoves/ui | ||
| run: npm ci | ||
|
|
||
| - name: Run ESLint | ||
| working-directory: pmoves/ui | ||
| run: npm run lint | ||
|
|
||
| typecheck: | ||
| name: Type Check (TypeScript) | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| steps: | ||
| - name: Harden Runner | ||
| uses: step-security/harden-runner@v2 | ||
| with: | ||
| egress-policy: audit | ||
|
|
||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
| cache: 'npm' | ||
| cache-dependency-path: pmoves/ui/package-lock.json | ||
|
|
||
| - name: Install dependencies | ||
| working-directory: pmoves/ui | ||
| run: npm ci | ||
|
|
||
| - name: Run TypeScript type check | ||
| working-directory: pmoves/ui | ||
| run: npm run typecheck | ||
|
|
||
| unit-tests: | ||
| name: Unit Tests (Jest) | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| actions: read | ||
| checks: write | ||
| steps: | ||
| - name: Harden Runner | ||
| uses: step-security/harden-runner@v2 | ||
| with: | ||
| egress-policy: audit | ||
|
|
||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
| cache: 'npm' | ||
| cache-dependency-path: pmoves/ui/package-lock.json | ||
|
|
||
| - name: Install dependencies | ||
| working-directory: pmoves/ui | ||
| run: npm ci | ||
|
|
||
| - name: Run Jest unit tests | ||
| working-directory: pmoves/ui | ||
| env: | ||
| # Mock Supabase for unit tests | ||
| NEXT_PUBLIC_SUPABASE_URL: http://localhost:54321 | ||
| NEXT_PUBLIC_SUPABASE_ANON_KEY: mock-anon-key | ||
| SUPABASE_SERVICE_ROLE_KEY: mock-service-role-key | ||
| run: npm test -- --ci --coverage --maxWorkers=2 | ||
|
|
||
| - name: Upload coverage reports | ||
| uses: codecov/codecov-action@v4 | ||
| if: always() | ||
| with: | ||
| files: pmoves/ui/coverage/coverage-final.json | ||
| flags: ui-unit | ||
| name: ui-unit-coverage | ||
| fail_ci_if_error: false | ||
| token: ${{ secrets.CODECOV_TOKEN }} | ||
|
|
||
| e2e-tests: | ||
| name: E2E Tests (Playwright) | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| steps: | ||
| - name: Harden Runner | ||
| uses: step-security/harden-runner@v2 | ||
| with: | ||
| egress-policy: audit | ||
|
|
||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
| cache: 'npm' | ||
| cache-dependency-path: pmoves/ui/package-lock.json | ||
|
|
||
| - name: Install dependencies | ||
| working-directory: pmoves/ui | ||
| run: npm ci | ||
|
|
||
| - name: Install Playwright browsers | ||
| working-directory: pmoves/ui | ||
| run: npx playwright install --with-deps | ||
|
|
||
| - name: Run Playwright E2E tests | ||
| working-directory: pmoves/ui | ||
| env: | ||
| # Configure Playwright to use correct port (4482) | ||
| PLAYWRIGHT_HOST: 127.0.0.1 | ||
| PLAYWRIGHT_PORT: 4482 | ||
| # Mock Supabase for E2E tests | ||
| NEXT_PUBLIC_SUPABASE_URL: http://localhost:54321 | ||
| NEXT_PUBLIC_SUPABASE_ANON_KEY: playwright-anon-key | ||
| NEXT_PUBLIC_SUPABASE_BOOT_USER_JWT: playwright-boot-user-jwt | ||
| SUPABASE_SERVICE_ROLE_KEY: playwright-service-role | ||
| run: npm run test:e2e | ||
|
|
||
| - name: Upload Playwright report | ||
| uses: actions/upload-artifact@v4 | ||
| if: always() | ||
| with: | ||
| name: playwright-report | ||
| path: pmoves/ui/playwright-report/ | ||
| retention-days: 7 | ||
|
|
||
| - name: Upload Playwright screenshots | ||
| uses: actions/upload-artifact@v4 | ||
| if: failure() | ||
| with: | ||
| name: playwright-screenshots | ||
| path: pmoves/ui/test-results/ | ||
| retention-days: 7 | ||
|
|
||
| integration-tests: | ||
| name: Integration Tests (API Clients) | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| actions: read | ||
| checks: write | ||
| steps: | ||
| - name: Harden Runner | ||
| uses: step-security/harden-runner@v2 | ||
| with: | ||
| egress-policy: audit | ||
| allowed-endpoints: > | ||
| github.com:443 | ||
| api.github.com:443 | ||
| registry.npmjs.org:443 | ||
| localhost:4482 | ||
| localhost:8086 | ||
| localhost:8093 | ||
| localhost:8098 | ||
|
|
||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
| cache: 'npm' | ||
| cache-dependency-path: pmoves/ui/package-lock.json | ||
|
|
||
| - name: Install dependencies | ||
| working-directory: pmoves/ui | ||
| run: npm ci | ||
|
|
||
| - name: Run API client integration tests | ||
| working-directory: pmoves/ui | ||
| run: npm test -- --testPathPattern="lib/api/.*\.test\.ts$" --ci | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,13 @@ import { getServiceSupabaseClient } from '@/lib/supabaseServer'; | |
| const DEFAULT_BUCKET = process.env.NEXT_PUBLIC_UPLOAD_BUCKET || process.env.PMOVES_UPLOAD_BUCKET || 'assets'; | ||
| const DEFAULT_NAMESPACE = process.env.PMOVES_DEFAULT_NAMESPACE || 'pmoves'; | ||
| const SMOKE_SECRET = process.env.SMOKE_SHARED_SECRET || process.env.PMOVES_SMOKE_SHARED_SECRET; | ||
| const SINGLE_USER = String(process.env.NEXT_PUBLIC_SINGLE_USER_MODE || process.env.SINGLE_USER_MODE || '1') === '1'; | ||
|
|
||
| /** | ||
| * SECURITY: Default to requiring authentication. | ||
| * Set SINGLE_USER_MODE=1 or NEXT_PUBLIC_SINGLE_USER_MODE=1 explicitly to enable | ||
| * single-user mode without auth for development. | ||
| */ | ||
| const SINGLE_USER = String(process.env.NEXT_PUBLIC_SINGLE_USER_MODE || process.env.SINGLE_USER_MODE || '0') === '1'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Find all SINGLE_USER_MODE default values in the codebase
rg -n "SINGLE_USER_MODE.*\|\|.*['\"][01]['\"]" pmoves/ui/Repository: POWERFULMOVES/PMOVES.AI Length of output: 382 🏁 Script executed: # Check context around both files
echo "=== ingest-smoke/route.ts context ===" && \
sed -n '10,20p' pmoves/ui/app/api/health/ingest-smoke/route.ts && \
echo -e "\n=== DashboardNavigation.tsx context ===" && \
sed -n '60,75p' pmoves/ui/components/DashboardNavigation.tsxRepository: POWERFULMOVES/PMOVES.AI Length of output: 1496 Inconsistent SINGLE_USER_MODE defaults across codebase. This file defaults const singleUser =
String(process.env.NEXT_PUBLIC_SINGLE_USER_MODE || process.env.SINGLE_USER_MODE || '1') === '1';The ingest-smoke endpoint has an explicit security comment documenting this choice, but the dashboard navigation has the opposite default. This could cause confusion where the dashboard behaves as single-user mode while the health check endpoint requires authentication. 🤖 Prompt for AI Agents |
||
|
|
||
| async function getBootUserId(): Promise<string | null> { | ||
| const email = process.env.SUPABASE_BOOT_USER_EMAIL; | ||
|
|
@@ -31,11 +37,25 @@ export async function POST(request: NextRequest) { | |
| // Auth: allow in single-user mode, else require the shared secret | ||
| if (!SINGLE_USER) { | ||
| if (!SMOKE_SECRET) { | ||
| return NextResponse.json({ error: 'SMOKE_SHARED_SECRET not set' }, { status: 500 }); | ||
| return NextResponse.json( | ||
| { | ||
| error: 'SMOKE_SHARED_SECRET not set', | ||
| message: 'Authentication is required but SMOKE_SHARED_SECRET is not configured. ' | ||
| + 'Set SMOKE_SHARED_SECRET in your environment or enable single-user mode ' | ||
| + 'by setting SINGLE_USER_MODE=1 for development.', | ||
| }, | ||
| { status: 500 } | ||
| ); | ||
| } | ||
| const auth = request.headers.get('authorization') || ''; | ||
| if (auth !== `Bearer ${SMOKE_SECRET}`) { | ||
| return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); | ||
| return NextResponse.json( | ||
| { | ||
| error: 'Unauthorized', | ||
| message: 'Valid Bearer token required in Authorization header', | ||
| }, | ||
| { status: 401 } | ||
| ); | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: POWERFULMOVES/PMOVES.AI
Length of output: 99
🏁 Script executed:
Repository: POWERFULMOVES/PMOVES.AI
Length of output: 1213
🏁 Script executed:
Repository: POWERFULMOVES/PMOVES.AI
Length of output: 610
🏁 Script executed:
Repository: POWERFULMOVES/PMOVES.AI
Length of output: 116
🏁 Script executed:
Repository: POWERFULMOVES/PMOVES.AI
Length of output: 4043
🏁 Script executed:
Repository: POWERFULMOVES/PMOVES.AI
Length of output: 1141
🏁 Script executed:
Repository: POWERFULMOVES/PMOVES.AI
Length of output: 49
🏁 Script executed:
Repository: POWERFULMOVES/PMOVES.AI
Length of output: 110
🏁 Script executed:
Repository: POWERFULMOVES/PMOVES.AI
Length of output: 49
🏁 Script executed:
Repository: POWERFULMOVES/PMOVES.AI
Length of output: 813
🏁 Script executed:
Repository: POWERFULMOVES/PMOVES.AI
Length of output: 295
🌐 Web query:
codecov-action fork PR secrets unavailable GitHub Actions💡 Result:
On GitHub Actions, this is expected behavior: for workflows triggered by
pull_requestfrom a fork, GitHub does not pass repository/org secrets to the runner (exceptGITHUB_TOKEN, which is also reduced to minimal/read-only permissions) to prevent secret exfiltration by untrusted code in the PR [1]. GitHub explicitly documents: “With the exception ofGITHUB_TOKEN, secrets are not passed … when a workflow is triggered from a forked repository” [1].What this means for
codecov/codecov-actionwith: token: ${{ secrets.CODECOV_TOKEN }}, that secret will be empty on fork PRs, so uploads that require a token will fail [1][2].forkname:main), and the Codecov action automatically adjusts the branch name for fork PRs to include:starting with v4+ [2].Practical options
CODECOV_TOKENfor fork PR uploads (or allow tokenless uploads in your Codecov org settings for public repos) [2][3].pull_request_target: be very carefulpull_request_targetruns in the context of the base repo and can access secrets even for fork PRs, which is why it’s considered risky if you check out / run untrusted PR code [4].Sources: GitHub secrets behavior [1], Codecov token requirements and tokenless rules [2], Codecov action notes about fork PR tokenless support [3], GitHub security rationale for fork PR restrictions [4].
🌐 Web query:
GitHub Actions fork pull request secrets access best practices💡 Result:
What to do for fork-based PRs (best practice)
pull_requestevent (lint/unit tests that don’t need credentials). GitHub notes thatpull_requestruns from forks with no secrets and a read-only token, which limits impact if someone tries to exfiltrate data. [2]If you must use secrets with PRs (common safe patterns)
pull_request_targetto run PR code. GitHub explicitly warns thatpull_request_targetruns in the base-repo context with access to repo secrets and typically write permissions, and becomes dangerous if you check out/execute PR code (“pwn request”). [3]pull_request_target, keep it to metadata-only tasks (label/comment) and ensure user-controlled input cannot influence execution. [3][4]pull_request(no secrets).Hardening controls to enable
.github/workflows/. [5]GITHUB_TOKENusing the workflowpermissions:key and keep defaults restrictive. [2][4][6]Key rule of thumb
If a workflow can be influenced by fork PR code/inputs, don’t give it secrets; if a workflow needs secrets, ensure it cannot execute untrusted PR code and is gated (approvals/environments/protected branches). [3][4][6]
Sources
[1] GitHub Docs – “Actions secrets … are not passed to workflows that are triggered by a pull request from a fork.” (docs.github.com)
[2] GitHub Blog (Security) –
pull_requestfrom forks runs with no secrets + read-only token. (github.blog)[3] GitHub Well-Architected – avoid
pull_request_target; explains “pwn request” risk. (wellarchitected.github.com)[4] GitHub Changelog (2025-11-07) –
pull_request_targetwith forks increases risk; recommends least privilege / preferpull_requestif no secrets needed. (github.blog)[5] GitHub Docs – approving runs from forks; be alert to
.github/workflows/changes. (docs.github.com)[6] GitHub Docs – repo settings for fork PR workflows; “send write tokens/secrets”, approval requirements, and token permissions. (docs.github.com)
Citations:
🏁 Script executed:
# Check if the repository is public or private by looking at git config git config --get remote.origin.urlRepository: POWERFULMOVES/PMOVES.AI
Length of output: 113
🏁 Script executed:
Repository: POWERFULMOVES/PMOVES.AI
Length of output: 1866
🏁 Script executed:
Repository: POWERFULMOVES/PMOVES.AI
Length of output: 49
Guard Codecov upload for fork PRs to prevent secret reference in untrusted contexts
Line 120 references
secrets.CODECOV_TOKEN, which is unavailable on fork PRs per GitHub Actions security controls. Add anifguard to skip the upload step for fork-based PRs, preventing unnecessary secret attempts in untrusted workflow runs.Suggested guard
This aligns with the coding guideline to maintain secret-handling paths and follows GitHub's recommended pattern for fork PR workflows.
🤖 Prompt for AI Agents