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): use the singular for one finding in import prompts (#2345)

wj443fe962ca65
diff --git a/sdk/typescript/src/cli.ts b/sdk/typescript/src/cli.ts
index 0570f19cb..fd518dcc3 100644
--- a/sdk/typescript/src/cli.ts
+++ b/sdk/typescript/src/cli.ts
@@ -647,6 +647,10 @@ function publicationDestination(
};
}
+function formatItemCount(count: number, singular: string): string {
+ return count === 1 ? `1 ${singular}` : `${count} ${singular}s`;
+}
+
function publicationScanAge(timestamp: string, now: number): string {
const completedAt = Date.parse(timestamp);
if (!Number.isFinite(completedAt)) return "unknown";
@@ -848,7 +852,7 @@ class PublicationProgressPresenter {
this.#dashboard.setStage(`Publishing findings · 0/${event.total}`);
} else {
this.#write(
- `Publishing ${event.total} finding${event.total === 1 ? "" : "s"} to Linear.`,
+ `Publishing ${formatItemCount(event.total, "finding")} to Linear.`,
);
}
return;
@@ -917,7 +921,7 @@ class PublicationProgressPresenter {
return;
}
- const summary = `Published ${event.created}/${event.total} finding${event.total === 1 ? "" : "s"}${event.failed === 0 ? "" : ` (${event.failed} failed)`}.`;
+ const summary = `Published ${event.created}/${formatItemCount(event.total, "finding")}${event.failed === 0 ? "" : ` (${event.failed} failed)`}.`;
if (this.#dashboard !== null) {
this.#dashboard.setPublicationProgress(
event.created + event.failed,
@@ -989,7 +993,7 @@ class FindingProgressPresenter {
}
this.#write(
- `Verifying ${this.#total} finding${this.#total === 1 ? "" : "s"} against the current checkout.`,
+ `Verifying ${formatItemCount(this.#total, "finding")} against the current checkout.`,
);
}
@@ -3553,7 +3557,7 @@ export async function main(
const findingCount = scan["findingCount"];
const findings =
typeof findingCount === "number"
- ? `${findingCount} finding${findingCount === 1 ? "" : "s"}`
+ ? formatItemCount(findingCount, "finding")
: "unknown findings";
const shortScanId = `...${stripVTControlCharacters(scanId)
.replaceAll(/[\u0000-\u001F\u007F-\u009F]/gu, " ")
@@ -3931,14 +3935,16 @@ export async function main(
`${local ? "Local import" : "Publication"} needs confirmation. Run --dry-run, review the results, then use --yes to approve this input.`,
);
if (structured) showPreview();
- const action = local
- ? `Store these ${preview.findings.length} findings locally`
- : `Publish these ${preview.findings.length} findings`;
- return prompt.confirm(
- `${action}${preview.excluded.length ? ` and skip ${preview.excluded.length} excluded records` : ""}?`,
- false,
- controller.signal,
- );
+ const count = preview.findings.length;
+ const findings =
+ count === 1 ? "this finding" : `these ${count} findings`;
+ let action = local
+ ? `Store ${findings} locally`
+ : `Publish ${findings}`;
+ const excluded = preview.excluded.length;
+ if (excluded)
+ action += ` and skip ${formatItemCount(excluded, "excluded record")}`;
+ return prompt.confirm(`${action}?`, false, controller.signal);
};
const showScannerReport = (preview: ExternalFindings) => {
if (options.provider !== "opengrep") return;
@@ -7969,7 +7975,7 @@ async function runScanImport(
if ("dryRun" in result) return { exitCode: 0, data: { ...result } };
try {
errorOutput.write(
- `Imported ${result.findings.findings.length} findings as scan ${result.manifest.scan.id}.\n` +
+ `Imported ${formatItemCount(result.findings.findings.length, "finding")} as scan ${result.manifest.scan.id}.\n` +
`Artifacts: ${result.scanDir}\n`,
);
} catch {}
@@ -9136,7 +9142,7 @@ async function runFindingPatches(
}
stderr.write(
- `\nPatching ${selected.findings.length} confirmed finding${selected.findings.length === 1 ? "" : "s"}...\n`,
+ `\nPatching ${formatItemCount(selected.findings.length, "confirmed finding")}...\n`,
);
const patches: FindingPatch[] = [];
for (const finding of selected.findings) {
diff --git a/sdk/typescript/tests-ts/cli-local-import.test.ts b/sdk/typescript/tests-ts/cli-local-import.test.ts
index 1ebc0fe98..295d7a5a7 100644
--- a/sdk/typescript/tests-ts/cli-local-import.test.ts
+++ b/sdk/typescript/tests-ts/cli-local-import.test.ts
@@ -187,7 +187,7 @@ test("local preview and declined confirmation do not create database state or us
externalPublicationPrompt: {
isInteractive: () => true,
confirm: async (question, defaultValue) => {
- expect(question).toContain("Store these 1 findings locally");
+ expect(question).toBe("Store this finding locally?");
expect(defaultValue).toBe(false);
expect(declined.stderr.text()).toContain(f.repository);
expect(declined.stderr.text()).toContain(f.record.id);
@@ -415,7 +415,9 @@ test("local import confirms exclusions and returns partial status after storing
externalPublicationPrompt: {
isInteractive: () => true,
confirm: async (question) => {
- expect(question).toContain("skip 1 excluded records");
+ expect(question).toBe(
+ "Store this finding locally and skip 1 excluded record?",
+ );
expect(cli.stderr.text()).toContain("Excluded: 1");
return true;
},
diff --git a/sdk/typescript/tests-ts/cli-scan-import.test.ts b/sdk/typescript/tests-ts/cli-scan-import.test.ts
index 79ca6d94b..bca609337 100644
--- a/sdk/typescript/tests-ts/cli-scan-import.test.ts
+++ b/sdk/typescript/tests-ts/cli-scan-import.test.ts
@@ -12,7 +12,7 @@ import {
import { rejecting, throwing } from "./support/errors.js";
import { createCliTest, captureCli } from "./support/cli-run.js";
-function importDependencies() {
+function importDependencies(result = fakeResult(["high", "high"])) {
const deps = dependencies({
currentDirectory: resolve("workspace"),
onConfig: throwing("Import must not create a model client"),
@@ -26,11 +26,11 @@ function importDependencies() {
dryRun: true,
inputPath: options.sourcePath,
format: options.format,
- findingCount: 2,
+ findingCount: result.findings.findings.length,
}
- : fakeResult(["high", "high"]);
+ : result;
};
- return { deps, calls };
+ return { deps, calls, result };
}
describe("scan import", () => {
@@ -150,7 +150,7 @@ describe("scan import", () => {
test.each(["csv", "json"] as const)(
"imports --%s while --format json controls output",
async (format) => {
- const { deps, calls } = importDependencies();
+ const { deps, calls, result } = importDependencies();
const { stdout, stderr, runCli } = createCliTest(main);
expect(
@@ -179,13 +179,8 @@ describe("scan import", () => {
signal: expect.any(AbortSignal),
});
expect(JSON.parse(stdout.text())).toMatchObject({
- manifest: { scan: { id: "scan" } },
- findings: {
- findings: [
- { severity: { level: "high" } },
- { severity: { level: "high" } },
- ],
- },
+ manifest: result.manifest,
+ findings: result.findings,
});
expect(stderr.text()).toContain("Imported 2 findings as scan scan.");
},
@@ -217,15 +212,15 @@ describe("scan import", () => {
expect(stderr.text()).toBe("");
});
- test("uses a concise summary for default output", async () => {
- const { deps } = importDependencies();
+ test("uses a concise singular summary for one imported finding", async () => {
+ const { deps } = importDependencies(fakeResult(["high"]));
const { stdout, stderr, runCli } = createCliTest(main);
expect(
await runCli(["scan", "import", "--json", "findings.json"], deps),
).toBe(0);
expect(stdout.text()).toBe("");
- expect(stderr.text()).toContain("Imported 2 findings as scan scan.");
+ expect(stderr.text()).toContain("Imported 1 finding as scan scan.");
});
test.each([
diff --git a/sdk/typescript/tests-ts/external-findings-publish.test.ts b/sdk/typescript/tests-ts/external-findings-publish.test.ts
index 26bf51209..f0d482c29 100644
--- a/sdk/typescript/tests-ts/external-findings-publish.test.ts
+++ b/sdk/typescript/tests-ts/external-findings-publish.test.ts
@@ -5338,7 +5338,9 @@ test.each(["human", "json"])(
expect(cli.stderr.text()).toContain("synthetic-account");
expect(cli.stderr.text()).toContain("environment-example");
expect(cli.stderr.text()).toContain("Excluded: 1");
- expect(question).toContain("skip 1 excluded");
+ expect(question).toBe(
+ "Publish this finding and skip 1 excluded record?",
+ );
expect(cli.stderr.text()).toContain("vendor-selected [high]");
expect(cli.stderr.text()).toContain(f.file);
expect(cli.stderr.text()).toContain("--dry-run --format json");