Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

ci: skip independent jobs for edits to existing Python tests (#2002)

Michael D'Angelo85b2574630ba
diff --git a/.github/scripts/select-ci-checks.mjs b/.github/scripts/select-ci-checks.mjs
index d503bcf4f..dd159562d 100644
--- a/.github/scripts/select-ci-checks.mjs
+++ b/.github/scripts/select-ci-checks.mjs
@@ -6,6 +6,7 @@ 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$/;
+const pythonTest = /^plugins\/codex-security\/tests\/test_[^/]*\.py$/;
const sdkTest = /^sdk\/typescript\/tests-ts\/[^/]+\.test\.ts$/;
const actionFiles =
/^(?:action\.yml|github-action\/(?:README\.md|(?:runtime\/)?package(?:-lock)?\.json|dist\/(?:index|post)\.cjs|(?:src|scripts|tests)\/[^/]+\.(?:mjs|ts)))$/;
@@ -24,8 +25,10 @@ const packagedDocs = new Set(
.map((file) => `sdk/typescript/${file}`),
);
-function scopeFor(paths, event, baseChanged) {
+function scopeFor(paths, { event, baseChanged, modifiedOnly }) {
if (event !== "pull_request" || baseChanged || !paths.length) return "full";
+ if (modifiedOnly && paths.every((path) => pythonTest.test(path)))
+ return "python-tests";
if (
paths.every(
(path) =>
@@ -47,9 +50,9 @@ function scopeFor(paths, event, baseChanged) {
return "full";
}
-export function selectChecks(paths, { event, baseChanged = false }) {
- const scope = scopeFor(paths, event, baseChanged);
- const full = scope === "full";
+export function selectChecks(paths, options) {
+ const scope = scopeFor(paths, options);
+ const full = scope === "full" || scope === "python-tests";
const source = full || scope === "source";
const sourceBeyondSdkTests =
full || (scope === "source" && !paths.every((path) => sdkTest.test(path)));
@@ -82,7 +85,7 @@ export function selectChecks(paths, { event, baseChanged = false }) {
markers: "cross_platform or native_windows",
},
];
- return {
+ const selected = {
"source-required": String(source),
"plugin-tests-required": String(sourceBeyondSdkTests),
"package-required": String(source || scope === "action"),
@@ -105,6 +108,11 @@ export function selectChecks(paths, { event, baseChanged = false }) {
node: full ? ["22.13.0", "24"] : ["22.13.0"],
}),
};
+ if (scope === "python-tests") {
+ for (const name of ["source-required", "action-ci", "eval-contracts"])
+ selected[name] = "false";
+ }
+ return selected;
}
if (
@@ -130,17 +138,19 @@ if (
);
}
}
- const paths =
+ const changes =
event === "pull_request" && !baseChanged
? execFileSync(
"git",
- ["diff", "--no-renames", "--name-only", "-z", "HEAD^1", "HEAD"],
+ ["diff", "--no-renames", "--name-status", "-z", "HEAD^1", "HEAD"],
{ encoding: "utf8" },
)
.split("\0")
.filter(Boolean)
: [];
- const selected = selectChecks(paths, { event, baseChanged });
+ const paths = changes.filter((_, i) => i % 2);
+ const modifiedOnly = changes.every((field, i) => i % 2 || field === "M");
+ const selected = selectChecks(paths, { event, baseChanged, modifiedOnly });
appendFileSync(
process.env.GITHUB_OUTPUT,
Object.entries(selected)
diff --git a/.github/scripts/test-ci-selection.mjs b/.github/scripts/test-ci-selection.mjs
index 5ab3d7cfd..09fff0ec5 100644
--- a/.github/scripts/test-ci-selection.mjs
+++ b/.github/scripts/test-ci-selection.mjs
@@ -1,5 +1,8 @@
import assert from "node:assert/strict";
-import { spawnSync } from "node:child_process";
+import { execFileSync, spawnSync } from "node:child_process";
+import * as fs from "node:fs";
+import { tmpdir } from "node:os";
+import { join, resolve } from "node:path";
import { test } from "node:test";
import { selectChecks } from "./select-ci-checks.mjs";
import { failedChecks } from "./check-ci-results.mjs";
@@ -85,6 +88,58 @@ const docs = {
"container-validate": "false",
};
+test("only edits to existing direct pytest modules skip independent jobs", (t) => {
+ const cwd = fs.mkdtempSync(resolve(tmpdir(), "ci-pytest-"));
+ t.after(() => fs.rmSync(cwd, { recursive: true, force: true }));
+ const files = join(cwd, "plugins/codex-security/tests");
+ const output = join(cwd, "output");
+ const script = join(import.meta.dirname, "select-ci-checks.mjs");
+ const env = {
+ ...process.env,
+ EVENT_NAME: "pull_request",
+ BASE_CHANGED: "false",
+ GITHUB_OUTPUT: output,
+ };
+ // A Git hook may export its own repository and index into this process.
+ for (const name of Object.keys(env))
+ if (/^GIT_/iu.test(name)) delete env[name];
+ env.GIT_CONFIG_GLOBAL = join(cwd, "empty.gitconfig");
+ env.GIT_CONFIG_NOSYSTEM = "1";
+ const git = (...args) => execFileSync("git", args, { cwd, env });
+ git("init", "-q");
+ git("config", "user.name", "CI Fixture");
+ git("config", "user.email", "[email protected]");
+ fs.mkdirSync(files, { recursive: true });
+ let revision = 0;
+ function commit(...names) {
+ for (const name of names)
+ fs.writeFileSync(join(files, name), String(revision++));
+ git("add", "--force", "plugins");
+ git("commit", "-qm", "fixture");
+ }
+ commit("test_2fa.py", "conftest.py");
+ const reduced = {
+ ...fullQualification,
+ "source-required": "false",
+ "action-ci": "false",
+ "eval-contracts": "false",
+ };
+ for (const [names, expected] of [
+ [["test_2fa.py"], reduced],
+ [["test_2fa.py", "test_added.py"], fullQualification],
+ [["test_2fa.py", "conftest.py"], fullQualification],
+ ]) {
+ commit(...names);
+ fs.writeFileSync(output, "");
+ execFileSync(process.execPath, [script], { cwd, env });
+ const lines = fs.readFileSync(output, "utf8").trim().split("\n");
+ assert.deepEqual(
+ Object.fromEntries(lines.map((line) => line.split("="))),
+ expected,
+ );
+ }
+});
+
test("ordinary documentation selects static checks", () => {
assert.deepEqual(select(["README.md", "docs/bedrock.md"]), docs);
for (const path of [
diff --git a/docs/ci.md b/docs/ci.md
index 22ba3433a..cffce852c 100644
--- a/docs/ci.md
+++ b/docs/ci.md
@@ -56,6 +56,12 @@ and host plugin, checks the Codex version across the SDK, MCP and triage
lockfiles, and runs the triage, secret-discovery, Standard time-budget and
workflow-routing suites.
+Edits limited to existing top-level `plugins/codex-security/tests/test_*.py`
+modules keep all five Python jobs, MCP, host, native, package, compatibility,
+and container checks. They skip the SDK shards, Windows install checks, Action
+and eval jobs. Adding, removing, or renaming modules, editing shared helpers,
+or including any other path selects full qualification.
+
Inputs outside these routes select 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