From 761e1438344aa6c552af9a4f98bb7742f09773ba Mon Sep 17 00:00:00 2001 From: Yaacov Date: Tue, 22 Sep 2026 20:02:47 +0300 Subject: [PATCH] ci: select Compute qualification suites independently --- .github/scripts/compute-ci-gate.mjs | 60 ++++++-- .github/scripts/compute-ci-gate.test.mjs | 128 +++++++++++++++++- .github/workflows/ci.yml | 5 + .../scient-compute-python-kernel.yml | 18 +++ docs/operations/development.md | 23 +++- scripts/compute-ci-workflows.test.ts | 60 ++++++++ 6 files changed, 273 insertions(+), 21 deletions(-) create mode 100644 scripts/compute-ci-workflows.test.ts diff --git a/.github/scripts/compute-ci-gate.mjs b/.github/scripts/compute-ci-gate.mjs index 0b3752c363..0c6e6dd60d 100644 --- a/.github/scripts/compute-ci-gate.mjs +++ b/.github/scripts/compute-ci-gate.mjs @@ -2,12 +2,26 @@ import * as NodeChildProcess from "node:child_process"; import * as NodeFS from "node:fs"; import * as NodeURL from "node:url"; -export function needsComputeQualification(paths) { +export function computeQualificationSuites(paths) { + // Only narrow inputs whose consumer is known. Shared runtime code (including + // ManagedPython*.ts imported by PythonComputeRuntime) still selects both. + const kernelOnly = new Set([ + "apps/server/src/scient/compute/PythonKernel.integration.test.ts", + "apps/server/src/scient/compute/PythonComputeService.integration.test.ts", + "apps/server/src/scient/compute/FreshCompute.integration.test.ts", + ]); + const managedOnly = new Set([ + "apps/server/src/scient/compute/ManagedPythonProduct.live.test.ts", + "apps/server/src/scient/compute/ComputeRecipe.live.test.ts", + "apps/server/src/scient/compute/managed-python/pyproject.toml", + "apps/server/src/scient/compute/managed-python/uv.lock", + ]); const exact = new Set([ ".github/workflows/ci.yml", ".github/workflows/scient-compute-python-kernel.yml", ".github/scripts/compute-ci-gate.mjs", ".github/scripts/compute-ci-gate.test.mjs", + "scripts/compute-ci-workflows.test.ts", "apps/server/src/atomicWrite.ts", "apps/server/src/atomicWrite.test.ts", "apps/server/scripts/compute-recipes.ts", @@ -16,6 +30,9 @@ export function needsComputeQualification(paths) { "package.json", "apps/server/package.json", "apps/server/vite.config.ts", + "vite.config.ts", + "apps/server/src/config.ts", + "apps/server/src/serverSettings.ts", ]); const prefixes = [ "apps/server/src/scient/compute/", @@ -24,10 +41,31 @@ export function needsComputeQualification(paths) { "apps/server/src/localEndpoints/", "packages/scient-compute/", "packages/contracts/src/scientCompute", + "packages/scient-execution/", + "packages/scient-project-init/", + "packages/scient-provider-runtime/", + "packages/shared/src/hostProcess", + "apps/server/src/workspace/", + "apps/server/src/testUtils/", ]; - return paths.some( - (path) => exact.has(path) || prefixes.some((prefix) => path.startsWith(prefix)), - ); + let realKernel = false; + let managedPython = false; + for (const path of paths) { + if (kernelOnly.has(path) || path.startsWith("apps/server/src/preview/PortScanner")) { + realKernel = true; + } else if (managedOnly.has(path)) { + managedPython = true; + } else if (exact.has(path) || prefixes.some((prefix) => path.startsWith(prefix))) { + realKernel = true; + managedPython = true; + } + } + return { realKernel, managedPython }; +} + +export function needsComputeQualification(paths) { + const suites = computeQualificationSuites(paths); + return suites.realKernel || suites.managedPython; } export function testGatePasses({ workspace, detection, changed, native }) { @@ -55,18 +93,22 @@ function detectChanges() { maxBuffer: 32 * 1024 * 1024, }, ).split("\0"); - return needsComputeQualification(paths); + return computeQualificationSuites(paths); } catch { console.warn("Could not establish the changed paths; running Compute qualification."); - return true; + return { realKernel: true, managedPython: true }; } } if (process.argv[1] && import.meta.url === NodeURL.pathToFileURL(process.argv[1]).href) { if (process.argv[2] === "detect") { - const changed = detectChanges(); - NodeFS.appendFileSync(process.env.GITHUB_OUTPUT, `changed=${changed}\n`); - console.log(`Compute qualification required: ${changed}`); + const suites = detectChanges(); + const changed = suites.realKernel || suites.managedPython; + NodeFS.appendFileSync( + process.env.GITHUB_OUTPUT, + `changed=${changed}\nreal_kernel=${suites.realKernel}\nmanaged_python=${suites.managedPython}\n`, + ); + console.log("Compute qualification:", suites); } else if (process.argv[2] === "check") { const results = { workspace: process.env.WORKSPACE_RESULT, diff --git a/.github/scripts/compute-ci-gate.test.mjs b/.github/scripts/compute-ci-gate.test.mjs index b7504b7e70..ff0f2185be 100644 --- a/.github/scripts/compute-ci-gate.test.mjs +++ b/.github/scripts/compute-ci-gate.test.mjs @@ -5,7 +5,81 @@ import * as NodeOS from "node:os"; import * as NodePath from "node:path"; import * as NodeURL from "node:url"; import * as NodeTest from "node:test"; -import { needsComputeQualification, testGatePasses } from "./compute-ci-gate.mjs"; +import { + computeQualificationSuites, + needsComputeQualification, + testGatePasses, +} from "./compute-ci-gate.mjs"; + +const neither = { realKernel: false, managedPython: false }; +const kernel = { realKernel: true, managedPython: false }; +const managed = { realKernel: false, managedPython: true }; +const both = { realKernel: true, managedPython: true }; + +NodeTest.test("known suite-specific inputs select only their consumer", () => { + for (const path of [ + "apps/server/src/preview/PortScanner.ts", + "apps/server/src/preview/PortScanner.test.ts", + "apps/server/src/preview/PortScannerPythonCompute.integration.test.ts", + "apps/server/src/scient/compute/PythonKernel.integration.test.ts", + "apps/server/src/scient/compute/PythonComputeService.integration.test.ts", + "apps/server/src/scient/compute/FreshCompute.integration.test.ts", + ]) + NodeAssert.deepEqual(computeQualificationSuites([path]), kernel, path); + for (const path of [ + "apps/server/src/scient/compute/ManagedPythonProduct.live.test.ts", + "apps/server/src/scient/compute/ComputeRecipe.live.test.ts", + "apps/server/src/scient/compute/managed-python/pyproject.toml", + "apps/server/src/scient/compute/managed-python/uv.lock", + ]) + NodeAssert.deepEqual(computeQualificationSuites([path]), managed, path); +}); + +NodeTest.test("shared runtime, setup and uncertain dependencies retain both suites", () => { + for (const path of [ + "apps/server/src/scient/compute/ComputeSessionService.ts", + "apps/server/src/scient/compute/ManagedPythonEnvironment.ts", + "apps/server/src/scient/compute/ManagedPythonProvisioner.ts", + "apps/server/src/scient/compute/ComputeRecipeSource.ts", + "apps/server/src/scient/compute/managed-python/bundled-recipes.json", + "apps/server/src/scient/compute/NewRuntimeDependency.ts", + "apps/server/src/scient/compute/bridge/scient_compute_bridge.py", + "apps/server/src/scient/execution/LocalOwnedProcess.ts", + "apps/server/src/atomicWrite.ts", + "apps/server/src/config.ts", + "apps/server/src/serverSettings.ts", + "apps/server/src/workspace/WorkspacePaths.ts", + "apps/server/src/testUtils/gitConfig.setup.ts", + "packages/scient-execution/src/index.ts", + "packages/scient-project-init/src/index.ts", + "packages/scient-provider-runtime/src/index.ts", + "packages/shared/src/hostProcess.ts", + "vite.config.ts", + "pnpm-lock.yaml", + "apps/server/scripts/compute-recipes.ts", + ".github/workflows/ci.yml", + ]) + NodeAssert.deepEqual(computeQualificationSuites([path]), both, path); +}); + +NodeTest.test("selection is a union: adding files never removes required coverage", () => { + const paths = [ + "README.md", + "apps/server/src/preview/PortScanner.ts", + "apps/server/src/scient/compute/managed-python/uv.lock", + "apps/server/src/scient/compute/PythonComputeRuntime.ts", + ]; + for (const first of paths) + for (const second of paths) { + const a = computeQualificationSuites([first]); + const b = computeQualificationSuites([second]); + NodeAssert.deepEqual(computeQualificationSuites([first, second]), { + realKernel: a.realKernel || b.realKernel, + managedPython: a.managedPython || b.managedPython, + }); + } + NodeAssert.deepEqual(computeQualificationSuites([]), neither); +}); NodeTest.test( "native inputs, lifecycle dependencies and the gate itself trigger qualification", @@ -77,7 +151,12 @@ NodeTest.test("detector handles PRs, pushes, deletions/renames and unresolved co }, stdio: "pipe", }); - return NodeFS.readFileSync(outputPath, "utf8").trim(); + return Object.fromEntries( + NodeFS.readFileSync(outputPath, "utf8") + .trim() + .split("\n") + .map((line) => line.split("=")), + ); }; try { git("init", "--quiet"); @@ -88,7 +167,11 @@ NodeTest.test("detector handles PRs, pushes, deletions/renames and unresolved co git("add", "apps"); git("-c", "core.hooksPath=/dev/null", "commit", "--quiet", "-m", "baseline"); const base = git("rev-parse", "HEAD"); - NodeAssert.equal(detect({ before: base }, base), "changed=false"); + NodeAssert.deepEqual(detect({ before: base }, base), { + changed: "false", + real_kernel: "false", + managed_python: "false", + }); NodeFS.renameSync( NodePath.join(directory, "apps/server/src/atomicWrite.ts"), NodePath.join(directory, "moved.txt"), @@ -96,10 +179,41 @@ NodeTest.test("detector handles PRs, pushes, deletions/renames and unresolved co git("add", "apps", "moved.txt"); git("-c", "core.hooksPath=/dev/null", "commit", "--quiet", "-m", "move out of scope"); const head = git("rev-parse", "HEAD"); - NodeAssert.equal(detect({ pull_request: { base: { sha: base } } }, head), "changed=true"); - NodeAssert.equal(detect({ before: base }, head), "changed=true"); - NodeAssert.equal(detect({ before: "0".repeat(40) }, head), "changed=true"); - NodeAssert.equal(detect({}, head), "changed=true"); + const all = { changed: "true", real_kernel: "true", managed_python: "true" }; + NodeAssert.deepEqual(detect({ pull_request: { base: { sha: base } } }, head), all); + NodeAssert.deepEqual(detect({ before: base }, head), all); + NodeAssert.deepEqual(detect({ before: "0".repeat(40) }, head), all); + NodeAssert.deepEqual(detect({}, head), all); + // A normal PR and a post-merge push select the same relevant suites. + NodeFS.mkdirSync(NodePath.join(directory, "apps/server/src/preview"), { recursive: true }); + NodeFS.writeFileSync( + NodePath.join(directory, "apps/server/src/preview/PortScanner.ts"), + "fixture\n", + ); + git("add", "apps"); + git("-c", "core.hooksPath=/dev/null", "commit", "--quiet", "-m", "scanner change"); + const scannerHead = git("rev-parse", "HEAD"); + const scanner = { changed: "true", real_kernel: "true", managed_python: "false" }; + NodeAssert.deepEqual(detect({ before: head }, scannerHead), scanner); + NodeAssert.deepEqual(detect({ pull_request: { base: { sha: head } } }, scannerHead), scanner); + NodeFS.mkdirSync(NodePath.join(directory, "apps/server/src/scient/compute/managed-python"), { + recursive: true, + }); + NodeFS.writeFileSync( + NodePath.join(directory, "apps/server/src/scient/compute/managed-python/uv.lock"), + "fixture\n", + ); + git("add", "apps"); + git("-c", "core.hooksPath=/dev/null", "commit", "--quiet", "-m", "managed recipe change"); + const recipeHead = git("rev-parse", "HEAD"); + const recipe = { changed: "true", real_kernel: "false", managed_python: "true" }; + NodeAssert.deepEqual(detect({ before: scannerHead }, recipeHead), recipe); + NodeAssert.deepEqual( + detect({ pull_request: { base: { sha: scannerHead } } }, recipeHead), + recipe, + ); + // Both changes in the same PR must retain both suites. + NodeAssert.deepEqual(detect({ pull_request: { base: { sha: head } } }, recipeHead), all); } finally { NodeFS.rmSync(directory, { recursive: true, force: true }); } diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9cf51ae3bb..7651d310bc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -131,6 +131,8 @@ jobs: timeout-minutes: 5 outputs: changed: ${{ steps.detect.outputs.changed }} + real_kernel: ${{ steps.detect.outputs.real_kernel }} + managed_python: ${{ steps.detect.outputs.managed_python }} steps: - uses: actions/checkout@v6 with: @@ -146,6 +148,9 @@ jobs: needs: compute_changes if: ${{ !cancelled() && needs.compute_changes.outputs.changed != 'false' }} uses: ./.github/workflows/scient-compute-python-kernel.yml + with: + real_kernel: ${{ needs.compute_changes.outputs.real_kernel != 'false' }} + managed_python: ${{ needs.compute_changes.outputs.managed_python != 'false' }} # Keep the already-required check name. Native failures must block it, while # unrelated PRs may skip native qualification only after a successful diff. diff --git a/.github/workflows/scient-compute-python-kernel.yml b/.github/workflows/scient-compute-python-kernel.yml index e70e43e956..8131bc59a9 100644 --- a/.github/workflows/scient-compute-python-kernel.yml +++ b/.github/workflows/scient-compute-python-kernel.yml @@ -13,7 +13,23 @@ name: Scient Compute Python Kernel on: workflow_call: + inputs: + real_kernel: + type: boolean + default: true + managed_python: + type: boolean + default: true workflow_dispatch: + inputs: + real_kernel: + description: Run the real-kernel OS and Python-version matrix + type: boolean + default: true + managed_python: + description: Provision and qualify managed Python toolkits + type: boolean + default: true permissions: contents: read @@ -24,6 +40,7 @@ concurrency: jobs: managed_python: + if: ${{ inputs.managed_python }} name: Managed Python toolkits / ${{ matrix.runner }} runs-on: ${{ matrix.runner }} timeout-minutes: 30 @@ -68,6 +85,7 @@ jobs: run: vp test run src/scient/compute/ManagedPythonProduct.live.test.ts src/scient/compute/ComputeRecipe.live.test.ts --maxWorkers=1 real_kernel: + if: ${{ inputs.real_kernel }} name: Real kernel / ${{ matrix.runner }} / Python ${{ matrix.python }} runs-on: ${{ matrix.runner }} timeout-minutes: 20 diff --git a/docs/operations/development.md b/docs/operations/development.md index feea47f250..f896d83bde 100644 --- a/docs/operations/development.md +++ b/docs/operations/development.md @@ -154,11 +154,24 @@ revision or working diff and reuse that evidence while the candidate is unchange can invalidate a result, rerun the affected check; broad shared-runtime, orchestration, packaging, or test-harness changes normally need wider requalification. See [ci.yml](../../.github/workflows/ci.yml) for hosted checks. -The required `Test` check includes the native Compute matrix when its inputs -change, including process ownership, atomic persistence, contracts and dependency -locks. Unrelated changes skip that matrix; an unresolved diff runs it. The matrix -also remains manually dispatchable. This uses the existing required check, without -requiring a separate branch-protection setting for path-dependent jobs. +The required `Test` check includes applicable native Compute suites. The selector +in `.github/scripts/compute-ci-gate.mjs` distinguishes these inputs: + +- Preview-scanner changes and the real-kernel integration test files run the + Linux/macOS/Windows real-kernel matrix, without provisioning managed toolkits. +- Managed live-test files and the managed `pyproject.toml`/`uv.lock` fixtures run + managed Python qualification, without the system-Python matrix. +- Shared runtime, process ownership, persistence, workspace dependencies, Compute + contracts and test infrastructure run both. `ManagedPython*.ts` is shared too: + the existing-Python runtime imports it even when not provisioning an environment. +- Unrelated UI/docs changes run neither. Mixed changes take the union; uncertain + diffs and JavaScript dependency lockfile changes retain both suites. + +Both suites remain enabled by default for reusable callers and manual dispatch; +manual dispatch can also select either suite. Relevant pushes to main retain +post-merge verification of the integrated tree. No cross-revision success cache or +dependency-lock graph is used to skip checks. This uses the existing required +`Test` check without separate branch-protection settings for conditional jobs. The [manual Windows lane](../../.github/workflows/windows-tests.yml) is available for focused Windows investigation while that suite is not a required gate. diff --git a/scripts/compute-ci-workflows.test.ts b/scripts/compute-ci-workflows.test.ts new file mode 100644 index 0000000000..07333457f5 --- /dev/null +++ b/scripts/compute-ci-workflows.test.ts @@ -0,0 +1,60 @@ +// @effect-diagnostics nodeBuiltinImport:off -- workflow contract tests read checked-in YAML only. +import * as NodeFS from "node:fs"; +import { describe, expect, it } from "@effect/vitest"; +import * as YAML from "yaml"; + +const workflow = (name: string): unknown => + YAML.parse(NodeFS.readFileSync(new URL(`../.github/workflows/${name}`, import.meta.url), "utf8")); + +describe("Compute CI suite selection", () => { + it("keeps both suites enabled by default for release callers and manual runs", () => { + expect(workflow("scient-compute-python-kernel.yml")).toMatchObject({ + on: { + workflow_call: { + inputs: { + real_kernel: { type: "boolean", default: true }, + managed_python: { type: "boolean", default: true }, + }, + }, + workflow_dispatch: { + inputs: { + real_kernel: { type: "boolean", default: true }, + managed_python: { type: "boolean", default: true }, + }, + }, + }, + jobs: { + real_kernel: { if: "${{ inputs.real_kernel }}" }, + managed_python: { if: "${{ inputs.managed_python }}" }, + }, + }); + }); + + it("wires each suite independently and skips it only on an explicit false", () => { + expect(workflow("ci.yml")).toMatchObject({ + jobs: { + compute_changes: { + outputs: { + changed: "${{ steps.detect.outputs.changed }}", + real_kernel: "${{ steps.detect.outputs.real_kernel }}", + managed_python: "${{ steps.detect.outputs.managed_python }}", + }, + }, + compute_native: { + needs: "compute_changes", + if: "${{ !cancelled() && needs.compute_changes.outputs.changed != 'false' }}", + uses: "./.github/workflows/scient-compute-python-kernel.yml", + with: { + real_kernel: "${{ needs.compute_changes.outputs.real_kernel != 'false' }}", + managed_python: "${{ needs.compute_changes.outputs.managed_python != 'false' }}", + }, + }, + test: { + name: "Test", + needs: ["test_workspaces", "compute_changes", "compute_native"], + if: "${{ always() }}", + }, + }, + }); + }); +});