From 786c14c56db30203dca1347ab101c133f5435105 Mon Sep 17 00:00:00 2001 From: CodewithJha <155089480+CodewithJha@users.noreply.github.com> Date: Mon, 23 Nov 2026 01:23:25 +0530 Subject: [PATCH 01/10] fix(test): isolate seeded browsers and exercise canonical fixtures (T-117) --- .dockerignore | 6 + .github/workflows/e2e.yml | 49 ++++---- docker/e2e.compose.yaml | 27 ++++ docker/e2e.env | 13 +- docs/18-testing-strategy-and-qa.md | 6 + docs/27-configuration-reference.md | 4 + scripts/e2e_stack.sh | 114 +---------------- web/.prettierignore | 5 + web/e2e/a11y.ts | 2 +- web/e2e/fixtures.ts | 13 +- web/e2e/global-setup.ts | 167 +++++++++++++++++++++++-- web/e2e/global-teardown.ts | 9 -- web/e2e/pages/casebook.ts | 8 +- web/e2e/pages/wizard.ts | 6 +- web/e2e/seed.ts | 19 +++ web/e2e/specs/a11y-sweep.spec.ts | 4 +- web/e2e/specs/investigate-case.spec.ts | 9 +- web/e2e/specs/smoke.spec.ts | 33 +++-- web/e2e/specs/trials.spec.ts | 12 +- web/e2e/with-stack.ts | 26 ++++ web/eslint.config.js | 2 + web/playwright.config.ts | 1 - web/src/features/runs/RunPage.tsx | 1 + web/tsconfig.node.json | 2 +- 24 files changed, 351 insertions(+), 187 deletions(-) create mode 100644 docker/e2e.compose.yaml delete mode 100644 web/e2e/global-teardown.ts create mode 100644 web/e2e/seed.ts create mode 100644 web/e2e/with-stack.ts diff --git a/.dockerignore b/.dockerignore index 30728c4e..90c116db 100644 --- a/.dockerignore +++ b/.dockerignore @@ -14,6 +14,12 @@ !docker/web/ **/node_modules/ web/dist/ +web/coverage/ +web/playwright-report/ +web/test-results/ +web/e2e-results/ +web/e2e-artifacts/ +web/.lighthouseci/ **/__pycache__/ **/*.py[cod] **/.DS_Store diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index dc8f1e82..f3d77fb6 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -6,6 +6,8 @@ on: paths: - 'web/**' - 'backend/src/roboprobe/api/**' + - 'backend/alembic/**' + - 'backend/tests/fixtures/db/**' - 'docker/**' - 'scripts/e2e_stack.sh' - '.github/workflows/e2e.yml' @@ -21,48 +23,50 @@ concurrency: cancel-in-progress: true env: - PYTHON_VERSION: '3.12' NODE_VERSION: '24' E2E_BASE_URL: http://127.0.0.1:8080 + E2E_COMPOSE_PROJECT: roboprobe-e2e-${{ github.run_id }}-${{ github.run_attempt }} jobs: playwright: - name: playwright + name: Playwright (${{ matrix.browser }}) runs-on: ubuntu-latest timeout-minutes: 25 + strategy: + fail-fast: false + matrix: + include: + - browser: chromium + spec: '' + - browser: firefox + spec: smoke.spec.ts steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 - with: - python-version: ${{ env.PYTHON_VERSION }} - uses: ./.github/actions/setup-web with: node-version: ${{ env.NODE_VERSION }} - name: Install Playwright browsers working-directory: web - run: pnpm exec playwright install --with-deps chromium firefox + run: pnpm exec playwright install --with-deps ${{ matrix.browser }} - name: Stack up, seed DB, run Playwright - run: | - make setup - cd web && pnpm exec playwright test --project=chromium - - name: Playwright summary - if: always() working-directory: web - run: | - if [[ -d playwright-report ]]; then - echo "### Playwright report" >>"$GITHUB_STEP_SUMMARY" - echo "Artefacts uploaded as playwright-report" >>"$GITHUB_STEP_SUMMARY" - fi + run: pnpm exec playwright test --project=${{ matrix.browser }} ${{ matrix.spec }} - name: Upload Playwright report if: failure() + id: reports uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: - name: playwright-report + name: playwright-${{ matrix.browser }}-report path: | web/playwright-report/ web/e2e-results/ web/e2e-artifacts/ if-no-files-found: ignore + - name: Link Playwright report + if: ${{ failure() && steps.reports.outputs.artifact-url != '' }} + env: + ARTIFACT_URL: ${{ steps.reports.outputs.artifact-url }} + run: printf '[Download the browser report and Compose logs](%s)\n' "$ARTIFACT_URL" >> "$GITHUB_STEP_SUMMARY" lighthouse: name: lighthouse @@ -71,21 +75,16 @@ jobs: timeout-minutes: 20 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 - with: - python-version: ${{ env.PYTHON_VERSION }} - uses: ./.github/actions/setup-web with: node-version: ${{ env.NODE_VERSION }} - name: Lighthouse on seeded stack - run: | - make setup - bash scripts/e2e_stack.sh up - cd web && pnpm exec lhci autorun --config=lighthouserc.live.json + working-directory: web + run: bash ../scripts/e2e_stack.sh pnpm exec lhci autorun --config=lighthouserc.live.json - name: Collect compose logs if: always() uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: e2e-compose-logs path: web/e2e-artifacts/compose.log - if-no-files-found: ignore \ No newline at end of file + if-no-files-found: ignore diff --git a/docker/e2e.compose.yaml b/docker/e2e.compose.yaml new file mode 100644 index 00000000..5601ccd2 --- /dev/null +++ b/docker/e2e.compose.yaml @@ -0,0 +1,27 @@ +# Playwright overrides. Docker Compose resolves these paths relative to compose.yaml. +x-e2e-backend: &e2e-backend + env_file: !override [./e2e.env] + volumes: + - e2e-artifacts:/data/artifacts + +services: + migrate: + <<: *e2e-backend + orchestrator: + <<: *e2e-backend + worker-k2d: + <<: *e2e-backend + api: + <<: *e2e-backend + secrets: [api_token] + web: + env_file: !override [./e2e.env] + +secrets: + db_password: + file: ${E2E_DB_PASSWORD_FILE:-/dev/null} + api_token: + file: ${E2E_API_TOKEN_FILE:-/dev/null} + +volumes: + e2e-artifacts: {} diff --git a/docker/e2e.env b/docker/e2e.env index a1b867e7..eaf6ad16 100644 --- a/docker/e2e.env +++ b/docker/e2e.env @@ -1,6 +1,11 @@ -# E2E stack overrides (T-117). Composed with repo `.env` when present; tunables live in docs/27. +# Local bindings and runtime settings for the isolated Playwright Compose project. +ROBOPROBE_WEB_PORT=8080 ROBOPROBE_K2D_REPLICAS=2 +ROBOPROBE_DB_NAME=roboprobe_e2e +ROBOPROBE_STORAGE__ARTIFACT_ROOT=/data/artifacts/e2e +ROBOPROBE_STORAGE__WORKDIR_ROOT=/tmp/roboprobe-work +ROBOPROBE_RUNNER__MAX_BATCH_SIZE=4 ROBOPROBE_RUNNER__MAX_CONCURRENT_CAMPAIGNS=2 -ROBOPROBE_API__HOST=0.0.0.0 -ROBOPROBE_WEB_PORT=8080 -ROBOPROBE_DB_PORT=5432 \ No newline at end of file +ROBOPROBE_RUNNER__MAX_MANUAL_REPEATS=5 +OMP_NUM_THREADS=1 +MKL_NUM_THREADS=1 diff --git a/docs/18-testing-strategy-and-qa.md b/docs/18-testing-strategy-and-qa.md index 4c0f8ab1..5b383256 100644 --- a/docs/18-testing-strategy-and-qa.md +++ b/docs/18-testing-strategy-and-qa.md @@ -94,6 +94,12 @@ Schema conformance (`schemathesis` against OpenAPI, nightly); error envelope; pa Component tests for ConditionStrip, RiskHeatmap, RobustnessBar (rendering & a11y); MSW-mocked feature tests for wizard and console; Playwright flows: create campaign → see runs stream → open case → replay → export report; axe on every route; visual snapshot of tokens page (light/dark). +From `web/`, install Chromium and Firefox with `pnpm exec playwright install chromium firefox`. +Run the seeded smoke in both browsers with `pnpm test:e2e smoke.spec.ts`. The harness builds +the production images, loads the shared seed into a dedicated Compose project, and tears it down +on completion. Browser reports and Compose logs are under `web/playwright-report/`, +`web/e2e-results/`, and `web/e2e-artifacts/`. + ## 5. Test data & fixtures - `fixtures/spaces/warehouse_v1.yaml`, `fixtures/traces/*.parquet` (golden), `fixtures/db/seed_small.sql` (1 campaign, 60 runs, 3 modes) for API/web tests, `fixtures/reference/` small reference set for risk tests. diff --git a/docs/27-configuration-reference.md b/docs/27-configuration-reference.md index 9d942b1f..a2108567 100644 --- a/docs/27-configuration-reference.md +++ b/docs/27-configuration-reference.md @@ -367,6 +367,10 @@ The database password is never a variable: `make setup` writes `secrets/db_passw Set `ROBOPROBE_API_TOKEN_FILE` to override the source file for the shared API and Prometheus `api_token` secret. Compose defaults to `secrets/api_token` at the repository root. +Browser tests default to `E2E_BASE_URL=http://127.0.0.1:8080`. Use HTTP on `localhost` or +`127.0.0.1` to change the port. `E2E_COMPOSE_PROJECT` defaults to +`roboprobe-e2e-`. Use a different `roboprobe-e2e-*` project for each concurrent test. + ### 4.14 API load-test budgets The `[p95_ms]` table in [thresholds.toml](../backend/tests/perf/thresholds.toml) sets the p95 limit diff --git a/scripts/e2e_stack.sh b/scripts/e2e_stack.sh index 57cb9d90..36271b96 100755 --- a/scripts/e2e_stack.sh +++ b/scripts/e2e_stack.sh @@ -1,113 +1,5 @@ #!/usr/bin/env bash -# Compose-backed stack for Playwright E2E (T-117). Used by web/e2e global setup and e2e.yml. +# Run a command against a disposable Compose project and clean up afterwards. set -euo pipefail - -ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" -cd "$ROOT" - -ACTION="${1:-}" -COMPOSE_FILE="${COMPOSE_FILE:-docker/compose.yaml}" -E2E_ENV="${E2E_ENV:-docker/e2e.env}" -ARTIFACTS_DIR="${E2E_ARTIFACT_ROOT:-data/artifacts}" -SECRETS_DIR="${SECRETS_DIR:-secrets}" -DB_PASSWORD_FILE="${SECRETS_DIR}/db_password" -API_TOKEN_FILE="${SECRETS_DIR}/api_token" -LOG_DIR="${E2E_LOG_DIR:-web/e2e-artifacts}" -READY_URL="${E2E_READY_URL:-http://127.0.0.1:8000/api/v1/health/ready}" -WEB_URL="${E2E_BASE_URL:-http://127.0.0.1:8080}" -READY_TIMEOUT_S="${E2E_READY_TIMEOUT_S:-180}" - -compose() { - local -a args=(docker compose -f "$COMPOSE_FILE" --env-file "$E2E_ENV") - if [[ -f .env ]]; then - args+=(--env-file .env) - fi - args+=(--profile core --profile app --profile dev "$@") - "${args[@]}" -} - -ensure_secret() { - mkdir -p "$SECRETS_DIR" && chmod 700 "$SECRETS_DIR" - umask 022 - for file in "$DB_PASSWORD_FILE" "$API_TOKEN_FILE"; do - if [[ ! -s $file ]]; then - python3 -c 'import secrets; print(secrets.token_urlsafe(32))' >"$file" - fi - done -} - -wait_http() { - local url=$1 timeout=$2 - python3 - "$url" "$timeout" <<'PY' -import sys, time, urllib.error, urllib.request - -url, limit = sys.argv[1], float(sys.argv[2]) -deadline = time.monotonic() + limit -while time.monotonic() < deadline: - try: - with urllib.request.urlopen(url, timeout=3) as response: - if response.status == 200: - sys.exit(0) - except urllib.error.HTTPError as exc: - if exc.code in {503, 502}: - time.sleep(2) - continue - raise - except OSError: - time.sleep(2) -raise SystemExit(f"timed out waiting for {url}") -PY -} - -wait_loopback_postgres() { - python3 - <<'PY' -import socket, sys, time - -for _ in range(60): - try: - with socket.create_connection(("127.0.0.1", 5432), timeout=1): - sys.exit(0) - except OSError: - time.sleep(1) -raise SystemExit("postgres port 5432 not reachable on loopback") -PY -} - -database_url() { - local db_pass - db_pass="$(<"$DB_PASSWORD_FILE")" - printf 'postgresql+psycopg://roboprobe:%s@127.0.0.1:5432/roboprobe' "$db_pass" -} - -seed_database() { - rm -rf "$ARTIFACTS_DIR" - mkdir -p "$ARTIFACTS_DIR" - uv run --directory backend python tests/fixtures/db/load_seed.py \ - --database-url "$(database_url)" --artifact-root "$ARTIFACTS_DIR" -} - -case "$ACTION" in - up) - ensure_secret - mkdir -p "$ARTIFACTS_DIR" "$LOG_DIR" - compose down --remove-orphans -v || true - compose build postgres migrate orchestrator worker-k2d api web - compose up -d postgres postgres-port - compose up -d migrate - compose wait migrate - wait_loopback_postgres - seed_database - compose up -d --wait orchestrator worker-k2d api web - wait_http "$READY_URL" "$READY_TIMEOUT_S" - wait_http "$WEB_URL/" 60 - ;; - down) - mkdir -p "$LOG_DIR" - compose logs --no-color >"$LOG_DIR/compose.log" 2>&1 || true - compose down --remove-orphans - ;; - *) - echo "usage: $0 {up|down}" >&2 - exit 2 - ;; -esac \ No newline at end of file +root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +exec node "$root/web/e2e/with-stack.ts" "$@" diff --git a/web/.prettierignore b/web/.prettierignore index 6115aff2..7e6f1519 100644 --- a/web/.prettierignore +++ b/web/.prettierignore @@ -1,5 +1,10 @@ dist coverage +playwright-report +test-results +e2e-results +e2e-artifacts +.lighthouseci pnpm-lock.yaml # Generated by scripts/gen-tokens.ts (checked by `pnpm gen:tokens --check`) src/styles/tokens.css diff --git a/web/e2e/a11y.ts b/web/e2e/a11y.ts index 7bae1330..b251efc5 100644 --- a/web/e2e/a11y.ts +++ b/web/e2e/a11y.ts @@ -1,6 +1,6 @@ import AxeBuilder from '@axe-core/playwright'; import type { Page } from '@playwright/test'; -import config from './e2e.config.json'; +import config from './e2e.config.json' with { type: 'json' }; export async function expectNoA11yViolations( page: Page, diff --git a/web/e2e/fixtures.ts b/web/e2e/fixtures.ts index 63df7402..a2077cc2 100644 --- a/web/e2e/fixtures.ts +++ b/web/e2e/fixtures.ts @@ -1,7 +1,7 @@ import { test as base, expect } from '@playwright/test'; import type { Page } from '@playwright/test'; import { expectNoA11yViolations } from './a11y'; -import config from './e2e.config.json'; +import config from './e2e.config.json' with { type: 'json' }; function guardConsole(page: Page): string[] { const errors: string[] = []; @@ -17,6 +17,17 @@ function guardConsole(page: Page): string[] { } export const test = base.extend<{ consoleErrors: string[] }>({ + page: async ({ page, baseURL }, provide) => { + const token = process.env['E2E_API_TOKEN']; + if (!baseURL || !token) throw new Error('The Compose setup did not supply an E2E API session.'); + await page.addInitScript( + ({ origin, bearer }) => { + if (location.origin === origin) sessionStorage.setItem('roboprobe.api-token', bearer); + }, + { origin: new URL(baseURL).origin, bearer: token }, + ); + await provide(page); + }, consoleErrors: [ async ({ page }, use) => { const errors = guardConsole(page); diff --git a/web/e2e/global-setup.ts b/web/e2e/global-setup.ts index e72d2e7f..707f8bd1 100644 --- a/web/e2e/global-setup.ts +++ b/web/e2e/global-setup.ts @@ -1,16 +1,157 @@ -import { execSync } from 'node:child_process'; -import path from 'node:path'; -import { fileURLToPath } from 'node:url'; +import { execFile } from 'node:child_process'; +import { randomBytes } from 'node:crypto'; +import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'; +import { tmpdir } from 'node:os'; +import { join, resolve } from 'node:path'; +import { promisify } from 'node:util'; +import type { FullConfig } from '@playwright/test'; -const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..'); +const root = resolve(import.meta.dirname, '../..'); +const reportDir = join(root, 'web/e2e-artifacts'); +const run = promisify(execFile); +const BUILD_TIMEOUT_MS = 420_000; +const START_TIMEOUT_MS = 180_000; +const SEED_TIMEOUT_MS = 90_000; +const COMMAND_TIMEOUT_MS = 30_000; +const OUTPUT_LIMIT = 8 * 1024 * 1024; +const SEED_SCRIPT = [ + 'import sys', + 'from roboprobe.core.settings import load_settings', + 'sys.path.insert(0, "/e2e-seed")', + 'from load_seed import load_seed', + 'settings = load_settings()', + 'load_seed(settings.database.url.get_secret_value(), settings.storage.artifact_root)', +].join('\n'); +const HEALTH_SCRIPT = [ + 'from urllib.request import Request, urlopen', + 'from roboprobe.core.settings import load_settings', + 'api = load_settings().api', + 'headers = {"Authorization": "Bearer " + api.token.get_secret_value()} if api.token else {}', + 'request = Request(f"http://127.0.0.1:{api.port}/health/ready", headers=headers)', + 'with urlopen(request, timeout=5) as response:', + ' print(response.read().decode())', +].join('\n'); -export default function globalSetup(): void { - execSync('bash scripts/e2e_stack.sh up', { - cwd: root, - stdio: 'inherit', - env: { - ...process.env, - E2E_BASE_URL: process.env['E2E_BASE_URL'] ?? 'http://127.0.0.1:8080', - }, - }); +export async function startE2eStack(baseURL: string) { + const browserURL = new URL(baseURL); + if ( + browserURL.protocol !== 'http:' || + !['localhost', '127.0.0.1'].includes(browserURL.hostname) + ) { + throw new Error('E2E_BASE_URL must use HTTP on localhost or 127.0.0.1.'); + } + const project = process.env['E2E_COMPOSE_PROJECT'] ?? `roboprobe-e2e-${String(process.pid)}`; + if (!/^roboprobe-e2e-[a-z0-9-]+$/.test(project)) { + throw new Error('E2E_COMPOSE_PROJECT must be a dedicated roboprobe-e2e-* project.'); + } + const secretDir = await mkdtemp(join(tmpdir(), 'roboprobe-e2e-')); + const apiToken = randomBytes(32).toString('hex'); + const databasePasswordFile = join(secretDir, 'db_password'); + const apiTokenFile = join(secretDir, 'api_token'); + const env = { + ...process.env, + ROBOPROBE_IMAGE_TAG: project, + ROBOPROBE_WEB_PORT: browserURL.port || '80', + E2E_DB_PASSWORD_FILE: databasePasswordFile, + E2E_API_TOKEN_FILE: apiTokenFile, + }; + const composeFlags = [ + 'compose', + '--project-name', + project, + '--env-file', + 'docker/e2e.env', + '-f', + 'docker/compose.yaml', + '-f', + 'docker/e2e.compose.yaml', + '--profile', + 'core', + '--profile', + 'app', + ]; + const compose = (args: string[], timeout = COMMAND_TIMEOUT_MS) => + run('docker', [...composeFlags, ...args], { + cwd: root, + env, + timeout, + maxBuffer: OUTPUT_LIMIT, + }); + const cleanup = async () => { + try { + await mkdir(reportDir, { recursive: true }); + const logs = await compose(['logs', '--no-color']); + await writeFile(join(reportDir, 'compose.log'), logs.stdout + logs.stderr); + } finally { + try { + await compose(['down', '--volumes', '--remove-orphans']); + } finally { + await rm(secretDir, { recursive: true, force: true }); + } + } + }; + try { + await Promise.all([ + rm(join(reportDir, 'compose.log'), { force: true }), + rm(join(reportDir, 'compose-setup-error.txt'), { force: true }), + writeFile(databasePasswordFile, randomBytes(32).toString('hex'), { mode: 0o444 }), + writeFile(apiTokenFile, apiToken, { mode: 0o444 }), + ]); + // The API, orchestrator and workers all use the backend image built for migrate. + await compose(['build', 'migrate', 'web'], BUILD_TIMEOUT_MS); + await compose(['up', '--no-build', '-d', '--wait', '--wait-timeout', '150'], START_TIMEOUT_MS); + await compose( + [ + 'run', + '--no-deps', + '--rm', + '-T', + '--volume', + `${join(root, 'backend/tests/fixtures/db')}:/e2e-seed:ro`, + '--entrypoint', + 'python', + 'api', + '-c', + SEED_SCRIPT, + ], + SEED_TIMEOUT_MS, + ); + await compose(['exec', '-T', 'api', 'python', '-c', HEALTH_SCRIPT]); + const campaigns = await fetch(new URL('/api/v1/campaigns', browserURL), { + headers: { Authorization: `Bearer ${apiToken}` }, + signal: AbortSignal.timeout(COMMAND_TIMEOUT_MS), + }); + if (!campaigns.ok || !campaigns.headers.get('content-type')?.includes('application/json')) { + throw new Error( + `The dashboard proxy returned ${String(campaigns.status)} instead of campaigns.`, + ); + } + return { apiToken, cleanup }; + } catch (error) { + const errors: unknown[] = [error]; + try { + await mkdir(reportDir, { recursive: true }); + const output = + error instanceof Error && 'stdout' in error && typeof error.stdout === 'string' + ? error.stdout + : ''; + await writeFile(join(reportDir, 'compose-setup-error.txt'), `${String(error)}\n${output}`); + } catch (reportError) { + errors.push(reportError); + } + await cleanup().catch((cleanupError: unknown) => { + errors.push(cleanupError); + }); + if (errors.length > 1) + throw new AggregateError(errors, 'Compose setup and diagnostics failed.'); + throw error; + } +} + +export default async function globalSetup(config: FullConfig) { + const baseURL = config.projects[0]?.use.baseURL; + if (!baseURL) throw new Error('The Playwright project must declare a base URL.'); + const { apiToken, cleanup } = await startE2eStack(baseURL); + process.env['E2E_API_TOKEN'] = apiToken; + return cleanup; } diff --git a/web/e2e/global-teardown.ts b/web/e2e/global-teardown.ts deleted file mode 100644 index 6d2bcb41..00000000 --- a/web/e2e/global-teardown.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { execSync } from 'node:child_process'; -import path from 'node:path'; -import { fileURLToPath } from 'node:url'; - -const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..'); - -export default function globalTeardown(): void { - execSync('bash scripts/e2e_stack.sh down', { cwd: root, stdio: 'inherit' }); -} diff --git a/web/e2e/pages/casebook.ts b/web/e2e/pages/casebook.ts index 258fc4cc..cfac1616 100644 --- a/web/e2e/pages/casebook.ts +++ b/web/e2e/pages/casebook.ts @@ -8,7 +8,11 @@ export class CasebookPage { await this.page.getByRole('heading', { name: 'Casebook' }).waitFor(); } - openMedoid(): Promise { - return this.page.getByRole('link', { name: 'Medoid run' }).first().click(); + openMedoid(modeCode: string): Promise { + return this.page + .getByRole('article') + .filter({ hasText: modeCode }) + .getByRole('link', { name: 'Medoid run', exact: true }) + .click(); } } diff --git a/web/e2e/pages/wizard.ts b/web/e2e/pages/wizard.ts index 2c65aacc..b89f7810 100644 --- a/web/e2e/pages/wizard.ts +++ b/web/e2e/pages/wizard.ts @@ -1,5 +1,6 @@ import type { Page } from '@playwright/test'; import type e2eConfig from '../e2e.config.json'; +import { seed } from '../seed'; export class WizardPage { constructor( @@ -13,9 +14,8 @@ export class WizardPage { } async createK2dCampaign(): Promise { - await this.page - .getByLabel(/Scenario space/) - .selectOption({ label: 'warehouse_v1 · 09cf763f2e0d' }); + const { id, version } = seed.campaign.space; + await this.page.getByLabel(/Scenario space/).selectOption(JSON.stringify([id, version])); await this.page.getByRole('button', { name: 'Continue' }).click(); await this.page.getByLabel('Backend').selectOption('kinematic2d'); await this.page.getByLabel('Robot profile').selectOption('k2d_default'); diff --git a/web/e2e/seed.ts b/web/e2e/seed.ts new file mode 100644 index 00000000..644ee9f1 --- /dev/null +++ b/web/e2e/seed.ts @@ -0,0 +1,19 @@ +import campaignPage from '../src/test/fixtures/campaigns.json' with { type: 'json' }; +import comparison from '../src/test/fixtures/comparison.json' with { type: 'json' }; +import modePage from '../src/test/fixtures/modes.json' with { type: 'json' }; +import config from './e2e.config.json' with { type: 'json' }; + +const campaign = campaignPage.items[0]; +if (!campaign) throw new Error('The checked-in E2E seed has no campaign.'); +const mode = modePage.items.find((item) => item.code === config.seed.modeCode); +if (!mode?.medoid_run_id) throw new Error('The checked-in E2E mode has no medoid run.'); +const strategies = Object.keys(comparison.strategies); +if (!strategies.length) throw new Error('The checked-in E2E comparison has no strategies.'); + +export const seed = { + campaign, + campaignModes: modePage.items, + medoid: { id: mode.medoid_run_id, modeCode: mode.code }, + experimentId: comparison.experiment_id, + strategies, +}; diff --git a/web/e2e/specs/a11y-sweep.spec.ts b/web/e2e/specs/a11y-sweep.spec.ts index 17025fa7..d0e00774 100644 --- a/web/e2e/specs/a11y-sweep.spec.ts +++ b/web/e2e/specs/a11y-sweep.spec.ts @@ -9,9 +9,11 @@ async function setTheme( } async function tabThrough(page: import('@playwright/test').Page): Promise { + const active = page.locator(':focus'); for (let i = 0; i < 12; i += 1) { await page.keyboard.press('Tab'); - const active = page.locator(':focus'); + // Chromium may move focus to its own controls when advancing past the document. + if ((await active.count()) === 0) await page.keyboard.press('Tab'); await expect(active).toBeVisible(); } } diff --git a/web/e2e/specs/investigate-case.spec.ts b/web/e2e/specs/investigate-case.spec.ts index fadbbc72..1b313ca3 100644 --- a/web/e2e/specs/investigate-case.spec.ts +++ b/web/e2e/specs/investigate-case.spec.ts @@ -1,16 +1,15 @@ import { CasebookPage } from '../pages/casebook'; import { afterNavigation, e2e, test, expect } from '../fixtures'; +import { seed } from '../seed'; test('casebook medoid → replay ×3 → export report', async ({ page }) => { const casebook = new CasebookPage(page); - const { campaignId, medoidRunId } = e2e.seed; - - await casebook.open(campaignId); + await casebook.open(seed.campaign.id); await afterNavigation(page); - await casebook.openMedoid(); + await casebook.openMedoid(seed.medoid.modeCode); await afterNavigation(page); - await expect(page).toHaveURL(new RegExp(`/runs/${medoidRunId.replace(/-/g, '\\-')}`)); + await expect(page).toHaveURL(new RegExp(`/runs/${seed.medoid.id}$`)); await page.getByRole('button', { name: 'Replay' }).click(); await page.getByLabel('Repeats').fill(String(e2e.replayRepeats)); await page.getByRole('button', { name: 'Queue replay' }).click(); diff --git a/web/e2e/specs/smoke.spec.ts b/web/e2e/specs/smoke.spec.ts index 83e3b868..26a989df 100644 --- a/web/e2e/specs/smoke.spec.ts +++ b/web/e2e/specs/smoke.spec.ts @@ -1,9 +1,28 @@ -import { BenchPage } from '../pages/bench'; -import { afterNavigation, expect, test } from '../fixtures'; +import AxeBuilder from '@axe-core/playwright'; +import { expect, test } from '../fixtures'; +import { seed } from '../seed'; -test('bench renders with axe clean', async ({ page }) => { - const bench = new BenchPage(page); - await bench.open(); - await expect(page.getByRole('heading', { name: 'Bench' })).toBeVisible(); - await afterNavigation(page); +test('renders the seeded Bench and opens its campaign console', async ({ page }) => { + const response = await page.goto('/'); + expect(response?.headers()['content-security-policy']).toContain("default-src 'self'"); + await expect(page.getByRole('heading', { name: 'Bench', exact: true })).toBeVisible(); + await expect(page.getByRole('link', { name: 'New campaign', exact: true })).toBeVisible(); + const campaign = page + .getByRole('table', { name: 'Recent campaigns' }) + .getByRole('link', { name: seed.campaign.name, exact: true }); + await expect(campaign).toBeVisible(); + const cases = seed.campaignModes.map((mode) => + expect(page.getByRole('link', { name: new RegExp(mode.code) })).toBeVisible(), + ); + await Promise.all(cases); + + const { violations } = await new AxeBuilder({ page }).analyze(); + expect( + violations.filter(({ impact }) => impact === 'serious' || impact === 'critical'), + 'serious or critical Bench accessibility violations', + ).toEqual([]); + + await campaign.press('Enter'); + await expect(page.getByRole('heading', { name: seed.campaign.name, exact: true })).toBeVisible(); + await expect(page).toHaveURL(new RegExp(`/campaigns/${seed.campaign.id}/console$`)); }); diff --git a/web/e2e/specs/trials.spec.ts b/web/e2e/specs/trials.spec.ts index 93e8016c..53e8e6a3 100644 --- a/web/e2e/specs/trials.spec.ts +++ b/web/e2e/specs/trials.spec.ts @@ -1,8 +1,14 @@ -import { afterNavigation, e2e, test, expect } from '../fixtures'; +import { afterNavigation, test, expect } from '../fixtures'; +import { seed } from '../seed'; test('experiment comparison lists every strategy', async ({ page }) => { - await page.goto(`/trials/${e2e.seed.experimentId}/comparison`); + await page.goto(`/trials/${seed.experimentId}/comparison`); await page.getByRole('heading', { name: 'Compare strategies' }).waitFor(); await afterNavigation(page); - await expect(page.getByText('S-RANDOM')).toBeVisible(); + const metrics = page.getByRole('table', { name: 'Strategy metrics' }); + await Promise.all( + seed.strategies.map((name) => + expect(metrics.getByRole('cell', { name, exact: true }).first()).toBeVisible(), + ), + ); }); diff --git a/web/e2e/with-stack.ts b/web/e2e/with-stack.ts new file mode 100644 index 00000000..3bbce66d --- /dev/null +++ b/web/e2e/with-stack.ts @@ -0,0 +1,26 @@ +import { spawn } from 'node:child_process'; +import { startE2eStack } from './global-setup.ts'; + +const [command, ...args] = process.argv.slice(2); +if (!command || command === 'up' || command === 'down') { + throw new Error('Pass the command to run inside the isolated E2E stack.'); +} + +const { apiToken, cleanup } = await startE2eStack( + process.env['E2E_BASE_URL'] ?? 'http://127.0.0.1:8080', +); +try { + const result = await new Promise((resolve, reject) => { + const child = spawn(command, args, { + stdio: 'inherit', + env: { ...process.env, E2E_API_TOKEN: apiToken }, + }); + child.once('error', reject); + child.once('close', (code) => { + resolve(code ?? 1); + }); + }); + process.exitCode = result; +} finally { + await cleanup(); +} diff --git a/web/eslint.config.js b/web/eslint.config.js index 209bdfd5..88605293 100644 --- a/web/eslint.config.js +++ b/web/eslint.config.js @@ -18,6 +18,8 @@ export default tseslint.config( 'src/api/schema.d.ts', 'playwright-report', 'e2e-results', + 'e2e-artifacts', + '.lighthouseci', ], }, { diff --git a/web/playwright.config.ts b/web/playwright.config.ts index 9aee286c..ac7cf54e 100644 --- a/web/playwright.config.ts +++ b/web/playwright.config.ts @@ -12,7 +12,6 @@ export default defineConfig({ reporter: [['list'], ['html', { open: 'never', outputFolder: 'playwright-report' }]], outputDir: 'e2e-results', globalSetup: './e2e/global-setup.ts', - globalTeardown: './e2e/global-teardown.ts', timeout: 180_000, expect: { timeout: 15_000 }, use: { diff --git a/web/src/features/runs/RunPage.tsx b/web/src/features/runs/RunPage.tsx index d7df4b6b..7bbeb3cf 100644 --- a/web/src/features/runs/RunPage.tsx +++ b/web/src/features/runs/RunPage.tsx @@ -175,6 +175,7 @@ function Parameters({ <> Date: Mon, 23 Nov 2026 01:27:06 +0530 Subject: [PATCH 02/10] test(web): assert the confirmed cancellation state (T-118) --- web/e2e/specs/controls.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/e2e/specs/controls.spec.ts b/web/e2e/specs/controls.spec.ts index 252147ac..1a35aeab 100644 --- a/web/e2e/specs/controls.spec.ts +++ b/web/e2e/specs/controls.spec.ts @@ -17,5 +17,5 @@ test('campaign pause resume cancel transitions', async ({ page }) => { await expect(page.getByRole('button', { name: 'Resume' })).toBeDisabled(); await console.cancel(); await page.getByRole('button', { name: 'Confirm cancellation' }).click(); - await expect(page.getByText(/CANCELLED|cancelled/i)).toBeVisible(); + await expect(page.getByText(/\bCANCELLED$/)).toBeVisible(); }); From 81c8a4ee1f4eb04dc9fa5cd6b39da144c6f0bf37 Mon Sep 17 00:00:00 2001 From: CodewithJha <155089480+CodewithJha@users.noreply.github.com> Date: Mon, 23 Nov 2026 01:31:06 +0530 Subject: [PATCH 03/10] test(web): wait for wizard data and verify the report preview (T-118) --- web/e2e/pages/wizard.ts | 1 + web/e2e/specs/investigate-case.spec.ts | 2 ++ 2 files changed, 3 insertions(+) diff --git a/web/e2e/pages/wizard.ts b/web/e2e/pages/wizard.ts index b89f7810..da2c5aa5 100644 --- a/web/e2e/pages/wizard.ts +++ b/web/e2e/pages/wizard.ts @@ -16,6 +16,7 @@ export class WizardPage { async createK2dCampaign(): Promise { const { id, version } = seed.campaign.space; await this.page.getByLabel(/Scenario space/).selectOption(JSON.stringify([id, version])); + await this.page.getByRole('status').filter({ hasText: /\d+ free parameters/ }).waitFor(); await this.page.getByRole('button', { name: 'Continue' }).click(); await this.page.getByLabel('Backend').selectOption('kinematic2d'); await this.page.getByLabel('Robot profile').selectOption('k2d_default'); diff --git a/web/e2e/specs/investigate-case.spec.ts b/web/e2e/specs/investigate-case.spec.ts index 1b313ca3..13770969 100644 --- a/web/e2e/specs/investigate-case.spec.ts +++ b/web/e2e/specs/investigate-case.spec.ts @@ -20,4 +20,6 @@ test('casebook medoid → replay ×3 → export report', async ({ page }) => { await expect(page.getByRole('heading', { name: 'Exported report' })).toBeVisible({ timeout: e2e.timeoutsMs.campaignRun, }); + const preview = page.frameLocator('iframe[title="Report preview"]'); + await expect(preview.getByRole('heading', { name: 'Campaign report', exact: true })).toBeVisible(); }); From 316cee70edc06bb4b46fcd68789ee60e061f8c09 Mon Sep 17 00:00:00 2001 From: CodewithJha <155089480+CodewithJha@users.noreply.github.com> Date: Mon, 23 Nov 2026 01:33:08 +0530 Subject: [PATCH 04/10] test(web): distinguish campaign cancellation from its runs (T-118) --- web/e2e/specs/controls.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/e2e/specs/controls.spec.ts b/web/e2e/specs/controls.spec.ts index 1a35aeab..b54b77b4 100644 --- a/web/e2e/specs/controls.spec.ts +++ b/web/e2e/specs/controls.spec.ts @@ -17,5 +17,5 @@ test('campaign pause resume cancel transitions', async ({ page }) => { await expect(page.getByRole('button', { name: 'Resume' })).toBeDisabled(); await console.cancel(); await page.getByRole('button', { name: 'Confirm cancellation' }).click(); - await expect(page.getByText(/\bCANCELLED$/)).toBeVisible(); + await expect(page.getByText(/· CANCELLED$/)).toBeVisible(); }); From 0f776c688d5c2d63341a3f8fe1be09c73bcf7bbe Mon Sep 17 00:00:00 2001 From: CodewithJha <155089480+CodewithJha@users.noreply.github.com> Date: Mon, 23 Nov 2026 01:36:35 +0530 Subject: [PATCH 05/10] fix(reporting): render legacy atlas data and authenticate report previews --- CHANGELOG.md | 2 + backend/src/roboprobe/reporting/campaign.py | 51 +++++++++++++-- backend/src/roboprobe/reporting/figures.py | 21 +++++-- .../unit/reporting/test_campaign_report.py | 26 ++++++++ web/src/features/reports/ReportPage.test.tsx | 46 +++++++++++++- web/src/features/reports/ReportPage.tsx | 63 ++++++++++++++----- web/src/features/reports/useReportJob.ts | 19 ++++++ 7 files changed, 200 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3340d71..6a2a54fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -232,6 +232,8 @@ versioning: [Semantic Versioning 2.0.0](https://semver.org/) (policy in `docs/33 ### Fixed +- Campaign reports render legacy risk slices, and authenticated dashboard sessions can preview + and download completed reports. - Embed the API comparison payload in offline experiment reports and surface restart-interrupted report jobs as errors (T-084a). - Casebook interaction checks, replays, and Atlas manual probes run after campaign completion. diff --git a/backend/src/roboprobe/reporting/campaign.py b/backend/src/roboprobe/reporting/campaign.py index 43c711f0..f47d65b9 100644 --- a/backend/src/roboprobe/reporting/campaign.py +++ b/backend/src/roboprobe/reporting/campaign.py @@ -24,10 +24,16 @@ from roboprobe.metrics.discovery_metrics import discovery_curve from roboprobe.reporting import figures from roboprobe.reporting._env import template_env -from roboprobe.reporting.figures import _ImportanceLike +from roboprobe.reporting.figures import _ImportanceLike, _RiskSlicePlot from roboprobe.reporting.ports import ReportArtifactStore, ReportUnitOfWork from roboprobe.reporting.theme import load_theme, tokens_path -from roboprobe.risk.mapper import RiskSlice, load_slices +from roboprobe.risk.mapper import ( + REGION_FAILURE, + REGION_SAFE, + REGION_UNCERTAIN, + RiskSlice, + load_slices, +) from roboprobe.risk.volume import RegionVolumes, robustness_score __all__ = ["CampaignReportContext", "render_campaign_report"] @@ -135,9 +141,38 @@ def _volumes_from_summary(summary: Mapping[str, Any]) -> RegionVolumes | None: return None +def _legacy_slice_plots(payload: object) -> list[_RiskSlicePlot]: + """Read only the chart coordinates present in JSON fixture and legacy records.""" + if not isinstance(payload, list): + return [] + plots: list[_RiskSlicePlot] = [] + for row in payload: + if not isinstance(row, dict): + continue + x_param, y_param = row.get("x_param"), row.get("y_param") + if not isinstance(x_param, str) or not isinstance(y_param, str): + continue + x = np.asarray(row.get("x_values"), dtype=np.float64) + y = np.asarray(row.get("y_values"), dtype=np.float64) + region = np.asarray(row.get("region"), dtype=np.float64) + if ( + x.ndim != 1 + or y.ndim != 1 + or not x.size + or not y.size + or not np.isfinite(x).all() + or not np.isfinite(y).all() + or region.shape != (x.size, y.size) + or not np.isin(region, (REGION_SAFE, REGION_UNCERTAIN, REGION_FAILURE)).all() + ): + continue + plots.append(_RiskSlicePlot(x_param, y_param, x, y, region.astype(np.int8))) + return plots + + def _load_slices_from_store( store: ReportArtifactStore, uow: ReportUnitOfWork, campaign_id: UUID -) -> list[RiskSlice]: +) -> Sequence[RiskSlice | _RiskSlicePlot]: latest = uow.risk_maps.latest(campaign_id) if latest is None or latest.slices_artifact is None: return [] @@ -149,9 +184,15 @@ def _load_slices_from_store( blob = store.path(ref) except Exception: return [] - if not Path(blob).is_file(): + try: + with Path(blob).open("rb") as stream: + prefix = stream.read(2) + stream.seek(0) + if prefix == b"PK": + return load_slices(stream) + return _legacy_slice_plots(json.load(stream)) + except (OSError, KeyError, TypeError, ValueError): return [] - return load_slices(Path(blob)) def build_campaign_context( # noqa: PLR0915 diff --git a/backend/src/roboprobe/reporting/figures.py b/backend/src/roboprobe/reporting/figures.py index 1d90414b..9806bf9e 100644 --- a/backend/src/roboprobe/reporting/figures.py +++ b/backend/src/roboprobe/reporting/figures.py @@ -8,6 +8,7 @@ from __future__ import annotations from collections.abc import Mapping, Sequence +from dataclasses import dataclass from io import StringIO from typing import TYPE_CHECKING, Any, Protocol @@ -30,6 +31,17 @@ class _ImportanceLike(Protocol): mean_abs_shap: Sequence[float] +@dataclass(frozen=True, slots=True) +class _RiskSlicePlot: + """Axis and region data needed to render a persisted slice.""" + + x_param: str + y_param: str + x_values: npt.NDArray[np.float64] + y_values: npt.NDArray[np.float64] + region: npt.NDArray[np.int8] + + __all__ = [ "discovery_curve_svg", "discovery_curve_with_ci_svg", @@ -309,7 +321,7 @@ def interaction_heatmap_svg( def risk_slice_svg( - slice_: RiskSlice | None, + slice_: RiskSlice | _RiskSlicePlot | None, *, settings: ReportingSettings | None = None, ) -> str: @@ -335,11 +347,10 @@ def risk_slice_svg( ) uncertain = slice_.region == REGION_UNCERTAIN if np.any(uncertain): - yy, xx = np.meshgrid(slice_.y_values, slice_.x_values, indexing="ij") ax.contourf( - xx, - yy, - uncertain.astype(np.float64), + slice_.x_values, + slice_.y_values, + uncertain.T.astype(np.float64), levels=[0.5, 1.5], colors=["none"], hatches=["//"], diff --git a/backend/tests/unit/reporting/test_campaign_report.py b/backend/tests/unit/reporting/test_campaign_report.py index e6835389..1f493f25 100644 --- a/backend/tests/unit/reporting/test_campaign_report.py +++ b/backend/tests/unit/reporting/test_campaign_report.py @@ -2,10 +2,12 @@ from __future__ import annotations +import json import re from dataclasses import dataclass, field from html.parser import HTMLParser from pathlib import Path +from types import SimpleNamespace from typing import Any from uuid import UUID, uuid4 @@ -118,6 +120,30 @@ def test_render_campaign_report_offline_html(tmp_path: Path) -> None: assert parser.external == [] +def test_report_renders_legacy_json_risk_regions(tmp_path: Path) -> None: + """Older records still supply a plotted risk slice.""" + risk = tmp_path / "risk.json" + risk.write_text( + json.dumps( + [ + { + "x_param": "robot.max_speed", + "y_param": "env.illuminance", + "x_values": [0.1, 0.2], + "y_values": [1.0, 2.0, 3.0], + "region": [[0, 1, 2], [0, 0, 1]], + } + ] + ), + encoding="utf-8", + ) + uow = _FakeUow() + uow.risk_maps = SimpleNamespace(latest=lambda _id: SimpleNamespace(slices_artifact="risk")) + uow.artifacts = SimpleNamespace(get=lambda _id: SimpleNamespace(sha256="0" * 64, rel_path=risk)) + out = render_campaign_report(CID, uow, _FakeStore(), out=tmp_path / "report.html") + assert "robot.max_speed x env.illuminance" in out.read_text(encoding="utf-8") + + def test_xss_escaped_mode_label(tmp_path: Path) -> None: uow = _FakeUow() uow.modes = type( diff --git a/web/src/features/reports/ReportPage.test.tsx b/web/src/features/reports/ReportPage.test.tsx index 4bedd8be..f0d3d72a 100644 --- a/web/src/features/reports/ReportPage.test.tsx +++ b/web/src/features/reports/ReportPage.test.tsx @@ -6,6 +6,7 @@ import { afterAll, afterEach, beforeAll, expect, it } from 'vitest'; import { AppProviders } from '../../app/providers'; import { apiUrl } from '../../api/client'; import { DEFAULT_CONFIG } from '../../lib/config'; +import { setToken } from '../../lib/token'; import { Component } from './ReportPage'; const server = setupServer( @@ -18,27 +19,66 @@ const server = setupServer( }), ), ); +const reportHtml = + '

Report body

'; beforeAll(() => { server.listen(); }); afterEach(() => { server.resetHandlers(); + setToken(null); }); afterAll(() => { server.close(); }); -it('embeds the report without allow-scripts', async () => { +function renderReport() { const router = createMemoryRouter([{ path: '/reports/:id', Component }], { initialEntries: ['/reports/job-1'], }); - render( + return render( , ); +} + +it('loads the report with the session bearer and embeds its HTML without scripts', async () => { + let authorization: string | null | undefined; + setToken('report-session-token'); + server.use( + http.get(apiUrl('/reports/job-1/content'), ({ request }) => { + authorization = request.headers.get('authorization'); + return HttpResponse.html(reportHtml); + }), + ); + renderReport(); const frame = await screen.findByTitle('Report preview'); - expect(frame).toHaveAttribute('sandbox', 'allow-same-origin'); + expect(authorization).toBe('Bearer report-session-token'); + expect(frame.getAttribute('srcdoc')).toContain('

Report body

'); + expect(frame.getAttribute('sandbox')).toContain('allow-modals'); expect(frame.getAttribute('sandbox') ?? '').not.toMatch(/allow-scripts/); + expect(screen.getByRole('button', { name: 'Download HTML' })).toBeEnabled(); +}); + +it('offers the archive without trying to preview binary report content', async () => { + server.use( + http.get(apiUrl('/reports/job-1'), () => + HttpResponse.json({ + id: 'job-1', + kind: 'bundle', + target_id: 'c1', + status: 'COMPLETED', + }), + ), + http.get(apiUrl('/reports/job-1/content'), () => + HttpResponse.arrayBuffer(new Uint8Array([1, 2, 3]).buffer, { + headers: { 'Content-Type': 'application/zstd' }, + }), + ), + ); + renderReport(); + expect(await screen.findByRole('button', { name: 'Download archive' })).toBeEnabled(); + expect(screen.queryByTitle('Report preview')).not.toBeInTheDocument(); }); diff --git a/web/src/features/reports/ReportPage.tsx b/web/src/features/reports/ReportPage.tsx index a8608089..a720380f 100644 --- a/web/src/features/reports/ReportPage.tsx +++ b/web/src/features/reports/ReportPage.tsx @@ -1,44 +1,77 @@ import { useRef } from 'react'; import { Link, useParams } from 'react-router-dom'; -import { apiUrl } from '../../api/client'; import { ProblemView } from '../../app/ProblemView'; -import { useReportJob } from './useReportJob'; +import { useReportContent, useReportJob } from './useReportJob'; + +const reportPolicy = + ''; + +function previewDocument(html: string): string { + const head = /]*)?>/i; + return head.test(html) + ? html.replace(head, (openingTag) => openingTag + reportPolicy) + : `${reportPolicy}${html}`; +} + +function downloadReport(blob: Blob, filename: string) { + const url = URL.createObjectURL(blob); + const anchor = document.createElement('a'); + anchor.href = url; + anchor.download = filename; + anchor.click(); + window.setTimeout(() => { + URL.revokeObjectURL(url); + }, 0); +} export function Component() { const { id = '' } = useParams(); const job = useReportJob(id); + const content = useReportContent(id, job.data?.status === 'COMPLETED'); const frame = useRef(null); - const contentUrl = id ? apiUrl(`/reports/${id}/content`) : ''; if (job.isError) return ; if (job.isPending) return

Loading report…

; const status = job.data.status; if (status === 'FAILED') return

Report generation failed.

; if (status !== 'COMPLETED') return

Report is still generating…

; + if (content.isError) return ; + if (content.isPending) return

Loading report content…

; + const { blob, html } = content.data; + const bundle = job.data.kind === 'bundle'; return (

RoboProbe / Report

Exported report

+ {html && ( + + )}{' '} {' '} - - Download HTML - {' '} Back to Bench

-