chore: preserve current main archive typing and runtime fixes
This commit is contained in:
@@ -2,6 +2,7 @@ import { createHash } from "node:crypto";
|
||||
import { expect } from "vitest";
|
||||
import { toolContract } from "../../src/contracts/toolContracts.js";
|
||||
import { parseEvidence } from "../../src/domain/evidence.js";
|
||||
import { flutterResultSchemas } from "../../src/domain/flutter/flutterBuildAnalysis.js";
|
||||
import {
|
||||
aotFixtureImage,
|
||||
engineFixtureImage,
|
||||
@@ -59,6 +60,9 @@ cliTest(
|
||||
});
|
||||
expect(result.exitCode, result.stderr).toBe(0);
|
||||
const evidence = toolContract(name).outputSchema.parse(result.json);
|
||||
const complete = flutterResultSchemas[name].parse(
|
||||
evidence.normalized_result,
|
||||
);
|
||||
const response = await call(name, {
|
||||
path,
|
||||
...(abi === undefined ? {} : { abi }),
|
||||
@@ -70,7 +74,7 @@ cliTest(
|
||||
expect(mcp.subject).toMatchObject({
|
||||
local_path: path,
|
||||
format: "apk",
|
||||
digest: { sha256: evidence.normalized_result.target.sha256 },
|
||||
digest: { sha256: complete.target.sha256 },
|
||||
});
|
||||
expect(mcp.evidence_id).toBe(evidence.evidence_id);
|
||||
if (name === "inspect_dart_aot") {
|
||||
@@ -134,6 +138,9 @@ cliTest(
|
||||
const evidence = toolContract("inspect_dart_aot").outputSchema.parse(
|
||||
result.json,
|
||||
);
|
||||
const complete = flutterResultSchemas.inspect_dart_aot.parse(
|
||||
evidence.normalized_result,
|
||||
);
|
||||
const { call } = await connectLocalToolsMcp();
|
||||
const response = await call("inspect_dart_aot", { path });
|
||||
expect(response.isError, JSON.stringify(response)).not.toBe(true);
|
||||
@@ -146,7 +153,7 @@ cliTest(
|
||||
string_pool: { coverage: "complete" },
|
||||
});
|
||||
expect(
|
||||
evidence.normalized_result.libapp.sections
|
||||
complete.libapp.sections
|
||||
.filter((section) => section.name.endsWith("Data"))
|
||||
.map((section) => section.kind),
|
||||
).toEqual([4, 4]);
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { readFile, writeFile } from "node:fs/promises";
|
||||
import { resolve } from "node:path";
|
||||
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import { TextReader, Uint8ArrayWriter, ZipWriter } from "@zip.js/zip.js";
|
||||
import { expect } from "vitest";
|
||||
|
||||
import { artifactInspectionResultSchema } from "../../src/domain/artifactInspection.js";
|
||||
import { parseEvidence } from "../../src/domain/evidence.js";
|
||||
import { harmonyApplicationProjectionResultSchema } from "../../src/domain/harmony/harmonyApplication.js";
|
||||
import { workspaceCliTest as test } from "../support/cli/workspaceCliFixture.js";
|
||||
|
||||
test("preserves Harmony archive formats through the public CLI/MCP lifecycle", async ({
|
||||
cli,
|
||||
workspace,
|
||||
}) => {
|
||||
const writer = new ZipWriter(new Uint8ArrayWriter());
|
||||
await writer.add(
|
||||
"module.json",
|
||||
new TextReader('{"module":{"name":"fixture"}}'),
|
||||
);
|
||||
await writer.add(
|
||||
"ets/modules.abc",
|
||||
new TextReader("opaque bytecode fixture"),
|
||||
);
|
||||
const bytes = await writer.close();
|
||||
const environment = {
|
||||
PATH: process.env.PATH ?? "",
|
||||
HOME: workspace.root,
|
||||
USERPROFILE: workspace.root,
|
||||
XDG_CONFIG_HOME: workspace.path("config"),
|
||||
XDG_CACHE_HOME: workspace.path("cache"),
|
||||
XDG_STATE_HOME: workspace.path("state"),
|
||||
NODE_OPTIONS: "--max-old-space-size=512",
|
||||
REA_LOG_LEVEL: "silent",
|
||||
};
|
||||
const client = new Client({ name: "rea-harmony-acceptance", version: "1" });
|
||||
const transport = new StdioClientTransport({
|
||||
command: process.execPath,
|
||||
args: [resolve("scripts/rea.mjs"), "mcp"],
|
||||
env: environment,
|
||||
stderr: "pipe",
|
||||
});
|
||||
try {
|
||||
await client.connect(transport);
|
||||
await client.listTools();
|
||||
for (const { suffix, format } of [
|
||||
{ suffix: "hap", format: "hap" },
|
||||
{ suffix: "hsp", format: "hsp" },
|
||||
{ suffix: "app", format: "app-pack" },
|
||||
]) {
|
||||
const path = workspace.path(`fixture.${suffix}`);
|
||||
await writeFile(path, bytes);
|
||||
const sha256 = createHash("sha256").update(bytes).digest("hex");
|
||||
const cliReply = await cli.run({
|
||||
arguments: ["inspect-artifact", path, "--format", "json"],
|
||||
environment,
|
||||
});
|
||||
expect(cliReply.exitCode, cliReply.stderr).toBe(0);
|
||||
const cliEvidence = parseEvidence(cliReply.json);
|
||||
const cliInventory = artifactInspectionResultSchema.parse(
|
||||
cliEvidence.normalized_result,
|
||||
);
|
||||
expect(cliInventory.subject).toMatchObject({
|
||||
root_format: format,
|
||||
root_sha256: sha256,
|
||||
});
|
||||
const opened = await client.callTool({
|
||||
name: "open_binary",
|
||||
arguments: { path },
|
||||
});
|
||||
expect(opened.isError, JSON.stringify(opened)).not.toBe(true);
|
||||
expect(opened.structuredContent).toMatchObject({
|
||||
result: { kind: "archive", format, sha256 },
|
||||
});
|
||||
const status = await client.callTool({
|
||||
name: "binary_session",
|
||||
arguments: {},
|
||||
});
|
||||
expect(status.isError, JSON.stringify(status)).not.toBe(true);
|
||||
expect(status.structuredContent).toMatchObject({
|
||||
result: { open: true, kind: "archive", format, sha256 },
|
||||
});
|
||||
const inspected = await client.callTool({
|
||||
name: "inspect_artifact",
|
||||
arguments: {},
|
||||
});
|
||||
expect(inspected.isError, JSON.stringify(inspected)).not.toBe(true);
|
||||
const inventoryEvidence = parseEvidence(inspected.structuredContent);
|
||||
expect(
|
||||
artifactInspectionResultSchema.parse(
|
||||
inventoryEvidence.normalized_result,
|
||||
),
|
||||
).toEqual(cliInventory);
|
||||
|
||||
const projected = await client.callTool({
|
||||
name: "project_harmony_application_graph",
|
||||
arguments: { inventory_evidence: [inventoryEvidence] },
|
||||
});
|
||||
expect(projected.isError, JSON.stringify(projected)).not.toBe(true);
|
||||
const graph = harmonyApplicationProjectionResultSchema.parse(
|
||||
parseEvidence(projected.structuredContent).normalized_result,
|
||||
);
|
||||
expect(graph).toMatchObject({
|
||||
root_format: format,
|
||||
root_sha256: sha256,
|
||||
coverage: { status: "complete-within-inventory" },
|
||||
});
|
||||
expect(
|
||||
graph.components.manifests.map(({ path: member }) => member),
|
||||
).toEqual(["module.json"]);
|
||||
expect(
|
||||
graph.components.bytecode.map(({ path: member }) => member),
|
||||
).toEqual(["ets/modules.abc"]);
|
||||
const closed = await client.callTool({
|
||||
name: "close_binary",
|
||||
arguments: {},
|
||||
});
|
||||
expect(closed.isError, JSON.stringify(closed)).not.toBe(true);
|
||||
const empty = await client.callTool({
|
||||
name: "binary_session",
|
||||
arguments: {},
|
||||
});
|
||||
expect(empty.isError, JSON.stringify(empty)).not.toBe(true);
|
||||
expect(empty.structuredContent).toMatchObject({
|
||||
result: { open: false },
|
||||
});
|
||||
expect(await readFile(path)).toEqual(Buffer.from(bytes));
|
||||
}
|
||||
} finally {
|
||||
await client.close();
|
||||
}
|
||||
}, 120_000);
|
||||
@@ -0,0 +1,117 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { copyFile, mkdir, readFile, writeFile } from "node:fs/promises";
|
||||
import { resolve } from "node:path";
|
||||
|
||||
import { expect } from "vitest";
|
||||
|
||||
import { processTest as test } from "../../support/process/processFixture.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
test("generates locked inventory and rejects stale notice metadata or preserved texts", async ({
|
||||
processes,
|
||||
}) => {
|
||||
const root = await createTestTempDirectory("rea-notice-records-");
|
||||
await mkdir(resolve(root, "scripts/lib"), { recursive: true });
|
||||
await mkdir(resolve(root, "licenses"));
|
||||
for (const file of [
|
||||
"scripts/generate-third-party-inventory.mjs",
|
||||
"scripts/lib/generated-file.mjs",
|
||||
])
|
||||
await copyFile(resolve(file), resolve(root, file));
|
||||
const script = resolve(root, "scripts/generate-third-party-inventory.mjs");
|
||||
const runtime = {
|
||||
version: "1.0.0",
|
||||
license: "MIT",
|
||||
resolved:
|
||||
"https://registry.npmjs.org/fixture-runtime/-/fixture-runtime-1.0.0.tgz",
|
||||
integrity: "sha512-fixture-integrity",
|
||||
optional: true,
|
||||
};
|
||||
await writeFile(
|
||||
resolve(root, "package-lock.json"),
|
||||
JSON.stringify({
|
||||
packages: {
|
||||
"": { name: "fixture", version: "1.0.0" },
|
||||
"node_modules/fixture-runtime": runtime,
|
||||
"node_modules/fixture-dev": { ...runtime, dev: true, optional: false },
|
||||
},
|
||||
}),
|
||||
);
|
||||
const generated = await processes.run(process.execPath, [script]);
|
||||
expect(generated.exitCode, generated.stderr).toBe(0);
|
||||
const inventory = await readFile(
|
||||
resolve(root, "licenses/npm-dependencies.txt"),
|
||||
"utf8",
|
||||
);
|
||||
expect(inventory).toContain("Locked package entries: 2; runtime: 1.");
|
||||
expect(inventory).toContain(
|
||||
"fixture-runtime@1.0.0 | runtime, optional | MIT",
|
||||
);
|
||||
expect(inventory).toContain("fixture-dev@1.0.0 | development | MIT");
|
||||
const fingerprint = (
|
||||
JSON.parse(generated.stdout) as { runtime_dependency_fingerprint: string }
|
||||
).runtime_dependency_fingerprint;
|
||||
const notice = [
|
||||
`Runtime dependency fingerprint (SHA-256): ${fingerprint}`,
|
||||
"",
|
||||
"===== fixture-runtime@1.0.0 =====",
|
||||
"Declared license: MIT",
|
||||
`Archive: ${runtime.resolved}`,
|
||||
`Integrity: ${runtime.integrity}`,
|
||||
"",
|
||||
"Fixture text; this test does not establish real package attribution.",
|
||||
"",
|
||||
].join("\n");
|
||||
const noticePath = resolve(root, "licenses/npm-runtime-notices.txt");
|
||||
const referencePath = resolve(root, "licenses/reference.txt");
|
||||
await writeFile(noticePath, notice);
|
||||
await writeFile(referencePath, "preserved fixture text\n");
|
||||
await writeFile(
|
||||
resolve(root, "licenses/upstream-sources.json"),
|
||||
JSON.stringify([
|
||||
{
|
||||
file: "licenses/reference.txt",
|
||||
sha256: createHash("sha256")
|
||||
.update("preserved fixture text\n")
|
||||
.digest("hex"),
|
||||
},
|
||||
]),
|
||||
);
|
||||
const check = () => processes.run(process.execPath, [script, "--check"]);
|
||||
const valid = await check();
|
||||
expect(valid.exitCode, valid.stderr).toBe(0);
|
||||
for (const [changed, diagnostic] of [
|
||||
[
|
||||
notice.replace(
|
||||
"===== fixture-runtime@1.0.0 =====",
|
||||
"===== another-package@1.0.0 =====",
|
||||
),
|
||||
"Missing runtime notice",
|
||||
],
|
||||
[
|
||||
notice.replace(runtime.integrity, "sha512-different"),
|
||||
"Runtime notice metadata differs",
|
||||
],
|
||||
[
|
||||
notice.replace(fingerprint, "0".repeat(64)),
|
||||
"Runtime notice fingerprint differs",
|
||||
],
|
||||
[
|
||||
notice + notice.slice(notice.indexOf("===== ")),
|
||||
"Duplicate runtime notice",
|
||||
],
|
||||
] as const) {
|
||||
await writeFile(noticePath, changed);
|
||||
const rejected = await check();
|
||||
expect(rejected.exitCode).toBe(1);
|
||||
expect(rejected.stderr).toContain(diagnostic);
|
||||
}
|
||||
await writeFile(noticePath, notice);
|
||||
await writeFile(referencePath, "changed fixture text\n");
|
||||
const tampered = await check();
|
||||
expect(tampered.exitCode).toBe(1);
|
||||
expect(tampered.stderr).toContain("Preserved notice digest differs");
|
||||
expect(
|
||||
await readFile(resolve(root, "licenses/npm-dependencies.txt"), "utf8"),
|
||||
).toBe(inventory);
|
||||
});
|
||||
@@ -0,0 +1,35 @@
|
||||
import { expect, it } from "vitest";
|
||||
import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js";
|
||||
import { runSourceMapCommand } from "../../../src/javascript/sourceMaps/SourceMapCommand.js";
|
||||
import { PrivateRuntimeRootUnavailableError } from "../../../src/process/PrivateRuntimeRootUnavailableError.js";
|
||||
|
||||
it.each([false, true])(
|
||||
"preserves private-runtime retryable=%s through the source-map operation",
|
||||
async (retryable) => {
|
||||
const reason = "Native runtime self-test failed with a sharing violation";
|
||||
let launches = 0;
|
||||
const result = await runSourceMapCommand("{}", "/selected.map", undefined, {
|
||||
prepareOwnership: async () => {},
|
||||
createRuntime: async () => {
|
||||
throw new PrivateRuntimeRootUnavailableError(reason, { retryable });
|
||||
},
|
||||
launcher: async () => {
|
||||
launches += 1;
|
||||
throw new Error("A refused runtime must not launch a codec");
|
||||
},
|
||||
});
|
||||
expect(launches).toBe(0);
|
||||
if (result.ok) throw new Error("Unavailable runtime must refuse decoding");
|
||||
expect(projectAnalysisError(result.error)).toMatchObject({
|
||||
code: "capability_unavailable",
|
||||
category: retryable ? "unavailable" : "unsupported_provider",
|
||||
retryable,
|
||||
details: {
|
||||
provider_id: "source-map-decoder",
|
||||
operation: "trace_web_source_location",
|
||||
reason,
|
||||
},
|
||||
});
|
||||
expect(result.error.cleanupIncomplete).toBe(false);
|
||||
},
|
||||
);
|
||||
@@ -69,6 +69,12 @@ const connect = async (
|
||||
|
||||
it("discovers an oversized native dossier by exact metadata and reads its retained view", async () => {
|
||||
const { client, session } = await connect();
|
||||
const advertised = (await client.listTools()).tools.find(
|
||||
(tool) => tool.name === "inspect_analysis_view",
|
||||
);
|
||||
expect(advertised?.description).toContain(
|
||||
'Native function Evidence requires kind native: view: {kind: "native", facet: "procedure"}',
|
||||
);
|
||||
const provider = { id: "ghidra", name: "Ghidra", version: "12.1.4" };
|
||||
const profile = createAnalysisProfile(provider, { language: "fixture" });
|
||||
const parent = createEvidence(
|
||||
@@ -98,6 +104,24 @@ it("discovers an oversized native dossier by exact metadata and reads its retain
|
||||
const retained = session.recordEvidence(record);
|
||||
if (!retained.ok) throw retained.error;
|
||||
}
|
||||
const unsupportedSummary = await client.callTool({
|
||||
name: "inspect_analysis_view",
|
||||
arguments: {
|
||||
source: { kind: "retained-evidence", evidence_id: parent.evidence_id },
|
||||
view: { kind: "summary" },
|
||||
},
|
||||
});
|
||||
expect(parseMcpToolError(unsupportedSummary).error).toMatchObject({
|
||||
code: "invalid_request",
|
||||
details: {
|
||||
issues: [
|
||||
{
|
||||
path: ["view"],
|
||||
message: "analyze_function Evidence requires a native view.",
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
const broad = await client.callTool({
|
||||
name: "get_evidence_bundle",
|
||||
arguments: {},
|
||||
|
||||
@@ -0,0 +1,285 @@
|
||||
import { unlink } from "node:fs/promises";
|
||||
import { Ajv2020 } from "ajv/dist/2020.js";
|
||||
import { expect, it, onTestFinished, vi } from "vitest";
|
||||
import { FlutterBuildAnalysisService } from "../../../src/application/flutter/FlutterBuildAnalysisService.js";
|
||||
import { inspectDartAot } from "../../../src/application/flutter/DartAotInspection.js";
|
||||
import { inspectAnalysisView } from "../../../src/application/analysisView/AnalysisViewService.js";
|
||||
import { createFlutterBuildAnalysisProvider } from "../../../src/composition/flutter.js";
|
||||
import {
|
||||
analysisViewResultSchema,
|
||||
dartAotSummaryViewResultSchema,
|
||||
} from "../../../src/domain/analysisView/analysisView.js";
|
||||
import { createEvidence, parseEvidence } from "../../../src/domain/evidence.js";
|
||||
import { flutterResultSchemas } from "../../../src/domain/flutter/flutterBuildAnalysis.js";
|
||||
import type { JsonValue } from "../../../src/domain/jsonValue.js";
|
||||
import { aotFixtureImage } from "../../../src/flutter/FlutterBuild.fixture.js";
|
||||
import { createFlutterApk } from "../../fixtures/flutterApk.js";
|
||||
import { createApplicationMcpHarness } from "../../fixtures/applicationMcpHarness.js";
|
||||
|
||||
it("honors explicit ABI and old full requests, validates SDK schemas and reuses complete Evidence after APK removal", async () => {
|
||||
const path = await createFlutterApk("views.apk", [
|
||||
{ path: "lib/arm64-v8a/libapp.so", bytes: aotFixtureImage() },
|
||||
{ path: "lib/x86_64/libapp.so", bytes: aotFixtureImage("b".repeat(32)) },
|
||||
]);
|
||||
const provider = createFlutterBuildAnalysisProvider();
|
||||
const execute = vi.spyOn(provider, "execute");
|
||||
const harness = await createApplicationMcpHarness({
|
||||
serverOptions: { flutterAnalysis: provider },
|
||||
});
|
||||
onTestFinished(harness.close);
|
||||
const { client, session } = harness;
|
||||
const catalog = (await client.listTools()).tools;
|
||||
const definition = catalog.find((tool) => tool.name === "inspect_dart_aot");
|
||||
if (definition?.outputSchema === undefined)
|
||||
throw new Error("Missing AOT output schema");
|
||||
const outputSchema: Record<string, unknown> = definition.outputSchema;
|
||||
const ajv = new Ajv2020({ strict: false, validateFormats: false });
|
||||
expect(ajv.validateSchema(definition.inputSchema)).toBe(true);
|
||||
expect(ajv.validateSchema(outputSchema)).toBe(true);
|
||||
expect(
|
||||
ajv.validate(
|
||||
catalog.find((tool) => tool.name === "identify_flutter_build")!
|
||||
.inputSchema,
|
||||
{ path, detail: "summary" },
|
||||
),
|
||||
).toBe(false);
|
||||
const reply = await client.callTool({
|
||||
name: "inspect_dart_aot",
|
||||
arguments: { path, abi: "x86_64", detail: "summary" },
|
||||
});
|
||||
expect(reply.isError).not.toBe(true);
|
||||
expect(
|
||||
ajv.validate(outputSchema, reply.structuredContent),
|
||||
JSON.stringify(ajv.errors),
|
||||
).toBe(true);
|
||||
const receipt = parseEvidence(reply.structuredContent);
|
||||
const view = dartAotSummaryViewResultSchema.parse(receipt.normalized_result);
|
||||
const parent = session.evidenceById(view.parent_evidence_id);
|
||||
if (parent === undefined)
|
||||
throw new Error("Complete AOT source was not retained");
|
||||
const report = flutterResultSchemas.inspect_dart_aot.parse(
|
||||
parent.normalized_result,
|
||||
);
|
||||
expect(report.abi).toBe("x86_64");
|
||||
expect(report.libapp.snapshot_hash).toBe("b".repeat(32));
|
||||
expect(parent.parameters).toEqual({ path, abi: "x86_64" });
|
||||
expect(execute).toHaveBeenLastCalledWith(
|
||||
{ operation: "inspect_dart_aot", input: { path, abi: "x86_64" } },
|
||||
expect.anything(),
|
||||
);
|
||||
expect(view.summary.libapp).toEqual(report.libapp);
|
||||
expect(view.summary.target).toEqual(report.target);
|
||||
expect(view.summary.coverage).toBe(report.coverage);
|
||||
expect(receipt.evidence_id).not.toBe(parent.evidence_id);
|
||||
expect(receipt.evidence_links).toEqual([parent.evidence_id]);
|
||||
for (const detail of [undefined, "complete"]) {
|
||||
const complete = parseEvidence(
|
||||
(
|
||||
await client.callTool({
|
||||
name: "inspect_dart_aot",
|
||||
arguments: {
|
||||
path,
|
||||
abi: "x86_64",
|
||||
...(detail === undefined ? {} : { detail }),
|
||||
},
|
||||
})
|
||||
).structuredContent,
|
||||
);
|
||||
expect(complete.operation).toBe("inspect_dart_aot");
|
||||
expect(complete.normalized_result).toEqual(parent.normalized_result);
|
||||
expect(complete.parameters).toEqual(parent.parameters);
|
||||
}
|
||||
const preferred = parseEvidence(
|
||||
(await client.callTool({ name: "inspect_dart_aot", arguments: { path } }))
|
||||
.structuredContent,
|
||||
);
|
||||
expect(
|
||||
flutterResultSchemas.inspect_dart_aot.parse(preferred.normalized_result)
|
||||
.abi,
|
||||
).toBe("arm64-v8a");
|
||||
const original = JSON.stringify(parent);
|
||||
await unlink(path);
|
||||
const calls = execute.mock.calls.length;
|
||||
for (const collection of [
|
||||
"package_uris",
|
||||
"dart_uris",
|
||||
"class_like_tokens",
|
||||
] as const) {
|
||||
const strings: string[] = [];
|
||||
let offset = 0;
|
||||
do {
|
||||
const reply = await client.callTool({
|
||||
name: "inspect_analysis_view",
|
||||
arguments: {
|
||||
source: {
|
||||
kind: "retained-evidence",
|
||||
evidence_id: parent.evidence_id,
|
||||
},
|
||||
view: { kind: "dart-aot", collection, offset, limit: 1 },
|
||||
},
|
||||
});
|
||||
expect(reply.isError).not.toBe(true);
|
||||
const page = analysisViewResultSchema.parse(
|
||||
parseEvidence(reply.structuredContent).normalized_result,
|
||||
);
|
||||
if (page.kind !== "dart-aot") throw new Error("Wrong pool page kind");
|
||||
strings.push(...page.items);
|
||||
expect(page.libapp).toEqual(report.libapp);
|
||||
expect(page.source_coverage).toBe(report.coverage);
|
||||
expect(page.string_pool.coverage).toBe(report.string_pool.coverage);
|
||||
offset =
|
||||
page.coverage.next_offset ?? report.string_pool[collection].length;
|
||||
} while (offset < report.string_pool[collection].length);
|
||||
expect(strings).toEqual(report.string_pool[collection]);
|
||||
}
|
||||
expect(execute).toHaveBeenCalledTimes(calls);
|
||||
expect(JSON.stringify(session.evidenceById(parent.evidence_id))).toBe(
|
||||
original,
|
||||
);
|
||||
expect(
|
||||
session
|
||||
.exportEvidenceBundle()
|
||||
.records.find((record) => record.evidence_id === parent.evidence_id),
|
||||
).toEqual(parent);
|
||||
const portable = inspectAnalysisView({
|
||||
source: { kind: "inline", evidence: parent },
|
||||
view: { kind: "summary" },
|
||||
});
|
||||
if (!portable.ok) throw portable.error;
|
||||
expect(portable.value.normalized_result).toEqual(view);
|
||||
}, 30000);
|
||||
|
||||
it("preserves null snapshot facts and pool lower bounds after exhaustion, rejecting malformed and conflicting identities", () => {
|
||||
const report = {
|
||||
target: { path: "/source.apk", bytes: 10, sha256: "a".repeat(64) },
|
||||
abi: "arm64-v8a",
|
||||
libapp: {
|
||||
coverage: "partial",
|
||||
bytes: 1,
|
||||
sha256: "b".repeat(64),
|
||||
snapshot_hash: null,
|
||||
snapshot_hash_candidates: [],
|
||||
snapshot_hash_sources: 0,
|
||||
sections: [],
|
||||
},
|
||||
string_pool: {
|
||||
coverage: "partial",
|
||||
package_uris: ["package:opaque/a.dart"],
|
||||
package_uri_count_at_least: 1000,
|
||||
dart_uris: [],
|
||||
dart_uri_count_at_least: 0,
|
||||
class_like_tokens: ["incidental"],
|
||||
class_like_token_count_at_least: 4000,
|
||||
printable_run_count: 12,
|
||||
},
|
||||
coverage: "partial",
|
||||
};
|
||||
const evidence = (
|
||||
result: JsonValue = report,
|
||||
sha: string | null = "a".repeat(64),
|
||||
) =>
|
||||
createEvidence(
|
||||
sha === null
|
||||
? undefined
|
||||
: { path: "/source.apk", sha256: sha, format: "apk" },
|
||||
{ id: "flutter", name: "Flutter", version: null },
|
||||
{
|
||||
operation: "inspect_dart_aot",
|
||||
parameters: {},
|
||||
result,
|
||||
limitations: ["Original uncertainty"],
|
||||
},
|
||||
);
|
||||
for (const parent of [evidence(), evidence(report, null)]) {
|
||||
const summary = inspectAnalysisView({
|
||||
source: { kind: "inline", evidence: parent },
|
||||
view: { kind: "summary" },
|
||||
});
|
||||
if (!summary.ok) throw summary.error;
|
||||
const result = dartAotSummaryViewResultSchema.parse(
|
||||
summary.value.normalized_result,
|
||||
);
|
||||
expect(result.summary.libapp.snapshot_hash).toBeNull();
|
||||
expect(result.summary.string_pool.package_uri_count_at_least).toBe(1000);
|
||||
expect(result.summary.string_pool.returned_counts.package_uris).toBe(1);
|
||||
expect(result.limitations).toEqual(parent.limitations);
|
||||
const page = inspectAnalysisView({
|
||||
source: { kind: "inline", evidence: parent },
|
||||
view: {
|
||||
kind: "dart-aot",
|
||||
collection: "package_uris",
|
||||
offset: 0,
|
||||
limit: 10,
|
||||
},
|
||||
});
|
||||
if (!page.ok) throw page.error;
|
||||
expect(page.value.normalized_result).toMatchObject({
|
||||
kind: "dart-aot",
|
||||
items: report.string_pool.package_uris,
|
||||
source_coverage: "partial",
|
||||
string_pool: { coverage: "partial", package_uri_count_at_least: 1000 },
|
||||
coverage: { total: 1, exhausted: true },
|
||||
});
|
||||
}
|
||||
expect(
|
||||
inspectAnalysisView({
|
||||
source: { kind: "inline", evidence: evidence(report, "c".repeat(64)) },
|
||||
view: { kind: "summary" },
|
||||
}),
|
||||
).toMatchObject({ ok: false, error: { _tag: "EvidenceIntegrityError" } });
|
||||
expect(
|
||||
inspectAnalysisView({
|
||||
source: {
|
||||
kind: "inline",
|
||||
evidence: evidence({
|
||||
...report,
|
||||
string_pool: {
|
||||
...report.string_pool,
|
||||
package_uri_count_at_least: -1,
|
||||
},
|
||||
}),
|
||||
},
|
||||
view: { kind: "summary" },
|
||||
}),
|
||||
).toMatchObject({ ok: false, error: { _tag: "AnalysisInputError" } });
|
||||
expect(
|
||||
inspectAnalysisView({
|
||||
source: { kind: "inline", evidence: evidence() },
|
||||
view: { kind: "android", facet: "manifest", offset: 0, limit: 1 },
|
||||
}),
|
||||
).toMatchObject({ ok: false, error: { _tag: "AnalysisInputError" } });
|
||||
});
|
||||
|
||||
it("rejects unavailable retention, invalid delivery and cancellation before producer work", async () => {
|
||||
const provider = createFlutterBuildAnalysisProvider();
|
||||
onTestFinished(() => provider.close());
|
||||
const execute = vi.spyOn(provider, "execute");
|
||||
const service = new FlutterBuildAnalysisService(provider);
|
||||
const retention = { recordEvidence: undefined, evidenceById: undefined };
|
||||
expect(
|
||||
await inspectDartAot(
|
||||
service,
|
||||
{ path: "/missing.apk", abi: "x86_64", detail: "summary" },
|
||||
retention,
|
||||
),
|
||||
).toMatchObject({
|
||||
ok: false,
|
||||
error: { _tag: "AnalysisCapabilityUnavailableError" },
|
||||
});
|
||||
expect(
|
||||
await inspectDartAot(
|
||||
service,
|
||||
{ path: "/missing.apk", detail: "other" },
|
||||
retention,
|
||||
),
|
||||
).toMatchObject({ ok: false, error: { _tag: "AnalysisInputError" } });
|
||||
expect(
|
||||
await inspectDartAot(
|
||||
service,
|
||||
{ path: "/missing.apk", detail: "summary" },
|
||||
retention,
|
||||
{ signal: AbortSignal.abort() },
|
||||
),
|
||||
).toMatchObject({ ok: false, error: { _tag: "AnalysisCancelledError" } });
|
||||
expect(execute).not.toHaveBeenCalled();
|
||||
});
|
||||
@@ -122,11 +122,18 @@ it("advertises the complete currently available inventory with a session", async
|
||||
|
||||
const listed = await client.listTools();
|
||||
const names = listed.tools.map((t) => t.name);
|
||||
const sessionTool = listed.tools.find(
|
||||
({ name }) => name === "binary_session",
|
||||
);
|
||||
if (sessionTool === undefined)
|
||||
throw new Error("Missing advertised binary_session tool");
|
||||
// Validate this reply with its current advertised schema. The SDK otherwise
|
||||
// builds output validators for the entire catalog on the first cached call.
|
||||
const status = structured(
|
||||
await client.callTool({
|
||||
name: "binary_session",
|
||||
arguments: {},
|
||||
}),
|
||||
await client.callTool(
|
||||
{ name: "binary_session", arguments: {} },
|
||||
{ toolDefinition: sessionTool },
|
||||
),
|
||||
);
|
||||
const inventory = expandToolAvailability(
|
||||
toolContract("binary_session").outputSchema.parse(status).result
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
import { beforeEach, expect, it, vi } from "vitest";
|
||||
import { WindowsPrivateRuntime } from "../../src/windows/WindowsPrivateRuntime.js";
|
||||
import { PrivateRuntimeRootUnavailableError } from "../../src/process/PrivateRuntimeRootUnavailableError.js";
|
||||
|
||||
const { nativeCall } = vi.hoisted(() => ({ nativeCall: vi.fn() }));
|
||||
vi.mock("../../src/windows/WindowsNativeLoader.js", async (original) => ({
|
||||
...(await original<
|
||||
typeof import("../../src/windows/WindowsNativeLoader.js")
|
||||
>()),
|
||||
requireWindowsNativeAuthority: () => ({ call: nativeCall }),
|
||||
}));
|
||||
beforeEach(() => {
|
||||
nativeCall.mockReset();
|
||||
});
|
||||
|
||||
it.each([
|
||||
{
|
||||
label: "sharing conflict before allocation",
|
||||
win32Code: 32,
|
||||
runtimeAllocation: "not-started",
|
||||
retryable: true,
|
||||
},
|
||||
{
|
||||
label: "lock conflict before allocation",
|
||||
win32Code: 33,
|
||||
runtimeAllocation: "not-started",
|
||||
retryable: true,
|
||||
},
|
||||
{ label: "unknown allocation", win32Code: 32, retryable: false },
|
||||
{
|
||||
label: "possible allocation",
|
||||
win32Code: 32,
|
||||
runtimeAllocation: "started",
|
||||
retryable: false,
|
||||
},
|
||||
{
|
||||
label: "permission failure",
|
||||
win32Code: 5,
|
||||
runtimeAllocation: "not-started",
|
||||
retryable: false,
|
||||
},
|
||||
{
|
||||
label: "string code",
|
||||
win32Code: "32",
|
||||
runtimeAllocation: "not-started",
|
||||
retryable: false,
|
||||
},
|
||||
{
|
||||
label: "inconsistent error code",
|
||||
win32Code: 32,
|
||||
code: "EACCES",
|
||||
runtimeAllocation: "not-started",
|
||||
retryable: false,
|
||||
},
|
||||
])(
|
||||
"retains $label without guessing runtime ownership",
|
||||
({ retryable, label: _label, ...facts }) => {
|
||||
const cause = Object.assign(new Error("Selected native diagnostic"), {
|
||||
code: "ERR_REA_WINDOWS_NATIVE",
|
||||
...facts,
|
||||
});
|
||||
nativeCall.mockImplementation(() => {
|
||||
throw cause;
|
||||
});
|
||||
let observed: unknown;
|
||||
try {
|
||||
WindowsPrivateRuntime.create("D:/selected parent", "selected-prefix-");
|
||||
} catch (failure: unknown) {
|
||||
observed = failure;
|
||||
}
|
||||
expect(nativeCall).toHaveBeenCalledTimes(1);
|
||||
expect(nativeCall).toHaveBeenCalledWith("runtime_create", [
|
||||
"D:/selected parent",
|
||||
"selected-prefix-",
|
||||
]);
|
||||
if (retryable) {
|
||||
expect(observed).toBeInstanceOf(PrivateRuntimeRootUnavailableError);
|
||||
expect(observed).toMatchObject({
|
||||
message: cause.message,
|
||||
cause,
|
||||
retryable: true,
|
||||
});
|
||||
} else expect(observed).toBe(cause);
|
||||
},
|
||||
);
|
||||
|
||||
it("does not infer a transient status from a human-readable diagnostic", () => {
|
||||
const cause = new Error("Open Windows path component failed (Win32 32)");
|
||||
nativeCall.mockImplementation(() => {
|
||||
throw cause;
|
||||
});
|
||||
let observed: unknown;
|
||||
try {
|
||||
WindowsPrivateRuntime.create("D:/selected parent", "selected-prefix-");
|
||||
} catch (failure: unknown) {
|
||||
observed = failure;
|
||||
}
|
||||
expect(observed).toBe(cause);
|
||||
});
|
||||
Reference in New Issue
Block a user