refactor(artifacts): consolidate inventory into inspection

This commit is contained in:
morluto
2026-09-29 09:22:24 +08:00
parent a66e43a99d
commit 0fe96d92df
28 changed files with 375 additions and 280 deletions
+40 -18
View File
@@ -11,32 +11,49 @@ export async function verifyPackageArtifactAndElectron({
workspace,
environment,
}) {
const artifactArchive = await verifyPackagedArtifact({
cli,
workspace,
environment,
});
await verifyPackagedElectronApplication({
cli,
workspace,
environment,
});
return { artifactArchive };
}
const verifyPackagedArtifact = async ({ cli, workspace, environment }) => {
const artifactArchive = join(workspace, "artifact.zip");
const artifactWriter = new ZipWriter(new Uint8ArrayWriter());
await artifactWriter.add("app/main.js", new TextReader("main();"));
await writeFile(artifactArchive, await artifactWriter.close());
const artifactInventory = json(
const artifactInspection = json(
await run(
cli,
["inventory-artifact", artifactArchive, "--limit", "500", "--json"],
["inspect-artifact", artifactArchive, "--json"],
environment,
),
);
const repeatedArtifactInventory = json(
const repeatedArtifactInspection = json(
await run(
cli,
["inventory-artifact", artifactArchive, "--limit", "500", "--json"],
["inspect-artifact", artifactArchive, "--json"],
environment,
),
);
const artifactInventory =
artifactInspection.normalized_result?.substeps?.[0]?.evidence
?.normalized_result;
const repeatedArtifactInventory =
repeatedArtifactInspection.normalized_result?.substeps?.[0]?.evidence
?.normalized_result;
if (
artifactInventory.operation !== "inventory_artifact" ||
artifactInventory.provider?.id !== "rea-artifact-graph" ||
artifactInventory.normalized_result?.manifest?.root_format !== "zip" ||
!sameArtifactIdentity(
artifactInventory.normalized_result,
repeatedArtifactInventory.normalized_result,
)
artifactInspection.operation !== "inspect_artifact" ||
artifactInspection.provider?.id !== "rea-artifact-graph" ||
artifactInventory?.manifest?.root_format !== "zip" ||
!sameArtifactIdentity(artifactInventory, repeatedArtifactInventory)
)
throw new Error("packaged artifact inventory CLI failed");
await verifyPackagedArtifactExtraction({
@@ -46,6 +63,14 @@ export async function verifyPackageArtifactAndElectron({
environment,
workspace,
});
return artifactArchive;
};
const verifyPackagedElectronApplication = async ({
cli,
workspace,
environment,
}) => {
const applicationRoot = join(workspace, "electron-app");
await mkdir(applicationRoot);
await writeFile(
@@ -88,9 +113,7 @@ export async function verifyPackageArtifactAndElectron({
),
);
assertRoutedApplicationAnalysis(routedApplicationAnalysis);
return { artifactArchive };
}
};
const sameArtifactIdentity = (left, right) =>
isDeepStrictEqual(left?.manifest, right?.manifest) &&
@@ -105,10 +128,9 @@ const verifyPackagedArtifactExtraction = async ({
environment,
workspace,
}) => {
const occurrence =
artifactInventory.normalized_result?.occurrences?.items?.find(
({ logical_path: path }) => path === "app/main.js",
);
const occurrence = artifactInventory?.occurrences?.items?.find(
({ logical_path: path }) => path === "app/main.js",
);
if (occurrence?.occurrence_id === undefined)
throw new Error("packaged artifact inventory omitted the selected member");
const outputRoot = join(workspace, "artifact-extraction");
+2 -2
View File
@@ -3,7 +3,7 @@ import { json, run, runWithStatus } from "./lib/verify-package-core.mjs";
const REQUIRED_HELP_COMMANDS = [
"setup",
"upgrade",
"inventory-artifact",
"inspect-artifact",
"extract-artifact",
"import-reference-source",
"list-browser-targets",
@@ -21,7 +21,7 @@ const REQUIRED_LLM_TOPICS = [
"trace",
"capabilities",
"providers",
"inventory-artifact",
"inspect-artifact",
"list-browser-targets",
"inspect-web-page",
"analyze-javascript-application",