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

test(ci): share workflow script execution fixtures (#1396)

mldangelo-oai987f6a5247cf
diff --git a/sdk/typescript/tests-ts/azure-pipelines-example.test.ts b/sdk/typescript/tests-ts/azure-pipelines-example.test.ts
index d1c53deb4..afd0eb70c 100644
--- a/sdk/typescript/tests-ts/azure-pipelines-example.test.ts
+++ b/sdk/typescript/tests-ts/azure-pipelines-example.test.ts
@@ -1,4 +1,3 @@
-import { spawnSync } from "node:child_process";
import {
existsSync,
mkdirSync,
@@ -12,6 +11,7 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, expect, test } from "bun:test";
import { parse } from "yaml";
+import { runWorkflowScript } from "./support/workflow-script.js";
interface Step {
name?: string;
@@ -69,46 +69,20 @@ function runStep(
}
// Git Bash accepts forward-slash drive paths on Windows.
const root = directory.replaceAll("\\", "/");
- const bash =
- process.platform === "win32"
- ? join(
- process.env["ProgramFiles"] ?? "C:/Program Files",
- "Git/bin/bash.exe",
- )
- : "bash";
- const result = spawnSync(
- bash,
- [
- "--noprofile",
- "--norc",
- "-c",
- `codex-security() {
- printf '%s\\0' "$@" > "$ARGUMENTS_PATH"
- printf '{"mock":true}\\n'
- return "$MOCK_EXIT_CODE"
-}
-${step.inputs?.["inlineScript"] ?? step.inputs?.["script"]}`,
- ],
+ const result = runWorkflowScript(
+ directory,
+ step.inputs?.["inlineScript"] ?? step.inputs?.["script"],
{
- cwd: directory,
- encoding: "utf8",
- env: {
- PATH: process.env["PATH"],
- SYSTEMROOT: process.env["SYSTEMROOT"],
- ARGUMENTS_PATH: `${root}/arguments`,
- TARGET_DIRECTORY: `${root}/repository with spaces`,
- SCAN_DIRECTORY: `${root}/scan`,
- REPORT_DIRECTORY: `${root}/reports`,
- BEDROCK_MODEL_ID: "example.model",
- SCAN_MODE: "full",
- BASE_REVISION: "HEAD^",
- FAIL_ON_SEVERITY: "none",
- MOCK_EXIT_CODE: "0",
- ...overrides,
- },
+ ARGUMENTS_PATH: `${root}/arguments`,
+ TARGET_DIRECTORY: `${root}/repository with spaces`,
+ SCAN_DIRECTORY: `${root}/scan`,
+ REPORT_DIRECTORY: `${root}/reports`,
+ SCAN_MODE: "full",
+ BASE_REVISION: "HEAD^",
+ FAIL_ON_SEVERITY: "none",
+ ...overrides,
},
);
- if (result.error) throw result.error;
const argumentsPath = join(directory, "arguments");
const args = existsSync(argumentsPath)
? readFileSync(argumentsPath, "utf8").split("\0").slice(0, -1)
diff --git a/sdk/typescript/tests-ts/github-actions-example.test.ts b/sdk/typescript/tests-ts/github-actions-example.test.ts
index 563faff77..87212b91c 100644
--- a/sdk/typescript/tests-ts/github-actions-example.test.ts
+++ b/sdk/typescript/tests-ts/github-actions-example.test.ts
@@ -1,9 +1,9 @@
-import { spawnSync } from "node:child_process";
import { mkdtempSync, readFileSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, expect, test } from "bun:test";
import { parse } from "yaml";
+import { runWorkflowScript } from "./support/workflow-script.js";
interface Step {
id?: string;
@@ -48,48 +48,21 @@ function runStep(step: Step, overrides: Record<string, string> = {}) {
temporaryDirectories.push(directory);
// Git Bash accepts forward-slash drive paths on Windows.
const root = directory.replaceAll("\\", "/");
- const bash =
- process.platform === "win32"
- ? join(
- process.env["ProgramFiles"] ?? "C:/Program Files",
- "Git/bin/bash.exe",
- )
- : "bash";
- const result = spawnSync(
- bash,
- [
- "--noprofile",
- "--norc",
- "-e",
- "-o",
- "pipefail",
- "-c",
- `codex-security() {
- printf '%s\\0' "$@" > "$RUNNER_TEMP/arguments"
- printf '{"mock":true}\\n'
- return "$MOCK_EXIT_CODE"
-}
-${step.run}`,
- ],
+ const result = runWorkflowScript(
+ directory,
+ step.run,
{
- cwd: directory,
- encoding: "utf8",
- env: {
- PATH: process.env["PATH"],
- SYSTEMROOT: process.env["SYSTEMROOT"],
- RUNNER_TEMP: root,
- GITHUB_WORKSPACE: `${root}/repository with spaces`,
- GITHUB_OUTPUT: `${root}/outputs`,
- BEDROCK_MODEL_ID: "example.model",
- EVENT_NAME: "workflow_dispatch",
- BASE_SHA: "",
- FAIL_ON_SEVERITY: "",
- MOCK_EXIT_CODE: "0",
- ...overrides,
- },
+ RUNNER_TEMP: root,
+ GITHUB_WORKSPACE: `${root}/repository with spaces`,
+ GITHUB_OUTPUT: `${root}/outputs`,
+ EVENT_NAME: "workflow_dispatch",
+ BASE_SHA: "",
+ FAIL_ON_SEVERITY: "",
+ ...overrides,
},
+ ["-e", "-o", "pipefail"],
+ "$RUNNER_TEMP/arguments",
);
- if (result.error) throw result.error;
const args = readFileSync(join(directory, "arguments"), "utf8")
.split("\0")
.slice(0, -1);
diff --git a/sdk/typescript/tests-ts/support/workflow-script.ts b/sdk/typescript/tests-ts/support/workflow-script.ts
new file mode 100644
index 000000000..f1dd7c907
--- /dev/null
+++ b/sdk/typescript/tests-ts/support/workflow-script.ts
@@ -0,0 +1,46 @@
+import { spawnSync } from "node:child_process";
+import { join } from "node:path";
+
+export function runWorkflowScript(
+ directory: string,
+ script: unknown,
+ env: Record<string, string>,
+ shellOptions: string[] = [],
+ argumentsPath = "$ARGUMENTS_PATH",
+) {
+ const bash =
+ process.platform === "win32"
+ ? join(
+ process.env["ProgramFiles"] ?? "C:/Program Files",
+ "Git/bin/bash.exe",
+ )
+ : "bash";
+ const result = spawnSync(
+ bash,
+ [
+ "--noprofile",
+ "--norc",
+ ...shellOptions,
+ "-c",
+ `codex-security() {
+ printf '%s\\0' "$@" > "${argumentsPath}"
+ printf '{"mock":true}\\n'
+ return "$MOCK_EXIT_CODE"
+}
+${script}`,
+ ],
+ {
+ cwd: directory,
+ encoding: "utf8",
+ env: {
+ PATH: process.env["PATH"],
+ SYSTEMROOT: process.env["SYSTEMROOT"],
+ BEDROCK_MODEL_ID: "example.model",
+ MOCK_EXIT_CODE: "0",
+ ...env,
+ },
+ },
+ );
+ if (result.error) throw result.error;
+ return result;
+}