diff --git a/.github/workflows/copy-audit-evidence.yml b/.github/workflows/copy-audit-evidence.yml new file mode 100644 index 00000000..c44aa61b --- /dev/null +++ b/.github/workflows/copy-audit-evidence.yml @@ -0,0 +1,116 @@ +name: Copy audit UI evidence + +on: + push: + branches: [test/copy-audit-ui-evidence] + paths: + - '.github/workflows/copy-audit-evidence.yml' + - 'scripts/ui-evidence/**' + workflow_dispatch: + +permissions: + contents: read + +jobs: + capture: + name: ${{ matrix.scenario }} before and after + runs-on: ubuntu-latest + timeout-minutes: 25 + strategy: + fail-fast: false + matrix: + include: + - scenario: auth + after: 94d238c4d8475439a0f569d05590d270f6ac69d9 + - scenario: project-feedback + after: 2f500ace5aa4de98d9422899f18baa2a16f62e5b + - scenario: editor + after: b3c1a666b5f9cdcec94be7480ca978e7fa5397a2 + - scenario: onboarding + after: 5318d2e84137dc57e70e747c02cf0d898031df57 + env: + NEXT_TELEMETRY_DISABLED: '1' + PUPPETEER_SKIP_DOWNLOAD: 'true' + EVIDENCE_SCENARIO: ${{ matrix.scenario }} + AFTER_SHA: ${{ matrix.after }} + BEFORE_DIR: ${{ github.workspace }}/before + AFTER_DIR: ${{ github.workspace }}/after + EVIDENCE_OUTPUT: ${{ github.workspace }}/artifacts/${{ matrix.scenario }} + + steps: + - name: Initialize retained diagnostics + run: | + mkdir -p "$EVIDENCE_OUTPUT" + printf 'scenario=%s\nafter=%s\nharness=%s\n' "$EVIDENCE_SCENARIO" "$AFTER_SHA" "$GITHUB_SHA" > "$EVIDENCE_OUTPUT/setup.txt" + + - name: Checkout capture infrastructure + uses: actions/checkout@v4 + with: + path: harness + + - name: Checkout exact audited baseline + uses: actions/checkout@v4 + with: + ref: dd33611e3debb0170b801f42370cda55d6c5caa7 + path: before + + - name: Checkout exact feature revision + uses: actions/checkout@v4 + with: + ref: ${{ matrix.after }} + path: after + + - uses: pnpm/action-setup@v4 + with: + package_json_file: before/package.json + + - uses: actions/setup-node@v4 + with: + node-version: '22' + cache: pnpm + cache-dependency-path: before/pnpm-lock.yaml + + - name: Install locked app dependencies without unrelated native postinstalls + working-directory: before + run: pnpm install --frozen-lockfile --ignore-scripts + + - name: Install independent feature dependencies + working-directory: after + run: pnpm install --frozen-lockfile --ignore-scripts + + - name: Install locked evidence tooling + working-directory: harness/scripts/ui-evidence + run: npm ci --ignore-scripts + + - name: Install the pinned Chromium browser + id: browser-setup + working-directory: harness/scripts/ui-evidence + run: | + npx playwright install --with-deps chromium + echo "CHROME_PATH=$(node -e "console.log(require('playwright').chromium.executablePath())")" >> "$GITHUB_ENV" + + - name: Build the exact feature frontend revision + id: feature-build + if: matrix.scenario == 'project-feedback' || matrix.scenario == 'editor' + working-directory: after/frontend + run: | + set -o pipefail + set +e + pnpm build 2>&1 | tee "$EVIDENCE_OUTPUT/${EVIDENCE_SCENARIO}-after-build.log" + status=$? + set -e + printf '%s\n' "$status" > "$EVIDENCE_OUTPUT/${EVIDENCE_SCENARIO}-build-exit-code.txt" + exit "$status" + + - name: Capture real before and after components with local fixture responses + if: ${{ !cancelled() && steps.browser-setup.outcome == 'success' }} + run: node harness/scripts/ui-evidence/run.mjs + + - name: Retain screenshots, source SHAs, fixture observations and logs + if: always() + uses: actions/upload-artifact@v4 + with: + name: copy-audit-${{ matrix.scenario }}-${{ github.run_id }} + path: artifacts/${{ matrix.scenario }}/ + if-no-files-found: error + retention-days: 7 diff --git a/.github/workflows/copy-audit-integration.yml b/.github/workflows/copy-audit-integration.yml new file mode 100644 index 00000000..dc9e2514 --- /dev/null +++ b/.github/workflows/copy-audit-integration.yml @@ -0,0 +1,218 @@ +name: Copy audit feature integration + +on: + push: + branches: [test/copy-audit-ui-evidence] + paths: + - '.github/workflows/copy-audit-integration.yml' + workflow_dispatch: + +permissions: + contents: read + +jobs: + validate: + name: ${{ matrix.scenario }} with CI repair + runs-on: ubuntu-latest + timeout-minutes: 45 + strategy: + fail-fast: false + matrix: + include: + - scenario: onboarding + feature_sha: 5318d2e84137dc57e70e747c02cf0d898031df57 + jest_config: jest.onboarding-copy.config.js + - scenario: project-feedback + feature_sha: 2f500ace5aa4de98d9422899f18baa2a16f62e5b + jest_config: jest.project-feedback.config.js + - scenario: auth + feature_sha: 94d238c4d8475439a0f569d05590d270f6ac69d9 + jest_config: jest.auth-copy.config.js + - scenario: editor + feature_sha: b3c1a666b5f9cdcec94be7480ca978e7fa5397a2 + jest_config: jest.editor-feedback.config.js + defaults: + run: + shell: bash + working-directory: integration + env: + CI: 'true' + NEXT_TELEMETRY_DISABLED: '1' + PUPPETEER_SKIP_DOWNLOAD: 'true' + CI_SHA: f5ea2bfdf2037ace6ad50f6c3c7feaa9df0693d9 + FEATURE_SHA: ${{ matrix.feature_sha }} + FRONTEND_JEST_CONFIG: ${{ matrix.jest_config }} + ARTIFACT_DIR: ${{ github.workspace }}/ci-integration-artifacts/${{ matrix.scenario }} + + steps: + - name: Initialize retained diagnostics + working-directory: ${{ github.workspace }} + run: | + mkdir -p "$ARTIFACT_DIR" + printf 'feature_sha=%s\nci_sha=%s\nworkflow_sha=%s\nrun_id=%s\nrun_attempt=%s\n' \ + "$FEATURE_SHA" "$CI_SHA" "$GITHUB_SHA" "$GITHUB_RUN_ID" "$GITHUB_RUN_ATTEMPT" \ + > "$ARTIFACT_DIR/requested-revisions.txt" + + - name: Checkout the exact CI repair with full history + id: checkout + uses: actions/checkout@v4 + with: + repository: CodeFox-Repo/codefox + ref: ${{ env.CI_SHA }} + path: integration + fetch-depth: 0 + persist-credentials: false + + - name: Merge the exact feature locally without creating a commit + id: merge + run: | + set -euo pipefail + exec > >(tee "$ARTIFACT_DIR/merge.log") 2>&1 + test "$(git rev-parse HEAD)" = "$CI_SHA" + git fetch --no-tags origin "$FEATURE_SHA" + test "$(git rev-parse FETCH_HEAD)" = "$FEATURE_SHA" + merge_base=$(git merge-base "$CI_SHA" "$FEATURE_SHA") + git -c user.name='Copy audit integration' \ + -c user.email='copy-audit-integration@users.noreply.github.com' \ + -c core.hooksPath=/dev/null \ + merge --no-commit --no-ff "$FEATURE_SHA" + # HEAD must remain the CI repair; the staged tree is the integration. + test "$(git rev-parse HEAD)" = "$CI_SHA" + integration_tree=$(git write-tree) + git cat-file -e "$integration_tree:frontend/$FRONTEND_JEST_CONFIG" + printf 'INTEGRATION_TREE=%s\n' "$integration_tree" >> "$GITHUB_ENV" + printf '{\n "feature_sha": "%s",\n "ci_sha": "%s",\n "merge_base": "%s",\n "integration_tree": "%s",\n "workflow_sha": "%s"\n}\n' \ + "$FEATURE_SHA" "$CI_SHA" "$merge_base" "$integration_tree" "$GITHUB_SHA" \ + > "$ARTIFACT_DIR/provenance.json" + git status --short > "$ARTIFACT_DIR/merged-status.txt" + git diff --stat "$merge_base" "$integration_tree" > "$ARTIFACT_DIR/merged-diff-stat.txt" + # Include eligible changes from both the feature and the CI repair. + git diff --name-only --diff-filter=ACMR -z "$merge_base" "$integration_tree" -- \ + '*.js' '*.jsx' '*.ts' '*.tsx' > "$ARTIFACT_DIR/changed-js-ts.nul" + cat "$ARTIFACT_DIR/provenance.json" + + - name: Set up Node.js 22 + uses: actions/setup-node@v4 + with: + node-version: '22' + + - name: Set up the declared pnpm version + uses: pnpm/action-setup@v4 + with: + version: 9.1.0 + package_json_file: integration/package.json + run_install: false + + - name: Install independently from the lockfile + id: install + run: | + set -euo pipefail + exec > >(tee "$ARTIFACT_DIR/install.log") 2>&1 + # No restored node_modules, shared checkout links, or dependency cache. + test ! -e node_modules + test ! -e frontend/node_modules + test ! -e backend/node_modules + node --version + pnpm --version + test "$(pnpm --version)" = '9.1.0' + pnpm install --frozen-lockfile --store-dir "$RUNNER_TEMP/copy-audit-pnpm-store" + + # A failed validation stays blocking, while unrelated checks still run. + - name: Check frontend TypeScript + id: frontend_types + if: ${{ !cancelled() && steps.merge.outcome == 'success' && steps.install.outcome == 'success' }} + run: | + pnpm exec tsc --project frontend/tsconfig.json --noEmit 2>&1 | tee "$ARTIFACT_DIR/frontend-types.log" + + - name: Check backend TypeScript + id: backend_types + if: ${{ !cancelled() && steps.merge.outcome == 'success' && steps.install.outcome == 'success' }} + run: | + pnpm exec tsc --project backend/tsconfig.json --noEmit 2>&1 | tee "$ARTIFACT_DIR/backend-types.log" + + - name: Build frontend + id: frontend_build + if: ${{ !cancelled() && steps.merge.outcome == 'success' && steps.install.outcome == 'success' }} + working-directory: integration/frontend + run: | + pnpm build 2>&1 | tee "$ARTIFACT_DIR/frontend-build.log" + + - name: Build backend + id: backend_build + if: ${{ !cancelled() && steps.merge.outcome == 'success' && steps.install.outcome == 'success' }} + working-directory: integration/backend + run: | + pnpm build 2>&1 | tee "$ARTIFACT_DIR/backend-build.log" + + - name: Run all source guards + id: source_guards + if: ${{ !cancelled() && steps.merge.outcome == 'success' && steps.install.outcome == 'success' }} + run: | + pnpm check 2>&1 | tee "$ARTIFACT_DIR/source-guards.log" + + - name: Run the matching focused frontend suite + id: frontend_tests + if: ${{ !cancelled() && steps.merge.outcome == 'success' && steps.install.outcome == 'success' }} + working-directory: integration/frontend + run: | + pnpm exec jest --config "$FRONTEND_JEST_CONFIG" --runInBand 2>&1 | tee "$ARTIFACT_DIR/frontend-jest.log" + + - name: Run the full backend Jest suite + id: backend_tests + if: ${{ !cancelled() && steps.merge.outcome == 'success' && steps.install.outcome == 'success' }} + working-directory: integration/backend + run: | + pnpm exec jest --runInBand 2>&1 | tee "$ARTIFACT_DIR/backend-jest.log" + + - name: Lint changed eligible JavaScript and TypeScript without fixes + id: lint + if: ${{ !cancelled() && steps.merge.outcome == 'success' && steps.install.outcome == 'success' }} + run: | + set -euo pipefail + pnpm exec node <<'NODE' 2>&1 | tee "$ARTIFACT_DIR/lint-selection.log" + const fs = require('node:fs'); + const path = require('node:path'); + const { ESLint } = require('eslint'); + (async () => { + const output = process.env.ARTIFACT_DIR; + const candidates = fs.readFileSync(path.join(output, 'changed-js-ts.nul'), 'utf8').split('\0').filter(Boolean); + const eslint = new ESLint({ resolvePluginsRelativeTo: path.resolve('backend') }); + const eligible = []; + const ignored = []; + for (const file of candidates) { + if (await eslint.isPathIgnored(file)) { + ignored.push(file); + console.log(`Ignored by existing ESLint configuration: ${file}`); + } else { + eligible.push(file); + console.log(`Linting: ${file}`); + } + } + fs.writeFileSync(path.join(output, 'lint-files.nul'), eligible.map(file => `${file}\0`).join('')); + fs.writeFileSync(path.join(output, 'lint-files.json'), JSON.stringify({ eligible, ignored }, null, 2) + '\n'); + })().catch(error => { console.error(error); process.exitCode = 1; }); + NODE + mapfile -d '' files < "$ARTIFACT_DIR/lint-files.nul" + if (( ${#files[@]} )); then + pnpm exec eslint --resolve-plugins-relative-to backend "${files[@]}" 2>&1 | tee "$ARTIFACT_DIR/eslint.log" + else + echo 'No changed files are eligible under the existing ESLint configuration.' | tee "$ARTIFACT_DIR/eslint.log" + fi + + - name: Retain validation outcomes + if: always() + working-directory: ${{ github.workspace }} + env: + STEP_RESULTS: ${{ toJSON(steps) }} + run: | + mkdir -p "$ARTIFACT_DIR" + printf '%s\n' "$STEP_RESULTS" > "$ARTIFACT_DIR/step-outcomes.json" + + - name: Upload integration provenance and logs + if: always() + uses: actions/upload-artifact@v4 + with: + name: copy-audit-integration-${{ matrix.scenario }}-${{ github.run_id }}-${{ github.run_attempt }} + path: ${{ env.ARTIFACT_DIR }}/ + if-no-files-found: error + retention-days: 7 diff --git a/scripts/ui-evidence/README.md b/scripts/ui-evidence/README.md new file mode 100644 index 00000000..5c23ed56 --- /dev/null +++ b/scripts/ui-evidence/README.md @@ -0,0 +1,36 @@ +# Copy-audit UI evidence (CI only) + +This infrastructure is deliberately separate from the feature changes. The +workflow runs on pushes to `test/copy-audit-ui-evidence`, so it can collect +review evidence before any workflow is merged into the default branch. + +Each matrix job checks out the exact audited baseline and one exact published +feature commit, installs their locked dependencies independently, then starts +actual Next/React components with deterministic local fixture responses. Only +pnpm's download cache is shared. Never symlink dependencies or build output +between source trees: Next's output tracing can follow those links during +cleanup. + +The runner verifies both source SHAs and writes them together with its own +harness SHA and the fixture limitations into `run.json`. Images visibly label +their fixture scope and source commit. Application copy is never replaced by +the capture scripts. The editor harness adds a disposable route importing the +real components and a minimal layout retaining the real font definitions; that override is recorded explicitly. + +All browser network requests outside the local fixture endpoints are blocked +(or, for the decorative GitHub star counter, answered with a fixed local +response). All identities, strings and tokens are synthetic. Auth/onboarding +assert zero submitted mutations. Project actions and deployment use local +mock outcomes, not live services. These captures do not validate production +accounts, emails, paid generation, persistence, deployment or real clipboard +permission handling. + +The workflow uses read-only repository permissions and no secrets. It pins the +browser tooling, fails on assertions, retains raw PNGs/text observations and +logs for seven days, and uploads artifacts even if a scenario fails. Failure +captures and metadata help diagnose incomplete runs. Inspect the pixels before +calling the result visually verified. + +The harnesses have syntax/YAML validation locally; browser execution is owned +by the isolated repository CI jobs. Do not use these scripts as an alternate +route around a denied local browser connection. diff --git a/scripts/ui-evidence/auth/README.md b/scripts/ui-evidence/auth/README.md new file mode 100644 index 00000000..285e5db5 --- /dev/null +++ b/scripts/ui-evidence/auth/README.md @@ -0,0 +1,13 @@ +# Auth copy UI evidence + +The capture script starts the actual Next frontends from two checkouts, with synthetic GraphQL responses and all external browser requests blocked. It captures signup requirements and unavailable password-reset email before and after. It never submits registration, login, email, payment, or generation mutations. + +Prerequisites: Node 20+, repository dependencies installed from pnpm-lock.yaml with pnpm 9.1.0; Playwright plus Chromium available to this script. Make the original base commit dd33611e3debb0170b801f42370cda55d6c5caa7 and the auth fix commit available as separate checkouts. Install each checkout independently; never symlink node_modules between source trees. + +Run: + +AUTH_COPY_BEFORE_DIR=/absolute/base AUTH_COPY_AFTER_DIR=/absolute/fix AUTH_COPY_OUTPUT_DIR=/absolute/artifacts node capture.mjs + +Ports: browser fixtures 3204 (before) and 3104 (after); internal Next servers 3206 and 3106. Fixture responses are local only. Both contexts block requests to any other origin. Entered strings are synthetic example.test addresses and a dummy password, with no submissions. + +Output: four PNGs plus metadata.json recording exact checkout SHAs, fixture state, viewport, and that no mutations were submitted. These are fixture-state screenshots, not production sign-in or email-delivery validation. diff --git a/scripts/ui-evidence/auth/capture.mjs b/scripts/ui-evidence/auth/capture.mjs new file mode 100644 index 00000000..15e0c943 --- /dev/null +++ b/scripts/ui-evidence/auth/capture.mjs @@ -0,0 +1,126 @@ +import assert from 'node:assert/strict'; +import http from 'node:http'; +import { spawn, execFileSync } from 'node:child_process'; +import { mkdir, writeFile } from 'node:fs/promises'; +import { join, resolve } from 'node:path'; +import { chromium } from 'playwright'; + +const before = resolve(process.env.AUTH_COPY_BEFORE_DIR || '../codefox-auth-before'); +const after = resolve(process.env.AUTH_COPY_AFTER_DIR || '../codefox-fix-auth'); +const output = resolve(process.env.AUTH_COPY_OUTPUT_DIR || './artifacts'); +const expectedBase = 'dd33611e3debb0170b801f42370cda55d6c5caa7'; +const sha = (cwd) => execFileSync('git', ['rev-parse', 'HEAD'], { cwd, encoding: 'utf8' }).trim(); +assert.equal(sha(before), expectedBase, 'Before checkout must use the audited base commit'); +await mkdir(output, { recursive: true }); +const data = { + registrationOpen: true, emailVerificationRequired: false, + googleAuthAvailable: false, passwordResetEmailAvailable: false, + fetchPublicProjects: [], getAvailableModelTags: [], scenarios: [], + designSystems: [], getUserChats: [], getUserProjects: [], me: null, myRoles: [], +}; +const processes = [], servers = [], logs = {}; +let mutations = 0; +let browser; +let lastPage; +let lastLabel; +const csp = "connect-src 'self'; img-src 'self' data: blob:; media-src 'self' blob:;"; +try { + for (const [label, directory, port, nextPort] of [['before', before, 3204, 3206], ['after', after, 3104, 3106]]) { + logs[label] = ''; + const server = http.createServer(async (req, res) => { + res.setHeader('Content-Security-Policy', csp); + res.setHeader('X-Codefox-Review', 'synthetic-auth-copy-fixture'); + if (req.url === '/graphql') { + let body = ''; for await (const chunk of req) body += chunk; + const request = JSON.parse(body || '{}'); + res.setHeader('Content-Type', 'application/json'); + if (/\bmutation\b/.test(request.query || '')) { + mutations++; + res.end(JSON.stringify({ errors: [{ message: 'Review fixture: submissions disabled.' }] })); + } else res.end(JSON.stringify({ data })); + return; + } + if (req.url?.startsWith('/api/')) { + res.writeHead(405, { 'Content-Type': 'application/json' }); + res.end(JSON.stringify({ error: 'Review fixture: API actions disabled.' })); + return; + } + const proxy = http.request({ host: '127.0.0.1', port: nextPort, path: req.url, method: req.method, headers: { ...req.headers, host: `localhost:${nextPort}` } }, response => { + res.writeHead(response.statusCode, { ...response.headers, 'Content-Security-Policy': csp }); + response.pipe(res); + }); + proxy.on('error', () => { res.writeHead(503); res.end('Waiting for local Next server'); }); + req.pipe(proxy); + }); + await new Promise(resolve => server.listen(port, '127.0.0.1', resolve)); + servers.push(server); + const child = spawn(process.execPath, [join(directory, 'frontend/node_modules/next/dist/bin/next'), 'dev', '--hostname', '127.0.0.1', '--port', String(nextPort)], { + cwd: join(directory, 'frontend'), + env: { ...process.env, NEXT_TELEMETRY_DISABLED: '1', NEXT_PUBLIC_GRAPHQL_URL: `http://localhost:${port}/graphql`, NEXT_PUBLIC_GRAPHQL_WS_URL: `ws://localhost:${port}/graphql`, NEXT_PUBLIC_BACKEND_URL: `http://localhost:${port}` }, + stdio: ['ignore', 'pipe', 'pipe'], + }); + for (const stream of [child.stdout, child.stderr]) stream.on('data', chunk => { logs[label] += chunk; }); + processes.push(child); + } + for (const port of [3204, 3104]) { + const until = Date.now() + 180000; + while (true) { + try { const result = await fetch(`http://127.0.0.1:${port}/`, { signal: AbortSignal.timeout(15000) }); if (result.ok) break; } catch {} + assert.ok(Date.now() < until, `Next fixture ${port} did not become ready`); + await new Promise(resolve => setTimeout(resolve, 1000)); + } + } + browser = await chromium.launch({ headless: true }); + for (const [label, port] of [['before', 3204], ['after', 3104]]) { + const origin = `http://localhost:${port}`; + const context = await browser.newContext({ viewport: { width: 1440, height: 1000 }, colorScheme: 'dark' }); + await context.route('**/*', route => { + const url = new URL(route.request().url()); + return url.origin === origin ? route.continue() : route.abort('blockedbyclient'); + }); + const page = await context.newPage(); + lastPage = page; + lastLabel = label; + await page.goto(origin, { waitUntil: 'domcontentloaded' }); + await page.evaluate(({ label, commit }) => { + const badge = document.createElement('div'); + badge.textContent = `UI TEST · synthetic read-only auth fixture · ${label} ${commit.slice(0, 8)}`; + badge.style.cssText = 'position:fixed;bottom:0;left:0;right:0;padding:8px;background:#172033;color:#fff;font:12px monospace;z-index:2147483647;text-align:center'; + document.body.appendChild(badge); + }, { label, commit: sha(label === 'before' ? before : after) }); + await page.getByRole('button', { name: 'Sign Up', exact: true }).click(); + await page.getByRole('dialog').waitFor(); + await page.getByLabel('Password', { exact: true }).fill('abcde1'); + if (label === 'after') { + await page.getByText('Use at least 6 characters and at least two of these:', { exact: false }).waitFor(); + await page.getByLabel('Display name', { exact: true }).waitFor(); + } else await page.getByText('Include at least one uppercase letter', { exact: true }).waitFor(); + await page.screenshot({ path: join(output, `auth-signup-${label}.png`) }); + await page.getByRole('button', { name: 'Close', exact: true }).click(); + await page.getByRole('button', { name: 'Sign In', exact: true }).click(); + await page.getByRole('button', { name: 'Forgot your password?', exact: true }).click(); + await page.getByLabel('Email', { exact: true }).fill('review@example.test'); + const send = page.getByRole('button', { name: 'Send reset link', exact: true }); + if (label === 'after') { + await page.getByText('Password reset email isn’t available on this site right now.', { exact: true }).waitFor(); + assert.equal(await send.isDisabled(), true); + await page.getByRole('dialog', { name: 'Reset your password', exact: true }).waitFor(); + } else assert.equal(await send.isEnabled(), true); + await page.screenshot({ path: join(output, `auth-reset-unavailable-${label}.png`) }); + await context.close(); + } + assert.equal(mutations, 0, 'Screenshot capture must not submit account or email mutations'); + await writeFile(join(output, 'metadata.json'), JSON.stringify({ before: sha(before), after: sha(after), syntheticFixture: true, mailEnabled: false, viewport: { width: 1440, height: 1000 }, mutationsSubmitted: mutations }, null, 2)); +} catch (error) { + if (lastPage && !lastPage.isClosed()) { + await lastPage.screenshot({ path: join(output, `failure-${lastLabel}.png`), timeout: 10000 }).catch(() => {}); + } + await writeFile(join(output, 'failure.json'), JSON.stringify({ label: lastLabel, error: String(error.stack || error), mutationsSubmitted: mutations }, null, 2)); + throw error; +} finally { + await browser?.close(); + for (const child of processes) child.kill('SIGTERM'); + for (const server of servers) server.closeAllConnections?.(); + for (const server of servers) server.close(); + for (const [label, log] of Object.entries(logs)) await writeFile(join(output, `next-${label}.log`), log); +} diff --git a/scripts/ui-evidence/editor/README.md b/scripts/ui-evidence/editor/README.md new file mode 100644 index 00000000..9a8270be --- /dev/null +++ b/scripts/ui-evidence/editor/README.md @@ -0,0 +1,37 @@ +# Isolated editor-feedback screenshot fixtures for CI + +Baseline must be exactly `dd33611e3debb0170b801f42370cda55d6c5caa7`; after must +be the editor-feedback feature commit reported by the implementation worker. +Use separate checkouts, the committed lockfile, pnpm 9.1.0, and Node 22. + +This harness has **not been run locally**. The cloud browser denied localhost +access in this environment; these files prepare an independent CI artifact job. +The feature branch contains no fixture route/root-layout change. + +For each checkout: + +1. Install repository dependencies with pnpm 9.1.0. +2. Run `node /path/to/evidence/setup-fixture.mjs /path/to/checkout`. +3. Start `pnpm --dir /path/to/checkout/frontend exec next dev -p PORT`. +4. Install `playwright@1.51.0` in this evidence directory, then run + `npx playwright install --with-deps chromium`. +5. Run `node capture.mjs http://127.0.0.1:PORT before|after OUTPUT_DIR`. + Suggested isolated ports: 3203 before, 3103 after. +6. Upload all ten PNGs and both observation JSON files. Inspect image pixels + before publishing. A completed job is required before calling them verified. + +The page imports actual CodeEngine, CodeTab, SaveChangesBar, DeployDialog and +WebPreview. Context, HTTP/Apollo, and clipboard results are explicitly mocked; +all network destinations other than the local fixture origin are denied and +counted. No credentials, sign-in, paid generation or deployment is used. +The fake clipboard rejection has a no-op rejection observer to suppress only +the development overlay; it remains rejected for the component's await. +Monaco's script origin is changed to a local nonexistent fixture route so it +cannot fetch the external editor; the history panel itself remains real. +The app layout is temporarily simplified while retaining its actual Next font definitions. Fixture mode is selected after hydration to match the initial server markup. + +Assertions cover before/after indeterminate loading, failed-history treatment +and after retry, actual 320px save-bar layout, falsely optimistic baseline +copy versus selectable recovery after rejection, and preview accessible names. +Backend outcome uncertainty and save/restore request timing are covered by the +committed unit/component tests, not represented as real provider behavior. diff --git a/scripts/ui-evidence/editor/capture.mjs b/scripts/ui-evidence/editor/capture.mjs new file mode 100644 index 00000000..5703d0ad --- /dev/null +++ b/scripts/ui-evidence/editor/capture.mjs @@ -0,0 +1,89 @@ +import { chromium } from 'playwright'; +import assert from 'node:assert/strict'; +import { mkdir, writeFile } from 'node:fs/promises'; +import { join, resolve } from 'node:path'; +const [base, tag, output] = process.argv.slice(2); +assert.ok(base && ['before', 'after'].includes(tag) && output, 'usage: node capture.mjs URL before|after OUTPUT'); +const dir = resolve(output); +await mkdir(dir, { recursive: true }); +const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) }); +const blocked = []; +const results = []; +let lastPage; +let lastScenario; +try { + const context = await browser.newContext({ viewport: { width: 1280, height: 800 } }); + await context.route('**/*', async (route) => { + const url = new URL(route.request().url()); + if (url.origin === new URL(base).origin) return route.continue(); + blocked.push(url.origin + url.pathname); + return route.abort(); + }); + for (const scenario of ['preparing', 'history', 'save', 'deploy', 'preview']) { + const page = await context.newPage(); + lastPage = page; + lastScenario = scenario; + if (scenario === 'save') await page.setViewportSize({ width: 320, height: 720 }); + await page.goto(`${base}/editor-feedback-fixture?case=${scenario}`, { waitUntil: 'networkidle' }); + await page.getByText(/LOCAL CODEFOX FIXTURE/).waitFor(); + if (scenario === 'preparing') { + await page.getByText(tag === 'before' ? /Initializing project \(/ : 'Preparing your project…', { exact: tag === 'after' }).waitFor(); + results.push({ scenario, waitingText: await page.locator('body').innerText() }); + } + if (scenario === 'history') { + await page.getByRole('button', { name: 'History', exact: true }).click(); + await page.getByText(tag === 'before' ? /No history yet/ : "Couldn't load version history. Try again.").waitFor(); + if (tag === 'after') { + await page.getByRole('button', { name: 'Try again', exact: true }).click(); + await page.getByText("Couldn't load version history. Try again.").waitFor(); + } + results.push({ scenario, visibleText: await page.locator('body').innerText() }); + } + if (scenario === 'save') { + const discard = page.getByRole('button', { name: tag === 'before' ? 'Reset' : 'Discard changes', exact: true }); + const save = page.getByRole('button', { name: tag === 'before' ? 'Save' : 'Save file', exact: true }); + const boxes = [await discard.boundingBox(), await save.boundingBox()]; + if (tag === 'after') for (const box of boxes) assert.ok(box && box.x >= 0 && box.x + box.width <= 320, 'save action overflows the 320px viewport'); + results.push({ scenario, viewport: 320, actionBoxes: boxes }); + } + if (scenario === 'deploy') { + await page.getByLabel('Vercel token').fill('fixture-token-not-a-credential'); + await page.getByRole('button', { name: 'Deploy', exact: true }).click(); + await page.getByRole('link', { name: 'https://fixture.example.test/codefox-deployment' }).waitFor(); + await page.getByRole('button', { name: 'Copy deployment URL', exact: true }).click(); + if (tag === 'before') { + await page.locator('.lucide-check').waitFor(); + results.push({ scenario, falselyShowsCopiedCheckAfterRejection: true }); + } else { + const fallback = page.getByRole('textbox', { name: 'Deployment URL', exact: true }); + await fallback.waitFor(); + assert.equal(await fallback.inputValue(), 'https://fixture.example.test/codefox-deployment'); + assert.equal(await fallback.getAttribute('readonly'), ''); + results.push({ scenario, selectableFallback: true, copyStatus: await page.getByRole('status').allTextContents() }); + } + } + if (scenario === 'preview') { + const controls = await page.locator('button').evaluateAll((buttons) => buttons.map((button) => ({ label: button.getAttribute('aria-label'), text: button.textContent }))); + if (tag === 'after') for (const label of ['Go back', 'Go forward', 'Refresh preview', 'Zoom out', 'Zoom in', 'Open preview in new tab', 'Enter full screen']) assert.ok(controls.some((control) => control.label === label), `missing ${label}`); + results.push({ scenario, controls }); + } + await page.evaluate(({ tag, commit }) => { + const badge = document.createElement('div'); + badge.textContent = `UI TEST · mocked editor context/API · ${tag} ${commit.slice(0, 8)}`; + badge.style.cssText = 'position:fixed;top:0;right:0;max-width:100%;padding:3px 6px;background:#172033;color:#fff;font:10px monospace;z-index:2147483647;text-align:center;pointer-events:none'; + document.body.appendChild(badge); + }, { tag, commit: process.env.EVIDENCE_CURRENT_SHA || 'unknown' }); + await page.screenshot({ path: join(dir, `${tag}-${scenario}.png`) }); + await page.close(); + } + assert.deepEqual(blocked, [], 'fixture attempted an external request'); + await writeFile(join(dir, `${tag}-observations.json`), JSON.stringify({ tag, base, commit: process.env.EVIDENCE_CURRENT_SHA, fixtures: 'real components; mocked context, HTTP/Apollo, clipboard; 320px actual viewport for save bar', blockedExternalRequests: blocked, results }, null, 2)); +} catch (error) { + if (lastPage && !lastPage.isClosed()) { + await lastPage.screenshot({ path: join(dir, `${tag}-failure-${lastScenario}.png`), timeout: 10000 }).catch(() => {}); + } + await writeFile(join(dir, `${tag}-failure.json`), JSON.stringify({ tag, scenario: lastScenario, commit: process.env.EVIDENCE_CURRENT_SHA, error: String(error.stack || error), blockedExternalRequests: blocked, results }, null, 2)); + throw error; +} finally { + await browser.close(); +} diff --git a/scripts/ui-evidence/editor/fixture-page.tsx b/scripts/ui-evidence/editor/fixture-page.tsx new file mode 100644 index 00000000..167f40f5 --- /dev/null +++ b/scripts/ui-evidence/editor/fixture-page.tsx @@ -0,0 +1,45 @@ +"use client"; +import React, { useEffect, useMemo, useRef, useState } from 'react'; +import { ApolloClient, ApolloLink, ApolloProvider, InMemoryCache, Observable } from '@apollo/client'; +import { Toaster } from 'sonner'; +import { loader } from '@monaco-editor/react'; +loader.config({ paths: { vs: '/fixture-vs' } }); +import { CodeEngine } from '@/components/chat/code-engine/code-engine'; +import CodeTab from '@/components/chat/code-engine/tabs/code-tab'; +import SaveChangesBar from '@/components/chat/code-engine/save-changes-bar'; +import WebPreview from '@/components/chat/code-engine/web-view'; +import { DeployDialog } from '@/components/chat/code-engine/deploy-dialog'; +import { ProjectContext } from '@/components/chat/code-engine/project-context'; +const pending = new Promise(() => {}); +const fixtureFetch = async (url: any) => { + const path = String(url); + if (path.includes('/versions')) return new Response('{}', { status: 503 }); + if (path.includes('/changes')) return new Response(JSON.stringify({changes: []})); + throw new Error('Unconfigured local fixture request: ' + path); +}; +if (typeof window !== 'undefined') { + window.fetch = fixtureFetch as any; + Object.defineProperty(navigator, 'clipboard', { configurable: true, value: { writeText: () => { const denied = Promise.reject(new Error('Simulated clipboard permission denial')); denied.catch(() => {}); return denied; } } }); +} +export default function Fixture() { + const [mode, setMode] = useState(''); + useEffect(() => { setMode(new URLSearchParams(window.location.search).get('case') || ''); }, []); + const [filePath, setFilePath] = useState('index.html'); + const editorRef = useRef(null); + const client = useMemo(() => new ApolloClient({ cache: new InMemoryCache(), link: new ApolloLink(() => new Observable((observer) => { + observer.next({ data: { deployProject: { __typename:'DeployResult', ok:true, url:'https://fixture.example.test/codefox-deployment', message:'' } } }); observer.complete(); + })) }), []); + const context = useMemo(() => ({curProject:null, projectLoading:false, pollChatProject:() => pending, editorRef, turnsDone:0, turnFinished:()=>{},getWebUrl:()=>pending}),[]); + return +
+
LOCAL CODEFOX FIXTURE · Real components · Mocked context/API · No external requests
+ {mode === 'preparing' && } + {mode === 'history' &&
{}} filePath={filePath} setFilePath={setFilePath} />
} + {mode === 'save-mobile' &&

320px iframe viewport