From 369de39fbdb8ae3f4cd76730629913dbc6e5bba3 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Thu, 3 Dec 2026 07:45:50 +0800 Subject: [PATCH] refactor(managed): retain verified manifest method tokens (#16147) --- scripts/verify/managed/manifest.mjs | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/scripts/verify/managed/manifest.mjs b/scripts/verify/managed/manifest.mjs index 3efe5765811..205a63251fa 100644 --- a/scripts/verify/managed/manifest.mjs +++ b/scripts/verify/managed/manifest.mjs @@ -23,14 +23,13 @@ import { /** @typedef {import("#dist/resources/ArtifactResourceScope.js").ArtifactResourceScope} ArtifactResourceScope */ /** @typedef {import("#dist/domain/evidence.js").Evidence} Evidence */ /** @typedef {ReturnType} ManagedArtifactInspection */ -/** @typedef {ReturnType["methods"][number]} ManagedMethod */ /** @typedef {import("./manifest-parser.mjs").ManagedAppManifest} ManagedAppManifest */ /** @typedef {import("./manifest-parser.mjs").ManagedAppManifestMethod} ManagedAppManifestMethod */ /** @typedef {import("./manifest-parser.mjs").ManagedAppManifestGraph} ManagedAppManifestGraph */ /** * One manifest method's application graph projection. * @typedef {{ - * readonly method: ManagedMethod; + * readonly methodToken: string; * readonly evidence: Evidence; * readonly nodeKinds: readonly string[]; * readonly summary: import("zod").output["summary"]; @@ -40,7 +39,7 @@ import { * Inputs shared by the graph projections of one verified target. * @typedef {{ * readonly graphByToken: Map; - * readonly inspectedMethods: ReadonlyMap; + * readonly verifiedTokens: ReadonlySet; * readonly bytes: Buffer; * readonly target: BinaryTarget; * readonly artifact: ManagedArtifactInspection; @@ -100,7 +99,7 @@ async function verifyManifestSnapshot(rawManifest, manifestPath, resources) { const artifact = inspectManagedArtifactBytes(bytes, target); verifyManifestTarget(manifest, artifact); const methodVerification = verifyManifestMethods(manifest, bytes, target); - const { methods, inspectedMethods } = methodVerification; + const { methods } = methodVerification; let assertions = 1 + methodVerification.assertions; const applicationGraph = manifest.application_graph === undefined @@ -111,7 +110,7 @@ async function verifyManifestSnapshot(rawManifest, manifestPath, resources) { target, artifact, manifestMethods: manifest.methods, - inspectedMethods, + verifiedTokens: new Set(methods.map(({ token }) => token)), }); if (applicationGraph !== undefined) assertions += applicationGraph.assertions; return { @@ -172,8 +171,6 @@ function verifyManifestTarget(manifest, artifact) { function verifyManifestMethods(manifest, bytes, target) { const methods = []; let assertions = 0; - /** @type {Map} */ - const inspectedMethods = new Map(); for (const expectedMethod of manifest.methods) { const method = inspectManagedMethodByToken(bytes, target, expectedMethod); ensure( @@ -194,7 +191,6 @@ function verifyManifestMethods(manifest, bytes, target) { `method ${expectedMethod.token} normalized IL sha256 mismatch: expected ${expectedMethod.normalized_il_sha256}, observed ${method.body.normalized_il_sha256 ?? "null"}`, ); assertions += expectedMethod.il_sha256 === undefined ? 4 : 5; - inspectedMethods.set(expectedMethod.token, method); methods.push({ label: expectedMethod.label ?? null, token: method.token, @@ -206,7 +202,7 @@ function verifyManifestMethods(manifest, bytes, target) { normalized_il_sha256: method.body.normalized_il_sha256, }); } - return { methods, inspectedMethods, assertions }; + return { methods, assertions }; } /** @@ -216,7 +212,7 @@ function verifyManifestMethods(manifest, bytes, target) { * readonly target: BinaryTarget; * readonly artifact: ManagedArtifactInspection; * readonly manifestMethods: readonly ManagedAppManifestMethod[]; - * readonly inspectedMethods: ReadonlyMap; + * readonly verifiedTokens: ReadonlySet; * }} options */ function verifyManagedAppManifestApplicationGraph({ @@ -225,13 +221,13 @@ function verifyManagedAppManifestApplicationGraph({ target, artifact, manifestMethods, - inspectedMethods, + verifiedTokens, }) { /** @type {Map} */ const graphByToken = new Map(); const projectionState = { graphByToken, - inspectedMethods, + verifiedTokens, bytes, target, artifact, @@ -291,7 +287,7 @@ function verifyManagedAppManifestApplicationGraph({ assertions, summary: { projections: [...graphByToken.values()].map((projection) => ({ - method_token: projection.method.token, + method_token: projection.methodToken, graph_evidence_id: projection.evidence.evidence_id, node_kinds: projection.nodeKinds, summary: projection.summary, @@ -310,9 +306,8 @@ function verifyManagedAppManifestApplicationGraph({ const projectManifestMethod = (state, token) => { const existing = state.graphByToken.get(token); if (existing !== undefined) return existing; - const method = state.inspectedMethods.get(token); ensure( - method !== undefined, + state.verifiedTokens.has(token), `application graph method ${token} must also be declared in manifest.methods`, ); const members = inspectManagedMethodPageByToken( @@ -356,7 +351,7 @@ const projectManifestMethod = (state, token) => { projected.value.normalized_result, ); const projection = { - method, + methodToken: token, evidence: projected.value, nodeKinds: [...new Set(graph.graph.nodes.map(({ kind }) => kind))].sort(), summary: graph.summary,