refactor(contracts): simplify workflows and drop readiness tool

This commit is contained in:
morluto
2026-09-29 09:22:44 +08:00
parent 0fe96d92df
commit 7acac615ca
37 changed files with 401 additions and 505 deletions
@@ -1,97 +1,156 @@
import { readFile } from "node:fs/promises";
import { describe, expect, it } from "vitest";
import { parse } from "yaml";
import { z } from "zod";
import { packageHopperEnvironment } from "../../../scripts/verify-package-environment.mjs";
const workflowStepSchema = z
.object({
run: z.unknown().optional(),
name: z.unknown().optional(),
env: z.record(z.string(), z.unknown()).optional(),
})
.passthrough();
const workflowSchema = z
.object({
jobs: z.record(
z.string(),
z
.object({
steps: z.array(workflowStepSchema).default([]),
needs: z.union([z.array(z.string()), z.string()]).optional(),
})
.passthrough(),
),
})
.passthrough();
type Workflow = z.output<typeof workflowSchema>;
describe("package installation workflows", () => {
it("runs package E2E without the retired native rebuild script", async () => {
const continuousIntegration = await readFile(
new URL("../../../.github/workflows/ci.yml", import.meta.url),
"utf8",
);
const realHopperLinux = await readFile(
new URL(
"../../../.github/workflows/real-hopper-linux.yml",
import.meta.url,
const continuousIntegration = await readWorkflow("ci.yml");
const realHopperLinux = await readWorkflow("real-hopper-linux.yml");
const realHopperMac = await readWorkflow("real-hopper.yml");
expect(workflowJob(continuousIntegration, "package-e2e")).toMatchObject({
strategy: { matrix: { os: ["ubuntu-latest", "macos-14"] } },
steps: expect.arrayContaining([{ run: "npm run verify:package" }]),
});
expect(
workflowJob(continuousIntegration, "static").steps.map(
({ run }: { readonly run?: unknown }) => run,
),
"utf8",
);
const realHopperMac = await readFile(
new URL("../../../.github/workflows/real-hopper.yml", import.meta.url),
"utf8",
).toContain("npm run check:ci");
expect(workflowJob(continuousIntegration, "test-shard")).toMatchObject({
strategy: { matrix: { shard: ["1/4", "2/4", "3/4", "4/4"] } },
steps: expect.arrayContaining([
{ run: "npm run test:ci:shard:run -- --shard=${{ matrix.shard }}" },
]),
});
const testJob = workflowJob(continuousIntegration, "test");
expect(testJob.needs).toContain("test-shard");
expect(testJob.steps).toEqual(
expect.arrayContaining([
expect.objectContaining({
name: "Require successful test shards",
env: expect.objectContaining({
CODE_REQUIRED: "${{ needs.changes.outputs.code }}",
}),
}),
expect.objectContaining({
run: expect.stringContaining("npm run test:ci:merge"),
}),
]),
);
expect(continuousIntegration).toContain("os: [ubuntu-latest, macos-14]");
expect(continuousIntegration).toContain("npm run verify:package");
expect(continuousIntegration).toContain("name: Static checks");
expect(continuousIntegration).toContain("npm run check:ci");
expect(continuousIntegration).toContain("shard: [1/4, 2/4, 3/4, 4/4]");
expect(continuousIntegration).toContain("name: Build package");
expect(continuousIntegration).toContain("npm run build:cached");
expect(continuousIntegration).toContain("name: rea-dist");
expect(continuousIntegration).toContain("npm run test:ci:shard:run");
expect(continuousIntegration).toContain("needs: [changes, test-shard]");
expect(continuousIntegration).toContain("if-no-files-found: error");
expect(continuousIntegration).toContain("overwrite: true");
expect(continuousIntegration).toContain(
"code: ${{ steps.package.outputs.required }}",
);
expect(continuousIntegration).toContain("CODE_REQUIRED:");
expect(continuousIntegration).toContain(
'test "${CODE_REQUIRED}" != "true" || test "${SHARD_RESULT}" = "success"',
);
expect(continuousIntegration).toContain("npm run test:ci:merge");
expect(continuousIntegration).toContain("needs: changes");
expect(continuousIntegration).toContain(
"cancel-in-progress: ${{ github.event_name == 'pull_request' }}",
);
for (const workflow of [realHopperLinux, realHopperMac]) {
const verifyJob = workflowJob(workflow, "verify");
const verificationStep = verifyJob.steps.find(
({ run }: { readonly run?: unknown }) =>
typeof run === "string" && run.includes("npm run verify:hopper"),
);
expect(
verifyJob.steps.some(
({ run }: { readonly run?: unknown }) =>
typeof run === "string" &&
run.includes("npm install --global --ignore-scripts"),
),
).toBe(true);
expect(verificationStep).toBeDefined();
expect(verificationStep?.env).toMatchObject({
REA_HOPPER_CONFORMANCE_MANIFEST_PATH:
"${{ github.workspace }}/build/conformance/manifest.json",
});
}
for (const workflow of [
continuousIntegration,
realHopperLinux,
realHopperMac,
])
expect(workflow).not.toContain("npm run rebuild:native");
for (const workflow of [realHopperLinux, realHopperMac])
expect(workflow).toContain("npm install --global --ignore-scripts");
for (const workflow of [realHopperLinux, realHopperMac])
expect(workflow).toContain(
"REA_HOPPER_CONFORMANCE_MANIFEST_PATH: ${{ github.workspace }}/build/conformance/manifest.json",
]) {
const commands = Object.values(workflow.jobs).flatMap((job) =>
job.steps.flatMap(({ run }: { readonly run?: unknown }) =>
typeof run === "string" ? [run] : [],
),
);
expect(realHopperLinux).not.toContain("HOPPER_TARGET_PATH");
expect(realHopperLinux).not.toContain("HOPPER_SECOND_TARGET_PATH");
expect(realHopperLinux).not.toContain("first_target");
expect(realHopperLinux).not.toContain("second_target");
expect(commands.join("\n")).not.toContain("npm run rebuild:native");
}
});
it("verifies the package before publish and runs published canaries outside the checkout", async () => {
const release = await readFile(
new URL("../../../.github/workflows/release.yml", import.meta.url),
"utf8",
);
const release = await readWorkflow("release.yml");
const canary = await readFile(
new URL("../../../scripts/verify-published-package.mjs", import.meta.url),
"utf8",
);
expect(release.indexOf("npm run verify:package")).toBeLessThan(
release.indexOf("npm publish --access public"),
const publishJob = workflowJob(release, "publish");
const publishSteps = publishJob.steps;
const verifyPackageIndex = publishSteps.findIndex(
({ run }: { readonly run?: unknown }) => run === "npm run verify:package",
);
const npmPublishIndex = publishSteps.findIndex(
({ run }: { readonly run?: unknown }) =>
run === "npm publish --access public",
);
expect(verifyPackageIndex).toBeGreaterThanOrEqual(0);
expect(npmPublishIndex).toBeGreaterThan(verifyPackageIndex);
const publishedCanary = publishSteps.find(
({ name }: { readonly name?: unknown }) =>
name === "Verify published CLI from npm",
);
expect(publishedCanary?.run).toContain('verification_root="$(mktemp -d)"');
expect(publishedCanary?.run).toContain('cd "${verification_root}"');
expect(publishedCanary?.run).not.toContain(
'npm run verify:published -- "${version}"',
);
expect(release).toContain('verification_root="$(mktemp -d)"');
expect(release).toContain('cd "${verification_root}"');
expect(release).not.toContain('npm run verify:published -- "${version}"');
expect(canary).toContain('mkdtemp(join(tmpdir(), "rea-published-canary-")');
expect(canary).toContain("cwd: canaryRoot");
expect(release).toContain("publish-mcp:");
expect(release).toContain("needs: [release-please, publish]");
expect(release).toContain("MCP_PUBLISHER_VERSION: v1.8.0");
expect(release).toContain("mcp-publisher validate");
expect(release).toContain("mcp-publisher login github-oidc");
expect(release).toContain("mcp-publisher publish");
expect(release).toContain("id-token: write");
expect(release).toContain("contents: read");
expect(release).not.toContain("MCP_GITHUB_TOKEN");
expect(release.indexOf("publish-mcp:")).toBeGreaterThan(
release.indexOf("npm publish --access public"),
const publisherJob = workflowJob(release, "publish-mcp");
const publisherSteps = publisherJob.steps;
expect(publisherJob).toMatchObject({
needs: ["release-please", "publish"],
permissions: { contents: "read", "id-token": "write" },
});
expect(
publisherSteps.map(({ run }: { readonly run?: unknown }) => run),
).toEqual(
expect.arrayContaining([
"./mcp-publisher validate",
"./mcp-publisher login github-oidc",
"./mcp-publisher publish",
]),
);
expect(
publisherSteps.find(
({ name }: { readonly name?: unknown }) =>
name === "Install MCP Registry publisher",
)?.env,
).toMatchObject({
MCP_PUBLISHER_VERSION: "v1.8.0",
MCP_PUBLISHER_SHA256_LINUX_AMD64: expect.any(String),
});
});
it("uses direct Node ownership on macOS and Windows", () => {
@@ -117,3 +176,17 @@ describe("package installation workflows", () => {
});
});
});
async function readWorkflow(path: string) {
const yaml = await readFile(
new URL(`../../../.github/workflows/${path}`, import.meta.url),
"utf8",
);
return workflowSchema.parse(parse(yaml));
}
const workflowJob = (workflow: Workflow, name: string) => {
const value = workflow.jobs[name];
if (value === undefined) throw new Error(`Missing workflow job: ${name}`);
return value;
};
@@ -126,7 +126,6 @@ describe("canonical product catalog", () => {
"compare_javascript_export_shapes",
"compare_source_to_bundle",
"evaluate_reconstruction_coverage",
"evaluate_reconstruction_readiness",
"execute_node_characterization",
"prepare_node_characterization",
"run_controlled_replay",
@@ -1,36 +0,0 @@
import { execFile } from "node:child_process";
import { promisify } from "node:util";
import { describe, expect, it } from "vitest";
import { RECONSTRUCTION_READINESS_EXAMPLE } from "../../../src/contracts/reconstructionReadinessExample.js";
const execute = promisify(execFile);
describe("reconstruction readiness CLI parity", () => {
it("emits the same passing report through the public CLI", async () => {
const { stdout } = await execute(
process.execPath,
[
"scripts/rea.mjs",
"evaluate-reconstruction-readiness",
JSON.stringify(RECONSTRUCTION_READINESS_EXAMPLE),
"--json",
],
{
cwd: process.cwd(),
env: process.env,
maxBuffer: 32 * 1_024 * 1_024,
},
);
expect(JSON.parse(stdout)).toMatchObject({
operation: "evaluate_reconstruction_readiness",
predicate_type: "rea.reconstruction-readiness-report/v1",
normalized_result: {
schema: "ReconstructionReadinessReport",
status: "pass",
summary: { passed_required_stages: 9 },
},
});
}, 20_000);
});
+1 -1
View File
@@ -27,7 +27,7 @@ afterEach(async () => {
});
it(
"exposes CLI-equivalent Evidence v2 and session resources",
"exposes CLI-equivalent Evidence v2 results and session tools",
async () => {
const browser = await startFakeCdpBrowser({
sessionTimeline: "same_origin",
@@ -9,6 +9,8 @@ import { createTestBinarySession } from "../../fixtures/binarySession.js";
import { ARTIFACT_COMPARISON_EXAMPLE } from "../../../src/contracts/artifactComparisonExample.js";
import { PROCESS_CAPTURE_REFERENCE } from "../../../src/contracts/investigationExamples.js";
import { createEvidence } from "../../../src/domain/evidence.js";
import { createArtifactInspection } from "../../../src/domain/artifactInspection.js";
import { jsonValueSchema } from "../../../src/domain/jsonValue.js";
import { createPromptCompletionSource } from "../../../src/server/promptCompletion.js";
import { observed } from "../../fixtures/analysisExecution.js";
@@ -71,8 +73,20 @@ describe("guided prompt completion from investigation records", () => {
confidence: "observed",
authority: "shipped-artifact",
});
const inventoryInspection = createArtifactInspection(
ARTIFACT_COMPARISON_EXAMPLE.left,
);
const inspectionEvidence = createEvidence(undefined, fixtureProvider, {
operation: "inspect_artifact",
parameters: {},
result: jsonValueSchema.parse(inventoryInspection),
confidence: "observed",
authority: "shipped-artifact",
evidenceLinks: inventoryInspection.evidence_links,
});
for (const evidence of [
ARTIFACT_COMPARISON_EXAMPLE.left,
inspectionEvidence,
PROCESS_CAPTURE_REFERENCE,
invalidCapture,
invalidInventory,
@@ -1,47 +0,0 @@
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
import { describe, expect, it } from "vitest";
import { createTestBinarySession } from "../../fixtures/binarySession.js";
import { RECONSTRUCTION_READINESS_EXAMPLE } from "../../../src/contracts/reconstructionReadinessExample.js";
import { createServer } from "../../../src/server/createServer.js";
import { observed } from "../../fixtures/analysisExecution.js";
describe("reconstruction readiness MCP parity", () => {
it("returns the complete passing report inline", async () => {
const session = createTestBinarySession(() => ({
execute: () => Promise.resolve(observed(null)),
close: () => Promise.resolve(),
}));
const server = createServer(session, session);
const client = new Client({ name: "readiness-test", version: "1" });
const [clientTransport, serverTransport] =
InMemoryTransport.createLinkedPair();
try {
await server.connect(serverTransport);
await client.connect(clientTransport);
const result = await client.callTool({
name: "evaluate_reconstruction_readiness",
arguments: RECONSTRUCTION_READINESS_EXAMPLE,
});
expect(result.isError).not.toBe(true);
expect(result.structuredContent).toMatchObject({
evidence_id: expect.stringMatching(/^ev_[a-f0-9]{64}$/u),
result: {
schema: "ReconstructionReadinessReport",
status: "pass",
summary: { passed_required_stages: 9 },
stages: expect.arrayContaining([expect.any(Object)]),
},
});
expect(result.structuredContent).toHaveProperty("result.snapshot");
expect(result.structuredContent).toHaveProperty("result.stages");
expect(result.structuredContent).not.toHaveProperty(
"result.report_resource_uri",
);
} finally {
await client.close();
await server.close();
await session.close();
}
});
});
+2 -3
View File
@@ -241,12 +241,11 @@ describe("live server identity over MCP", () => {
const assertLiveIdentity = async (client: Client): Promise<void> => {
const instructions = client.getInstructions();
expect(instructions?.length).toBeLessThanOrEqual(640);
expect(instructions).toContain(
"ASAR/JavaScript -> analyze_javascript_application",
"For standalone JavaScript or ASAR analysis, use analyze_javascript_application",
);
expect(instructions).toContain(
"native binary/database -> open_binary, then binary_overview",
"For an archive or application package, call open_binary(path), then inspect_artifact",
);
const identity = await client.callTool({
name: "binary_session",
+19 -13
View File
@@ -116,14 +116,12 @@ describe("target-free MCP workflow", () => {
const beforeTools = (await mcp.listTools()).tools;
const beforeNames = beforeTools.map(({ name }) => name);
expect(mcp.getInstructions()).toContain(
"archive/package -> open_binary(path), then inspect_artifact/inventory_artifact",
"For an archive or application package, call open_binary(path), then inspect_artifact",
);
expect(
beforeTools.find(({ name }) => name === "inventory_artifact")
?.description,
).toContain(
"This tool accepts no path; in a target-free session open the target first.",
);
beforeTools.find(({ name }) => name === "inspect_artifact")?.description,
).toContain("Returns the complete content-addressed artifact graph");
expect(beforeNames).not.toContain("inventory_artifact");
expect(beforeNames).toContain("open_binary");
expect(beforeNames).toContain("binary_session");
expect(beforeNames).toContain("current_document");
@@ -132,14 +130,22 @@ describe("target-free MCP workflow", () => {
(await mcp.callTool({ name: "open_binary", arguments: { path: first } }))
.isError,
).not.toBe(true);
const openedStatus = structured(
await mcp.callTool({ name: "binary_session", arguments: {} }),
);
expect(openedStatus).toMatchObject({
result: { path: await realpath(first) },
});
expect(
structured(
await mcp.callTool({
name: "binary_session",
arguments: {},
}),
),
).toMatchObject({ result: { path: await realpath(first) } });
z
.object({
result: z.object({
capabilities: z.array(z.object({ operation: z.string() })),
}),
})
.parse(openedStatus)
.result.capabilities.map(({ operation }) => operation),
).not.toContain("inventory_artifact");
expect(
text(await mcp.callTool({ name: "current_document", arguments: {} })),
).toContain("first.hop");
+4 -4
View File
@@ -29,7 +29,7 @@ fixtures provide metadata-oriented inputs without package
or network dependencies.
`readiness/` adds source-only generated JavaScript CLI and Electron fixtures for
the public reconstruction-readiness journey. `npm run verify:readiness` combines
them with the compiled native fixtures, exercises CLI and MCP parity, and emits
the versioned machine-readable readiness report documented in
`docs/reconstruction-readiness.md`.
the repository's reconstruction-readiness verifier. `npm run verify:readiness`
combines them with the compiled native fixtures, exercises CLI and MCP parity
for real analysis operations, and checks the internal machine-readable report
documented in `docs/reconstruction-readiness.md`.
@@ -1,41 +1,25 @@
import { readFile } from "node:fs/promises";
import { describe, expect, it } from "vitest";
import {
generateLargeFixture,
HOPPER_C_ORACLE,
LARGE_FIXTURE_COUNT,
sha256,
sourceDigest,
} from "../../../scripts/lib/conformance-fixtures.mjs";
describe("source-built conformance fixtures", () => {
it("grounds the Hopper semantic oracle in the source-owned C fixture", async () => {
const source = await readFile("tests/conformance/c/fixture.c", "utf8");
for (const procedure of [
HOPPER_C_ORACLE.mainProcedure,
HOPPER_C_ORACLE.entryProcedure,
HOPPER_C_ORACLE.branchProcedure,
HOPPER_C_ORACLE.leafProcedure,
])
expect(source).toContain(`int ${procedure}`);
expect(source).toContain(HOPPER_C_ORACLE.entryString);
expect(source).toContain(HOPPER_C_ORACLE.leafString);
expect(source).toContain(HOPPER_C_ORACLE.globalName);
});
it("generates a deterministic large complete-inventory fixture", () => {
it("generates deterministic large-fixture source", () => {
const first = generateLargeFixture();
const second = generateLargeFixture();
expect(first).toBe(second);
expect(first.match(/int rea_inventory_/gu)).toHaveLength(
LARGE_FIXTURE_COUNT,
);
expect(first).toContain("rea_inventory_0000");
expect(first).toContain("rea_inventory_1204");
expect(() => generateLargeFixture(0)).toThrow(/positive integer/u);
expect(first).toContain(
`rea_inventory_${String(LARGE_FIXTURE_COUNT - 1).padStart(4, "0")}`,
);
expect(() => generateLargeFixture(0)).toThrow(
"Fixture count must be a positive integer",
);
});
it("hashes source manifests independently of input ordering", () => {
+1 -1
View File
@@ -19,7 +19,7 @@ describe("CLI operation status", () => {
};
await expect(
logCliCommand(silentLogger, "inventory-artifact", () =>
logCliCommand(silentLogger, "inspect-artifact", () =>
Promise.resolve(output),
),
).resolves.toBe(output);