fix: align MCP archive contracts and documentation (#2478)
Reuse the domain ZIP format list for session schemas, verify full Harmony CLI/MCP lifecycles, and correct native view guidance and audited docs drift. Refresh locked dependency notices and gate inventory/provenance consistency, including notice inputs in the cached documentation gate. Fixes #2454 Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
parent
a6efa4fcef
commit
a86deecac5
@@ -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);
|
||||
});
|
||||
@@ -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: {},
|
||||
|
||||
Reference in New Issue
Block a user