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

fix(cli): enforce CSV stdout rules for accepted format aliases (#1825)

Michael D'Angeloa9fb64983020
diff --git a/sdk/typescript/src/cli.ts b/sdk/typescript/src/cli.ts
index 455673525..b640cf071 100644
--- a/sdk/typescript/src/cli.ts
+++ b/sdk/typescript/src/cli.ts
@@ -6121,7 +6121,9 @@ export async function main(
argv.some(
(value, index) =>
value === "--export-format=csv" ||
- (value === "--export-format" && argv[index + 1] === "csv"),
+ value === "--exportFormat=csv" ||
+ ((value === "--export-format" || value === "--exportFormat") &&
+ argv[index + 1] === "csv"),
)
) {
return "CSV stdout cannot be combined with JSON output; write CSV to a file or omit --json.";
diff --git a/sdk/typescript/tests-ts/cli.test.ts b/sdk/typescript/tests-ts/cli.test.ts
index af7d7c8a6..b92046f93 100644
--- a/sdk/typescript/tests-ts/cli.test.ts
+++ b/sdk/typescript/tests-ts/cli.test.ts
@@ -2481,23 +2481,37 @@ describe("CLI", () => {
});
test("rejects CSV stdout when JSON output is requested", async () => {
- const exportFindings = mock(resolving(new Uint8Array()));
- const { stdout, stderr, runCli } = createCliTest(main);
-
- const deps = dependencies();
- deps.exportFindings = exportFindings;
+ for (const exportFormat of [
+ ["--export-format", "csv"],
+ ["--export-format=csv"],
+ ["--exportFormat", "csv"],
+ ["--exportFormat=csv"],
+ ]) {
+ for (const format of [
+ ["--json"],
+ ["--format", "json"],
+ ["--format=json"],
+ ["--format", "jsonl"],
+ ["--format=jsonl"],
+ ]) {
+ const exportFindings = mock(resolving(new Uint8Array()));
+ const { stdout, stderr, runCli } = createCliTest(main);
+ const deps = dependencies();
+ deps.exportFindings = exportFindings;
- expect(
- await runCli(
- ["export", "scan", "--export-format", "csv", "--output", "-", "--json"],
- deps,
- ),
- ).toBe(2);
- expect(exportFindings).not.toHaveBeenCalled();
- expect(stdout.text()).toBe("");
- expect(stderr.text()).toContain(
- "CSV stdout cannot be combined with JSON output",
- );
+ expect(
+ await runCli(
+ ["export", "scan", ...exportFormat, "--output", "-", ...format],
+ deps,
+ ),
+ ).toBe(2);
+ expect(exportFindings).not.toHaveBeenCalled();
+ expect(stdout.text()).toBe("");
+ expect(stderr.text()).toContain(
+ "CSV stdout cannot be combined with JSON output",
+ );
+ }
+ }
});
test("prints export help without initializing Codex", async () => {