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: use formatter-only checks for Markdown changes (#650)
mldangelo-oaia3b157ce1014
diff --git a/.github/workflows/node-ci.yml b/.github/workflows/node-ci.ymlindex b614c176a..f75ab0511 100644--- a/.github/workflows/node-ci.yml+++ b/.github/workflows/node-ci.yml@@ -10,35 +10,53 @@ permissions:contents: readconcurrency:- group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}-${{ github.event_name == 'pull_request' && github.event.action == 'edited' && github.event.changes.title == null && github.event.changes.base == null && 'metadata-only' || 'full' }}- cancel-in-progress: ${{ github.event_name == 'pull_request' && (github.event.action != 'edited' || github.event.changes.title != null || github.event.changes.base != null) }}+ group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}jobs:validate-title:- name: ${{ github.event_name == 'pull_request' && github.event.action == 'edited' && github.event.changes.title == null && github.event.changes.base == null && 'metadata-only / ' || '' }}validate pull request title+ name: validate pull requestruns-on: ubuntu-latest+ timeout-minutes: 10outputs:- run-full-ci: ${{ steps.scope.outputs.run-full-ci }}+ ci-mode: ${{ steps.scope.outputs.ci-mode }}steps:- - name: Decide whether full CI is needed+ - name: Checkout pull request for change classification+ if: github.event_name == 'pull_request' && github.event.changes.base == null+ uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2+ with:+ fetch-depth: 2+ persist-credentials: false++ - name: Decide CI modeid: scopeshell: bashenv:EVENT_NAME: ${{ github.event_name }}- EVENT_ACTION: ${{ github.event.action }}- TITLE_CHANGED: ${{ github.event.changes.title != null }}BASE_CHANGED: ${{ github.event.changes.base != null }}run: |set -euo pipefail- run_full_ci=true+ ci_mode=fullif [[ "$EVENT_NAME" == "pull_request" &&- "$EVENT_ACTION" == "edited" &&- "$TITLE_CHANGED" != "true" &&"$BASE_CHANGED" != "true" ]]; then- run_full_ci=false+ changed_files="$(mktemp)"+ trap 'rm -f "$changed_files"' EXIT+ git diff --no-renames --name-only -z HEAD^1 HEAD > "$changed_files"++ changed=false+ markdown_only=true+ while IFS= read -r -d '' path; do+ changed=true+ if [[ "$path" != *.md ]]; then+ markdown_only=false+ fi+ done < "$changed_files"+ if [[ "$changed" == "true" && "$markdown_only" == "true" ]]; then+ ci_mode=markdown+ fifi- printf 'run-full-ci=%s\n' "$run_full_ci" >> "$GITHUB_OUTPUT"+ printf 'ci-mode=%s\n' "$ci_mode" >> "$GITHUB_OUTPUT"- name: Require a Conventional Commit pull request titleif: github.event_name == 'pull_request'@@ -54,10 +72,45 @@ jobs:exit 1fi+ - name: Set up pnpm+ if: steps.scope.outputs.ci-mode == 'markdown'+ uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9+ with:+ package_json_file: sdk/typescript/package.json+ cache: true+ cache_dependency_path: sdk/typescript/pnpm-lock.yaml++ - name: Set up Node.js+ if: steps.scope.outputs.ci-mode == 'markdown'+ uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6+ with:+ node-version: "22.13.0"+ cache: npm+ cache-dependency-path: sdk/typescript/pnpm-lock.yaml++ - name: Install dependencies+ if: steps.scope.outputs.ci-mode == 'markdown'+ run: pnpm --dir sdk/typescript install --frozen-lockfile++ - name: Check Markdown formatting+ if: steps.scope.outputs.ci-mode == 'markdown'+ shell: bash+ run: |+ files=()+ while IFS= read -r -d '' path; do+ if [[ -f "$GITHUB_WORKSPACE/$path" &&+ ! -L "$GITHUB_WORKSPACE/$path" ]]; then+ files+=("$GITHUB_WORKSPACE/$path")+ fi+ done < <(git diff --no-renames --name-only -z HEAD^1 HEAD)+ if ((${#files[@]} > 0)); then+ pnpm --dir sdk/typescript exec prettier --check "${files[@]}"+ fi+test:- name: ${{ github.event_name == 'pull_request' && github.event.action == 'edited' && github.event.changes.title == null && github.event.changes.base == null && 'metadata-only / ' || '' }}tests / ${{ matrix.os }} / node-${{ matrix.node == '22.13.0' && '22' || matrix.node }}+ name: tests / ${{ matrix.os }} / node-${{ matrix.node == '22.13.0' && '22' || matrix.node }}needs: validate-title- if: needs.validate-title.outputs.run-full-ci == 'true'+ if: needs.validate-title.outputs.ci-mode == 'full'runs-on: ${{ matrix.os }}timeout-minutes: 20strategy:@@ -148,9 +201,9 @@ jobs:run: pnpm run check:package ../../dist/*.tgzrequired-test:- name: ${{ github.event_name == 'pull_request' && github.event.action == 'edited' && github.event.changes.title == null && github.event.changes.base == null && 'metadata-only / ' || '' }}${{ matrix.os }} / node-22+ name: ${{ matrix.os }} / node-22needs: [validate-title, test]- if: always() && !(github.event_name == 'pull_request' && github.event.action == 'edited' && github.event.changes.title == null && github.event.changes.base == null)+ if: always()runs-on: ubuntu-lateststrategy:fail-fast: false@@ -159,13 +212,13 @@ jobs:steps:- name: Require every Unix coverage job- if: needs.validate-title.result != 'success' || needs.test.result != 'success'+ if: needs.validate-title.result != 'success' || (needs.validate-title.outputs.ci-mode == 'full' && needs.test.result != 'success') || (needs.validate-title.outputs.ci-mode != 'full' && needs.validate-title.outputs.ci-mode != 'markdown')run: exit 1windows-test:- name: ${{ github.event_name == 'pull_request' && github.event.action == 'edited' && github.event.changes.title == null && github.event.changes.base == null && 'metadata-only / ' || '' }}windows-latest / node-${{ matrix.node == '22.13.0' && '22' || matrix.node }} / tests-${{ matrix.shard }}+ name: windows-latest / node-${{ matrix.node == '22.13.0' && '22' || matrix.node }} / tests-${{ matrix.shard }}needs: validate-title- if: needs.validate-title.outputs.run-full-ci == 'true'+ if: needs.validate-title.outputs.ci-mode == 'full'runs-on: windows-latesttimeout-minutes: 20strategy:@@ -223,9 +276,9 @@ jobs:run: bun test --timeout 120000 ./tests-ts/windows-machine-policy.test.tswindows-verify:- name: ${{ github.event_name == 'pull_request' && github.event.action == 'edited' && github.event.changes.title == null && github.event.changes.base == null && 'metadata-only / ' || '' }}windows-latest / node-${{ matrix.node == '22.13.0' && '22' || matrix.node }} / verify+ name: windows-latest / node-${{ matrix.node == '22.13.0' && '22' || matrix.node }} / verifyneeds: validate-title- if: needs.validate-title.outputs.run-full-ci == 'true'+ if: needs.validate-title.outputs.ci-mode == 'full'runs-on: windows-latesttimeout-minutes: 20strategy:@@ -263,9 +316,9 @@ jobs:run: pnpm run check:package ../../dist/*.tgzwindows:- name: ${{ github.event_name == 'pull_request' && github.event.action == 'edited' && github.event.changes.title == null && github.event.changes.base == null && 'metadata-only / ' || '' }}windows-latest / node-${{ matrix.node == '22.13.0' && '22' || matrix.node }}+ name: windows-latest / node-${{ matrix.node == '22.13.0' && '22' || matrix.node }}runs-on: ubuntu-latest- if: always() && !(github.event_name == 'pull_request' && github.event.action == 'edited' && github.event.changes.title == null && github.event.changes.base == null)+ if: always()needs: [validate-title, windows-test, windows-verify]strategy:fail-fast: false@@ -274,5 +327,5 @@ jobs:steps:- name: Require every Windows coverage job- if: needs.validate-title.result != 'success' || needs.windows-test.result != 'success' || needs.windows-verify.result != 'success'+ if: needs.validate-title.result != 'success' || (needs.validate-title.outputs.ci-mode == 'full' && (needs.windows-test.result != 'success' || needs.windows-verify.result != 'success')) || (needs.validate-title.outputs.ci-mode != 'full' && needs.validate-title.outputs.ci-mode != 'markdown')run: exit 1diff --git a/README.md b/README.mdindex bbf96c5d6..3c97d1505 100644--- a/README.md+++ b/README.md@@ -48,7 +48,6 @@ Use the included Docker Compose configuration for scans of many repositories. Se## Other providers-To use another inference provider, set its API key and select a model:```bashdiff --git a/sdk/typescript/tests-ts/release-automation.test.ts b/sdk/typescript/tests-ts/release-automation.test.tsindex efc764dd0..d73f58b64 100644--- a/sdk/typescript/tests-ts/release-automation.test.ts+++ b/sdk/typescript/tests-ts/release-automation.test.ts@@ -5,6 +5,7 @@ import {mkdtempSync,readFileSync,rmSync,+ symlinkSync,writeFileSync,} from "node:fs";import { tmpdir } from "node:os";@@ -3899,11 +3900,7 @@ describe("GitHub release workflow safeguards", () => {);});- test("isolates body-only edits from full CI names and concurrency", () => {- const metadataOnly =- "github.event_name == 'pull_request' && github.event.action == 'edited' && github.event.changes.title == null && github.event.changes.base == null";- const metadataPrefix =- "${{ " + metadataOnly + " && 'metadata-only / ' || '' }}";+ test("keeps required contexts stable across reduced CI", () => {const workflow = Bun.YAML.parse(nodeCiWorkflow) as {concurrency: {group: string;@@ -3914,48 +3911,95 @@ describe("GitHub release workflow safeguards", () => {{name: string;if?: string;+ "timeout-minutes"?: number;strategy?: { matrix: Record<string, string[]> };- steps: Array<{ if?: string }>;+ steps: Array<{+ if?: string;+ name?: string;+ run?: string;+ }>;}>;};expect(workflow.concurrency.group).toBe(- "${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}-${{ " +- metadataOnly +- " && 'metadata-only' || 'full' }}",+ "${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}",);expect(workflow.concurrency["cancel-in-progress"]).toBe(- "${{ github.event_name == 'pull_request' && (github.event.action != 'edited' || github.event.changes.title != null || github.event.changes.base != null) }}",+ "${{ github.event_name == 'pull_request' }}",);- for (const job of Object.values(workflow.jobs)) {- expect(job.name.startsWith(metadataPrefix), job.name).toBe(true);- }+ expect(workflow.jobs["validate-title"]?.["timeout-minutes"]).toBe(10);+ expect(+ workflow.jobs["validate-title"]?.steps.find(+ ({ name }) =>+ name === "Checkout pull request for change classification",+ )?.if,+ ).toContain("github.event.changes.base == null");- const fullCiCondition =- "needs.validate-title.outputs.run-full-ci == 'true'";+ const fullCiCondition = "needs.validate-title.outputs.ci-mode == 'full'";for (const job of ["test", "windows-test", "windows-verify"]) {expect(workflow.jobs[job]?.if).toBe(fullCiCondition);}- const requiredJobCondition = `always() && !(${metadataOnly})`;+ expect(workflow.jobs["markdown-checks"]).toBeUndefined();+ const validationSteps = workflow.jobs["validate-title"]?.steps ?? [];+ for (const stepName of [+ "Set up pnpm",+ "Set up Node.js",+ "Install dependencies",+ "Check Markdown formatting",+ ]) {+ expect(validationSteps.find(({ name }) => name === stepName)?.if).toBe(+ "steps.scope.outputs.ci-mode == 'markdown'",+ );+ }+ const markdownCommand =+ validationSteps.find(({ name }) => name === "Check Markdown formatting")+ ?.run ?? "";+ expect(markdownCommand).toContain(+ "git diff --no-renames --name-only -z HEAD^1 HEAD",+ );+ expect(markdownCommand).toContain("! -L");+ expect(markdownCommand).toContain(+ "pnpm --dir sdk/typescript exec prettier --check",+ );+ expect(markdownCommand).not.toContain("--ignore-path");+ const requiredJobCondition = "always()";expect(workflow.jobs["required-test"]?.if).toBe(requiredJobCondition);expect(workflow.jobs["windows"]?.if).toBe(requiredJobCondition);expect(workflow.jobs["required-test"]?.steps[0]?.if).toBe(- "needs.validate-title.result != 'success' || needs.test.result != 'success'",+ "needs.validate-title.result != 'success' || (needs.validate-title.outputs.ci-mode == 'full' && needs.test.result != 'success') || (needs.validate-title.outputs.ci-mode != 'full' && needs.validate-title.outputs.ci-mode != 'markdown')",);expect(workflow.jobs["windows"]?.steps[0]?.if).toBe(- "needs.validate-title.result != 'success' || needs.windows-test.result != 'success' || needs.windows-verify.result != 'success'",+ "needs.validate-title.result != 'success' || (needs.validate-title.outputs.ci-mode == 'full' && (needs.windows-test.result != 'success' || needs.windows-verify.result != 'success')) || (needs.validate-title.outputs.ci-mode != 'full' && needs.validate-title.outputs.ci-mode != 'markdown')",);+ for (const [ciMode, validation, upstream, gateFailure] of [+ ["full", "success", "success", false],+ ["full", "success", "skipped", true],+ ["markdown", "success", "skipped", false],+ ["markdown", "failure", "skipped", true],+ ["skip", "success", "skipped", true],+ ["unknown", "success", "skipped", true],+ ] as const) {+ const values = {+ "needs.test.result": upstream,+ "needs.validate-title.outputs.ci-mode": ciMode,+ "needs.validate-title.result": validation,+ "needs.windows-test.result": upstream,+ "needs.windows-verify.result": upstream,+ };+ for (const job of ["required-test", "windows"]) {+ expect(+ evaluateWorkflowCondition(+ workflow.jobs[job]?.steps[0]?.if ?? "",+ values,+ ),+ `${job}: ${ciMode}/${validation}/${upstream}`,+ ).toBe(gateFailure);+ }+ }- const renderName = (- template: string,- values: Record<string, string>,- metadata: boolean,- ) => {- let name = template.replace(- metadataPrefix,- metadata ? "metadata-only / " : "",- );+ const renderName = (template: string, values: Record<string, string>) => {+ let name = template;for (const [key, value] of Object.entries(values)) {name = name.replaceAll("${{ matrix." + key + " }}", value);}@@ -3968,18 +4012,10 @@ describe("GitHub release workflow safeguards", () => {const windowsJob = workflow.jobs["windows"];const fullNames = [...(unixJob?.strategy?.matrix["os"] ?? []).map((os) =>- renderName(unixJob?.name ?? "", { os }, false),- ),- ...(windowsJob?.strategy?.matrix["node"] ?? []).map((node) =>- renderName(windowsJob?.name ?? "", { node }, false),- ),- ];- const metadataNames = [- ...(unixJob?.strategy?.matrix["os"] ?? []).map((os) =>- renderName(unixJob?.name ?? "", { os }, true),+ renderName(unixJob?.name ?? "", { os }),),...(windowsJob?.strategy?.matrix["node"] ?? []).map((node) =>- renderName(windowsJob?.name ?? "", { node }, true),+ renderName(windowsJob?.name ?? "", { node }),),];const requiredContexts = new Set([@@ -3991,189 +4027,97 @@ describe("GitHub release workflow safeguards", () => {expect(fullNames.filter((name) => requiredContexts.has(name)).sort(),).toEqual([...requiredContexts].sort());- expect(metadataNames.some((name) => requiredContexts.has(name))).toBe(- false,- );- expect(- metadataNames.every((name) => name.startsWith("metadata-only / ")),- ).toBe(true);});test.each([- {- name: "body-only edit with a valid title",- eventName: "pull_request",- action: "edited",- titleChanged: false,- baseChanged: false,- title: "docs: clarify release notes",- fullCi: false,- titleValid: true,- upstream: "skipped",- gateFailure: false,- cancellation: false,- },- {- name: "body-only edit with an invalid title",- eventName: "pull_request",- action: "edited",- titleChanged: false,- baseChanged: false,- title: "Docs: invalid title ",- fullCi: false,- titleValid: false,- upstream: "skipped",- gateFailure: false,- cancellation: false,- },- {- name: "title edit",- eventName: "pull_request",- action: "edited",- titleChanged: true,- baseChanged: false,- title: "ci: update title",- fullCi: true,- titleValid: true,- upstream: "success",- gateFailure: false,- cancellation: true,- },- {- name: "base edit",- eventName: "pull_request",- action: "edited",- titleChanged: false,- baseChanged: true,- title: "ci: update base",- fullCi: true,- titleValid: true,- upstream: "success",- gateFailure: false,- cancellation: true,- },- {- name: "code synchronization",- eventName: "pull_request",- action: "synchronize",- titleChanged: false,- baseChanged: false,- title: "ci: update code",- fullCi: true,- titleValid: true,- upstream: "success",- gateFailure: false,- cancellation: true,- },- {- name: "push",- eventName: "push",- action: "none",- titleChanged: false,- baseChanged: false,- title: "",- fullCi: true,- titleValid: true,- upstream: "success",- gateFailure: false,- cancellation: false,- },- {- name: "full CI with skipped upstream jobs",- eventName: "pull_request",- action: "synchronize",- titleChanged: false,- baseChanged: false,- title: "ci: update code",- fullCi: true,- titleValid: true,- upstream: "skipped",- gateFailure: true,- cancellation: true,- },- ])(- "keeps required contexts truthful for $name",- ({- eventName,- action,- titleChanged,- baseChanged,- title,- fullCi,- titleValid,- upstream,- gateFailure,- cancellation,- }) => {- const workflow = Bun.YAML.parse(nodeCiWorkflow) as {- concurrency: { "cancel-in-progress": string };- jobs: Record<string, { steps: Array<{ if?: string }> }>;- };- const scopeScript = workflowStepShell(- nodeCiWorkflow,- "Decide whether full CI is needed",- );- const titleScript = workflowStepShell(- nodeCiWorkflow,- "Require a Conventional Commit pull request title",- );+ [+ "Markdown-only PR",+ "pull_request",+ false,+ ["README.md", "docs/guide.md"],+ "markdown",+ ],+ ["base retarget", "pull_request", true, ["README.md"], "full"],+ ["mixed PR", "pull_request", false, ["README.md", "src/index.ts"], "full"],+ [+ "source-to-Markdown rename",+ "pull_request",+ false,+ ["src/index.ts", "docs/index.md"],+ "full",+ ],+ ["empty merge diff", "pull_request", false, [], "full"],+ ["push", "push", false, ["README.md"], "full"],+ ] as const)(+ "selects the conservative CI mode for %s",+ (_name, eventName, baseChanged, changedPaths, ciMode) => {const workspace = mkdtempSync(join(tmpdir(), "release-ci-scope-"));const output = join(workspace, "output");+ const script = workflowStepShell(nodeCiWorkflow, "Decide CI mode");+ const gitMock = `git() {+ [[ "$*" == "diff --no-renames --name-only -z HEAD^1 HEAD" ]] || return 64+ while IFS= read -r path; do+ [[ -z "$path" ]] || printf '%s\\0' "$path"+ done <<< "$MOCK_CHANGED_FILES"+ }`;try {- const scope = spawnSync(bash, ["-c", scopeScript], {+ const result = spawnSync(bash, ["-c", `${gitMock}\n${script}`], {env: {...process.env,BASE_CHANGED: String(baseChanged),- EVENT_ACTION: action === "none" ? "" : action,EVENT_NAME: eventName,GITHUB_OUTPUT: output,- TITLE_CHANGED: String(titleChanged),+ MOCK_CHANGED_FILES: changedPaths.join("\n"),},});- expect(scope.status).toBe(0);- expect(readFileSync(output, "utf8")).toBe(- `run-full-ci=${String(fullCi)}\n`,- );-- const validation =- eventName === "pull_request"- ? spawnSync(bash, ["-c", titleScript], {- env: { ...process.env, PR_TITLE: title },- }).status === 0- ? "success"- : "failure"- : "success";- expect(validation === "success").toBe(titleValid);-- const values = {- "needs.test.result": upstream,- "needs.validate-title.result": validation,- "needs.windows-test.result": upstream,- "needs.windows-verify.result": upstream,- };- const unixGate = workflow.jobs["required-test"]?.steps[0]?.if ?? "";- const windowsGate = workflow.jobs["windows"]?.steps[0]?.if ?? "";- if (fullCi) {- expect(evaluateWorkflowCondition(unixGate, values)).toBe(gateFailure);- expect(evaluateWorkflowCondition(windowsGate, values)).toBe(- gateFailure,- );- } else {- expect(unixGate).toBeDefined();- expect(windowsGate).toBeDefined();- }+ expect(result.status).toBe(0);+ expect(readFileSync(output, "utf8")).toBe(`ci-mode=${ciMode}\n`);+ } finally {+ rmSync(workspace, { recursive: true, force: true });+ }+ },+ );- expect(- evaluateWorkflowCondition(- workflow.concurrency["cancel-in-progress"],- {- "github.event.changes.base": baseChanged ? "changed" : "null",- "github.event.changes.title": titleChanged ? "changed" : "null",- "github.event.action": action,- "github.event_name": eventName,+ test.skipIf(process.platform === "win32")(+ "formats every changed regular non-symlink Markdown file",+ () => {+ const workspace = mkdtempSync(join(tmpdir(), "release-ci-markdown-"));+ const argsFile = join(workspace, "prettier-args");+ const guide = join(workspace, "docs", "guide with spaces.md");+ const readme = join(workspace, "README.md");+ mkdirSync(join(workspace, "docs"));+ writeFileSync(guide, "# Guide\n");+ writeFileSync(readme, "# Readme\n");+ symlinkSync(readme, join(workspace, "docs", "link.md"));+ const mocks = `git() {+ printf '%s\\0' README.md 'docs/guide with spaces.md' docs/link.md deleted.md+ }+ pnpm() { printf '%s\\n' "$@" > "$MOCK_PNPM_ARGS"; }`;+ try {+ const result = spawnSync(+ bash,+ [+ "-c",+ `${mocks}\n${workflowStepShell(nodeCiWorkflow, "Check Markdown formatting")}`,+ ],+ {+ env: {+ ...process.env,+ GITHUB_WORKSPACE: workspace,+ MOCK_PNPM_ARGS: argsFile,},- ),- ).toBe(cancellation);+ },+ );+ expect(result.status).toBe(0);+ expect(readFileSync(argsFile, "utf8").trim().split("\n")).toEqual([+ "--dir",+ "sdk/typescript",+ "exec",+ "prettier",+ "--check",+ readme,+ guide,+ ]);} finally {rmSync(workspace, { recursive: true, force: true });}