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): hide session log hints for mock scans (#2488)

Michael D'Angelo2d9e2dbd7286
diff --git a/sdk/typescript/docs/cli.md b/sdk/typescript/docs/cli.md
index 00593bd00..e3bff1e2e 100644
--- a/sdk/typescript/docs/cli.md
+++ b/sdk/typescript/docs/cli.md
@@ -761,7 +761,8 @@ runs, four with new identities, and two duplicate pairs for testing deduplicatio
Paths and snippets are fictional; repository files remain unchanged.
Use a separate `CODEX_SECURITY_STATE_DIR` for disposable data. Output, exports,
-archiving, and severity thresholds work normally. Reruns preserve mock mode.
+archiving, and severity thresholds work normally. Use `scans show` to inspect a
+mock scan. Mock scans have no Codex session logs. Reruns preserve mock mode.
Separate matching or deduplication commands still make their usual model calls.
Mock mode supports Standard repository, path, and diff scans. It cannot combine
diff --git a/sdk/typescript/src/cli.ts b/sdk/typescript/src/cli.ts
index e2f1dfe73..d1066954e 100644
--- a/sdk/typescript/src/cli.ts
+++ b/sdk/typescript/src/cli.ts
@@ -2577,14 +2577,23 @@ export async function main(
return result;
};
const showHistoryNavigation = async (
- scan: JsonObject,
+ scan: ScanLogSource,
format: string,
selection?: string,
): Promise<void> => {
if (!useDefaultOutput(format)) return;
await withTerminalErrorsHandled(errorOutput, async () => {
try {
- printScanReference(scan, errorOutput, selection);
+ printScanReference(
+ scan,
+ errorOutput,
+ Boolean(
+ scan.continuationThreadId ||
+ scan.threadIds?.length ||
+ scan.executionThreadIds?.length,
+ ),
+ selection,
+ );
} catch {
// Optional navigation must not prevent reading saved results or logs.
}
@@ -2837,7 +2846,7 @@ export async function main(
await history(["get-scan", "--scan-id", scanId], async (value) => {
const { scan, recipe, parentScanId } = value;
await showHistoryNavigation(
- scan as JsonObject,
+ scan as ScanLogSource,
format,
args.scanId === undefined ? "latest completed scan" : undefined,
);
@@ -11808,6 +11817,7 @@ async function readDeepScanStop(
function printScanReference(
scan: JsonObject,
output: Writable,
+ showLogs: boolean,
selection?: string,
): void {
const scanId = scan["scanId"];
@@ -11832,7 +11842,7 @@ function printScanReference(
`\n${detail.join(" · ")}\n` +
(selection === undefined ? "" : `Selected ${selection}.\n`) +
`Inspect: codex-security scans show ${argument}\n` +
- `Logs: codex-security scans logs ${argument}\n`,
+ (showLogs ? `Logs: codex-security scans logs ${argument}\n` : ""),
);
}
@@ -11844,7 +11854,7 @@ function printFailedScanReference(
): void {
if (scan === undefined) return;
try {
- printScanReference(scan, output);
+ printScanReference(scan, output, !arguments_.mock);
if (phase !== null)
output.write(`Last observed phase: ${diagnosticValue(phase)}\n`);
output.write(
@@ -11956,6 +11966,7 @@ function printScanSummary(
startedAt: result.manifest.scan.startedAt,
},
errorOutput,
+ result.manifest.scan.scope.runtimeStatus !== "mock",
);
if (deepScanStop?.nextStep !== undefined) {
errorOutput.write(`\n ${deepScanStop.nextStep}\n`);
diff --git a/sdk/typescript/tests-ts/cli-scan-navigation.test.ts b/sdk/typescript/tests-ts/cli-scan-navigation.test.ts
index 750ea88af..2c21dc3c2 100644
--- a/sdk/typescript/tests-ts/cli-scan-navigation.test.ts
+++ b/sdk/typescript/tests-ts/cli-scan-navigation.test.ts
@@ -2,6 +2,7 @@ import { mkdir, rm, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { describe, expect, test } from "bun:test";
import { main } from "../src/cli.js";
+import { ScanResult } from "../src/result.js";
import type { JsonObject } from "../src/config.js";
import { dependencies, fakeResult } from "./cli-fixtures.js";
import { createCliTest } from "./support/cli-run.js";
@@ -81,7 +82,7 @@ describe("scan navigation", () => {
expect(show.stderr.text()).toContain(
`updated ${completed.updatedAt}`,
);
- expect(show.stderr.text()).toContain(`scans logs ${completedId}`);
+ expect(show.stderr.text()).not.toContain(`scans logs ${completedId}`);
expect(show.stderr.text()).not.toContain(latestId);
const logs = createCliTest(main, { stdout: interactive });
@@ -129,7 +130,7 @@ describe("scan navigation", () => {
});
test("completion navigation uses the complete scan ID without changing JSON", async () => {
- const result = fakeResult(["high"]);
+ const result = new ScanResult({ ...fakeResult(["high"]), threadId: "" });
result.manifest.scan.id = completedId;
const cli = createCliTest(main);
expect(await cli.runCli(["scan", "--json"], dependencies({ result }))).toBe(
@@ -145,6 +146,19 @@ describe("scan navigation", () => {
expect(cli.stderr.text()).toContain(result.scanDir);
});
+ test("mock scan completion points to its saved result without offering session logs", async () => {
+ const result = new ScanResult({ ...fakeResult(), threadId: "" });
+ result.manifest.scan.scope.runtimeStatus = "mock";
+ const cli = createCliTest(main);
+ expect(await cli.runCli(["scan", "--mock"], dependencies({ result }))).toBe(
+ 0,
+ );
+ expect(cli.stderr.text()).toContain(
+ `scans show ${result.manifest.scan.id}`,
+ );
+ expect(cli.stderr.text()).not.toContain("scans logs");
+ });
+
test.each([false, true])(
"identifies only the registered scan without a history lookup (custom prompts: %p)",
async (customPrompts) => {