mirror of
https://github.com/morluto/rea.git
synced 2026-11-17 04:04:25 +00:00
* feat(harmony): project HarmonyOS package inventory evidence First HarmonyOS increment from #1431: HAP, HSP, and App Pack roots are classified through the hardened ZIP reader and projected into an execution-free application graph with packaging-model hints, exact component paths and hashes, App Pack children by path, runtime-family hints, and path-based N-API bridge hypotheses. HarmonyOS .har stays unclassified by suffix because .har also names HTTP Archive JSON. Adds the project_harmony_application_graph tool (CLI and MCP), synthetic composition coverage, a pinned real-package verify lane, and docs. * refactor(domain): share application graph projection scaffolding The HarmonyOS projection mirrors the Android and Apple projections by design, which pushed jscpd duplication over its 2.5 percent budget. Extract the identical pieces (inventory input schema, projected component schema and occurrence flattening, bridge candidate schema factory, coverage assembly, comparator, canonical digest) into domain/mobileApplicationGraphProjection.ts and route all three projections plus the composition fixtures through it. Duplication drops from 2.52 to 2.49 percent with no behavior change: projection ids, classifications, and limitations are byte-identical. * fix(harmony): address review, stable app-pack roots, and rotated fixture - rebased onto main; the shared projection scaffolding now keeps main's nativeRuntimeConvention loop and the harmony runtime families adopt the same react-native/flutter/unity path conventions - the .app App Pack suffix is now a root-input rule only (verified ZIP magic in classifyRootFormat and BinaryTargetResolver); nested .app ZIP members inside other packages keep the generic zip classification, with a regression test, so existing inventories do not change - the signing limitation now states that an empty signing list does not mean unsigned because packaging-tool signatures live in the ZIP signing block, and the app-pack root rule is disclosed as suffix-based - repinned the real-package fixture to the current VHome 2.6.14-beta asset after the upstream deleted v5.0.111-beta and replaced the v2.6.14-beta asset within hours; the pin records both observed digests --------- Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
150 lines
5.1 KiB
TypeScript
150 lines
5.1 KiB
TypeScript
import { writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
|
|
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
|
import {
|
|
TextReader,
|
|
Uint8ArrayReader,
|
|
Uint8ArrayWriter,
|
|
ZipWriter,
|
|
} from "@zip.js/zip.js";
|
|
import { afterEach, expect, it } from "vitest";
|
|
|
|
import { createDirectAnalysis } from "../../../src/composition/directAnalysis.js";
|
|
import { parseEvidence } from "../../../src/domain/evidence.js";
|
|
import { createTestBinarySession } from "../../fixtures/binarySession.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
import { createServer } from "../../../src/server/createServer.js";
|
|
|
|
const { runProviderAnalysis } = createDirectAnalysis({});
|
|
|
|
const resources: Array<{ close(): Promise<unknown> }> = [];
|
|
afterEach(async () => {
|
|
for (const resource of resources.splice(0)) await resource.close();
|
|
});
|
|
|
|
async function connect() {
|
|
const session = createTestBinarySession(() => {
|
|
throw new Error("mobile graph projection must not launch a provider");
|
|
});
|
|
const server = createServer({ kind: "session", session });
|
|
const client = new Client({
|
|
name: "mobile-application-graph-test",
|
|
version: "1",
|
|
});
|
|
resources.push(client, server, session);
|
|
const [a, b] = InMemoryTransport.createLinkedPair();
|
|
await server.connect(b);
|
|
await client.connect(a);
|
|
return client;
|
|
}
|
|
|
|
const writeApk = async (directory: string): Promise<string> => {
|
|
const path = join(directory, "Fixture.apk");
|
|
const writer = new ZipWriter(new Uint8ArrayWriter());
|
|
await writer.add(
|
|
"AndroidManifest.xml",
|
|
new Uint8ArrayReader(Uint8Array.from([3, 0, 8, 0])),
|
|
);
|
|
await writer.add(
|
|
"classes.dex",
|
|
new Uint8ArrayReader(
|
|
Uint8Array.from([0x64, 0x65, 0x78, 0x0a, 0x30, 0x33, 0x35, 0]),
|
|
),
|
|
);
|
|
await writeFile(path, await writer.close());
|
|
return path;
|
|
};
|
|
|
|
const writeIpa = async (directory: string): Promise<string> => {
|
|
const path = join(directory, "Fixture.ipa");
|
|
const writer = new ZipWriter(new Uint8ArrayWriter());
|
|
await writer.add(
|
|
"Payload/Fixture.app/Info.plist",
|
|
new TextReader("<plist></plist>"),
|
|
);
|
|
await writer.add(
|
|
"Payload/Fixture.app/Fixture",
|
|
new Uint8ArrayReader(
|
|
Uint8Array.from([0xcf, 0xfa, 0xed, 0xfe, 0x0c, 0, 0, 1]),
|
|
),
|
|
);
|
|
await writeFile(path, await writer.close());
|
|
return path;
|
|
};
|
|
|
|
it("advertises and executes Android and Apple inventory projections", async () => {
|
|
const client = await connect();
|
|
const { tools } = await client.listTools();
|
|
const names = new Set(tools.map(({ name }) => name));
|
|
expect(names.has("project_android_application_graph")).toBe(true);
|
|
expect(names.has("project_apple_application_graph")).toBe(true);
|
|
|
|
const root = await createTestTempDirectory("rea-mobile-graph-mcp-");
|
|
const apkInventory = parseEvidence(
|
|
await runProviderAnalysis(await writeApk(root), "inventory_artifact", {}),
|
|
);
|
|
const android = await client.callTool({
|
|
name: "project_android_application_graph",
|
|
arguments: { inventory_evidence: [apkInventory] },
|
|
});
|
|
if (android.isError === true)
|
|
throw new Error(JSON.stringify(android, null, 2));
|
|
expect(android.structuredContent).toMatchObject({
|
|
operation: "project_android_application_graph",
|
|
provider: { id: "rea-android-application" },
|
|
});
|
|
|
|
const ipaInventory = parseEvidence(
|
|
await runProviderAnalysis(await writeIpa(root), "inventory_artifact", {}),
|
|
);
|
|
const apple = await client.callTool({
|
|
name: "project_apple_application_graph",
|
|
arguments: { inventory_evidence: [ipaInventory] },
|
|
});
|
|
if (apple.isError === true) throw new Error(JSON.stringify(apple, null, 2));
|
|
expect(apple.structuredContent).toMatchObject({
|
|
operation: "project_apple_application_graph",
|
|
provider: { id: "rea-apple-application" },
|
|
});
|
|
});
|
|
|
|
it("retains Harmony unavailable components and their source Evidence through MCP", async () => {
|
|
const client = await connect();
|
|
const root = await createTestTempDirectory("rea-harmony-graph-mcp-");
|
|
const path = join(root, "Locked.hap");
|
|
const writer = new ZipWriter(new Uint8ArrayWriter());
|
|
await writer.add("module.json", new TextReader("{}"));
|
|
await writer.add("ets/modules.abc", new TextReader("opaque bytecode"), {
|
|
password: "fixture-only",
|
|
});
|
|
await writeFile(path, await writer.close());
|
|
const inventory = parseEvidence(
|
|
await runProviderAnalysis(path, "inventory_artifact", {}),
|
|
);
|
|
const reply = await client.callTool({
|
|
name: "project_harmony_application_graph",
|
|
arguments: { inventory_evidence: [inventory] },
|
|
});
|
|
if (reply.isError === true) throw new Error(JSON.stringify(reply));
|
|
const evidence = parseEvidence(reply.structuredContent);
|
|
expect(evidence.normalized_result).toMatchObject({
|
|
unavailable_components: [
|
|
expect.objectContaining({
|
|
path: "ets/modules.abc",
|
|
artifact_id: null,
|
|
sha256: null,
|
|
encrypted: true,
|
|
}),
|
|
],
|
|
coverage: { status: "partial", inventory_complete: true },
|
|
});
|
|
const bundle = await client.callTool({
|
|
name: "get_evidence_bundle",
|
|
arguments: {},
|
|
});
|
|
expect(bundle.structuredContent).toMatchObject({
|
|
result: { records: expect.arrayContaining([inventory, evidence]) },
|
|
});
|
|
});
|