Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

ci(perf): keep web test jobs below five minutes (#15832)

Tobias Wochinger027f75c4f587
diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml
index c1600ea6fb..477ab89cb1 100644
--- a/.github/workflows/pipeline.yml
+++ b/.github/workflows/pipeline.yml
@@ -470,7 +470,7 @@ jobs:
if-no-files-found: ignore
tests-web:
timeout-minutes: 30
- runs-on: blacksmith-4vcpu-ubuntu-2404
+ runs-on: blacksmith-8vcpu-ubuntu-2404
needs:
- pre-job
# pre-job only runs on push events; everywhere else it resolves as skipped
@@ -613,23 +613,59 @@ jobs:
- name: run tests
working-directory: web
# The server tests are I/O-bound (Postgres/ClickHouse/HTTP roundtrips),
- # so 8 workers on the 4-vCPU runner overlap DB waits. Worker isolation
- # is configured per project in vitest.config.mts. The CPU-bound client
- # (jsdom) tests measured slower when merged into this invocation, so
- # they keep their own step below.
+ # but still need one runner vCPU per worker to avoid oversubscribing the
+ # local databases when several DB-heavy files run concurrently. Worker
+ # isolation is configured per project in vitest.config.mts. The
+ # CPU-bound client (jsdom) tests measured slower when merged into this
+ # invocation, so they run in their own parallel job below.
env:
NODE_COMPILE_CACHE: /tmp/node-compile-cache
- run: npx dotenv -e ../.env.test -e ../.env -- vitest run --project server --project server-isolated --project server-unit --maxWorkers=8
- - name: run test-client
- if: matrix.deploy-mode == ''
- working-directory: web
- run: npx dotenv -e ../.env.test -e ../.env -- vitest run --project client
+ run: npx dotenv -e ../.env.test -e ../.env -- vitest run --project server --project server-isolated --project server-shared-source --project server-unit --project server-shared-source-unit --maxWorkers=8
- name: Prune stale turbo cache entries
if: env.CI_CACHE_ALLOWED == 'true'
# Each run saves the restored archive plus new entries, so the cache
# grows without bound unless old entries are dropped before the save.
run: find .turbo/cache -type f -mtime +3 -delete 2>/dev/null || true
+ tests-web-client:
+ timeout-minutes: 10
+ runs-on: blacksmith-4vcpu-ubuntu-2404
+ needs:
+ - pre-job
+ if: ${{ !cancelled() && (github.event_name != 'push' || needs.pre-job.outputs.should_skip != 'true') }}
+ steps:
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ persist-credentials: false
+ - uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9
+ with:
+ version: 11.10.0
+ - name: Use Node.js ${{ env.NODE_VERSION }} without cache
+ if: env.CI_CACHE_ALLOWED != 'true'
+ uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
+ with:
+ node-version: ${{ env.NODE_VERSION }}
+ package-manager-cache: false
+ - name: Use Node.js ${{ env.NODE_VERSION }} with pnpm cache
+ if: env.CI_CACHE_ALLOWED == 'true'
+ uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # zizmor: ignore[cache-poisoning] test job dependency cache only; no released artifacts are built or published from this cached state
+ with:
+ node-version: ${{ env.NODE_VERSION }}
+ cache: "pnpm"
+ cache-dependency-path: "pnpm-lock.yaml"
+ - name: install dependencies
+ run: pnpm install
+ - name: Load default env
+ run: cp .env.dev.example .env
+ - name: Build client test dependencies
+ # Client tests import workspace packages directly. Build only web's
+ # dependencies (not the Next.js app) so cold caches have package entry
+ # points without paying for an unnecessary production web build.
+ run: pnpm turbo run build --filter=web^...
+ - name: run test-client
+ working-directory: web
+ run: pnpm run test-client
+
tests-worker:
timeout-minutes: 20
runs-on: blacksmith-4vcpu-ubuntu-2404
@@ -1037,6 +1073,7 @@ jobs:
tests-storybook,
tests-shared,
tests-web,
+ tests-web-client,
tests-worker,
test-worker-llm-connections,
e2e-tests,
diff --git a/.github/workflows/warm-caches.yml b/.github/workflows/warm-caches.yml
index 295f663bc8..3186afc151 100644
--- a/.github/workflows/warm-caches.yml
+++ b/.github/workflows/warm-caches.yml
@@ -15,10 +15,10 @@ name: Warm CI caches
# to daily or delete the workflow — it is purely compensatory.
on:
schedule:
- # Every 3 hours, offset from the top of the hour to dodge runner-pool
+ # Every 6 hours, offset from the top of the hour to dodge runner-pool
# congestion. Frequency chosen to stay under the observed hours-scale
# cache lifetime.
- - cron: "23 */3 * * *"
+ - cron: "23 */6 * * *"
workflow_dispatch:
permissions:
diff --git a/web/AGENTS.md b/web/AGENTS.md
index 6241c35e1b..478d3d9ed3 100644
--- a/web/AGENTS.md
+++ b/web/AGENTS.md
@@ -200,6 +200,18 @@ Sentry instrumentation skill first and decide whether it should capture at all
unique test data over global reset helpers.
- Put pure server unit tests that do not need Postgres bootstrap under
`src/__tests__/server/unit/**` so they skip the shared DB setup hook.
+- Preserve the server-test project split in `vitest.config.mts`. Most tests
+ consume the built `@langfuse/shared` package; only tests importing
+ `@langfuse/shared/in-app-agent` or `@langfuse/shared/src/env` use the
+ `server-shared-source*` projects. Do not move `sharedSourceResolve` back to
+ the root config: applying those aliases globally increased server-test
+ transforms/imports and made Vitest about 27–30% slower. The integration and
+ unit source projects stay separate because only integration tests run the
+ database `globalSetup`.
+- Keep CI web server tests at eight workers on an eight-vCPU runner unless a
+ new benchmark supports changing both together. With the current 4,237-test
+ suite, median Vitest duration was 82s at 8 workers/8 vCPUs, 115s at
+ 4 workers/8 vCPUs, and 145s at 8 workers/4 vCPUs (measured 2026-08-06).
- For small utility functions, prefer Vitest in-source tests when colocated
coverage is the simplest option, especially when the test needs access to
private implementation details without widening the module API.
diff --git a/web/package.json b/web/package.json
index f711c746ac..518229cf08 100644
--- a/web/package.json
+++ b/web/package.json
@@ -17,10 +17,10 @@
"analyze": "dotenv -e ../.env -- next experimental-analyze",
"clean": "rm -rf node_modules",
"start": "dotenv -e ../.env -- sh -c 'NEXT_MANUAL_SIG_HANDLE=true next start'",
- "test": "vitest run --project server --project server-isolated --project server-unit --project in-source",
+ "test": "vitest run --project server --project server-isolated --project server-shared-source --project server-unit --project server-shared-source-unit --project in-source",
"test:in-source": "vitest run --project in-source",
"test-client": "vitest run --project client",
- "test:watch": "vitest --project client --project server --project server-isolated --project server-unit --project in-source",
+ "test:watch": "vitest --project client --project server --project server-isolated --project server-shared-source --project server-unit --project server-shared-source-unit --project in-source",
"test-storybook": "vitest run --project storybook",
"test:e2e": "dotenv -e ../.env.test -e ../.env -- playwright test --reporter=line",
"test:e2e:server": "vitest run --project e2e-server",
diff --git a/web/vitest.config.mts b/web/vitest.config.mts
index 2f086d0c63..77e5745fa5 100644
--- a/web/vitest.config.mts
+++ b/web/vitest.config.mts
@@ -32,14 +32,29 @@ const sharedExclude = [
const GLOBAL_STATE_PATTERN =
/vi\.(mock|doMock|unmock|spyOn|useFakeTimers|setSystemTime|resetModules|stubEnv|stubGlobal|unstubAllEnvs|unstubAllGlobals)|process\.env\.[A-Z0-9_]+\s*=[^=]|process\.env\[[^\]]+\]\s*=[^=]|delete\s+process\.env|\(env as any\)\.\w+\s*=[^=]|\.(disconnect|quit|shutdown)\(|disconnectQueues/;
-const serverTestFiles = globSync("src/**/server/**/*.servertest.{ts,tsx}", {
+const allServerTestFiles = globSync("src/**/server/**/*.servertest.{ts,tsx}", {
cwd: import.meta.dirname,
- exclude: [
- "**/node_modules/**",
- "src/__e2e__/**",
- "src/__tests__/server/unit/**",
- ],
+ exclude: ["**/node_modules/**", "src/__e2e__/**"],
});
+const SHARED_SOURCE_IDENTITY_PATTERN =
+ /@langfuse\/shared\/(?:in-app-agent|src\/env)/;
+// Derive membership from imports so new tests cannot silently miss aliases.
+const sharedSourceTestFiles = allServerTestFiles.filter((file) =>
+ SHARED_SOURCE_IDENTITY_PATTERN.test(
+ readFileSync(join(import.meta.dirname, file), "utf8"),
+ ),
+);
+const sharedSourceUnitTestFiles = sharedSourceTestFiles.filter((file) =>
+ file.startsWith("src/__tests__/server/unit/"),
+);
+const sharedSourceIntegrationTestFiles = sharedSourceTestFiles.filter(
+ (file) => !sharedSourceUnitTestFiles.includes(file),
+);
+const serverTestFiles = allServerTestFiles.filter(
+ (file) =>
+ !file.startsWith("src/__tests__/server/unit/") &&
+ !sharedSourceIntegrationTestFiles.includes(file),
+);
const isolatedServerTestFiles = serverTestFiles.filter((file) =>
GLOBAL_STATE_PATTERN.test(
readFileSync(join(import.meta.dirname, file), "utf8"),
@@ -62,87 +77,107 @@ function markdownRawPlugin() {
};
}
+const sharedSourcePath = (path: string) =>
+ join(import.meta.dirname, "../packages/shared/src", path);
+
+// Shared's built dist is CJS, whose require() calls bypass Vitest's module
+// graph. Tests that mock the in-app-agent runtime or mutate shared's env need
+// one source module identity; applying these aliases globally makes every
+// server test transform shared.
+const sharedSourceResolve = {
+ alias: [
+ {
+ find: /^@langfuse\/shared\/in-app-agent\/server\/(.+)$/,
+ replacement: sharedSourcePath("in-app-agent/server/$1"),
+ },
+ {
+ find: /^@langfuse\/shared\/in-app-agent\/server$/,
+ replacement: sharedSourcePath("in-app-agent/server/index.ts"),
+ },
+ {
+ find: /^@langfuse\/shared\/in-app-agent$/,
+ replacement: sharedSourcePath("in-app-agent/index.ts"),
+ },
+ // The runtime source reaches the rest of shared via relative imports
+ // (../../../server etc.), so shared's other entry points must resolve
+ // to the same source files — otherwise tests would load a second dist
+ // copy of shared (split singletons, vi.mock("@langfuse/shared/src/
+ // server") missing the runtime's imports).
+ {
+ find: /^@langfuse\/shared\/src\/(.+)$/,
+ replacement: sharedSourcePath("$1"),
+ },
+ {
+ find: /^@langfuse\/shared\/encryption$/,
+ replacement: sharedSourcePath("encryption/index.ts"),
+ },
+ {
+ find: /^@langfuse\/shared\/query$/,
+ replacement: sharedSourcePath("features/query/index.ts"),
+ },
+ {
+ find: /^@langfuse\/shared\/query\/server$/,
+ replacement: sharedSourcePath("features/query/server/index.ts"),
+ },
+ {
+ find: /^@langfuse\/shared\/monitors$/,
+ replacement: sharedSourcePath("features/monitors/index.ts"),
+ },
+ {
+ find: /^@langfuse\/shared\/monitors\/server$/,
+ replacement: sharedSourcePath("features/monitors/server.ts"),
+ },
+ {
+ find: /^@langfuse\/shared$/,
+ replacement: sharedSourcePath("index.ts"),
+ },
+ ],
+ // Runtime source resolves these through shared's node_modules symlinks.
+ // Dedupe keeps one module identity so mocks registered from web intercept.
+ dedupe: [
+ "@mastra/core",
+ "@mastra/mcp",
+ "@ag-ui/core",
+ "@ag-ui/client",
+ "@ag-ui/mastra",
+ "ai-sdk-amazon-bedrock-v4",
+ "langfuse",
+ ],
+};
+
+function serverProject(
+ name: string,
+ include: string[],
+ options: {
+ database?: boolean;
+ env?: Record<string, string>;
+ exclude?: string[];
+ isolate?: boolean;
+ resolve?: typeof sharedSourceResolve;
+ } = {},
+) {
+ return {
+ extends: true as const,
+ ...(options.resolve ? { resolve: options.resolve } : {}),
+ test: {
+ name,
+ include,
+ exclude: [...sharedExclude, ...(options.exclude ?? [])],
+ ...(options.isolate === undefined ? {} : { isolate: options.isolate }),
+ ...(options.env ? { env: options.env } : {}),
+ environment: "node" as const,
+ setupFiles: ["./src/__tests__/after-teardown.ts"],
+ ...(options.database
+ ? { globalSetup: ["./src/__tests__/vitest-test-db-setup.ts"] }
+ : {}),
+ },
+ };
+}
+
export default defineConfig({
plugins: [markdownRawPlugin(), tsconfigPaths(), react()],
resolve: {
- // The in-app-agent runtime lives in @langfuse/shared. Its built dist is
- // CJS, whose require() calls bypass vitest's mocker — so tests that mock
- // the runtime's dependencies (@mastra/*, instrumentation, …) would hit
- // the real modules. Alias the runtime subpaths to shared *source* so
- // vite processes it as ESM and mocks intercept.
alias: [
- {
- find: /^@langfuse\/shared\/in-app-agent\/server\/(.+)$/,
- replacement: join(
- import.meta.dirname,
- "../packages/shared/src/in-app-agent/server/$1",
- ),
- },
- {
- find: /^@langfuse\/shared\/in-app-agent\/server$/,
- replacement: join(
- import.meta.dirname,
- "../packages/shared/src/in-app-agent/server/index.ts",
- ),
- },
- {
- find: /^@langfuse\/shared\/in-app-agent$/,
- replacement: join(
- import.meta.dirname,
- "../packages/shared/src/in-app-agent/index.ts",
- ),
- },
- // The runtime source reaches the rest of shared via relative imports
- // (../../../server etc.), so shared's other entry points must resolve
- // to the same source files — otherwise tests would load a second dist
- // copy of shared (split singletons, vi.mock("@langfuse/shared/src/
- // server") missing the runtime's imports).
- {
- find: /^@langfuse\/shared\/src\/(.+)$/,
- replacement: join(import.meta.dirname, "../packages/shared/src/$1"),
- },
- {
- find: /^@langfuse\/shared\/encryption$/,
- replacement: join(
- import.meta.dirname,
- "../packages/shared/src/encryption/index.ts",
- ),
- },
- {
- find: /^@langfuse\/shared\/query$/,
- replacement: join(
- import.meta.dirname,
- "../packages/shared/src/features/query/index.ts",
- ),
- },
- {
- find: /^@langfuse\/shared\/query\/server$/,
- replacement: join(
- import.meta.dirname,
- "../packages/shared/src/features/query/server/index.ts",
- ),
- },
- {
- find: /^@langfuse\/shared\/monitors$/,
- replacement: join(
- import.meta.dirname,
- "../packages/shared/src/features/monitors/index.ts",
- ),
- },
- {
- find: /^@langfuse\/shared\/monitors\/server$/,
- replacement: join(
- import.meta.dirname,
- "../packages/shared/src/features/monitors/server.ts",
- ),
- },
- {
- find: /^@langfuse\/shared$/,
- replacement: join(
- import.meta.dirname,
- "../packages/shared/src/index.ts",
- ),
- },
// next-query-params ships a CJS `pages` entry whose default-export
// interop breaks when the package is inlined (server.deps.inline
// below, needed so vi.mock("next/router") intercepts the adapter's
@@ -155,19 +190,6 @@ export default defineConfig({
),
},
],
- // The runtime source resolves Mastra/AG-UI/Bedrock through shared's
- // node_modules symlinks — a different module id than the test files'
- // vi.mock registrations, which resolve through web's. Dedupe forces a
- // single resolution so the mocks intercept the runtime's imports.
- dedupe: [
- "@mastra/core",
- "@mastra/mcp",
- "@ag-ui/core",
- "@ag-ui/client",
- "@ag-ui/mastra",
- "ai-sdk-amazon-bedrock-v4",
- "langfuse",
- ],
},
test: {
reporters: process.env.CI
@@ -214,43 +236,29 @@ export default defineConfig({
setupFiles: ["@testing-library/jest-dom/vitest"],
},
},
- {
- extends: true,
- test: {
- name: "server",
- include: sharedContextServerTestFiles,
- exclude: sharedExclude,
- isolate: false,
- // Workers are reused across files, so the per-file teardown must
- // not disconnect shared singletons (redis, ClickHouse) that later
- // files in the same worker still use. See after-teardown.ts.
- env: { VITEST_SHARED_CONTEXT: "1" },
- environment: "node",
- setupFiles: ["./src/__tests__/after-teardown.ts"],
- globalSetup: ["./src/__tests__/vitest-test-db-setup.ts"],
- },
- },
- {
- extends: true,
- test: {
- name: "server-isolated",
- include: isolatedServerTestFiles,
- exclude: sharedExclude,
- environment: "node",
- setupFiles: ["./src/__tests__/after-teardown.ts"],
- globalSetup: ["./src/__tests__/vitest-test-db-setup.ts"],
- },
- },
- {
- extends: true,
- test: {
- name: "server-unit",
- include: ["src/__tests__/server/unit/**/*.servertest.{ts,tsx}"],
- exclude: sharedExclude,
- environment: "node",
- setupFiles: ["./src/__tests__/after-teardown.ts"],
- },
- },
+ serverProject("server", sharedContextServerTestFiles, {
+ database: true,
+ isolate: false,
+ // Workers are reused across files, so the per-file teardown must not
+ // disconnect shared singletons (redis, ClickHouse) that later files
+ // in the same worker still use. See after-teardown.ts.
+ env: { VITEST_SHARED_CONTEXT: "1" },
+ }),
+ serverProject("server-isolated", isolatedServerTestFiles, {
+ database: true,
+ }),
+ serverProject("server-shared-source", sharedSourceIntegrationTestFiles, {
+ database: true,
+ resolve: sharedSourceResolve,
+ }),
+ serverProject(
+ "server-unit",
+ ["src/__tests__/server/unit/**/*.servertest.{ts,tsx}"],
+ { exclude: sharedSourceUnitTestFiles },
+ ),
+ serverProject("server-shared-source-unit", sharedSourceUnitTestFiles, {
+ resolve: sharedSourceResolve,
+ }),
{
extends: true,
plugins: [