Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions sdk/typescript/src/multiscan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ interface MultiscanReceipt extends MultiscanTask {
cost?: ScanCost;
error?: string;
warning?: string;
warnings?: string[];
}

export interface MultiscanOptions {
Expand Down Expand Up @@ -166,6 +167,16 @@ async function runCampaign(
receipt.outputDir === selectedArtifactOutput) &&
(await hasArtifacts(artifactOutput))
) {
if (receipt.status !== "failed") {
for (const warning of receipt.warnings ?? []) {
notifyProgress(options, {
repository: task.id,
status: receipt.status,
attempt: receipt.attempt,
warning,
});
}
}
if (receipt.status === "completed") {
completed += 1;
continue;
Expand Down Expand Up @@ -228,6 +239,7 @@ async function runCampaign(
notifyProgress(options, { ...progress, status: "started" });
let failure: string | undefined;
let warning: string | undefined;
const runWarnings: string[] = [];
let coverage: CoverageDocument["completeness"] | undefined;
let cost: Readonly<ScanCost> | null = null;
let exhaustedBudget = false;
Expand Down Expand Up @@ -272,12 +284,14 @@ async function runCampaign(
...(options.maxCostUsd === undefined
? {}
: { maxCostUsd: options.maxCostUsd }),
onWarning: (warning) =>
onWarning: (warning) => {
runWarnings.push(warning);
notifyProgress(options, {
...progress,
status: "started",
warning,
}),
});
},
...(options.signal === undefined ? {} : { signal: options.signal }),
});
cost = result.cost;
Expand Down Expand Up @@ -317,6 +331,7 @@ async function runCampaign(
...(cost === null ? {} : { cost }),
...(failure === undefined ? {} : { error: failure }),
...(warning === undefined ? {} : { warning }),
...(runWarnings.length === 0 ? {} : { warnings: runWarnings }),
})}\n`,
);
notifyProgress(options, {
Expand Down
40 changes: 40 additions & 0 deletions sdk/typescript/tests-ts/multiscan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ describe("multiscan", () => {
paths,
client(async (_repository, scanOptions = {}) => {
scanOptions.onWarning?.("Could not run post-scan instructions.");
scanOptions.onWarning?.("Repository changed during the scan.");
return await completedScan(scanOptions.outputDir!);
}),
{ onProgress: (event) => progress.push(event) },
Expand All @@ -382,6 +383,45 @@ describe("multiscan", () => {
status: "started",
warning: "Could not run post-scan instructions.",
});
expect(await results(summary.resultsPath)).toMatchObject([
{
id: "follow-up-warning",
status: "completed",
warnings: [
"Could not run post-scan instructions.",
"Repository changed during the scan.",
],
},
]);

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).toMatchObject({ completed: 1, skipped: 1, failed: 0 });
expect(resumedProgress).toEqual(
expect.arrayContaining([
{
repository: "follow-up-warning",
attempt: 1,
status: "completed",
warning: "Could not run post-scan instructions.",
},
{
repository: "follow-up-warning",
attempt: 1,
status: "completed",
warning: "Repository changed during the scan.",
},
]),
);
});

test.each([false, true])(
Expand Down