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.
This commit is contained in:
Adolanium
2026-10-25 07:46:26 +02:00
committed by GitHub
parent 06a4c338fc
commit 4973ce7202
2 changed files with 40 additions and 6 deletions
@@ -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";
+15 -6
View File
@@ -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({