From 842deefe5d63be05aac99c4f1cd58303936b7e8a Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 2 Mar 2026 05:31:39 +0000 Subject: [PATCH] test: split fast lane from channel and gateway suites --- docs/reference/test.md | 4 +++ package.json | 3 +++ scripts/test-parallel.mjs | 54 +++++++++++++++++++++++---------------- vitest.channels.config.ts | 20 +++++++++++++++ vitest.unit.config.ts | 14 +++++++++- 5 files changed, 72 insertions(+), 23 deletions(-) create mode 100644 vitest.channels.config.ts diff --git a/docs/reference/test.md b/docs/reference/test.md index 49fcdb4814b..8d99e674c3f 100644 --- a/docs/reference/test.md +++ b/docs/reference/test.md @@ -12,6 +12,10 @@ title: "Tests" - `pnpm test:force`: Kills any lingering gateway process holding the default control port, then runs the full Vitest suite with an isolated gateway port so server tests don’t collide with a running instance. Use this when a prior gateway run left port 18789 occupied. - `pnpm test:coverage`: Runs the unit suite with V8 coverage (via `vitest.unit.config.ts`). Global thresholds are 70% lines/branches/functions/statements. Coverage excludes integration-heavy entrypoints (CLI wiring, gateway/telegram bridges, webchat static server) to keep the target focused on unit-testable logic. - `pnpm test` on Node 24+: OpenClaw auto-disables Vitest `vmForks` and uses `forks` to avoid `ERR_VM_MODULE_LINK_FAILURE` / `module is already linked`. You can force behavior with `OPENCLAW_TEST_VM_FORKS=0|1`. +- `pnpm test`: runs the fast core unit lane by default for quick local feedback. +- `pnpm test:channels`: runs channel-heavy suites. +- `pnpm test:extensions`: runs extension/plugin suites. +- Gateway integration: opt-in via `OPENCLAW_TEST_INCLUDE_GATEWAY=1 pnpm test` or `pnpm test:gateway`. - `pnpm test:e2e`: Runs gateway end-to-end smoke tests (multi-instance WS/HTTP/node pairing). Defaults to `vmForks` + adaptive workers in `vitest.e2e.config.ts`; tune with `OPENCLAW_E2E_WORKERS=` and set `OPENCLAW_E2E_VERBOSE=1` for verbose logs. - `pnpm test:live`: Runs provider live tests (minimax/zai). Requires API keys and `LIVE=1` (or provider-specific `*_LIVE_TEST=1`) to unskip. diff --git a/package.json b/package.json index cc1e61966a4..357b4ac2b7a 100644 --- a/package.json +++ b/package.json @@ -123,6 +123,7 @@ "start": "node scripts/run-node.mjs", "test": "node scripts/test-parallel.mjs", "test:all": "pnpm lint && pnpm build && pnpm test && pnpm test:e2e && pnpm test:live && pnpm test:docker:all", + "test:channels": "vitest run --config vitest.channels.config.ts", "test:coverage": "vitest run --config vitest.unit.config.ts --coverage", "test:docker:all": "pnpm test:docker:live-models && pnpm test:docker:live-gateway && pnpm test:docker:onboard && pnpm test:docker:gateway-network && pnpm test:docker:qr && pnpm test:docker:doctor-switch && pnpm test:docker:plugins && pnpm test:docker:cleanup", "test:docker:cleanup": "bash scripts/test-cleanup-docker.sh", @@ -134,8 +135,10 @@ "test:docker:plugins": "bash scripts/e2e/plugins-docker.sh", "test:docker:qr": "bash scripts/e2e/qr-import-docker.sh", "test:e2e": "vitest run --config vitest.e2e.config.ts", + "test:extensions": "vitest run --config vitest.extensions.config.ts", "test:fast": "vitest run --config vitest.unit.config.ts", "test:force": "node --import tsx scripts/test-force.ts", + "test:gateway": "vitest run --config vitest.gateway.config.ts --pool=forks", "test:install:e2e": "bash scripts/test-install-sh-e2e-docker.sh", "test:install:e2e:anthropic": "OPENCLAW_E2E_MODELS=anthropic CLAWDBOT_E2E_MODELS=anthropic bash scripts/test-install-sh-e2e-docker.sh", "test:install:e2e:openai": "OPENCLAW_E2E_MODELS=openai CLAWDBOT_E2E_MODELS=openai bash scripts/test-install-sh-e2e-docker.sh", diff --git a/scripts/test-parallel.mjs b/scripts/test-parallel.mjs index d6b96c13382..83bf5e77302 100644 --- a/scripts/test-parallel.mjs +++ b/scripts/test-parallel.mjs @@ -102,6 +102,8 @@ const useVmForks = process.env.OPENCLAW_TEST_VM_FORKS === "1" || (process.env.OPENCLAW_TEST_VM_FORKS !== "0" && !isWindows && supportsVmForks && !lowMemLocalHost); const disableIsolation = process.env.OPENCLAW_TEST_NO_ISOLATE === "1"; +const includeGatewaySuite = process.env.OPENCLAW_TEST_INCLUDE_GATEWAY === "1"; +const includeExtensionsSuite = process.env.OPENCLAW_TEST_INCLUDE_EXTENSIONS === "1"; const runs = [ ...(useVmForks ? [ @@ -135,28 +137,36 @@ const runs = [ args: ["vitest", "run", "--config", "vitest.unit.config.ts"], }, ]), - { - name: "extensions", - args: [ - "vitest", - "run", - "--config", - "vitest.extensions.config.ts", - ...(useVmForks ? ["--pool=vmForks"] : []), - ], - }, - { - name: "gateway", - args: [ - "vitest", - "run", - "--config", - "vitest.gateway.config.ts", - // Gateway tests are sensitive to vmForks behavior (global state + env stubs). - // Keep them on process forks for determinism even when other suites use vmForks. - "--pool=forks", - ], - }, + ...(includeExtensionsSuite + ? [ + { + name: "extensions", + args: [ + "vitest", + "run", + "--config", + "vitest.extensions.config.ts", + ...(useVmForks ? ["--pool=vmForks"] : []), + ], + }, + ] + : []), + ...(includeGatewaySuite + ? [ + { + name: "gateway", + args: [ + "vitest", + "run", + "--config", + "vitest.gateway.config.ts", + // Gateway tests are sensitive to vmForks behavior (global state + env stubs). + // Keep them on process forks for determinism even when other suites use vmForks. + "--pool=forks", + ], + }, + ] + : []), ]; const shardOverride = Number.parseInt(process.env.OPENCLAW_TEST_SHARDS ?? "", 10); const configuredShardCount = diff --git a/vitest.channels.config.ts b/vitest.channels.config.ts new file mode 100644 index 00000000000..0b32080b1d5 --- /dev/null +++ b/vitest.channels.config.ts @@ -0,0 +1,20 @@ +import { defineConfig } from "vitest/config"; +import baseConfig from "./vitest.config.ts"; + +const base = baseConfig as unknown as Record; +const baseTest = (baseConfig as { test?: { exclude?: string[] } }).test ?? {}; + +export default defineConfig({ + ...base, + test: { + ...baseTest, + include: [ + "src/telegram/**/*.test.ts", + "src/discord/**/*.test.ts", + "src/web/**/*.test.ts", + "src/browser/**/*.test.ts", + "src/line/**/*.test.ts", + ], + exclude: [...(baseTest.exclude ?? []), "src/gateway/**", "extensions/**"], + }, +}); diff --git a/vitest.unit.config.ts b/vitest.unit.config.ts index 5031856d0ea..8116da0592b 100644 --- a/vitest.unit.config.ts +++ b/vitest.unit.config.ts @@ -13,6 +13,18 @@ export default defineConfig({ test: { ...baseTest, include, - exclude: [...exclude, "src/gateway/**", "extensions/**"], + exclude: [ + ...exclude, + "src/gateway/**", + "extensions/**", + "src/telegram/**", + "src/discord/**", + "src/web/**", + "src/browser/**", + "src/line/**", + "src/agents/**", + "src/auto-reply/**", + "src/commands/**", + ], }, });