From 4973ce7202d09c99dff8693600031bef87e48e8e Mon Sep 17 00:00:00 2001 From: Adolanium <94890352+Adolanium@users.noreply.github.com> Date: Sun, 25 Oct 2026 07:46:26 +0200 Subject: [PATCH] fix(capture): report an out-of-range record ordinal as a selection fault (#7067) inspect_web_network_capture reported a record_ordinals entry past the capture's records as an invalid_format issue on record_ordinals, with no bounds. It is now an out_of_range issue on that entry (record_ordinals[i]) with minimum 0 and maximum total_records - 1, or invalid_value when the capture has no records. --- .../WebNetworkCaptureService.test.ts | 25 +++++++++++++++++++ src/application/WebNetworkCaptureService.ts | 21 +++++++++++----- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/application/WebNetworkCaptureService.test.ts b/src/application/WebNetworkCaptureService.test.ts index b629b7ee26..bc9c660572 100644 --- a/src/application/WebNetworkCaptureService.test.ts +++ b/src/application/WebNetworkCaptureService.test.ts @@ -378,6 +378,31 @@ it.each([ if (!result.ok) expect(result.error._tag).toBe("AnalysisInputError"); }); +it("reports an ordinal past the capture's records as an out-of-range selection", async () => { + const report = fixture(); + const result = await new WebNetworkCaptureService({ + inspect: () => Promise.resolve(ok(report)), + }).inspect({ + capture_path: "/capture.har", + format: "har", + record_ordinals: [0, 5], + }); + if (result.ok) throw new Error("expected an out-of-range ordinal"); + expect(projectAnalysisError(result.error)).toMatchObject({ + code: "invalid_request", + details: { + issues: [ + { + path: ["record_ordinals", 1], + reason: "out_of_range", + minimum: 0, + maximum: report.total_records - 1, + }, + ], + }, + }); +}); + it("rejects a port changing the artifact identity or producer ordinal sequence", async () => { const report = fixture(); report.artifact.path = "/different.har"; diff --git a/src/application/WebNetworkCaptureService.ts b/src/application/WebNetworkCaptureService.ts index 8ea9f98e4a..806d9db4e9 100644 --- a/src/application/WebNetworkCaptureService.ts +++ b/src/application/WebNetworkCaptureService.ts @@ -155,16 +155,25 @@ export class WebNetworkCaptureService { const selected = input.record_ordinals ?? value.records.map(({ ordinal }) => ordinal); const records = []; - for (const ordinal of selected) { + for (const [index, ordinal] of selected.entries()) { const record = safeValue.records[ordinal]; + // A selection past the capture's records is a caller range fault. if (record === undefined) return err( new AnalysisInputError(OPERATION, undefined, [ - { - path: ["record_ordinals"], - reason: "invalid_format", - message: `Producer ordinal ${ordinal} is outside the retained capture (${value.total_records} records).`, - }, + value.total_records === 0 + ? { + path: ["record_ordinals", index], + reason: "invalid_value", + message: "The selected capture contains no records.", + } + : { + path: ["record_ordinals", index], + reason: "out_of_range", + minimum: 0, + maximum: value.total_records - 1, + message: `Producer ordinal ${ordinal} is outside the retained capture (${value.total_records} records).`, + }, ]), ); records.push({