perf(artifacts/browser/contracts): binary-search Deno owned ranges, fuse ManagedMemberInspector checks, drop redundant Playwright step re-parse, and use Set in schema projection (#13587)

* perf(artifacts/browser/contracts): binary-search Deno owned ranges, fuse ManagedMemberInspector checks, drop redundant Playwright step re-parse, and use Set in schema projection

* perf(deno): retain bounded Intel trailer membership checks
This commit is contained in:
morluto authored and GitHub committed 2026-11-22 15:45:15 -05:00
1 parent d4f67030f7
commit d328e2852d
5 files changed
+63 -16

No files matched your search

@@ -1121,6 +1121,46 @@ it("keeps a native Intel host whose __DATA segment stores an Intel Deno executab
expect(snapshot.manifest.root_format).not.toBe("deno-standalone");
});
it("ignores embedded Intel sentinels in out-of-order overlapping segments and accepts a trailer at their end", async () => {
const section = buildDenoSection();
const trailer = denoIntelTrailer(section).subarray(-section.length - 24);
const segmentSize = 72;
const header = Buffer.alloc(32 + 3 * segmentSize);
header.writeUInt32LE(0xfeedfacf, 0);
header.writeUInt32LE(0x01000007, 4);
header.writeUInt32LE(2, 12);
header.writeUInt32LE(3, 16);
header.writeUInt32LE(3 * segmentSize, 20);
const start = header.length;
const middle = start + trailer.length;
const end = middle + trailer.length;
const segments = [
[middle, end],
[start, middle],
[start + 1, middle + 1],
] as const;
for (const [index, [from, to]] of segments.entries()) {
const at = 32 + index * segmentSize;
header.writeUInt32LE(0x19, at);
header.writeUInt32LE(segmentSize, at + 4);
header.write("__DATA", at + 8, "ascii");
header.writeBigUInt64LE(BigInt(to - from), at + 32);
header.writeBigUInt64LE(BigInt(from), at + 40);
header.writeBigUInt64LE(BigInt(to - from), at + 48);
}
const native = Buffer.concat([header, trailer, trailer]);
await expect(
locateDenoStandalone(bytesHandle(native), native.length),
).resolves.toEqual({ status: "absent" });
const application = Buffer.concat([native, trailer]);
await expect(
locateDenoStandalone(bytesHandle(application), application.length),
).resolves.toMatchObject({
status: "present",
location: { offset: end + 24, length: section.length },
});
});
it("reads an Intel trailer that __LINKEDIT extends over", async () => {
const section = buildDenoSection();
const trailer = denoIntelTrailer(section);
@@ -28,8 +28,6 @@ import {
} from "../domain/browserScenarioCapture.js";
import {
classifyBrowserScenarioCompleteness,
browserScenarioStepSchema,
browserStepArtifactsSchema,
type BrowserScenarioCompleteness,
type BrowserScenarioCompletenessSection,
type BrowserScenarioStep,
@@ -94,14 +92,14 @@ const unavailableArtifacts = (
requested.has(kind)
? { state: "missing" as const, reason }
: { state: "not_requested" as const };
return browserStepArtifactsSchema.parse({
return {
screenshot: state("screenshot"),
dom: state("dom"),
accessibility: state("accessibility"),
url: state("url"),
history: state("history"),
storage: state("storage"),
});
};
};
const stepCompleteness = (
@@ -130,21 +128,23 @@ const createStep = (
readonly eventEnd: number;
readonly artifacts: BrowserStepArtifacts;
} & BrowserScenarioStepOutcome,
): BrowserScenarioStep =>
browserScenarioStepSchema.parse({
): BrowserScenarioStep => {
const base = {
step_index: input.stepIndex,
step_id: input.stepId,
action: input.action,
status: input.status,
elapsed_ms: input.elapsedMs,
before_url: input.beforeUrl,
after_url: input.afterUrl,
error: input.error,
event_sequence_start: input.eventStart,
event_sequence_end: input.eventEnd,
artifacts: input.artifacts,
completeness: stepCompleteness(input.artifacts, input.status),
});
};
return input.status === "completed"
? { ...base, status: "completed", error: null }
: { ...base, status: input.status, error: input.error };
};
const initialStep = async (input: {
readonly session: BrowserScenarioSessionPort;
+4 -1
View File
@@ -335,9 +335,12 @@ const nullableForm = (out: Schema): Schema => {
/** One projection: guidance sentences accumulate while the schema is built. */
class DialectProjection {
readonly notes: string[] = [];
readonly #seenNotes = new Set<string>();
note(sentence: string): void {
if (!this.notes.includes(sentence)) this.notes.push(sentence);
if (this.#seenNotes.has(sentence)) return;
this.#seenNotes.add(sentence);
this.notes.push(sentence);
}
project(value: unknown, path: string): unknown {
+5 -2
View File
@@ -137,13 +137,16 @@ const sharedRequiredProperties = (
branches: readonly Readonly<Record<string, unknown>>[],
): readonly string[] => {
const [first = [], ...others] = branches.map(requiredProperties);
return first.filter((name) => others.every((names) => names.includes(name)));
if (first.length === 0 || others.length === 0) return first;
const otherSets = others.map((names) => new Set(names));
return first.filter((name) => otherSets.every((names) => names.has(name)));
};
const inputGroup = (branch: Readonly<Record<string, unknown>>): string => {
const required = requiredProperties(branch);
const requiredSet = new Set(required);
const optional = Object.keys(branch.properties ?? {})
.filter((name) => !required.includes(name))
.filter((name) => !requiredSet.has(name))
.map((name) => `[${name}]`);
return [...required, ...optional].join(" + ");
};
+5 -4
View File
@@ -435,14 +435,15 @@ export const inspectManagedMembersBytes = (
);
appendManagedParseIssues(issues, targets.issues);
const incompleteMembers =
[...fields.fields, ...memberRefs.refs].some(
fields.fields.some(
(member) => member.signature.parse_status !== "decoded",
) ||
memberRefs.refs.some(
(member) => member.signature.parse_status !== "decoded",
) ||
resolvedMethods.some(
(method) => method.signature.parse_status !== "decoded",
) ||
resolvedMethods.some(
(method) =>
method.signature.parse_status !== "decoded" ||
method.body.status === "partial" ||
method.body.status === "malformed",
);