diff --git a/.github/scripts/tests/ci-plan.test.mjs b/.github/scripts/tests/ci-plan.test.mjs index 25e8580fb00..e27aa8d96d8 100644 --- a/.github/scripts/tests/ci-plan.test.mjs +++ b/.github/scripts/tests/ci-plan.test.mjs @@ -64,7 +64,17 @@ test("repository-wide guidance guards run uncached for every scanned UI file typ const workflow = readFileSync(new URL(".github/workflows/pr-trusted.yml", root), "utf8"); const job = workflow.split("\n typecheck_release_registry:\n")[1].split("\n general_tests:\n")[0]; assert.match(job, /\n run: node scripts\/ci-typecheck-lane\.mjs\n/); - const guidance = planLane({ buildGapPackages: [], testLayers: [] }).tasks.find((task) => task.name === "CLI guidance safety"); + assert.match(job, /\n if: \$\{\{ hashFiles\('scripts\/ci-typecheck-lane\.mjs'\) != '' \}\}\n run: node scripts\/ci-typecheck-lane\.mjs\n/); + const fallback = job.split("\n if: ${{ hashFiles('scripts/ci-typecheck-lane.mjs') == '' }}\n")[1].split("\n\n")[0]; + for (const command of [ + "pnpm run typecheck:build-gaps", + "node scripts/typecheck-test-programs.mjs --low-memory", + "pnpm --filter @paperclipai/server typecheck", + "node scripts/typecheck-test-projects.mjs --low-memory --reuse-declarations", + "server/src/__tests__/cli-invocation-safety.test.ts", + "pnpm run test:release-registry", + ]) assert.ok(fallback.includes(command), command); + const guidance = planLane({ buildGapPackages: [], testLayers: [] }).prepare.find((task) => task.name === "CLI guidance safety"); assert.deepEqual(guidance.args, ["exec", "vitest", "run", "--project", "@paperclipai/server", "server/src/__tests__/cli-invocation-safety.test.ts"]); assert.ok(!job.includes("uses: ./.github/actions/run-ci-task")); }); diff --git a/.github/workflows/pr-trusted.yml b/.github/workflows/pr-trusted.yml index 391df4f854f..5c8dfb63cd1 100644 --- a/.github/workflows/pr-trusted.yml +++ b/.github/workflows/pr-trusted.yml @@ -463,8 +463,21 @@ jobs: run: node scripts/runner-release-crate-cache.mjs mark-current - name: Typecheck, CLI guidance safety and release registry tests + if: ${{ hashFiles('scripts/ci-typecheck-lane.mjs') != '' }} run: node scripts/ci-typecheck-lane.mjs + - name: Typecheck a checkout that predates the typecheck lane script + if: ${{ hashFiles('scripts/ci-typecheck-lane.mjs') == '' }} + env: + PAPERCLIP_TYPECHECK_LOW_MEMORY: "1" + run: | + pnpm run typecheck:build-gaps + node scripts/typecheck-test-programs.mjs --low-memory + pnpm --filter @paperclipai/server typecheck + node scripts/typecheck-test-projects.mjs --low-memory --reuse-declarations + pnpm exec vitest run --project @paperclipai/server server/src/__tests__/cli-invocation-safety.test.ts + pnpm run test:release-registry + - name: Upload CI profile timings continue-on-error: true if: always() && env.PAPERCLIP_CI_PROFILE == 'true' diff --git a/doc/DEVELOPING.md b/doc/DEVELOPING.md index 7a03bbebfdc..a2cf4fd5be0 100644 --- a/doc/DEVELOPING.md +++ b/doc/DEVELOPING.md @@ -1564,13 +1564,15 @@ It first runs the steps that write shared outputs, one at a time: (`typecheck-test-programs.mjs --prepare-only`). 4. Typecheck the Runner. Its typecheck rebuilds the eval kernel, which other checks read, so it cannot run beside them. +5. Run the CLI guidance test. It runs here, before the parallel checks, because + one of its cases took 17 seconds beside them against a 15 second timeout. Then it runs the remaining checks in parallel, as many as the machine has CPUs (default) or `--concurrency`. Each `tsc` uses one thread. The server declaration layers start first, because the test layers and the test projects -read them. The test programs, the other build-gap workspaces and the CLI -guidance test run at a lower CPU priority, so they use only the CPU that the -server layers and the release registry tests leave free. +read them. The test programs and the other build-gap workspaces run at a lower +CPU priority, so they use only the CPU that the server layers and the release +registry tests leave free. A passing check prints its output in a collapsed log group. A failing check prints its output in full, between `=== FAILED ...` and `=== end of ...` @@ -1581,6 +1583,10 @@ nothing else runs. To add a check to the job, add it to `planLane` in the script. +PR runs take the workflow from `master` but check out the PR's merge commit. A +stacked PR, whose base is another branch, can have a merge commit without this +script. The job then runs the six earlier commands one after another instead. + #### Typecheck test files outside the build Most package tsconfigs exclude tests, and Vitest strips types, so a type error in diff --git a/scripts/__tests__/ci-typecheck-lane.test.mjs b/scripts/__tests__/ci-typecheck-lane.test.mjs index 64107c85eca..0385c614866 100644 --- a/scripts/__tests__/ci-typecheck-lane.test.mjs +++ b/scripts/__tests__/ci-typecheck-lane.test.mjs @@ -25,6 +25,9 @@ test("the shared outputs are written before the parallel checks start", () => { assert.ok(prepare.some((task) => task.name === `typecheck ${name}`), name); assert.ok(!tasks.some((task) => task.name === `typecheck ${name}`), name); } + const guidance = prepare.find((task) => task.name === "CLI guidance safety"); + assert.ok(guidance.args.includes("server/src/__tests__/cli-invocation-safety.test.ts")); + assert.equal(guidance.background, undefined); const programs = tasks.find((task) => task.name === "typecheck test programs"); assert.ok(programs.args.includes("--skip-prepare")); for (const task of tasks) { @@ -48,7 +51,7 @@ test("every check of the sequential job is planned, and only declaration readers } for (const name of ["paperclipai", "@paperclipai/ui"]) assert.ok(byName.has(`typecheck ${name}`), name); assert.deepEqual(byName.get("release registry tests").args, ["run", "test:release-registry"]); - assert.ok(byName.get("CLI guidance safety").args.includes("server/src/__tests__/cli-invocation-safety.test.ts")); + assert.ok(!byName.has("CLI guidance safety")); const waiting = tasks.filter((task) => task.needs); assert.equal(waiting.length, 2 + PROJECTS.length); assert.deepEqual( @@ -146,7 +149,11 @@ test("the PR typecheck job runs the lane after the Runner release crate restore" const job = workflow.split("\n typecheck_release_registry:\n")[1].split("\n general_tests:\n")[0]; const lane = job.indexOf("run: node scripts/ci-typecheck-lane.mjs"); assert.ok(lane > job.indexOf("- name: Mark the restored Runner release crate current")); + const missingScript = "if: ${{ hashFiles('scripts/ci-typecheck-lane.mjs') == '' }}"; + const [beforeFallback, fallback] = job.split(missingScript); + assert.ok(beforeFallback.includes("if: ${{ hashFiles('scripts/ci-typecheck-lane.mjs') != '' }}\n run: node scripts/ci-typecheck-lane.mjs")); for (const command of ["typecheck:build-gaps", "typecheck-test-programs.mjs", "typecheck-test-projects.mjs", "test:release-registry"]) { - assert.ok(!job.includes(command), command); + assert.ok(!beforeFallback.includes(command), command); + assert.ok(fallback.includes(command), command); } }); diff --git a/scripts/ci-typecheck-lane.mjs b/scripts/ci-typecheck-lane.mjs index 312e9c57207..dedf200319a 100644 --- a/scripts/ci-typecheck-lane.mjs +++ b/scripts/ci-typecheck-lane.mjs @@ -11,6 +11,7 @@ import { PROJECTS } from "./typecheck-test-projects.mjs"; export const SERIAL_BUILD_GAPS = ["@paperclipai/paperclip-runner"]; export const BACKGROUND_PRIORITY = 10; const SERVER_DECLARATIONS = "server declarations"; +export const CLI_GUIDANCE_SAFETY = "CLI guidance safety"; const lowMemory = { [LOW_MEMORY_VARIABLE]: "1" }; export function planLane({ buildGapPackages, testLayers, projects = PROJECTS }) { @@ -37,6 +38,11 @@ export function planLane({ buildGapPackages, testLayers, projects = PROJECTS }) }, { name: "install test program dependencies", command: "node", args: ["scripts/typecheck-test-programs.mjs", "--prepare-only"] }, ...buildGapPackages.filter((name) => SERIAL_BUILD_GAPS.includes(name)).map((name) => typecheckPackage(name, false)), + { + name: CLI_GUIDANCE_SAFETY, + command: "pnpm", + args: ["exec", "vitest", "run", "--project", "@paperclipai/server", "server/src/__tests__/cli-invocation-safety.test.ts"], + }, ]; const needsDeclarations = [SERVER_DECLARATIONS]; const tasks = [ @@ -67,12 +73,6 @@ export function planLane({ buildGapPackages, testLayers, projects = PROJECTS }) needs: needsDeclarations, })), ...buildGapPackages.filter((name) => !SERIAL_BUILD_GAPS.includes(name)).map((name) => typecheckPackage(name, true)), - { - name: "CLI guidance safety", - command: "pnpm", - args: ["exec", "vitest", "run", "--project", "@paperclipai/server", "server/src/__tests__/cli-invocation-safety.test.ts"], - background: true, - }, ]; return { prepare, tasks }; }