fix(captures): scope HAR HTTP interpretation to entries (#4351)

* fix(captures): scope HAR HTTP interpretation to entries

* test(snapshot): preserve Evidence-scoped native workflow unknowns

* test(process): assert owned snapshot cancellation outcomes

* test(process): preserve snapshot race causes and owned cleanup

* test(cli): scope runtime cleanup provider injection

CLI boundary tests share a module graph. The cleanup fixture's module mock
cannot replace a provider factory already captured by the real command
registration, leaving its close count at zero after another test imports it.

Inject a typed provider factory into the registration instance, defaulting
to the existing production factory. Both commands still create their own
provider at execution time. Remove the redundant runtime context wrapper
and the global mock state. Keep the real child CLI parity case and verify
that neither command completion nor JSON output precedes awaited cleanup;
retain the close-count, cleanup error and completed Evidence assertions.

The unchanged test passes alone but fails with the command module preloaded.
Both modes pass after the correction. Seven related files pass 28 tests;
check and docs:check also pass on Node24.18.0/npm11.16.0 macOS arm64.

* test(artifacts): use valid ASAR bytes for signature control

* test(mcp): isolate snapshot filesystem fault injection

* test(process): distinguish unacquired resources in failure progress

* chore: restore main's copies of files the merge hook reformatted

The pre-commit oxlint --fix touched two files this PR does not change; keep them identical to main.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Kaoru0822 <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
authored and GitHub committed 2026-10-23 02:30:06 +08:00
1 parent 1684c73d4f
commit b4bc6cf3ee
5 files changed
+177 -10

No files matched your search

+62 -1
View File
@@ -1,9 +1,70 @@
import { createHash } from "node:crypto";
import { expect, it } from "vitest";
import { historicalHar } from "../../../tests/fixtures/historicalHar.js";
import {
historicalHar,
harWithContainerLookalikes,
} from "../../../tests/fixtures/historicalHar.js";
import { decodeCaptureText } from "./CaptureJson.js";
import { decodeHarCapture } from "./HarCapture.js";
it("interprets HTTP fields only within HAR entries, preserving document lookalikes", () => {
const fixture = harWithContainerLookalikes();
const decoded = decodeHarCapture(JSON.stringify(fixture), []);
expect(decoded.container.reported).toMatchObject({
request: fixture.request,
response: fixture.response,
});
expect(decoded.container.redactions).toEqual([]);
expect(decoded.records[0]).toMatchObject({
reported: {
request: {
url: "https://example.test/opaque",
headers: [{ name: "Authorization", value: null }],
cookies: [{ name: "session", value: null }],
},
response: {
redirectURL: "https://example.test/redirect",
headers: [{ name: "Set-Cookie", value: null }],
},
},
binary_fields: [
{ pointer: "/response/content/text", content_base64: "QUJD", bytes: 3 },
],
});
const marked = decodeHarCapture(JSON.stringify(fixture), [
"ordinary-root-evidence",
]);
expect(marked.container.reported).toMatchObject({
request: {
headers: [{ value: null }],
cookies: [{ value: null }],
},
response: { headers: [{ value: null }], content: { text: null } },
});
expect(marked.container.redactions).toHaveLength(4);
expect(
marked.container.redactions.every(
({ reason }) => reason === "explicit-sensitive-value",
),
).toBe(true);
});
it("does not decode container lookalikes when excluding explicitly sensitive body bytes", () => {
const fixture = harWithContainerLookalikes();
fixture.response.content.text = "QUJD";
const decoded = decodeHarCapture(JSON.stringify(fixture), ["ABC"]);
expect(decoded.container.reported).toMatchObject({
response: { content: { text: "QUJD" } },
});
expect(decoded.container.redactions).toEqual([]);
expect(decoded.records[0]).toMatchObject({
reported: { response: { content: { text: null } } },
binary_fields: [
{ state: "redacted", content_base64: null, bytes: null, sha256: null },
],
});
});
it.each([
{ values: [] },
{ values: ["response"] },
+9 -8
View File
@@ -32,7 +32,7 @@ export const decodeHarCapture = (
sensitiveValues: readonly string[],
): DecodedCapture => {
const raw = parseCaptureJson(text, "HAR");
const validation = projectHar(raw, [], false);
const validation = projectHar(raw, [], "validation");
const adaptedPlaywrightEntries = new Set(
createHarValidator()(validation.reported),
);
@@ -55,11 +55,11 @@ export const decodeHarCapture = (
const container = projectHar(
{ ...raw, log: { ...raw.log, entries: null } },
sensitiveValues,
true,
"container",
);
const records = entries.map((entry, ordinal): WebNetworkCaptureRecord => {
// Validate each original record even when a structural ancestor excludes it.
const projected = projectHar(entry, sensitiveValues, true);
const projected = projectHar(entry, sensitiveValues, "entry");
const projection: Projection = recordsExcluded
? {
reported: null,
@@ -102,12 +102,13 @@ export const decodeHarCapture = (
};
};
/** Evidence projection when `redact` is true; the upstream schema validation copy otherwise. */
/** Relative HTTP paths belong only to entries, never similarly named container extensions. */
const projectHar = (
value: unknown,
sensitiveValues: readonly string[],
redact: boolean,
scope: "validation" | "container" | "entry",
): Projection => {
const redact = scope !== "validation";
const redactor = new CaptureRedaction(sensitiveValues);
const numeric_literals: Projection["numeric_literals"] = [];
const binary_fields: Projection["binary_fields"] = [];
@@ -136,7 +137,7 @@ const projectHar = (
pointer,
);
if (
redact &&
scope === "entry" &&
parent !== undefined &&
redactor.harCredential(pointer, parent)
)
@@ -144,7 +145,7 @@ const projectHar = (
if (item instanceof LosslessNumber) return projectNumber(item, pointer);
if (typeof item === "string") {
if (
redact &&
scope === "entry" &&
pointer === "/response/content/text" &&
parent?.encoding === "base64"
) {
@@ -191,7 +192,7 @@ const projectHar = (
? redactor.text(
item,
pointer,
redactor.harTransportUrl(pointer, parent),
scope === "entry" && redactor.harTransportUrl(pointer, parent),
)
: item;
}