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
fix(multiscan): surface run warnings in campaign summaries (#1172)
Anirudh N Shandilya9c3df087ed16
diff --git a/sdk/typescript/src/multiscan.ts b/sdk/typescript/src/multiscan.tsindex f1c39d809..b813bca13 100644--- a/sdk/typescript/src/multiscan.ts+++ b/sdk/typescript/src/multiscan.ts@@ -71,6 +71,7 @@ interface MultiscanReceipt extends MultiscanTask {cost?: ScanCost;error?: string;warning?: string;+ warnings?: string[];policyFailed?: boolean;}@@ -113,6 +114,7 @@ export interface MultiscanResult {failed: number;skipped: number;resultsPath: string;+ warnings?: { repository: string; warnings: string[] }[];policyFailed?: boolean;}@@ -221,6 +223,7 @@ async function runCampaign(let completed = 0;let incomplete = 0;let policyFailed = false;+ const warnings: NonNullable<MultiscanResult["warnings"]> = [];const hasPolicy = Object.values(options.scanOptionsByMode ?? {}).some((settings) => settings.failureSeverity !== undefined,);@@ -258,6 +261,17 @@ async function runCampaign(receipt.outputDir === selectedArtifactOutput) &&(await hasArtifacts(artifactOutput))) {+ if (receipt.status !== "failed" && receipt.warnings?.length) {+ warnings.push({ repository: task.id, warnings: receipt.warnings });+ for (const warning of receipt.warnings) {+ notifyProgress(options, {+ repository: task.id,+ status: receipt.status,+ attempt: receipt.attempt,+ warning,+ });+ }+ }if (receipt.status === "completed") {policyFailed ||= receipt.policyFailed === true;completed += 1;@@ -295,6 +309,7 @@ async function runCampaign(failed: 0,skipped,resultsPath: ledger,+ ...(warnings.length === 0 ? {} : { warnings }),...(hasPolicy ? { policyFailed } : {}),};}@@ -326,6 +341,7 @@ async function runCampaign(let attemptedResume = false;let failure: string | undefined;let warning: string | undefined;+ const runWarnings: string[] = [];let attemptPolicyFailed: boolean | undefined;let coverage: CoverageDocument["completeness"] | undefined;let cost: Readonly<ScanCost> | null = null;@@ -430,13 +446,15 @@ async function runCampaign(...(options.maxCostUsd === undefined? {}: { maxCostUsd: options.maxCostUsd }),- onWarning: (warning) =>+ onWarning: (warning) => {+ runWarnings.push(warning);notifyProgress(options, {repository: task.id,attempt,status: "started",warning,- }),+ });+ },...(options.signal === undefined? {}: { signal: options.signal }),@@ -498,6 +516,7 @@ async function runCampaign(...(cost === null ? {} : { cost }),...(failure === undefined ? {} : { error: failure }),...(warning === undefined ? {} : { warning }),+ ...(runWarnings.length === 0 ? {} : { warnings: runWarnings }),...(attemptPolicyFailed === undefined? {}: { policyFailed: attemptPolicyFailed }),@@ -519,6 +538,9 @@ async function runCampaign(});if (failure === undefined) {policyFailed ||= attemptPolicyFailed === true;+ if (runWarnings.length > 0) {+ warnings.push({ repository: task.id, warnings: runWarnings });+ }if (warning === undefined) completed += 1;else incomplete += 1;break;@@ -553,6 +575,7 @@ async function runCampaign(failed,skipped,resultsPath: ledger,+ ...(warnings.length === 0 ? {} : { warnings }),...(hasPolicy ? { policyFailed } : {}),};}diff --git a/sdk/typescript/tests-ts/multiscan.test.ts b/sdk/typescript/tests-ts/multiscan.test.tsindex 43f83c6a4..c2048f215 100644--- a/sdk/typescript/tests-ts/multiscan.test.ts+++ b/sdk/typescript/tests-ts/multiscan.test.ts@@ -898,24 +898,66 @@ describe("multiscan", () => {NonNullable<MultiscanOptions["onProgress"]>>[0][] = [];+ const warnings = [+ "Could not run post-scan instructions.",+ "Repository changed during the scan.",+ ];const summary = await runMultiscan(options(paths,client(async (_repository, scanOptions = {}) => {- scanOptions.onWarning?.("Could not run post-scan instructions.");+ for (const warning of warnings) scanOptions.onWarning?.(warning);return await completedScan(scanOptions.outputDir!);}),{ onProgress: (event) => progress.push(event) },),);- expect(summary).toMatchObject({ completed: 1, incomplete: 0, failed: 0 });+ expect(summary).toMatchObject({+ completed: 1,+ incomplete: 0,+ failed: 0,+ warnings: [+ {+ repository: "follow-up-warning",+ warnings,+ },+ ],+ });expect(progress).toContainEqual({repository: "follow-up-warning",attempt: 1,status: "started",warning: "Could not run post-scan instructions.",});+ expect(await results(summary.resultsPath)).toMatchObject([+ {+ id: "follow-up-warning",+ status: "completed",+ warnings,+ },+ ]);++ const resumedProgress: typeof progress = [];+ const resumed = await runMultiscan(+ options(+ paths,+ client(async () => Promise.reject(new Error("must not rerun"))),+ {+ onProgress: (event) => resumedProgress.push(event),+ },+ ),+ );++ expect(resumed).toEqual({ ...summary, skipped: 1 });+ for (const warning of warnings) {+ expect(resumedProgress).toContainEqual({+ repository: "follow-up-warning",+ attempt: 1,+ status: "completed",+ warning,+ });+ }});test.each([false, true])(@@ -1924,6 +1966,7 @@ describe("multiscan", () => {expect(scanOptions.knowledgeBasePaths).toEqual(knowledgeBasePaths);attempts += 1;if (attempts === 1) {+ scanOptions.onWarning?.("Warning from the failed attempt.");throw new Error(failure);}return await completedScan(scanOptions.outputDir!);@@ -1934,8 +1977,15 @@ describe("multiscan", () => {expect(attempts).toBe(2);expect(summary).toMatchObject({ completed: 1, failed: 0 });+ expect(summary).not.toHaveProperty("warnings");expect(await results(summary.resultsPath)).toMatchObject([- { id: "retry", status: "failed", attempt: 1, error: failure },+ {+ id: "retry",+ status: "failed",+ attempt: 1,+ error: failure,+ warnings: ["Warning from the failed attempt."],+ },{ id: "retry", status: "completed", attempt: 2 },]);});