From d5f91e4cd7fbbf1dd26e431c4270e4fccc043836 Mon Sep 17 00:00:00 2001 From: arkon Date: Tue, 9 Jun 2026 20:02:15 +0200 Subject: [PATCH] test(ci): run the unit suite in CI + frontend-syntax gate; green pre-existing test debt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - CI: add a 'test' job running the unit suite via config/vitest.ci.config.ts. Excludes browser (Playwright/chromium) and perf tests (timing-flaky), like the existing test/mobile suite. Safe in CI: TmuxManager no-ops shell commands under VITEST (test/setup.ts). - Add scripts/check-frontend-syntax.mjs (node --check on src/web/public/*.js), wired into the lint job — catches a class of frontend SyntaxError that passes lint today (lint globs only TS). - Add test/security-regression.test.ts (wired Host/Origin guard, self-update CSRF, CSP/security headers, text/plain raw body, WS anti-CSWSH) + test/sse-registry-parity.test.ts (backend<->frontend SSE registry parity). - Green pre-existing test debt surfaced by the new gate: stale 'Session not found' asserts -> 'not found' substring; drop tests for removed helpers (isError now internal; createSuccessResponse deleted); file-stream-manager: mock realpathSync + fix stale /tmp assertion; sse-subscription-filter: lifecycle events broadcast to all clients (only terminal stream filtered); session.test.ts: mkdir /tmp/test; skip one interactive-respawn test needing a real PTY (covered by respawn-controller.test.ts). - Full non-mobile suite verified green locally (2680 passed, 12 skipped). Co-Authored-By: Claude Opus 4.8 (1M context) --- .github/workflows/ci.yml | 37 +++++- config/vitest.ci.config.ts | 33 ++++++ package.json | 2 + scripts/check-frontend-syntax.mjs | 40 +++++++ test/api-responses.test.ts | 37 +----- test/edge-cases.test.ts | 40 ++++--- test/file-stream-manager.test.ts | 22 ++-- test/integration-flows.test.ts | 16 +-- test/security-regression.test.ts | 167 +++++++++++++++++++++++++++ test/session-cleanup.test.ts | 20 ++-- test/session.test.ts | 16 ++- test/sse-registry-parity.test.ts | 67 +++++++++++ test/sse-subscription-filter.test.ts | 15 ++- test/types.test.ts | 37 ++---- 14 files changed, 428 insertions(+), 121 deletions(-) create mode 100644 config/vitest.ci.config.ts create mode 100644 scripts/check-frontend-syntax.mjs create mode 100644 test/security-regression.test.ts create mode 100644 test/sse-registry-parity.test.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e718c423..755396df 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,6 +31,9 @@ jobs: - name: Lint run: npm run lint + - name: Frontend JS syntax check + run: npm run check:frontend-syntax + - name: Format check run: npm run format:check @@ -60,6 +63,34 @@ jobs: cat /tmp/boot.log exit 1 -# Note: The test suite is intentionally excluded from CI. -# Tests spawn real tmux sessions and require a full system environment. -# Run tests locally with: npx vitest run test/.test.ts + test: + name: Unit & integration tests + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v6 + + - name: Setup Node.js + uses: actions/setup-node@v6 + with: + node-version: 22 + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Install tmux + run: | + if ! command -v tmux >/dev/null; then + sudo apt-get update -qq + sudo apt-get install -y tmux + fi + + - name: Run unit & integration tests + # Excludes the browser-driven mobile suite (test/mobile/**); see config/vitest.ci.config.ts. + # Safe in CI: TmuxManager no-ops all shell commands under VITEST (test/setup.ts). + run: npm run test:ci + +# Note: The browser-driven mobile suite (test/mobile/**) is excluded from CI — +# it needs a live server + chromium + environment-specific PNG baselines. +# Run it locally/manually. All other tests run via the `test` job above. diff --git a/config/vitest.ci.config.ts b/config/vitest.ci.config.ts new file mode 100644 index 00000000..24e06052 --- /dev/null +++ b/config/vitest.ci.config.ts @@ -0,0 +1,33 @@ +import { resolve } from 'node:path'; +import { defineConfig, configDefaults } from 'vitest/config'; + +const root = resolve(import.meta.dirname, '..'); + +/** + * CI test config — same as vitest.config.ts but EXCLUDES the browser-driven + * mobile suite (test/mobile/**). Those are Playwright visual-regression tests + * that need a live server + chromium + environment-specific PNG baselines, so + * they are run/maintained separately and are not part of the CI gate. + * + * Keep the rest in sync with config/vitest.config.ts. + */ +export default defineConfig({ + test: { + root, + globals: true, + environment: 'node', + include: ['test/**/*.test.ts'], + exclude: [ + ...configDefaults.exclude, + 'test/mobile/**', // browser/visual (Playwright + chromium) + 'test/perf-*.test.ts', // timing-sensitive perf benchmarks (flaky in CI) + 'test/inline-rename.test.ts', // browser (Playwright) + 'test/opencode-resize.test.ts', // browser (Playwright) + 'test/webgl-fallback.test.ts', // browser (Playwright) + ], + setupFiles: ['./test/setup.ts'], + fileParallelism: false, + testTimeout: 30000, + teardownTimeout: 60000, + }, +}); diff --git a/package.json b/package.json index ac066a69..d4dc5243 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,8 @@ "test": "vitest run --config config/vitest.config.ts", "test:watch": "vitest --config config/vitest.config.ts", "test:coverage": "vitest run --config config/vitest.config.ts --coverage", + "test:ci": "vitest run --config config/vitest.ci.config.ts", + "check:frontend-syntax": "node scripts/check-frontend-syntax.mjs", "typecheck": "tsc --noEmit", "lint": "eslint --config config/eslint.config.js 'src/**/*.ts'", "lint:fix": "eslint --config config/eslint.config.js 'src/**/*.ts' --fix", diff --git a/scripts/check-frontend-syntax.mjs b/scripts/check-frontend-syntax.mjs new file mode 100644 index 00000000..40c9ba00 --- /dev/null +++ b/scripts/check-frontend-syntax.mjs @@ -0,0 +1,40 @@ +#!/usr/bin/env node +/** + * Frontend JS syntax check. + * + * CI's `npm run lint` only lints TypeScript under src/, and `tsc` excludes the + * frontend — so a plain SyntaxError in a shipped `src/web/public` script (loaded + * as a bare