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
test(action): check declared inputs against parser reads (#2457)
Michael D'Angelof9fb15c39366
diff --git a/github-action/scripts/check-metadata.ts b/github-action/scripts/check-metadata.tsindex d1e48a0f6..d06e63e1e 100644--- a/github-action/scripts/check-metadata.ts+++ b/github-action/scripts/check-metadata.ts@@ -1,16 +1,20 @@import { readFile } from 'node:fs/promises';import assert from 'node:assert/strict';import { parse } from 'yaml';-import { INPUT_NAMES, parseInputs } from '../src/inputs.ts';+import { parseInputs } from '../src/inputs.ts';import { OUTPUT_NAMES } from '../src/main.ts';const metadata = parse(await readFile(new URL('../../action.yml', import.meta.url), 'utf8'));-assert.deepEqual(Object.keys(metadata.inputs).sort(), [...INPUT_NAMES].sort(), 'action.yml inputs must match the parser');assert.deepEqual(Object.keys(metadata.outputs).sort(), [...OUTPUT_NAMES].sort(), 'action.yml outputs must match implementation');assert.equal(metadata.runs.using, 'node24');assert.equal(metadata.runs.main, 'github-action/dist/index.cjs');assert.equal(metadata.runs.post, 'github-action/dist/post.cjs');assert.equal(metadata.runs['post-if'], 'always()');-const defaults = parseInputs(name => String(metadata.inputs[name]?.default ?? '').replace('${{ github.workspace }}', '/checkout'), '/checkout');+const inputNames = new Set<string>();+const parseWithMetadata = (overrides: Record<string, string> = {}) => parseInputs(name => {+ inputNames.add(name);+ return overrides[name] ?? String(metadata.inputs[name]?.default ?? '').replace('${{ github.workspace }}', '/checkout');+}, '/checkout');+const defaults = parseWithMetadata();assert.equal(defaults.failOnSeverity, 'none');assert.equal(defaults.scope, 'repository');assert.equal(defaults.uploadArtifacts, false);@@ -18,9 +22,11 @@ assert.equal(defaults.verbose, true);assert.equal(defaults.provider, 'openai');assert.equal(defaults.model, 'gpt-5.6-sol');for (const provider of ['amazon-bedrock', 'openrouter', 'fireworks']) {- const inputs = parseInputs(name => name === 'provider' ? provider : String(metadata.inputs[name]?.default ?? ''), '/checkout');+ const inputs = parseWithMetadata({provider});assert.equal(inputs.model, '', 'Non-OpenAI providers must not inherit an OpenAI model default');}+assert.equal(parseWithMetadata({mode:'deep', 'cyber-access-program':'standard'}).cyberAccessProgram, 'standard');+assert.deepEqual([...inputNames].sort(), Object.keys(metadata.inputs).sort(), 'action.yml inputs must match the parser');for (const group of [metadata.inputs, metadata.outputs]) for (const value of Object.values(group) as {description: string}[]) assert.ok(value.description);const examples = await readFile(new URL('../README.md', import.meta.url), 'utf8');let workflowCount = 0;@@ -31,7 +37,7 @@ for (const match of examples.matchAll(/```yaml\n([\s\S]*?)\n```/g)) {for (const job of Object.values(example.jobs) as {steps: {uses?: string; with?: Record<string,unknown>}[]}[]) {for (const step of job.steps) {if (step.uses?.startsWith('openai/codex-security@')) {- for (const key of Object.keys(step.with ?? {})) assert.ok(INPUT_NAMES.includes(key as typeof INPUT_NAMES[number]), `Workflow example uses unknown input ${key}`);+ for (const key of Object.keys(step.with ?? {})) assert.ok(Object.hasOwn(metadata.inputs, key), `Workflow example uses unknown input ${key}`);} else if (step.uses) assert.match(step.uses, /@[a-f0-9]{40}$/, 'Example dependency must use a full commit SHA');}}diff --git a/github-action/src/inputs.ts b/github-action/src/inputs.tsindex af3753b7c..aae5bb34b 100644--- a/github-action/src/inputs.ts+++ b/github-action/src/inputs.ts@@ -1,10 +1,3 @@-export const INPUT_NAMES = [- 'repository', 'scope', 'paths', 'diff-base', 'mode',- 'provider', 'model', 'cyber-access-program', 'effort', 'max-cost', 'max-time-hours', 'fail-on-severity', 'verbose', 'dry-run',- 'summary', 'annotations',- 'upload-artifacts', 'artifact-name', 'retention-days',-] as const;-export type Inputs = ReturnType<typeof parseInputs>;export function parseInputs(read: (name: string) => string, workspace: string) {diff --git a/github-action/tests/main.test.ts b/github-action/tests/main.test.tsindex 7f395647b..4daf79570 100644--- a/github-action/tests/main.test.ts+++ b/github-action/tests/main.test.ts@@ -10,13 +10,14 @@ import * as core from '@actions/core';import { DefaultArtifactClient } from '@actions/artifact';import { BlobClient } from '@azure/storage-blob';import { runAction } from '../src/main.ts';-import { INPUT_NAMES } from '../src/inputs.ts';+import { parse } from 'yaml';import { gitEnvironment } from '../src/targets.ts';import { runtimeEnvironment, type Runtime } from '../src/runtime.ts';import type { ProcessResult } from '../src/process.ts';import { copyCompletedScan } from './fixtures.ts';type Scenario = 'schedule' | 'pr' | 'policy-pr' | 'empty-pr';+const inputNames = Object.keys(parse(await readFile(new URL('../../action.yml', import.meta.url), 'utf8')).inputs);const inputKey = (name: string): string => `INPUT_${name.toUpperCase()}`;function assertAttribution(args: readonly string[], provider: string): void {@@ -69,7 +70,7 @@ async function harness(t: TestContext, scenario: Scenario = 'schedule', serverUrprocess.exitCode = previousExitCode;await rm(root, { recursive: true, force: true });});- for (const name of INPUT_NAMES) delete process.env[inputKey(name)];+ for (const name of inputNames) delete process.env[inputKey(name)];const eventPath = join(root, 'event.json');const outputPath = join(root, 'outputs');const statePath = join(root, 'state');