mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 21:46:01 +00:00
refactor(managed): retain verified manifest method tokens (#16147)
This commit is contained in:
1 parent
a365354ec5
commit
369de39fbd
1 file changed
+11
-16
@@ -23,14 +23,13 @@ import {
|
||||
/** @typedef {import("#dist/resources/ArtifactResourceScope.js").ArtifactResourceScope} ArtifactResourceScope */
|
||||
/** @typedef {import("#dist/domain/evidence.js").Evidence} Evidence */
|
||||
/** @typedef {ReturnType<typeof inspectManagedArtifactBytes>} ManagedArtifactInspection */
|
||||
/** @typedef {ReturnType<typeof inspectManagedMembersBytes>["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<typeof managedApplicationGraphResultSchema>["summary"];
|
||||
@@ -40,7 +39,7 @@ import {
|
||||
* Inputs shared by the graph projections of one verified target.
|
||||
* @typedef {{
|
||||
* readonly graphByToken: Map<string, ManifestMethodProjection>;
|
||||
* readonly inspectedMethods: ReadonlyMap<string, ManagedMethod>;
|
||||
* readonly verifiedTokens: ReadonlySet<string>;
|
||||
* 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<string, ManagedMethod>} */
|
||||
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<string, ManagedMethod>;
|
||||
* readonly verifiedTokens: ReadonlySet<string>;
|
||||
* }} options
|
||||
*/
|
||||
function verifyManagedAppManifestApplicationGraph({
|
||||
@@ -225,13 +221,13 @@ function verifyManagedAppManifestApplicationGraph({
|
||||
target,
|
||||
artifact,
|
||||
manifestMethods,
|
||||
inspectedMethods,
|
||||
verifiedTokens,
|
||||
}) {
|
||||
/** @type {Map<string, ManifestMethodProjection>} */
|
||||
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,
|
||||
|
||||
Reference in new issue
Block a user