refactor(captures)!: require canonical producer metadata
Require process retention accounting, browser network transaction identity, and all web comparison dimensions. Remove obsolete omission repairs and derive completeness from the owning producer facts. BREAKING CHANGE: Historical captures without current producer accounting or transaction identity, and web diffs missing accessibility or storage dimensions, are rejected.
This commit is contained in:
@@ -34,12 +34,12 @@ const indexResponses = (
|
||||
requests: new Map(),
|
||||
};
|
||||
for (const event of events) {
|
||||
if (event.kind === "request" && event.transaction_id !== undefined)
|
||||
if (event.kind === "request")
|
||||
index.requests.set(
|
||||
event.transaction_id,
|
||||
(index.requests.get(event.transaction_id) ?? 0) + 1,
|
||||
);
|
||||
if (event.kind === "response" && event.transaction_id !== undefined)
|
||||
if (event.kind === "response")
|
||||
append(index.responses, event.transaction_id, event);
|
||||
if (event.kind === "network-content" && event.phase === "response")
|
||||
append(index.contents, event.source_event_sequence, event);
|
||||
@@ -52,25 +52,23 @@ const projectRequest = (
|
||||
index: ResponseIndex,
|
||||
): CapturedWebScript => {
|
||||
const id = request.transaction_id;
|
||||
const matches = id === undefined ? [] : (index.responses.get(id) ?? []);
|
||||
const matches = index.responses.get(id) ?? [];
|
||||
const response = matches.length === 1 ? matches[0] : undefined;
|
||||
const bodies =
|
||||
response === undefined ? [] : (index.contents.get(response.sequence) ?? []);
|
||||
const body = bodies.length === 1 ? bodies[0]?.body : undefined;
|
||||
const ambiguous =
|
||||
(id !== undefined && index.requests.get(id) !== 1) ||
|
||||
matches.length > 1 ||
|
||||
bodies.length > 1;
|
||||
index.requests.get(id) !== 1 || matches.length > 1 || bodies.length > 1;
|
||||
return {
|
||||
source: {
|
||||
kind: "scenario-response",
|
||||
transaction_id: id ?? null,
|
||||
transaction_id: id,
|
||||
request_sequence: request.sequence,
|
||||
response_sequence: ambiguous ? null : (response?.sequence ?? null),
|
||||
status: ambiguous ? null : (response?.status ?? null),
|
||||
},
|
||||
url: request.url.url,
|
||||
content: projectBody(body, id, ambiguous),
|
||||
content: projectBody(body, ambiguous),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -81,7 +79,6 @@ const unavailable = (
|
||||
|
||||
const projectBody = (
|
||||
body: BrowserNetworkBody | undefined,
|
||||
transactionId: string | undefined,
|
||||
ambiguous: boolean,
|
||||
): CapturedWebScript["content"] => {
|
||||
if (ambiguous)
|
||||
@@ -91,9 +88,7 @@ const projectBody = (
|
||||
);
|
||||
if (body === undefined)
|
||||
return unavailable(
|
||||
transactionId === undefined
|
||||
? "transaction-identity-unavailable"
|
||||
: "response-content-not-retained",
|
||||
"response-content-not-retained",
|
||||
"No selected, completed script response bytes were retained for this request.",
|
||||
);
|
||||
if (body.state === "unavailable")
|
||||
|
||||
@@ -164,21 +164,39 @@ describe("script capture identity and response projection", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("does not join legacy metadata by URL when transaction identity is absent", () => {
|
||||
it("rejects captures without explicit transaction identity metadata", () => {
|
||||
const capture = scriptScenarioFixture();
|
||||
capture.events.items = capture.events.items.filter(
|
||||
({ kind }) => kind !== "network-content",
|
||||
);
|
||||
for (const event of capture.events.items)
|
||||
if (event.kind === "request" || event.kind === "response")
|
||||
delete event.transaction_id;
|
||||
capture.events.retained = capture.events.items.length;
|
||||
expect(selectScriptCapture(capture).scripts[0]).toMatchObject({
|
||||
source: { transaction_id: null },
|
||||
content: {
|
||||
state: "unavailable",
|
||||
reason: "transaction-identity-unavailable",
|
||||
const request = capture.events.items.find(({ kind }) => kind === "request");
|
||||
if (request?.kind !== "request") throw new Error("Missing request");
|
||||
const { transaction_id: _transactionId, ...requestWithoutId } = request;
|
||||
const withoutTransactionId: unknown = {
|
||||
...capture,
|
||||
events: {
|
||||
...capture.events,
|
||||
items: capture.events.items.map((event) =>
|
||||
event === request ? requestWithoutId : event,
|
||||
),
|
||||
},
|
||||
});
|
||||
};
|
||||
expect(() => selectScriptCapture(withoutTransactionId)).toThrow(
|
||||
"Expected a valid",
|
||||
);
|
||||
|
||||
const {
|
||||
redirected_from_transaction_id: _redirect,
|
||||
...requestWithoutRedirect
|
||||
} = request;
|
||||
const withoutRedirectMetadata: unknown = {
|
||||
...capture,
|
||||
events: {
|
||||
...capture.events,
|
||||
items: capture.events.items.map((event) =>
|
||||
event === request ? requestWithoutRedirect : event,
|
||||
),
|
||||
},
|
||||
};
|
||||
expect(() => selectScriptCapture(withoutRedirectMetadata)).toThrow(
|
||||
"Expected a valid",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user