feat(artifacts): let extraction and JavaScript analysis record integrity mismatches
macOS code signing rewrites unpacked native modules after electron-builder records their ASAR integrity, so the declared and observed hashes of those .node files differ in most signed Electron apps. Claude, ChatGPT, Notion, Obsidian, and Tabby all failed inspect_artifact, extract_artifact, and analyze_javascript_application by default. Only inspect_artifact offered integrity_policy, so extraction and JavaScript analysis of these apps was impossible. extract_artifact and analyze_javascript_application now accept the same integrity_policy (default fail). With record-and-continue, extraction writes the observed bytes, and JavaScript analysis reads contradicted files as observed. Contradicted nested archives stay unexpanded. Both results return the recorded integrity_contradictions and a limitation. The mismatch remediation now names this option instead of only advising a fresh copy, which cannot help for a signed installation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
0804722cdf
commit
69af884666
@@ -228,11 +228,16 @@ and returns its result and Evidence inline.
|
||||
|
||||
## Integrity record-and-continue
|
||||
|
||||
Artifact integrity fails closed by default. A request can explicitly select
|
||||
Artifact integrity fails closed by default. `inspect_artifact`,
|
||||
`extract_artifact`, and `analyze_javascript_application` accept
|
||||
`integrity_policy=record-and-continue` when the investigation needs verified
|
||||
siblings to continue after a mismatch.
|
||||
siblings to continue after a mismatch. A common expected mismatch is an
|
||||
unpacked native module that macOS code signing rewrote after the ASAR header
|
||||
recorded its integrity.
|
||||
|
||||
Contradictory bytes are quarantined from nested expansion and recorded with
|
||||
declared and observed hashes, trust, provenance, path, and unpacked state.
|
||||
Verified siblings continue. Comparisons classify the result as a contradiction
|
||||
and reconstruction cannot treat it as unchanged.
|
||||
Verified siblings continue. Extraction writes the observed bytes and returns the
|
||||
contradictions with its result; JavaScript analysis reads contradicted files as
|
||||
observed and lists them in `integrity_contradictions`. Comparisons classify the
|
||||
result as a contradiction and reconstruction cannot treat it as unchanged.
|
||||
|
||||
@@ -663,9 +663,9 @@
|
||||
"mcp_prompts": 6
|
||||
},
|
||||
"digests": {
|
||||
"tools_sha256": "676a0ae5ff16933e3a9b2db0e5a95fcecf57ac926d18ce8b7a31909e040a9972",
|
||||
"tools_sha256": "5afa0b635fbbb291576b5918cd3fa9b4808b3276a6892cae77365e8ca4d6b93d",
|
||||
"prompts_sha256": "ef2de8814390b340623c32001610aa2709d90bed51537b6e562ab3abf144ab4d",
|
||||
"combined_sha256": "c32a78528d109b2c25582a74c02d25ccb779cb511f6e2477017a2e8805c07bac",
|
||||
"combined_sha256": "fa2fca0f1823799533ac9b45d158c392d88cd473d7c3f7c6072cb4c8d96e7349",
|
||||
"providers_sha256": "67251a90abf28e1cd9020cf68f579bf2460922d90dc113798a391039279db009"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"manifest_id": "ecm_df760a39c0bf1144d883fe0b80e22cc93364d23289b9a9a14d0efff72a1031bb",
|
||||
"manifest_id": "ecm_120aab8b6dcf6dbc4f67c39141c04b4e851796fdec4056221ed557a3ec22cf3b",
|
||||
"verifier": {
|
||||
"id": "rea-managed-conformance",
|
||||
"version": "1"
|
||||
@@ -13,7 +13,7 @@
|
||||
"skill_digests": [
|
||||
{
|
||||
"skill_id": "reverse-engineer-anything",
|
||||
"sha256": "e6e0645e84a6514c7d7d3e42d5b0a424bfb0110951eff41471f901de39dbec17"
|
||||
"sha256": "fa163dadc02b0d36a3c91892c6fe6df042c6592ec7cdd8ee743a9ec7b7049e0a"
|
||||
}
|
||||
],
|
||||
"claims": [
|
||||
|
||||
@@ -4,7 +4,7 @@ description: Reverse engineer native, managed, Electron/JavaScript, packaged, fi
|
||||
metadata:
|
||||
version: "26"
|
||||
tool_count: 130
|
||||
catalog_digest: "c32a78528d109b2c25582a74c02d25ccb779cb511f6e2477017a2e8805c07bac"
|
||||
catalog_digest: "fa2fca0f1823799533ac9b45d158c392d88cd473d7c3f7c6072cb4c8d96e7349"
|
||||
---
|
||||
|
||||
# REA
|
||||
|
||||
@@ -21,15 +21,19 @@ import {
|
||||
type ArtifactGraphManifest,
|
||||
type ArtifactNode,
|
||||
type ArtifactOccurrence,
|
||||
type IntegrityContradiction,
|
||||
} from "../domain/artifactGraph.js";
|
||||
import type { BinaryTarget } from "../domain/binaryTarget.js";
|
||||
import { scanArtifactInventory } from "./ArtifactInventory.js";
|
||||
import type { ArtifactIntegrityPolicy } from "./ArtifactInventory/types.js";
|
||||
|
||||
/** Local extraction input with the output root chosen by the adapter. */
|
||||
export interface ArtifactExtractionInput {
|
||||
readonly inputPath: string;
|
||||
readonly inputFormat: BinaryTarget["format"];
|
||||
readonly outputRoot: string;
|
||||
/** Integrity mismatches fail unless the caller records and continues. */
|
||||
readonly integrity?: ArtifactIntegrityPolicy;
|
||||
}
|
||||
|
||||
/** Extract every regular inventory occurrence into an exclusively owned absent root. */
|
||||
@@ -40,6 +44,7 @@ export const extractArtifact = async (
|
||||
const sourcePath = await realpath(input.inputPath);
|
||||
const snapshot = await scanArtifactInventory(sourcePath, {
|
||||
signal,
|
||||
integrity: input.integrity,
|
||||
});
|
||||
const selectedOccurrences = snapshot.occurrences.filter(
|
||||
(occurrence) =>
|
||||
@@ -63,6 +68,7 @@ export const extractArtifact = async (
|
||||
manifest: snapshot.manifest,
|
||||
occurrences,
|
||||
nodes,
|
||||
integrityContradictions: snapshot.integrity_contradictions,
|
||||
};
|
||||
const selected = selectedOccurrences.map((occurrence) => {
|
||||
if (
|
||||
@@ -206,8 +212,14 @@ const createExtractionResult = (
|
||||
containment_verified: true,
|
||||
cleanup: { attempted: false, verified: true, residual_paths: [] },
|
||||
provenance: [],
|
||||
integrity_contradictions: inventory.integrityContradictions,
|
||||
limitations: [
|
||||
"All regular files in the active artifact were materialized; nested archive contents remain represented by their containing file.",
|
||||
...(inventory.integrityContradictions.length === 0
|
||||
? []
|
||||
: [
|
||||
`${String(inventory.integrityContradictions.length)} extracted file(s) contradict declared integrity; their observed bytes were written and are untrusted.`,
|
||||
]),
|
||||
],
|
||||
});
|
||||
};
|
||||
@@ -216,6 +228,7 @@ interface LoadedInventory {
|
||||
readonly manifest: ArtifactGraphManifest;
|
||||
readonly occurrences: ReadonlyMap<string, ArtifactOccurrence>;
|
||||
readonly nodes: ReadonlyMap<string, ArtifactNode>;
|
||||
readonly integrityContradictions: readonly IntegrityContradiction[];
|
||||
}
|
||||
|
||||
const collectOccurrences = (
|
||||
|
||||
@@ -40,4 +40,5 @@ const parameters = (
|
||||
input: AnalyzeJavaScriptApplicationInput,
|
||||
): EvidenceObservation["parameters"] => ({
|
||||
format: input.format,
|
||||
integrity_policy: input.integrity_policy,
|
||||
});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { mkdir, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { createPackageWithOptions } from "@electron/asar";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { z } from "zod";
|
||||
|
||||
@@ -120,3 +121,57 @@ describe("JavaScript application failure diagnostics", () => {
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("JavaScript application artifact integrity", () => {
|
||||
it("analyzes a signed-after-packaging native module only when the mismatch is recorded", async () => {
|
||||
const root = await createTestTempDirectory("rea-js-integrity-");
|
||||
const source = join(root, "source");
|
||||
await mkdir(source);
|
||||
await writeFile(
|
||||
join(source, "package.json"),
|
||||
'{"name":"signed","main":"main.js"}',
|
||||
);
|
||||
await writeFile(join(source, "main.js"), "require('./addon.node');\n");
|
||||
await writeFile(join(source, "addon.node"), "packed native bytes");
|
||||
const archive = join(root, "app.asar");
|
||||
await createPackageWithOptions(source, archive, { unpack: "*.node" });
|
||||
// macOS code signing rewrites unpacked binaries after the archive header
|
||||
// has recorded their integrity.
|
||||
await writeFile(
|
||||
join(`${archive}.unpacked`, "addon.node"),
|
||||
"signed native bytes",
|
||||
);
|
||||
|
||||
const strict = await analyzeJavaScriptApplication({ input_path: archive });
|
||||
expect(strict.ok).toBe(false);
|
||||
if (strict.ok) throw new Error("Expected an integrity failure");
|
||||
expect(projectAnalysisError(strict.error)).toMatchObject({
|
||||
code: "artifact_integrity_mismatch",
|
||||
details: { logical_path: "addon.node", unpacked: true },
|
||||
});
|
||||
|
||||
const recorded = await analyzeJavaScriptApplication({
|
||||
input_path: archive,
|
||||
integrity_policy: "record-and-continue",
|
||||
});
|
||||
expect(recorded.ok).toBe(true);
|
||||
if (!recorded.ok) throw new Error("Expected recorded analysis");
|
||||
expect(recorded.value.parameters).toEqual({
|
||||
format: "auto",
|
||||
integrity_policy: "record-and-continue",
|
||||
});
|
||||
expect(recorded.value.normalized_result).toMatchObject({
|
||||
format: "asar",
|
||||
integrity_contradictions: [
|
||||
{
|
||||
logical_path: "addon.node",
|
||||
unpacked: true,
|
||||
trust: "observed-untrusted",
|
||||
},
|
||||
],
|
||||
limitations: expect.arrayContaining([
|
||||
"1 artifact file(s) contradict declared integrity; their observed bytes are untrusted, and contradicted nested archives were not expanded.",
|
||||
]),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -55,14 +55,23 @@ export const analyzeJavaScriptApplicationValidated = async (
|
||||
{
|
||||
input_path: input.input_path,
|
||||
format: input.format,
|
||||
integrity_policy: input.integrity_policy,
|
||||
},
|
||||
options.signal,
|
||||
);
|
||||
const { electron_summary: summary, ...application } = reconstructed;
|
||||
const contradictions = reconstructed.integrity_contradictions.length;
|
||||
const result = javascriptApplicationAnalysisResultSchema.parse({
|
||||
...application,
|
||||
summary,
|
||||
limitations: reconstructed.graph.limitations,
|
||||
limitations: [
|
||||
...reconstructed.graph.limitations,
|
||||
...(contradictions === 0
|
||||
? []
|
||||
: [
|
||||
`${String(contradictions)} artifact file(s) contradict declared integrity; their observed bytes are untrusted, and contradicted nested archives were not expanded.`,
|
||||
]),
|
||||
],
|
||||
});
|
||||
await options.progress?.report({
|
||||
phase: "analyze_javascript_application",
|
||||
|
||||
@@ -9,6 +9,7 @@ import { DirectoryArtifactReader } from "../../artifacts/DirectoryArtifactReader
|
||||
import type { JavaScriptApplicationGraph } from "../../domain/javascriptApplicationGraph.js";
|
||||
import type { JavaScriptSemanticGraph } from "../../domain/javascriptSemanticGraph.js";
|
||||
import type { ElectronBoundarySummary } from "../../domain/javascriptApplicationAnalysis.js";
|
||||
import type { IntegrityContradiction } from "../../domain/artifactGraph.js";
|
||||
import { analyzeJavaScriptArtifactFiles } from "./JavaScriptArtifactAnalysis.js";
|
||||
import { readJavaScriptArtifactFiles } from "./JavaScriptArtifactFiles.js";
|
||||
import { buildJavaScriptArtifactGraph } from "./JavaScriptArtifactGraphBuilder.js";
|
||||
@@ -30,6 +31,7 @@ export interface JavaScriptArtifactReconstructionResult {
|
||||
readonly graph: JavaScriptApplicationGraph;
|
||||
readonly semantic_graph: JavaScriptSemanticGraph;
|
||||
readonly electron_summary: ElectronBoundarySummary;
|
||||
readonly integrity_contradictions: readonly IntegrityContradiction[];
|
||||
readonly statistics: {
|
||||
readonly relevant_files: number;
|
||||
readonly nested_asar_containers: number;
|
||||
@@ -54,7 +56,10 @@ export const reconstructJavaScriptArtifact = async (
|
||||
abortIfNeeded(signal);
|
||||
const path = await realpath(input.input_path);
|
||||
const format = await resolveFormat(path, input);
|
||||
const snapshot = await scanCanonicalArtifactInventory(path, { signal });
|
||||
const snapshot = await scanCanonicalArtifactInventory(path, {
|
||||
signal,
|
||||
integrity: { mode: input.integrity_policy },
|
||||
});
|
||||
if (snapshot.manifest.root_format !== format)
|
||||
throw new ArtifactReaderFailure(
|
||||
"format",
|
||||
@@ -80,6 +85,7 @@ export const reconstructJavaScriptArtifact = async (
|
||||
graph,
|
||||
semantic_graph: semanticGraph,
|
||||
electron_summary: summarizeElectronBoundaries(analysis),
|
||||
integrity_contradictions: snapshot.integrity_contradictions,
|
||||
statistics: {
|
||||
relevant_files: files.files.length,
|
||||
nested_asar_containers: files.containers.length,
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { artifactIntegrityPolicySchema } from "../../domain/artifactGraph.js";
|
||||
|
||||
/** Local ASAR/directory reconstruction request. */
|
||||
export const javascriptArtifactReconstructionInputSchema = z.strictObject({
|
||||
input_path: z.string().min(1),
|
||||
format: z.enum(["auto", "asar", "directory"]).default("auto"),
|
||||
integrity_policy: artifactIntegrityPolicySchema,
|
||||
});
|
||||
|
||||
/** Parsed local reconstruction request. */
|
||||
|
||||
@@ -160,6 +160,9 @@ class ArtifactClient implements AnalysisClient {
|
||||
inputPath: this.target.sourcePath ?? this.target.path,
|
||||
inputFormat: this.target.format,
|
||||
outputRoot: parsed.output_root,
|
||||
integrity: resolveArtifactIntegrityPolicy({
|
||||
mode: parsed.integrity_policy,
|
||||
}),
|
||||
},
|
||||
options?.signal,
|
||||
);
|
||||
|
||||
@@ -153,14 +153,23 @@ const registerExtractionCommand = (cli: CliInstance, logger: Logger): void => {
|
||||
args: z.object({
|
||||
path: z.string().describe("Application or package path"),
|
||||
}),
|
||||
options: z.object({}),
|
||||
run: ({ args }) =>
|
||||
options: z.object({
|
||||
integrityPolicy: z
|
||||
.enum(["fail", "record-and-continue"])
|
||||
.default("fail")
|
||||
.describe("Behavior when declared artifact integrity does not match"),
|
||||
}),
|
||||
alias: {
|
||||
integrityPolicy: "integrity-policy",
|
||||
},
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, "extract-artifact", () =>
|
||||
runProviderAnalysis(
|
||||
args.path,
|
||||
"extract_artifact",
|
||||
{
|
||||
output_root: createArtifactExtractionDestination(),
|
||||
integrity_policy: options.integrityPolicy,
|
||||
},
|
||||
logger,
|
||||
),
|
||||
|
||||
@@ -175,6 +175,7 @@ const registerJavaScriptApplicationCommand = (
|
||||
runCliJavaScriptApplicationAnalysis({
|
||||
input_path: args.path,
|
||||
format: options.artifactFormat,
|
||||
integrity_policy: options.integrityPolicy,
|
||||
}),
|
||||
),
|
||||
});
|
||||
|
||||
@@ -63,4 +63,8 @@ export const javascriptApplicationOptions = z.object({
|
||||
.enum(["auto", "asar", "directory"])
|
||||
.default("auto")
|
||||
.describe("Application artifact format"),
|
||||
integrityPolicy: z
|
||||
.enum(["fail", "record-and-continue"])
|
||||
.default("fail")
|
||||
.describe("Behavior when declared artifact integrity does not match"),
|
||||
});
|
||||
|
||||
@@ -7,17 +7,21 @@ import { toolContractMetadata } from "./toolEffects.js";
|
||||
import { requireOutputSchema } from "./toolOutputSchemaPrimitives.js";
|
||||
import { appleAssetCatalogInputSchema } from "../domain/appleAssetCatalog.js";
|
||||
import { keyedArchiveInputSchema } from "../domain/keyedArchive.js";
|
||||
import { artifactIntegrityPolicySchema } from "../domain/artifactGraph.js";
|
||||
/** Exact caller boundary for deterministic artifact inventory. */
|
||||
export const artifactInventoryInputSchema = z.strictObject({
|
||||
integrity_policy: z.enum(["fail", "record-and-continue"]).default("fail"),
|
||||
integrity_policy: artifactIntegrityPolicySchema,
|
||||
});
|
||||
|
||||
/** Extraction needs no selector: it materializes every regular child file. */
|
||||
export const artifactExtractionInputSchema = z.strictObject({});
|
||||
export const artifactExtractionInputSchema = z.strictObject({
|
||||
integrity_policy: artifactIntegrityPolicySchema,
|
||||
});
|
||||
|
||||
/** Provider input containing the destination chosen by the local adapter. */
|
||||
export const artifactExtractionExecutionSchema = z.strictObject({
|
||||
output_root: z.string().min(1),
|
||||
integrity_policy: artifactIntegrityPolicySchema,
|
||||
});
|
||||
|
||||
const exampleInputSchema = z.record(z.string(), jsonValueSchema);
|
||||
@@ -63,7 +67,7 @@ export const ARTIFACT_TOOL_CONTRACTS = [
|
||||
),
|
||||
artifact(
|
||||
"extract_artifact",
|
||||
"Extract all regular files from the active archive or application package into a fresh temporary directory chosen by REA. The result includes its location. Rejects traversal and symlink escapes, never overwrites, enforces archive integrity checks, and verifies cleanup.",
|
||||
"Extract all regular files from the active archive or application package into a fresh temporary directory chosen by REA. The result includes its location. Rejects traversal and symlink escapes, never overwrites, enforces archive integrity checks, and verifies cleanup. Integrity mismatches fail by default; record-and-continue extracts the observed bytes and reports each mismatch as an untrusted integrity contradiction.",
|
||||
artifactExtractionInputSchema,
|
||||
),
|
||||
artifact(
|
||||
|
||||
@@ -79,7 +79,7 @@ export const ELECTRON_TOOL_CONTRACTS = [
|
||||
name: "analyze_javascript_application",
|
||||
...toolContractMetadata("analyze_javascript_application"),
|
||||
description:
|
||||
"Reconstruct one local ASAR or extracted JavaScript application as an inline application graph without executing it. Returns all recovered graph nodes, edges, semantic relations, limitations, and coverage.",
|
||||
"Reconstruct one local ASAR or extracted JavaScript application as an inline application graph without executing it. Returns all recovered graph nodes, edges, semantic relations, limitations, and coverage. Integrity mismatches, such as unpacked native modules signed after packaging, fail by default; record-and-continue analyzes the observed bytes and reports each mismatch as an untrusted integrity contradiction.",
|
||||
kind: "electron-provider",
|
||||
inputSchema: analyzeJavaScriptApplicationInputSchema,
|
||||
outputSchema: applicationOutputSchema,
|
||||
|
||||
@@ -127,7 +127,11 @@ export const analysisErrorUserMessage = (error: AnalysisError): string => {
|
||||
const standardMessage = standardErrorMessage(error._tag);
|
||||
if (standardMessage !== undefined) return standardMessage;
|
||||
if (error instanceof ArtifactOperationError)
|
||||
return artifactMessage(error.reason);
|
||||
return error.reason === "integrity" &&
|
||||
error.artifactDetails !== undefined &&
|
||||
INTEGRITY_POLICY_OPERATIONS.has(error.operation)
|
||||
? "Artifact bytes contradict their declared integrity. If that is expected, such as an unpacked native module signed after packaging, rerun with integrity_policy record-and-continue to keep the mismatch as an untrusted contradiction; otherwise get a fresh copy."
|
||||
: artifactMessage(error.reason);
|
||||
if (error instanceof EvidenceReferenceError)
|
||||
return error.reason === "missing"
|
||||
? `Evidence ${error.evidenceId} is not retained in this session. Supply complete inline Evidence, re-run its producer, or import its bundle before using this reference.`
|
||||
@@ -216,6 +220,15 @@ const START_FAILURE_TAGS: ReadonlySet<AnalysisErrorTag> = new Set([
|
||||
"HopperStartError",
|
||||
]);
|
||||
|
||||
/** Operations whose callers can record integrity mismatches and continue. */
|
||||
const INTEGRITY_POLICY_OPERATIONS: ReadonlySet<
|
||||
ArtifactOperationError["operation"]
|
||||
> = new Set([
|
||||
"inspect_artifact",
|
||||
"extract_artifact",
|
||||
"analyze_javascript_application",
|
||||
]);
|
||||
|
||||
const artifactMessage = (reason: ArtifactOperationError["reason"]): string => {
|
||||
if (reason === "cancelled")
|
||||
return "Artifact operation was cancelled. Start it again when ready.";
|
||||
|
||||
@@ -122,8 +122,13 @@ const artifactOccurrenceSchema = z.object({
|
||||
limitations: z.array(z.string()),
|
||||
});
|
||||
|
||||
/** Behavior when observed bytes contradict declared artifact integrity. */
|
||||
export const artifactIntegrityPolicySchema = z
|
||||
.enum(["fail", "record-and-continue"])
|
||||
.default("fail");
|
||||
|
||||
/** Observed bytes that contradict a container's declared integrity identity. */
|
||||
const integrityContradictionSchema = z.object({
|
||||
export const integrityContradictionSchema = z.object({
|
||||
contradiction_id: contradictionIdSchema,
|
||||
occurrence_id: occurrenceIdSchema,
|
||||
parent_artifact_id: artifactIdSchema,
|
||||
@@ -211,6 +216,7 @@ export const artifactExtractionResultSchema = z.object({
|
||||
residual_paths: z.array(boundedRelativePathSchema),
|
||||
}),
|
||||
provenance: z.array(artifactCommandSchema),
|
||||
integrity_contradictions: z.array(integrityContradictionSchema).default([]),
|
||||
limitations: z.array(z.string()),
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import {
|
||||
artifactIntegrityPolicySchema,
|
||||
integrityContradictionSchema,
|
||||
} from "./artifactGraph.js";
|
||||
import { javascriptApplicationGraphSchema } from "./javascriptApplicationGraph.js";
|
||||
import { javaScriptSemanticGraphSchema } from "./javascriptSemanticGraph.js";
|
||||
import { digestSchema } from "./../domain/digests.js";
|
||||
@@ -11,6 +15,7 @@ const countSchema = z.number().int().min(0);
|
||||
export const analyzeJavaScriptApplicationInputSchema = z.strictObject({
|
||||
input_path: z.string().min(1),
|
||||
format: z.enum(["auto", "asar", "directory"]).default("auto"),
|
||||
integrity_policy: artifactIntegrityPolicySchema,
|
||||
});
|
||||
|
||||
/** Compact counts for the high-level Electron architecture/security surface. */
|
||||
@@ -62,6 +67,7 @@ export const javascriptApplicationAnalysisResultSchema = z
|
||||
graph: javascriptApplicationGraphSchema,
|
||||
summary: electronBoundarySummarySchema,
|
||||
statistics: reconstructionStatisticsSchema,
|
||||
integrity_contradictions: z.array(integrityContradictionSchema).default([]),
|
||||
limitations: z.array(z.string().min(1)),
|
||||
semantic_graph: javaScriptSemanticGraphSchema,
|
||||
})
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -66,8 +66,7 @@ it.each([
|
||||
error: {
|
||||
code: "artifact_integrity_mismatch",
|
||||
category: "integrity_mismatch",
|
||||
message:
|
||||
"Artifact is invalid or has changed. Get a fresh copy and try again.",
|
||||
message: INTEGRITY_REMEDIATION,
|
||||
details: {
|
||||
logical_path: "main.js",
|
||||
declared_sha256: expect.stringMatching(/^[a-f0-9]{64}$/u),
|
||||
@@ -76,8 +75,7 @@ it.each([
|
||||
},
|
||||
retryable: false,
|
||||
remediation: {
|
||||
action:
|
||||
"Artifact is invalid or has changed. Get a fresh copy and try again.",
|
||||
action: INTEGRITY_REMEDIATION,
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -92,6 +90,9 @@ it.each([
|
||||
20_000,
|
||||
);
|
||||
|
||||
const INTEGRITY_REMEDIATION =
|
||||
"Artifact bytes contradict their declared integrity. If that is expected, such as an unpacked native module signed after packaging, rerun with integrity_policy record-and-continue to keep the mismatch as an untrusted contradiction; otherwise get a fresh copy.";
|
||||
|
||||
const artifactInventoryResultSchema = z.object({
|
||||
occurrences: z.array(
|
||||
z.object({ logical_path: z.string(), hash_status: z.string() }),
|
||||
@@ -148,6 +149,81 @@ it("extracts an active archive through MCP when requested", async () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("extracts an unpacked integrity mismatch only when the caller records it", async () => {
|
||||
const root = await createTestTempDirectory("rea-asar-extract-continue-mcp-");
|
||||
const source = join(root, "source");
|
||||
await mkdir(source);
|
||||
await writeFile(join(source, "main.js"), "console.log('ok');\n");
|
||||
await writeFile(join(source, "kept.txt"), "kept\n");
|
||||
const archive = join(root, "fixture.asar");
|
||||
await createPackageWithOptions(source, archive, { unpack: "*.js" });
|
||||
// Code signing after packaging changes unpacked bytes in the same way.
|
||||
await writeFile(
|
||||
join(`${archive}.unpacked`, "main.js"),
|
||||
"console.log('no');\n",
|
||||
);
|
||||
|
||||
const session = createTestBinarySession(new ArtifactProvider());
|
||||
const server = createServer(session, session);
|
||||
const client = new Client({ name: "asar-extract-continue", version: "1" });
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
let outputRoot: string | undefined;
|
||||
try {
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
await client.callTool({
|
||||
name: "open_binary",
|
||||
arguments: { path: archive },
|
||||
});
|
||||
const strict = await client.callTool({
|
||||
name: "extract_artifact",
|
||||
arguments: {},
|
||||
});
|
||||
expect(strict.isError).toBe(true);
|
||||
expect(strict.structuredContent).toMatchObject({
|
||||
error: {
|
||||
code: "artifact_integrity_mismatch",
|
||||
message: INTEGRITY_REMEDIATION,
|
||||
},
|
||||
});
|
||||
|
||||
const result = await client.callTool({
|
||||
name: "extract_artifact",
|
||||
arguments: { integrity_policy: "record-and-continue" },
|
||||
});
|
||||
expect(result.isError, JSON.stringify(result.structuredContent)).not.toBe(
|
||||
true,
|
||||
);
|
||||
const extraction = z
|
||||
.object({
|
||||
output_root: z.string(),
|
||||
integrity_contradictions:
|
||||
artifactInventoryResultSchema.shape.integrity_contradictions,
|
||||
limitations: z.array(z.string()),
|
||||
})
|
||||
.parse(compactResult(result.structuredContent).result);
|
||||
outputRoot = extraction.output_root;
|
||||
expect(await readFile(join(outputRoot, "main.js"), "utf8")).toBe(
|
||||
"console.log('no');\n",
|
||||
);
|
||||
expect(await readFile(join(outputRoot, "kept.txt"), "utf8")).toBe("kept\n");
|
||||
expect(extraction.integrity_contradictions).toEqual([
|
||||
expect.objectContaining({
|
||||
logical_path: "main.js",
|
||||
trust: "observed-untrusted",
|
||||
}),
|
||||
]);
|
||||
expect(extraction.limitations).toContain(
|
||||
"1 extracted file(s) contradict declared integrity; their observed bytes were written and are untrusted.",
|
||||
);
|
||||
} finally {
|
||||
await Promise.allSettled([client.close(), server.close(), session.close()]);
|
||||
if (outputRoot !== undefined)
|
||||
await rm(outputRoot, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it("records an explicitly continued mismatch, preserves verified siblings, and never reports equivalence", async () => {
|
||||
const root = await createTestTempDirectory("rea-asar-continue-mcp-");
|
||||
const source = join(root, "source");
|
||||
|
||||
Reference in New Issue
Block a user