OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security
TypeScript ai-securityapplication-securityclicode-scanningcodexcodex-securitycybersecuritydevsecopsnodejsnpmopenaisdksecuritytypescriptvulnerability-scanning
ci: select required checks and centralize their result gate (#1902)
Michael D'Angelo8cd61797506a
diff --git a/.github/scripts/check-ci-results.mjs b/.github/scripts/check-ci-results.mjsnew file mode 100644index 000000000..2c9a865e8--- /dev/null+++ b/.github/scripts/check-ci-results.mjs@@ -0,0 +1,39 @@+import { pathToFileURL } from "node:url";++export function failedChecks(needs) {+ if (needs["classify-changes"]?.result !== "success")+ return ["classify-changes"];+ const selected = needs["classify-changes"].outputs;+ const required = ["static-checks"];+ if (selected["source-required"] === "true") {+ required.push(+ "native",+ "package",+ "test",+ "compatibility",+ "mcp",+ "plugin-host",+ "plugin-source",+ "windows-test",+ "windows-verify",+ );+ } else if (selected["source-required"] !== "false") {+ return ["source-required classification"];+ }+ for (const check of ["workflow-quality", "container-validate"]) {+ if (selected[check] === "true") required.push(check);+ else if (selected[check] !== "false") return [`${check} classification`];+ }+ return required.filter((name) => needs[name]?.result !== "success");+}++if (+ process.argv[1] &&+ import.meta.url === pathToFileURL(process.argv[1]).href+) {+ const failures = failedChecks(JSON.parse(process.env.CI_RESULTS));+ if (failures.length) {+ console.error(`Required CI checks did not pass: ${failures.join(", ")}`);+ process.exitCode = 1;+ } else console.log("All selected required CI checks passed.");+}diff --git a/.github/scripts/select-ci-checks.mjs b/.github/scripts/select-ci-checks.mjsnew file mode 100644index 000000000..5734ea589--- /dev/null+++ b/.github/scripts/select-ci-checks.mjs@@ -0,0 +1,78 @@+import { execFileSync } from "node:child_process";+import { appendFileSync } from "node:fs";+import { pathToFileURL } from "node:url";++const documentation =+ /^(?:README\.md|CONTRIBUTING\.md|CODE_OF_CONDUCT\.md|docs\/.*\.md|github-action\/README\.md|docker\/README\.md)$/;+const ordinarySource =+ /^(?:sdk\/typescript\/(?:src|tests-ts)|plugins\/codex-security\/mcp-app\/(?:src|tests))\/.*\.ts$/;++export function selectChecks(paths, { event, baseChanged = false }) {+ // Only known documentation and TypeScript source paths can narrow qualification.+ const full =+ event !== "pull_request" ||+ baseChanged ||+ paths.length === 0 ||+ paths.some(+ (path) => !documentation.test(path) && !ordinarySource.test(path),+ );+ const source = full || !paths.every((path) => documentation.test(path));+ const compatibility = ["22.13.0", "24.0.0", "24", "26.0.0", "26"]+ .filter((version) => full || version !== "26")+ .map((version) => ({ os: "ubuntu-latest", node: version }));+ compatibility.push({ os: "macos-latest", node: "22.13.0" });+ const pythonMatrix = [+ ...["3.10", "3.12", "3.14"]+ .filter((version) => full || version === "3.12")+ .map((version) => ({+ os: "ubuntu-latest",+ python: version,+ markers: "",+ })),+ {+ os: "macos-latest",+ python: "3.12",+ markers: "cross_platform or native_macos",+ },+ {+ os: "windows-latest",+ python: "3.12",+ markers: "cross_platform or native_windows",+ },+ ];+ return {+ "source-required": String(source),+ "workflow-quality": String(full),+ "container-validate": String(source),+ "compatibility-matrix": JSON.stringify({ include: compatibility }),+ "python-matrix": JSON.stringify({ include: pythonMatrix }),+ "windows-node-matrix": JSON.stringify({+ node: full ? ["22.13.0", "24"] : ["22.13.0"],+ }),+ };+}++if (+ process.argv[1] &&+ import.meta.url === pathToFileURL(process.argv[1]).href+) {+ const event = process.env.EVENT_NAME;+ const baseChanged = process.env.BASE_CHANGED === "true";+ const paths =+ event === "pull_request" && !baseChanged+ ? execFileSync(+ "git",+ ["diff", "--no-renames", "--name-only", "-z", "HEAD^1", "HEAD"],+ { encoding: "utf8" },+ )+ .split("\0")+ .filter(Boolean)+ : [];+ const selected = selectChecks(paths, { event, baseChanged });+ appendFileSync(+ process.env.GITHUB_OUTPUT,+ Object.entries(selected)+ .map(([key, value]) => `${key}=${value}\n`)+ .join(""),+ );+}diff --git a/.github/scripts/test-ci-selection.mjs b/.github/scripts/test-ci-selection.mjsnew file mode 100644index 000000000..ab86b340e--- /dev/null+++ b/.github/scripts/test-ci-selection.mjs@@ -0,0 +1,272 @@+import assert from "node:assert/strict";+import { readFileSync } from "node:fs";+import { test } from "node:test";+import { selectChecks } from "./select-ci-checks.mjs";+import { failedChecks } from "./check-ci-results.mjs";++const select = (paths, options = {}) =>+ selectChecks(paths, { event: "pull_request", ...options });++const regularSource = {+ "source-required": "true",+ "workflow-quality": "false",+ "container-validate": "true",+ "compatibility-matrix": JSON.stringify({+ include: [+ { os: "ubuntu-latest", node: "22.13.0" },+ { os: "ubuntu-latest", node: "24.0.0" },+ { os: "ubuntu-latest", node: "24" },+ { os: "ubuntu-latest", node: "26.0.0" },+ { os: "macos-latest", node: "22.13.0" },+ ],+ }),+ "python-matrix": JSON.stringify({+ include: [+ { os: "ubuntu-latest", python: "3.12", markers: "" },+ {+ os: "macos-latest",+ python: "3.12",+ markers: "cross_platform or native_macos",+ },+ {+ os: "windows-latest",+ python: "3.12",+ markers: "cross_platform or native_windows",+ },+ ],+ }),+ "windows-node-matrix": JSON.stringify({ node: ["22.13.0"] }),+};+const fullQualification = {+ "source-required": "true",+ "workflow-quality": "true",+ "container-validate": "true",+ "compatibility-matrix": JSON.stringify({+ include: [+ { os: "ubuntu-latest", node: "22.13.0" },+ { os: "ubuntu-latest", node: "24.0.0" },+ { os: "ubuntu-latest", node: "24" },+ { os: "ubuntu-latest", node: "26.0.0" },+ { os: "ubuntu-latest", node: "26" },+ { os: "macos-latest", node: "22.13.0" },+ ],+ }),+ "python-matrix": JSON.stringify({+ include: [+ { os: "ubuntu-latest", python: "3.10", markers: "" },+ { os: "ubuntu-latest", python: "3.12", markers: "" },+ { os: "ubuntu-latest", python: "3.14", markers: "" },+ {+ os: "macos-latest",+ python: "3.12",+ markers: "cross_platform or native_macos",+ },+ {+ os: "windows-latest",+ python: "3.12",+ markers: "cross_platform or native_windows",+ },+ ],+ }),+ "windows-node-matrix": JSON.stringify({ node: ["22.13.0", "24"] }),+};++test("only ordinary documentation can skip source qualification", () => {+ assert.deepEqual(select(["README.md", "docs/bedrock.md"]), {+ ...regularSource,+ "source-required": "false",+ "container-validate": "false",+ });+ for (const path of [+ "plugins/codex-security/skills/security-scan/SKILL.md",+ "plugins/codex-security/references/core-scan.md",+ "plugins/codex-security/schemas/finding.schema.json",+ "sdk/typescript/src/api.ts",+ "new-runtime/file",+ "AGENTS.md",+ ]) {+ assert.equal(select(["README.md", path])["source-required"], "true", path);+ }+ assert.equal(select([])["source-required"], "true");+ assert.equal(+ select(["README.md"], { baseChanged: true })["source-required"],+ "true",+ );+});++test("packaged SDK documentation keeps package validation selected", () => {+ const manifest = JSON.parse(+ readFileSync(+ new URL("../../sdk/typescript/package.json", import.meta.url),+ "utf8",+ ),+ );+ for (const file of manifest.files.filter((file) => file.endsWith(".md"))) {+ const path = `sdk/typescript/${file}`;+ const selected = select([path]);+ assert.deepEqual(selected, fullQualification, path);+ }+ // The --no-renames diff reports the old path when a required doc is renamed.+ const renamed = select([+ "sdk/typescript/docs/hosted-scans.md",+ "docs/hosted-scans.md",+ ]);+ assert.equal(renamed["source-required"], "true");+ assert.equal(+ select(["README.md", "sdk/typescript/README.md"])["source-required"],+ "true",+ );+});++test("release recovery documentation keeps its SDK contract selected", () => {+ for (const paths of [["RELEASING.md"], ["README.md", "RELEASING.md"]]) {+ const outputs = select(paths);+ assert.deepEqual(outputs, fullQualification);+ // release-automation.test.ts validates the documented recovery marker.+ const missing = failedChecks({+ "classify-changes": { result: "success", outputs },+ "static-checks": { result: "success" },+ });+ assert.ok(missing.includes("test"));+ }+});++test("release helper changes select their release-progress regression checks", () => {+ assert.equal(+ select(["sdk/typescript/scripts/release-pr.mjs"])["workflow-quality"],+ "true",+ );+});++test("ordinary TypeScript source and tests retain the reduced version matrices", () => {+ for (const path of [+ "sdk/typescript/src/cost.ts",+ "sdk/typescript/tests-ts/skeleton.test.ts",+ "sdk/typescript/tests-ts/support/test-subprocess.ts",+ "plugins/codex-security/mcp-app/src/stdio-transport.ts",+ "plugins/codex-security/mcp-app/tests/test_deep_scan_executor.ts",+ "plugins/codex-security/mcp-app/tests/support/fixture.ts",+ ]) {+ assert.deepEqual(select([path]), regularSource, path);+ assert.deepEqual(select(["README.md", path]), regularSource, path);+ }+});++test("unknown paths and dependency configuration receive full qualification", () => {+ for (const paths of [+ ["new-runtime/file"],+ ["sdk/typescript/src/new-runtime.json"],+ ["sdk/typescript/src/runtime.mjs"],+ ["sdk/typescript/tests-ts/runtime.mts"],+ ["sdk/typescript/src-extra/runtime.ts"],+ ["plugins/codex-security/mcp-app/src/runtime.yaml"],+ ["plugins/codex-security/mcp-app/main.ts"],+ ["other/sdk/typescript/src/runtime.ts"],+ [".npmrc"],+ ["sdk/typescript/.npmrc"],+ ["plugins/codex-security/mcp-app/src/.npmrc"],+ ["pnpm-workspace.yaml"],+ ["sdk/typescript/pnpm-workspace.yaml"],+ ["plugins/codex-security/mcp-app/pnpm-workspace.yaml"],+ ["evals/triage-finding/pnpm-workspace.yaml"],+ ["README.md", "new-runtime/file"],+ ["sdk/typescript/src/cost.ts", "new-runtime/file"],+ // --no-renames reports both sides when source becomes an unknown input.+ ["sdk/typescript/src/runtime.ts", "new-runtime/runtime.ts"],+ ["sdk/typescript/src/runtime.ts", "sdk/typescript/.npmrc"],+ ]) {+ assert.deepEqual(select(paths), fullQualification, paths.join(", "));+ }+});++test("tooling and non-TypeScript product inputs receive full qualification", () => {+ for (const path of [+ "package.json",+ "sdk/typescript/pnpm-lock.yaml",+ "sdk/typescript/bunfig.toml",+ "sdk/typescript/tsconfig.json",+ "plugins/codex-security/native/src/lib.rs",+ "sdk/typescript/scripts/build-plugin.mjs",+ ".github/workflows/node-ci.yml",+ "plugins/codex-security/scripts/workbench_db.py",+ "plugins/codex-security/tests/test_database.py",+ "plugins/codex-security/requirements-test.txt",+ "plugins/codex-security/pyproject.toml",+ "plugins/codex-security/schemas/finding.schema.json",+ "plugins/codex-security/skills/security-scan/SKILL.md",+ ".github/actions/setup-tools/action.yml",+ ]) {+ assert.deepEqual(select([path]), fullQualification, path);+ }+});++test("main, scheduled, manual, empty and retargeted changes receive full qualification", () => {+ for (const options of [+ { event: "push" },+ { event: "schedule" },+ { event: "workflow_dispatch" },+ { baseChanged: true },+ ]) {+ assert.deepEqual(select(["README.md"], options), fullQualification);+ }+ assert.deepEqual(select([]), fullQualification);+});++test("the final gate rejects every missing or unsuccessful selected check", () => {+ const outputs = select([".github/workflows/node-ci.yml"]);+ const needs = Object.fromEntries(+ [+ "static-checks",+ "native",+ "package",+ "test",+ "compatibility",+ "mcp",+ "plugin-host",+ "plugin-source",+ "windows-test",+ "windows-verify",+ "workflow-quality",+ "container-validate",+ ].map((name) => [name, { result: "success" }]),+ );+ needs["classify-changes"] = { result: "success", outputs };+ assert.deepEqual(failedChecks(needs), []);+ for (const name of Object.keys(needs)) {+ for (const result of ["failure", "cancelled", "skipped", undefined]) {+ assert.deepEqual(+ failedChecks({ ...needs, [name]: { ...needs[name], result } }),+ [name],+ );+ }+ }+});++test("documentation requires static checks and explicit selection, without skipped source failures", () => {+ const outputs = select(["README.md"]);+ const needs = {+ "classify-changes": { result: "success", outputs },+ "static-checks": { result: "success" },+ };+ assert.deepEqual(failedChecks(needs), []);+ assert.deepEqual(+ failedChecks({ ...needs, "static-checks": { result: "failure" } }),+ ["static-checks"],+ );+ for (const key of [+ "source-required",+ "workflow-quality",+ "container-validate",+ ]) {+ assert.deepEqual(+ failedChecks({+ ...needs,+ "classify-changes": {+ result: "success",+ outputs: { ...outputs, [key]: undefined },+ },+ }),+ [`${key} classification`],+ );+ }+});diff --git a/.github/workflows/node-ci.yml b/.github/workflows/node-ci.ymlindex 0a8c71c72..114de3c37 100644--- a/.github/workflows/node-ci.yml+++ b/.github/workflows/node-ci.yml@@ -5,6 +5,9 @@ on:branches: [main]pull_request:types: [opened, edited, reopened, synchronize]+ schedule:+ - cron: "17 3 * * *"+ workflow_dispatch:permissions:contents: read@@ -21,83 +24,24 @@ jobs:runs-on: ubuntu-latesttimeout-minutes: 10outputs:+ source-required: ${{ steps.scope.outputs.source-required }}container-validate: ${{ steps.scope.outputs.container-validate }}- test-quality: ${{ steps.scope.outputs.test-quality }}workflow-quality: ${{ steps.scope.outputs.workflow-quality }}-+ compatibility-matrix: ${{ steps.scope.outputs.compatibility-matrix }}+ python-matrix: ${{ steps.scope.outputs.python-matrix }}+ windows-node-matrix: ${{ steps.scope.outputs.windows-node-matrix }}steps:- - name: Checkout pull request for change classification- if: github.event_name == 'pull_request' && github.event.changes.base == null+ - name: Checkout repository for change classificationuses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1with:fetch-depth: 2persist-credentials: false-- - name: Select additional checks+ - name: Select required checksid: scope- shell: bashenv:EVENT_NAME: ${{ github.event_name }}BASE_CHANGED: ${{ github.event.changes.base != null }}- run: |- set -euo pipefail- container_validate=false- if [[ "$EVENT_NAME" == "push" ]]; then- container_validate=true- fi- test_quality=false- workflow_quality=false- if [[ "$EVENT_NAME" == "push" || "$BASE_CHANGED" == "true" ]]; then- workflow_quality=true- fi- if [[ "$EVENT_NAME" == "pull_request" && "$BASE_CHANGED" == "true" ]]; then- container_validate=true- test_quality=true- fi- if [[ "$EVENT_NAME" == "pull_request" &&- "$BASE_CHANGED" != "true" ]]; then- changed_files="$(mktemp)"- trap 'rm -f "$changed_files"' EXIT- git diff --no-renames --name-only -z HEAD^1 HEAD > "$changed_files"-- while IFS= read -r -d '' path; do- case "$path" in- .github/workflows/* | .github/actions/* | .github/actionlint.yaml | .github/zizmor.yml | \- .github/scripts/release-progress.mjs | .github/scripts/test_release_progress.mjs | \- sdk/typescript/scripts/release-pr.mjs | docker/verify-container-compose.sh)- workflow_quality=true- ;;- esac- case "$path" in- .dockerignore | .github/workflows/native-*.yml | \- .github/actions/download-native/* | Dockerfile | \- Dockerfile.dockerignore | compose.yaml | compose.apparmor.yaml | \- compose.runner.yaml | docker/* | \- plugins/codex-security/* | sdk/typescript/* | \- .github/workflows/container-ci.yml | .github/workflows/container-release.yml | \- .github/workflows/container-validate.yml)- container_validate=true- ;;- .github/workflows/node-ci.yml | .github/actions/setup-tools/*)- container_validate=true- ;;- esac- case "$path" in- .github/workflows/node-ci.yml | .github/workflows/test-quality.yml | \- .github/actions/setup-tools/* | sdk/typescript/bunfig.toml | \- sdk/typescript/scripts/compare-test-reports.mts | \- sdk/typescript/scripts/prepare-windows-test-root.ps1 | \- sdk/typescript/scripts/run-ci-tests.mts | \- sdk/typescript/scripts/test-shards.mts | \- sdk/typescript/scripts/test-timings.json)- test_quality=true- ;;- esac- done < "$changed_files"- fi- printf 'container-validate=%s\n' "$container_validate" >> "$GITHUB_OUTPUT"- printf 'test-quality=%s\n' "$test_quality" >> "$GITHUB_OUTPUT"- printf 'workflow-quality=%s\n' "$workflow_quality" >> "$GITHUB_OUTPUT"+ run: node .github/scripts/select-ci-checks.mjsworkflow-quality:needs: classify-changes@@ -134,6 +78,8 @@ jobs:env:GH_TOKEN: ${{ github.token }}run: node --experimental-strip-types sdk/typescript/scripts/check-devcontainer-cooldown.mts+ - name: Test CI selection and result gating+ run: node --test .github/scripts/test-ci-selection.mjs- name: Typecheckrun: pnpm --dir sdk/typescript run types- name: Check formatting@@ -144,6 +90,7 @@ jobs:run: pnpm --dir sdk/typescript run audit:prodnative:+ if: needs.classify-changes.outputs.source-required == 'true'needs: classify-changesuses: ./.github/workflows/native-artifacts.yml@@ -152,14 +99,8 @@ jobs:if: needs.classify-changes.outputs.container-validate == 'true'uses: ./.github/workflows/container-validate.yml- test-quality:- needs: [classify-changes, native]- if: needs.classify-changes.outputs.test-quality == 'true'- uses: ./.github/workflows/test-quality.yml- with:- native-artifacts-ready: true-package:+ if: needs.classify-changes.outputs.source-required == 'true'name: build and check packageneeds: [classify-changes, native]runs-on: ubuntu-latest@@ -193,6 +134,7 @@ jobs:retention-days: 7test:+ if: needs.classify-changes.outputs.source-required == 'true'name: tests / ${{ matrix.os }} / shard-${{ matrix.shard }}needs: [classify-changes, package]runs-on: ${{ matrix.os }}@@ -248,18 +190,14 @@ jobs:retention-days: 14compatibility:+ if: needs.classify-changes.outputs.source-required == 'true'name: installed package / ${{ matrix.os }} / node-${{ matrix.node }}needs: [classify-changes, package]runs-on: ${{ matrix.os }}timeout-minutes: 20strategy:fail-fast: false- matrix:- os: [ubuntu-latest]- node: ["22.13.0", "24.0.0", "24", "26.0.0", "26"]- include:- - os: macos-latest- node: "22.13.0"+ matrix: ${{ fromJSON(needs.classify-changes.outputs.compatibility-matrix) }}steps:- *checkout-repository- &set-up-node-js@@ -298,6 +236,7 @@ jobs:uses: ./.github/actions/check-action-candidatemcp:+ if: needs.classify-changes.outputs.source-required == 'true'name: MCP app testsneeds: [classify-changes, package]runs-on: ubuntu-latest@@ -332,6 +271,7 @@ jobs:retention-days: 14plugin-host:+ if: needs.classify-changes.outputs.source-required == 'true'name: standalone plugin / ${{ matrix.os }}needs: classify-changesruns-on: ${{ matrix.os }}@@ -355,29 +295,14 @@ jobs:run: node --experimental-strip-types --test plugins/codex-security/mcp-app/scripts/test_host_build.mtsplugin-source:+ if: needs.classify-changes.outputs.source-required == 'true'name: plugin source contracts / ${{ matrix.os }} / python-${{ matrix.python }}needs: classify-changesruns-on: ${{ matrix.os }}timeout-minutes: 30strategy:fail-fast: false- matrix:- include:- - os: ubuntu-latest- python: "3.10"- markers: ""- - os: ubuntu-latest- python: "3.12"- markers: ""- - os: ubuntu-latest- python: "3.14"- markers: ""- - os: macos-latest- python: "3.12"- markers: cross_platform or native_macos- - os: windows-latest- python: "3.12"- markers: cross_platform or native_windows+ matrix: ${{ fromJSON(needs.classify-changes.outputs.python-matrix) }}steps:- *checkout-repository- name: Set up Node.js@@ -474,14 +399,13 @@ jobs:if: matrix.os == 'ubuntu-latest' && matrix.python == '3.12'run: node --experimental-strip-types --test evals/workflow-routing/test_*.mts- required-test:- # Skipped metadata jobs must not satisfy required source-check contexts.- name: ${{ github.event_name == 'pull_request' && github.event.action == 'edited' && github.event.changes.base == null && 'metadata / ' || '' }}${{ matrix.os }} / node-22+ ci:+ name: ${{ github.event_name == 'pull_request' && github.event.action == 'edited' && github.event.changes.base == null && 'metadata / ' || '' }}cineeds:[classify-changes,- workflow-quality,static-checks,+ native,package,test,compatibility,@@ -489,25 +413,35 @@ jobs:plugin-host,plugin-source,container-validate,+ workflow-quality,+ windows-test,+ windows-verify,]if: &source-aggregate always() && (github.event_name != 'pull_request' || github.event.action != 'edited' || github.event.changes.base != null)runs-on: ubuntu-latest+ steps:+ - *checkout-repository+ - name: Require selected checks+ env:+ CI_RESULTS: ${{ toJSON(needs) }}+ run: node .github/scripts/check-ci-results.mjs++ # Retain required names until the repository ruleset has migrated to `ci`.+ required-test:+ name: ${{ github.event_name == 'pull_request' && github.event.action == 'edited' && github.event.changes.base == null && 'metadata / ' || '' }}${{ matrix.os }} / node-22+ needs: [classify-changes, ci]+ if: *source-aggregate+ runs-on: ubuntu-lateststrategy:- fail-fast: falsematrix:os: [ubuntu-latest, macos-latest]steps:- - name: Require selected workflow checks- if: needs.classify-changes.outputs.workflow-quality == 'true' && needs.workflow-quality.result != 'success'- run: exit 1- - name: Require every Unix coverage job- if: needs.classify-changes.result != 'success' || (needs.static-checks.result != 'success' || needs.package.result != 'success' || needs.test.result != 'success' || needs.compatibility.result != 'success' || needs.mcp.result != 'success' || needs.plugin-host.result != 'success' || needs.plugin-source.result != 'success')- run: exit 1- - name: Require selected container coverage- if: needs.classify-changes.outputs.container-validate == 'true' && needs.container-validate.result != 'success'+ - name: Require CI gate+ if: needs.ci.result != 'success'run: exit 1windows-test:+ if: needs.classify-changes.outputs.source-required == 'true'name: windows-latest / node-22 / tests-${{ matrix.shard }}needs: [classify-changes, package]runs-on: windows-latest@@ -524,14 +458,7 @@ jobs:with:python-version: "3.12"- *download-native- - name: Set up Node.js- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0- with:- node-version: "22.13.0"- - name: Set up pnpm- uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0- with:- package_json_file: package.json+ - *set-up-typescript-tools- *set-up-bun- *install-dependencies- *download-package-for-this-commit@@ -571,14 +498,14 @@ jobs:run: bun test --timeout 360000 ./tests-ts/windows-machine-policy.test.tswindows-verify:+ if: needs.classify-changes.outputs.source-required == 'true'name: windows-latest / node-${{ matrix.node == '22.13.0' && '22' || matrix.node }} / verifyneeds: [classify-changes, package]runs-on: windows-latesttimeout-minutes: 20- strategy: &windows-node-strategy+ strategy:fail-fast: false- matrix:- node: ["22.13.0", "24"]+ matrix: ${{ fromJSON(needs.classify-changes.outputs.windows-node-matrix) }}steps:- *checkout-repository- *set-up-python@@ -595,17 +522,11 @@ jobs:name: ${{ github.event_name == 'pull_request' && github.event.action == 'edited' && github.event.changes.base == null && 'metadata / ' || '' }}windows-latest / node-${{ matrix.node == '22.13.0' && '22' || matrix.node }}runs-on: ubuntu-latestif: *source-aggregate- needs:- [- classify-changes,- static-checks,- plugin-host,- plugin-source,- windows-test,- windows-verify,- ]- strategy: *windows-node-strategy+ needs: [classify-changes, ci]+ strategy:+ matrix:+ node: ["22.13.0", "24"]steps:- - name: Require every Windows coverage job- if: needs.classify-changes.result != 'success' || (needs.static-checks.result != 'success' || needs.plugin-host.result != 'success' || needs.plugin-source.result != 'success' || needs.windows-test.result != 'success' || needs.windows-verify.result != 'success')+ - name: Require CI gate+ if: needs.ci.result != 'success'run: exit 1diff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex 3d2ba1de9..a12e34be3 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -32,6 +32,9 @@ Model-based evaluations live in [`evals/`](evals/README.md), outside the pluginsource. Deterministic triage checks and the MCP reducer IPC regression remainpart of normal CI.+See the [CI guide](docs/ci.md) for check selection, platform/version coverage,+required status checks, and test-runner qualification.+## Where to make a changeStart with the owner of the behavior, then follow its callers when the changediff --git a/docs/ci.md b/docs/ci.mdnew file mode 100644index 000000000..dc98c7ab2--- /dev/null+++ b/docs/ci.md@@ -0,0 +1,78 @@+# Continuous integration++The `node-ci` workflow selects checks from the complete pull request diff. An+ordinary documentation-only change runs static checks and the final `ci` gate.+Plugin skills, references, schemas, examples, and unrecognized paths receive+full qualification: plugin Markdown is part of the product. SDK README and+documentation changes also receive full qualification because those files are+required package contents; deleting or renaming them must pass archive checks.+`RELEASING.md` also receives full qualification because SDK tests validate its+canonical release recovery example.++Source changes run the complete SDK suite on Linux, macOS, and Windows, plus+MCP, standalone-plugin, native-runtime, and installed-package checks. Tests+are discovered from the source tree, including new files without timing data.+Platform-specific filesystem, credential, process, cancellation, and resumed+worker cases remain enabled.++Pull requests limited to `.ts` files under `sdk/typescript/src/`,+`sdk/typescript/tests-ts/`, `plugins/codex-security/mcp-app/src/`, and+`plugins/codex-security/mcp-app/tests/`, optionally mixed with ordinary docs,+use reduced version matrices. They test the minimum Node 22, 24, and 26 versions,+current Node 24 for the Action adapter, macOS installation, and Windows Node 22+installation. Python runs the full suite on 3.12 and the native subsets on macOS+and Windows. All source changes still select container validation.++Every other path selects full qualification, including workflow checks,+containers, current Node 26, Windows Node 24 installation, and Python 3.10 and+3.14 Linux suites. This includes dependency configuration such as `.npmrc` and+`pnpm-workspace.yaml`, build tooling, Python and native code, and unknown paths+even when mixed with ordinary source or documentation.++Every push to `main`, nightly run, manual `node-ci` dispatch, and pull-request+retarget runs the complete version matrices. Release automation still requires+successful CI for the exact main commit before publication. Title and body edits+neither cancel source runs nor satisfy their required check names.++## Required gate++The `ci` job checks every selected required job. A failed, cancelled, missing,+or unexpectedly skipped selected job fails the gate. An explicitly unselected+job can be skipped. Static checks are always required. Broad test-runner+experiments run through the separate scheduled/manual `test-quality` workflow;+they are not merge gates.++The existing OS-named check contexts temporarily forward the `ci` result so+repository branch rules continue to work during migration. To finish migration:++1. Merge the workflow change and verify that `ci` is reported for source and+ documentation pull requests, including a failing selected-check example.+2. Change the repository's required status checks to `ci` and `Validate PR Title`,+ preserving their GitHub Actions integration and all unrelated protection rules.+3. Remove the compatibility jobs `required-test` and `windows` in a follow-up.++Do not remove the old contexts before changing the rules. The workflow change+itself does not change repository protection settings.++## Diagnostics and local checks++The workflow-selection and gate tests run without installing dependencies:++```bash+node --test .github/scripts/test-ci-selection.mjs+```++The [SDK testing guide](../sdk/typescript/TESTING.md) describes local behavioral+tests. For CI edits, also run actionlint and the repository's configured zizmor+checks. Test-runner changes should compare the same test inventory, outcomes,+and covered lines with the same Bun version, seed, and coverage settings before+promotion. A different runtime or disabled coverage is a different experiment.++Linux coverage artifacts are review evidence, not a percentage-based merge+gate. Mutation diagnostics also measure results without enforcing a minimum+score. Ordinary report upload failures do not replace the test result.++When measuring CI changes, separate time to required-green from summed job+execution time, prerequisite waits, runner scheduling, approval waits, and+manual retry delays. Compare matching revisions and test configurations, and+record failures as well as successful runs.diff --git a/sdk/typescript/TESTING.md b/sdk/typescript/TESTING.mdindex b027151e3..0a50f9c03 100644--- a/sdk/typescript/TESTING.md+++ b/sdk/typescript/TESTING.md@@ -131,23 +131,29 @@ default to 100 cases; filesystem contract properties default to 20.## GitHub Actions-`node-ci` retains the required `ubuntu-latest / node-22`,-`macos-latest / node-22`, and `windows-latest / node-22` checks. It builds and-inspects one package archive, then passes that archive to jobs in the same-workflow run, using the commit SHA in the artifact name. Every supported Node-runtime still installs and inspects the package, including a strict NodeNext-TypeScript consumer, the actual CLI, credential locking, and-a nested Codex worker. Native plugin-build tests remain in the shared Bun suite.+`node-ci` reports one `ci` gate for all selected required checks. The existing+`ubuntu-latest / node-22`, `macos-latest / node-22`, and+`windows-latest / node-22` check names forward that result while repository+branch rules migrate. The [CI guide](../../docs/ci.md) describes documentation-only+routing, platform/version selection, full scheduled qualification, and the gate+migration.++For source qualification, CI builds and inspects one package archive, then passes+that archive to jobs in the same workflow run, using the commit SHA in the+artifact name. Selected Node runtimes install and inspect the package, including+a strict NodeNext TypeScript consumer, the actual CLI, credential locking, and a+nested Codex worker. Native plugin-build tests remain in the shared Bun suite.Typechecking and formatting run once in an independent required job, so packageconsumers do not wait for those checks. Package compilation and archivevalidation still finish before the test jobs start.-The full Bun suite runs once per OS under Node 22: six file shards on Linux-and macOS, and fourteen on Windows. GitHub runs the shards as separate jobs;-each job uses Bun's default serial runner. The other Node versions run the-installed-package checks instead of repeating the same Bun suite. MCP and-Python tests run in separate required jobs. Python uses four isolated-pytest-xdist workers with work stealing; worker crashes fail the run without automatic restarts.+Source qualification runs the full Bun suite once per OS under Node 22: six+file shards on Linux and macOS, and fourteen on Windows. GitHub runs the shards+as separate jobs; each job uses Bun's default serial runner. The other selected+Node versions run the installed-package checks instead of repeating the same+Bun suite. MCP and Python tests run in separate required jobs. Python uses four+isolated pytest-xdist workers with work stealing; worker crashes fail the run+without automatic restarts.`scripts/run-ci-tests.mts` discovers every shared test file and balances wholefiles using the platform's recorded durations in `scripts/test-timings.json`.@@ -175,20 +181,20 @@ Coverage is diagnostic and split across shards, not a combined percentage.Failed tests and missing package artifacts block CI; failed diagnostic uploadsdo not. Use `python -m pytest -n 0` to reproduce Python failures serially.-The separate `test-quality` workflow runs weekly, can be dispatched manually,-and runs on pull requests that change its workflow, setup tools, Bun configuration,-shard runner, timing metadata, report comparator, or Windows test-root helper.-It compares the previous layout (three shards on Linux/macOS, seven on Windows)-with the expanded production layout (six on Linux/macOS, fourteen on Windows),-for 39 sharded runner jobs. Both layouts use the same serial Bun runner and-platform timing snapshot; the comparison combines all shards for each OS before-checking inventory and outcomes. Local full-suite runs still cover unsharded-cross-file ordering. More jobs add setup overhead, so compare required-green+The separate `test-quality` workflow runs weekly and can be dispatched manually.+Ordinary source pull requests run focused contracts for the shard runner, timing+metadata, report comparator, and Windows test-root helper in the required SDK suite.+The diagnostic workflow compares the previous layout (three shards on Linux/macOS,+seven on Windows) with the expanded production layout (six on Linux/macOS,+fourteen on Windows), for 39 sharded runner jobs. Both layouts use the same serial+Bun runner and platform timing snapshot; the comparison combines all shards for+each OS before checking inventory and outcomes. Local full-suite runs still cover+unsharded cross-file ordering. More jobs add setup overhead, so compare required-greenlatency and summed runner time alongside shard test timings.-Every layout uses the same seed for property cases and test ordering: pull requests-replay seed 1; scheduled and manual runs use the workflow run number. Reports have-unique OS/mode/shard names. The workflow requires every expected shard report+Scheduled and manual diagnostics use the workflow run number as the same seed for+property cases and test ordering in every layout. Reports have unique OS/layout/shard+names. The workflow requires every expected shard reportbefore accepting comparisons, then compares complete shard groups by testidentity, outcome, assertion count, and occurrence count, retaining legitimaterepeated names from parameterized tests while detecting missing or extra instances. It records every@@ -203,8 +209,10 @@ before promotion.Both layouts use the same property seed and coverage settings. Required CI usesthe default property seed and collects Linux coverage; diagnostics use the seedabove and the same Linux LCOV instrumentation. Artifacts include JUnit and-coverage in separate OS/layout/shard paths. Compare inventories across required-CI and diagnostics, but measure scheduling changes between diagnostic layouts.+coverage in separate OS/layout/shard paths. The automated comparison checks JUnit+inventories, outcomes, and assertion counts; LCOV remains available for covered-line+comparison during qualification. Compare inventories across required CI and+diagnostics, but measure scheduling changes between diagnostic layouts.Both workflows install ripgrep on Linux so the inventory-path test executes.Keep the machine-policy test serial. Do not replace the full required suitediff --git a/sdk/typescript/tests-ts/container-ci-workflow.test.ts b/sdk/typescript/tests-ts/container-ci-workflow.test.tsindex 4fe3d3d3f..61251efcf 100644--- a/sdk/typescript/tests-ts/container-ci-workflow.test.ts+++ b/sdk/typescript/tests-ts/container-ci-workflow.test.ts@@ -1,9 +1,7 @@import { spawnSync } from "node:child_process";-import { mkdtempSync, readFileSync, rmSync } from "node:fs";-import { tmpdir } from "node:os";-import { join } from "node:path";+import { readFileSync } from "node:fs";+import { fileURLToPath } from "node:url";import { expect, test } from "bun:test";-import { bashCommand } from "./support/shell.js";type Step = { name?: string; uses?: string; run?: string; if?: string };type Job = {@@ -24,7 +22,14 @@ function workflow(name: string) {}const ci = workflow("node-ci");-const bash = bashCommand();+const { selectChecks } = (await import(+ new URL("../../../.github/scripts/select-ci-checks.mjs", import.meta.url).href+)) as {+ selectChecks(+ paths: string[],+ options: { event: string; baseChanged: boolean },+ ): Record<string, string>;+};test("shares one native build and container matrix in automatic CI", () => {const container = workflow("container-ci");@@ -104,62 +109,52 @@ test.each([] as const)("selects container validation for %s / retarget=%p / %s",(eventName, baseChanged, path, selected) => {- const directory = mkdtempSync(join(tmpdir(), "container-ci-scope-"));- const output = join(directory, "outputs");- const script = ci.jobs["classify-changes"]!.steps!.find(- (step) => step.name === "Select additional checks",- )!.run!;- try {- const result = spawnSync(- bash,- ["-c", `git() { printf '%s\\0' "$CHANGED_PATH"; }\n${script}`],- {- env: {- ...process.env,- EVENT_NAME: eventName,- BASE_CHANGED: String(baseChanged),- CHANGED_PATH: path,- GITHUB_OUTPUT: output,- },- },- );- expect(result.status).toBe(0);- const outputs = Object.fromEntries(- readFileSync(output, "utf8")- .trim()- .split("\n")- .map((line) => line.split("=")),- );- expect(outputs["container-validate"]).toBe(String(selected));- if (path === ".github/actions/setup-tools/action.yml") {- expect(outputs["test-quality"]).toBe("true");- }- } finally {- rmSync(directory, { recursive: true, force: true });- }+ const outputs = selectChecks([path], { event: eventName, baseChanged });+ expect(outputs["container-validate"]).toBe(String(selected));},);-test("required CI rejects failed, cancelled, or skipped selected container checks", () => {- const gate = ci.jobs["required-test"]!;+test("the final CI gate executes selected container failures and permits unselected checks", () => {+ const gate = ci.jobs["ci"]!;expect(gate.needs).toContain("container-validate");expect(gate.if).toContain("always()");const step = gate.steps!.find(- (step) => step.name === "Require selected container coverage",+ (step) => step.name === "Require selected checks",)!;- expect(step.run).toBe("exit 1");- for (const selected of ["true", "false"]) {+ const [command, script] = step.run!.split(" ");+ expect(command).toBe("node");+ for (const selected of [true, false]) {+ const outputs = selectChecks([selected ? "Dockerfile" : "README.md"], {+ event: "pull_request",+ baseChanged: false,+ });+ const needs = Object.fromEntries(+ (gate.needs as string[]).map((name) => [name, { result: "success" }]),+ );+ const classified = {+ ...needs,+ "classify-changes": { result: "success", outputs },+ };for (const result of ["success", "failure", "cancelled", "skipped"]) {- const condition = step- .if!.replaceAll(- "needs.classify-changes.outputs.container-validate",- `'${selected}'`,- )- .replaceAll("needs.container-validate.result", `'${result}'`);- const evaluation = spawnSync(bash, ["-c", `[[ ${condition} ]]`]);- expect(evaluation.status, `${selected}/${result}`).toBe(- selected === "true" && result !== "success" ? 0 : 1,+ const execution = spawnSync(+ command!,+ [fileURLToPath(new URL(`../../../${script}`, import.meta.url))],+ {+ encoding: "utf8",+ env: {+ ...process.env,+ CI_RESULTS: JSON.stringify({+ ...classified,+ "container-validate": { result },+ }),+ },+ },+ );+ expect(execution.status, execution.stderr).toBe(+ selected && result !== "success" ? 1 : 0,);+ if (selected && result !== "success")+ expect(execution.stderr).toContain("container-validate");}}});diff --git a/sdk/typescript/tests-ts/devcontainer-cooldown.test.ts b/sdk/typescript/tests-ts/devcontainer-cooldown.test.tsindex e7a9a50b4..45a64ff2f 100644--- a/sdk/typescript/tests-ts/devcontainer-cooldown.test.ts+++ b/sdk/typescript/tests-ts/devcontainer-cooldown.test.ts@@ -363,14 +363,21 @@ test("runs the guard with package metadata access inside the existing required cexpect(job.steps[index]!.env).toEqual({ GH_TOKEN: "${{ github.token }}" });expect(job.permissions).toEqual({ contents: "read", packages: "read" });expect(job.steps[0]!.with?.["fetch-depth"]).toBe(2);+ const gate = workflow.jobs["ci"]!;+ expect(gate.needs).toContain("static-checks");+ expect(gate.steps).toContainEqual(+ expect.objectContaining({+ run: "node .github/scripts/check-ci-results.mjs",+ env: { CI_RESULTS: "${{ toJSON(needs) }}" },+ }),+ );for (const name of ["required-test", "windows"]) {const required = workflow.jobs[name]!;- expect(required.needs).toContain("static-checks");+ expect(required.needs).toContain("ci");expect(required.steps.some((step) =>- step.run === "exit 1" &&- step.if?.includes("needs.static-checks.result != 'success'"),+ step.run === "exit 1" && step.if === "needs.ci.result != 'success'",),).toBe(true);}diff --git a/sdk/typescript/tests-ts/release-automation.test.ts b/sdk/typescript/tests-ts/release-automation.test.tsindex 831261bdc..33b475672 100644--- a/sdk/typescript/tests-ts/release-automation.test.ts+++ b/sdk/typescript/tests-ts/release-automation.test.ts@@ -3815,7 +3815,7 @@ describe("GitHub release workflow safeguards", () => {expect(nodeCiWorkflow).toContain("needs: classify-changes");});- test("preserves source validation dependencies and fails closed on missing coverage", async () => {+ test("preserves source validation dependencies and forwards the centralized gate result", async () => {const workflow = Bun.YAML.parse(nodeCiWorkflow) as {concurrency: {group: string;@@ -3828,11 +3828,12 @@ describe("GitHub release workflow safeguards", () => {if?: string;needs?: string | string[];"timeout-minutes"?: number;- strategy?: { matrix: Record<string, string[]> };steps: Array<{if?: string;name?: string;run?: string;+ env?: Record<string, string>;+ with?: Record<string, unknown>;}>;}>;@@ -3844,19 +3845,21 @@ describe("GitHub release workflow safeguards", () => {expect(workflow.concurrency["cancel-in-progress"]).toBe("${{ github.event_name == 'pull_request' }}",);- expect(workflow.jobs["classify-changes"]?.["timeout-minutes"]).toBe(10);- expect(workflow.jobs["classify-changes"]?.if).toContain(- "github.event.changes.base != null",+ const classifier = workflow.jobs["classify-changes"]!;+ expect(classifier["timeout-minutes"]).toBe(10);+ expect(classifier.if).toContain("github.event.changes.base != null");+ const checkout = classifier.steps.find(+ ({ name }) => name === "Checkout repository for change classification",);- expect(- workflow.jobs["classify-changes"]?.steps.find(- ({ name }) =>- name === "Checkout pull request for change classification",- )?.if,- ).toContain("github.event.changes.base == null");+ expect(checkout?.with).toMatchObject({+ "fetch-depth": 2,+ "persist-credentials": false,+ });+ expect(checkout).not.toHaveProperty("if");+ expect(workflow.jobs["static-checks"]?.if).toBeUndefined();for (const job of [- "static-checks",+ "native","package","test","compatibility",@@ -3866,96 +3869,55 @@ describe("GitHub release workflow safeguards", () => {"windows-test","windows-verify",]) {- expect(workflow.jobs[job]?.if).toBeUndefined();+ expect(workflow.jobs[job]?.if).toBe(+ "needs.classify-changes.outputs.source-required == 'true'",+ );+ expect(workflow.jobs["ci"]?.needs).toContain(job);}for (const [name, job] of Object.entries(workflow.jobs)) {- if (["classify-changes", "required-test", "windows"].includes(name)) {+ if (+ ["classify-changes", "ci", "required-test", "windows"].includes(name)+ ) {continue;}expect([job.needs].flat(), name).toContain("classify-changes");expect(job.if ?? "", name).not.toMatch(/\b(always|failure|cancelled)\(/u);}- for (const job of ["required-test", "windows"]) {+ for (const job of ["ci", "required-test", "windows"]) {expect(workflow.jobs[job]?.if).toContain("always()");}- const coverageGate = (job: string) =>- workflow.jobs[job]?.steps.find(- ({ name }) =>- name ===- `Require every ${job === "windows" ? "Windows" : "Unix"} coverage job`,- );- const conditionCases: Array<{- condition: string;- values: Record<string, string>;- expected: boolean;- message: string;- }> = [];- for (const [validation, upstream, gateFailure] of [- ["success", "success", false],- ["success", "skipped", true],- ["failure", "skipped", true],- ] as const) {- const values = {- "needs.static-checks.result": upstream,- "needs.plugin-host.result": upstream,- "needs.plugin-source.result": upstream,- "needs.package.result": upstream,- "needs.compatibility.result": upstream,- "needs.mcp.result": upstream,- "needs.test.result": upstream,- "needs.classify-changes.result": validation,- "needs.windows-test.result": upstream,- "needs.windows-verify.result": upstream,- };- for (const job of ["required-test", "windows"]) {- conditionCases.push({- condition: coverageGate(job)?.if ?? "",- values,- expected: gateFailure,- message: `${job}: ${validation}/${upstream}`,- });- }+ for (const job of [+ "classify-changes",+ "static-checks",+ "workflow-quality",+ "container-validate",+ ]) {+ expect(workflow.jobs["ci"]?.needs).toContain(job);}+ expect(+ workflow.jobs["ci"]?.steps.find(+ ({ name }) => name === "Require selected checks",+ ),+ ).toMatchObject({+ run: "node .github/scripts/check-ci-results.mjs",+ env: { CI_RESULTS: "${{ toJSON(needs) }}" },+ });- for (const [gate, dependencies] of Object.entries({- "required-test": [- "static-checks",- "package",- "test",- "compatibility",- "mcp",- "plugin-host",- "plugin-source",- ],- windows: [- "static-checks",- "plugin-host",- "plugin-source",- "windows-test",- "windows-verify",- ],- })) {- for (const dependency of dependencies) {- for (const result of ["failure", "cancelled", "skipped"]) {- conditionCases.push({- condition: coverageGate(gate)?.if ?? "",- values: {- "needs.classify-changes.result": "success",- ...Object.fromEntries(- dependencies.map((job) => [- `needs.${job}.result`,- job === dependency ? result : "success",- ]),- ),- },- expected: true,- message: `${gate}: ${dependency}/${result}`,- });- }+ const conditionCases = [];+ for (const name of ["required-test", "windows"]) {+ const job = workflow.jobs[name]!;+ expect(job.needs).toEqual(["classify-changes", "ci"]);+ const gate = job.steps.find(({ name }) => name === "Require CI gate");+ expect(gate?.run).toBe("exit 1");+ for (const result of ["success", "failure", "cancelled", "skipped"]) {+ conditionCases.push({+ condition: gate?.if ?? "",+ values: { "needs.ci.result": result },+ expected: result !== "success",+ message: `${name}: ${result}`,+ });}- expect(coverageGate(gate)?.run).toBe("exit 1");}-const conditions = await evaluateWorkflowConditions(conditionCases);for (const [index, item] of conditionCases.entries()) {expect(conditions[index], item.message).toBe(item.expected);diff --git a/sdk/typescript/tests-ts/skeleton.test.ts b/sdk/typescript/tests-ts/skeleton.test.tsindex 94ae5689c..df914c043 100644--- a/sdk/typescript/tests-ts/skeleton.test.ts+++ b/sdk/typescript/tests-ts/skeleton.test.ts@@ -14,6 +14,18 @@ import { main } from "../src/cli.js";import { capture } from "./cli-fixtures.js";import { bashCommand, runCommand } from "./support/shell.js";+const { selectChecks } = (await import(+ new URL("../../../.github/scripts/select-ci-checks.mjs", import.meta.url).href+)) as {+ selectChecks(+ paths: string[],+ options: { event: string; baseChanged?: boolean },+ ): Record<+ "compatibility-matrix" | "windows-node-matrix" | "python-matrix",+ string+ >;+};+interface WorkflowStep {name?: string;id?: string;@@ -29,7 +41,7 @@ interface WorkflowJob {name?: string;needs?: string | string[];env?: Record<string, unknown>;- strategy?: { matrix: Record<string, unknown> };+ strategy?: { matrix: Record<string, unknown> | string };steps?: WorkflowStep[];}@@ -137,19 +149,28 @@ describe("TypeScript package skeleton", () => {test("runs Bun once per OS and checks every supported Node runtime with the installed package", async () => {const { jobs } = await workflow("node-ci.yml");+ const selected = selectChecks([], { event: "push" });expect(jobs["test"]?.strategy?.matrix).toEqual({os: ["ubuntu-latest", "macos-latest"],shard: [1, 2, 3, 4, 5, 6],});- expect(jobs["compatibility"]?.strategy?.matrix).toEqual({- os: ["ubuntu-latest"],- node: ["22.13.0", "24.0.0", "24", "26.0.0", "26"],- include: [{ os: "macos-latest", node: "22.13.0" }],- });+ expect(jobs["compatibility"]?.strategy?.matrix).toBe(+ "${{ fromJSON(needs.classify-changes.outputs.compatibility-matrix) }}",+ );+ expect(JSON.parse(selected["compatibility-matrix"]).include).toEqual([+ ...["22.13.0", "24.0.0", "24", "26.0.0", "26"].map((node) => ({+ os: "ubuntu-latest",+ node,+ })),+ { os: "macos-latest", node: "22.13.0" },+ ]);expect(jobs["windows-test"]?.strategy?.matrix).toEqual({shard: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],});- expect(jobs["windows-verify"]?.strategy?.matrix["node"]).toEqual([+ expect(jobs["windows-verify"]?.strategy?.matrix).toBe(+ "${{ fromJSON(needs.classify-changes.outputs.windows-node-matrix) }}",+ );+ expect(JSON.parse(selected["windows-node-matrix"]).node).toEqual(["22.13.0","24",]);@@ -178,10 +199,10 @@ describe("TypeScript package skeleton", () => {verificationSteps[pythonSetup]?.with?.["update-environment"],);expect(jobs["required-test"]?.name).toEndWith("${{ matrix.os }} / node-22");- expect(jobs["required-test"]?.needs).toEqual([+ expect(jobs["ci"]?.needs).toEqual(["classify-changes",- "workflow-quality","static-checks",+ "native","package","test","compatibility",@@ -189,15 +210,13 @@ describe("TypeScript package skeleton", () => {"plugin-host","plugin-source","container-validate",- ]);- expect(jobs["windows"]?.needs).toEqual([- "classify-changes",- "static-checks",- "plugin-host",- "plugin-source",+ "workflow-quality","windows-test","windows-verify",]);+ for (const name of ["required-test", "windows"]) {+ expect(jobs[name]?.needs).toEqual(["classify-changes", "ci"]);+ }for (const name of ["compatibility", "windows-verify"]) {expect(jobs[name]?.steps).toContainEqual(expect.objectContaining({@@ -312,7 +331,11 @@ describe("TypeScript package skeleton", () => {test("covers the Python runtime floor and native platform paths", async () => {const { jobs } = await workflow("node-ci.yml");const job = jobs["plugin-source"]!;- expect(job.strategy?.matrix["include"]).toEqual([+ const selected = selectChecks([], { event: "push" });+ expect(job.strategy?.matrix).toBe(+ "${{ fromJSON(needs.classify-changes.outputs.python-matrix) }}",+ );+ expect(JSON.parse(selected["python-matrix"]).include).toEqual([...["3.10", "3.12", "3.14"].map((python) => ({os: "ubuntu-latest",python,@@ -353,8 +376,9 @@ describe("TypeScript package skeleton", () => {"matrix.os == 'ubuntu-latest' && matrix.python == '3.12'",);}- expect(jobs["required-test"]?.needs).toContain("plugin-source");- expect(jobs["windows"]?.needs).toContain("plugin-source");+ expect(jobs["ci"]?.needs).toContain("plugin-source");+ expect(jobs["required-test"]?.needs).toContain("ci");+ expect(jobs["windows"]?.needs).toContain("ci");});test("checks one archive and restores its plugin before every test shard", async () => {@@ -490,12 +514,7 @@ describe("TypeScript package skeleton", () => {"workflow_call","workflow_dispatch",]);- expect(ci.jobs["test-quality"]).toMatchObject({- needs: ["classify-changes", "native"],- if: "needs.classify-changes.outputs.test-quality == 'true'",- uses: "./.github/workflows/test-quality.yml",- with: { "native-artifacts-ready": true },- });+ expect(ci.jobs).not.toHaveProperty("test-quality");expect(quality.env?.["CODEX_SECURITY_ALLOW_MACHINE_POLICY_TEST"]).toBe("false",);@@ -510,11 +529,16 @@ describe("TypeScript package skeleton", () => {"${{ github.event_name == 'pull_request' && 1 || github.run_number }}";expect(quality.env).not.toHaveProperty("CODEX_SECURITY_PROPERTY_SEED");expect(runner.env?.["CODEX_SECURITY_PROPERTY_SEED"]).toBe(seed);- const unixMatrix = ci.jobs["test"]!.strategy!.matrix;+ const unixMatrix = ci.jobs["test"]!.strategy!.matrix as Record<+ string,+ unknown+ >;const unixShards = unixMatrix["shard"] as number[];- const windowsShards = ci.jobs["windows-test"]!.strategy!.matrix[- "shard"- ] as number[];+ const windowsMatrix = ci.jobs["windows-test"]!.strategy!.matrix as Record<+ string,+ unknown+ >;+ const windowsShards = windowsMatrix["shard"] as number[];expect(runner.strategy?.matrix).toEqual({target: ["baseline", "expanded"].flatMap((mode) => [...(unixMatrix["os"] as string[]).flatMap((os) => {diff --git a/sdk/typescript/tests-ts/workflow-quality.test.ts b/sdk/typescript/tests-ts/workflow-quality.test.tsindex 16cc32062..418a9895e 100644--- a/sdk/typescript/tests-ts/workflow-quality.test.ts+++ b/sdk/typescript/tests-ts/workflow-quality.test.ts@@ -1,7 +1,8 @@-import { spawnSync } from "node:child_process";-import { mkdtemp, readFile, rm } from "node:fs/promises";+import { execFileSync, spawnSync } from "node:child_process";+import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";import { tmpdir } from "node:os";import { join } from "node:path";+import { fileURLToPath } from "node:url";import { expect, test } from "bun:test";const ci = Bun.YAML.parse(@@ -59,6 +60,7 @@ function eventContext(}const aggregates = [+ ["ci", {}, "ci"] as const,...ci.jobs["required-test"]!.strategy!.matrix["os"]!.map((os) => ["required-test", { os }, `${os} / node-22`] as const,),@@ -108,6 +110,7 @@ test.each([test("all source jobs depend on classification and titles cannot block source checks", () => {expect(aggregates.map(([, , name]) => name)).toEqual([+ "ci","ubuntu-latest / node-22","macos-latest / node-22","windows-latest / node-22",@@ -192,121 +195,74 @@ bashTest(},);-bashTest(- "selects workflow and runner checks for relevant changes and main pushes",- async () => {- const scope = ci.jobs["classify-changes"]!.steps.find(- (step) => step.name === "Select additional checks",- )!;- const directory = await mkdtemp(join(tmpdir(), "workflow-quality-"));- try {- for (const [- event,- baseChanged,- paths,- expected,- runnerExpected = "false",- ] of [- ["push", false, [], "true"],- ["pull_request", true, [], "true", "true"],- ["pull_request", false, [".github/workflows/node-release.yml"], "true"],- [- "pull_request",- false,- [".github/actions/download-native/action.yml"],- "true",- ],- ["pull_request", false, [".github/actionlint.yaml"], "true"],- ["pull_request", false, [".github/zizmor.yml"], "true"],- [- "pull_request",- false,- [".github/scripts/release-progress.mjs"],- "true",- ],- [- "pull_request",- false,- [".github/scripts/test_release_progress.mjs"],- "true",- ],- [- "pull_request",- false,- ["sdk/typescript/scripts/release-pr.mjs"],- "true",- ],- ["pull_request", false, ["docker/verify-container-compose.sh"], "true"],- ["pull_request", false, ["sdk/typescript/src/index.ts"], "false"],- ["pull_request", false, ["README.md"], "false"],- [- "pull_request",- false,- [".github/workflows/node-ci.yml"],- "true",- "true",- ],- [- "pull_request",- false,- [".github/workflows/test-quality.yml"],- "true",- "true",- ],- [- "pull_request",- false,- [".github/actions/setup-tools/action.yml"],- "true",- "true",- ],- ...[- "sdk/typescript/bunfig.toml",- "sdk/typescript/scripts/compare-test-reports.mts",- "sdk/typescript/scripts/prepare-windows-test-root.ps1",- "sdk/typescript/scripts/run-ci-tests.mts",- "sdk/typescript/scripts/test-shards.mts",- "sdk/typescript/scripts/test-timings.json",- ].map(- (path) => ["pull_request", false, [path], "false", "true"] as const,- ),- ] as const) {- const output = join(directory, "output");- await rm(output, { force: true });- const result = spawnSync(- "bash",- [- "-c",- 'changed_paths=("$@"); git() { if ((${#changed_paths[@]})); then printf "%s\\0" "${changed_paths[@]}"; fi; }\n' +- scope.run,- "scope",- ...paths,- ],- {- encoding: "utf8",- env: {- ...process.env,- EVENT_NAME: event,- BASE_CHANGED: String(baseChanged),- GITHUB_OUTPUT: output,- },- },- );- expect(result.status, result.stderr).toBe(0);- const outputs = Object.fromEntries(- (await readFile(output, "utf8"))- .trim()- .split("\n")- .map((line) => line.split("=")),- );- expect(outputs["workflow-quality"], paths.join(",")).toBe(expected);- expect(outputs["test-quality"], paths.join(",")).toBe(runnerExpected);- }- } finally {- await rm(directory, { recursive: true, force: true });- }- },-);+test("classification reads the PR merge diff rather than unrelated base changes", async () => {+ const scope = ci.jobs["classify-changes"]!.steps.find(+ (step) => step.name === "Select required checks",+ )!;+ const [command, script] = scope.run.split(" ");+ expect(command).toBe("node");+ const directory = await mkdtemp(join(tmpdir(), "ci-merge-diff-"));+ const repository = join(directory, "repository");+ const output = join(directory, "outputs");+ await mkdir(repository);+ const git = (...args: string[]) =>+ execFileSync(+ "git",+ [+ "-c",+ "user.name=CI Test",+ "-c",+ "[email protected]",+ "-c",+ "commit.gpgsign=false",+ ...args,+ ],+ { cwd: repository, encoding: "utf8", stdio: "pipe" },+ );+ try {+ git("init", "-b", "main");+ await writeFile(join(repository, "README.md"), "Original documentation\n");+ git("add", ".");+ git("commit", "-m", "Initial fixture");+ git("checkout", "-b", "docs");+ await writeFile(join(repository, "README.md"), "Updated documentation\n");+ git("commit", "-am", "Update documentation");+ git("checkout", "main");+ await writeFile(+ join(repository, "runtime.ts"),+ "export const value = 1;\n",+ );+ git("add", ".");+ git("commit", "-m", "Independent base change");+ git("merge", "--no-ff", "docs", "-m", "Merge fixture");+ const result = spawnSync(+ command!,+ [fileURLToPath(new URL(`../../../${script}`, import.meta.url))],+ {+ cwd: repository,+ encoding: "utf8",+ env: {+ ...process.env,+ EVENT_NAME: "pull_request",+ BASE_CHANGED: "false",+ GITHUB_OUTPUT: output,+ },+ },+ );+ expect(result.status, result.stderr).toBe(0);+ const outputs = Object.fromEntries(+ (await readFile(output, "utf8"))+ .trim()+ .split("\n")+ .map((line) => line.split("=")),+ );+ expect(outputs["source-required"]).toBe("false");+ expect(outputs["container-validate"]).toBe("false");+ expect(outputs["workflow-quality"]).toBe("false");+ } finally {+ await rm(directory, { recursive: true, force: true });+ }+});for (const target of musl.jobs.primitives.strategy.matrix.include) {for (const scenario of ["ecr-success", "ecr-failure", "both-fail"] as const) {@@ -406,36 +362,19 @@ for (const target of musl.jobs.primitives.strategy.matrix.include) {}}-bashTest(- "required Unix checks fail when selected workflow checks do not pass",- () => {- const aggregate = ci.jobs["required-test"]!;+test("legacy required check names propagate the final CI gate result", () => {+ for (const id of ["required-test", "windows"]) {+ const aggregate = ci.jobs[id]!;+ expect(aggregate.needs).toContain("ci");expect(aggregate.if).toContain("always()");const gate = aggregate.steps.find(- (step) => step.name === "Require selected workflow checks",+ (step) => step.name === "Require CI gate",)!;- const condition = gate- .if!.replaceAll(- "needs.classify-changes.outputs.workflow-quality",- '"$SELECTED"',- )- .replaceAll("needs.workflow-quality.result", '"$RESULT"');- for (const [selected, result, expected] of [- ["true", "success", 0],- ["true", "failure", 1],- ["true", "cancelled", 1],- ["true", "skipped", 1],- ["false", "skipped", 0],- ] as const) {- const execution = spawnSync(- "bash",- ["-c", `if [[ ${condition} ]]; then\n${gate.run}\nfi`],- {- encoding: "utf8",- env: { ...process.env, SELECTED: selected, RESULT: result },- },+ expect(gate.run).toBe("exit 1");+ for (const result of ["success", "failure", "cancelled", "skipped"]) {+ expect(expression(gate.if!, { needs: { ci: { result } } })).toBe(+ result !== "success",);- expect(execution.status, execution.stderr).toBe(expected);}- },-);+ }+});