From 6b9952525d2775e09e204e140c3ee4584dbfa602 Mon Sep 17 00:00:00 2001 From: appleguy Date: Fri, 20 Nov 2026 20:02:21 -0800 Subject: [PATCH] build(server): omit tests from production compilation (#19383) Use a separate production TypeScript configuration that excludes colocated tests while retaining every runtime source input and keeping tests in source typechecking. Verify the real compiler input sets and bound compiler-list capture for the larger source graph. Validation: focused compiler-input regression passes; fresh CI has 61 passing checks and three optional skips on 181ad8d; Greptile Apex is 5/5 with no unresolved comments. Co-Authored-By: Scott Goodson Co-Authored-By: Devin Foley Co-Authored-By: Paperclip --- doc/test-infrastructure.md | 7 ++++-- server/package.json | 2 +- server/scripts/build-config.test.mjs | 36 ++++++++++++++++++++++++++++ server/tsconfig.build.json | 4 ++++ 4 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 server/scripts/build-config.test.mjs create mode 100644 server/tsconfig.build.json diff --git a/doc/test-infrastructure.md b/doc/test-infrastructure.md index 914eef94f2a..60c663fa66f 100644 --- a/doc/test-infrastructure.md +++ b/doc/test-infrastructure.md @@ -149,8 +149,11 @@ cores. It also takes about twice as long. It checks one package at a time and uses one thread for the server layers and the UI. Do not add `GOMEMLIMIT` to this path. It saves at most 300 MiB here, and it slows `tsc` by up to 20 times when the live heap goes above the limit. -`pnpm build` still checks the whole server program and needs more than 8 GiB. The -Docker image sets `PAPERCLIP_TSC_EMIT_ONLY=1` for that build, which emits +`pnpm build` uses `server/tsconfig.build.json` for the production server compile. +It excludes colocated test modules and the top-level test helper tree. The source +typecheck still includes the tests. Compiler memory use depends on the runtime +source graph and checker count; excluding tests does not set a memory limit. +The Docker image sets `PAPERCLIP_TSC_EMIT_ONLY=1` for that build, which emits JavaScript without checks or declarations. Test projects outside `pnpm -r` import server source through relative paths. Each diff --git a/server/package.json b/server/package.json index cd8c75a7ad6..83e3c1564b6 100644 --- a/server/package.json +++ b/server/package.json @@ -36,7 +36,7 @@ "dev": "tsx src/index.ts", "dev:watch": "cross-env PAPERCLIP_MIGRATION_PROMPT=never PAPERCLIP_MIGRATION_AUTO_APPLY=true tsx ./scripts/dev-watch.ts", "prepare:ui-dist": "bash ../scripts/prepare-server-ui-dist.sh", - "build": "pnpm run prepare:runner-vendor && node scripts/verify-runner-vendor-dependencies.mjs && node ../scripts/run-tsc.mjs && mkdir -p dist/onboarding-assets dist/built-ins dist/services/scripts dist/vendor/paperclip-runner && cp -R src/onboarding-assets/. dist/onboarding-assets/ && cp -R src/built-ins/. dist/built-ins/ && cp -R src/services/scripts/. dist/services/scripts/ && cp -Rf ../packages/paperclip-runner/dist/. dist/vendor/paperclip-runner/ && cp ../packages/paperclip-runner/scripts/install-copilot-assets.mjs ../packages/paperclip-runner/scripts/materialize-copilot-binary.mjs ../packages/paperclip-runner/scripts/copilot-inner-distribution.mjs dist/ && node dist/install-copilot-assets.mjs && node scripts/write-build-stamp.mjs", + "build": "pnpm run prepare:runner-vendor && node scripts/verify-runner-vendor-dependencies.mjs && node ../scripts/run-tsc.mjs -p tsconfig.build.json && mkdir -p dist/onboarding-assets dist/built-ins dist/services/scripts dist/vendor/paperclip-runner && cp -R src/onboarding-assets/. dist/onboarding-assets/ && cp -R src/built-ins/. dist/built-ins/ && cp -R src/services/scripts/. dist/services/scripts/ && cp -Rf ../packages/paperclip-runner/dist/. dist/vendor/paperclip-runner/ && cp ../packages/paperclip-runner/scripts/install-copilot-assets.mjs ../packages/paperclip-runner/scripts/materialize-copilot-binary.mjs ../packages/paperclip-runner/scripts/copilot-inner-distribution.mjs dist/ && node dist/install-copilot-assets.mjs && node scripts/write-build-stamp.mjs", "prepack": "pnpm run prepare:ui-dist && pnpm run build", "postpack": "rm -rf ui-dist", "clean": "rm -rf dist", diff --git a/server/scripts/build-config.test.mjs b/server/scripts/build-config.test.mjs new file mode 100644 index 00000000000..ccbe2b088e8 --- /dev/null +++ b/server/scripts/build-config.test.mjs @@ -0,0 +1,36 @@ +import { spawnSync } from "node:child_process"; +import { readFileSync } from "node:fs"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; + +import { expect, it } from "vitest"; + +const serverRoot = fileURLToPath(new URL("../", import.meta.url)); + +function compilerInputs(args) { + const result = spawnSync(process.execPath, ["../scripts/run-tsc.mjs", ...args, "--listFilesOnly"], { + cwd: serverRoot, + encoding: "utf8", + maxBuffer: 8 * 1024 * 1024, + timeout: 30_000, + }); + if (result.error) throw result.error; + expect(result.status, result.stderr || result.stdout).toBe(0); + return result.stdout.split(/\r?\n/).filter((file) => file.startsWith(path.join(serverRoot, "src", path.sep))); +} + +it("omits co-located tests from the build while retaining source typecheck coverage", () => { + const { scripts } = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")); + const command = scripts.build.split("&&").map((part) => part.trim()) + .find((part) => part.startsWith("node ../scripts/run-tsc.mjs")); + expect(command).toBeDefined(); + const production = compilerInputs(command.split(/\s+/).slice(2)); + const source = compilerInputs(["-p", "tsconfig.json"]); + const isTest = (file) => /\.test\.tsx?$/.test(file); + + expect(source.filter(isTest).length).toBeGreaterThan(0); + expect(production.filter(isTest)).toEqual([]); + const productionFiles = new Set(production); + const testTree = path.join(serverRoot, "src", "__tests__", path.sep); + expect(source.filter((file) => !isTest(file) && !file.startsWith(testTree) && !productionFiles.has(file))).toEqual([]); +}, 60_000); diff --git a/server/tsconfig.build.json b/server/tsconfig.build.json new file mode 100644 index 00000000000..b30459b9d4f --- /dev/null +++ b/server/tsconfig.build.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.json", + "exclude": ["src/__tests__", "src/**/*.test.ts", "src/**/*.test.tsx"] +}