Skip to content
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
215 changes: 215 additions & 0 deletions .github/workflows/ui-tests.yml
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 }}

Comment on lines +112 to +121

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# First, locate and examine the workflow file
find . -path "./.github/workflows/ui-tests.yml" -type f

Repository: POWERFULMOVES/PMOVES.AI

Length of output: 99


🏁 Script executed:

# Check the content of the workflow file around lines 112-121
cat -n .github/workflows/ui-tests.yml | sed -n '100,130p'

Repository: POWERFULMOVES/PMOVES.AI

Length of output: 1213


🏁 Script executed:

# Search for any existing guards or conditionals in the workflow
rg -n "if:" .github/workflows/ui-tests.yml -A 2 -B 2

Repository: POWERFULMOVES/PMOVES.AI

Length of output: 610


🏁 Script executed:

# Look for other secret usage patterns in the file
rg -n "secrets\." .github/workflows/ui-tests.yml

Repository: POWERFULMOVES/PMOVES.AI

Length of output: 116


🏁 Script executed:

# Check the full context of the upload step and surrounding workflow
cat -n .github/workflows/ui-tests.yml | head -n 125

Repository: POWERFULMOVES/PMOVES.AI

Length of output: 4043


🏁 Script executed:

# Look for trigger conditions at the top of the workflow
rg -n "on:" .github/workflows/ui-tests.yml -A 15 | head -n 40

Repository: POWERFULMOVES/PMOVES.AI

Length of output: 1141


🏁 Script executed:

# Check if there are other steps that guard against fork PRs
rg -n "github.event.pull_request.head.repo" .github/workflows/ui-tests.yml

Repository: POWERFULMOVES/PMOVES.AI

Length of output: 49


🏁 Script executed:

# Search for how codecov-action is documented to handle missing tokens
rg -n "codecov" .github/workflows/ui-tests.yml

Repository: POWERFULMOVES/PMOVES.AI

Length of output: 110


🏁 Script executed:

# Search for any documentation or comments about secrets handling in the workflow
rg -n "fork" .github/workflows/ui-tests.yml

Repository: POWERFULMOVES/PMOVES.AI

Length of output: 49


🏁 Script executed:

# Check if there are other workflows in the repo that handle secrets for fork PRs
find .github/workflows -name "*.yml" -o -name "*.yaml" | head -20

Repository: POWERFULMOVES/PMOVES.AI

Length of output: 813


🏁 Script executed:

# Look at other workflows to see if they have similar patterns
rg -n "github.event.pull_request" .github/workflows/ || echo "No matches found"

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_request from a fork, GitHub does not pass repository/org secrets to the runner (except GITHUB_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 of GITHUB_TOKEN, secrets are not passed … when a workflow is triggered from a forked repository” [1].

What this means for codecov/codecov-action

  • If your workflow uses with: token: ${{ secrets.CODECOV_TOKEN }}, that secret will be empty on fork PRs, so uploads that require a token will fail [1][2].
  • For public repos, Codecov supports tokenless uploads for fork PRs (so OSS contributors don’t need your token) [3]. Codecov’s docs also explain tokenless uploads are allowed for public repos when the upload is for an “unprotected” branch name (e.g. forkname:main), and the Codecov action automatically adjusts the branch name for fork PRs to include : starting with v4+ [2].
  • For private repos, Codecov requires a token for all uploads, so fork PRs generally can’t upload coverage from the untrusted workflow run [2].

Practical options

  1. Public repo (recommended): use tokenless for fork PRs
    • Upgrade to a modern Codecov action (v4/v5) and do not require CODECOV_TOKEN for fork PR uploads (or allow tokenless uploads in your Codecov org settings for public repos) [2][3].
  2. Private repo: don’t upload coverage from fork PR runs
    • Keep tests running on fork PRs, but skip the Codecov upload step unless a token is available (since it won’t be on forks) [1][2].
  3. If you consider pull_request_target: be very careful
    • pull_request_target runs 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)

  • Assume fork PR code is untrusted. Design your PR CI so it does not require secrets. GitHub Actions does not pass Actions secrets to workflows triggered by a pull request from a fork. [1]
  • Prefer running untrusted PR checks on the pull_request event (lint/unit tests that don’t need credentials). GitHub notes that pull_request runs 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)

  • Don’t use pull_request_target to run PR code. GitHub explicitly warns that pull_request_target runs 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]
    • If you use pull_request_target, keep it to metadata-only tasks (label/comment) and ensure user-controlled input cannot influence execution. [3][4]
  • Split workflows into two phases:
    1. Untrusted build/test on pull_request (no secrets).
    2. Privileged work (deploy, publishing, integration tests with real credentials) only after trust is established—e.g., on push to protected branches, or via a maintainer-controlled trigger/approval gate.

Hardening controls to enable

  • Require approvals for fork PR workflow runs (especially for public repos) and review workflow changes carefully—GitHub advises being particularly alert to PRs that modify .github/workflows/. [5]
  • In repo/org settings, review fork policies and token/secrets exposure knobs (where applicable), such as:
    • “Send write tokens to workflows from pull requests”
    • “Send secrets to workflows from pull requests”
    • “Require approval for fork pull request workflows” [6]
  • Enforce least privilege for GITHUB_TOKEN using the workflow permissions: key and keep defaults restrictive. [2][4][6]
  • Prefer OIDC over long-lived cloud credentials stored as secrets (reduces secret exfiltration blast radius). [3]

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_request from 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_target with forks increases risk; recommends least privilege / prefer pull_request if 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.url

Repository: POWERFULMOVES/PMOVES.AI

Length of output: 113


🏁 Script executed:

# Also check for any repository metadata files
if [ -f README.md ]; then
  head -20 README.md
fi

Repository: POWERFULMOVES/PMOVES.AI

Length of output: 1866


🏁 Script executed:

# Look for any codecov configuration that might indicate coverage expectations for fork PRs
find . -name "codecov.yml" -o -name ".codecov.yml" -o -name "codecov.json" | xargs cat 2>/dev/null || echo "No codecov config found"

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 an if guard to skip the upload step for fork-based PRs, preventing unnecessary secret attempts in untrusted workflow runs.

Suggested guard
-      - name: Upload coverage reports
+      - name: Upload coverage reports
         uses: codecov/codecov-action@v4
-        if: always()
+        if: always() && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false)
         with:
           files: pmoves/ui/coverage/coverage-final.json
           flags: ui-unit
           name: ui-unit-coverage
           fail_ci_if_error: false
           token: ${{ secrets.CODECOV_TOKEN }}

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
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/ui-tests.yml around lines 112 - 121, Add a guard to the
"Upload coverage reports" step that skips the Codecov upload for forked PRs so
the workflow doesn't reference secrets in untrusted contexts; specifically,
update the step that uses codecov/codecov-action@v4 (and the
secrets.CODECOV_TOKEN) to include an if condition that only runs when the PR
originates from the same repository (for example: if: ${{
github.event.pull_request && github.event.pull_request.head.repo.full_name ==
github.repository }}), ensuring the upload and token are only used for non-fork
PRs.

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
20 changes: 14 additions & 6 deletions pmoves/docs/AGENTS/CODEX_CLAUDE_PARITY_GAPS.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Codex Claude Parity Gaps Report
_Generated: 2026-02-28_
_Generated: 2026-03-13_

## Scope
- Commands source: `.claude\commands`
- Parity map: `pmoves\docs\AGENTS\CODEX_CLAUDE_PARITY_MAP.md`

## Summary
- Claude command tokens: **113**
- Claude command tokens: **117**
- Parity map tokens: **114**
- Mapped tokens: **113**
- Missing tokens: **0**
- Coverage: **100.0%**
- Missing tokens: **4**
- Coverage: **96.6%**

## Prefix Coverage
| Prefix | Claude Tokens | Mapped Tokens | Missing Tokens |
Expand All @@ -19,12 +19,13 @@ _Generated: 2026-02-28_
| `agents` | 5 | 5 | 0 |
| `archon` | 3 | 3 | 0 |
| `botz` | 4 | 4 | 0 |
| `chit` | 6 | 6 | 0 |
| `chit` | 8 | 6 | 2 |
| `cipher` | 3 | 3 | 0 |
| `crush` | 2 | 2 | 0 |
| `db` | 3 | 3 | 0 |
| `deploy` | 7 | 7 | 0 |
| `discord` | 2 | 2 | 0 |
| `docs` | 1 | 0 | 1 |
| `github` | 4 | 4 | 0 |
| `gpu` | 3 | 3 | 0 |
| `health` | 3 | 3 | 0 |
Expand All @@ -41,6 +42,7 @@ _Generated: 2026-02-28_
| `pipecat` | 2 | 2 | 0 |
| `root` | 2 | 2 | 0 |
| `search` | 3 | 3 | 0 |
| `tac` | 1 | 0 | 1 |
| `tensorzero` | 1 | 1 | 0 |
| `test` | 2 | 2 | 0 |
| `tts` | 4 | 4 | 0 |
Expand All @@ -50,4 +52,10 @@ _Generated: 2026-02-28_
| `yt` | 10 | 10 | 0 |

## Missing Tokens by Prefix
- None
- `chit`
- `chit:review-sweep`
- `chit:sign-trail`
- `docs`
- `docs:reconcile`
- `tac`
- `tac:review`
11 changes: 7 additions & 4 deletions pmoves/ui/__tests__/serviceHealth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,13 @@ import {
function captureSetTimeoutMs(): { get: () => number } {
const holder = { value: 0 };
const orig = global.setTimeout;
jest.spyOn(global, 'setTimeout').mockImplementation((fn: TimerHandler, ms?: number) => {
holder.value = ms ?? 0;
return orig(fn, 0); // execute immediately for test speed
});
jest.spyOn(global, 'setTimeout').mockImplementation(
// @ts-expect-error - Mock implementation has different return type
(fn: TimerHandler, ms?: number) => {
holder.value = ms ?? 0;
return orig(fn, 0) as unknown as number;
}
);
return { get: () => holder.value };
}

Expand Down
10 changes: 6 additions & 4 deletions pmoves/ui/__tests__/utils/test-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { ReactElement } from 'react';
import { render, RenderOptions } from '@testing-library/react';
import type { ServiceHealth, ServiceHealthStatus } from '../../lib/serviceHealth';
import type { ServiceHealth } from '../../lib/serviceHealth';
import type { ServiceDefinition, ServiceCategory, ServiceColor } from '../../lib/serviceCatalog';

// =============================================================================
Expand Down Expand Up @@ -102,7 +102,7 @@ export function renderWithAuth(
};
} = {}
) {
const { authOverrides, ...renderOptions } = options;
const { authOverrides: _authOverrides, ...renderOptions } = options;

// TODO: Add actual auth context wrapper when available
return render(ui, renderOptions);
Expand All @@ -113,7 +113,7 @@ export function renderWithAuth(
*/
export function renderWithServiceHealth(
ui: ReactElement,
healthMap: Record<string, ServiceHealth> = {},
_healthMap: Record<string, ServiceHealth> = {},
options: Omit<RenderOptions, 'wrapper'> = {}
) {
// TODO: Add service health context wrapper when available
Expand Down Expand Up @@ -218,7 +218,7 @@ export function clearAllMocks() {
// Export all
// =============================================================================

export default {
const testHelpers = {
mockServiceHealth,
mockServiceHealthMap,
mockServiceEndpoint,
Expand All @@ -233,3 +233,5 @@ export default {
mockFetch,
clearAllMocks,
};

export default testHelpers;
2 changes: 1 addition & 1 deletion pmoves/ui/app/api/chat/messages/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ownerFromJwt } from '@/lib/jwtUtils';
import { logError } from '@/lib/errorUtils';
import { ErrorIds } from '@/lib/constants/errorIds';

export async function GET(req: NextRequest) {
export async function GET(_req: NextRequest) {
const supabase = getServiceSupabaseClient();
// Security: User identity must come from JWT only, never from query params
const { ownerId: jwtOwner, error: jwtError } = ownerFromJwt('chat/messages');
Expand Down
5 changes: 4 additions & 1 deletion pmoves/ui/app/api/health-all/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import { NextRequest, NextResponse } from 'next/server';
import { checkAllServices, checkServiceHealth, getHealthPercentage, getStatusText } from '@/lib/serviceHealth';

export const runtime = 'edge';
// NOTE: Using 'nodejs' runtime instead of 'edge' because Edge runtime
// doesn't support localhost DNS resolution, which is needed for service
// health checks within the Docker network.
export const runtime = 'nodejs';
export const dynamic = 'force-dynamic';

/**
Expand Down
25 changes: 24 additions & 1 deletion pmoves/ui/app/api/health/boot-jwt/route.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
import { NextResponse } from 'next/server';
import { getBootJwt } from '@/lib/supabaseClient';

/**
* Decodes a JWT payload using base64url encoding.
*
* JWT uses base64url encoding which differs from standard base64:
* - '-' (62) instead of '+'
* - '_' (63) instead of '/'
* - No padding '=' characters
*
* This function properly handles base64url decoding.
*/
function decode(token?: string) {
try {
if (!token) return null;
const parts = token.split('.');
if (parts.length !== 3) return null;
const payload = JSON.parse(Buffer.from(parts[1], 'base64').toString('utf-8')) as any;

// Convert base64url to base64 by replacing characters
// base64url: '-' (minus) and '_' (underscore)
// base64: '+' (plus) and '/' (slash)
let base64 = parts[1];
base64 = base64.replace(/-/g, '+');
base64 = base64.replace(/_/g, '/');

// Add padding if needed (base64url omits padding)
while (base64.length % 4) {
base64 += '=';
}

const payload = JSON.parse(Buffer.from(base64, 'base64').toString('utf-8')) as any;
return payload;
} catch {
return null;
Expand Down
Loading
Loading