Merge branch 'main' into codex/fix-flaky-integration-tests
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
import { mkdtemp, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
import {
|
||||
TextReader,
|
||||
Uint8ArrayReader,
|
||||
Uint8ArrayWriter,
|
||||
ZipWriter,
|
||||
} from "@zip.js/zip.js";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { projectAndroidApplicationEvidence } from "../src/application/AndroidApplicationService.js";
|
||||
import { runProviderAnalysis } from "../src/application/DirectAnalysis.js";
|
||||
import { androidApplicationProjectionResultSchema } from "../src/domain/androidApplication.js";
|
||||
import { parseEvidence } from "../src/domain/evidence.js";
|
||||
|
||||
describe("Android application projection", () => {
|
||||
it("projects deterministic APK components and explicit bridge hypotheses", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-android-"));
|
||||
const path = join(root, "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 writer.add(
|
||||
"lib/arm64-v8a/libreactnativejni.so",
|
||||
new Uint8ArrayReader(
|
||||
Uint8Array.from([0x7f, 0x45, 0x4c, 0x46, 2, 1, 1, 0]),
|
||||
),
|
||||
);
|
||||
await writer.add("assets/index.js", new TextReader("bridge();"));
|
||||
await writer.add("META-INF/FIXTURE.RSA", new TextReader("opaque signing"));
|
||||
await writeFile(path, await writer.close());
|
||||
|
||||
const inventory = parseEvidence(
|
||||
await runProviderAnalysis(path, "inventory_artifact", {
|
||||
node_limit: 500,
|
||||
occurrence_limit: 500,
|
||||
edge_limit: 500,
|
||||
}),
|
||||
);
|
||||
const first = projectAndroidApplicationEvidence({
|
||||
inventory_evidence: [inventory],
|
||||
limits: { max_components: 100 },
|
||||
});
|
||||
const second = projectAndroidApplicationEvidence({
|
||||
inventory_evidence: [inventory],
|
||||
limits: { max_components: 100 },
|
||||
});
|
||||
expect(first.ok).toBe(true);
|
||||
expect(second.ok).toBe(true);
|
||||
if (!first.ok || !second.ok) return;
|
||||
const left = androidApplicationProjectionResultSchema.parse(
|
||||
first.value.normalized_result,
|
||||
);
|
||||
const right = androidApplicationProjectionResultSchema.parse(
|
||||
second.value.normalized_result,
|
||||
);
|
||||
expect(left).toEqual(right);
|
||||
expect(left).toMatchObject({
|
||||
root_format: "apk",
|
||||
coverage: {
|
||||
status: "complete-within-inventory",
|
||||
inventory_complete: true,
|
||||
omitted_components: 0,
|
||||
},
|
||||
});
|
||||
expect(left.components.manifests).toHaveLength(1);
|
||||
expect(left.components.dex).toHaveLength(1);
|
||||
expect(left.components.native_libraries).toHaveLength(1);
|
||||
expect(left.components.javascript).toHaveLength(1);
|
||||
expect(left.components.signing).toHaveLength(1);
|
||||
expect(left.runtime_families).toEqual(
|
||||
expect.arrayContaining([
|
||||
"dalvik-art",
|
||||
"javascript",
|
||||
"native",
|
||||
"react-native",
|
||||
]),
|
||||
);
|
||||
expect(left.bridge_candidates).toEqual([
|
||||
expect.objectContaining({ basis: "react-native-convention" }),
|
||||
]);
|
||||
expect(JSON.stringify(left)).not.toContain("opaque signing");
|
||||
});
|
||||
|
||||
it("rejects non-APK inventory Evidence", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-android-invalid-"));
|
||||
const path = join(root, "fixture.zip");
|
||||
const writer = new ZipWriter(new Uint8ArrayWriter());
|
||||
await writer.add("one.js", new TextReader("one"));
|
||||
await writeFile(path, await writer.close());
|
||||
const inventory = parseEvidence(
|
||||
await runProviderAnalysis(path, "inventory_artifact", {}),
|
||||
);
|
||||
expect(
|
||||
projectAndroidApplicationEvidence({ inventory_evidence: [inventory] }),
|
||||
).toMatchObject({
|
||||
ok: false,
|
||||
error: { _tag: "AnalysisInputError" },
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,151 @@
|
||||
import { mkdtemp, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
import {
|
||||
TextReader,
|
||||
Uint8ArrayReader,
|
||||
Uint8ArrayWriter,
|
||||
ZipWriter,
|
||||
} from "@zip.js/zip.js";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { projectAppleApplicationEvidence } from "../src/application/AppleApplicationService.js";
|
||||
import { runProviderAnalysis } from "../src/application/DirectAnalysis.js";
|
||||
import { appleApplicationProjectionResultSchema } from "../src/domain/appleApplication.js";
|
||||
import { parseEvidence } from "../src/domain/evidence.js";
|
||||
|
||||
describe("Apple application projection", () => {
|
||||
it("projects deterministic IPA components and bridge hypotheses from exact inventory Evidence", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-apple-"));
|
||||
const path = join(root, "Fixture.ipa");
|
||||
const writer = new ZipWriter(new Uint8ArrayWriter());
|
||||
await writer.add("Payload/Fixture.app/", undefined, { directory: true });
|
||||
await writer.add(
|
||||
"Payload/Fixture.app/Info.plist",
|
||||
new TextReader("<plist><dict/></plist>"),
|
||||
);
|
||||
await writer.add(
|
||||
"Payload/Fixture.app/Fixture",
|
||||
new Uint8ArrayReader(
|
||||
Uint8Array.from([0xcf, 0xfa, 0xed, 0xfe, 0x0c, 0, 0, 1]),
|
||||
),
|
||||
);
|
||||
await writer.add(
|
||||
"Payload/Fixture.app/Frameworks/React.framework/React",
|
||||
new Uint8ArrayReader(
|
||||
Uint8Array.from([0xcf, 0xfa, 0xed, 0xfe, 0x0c, 0, 0, 1]),
|
||||
),
|
||||
);
|
||||
await writer.add(
|
||||
"Payload/Fixture.app/main.js",
|
||||
new TextReader("bridge.call();"),
|
||||
);
|
||||
await writer.add(
|
||||
"Payload/Fixture.app/embedded.mobileprovision",
|
||||
new TextReader("opaque signing bytes"),
|
||||
);
|
||||
await writeFile(path, await writer.close());
|
||||
|
||||
const inventory = parseEvidence(
|
||||
await runProviderAnalysis(path, "inventory_artifact", {
|
||||
node_limit: 500,
|
||||
occurrence_limit: 500,
|
||||
edge_limit: 500,
|
||||
}),
|
||||
);
|
||||
const first = projectAppleApplicationEvidence({
|
||||
inventory_evidence: [inventory],
|
||||
limits: { max_components: 100 },
|
||||
});
|
||||
const second = projectAppleApplicationEvidence({
|
||||
inventory_evidence: [inventory],
|
||||
limits: { max_components: 100 },
|
||||
});
|
||||
expect(first.ok).toBe(true);
|
||||
expect(second.ok).toBe(true);
|
||||
if (!first.ok || !second.ok) return;
|
||||
const left = appleApplicationProjectionResultSchema.parse(
|
||||
first.value.normalized_result,
|
||||
);
|
||||
const right = appleApplicationProjectionResultSchema.parse(
|
||||
second.value.normalized_result,
|
||||
);
|
||||
expect(left).toEqual(right);
|
||||
expect(left).toMatchObject({
|
||||
root_format: "ipa",
|
||||
application_roots: ["Payload/Fixture.app"],
|
||||
coverage: {
|
||||
status: "complete-within-inventory",
|
||||
inventory_complete: true,
|
||||
omitted_components: 0,
|
||||
},
|
||||
});
|
||||
expect(left.components.bundle_metadata).toHaveLength(1);
|
||||
expect(left.components.executables.length).toBeGreaterThanOrEqual(2);
|
||||
expect(left.components.frameworks).toHaveLength(1);
|
||||
expect(left.components.javascript).toHaveLength(1);
|
||||
expect(left.components.signing).toHaveLength(1);
|
||||
expect(left.runtime_families).toEqual(
|
||||
expect.arrayContaining(["javascript", "native", "react-native"]),
|
||||
);
|
||||
expect(left.bridge_candidates).toEqual([
|
||||
expect.objectContaining({
|
||||
basis: "javascript-and-native-content",
|
||||
native_path: "Payload/Fixture.app/Fixture",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
basis: "react-native-convention",
|
||||
native_path: "Payload/Fixture.app/Frameworks/React.framework/React",
|
||||
}),
|
||||
]);
|
||||
expect(JSON.stringify(left)).not.toContain("opaque signing bytes");
|
||||
});
|
||||
|
||||
it("rejects non-IPA Evidence and reports projection truncation", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-apple-invalid-"));
|
||||
const path = join(root, "fixture.zip");
|
||||
const writer = new ZipWriter(new Uint8ArrayWriter());
|
||||
await writer.add("one.js", new TextReader("one"));
|
||||
await writeFile(path, await writer.close());
|
||||
const inventory = parseEvidence(
|
||||
await runProviderAnalysis(path, "inventory_artifact", {}),
|
||||
);
|
||||
expect(
|
||||
projectAppleApplicationEvidence({ inventory_evidence: [inventory] }),
|
||||
).toMatchObject({
|
||||
ok: false,
|
||||
error: { _tag: "AnalysisInputError" },
|
||||
});
|
||||
});
|
||||
|
||||
it("infers an application root when the IPA omits directory entries", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-apple-root-"));
|
||||
const path = join(root, "Fixture.ipa");
|
||||
const writer = new ZipWriter(new Uint8ArrayWriter());
|
||||
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());
|
||||
|
||||
const inventory = parseEvidence(
|
||||
await runProviderAnalysis(path, "inventory_artifact", {}),
|
||||
);
|
||||
const result = projectAppleApplicationEvidence({
|
||||
inventory_evidence: [inventory],
|
||||
});
|
||||
expect(result.ok).toBe(true);
|
||||
if (!result.ok) return;
|
||||
expect(
|
||||
appleApplicationProjectionResultSchema.parse(
|
||||
result.value.normalized_result,
|
||||
),
|
||||
).toMatchObject({
|
||||
application_roots: ["Payload/Fixture.app"],
|
||||
components: { executables: [expect.any(Object)] },
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { projectBoundedCartesian } from "../src/domain/boundedCartesianProjection.js";
|
||||
|
||||
describe("bounded Cartesian projection", () => {
|
||||
it("stops projection work at the output limit", () => {
|
||||
const values = Array.from({ length: 10_000 }, (_, index) => index);
|
||||
let projections = 0;
|
||||
|
||||
const result = projectBoundedCartesian(values, values, 3, (left, right) => {
|
||||
projections += 1;
|
||||
return [left, right] as const;
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
values: [
|
||||
[0, 0],
|
||||
[0, 1],
|
||||
[0, 2],
|
||||
],
|
||||
omitted: 100_000_000 - 3,
|
||||
});
|
||||
expect(projections).toBe(3);
|
||||
});
|
||||
});
|
||||
@@ -55,7 +55,7 @@ describe("browser MCP tools", () => {
|
||||
);
|
||||
const status = await connected.client.callTool({
|
||||
name: "binary_session",
|
||||
arguments: {},
|
||||
arguments: { detail: "full" },
|
||||
});
|
||||
expect(status.structuredContent).toMatchObject({
|
||||
result: {
|
||||
|
||||
+34
-19
@@ -55,7 +55,9 @@ describe("interactive setup journey", () => {
|
||||
expect(result.output).toContain("Found 1 supported agent");
|
||||
expect(result.output).toContain("Codex");
|
||||
expect(result.output).toContain("Hopper deep-analysis provider (provider)");
|
||||
expect(result.output).toContain("REA reverse-engineering skill (skill)");
|
||||
expect(result.output).toContain(
|
||||
"Agent integration (MCP + guided workflow)",
|
||||
);
|
||||
expect(result.output).toContain(
|
||||
"Keys: ↑/↓ navigate · Space toggle · Enter confirm · Ctrl-C cancel",
|
||||
);
|
||||
@@ -65,8 +67,12 @@ describe("interactive setup journey", () => {
|
||||
it("does not turn available capabilities into selected setup actions", async () => {
|
||||
const result = await runJourney([step("What should REA set up?", "\r")]);
|
||||
|
||||
expect(result.output).toContain("Coding-agent access (MCP)");
|
||||
expect(result.output).toContain("REA reverse-engineering skill (skill)");
|
||||
expect(result.output).toContain(
|
||||
"Agent integration (MCP + guided workflow)",
|
||||
);
|
||||
expect(result.output).not.toContain(
|
||||
"REA reverse-engineering skill (skill)",
|
||||
);
|
||||
expect(result.output).toContain("Hopper deep-analysis provider (provider)");
|
||||
expect(result.output).not.toContain("Ready to review");
|
||||
expect(result.output).toContain("Nothing selected. No changes were made.");
|
||||
@@ -76,7 +82,7 @@ describe("interactive setup journey", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("omits MCP access when no agent integration needs configuration", async () => {
|
||||
it("offers one bundled repair when MCP is aligned but the skill is missing", async () => {
|
||||
const result = await runJourney(
|
||||
[step("What should REA set up?", "\r")],
|
||||
false,
|
||||
@@ -84,7 +90,12 @@ describe("interactive setup journey", () => {
|
||||
);
|
||||
|
||||
expect(result.output).toContain("No agent integrations need configuration");
|
||||
expect(result.output).not.toContain("Coding-agent access (MCP)");
|
||||
expect(result.output).toContain(
|
||||
"Agent integration (MCP + guided workflow)",
|
||||
);
|
||||
expect(result.output).not.toContain(
|
||||
"REA reverse-engineering skill (skill)",
|
||||
);
|
||||
expect(result.decision.selectedActionIds).toEqual([]);
|
||||
});
|
||||
|
||||
@@ -112,7 +123,7 @@ describe("interactive setup journey", () => {
|
||||
expect(result.decision.approved).toBe(false);
|
||||
});
|
||||
|
||||
it("asks for agent targets only after MCP access is selected", async () => {
|
||||
it("asks for agent targets only after agent integration is selected", async () => {
|
||||
const result = await runJourney([
|
||||
step("What should REA set up?", " \r"),
|
||||
step("Which agents should use REA?", "\u0003"),
|
||||
@@ -127,15 +138,13 @@ describe("interactive setup journey", () => {
|
||||
const result = await runJourney([
|
||||
step("What should REA set up?", " \r"),
|
||||
step("Which agents should use REA?", " \r"),
|
||||
step("Apply this change?", "\r"),
|
||||
step("Apply these 2 changes?", "\r"),
|
||||
]);
|
||||
|
||||
expect(result.output).toContain("Ready to review");
|
||||
expect(result.output).toContain("CREATE Codex");
|
||||
expect(result.output).toContain("/isolated/.codex/config.toml");
|
||||
expect(result.output).not.toContain(
|
||||
"INSTALL REA reverse-engineering skill",
|
||||
);
|
||||
expect(result.output).toContain("INSTALL REA reverse-engineering skill");
|
||||
expect(result.output).not.toContain(
|
||||
"INSTALL Hopper deep-analysis provider",
|
||||
);
|
||||
@@ -143,17 +152,24 @@ describe("interactive setup journey", () => {
|
||||
expect(result.output).toContain("Setup cancelled. No changes were made.");
|
||||
expect(result.decision).toEqual({
|
||||
approved: false,
|
||||
selectedActionIds: ["configure_client:codex"],
|
||||
selectedActionIds: ["configure_client:codex", "install_skill"],
|
||||
});
|
||||
});
|
||||
|
||||
it("can select the shared skill without selecting an agent integration", async () => {
|
||||
const result = await runJourney([
|
||||
step("What should REA set up?", "\u001b[B \r"),
|
||||
step("Apply this change?", "\r"),
|
||||
]);
|
||||
it("repairs an aligned agent integration through the bundled option", async () => {
|
||||
const result = await runJourney(
|
||||
[
|
||||
step("What should REA set up?", " \r"),
|
||||
step("Apply this change?", "\r"),
|
||||
],
|
||||
false,
|
||||
actions.filter(({ kind }) => kind !== "configure_client"),
|
||||
);
|
||||
|
||||
expect(result.output).toContain("INSTALL REA reverse-engineering skill");
|
||||
expect(result.output).toContain(
|
||||
"Agent integration (MCP + guided workflow)",
|
||||
);
|
||||
expect(result.output).not.toContain("CREATE Codex");
|
||||
expect(result.output).not.toContain(
|
||||
"INSTALL Hopper deep-analysis provider",
|
||||
@@ -167,8 +183,7 @@ describe("interactive setup journey", () => {
|
||||
it("keeps every accessible capability prompt defaulted to skip", async () => {
|
||||
const result = await runJourney(
|
||||
[
|
||||
step("Set up Coding-agent access (MCP)?", "\r"),
|
||||
step("Set up REA reverse-engineering skill (skill)?", "\r"),
|
||||
step("Set up Agent integration (MCP + guided workflow)?", "\r"),
|
||||
step("Set up Hopper deep-analysis provider (provider)?", "\r"),
|
||||
],
|
||||
true,
|
||||
@@ -213,7 +228,7 @@ describe("interactive setup journey", () => {
|
||||
expect(stderr).toContain("Guided reverse-engineering workflows: installed");
|
||||
expect(stderr).toContain("CLI: rea analyze /path/to/app");
|
||||
expect(stderr).toContain(
|
||||
'Try in Codex: "Use REA to explain how a feature works in /path/to/app."',
|
||||
'Try in Codex: "Explain how a feature works in /path/to/app and show the evidence."',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,6 +5,7 @@ import { join } from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { readClientRegistrationStatuses } from "../src/application/ClientRegistrationStatus.js";
|
||||
import { PRODUCT_IDENTITY } from "../src/identity.js";
|
||||
|
||||
describe("client registration status", () => {
|
||||
it("distinguishes aligned, stale, missing, and invalid registrations", async () => {
|
||||
@@ -17,7 +18,7 @@ describe("client registration status", () => {
|
||||
]);
|
||||
await writeFile(
|
||||
join(home, ".codex/config.toml"),
|
||||
'[mcp_servers.rea]\ncommand = "npx"\nargs = ["-y", "rea-agents@latest", "mcp"]\n',
|
||||
`[mcp_servers.rea]\ncommand = "npx"\nargs = ["-y", "${PRODUCT_IDENTITY.registrationPackageSpecifier}", "mcp"]\nstartup_timeout_sec = 30\n`,
|
||||
);
|
||||
await writeFile(
|
||||
join(home, ".cursor/mcp.json"),
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { evaluateCodexEvents } from "../src/evaluation/CodexAgentEval.js";
|
||||
|
||||
describe("Codex agent release evaluation", () => {
|
||||
it("measures natural routing, repeated calls, tokens, and epistemic completion", () => {
|
||||
const call = {
|
||||
id: "item-tool-1",
|
||||
type: "mcp_tool_call",
|
||||
server: "rea",
|
||||
tool: "analyze_javascript_application",
|
||||
arguments: { input_path: "/tmp/app", approved: true },
|
||||
};
|
||||
const metrics = evaluateCodexEvents(
|
||||
[
|
||||
{ type: "item.completed", item: call },
|
||||
{ type: "item.completed", item: call },
|
||||
{
|
||||
type: "item.completed",
|
||||
item: {
|
||||
id: "item-message-1",
|
||||
type: "agent_message",
|
||||
text: "The observed artifact evidence identifies one preload API. Runtime reachability remains unknown because no runtime authority was available.",
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "turn.completed",
|
||||
usage: {
|
||||
input_tokens: 12_345,
|
||||
cached_input_tokens: 10_000,
|
||||
output_tokens: 321,
|
||||
},
|
||||
},
|
||||
],
|
||||
"analyze_javascript_application",
|
||||
);
|
||||
|
||||
expect(metrics).toMatchObject({
|
||||
naturalUse: true,
|
||||
correctFirstTool: true,
|
||||
firstTool: "analyze_javascript_application",
|
||||
repeatedCallCount: 0,
|
||||
inputTokens: 12_345,
|
||||
cachedInputTokens: 10_000,
|
||||
outputTokens: 321,
|
||||
completionQuality: true,
|
||||
authorityHonesty: true,
|
||||
});
|
||||
expect(metrics.reaCalls).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("requires the final answer to cite produced Evidence when requested", () => {
|
||||
const evidenceId = `ev_${"a".repeat(64)}`;
|
||||
const events = [
|
||||
{
|
||||
type: "item.completed",
|
||||
item: {
|
||||
id: "item-tool",
|
||||
type: "mcp_tool_call",
|
||||
server: "rea",
|
||||
tool: "inspect_managed_artifact",
|
||||
arguments: { path: "/tmp/app.dll" },
|
||||
result: { evidence_id: evidenceId },
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "item.completed",
|
||||
item: {
|
||||
type: "agent_message",
|
||||
text: `The observed managed metadata is supported by evidence ${evidenceId}; runtime behavior remains unknown without runtime authority.`,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
expect(
|
||||
evaluateCodexEvents(events, "inspect_managed_artifact", {
|
||||
requireEvidence: true,
|
||||
}),
|
||||
).toMatchObject({
|
||||
evidenceIds: [evidenceId],
|
||||
finalCitesEvidence: true,
|
||||
completionQuality: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("flags identical calls with distinct item identities", () => {
|
||||
const event = (id: string) => ({
|
||||
type: "item.completed",
|
||||
item: {
|
||||
id,
|
||||
type: "mcp_tool_call",
|
||||
server: "rea",
|
||||
tool: "binary_session",
|
||||
arguments: {},
|
||||
},
|
||||
});
|
||||
|
||||
expect(
|
||||
evaluateCodexEvents([event("item-1"), event("item-2")], "binary_session")
|
||||
.repeatedCallCount,
|
||||
).toBe(1);
|
||||
});
|
||||
|
||||
it("requires scenario-specific answer facts when configured", () => {
|
||||
const event = (text: string) => [
|
||||
{
|
||||
type: "item.completed",
|
||||
item: {
|
||||
type: "mcp_tool_call",
|
||||
server: "rea",
|
||||
tool: "analyze_javascript_application",
|
||||
arguments: {},
|
||||
},
|
||||
},
|
||||
{ type: "item.completed", item: { type: "agent_message", text } },
|
||||
];
|
||||
const options = {
|
||||
requiredAnswerTermGroups: [["profileApi"], ["preload", "contextBridge"]],
|
||||
};
|
||||
|
||||
expect(
|
||||
evaluateCodexEvents(
|
||||
event(
|
||||
"Observed evidence connects profileApi through the preload bridge; runtime behavior remains unknown without authority.",
|
||||
),
|
||||
"analyze_javascript_application",
|
||||
options,
|
||||
),
|
||||
).toMatchObject({ contentCriteriaMet: true, completionQuality: true });
|
||||
expect(
|
||||
evaluateCodexEvents(
|
||||
event(
|
||||
"Observed artifact evidence is available, but application behavior remains unknown without more authority and detail.",
|
||||
),
|
||||
"analyze_javascript_application",
|
||||
options,
|
||||
),
|
||||
).toMatchObject({ contentCriteriaMet: false, completionQuality: false });
|
||||
});
|
||||
|
||||
it("recognizes Codex MCP failed status when the error field is null", () => {
|
||||
const metrics = evaluateCodexEvents(
|
||||
[
|
||||
{
|
||||
type: "item.completed",
|
||||
item: {
|
||||
id: "item-failed",
|
||||
type: "mcp_tool_call",
|
||||
server: "rea",
|
||||
tool: "analyze_javascript_application",
|
||||
arguments: { input_path: "/tmp/app.asar", approved: true },
|
||||
result: { structured_content: { error: { code: "denied" } } },
|
||||
error: null,
|
||||
status: "failed",
|
||||
},
|
||||
},
|
||||
],
|
||||
"analyze_javascript_application",
|
||||
);
|
||||
|
||||
expect(metrics.reaCalls[0]?.error).toBe(true);
|
||||
});
|
||||
});
|
||||
+57
-11
@@ -5,6 +5,7 @@ import { pathToFileURL } from "node:url";
|
||||
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { z } from "zod";
|
||||
|
||||
import { BinarySession } from "../src/application/BinarySession.js";
|
||||
import { loadConfiguredPermissionAuthority } from "../src/application/PermissionConfiguration.js";
|
||||
@@ -109,9 +110,17 @@ describe("Electron MCP tools", () => {
|
||||
});
|
||||
const analyzed = await client.callTool({
|
||||
name: "analyze_javascript_application",
|
||||
arguments: { input_path: root, approved: true },
|
||||
arguments: { input_path: root, approved: true, detail: "full" },
|
||||
});
|
||||
expect(analyzed.isError).not.toBe(true);
|
||||
expect(analyzed.structuredContent).toMatchObject({
|
||||
result: { graph: { nodes: expect.any(Array), edges: expect.any(Array) } },
|
||||
});
|
||||
const analysisText = analyzed.content.find(({ type }) => type === "text");
|
||||
expect(analysisText).toBeDefined();
|
||||
if (analysisText?.type !== "text")
|
||||
throw new TypeError("Missing JavaScript analysis text projection");
|
||||
expect(analysisText.text).not.toContain('"nodes":[');
|
||||
const reconciled = await client.callTool({
|
||||
name: "reconcile_javascript_runtime",
|
||||
arguments: {
|
||||
@@ -213,18 +222,55 @@ describe("Electron MCP tools", () => {
|
||||
});
|
||||
|
||||
expect(analyzed.isError).not.toBe(true);
|
||||
expect(analyzed.structuredContent).toMatchObject({
|
||||
result: {
|
||||
schema_version: 1,
|
||||
input_path: expect.stringMatching(/rea-electron-static-mcp-/u),
|
||||
summary: {
|
||||
browser_windows: 3,
|
||||
context_bridge_apis: 2,
|
||||
ipc: { paired_renderer_transmissions: 4 },
|
||||
},
|
||||
graph: { schema: "JavaScriptApplicationGraph", schema_version: 1 },
|
||||
const projected = z
|
||||
.object({
|
||||
evidence_id: z.string(),
|
||||
result: z.object({
|
||||
schema_version: z.literal(1),
|
||||
input_path: z.string(),
|
||||
unknowns: z.array(z.string()),
|
||||
summary: z.object({
|
||||
browser_windows: z.number(),
|
||||
context_bridge_apis: z.number(),
|
||||
ipc: z.object({ paired_renderer_transmissions: z.number() }),
|
||||
}),
|
||||
graph: z.object({
|
||||
graph_id: z.string(),
|
||||
node_count: z.number(),
|
||||
edge_count: z.number(),
|
||||
top_findings: z.array(z.unknown()),
|
||||
pages: z.object({ nodes: z.string(), edges: z.string() }),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
.parse(analyzed.structuredContent);
|
||||
expect(projected.result).toMatchObject({
|
||||
input_path: expect.stringMatching(/rea-electron-static-mcp-/u),
|
||||
summary: {
|
||||
browser_windows: 3,
|
||||
context_bridge_apis: 2,
|
||||
ipc: { paired_renderer_transmissions: 4 },
|
||||
},
|
||||
});
|
||||
expect(projected.result.graph.node_count).toBeGreaterThan(0);
|
||||
expect(JSON.stringify(analyzed.structuredContent)).not.toContain(
|
||||
'"nodes":[',
|
||||
);
|
||||
|
||||
const nodePage = await client.readResource({
|
||||
uri: projected.result.graph.pages.nodes,
|
||||
});
|
||||
const nodeContent = nodePage.contents[0];
|
||||
if (nodeContent === undefined || !("text" in nodeContent))
|
||||
throw new TypeError("Missing JavaScript application graph node page");
|
||||
expect(JSON.parse(nodeContent.text)).toMatchObject({
|
||||
evidence_id: projected.evidence_id,
|
||||
graph_id: projected.result.graph.graph_id,
|
||||
collection: "nodes",
|
||||
items: expect.any(Array),
|
||||
offset: 0,
|
||||
limit: 100,
|
||||
});
|
||||
});
|
||||
|
||||
const evidenceFor = (session: BinarySession, value: unknown) => {
|
||||
|
||||
@@ -231,7 +231,7 @@ describe("Ghidra MCP and shared CLI composition", () => {
|
||||
|
||||
const status = await mcp.callTool({
|
||||
name: "binary_session",
|
||||
arguments: {},
|
||||
arguments: { detail: "full" },
|
||||
});
|
||||
expect(status.structuredContent).toMatchObject({
|
||||
result: {
|
||||
|
||||
@@ -6,7 +6,7 @@ import { z } from "zod";
|
||||
import { PRODUCT_IDENTITY } from "../src/identity.js";
|
||||
|
||||
describe("package identity", () => {
|
||||
it("keeps the manifest, executable, and latest MCP command aligned", async () => {
|
||||
it("keeps the manifest, executable, and pinned MCP command aligned", async () => {
|
||||
const packageJson = z
|
||||
.object({
|
||||
name: z.string(),
|
||||
@@ -34,8 +34,11 @@ describe("package identity", () => {
|
||||
expect(PRODUCT_IDENTITY.packageSpecifier).toBe(
|
||||
`${packageJson.name}@latest`,
|
||||
);
|
||||
expect(PRODUCT_IDENTITY.registrationPackageSpecifier).toBe(
|
||||
`${packageJson.name}@${PRODUCT_IDENTITY.packageVersion}`,
|
||||
);
|
||||
expect(PRODUCT_IDENTITY.mcpCommand).toBe(
|
||||
`npx -y ${packageJson.name}@latest mcp`,
|
||||
`npx -y ${packageJson.name}@${PRODUCT_IDENTITY.packageVersion} mcp`,
|
||||
);
|
||||
expect(packageJson.scripts.start).toBe("node scripts/rea.mjs mcp");
|
||||
expect(packageJson.scripts.prepare).toBe("npm run build && husky");
|
||||
|
||||
@@ -154,14 +154,10 @@ describe("managed artifact MCP tools", () => {
|
||||
},
|
||||
});
|
||||
|
||||
await client.callTool({
|
||||
name: "open_binary",
|
||||
arguments: { path },
|
||||
});
|
||||
const inspected = structured(
|
||||
await client.callTool({
|
||||
name: "inspect_managed_artifact",
|
||||
arguments: { reference_limit: 1 },
|
||||
arguments: { path, reference_limit: 1 },
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
@@ -27,4 +27,24 @@ describe("package installation workflows", () => {
|
||||
for (const workflow of [realHopperLinux, realHopperMac])
|
||||
expect(workflow).toContain("npm install --global --ignore-scripts");
|
||||
});
|
||||
|
||||
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 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"),
|
||||
);
|
||||
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");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,247 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
runPairedProcessExperiment,
|
||||
type ProcessCapturePort,
|
||||
} from "../src/application/ProcessPairedExperiment.js";
|
||||
import { EMPTY_PROCESS_CAPTURE_EXAMPLE } from "../src/contracts/processCaptureExample.js";
|
||||
import { parseProcessCapture } from "../src/domain/processCapture.js";
|
||||
import {
|
||||
analyzeProcessRepeatability,
|
||||
bindProcessScenario,
|
||||
processPairedExperimentSchema,
|
||||
} from "../src/domain/processPairedExperiment.js";
|
||||
import { ok } from "../src/domain/result.js";
|
||||
|
||||
const experiment = () =>
|
||||
processPairedExperimentSchema.parse({
|
||||
approved: true,
|
||||
shared_scenario: {
|
||||
approved: true,
|
||||
executable: "/bin/template",
|
||||
arguments: ["shared"],
|
||||
working_directory: "/tmp",
|
||||
environment: { SHARED: "yes" },
|
||||
},
|
||||
authority: {
|
||||
id: "authority",
|
||||
executable: "/bin/authority",
|
||||
environment: { SIDE: "authority" },
|
||||
},
|
||||
candidate: {
|
||||
id: "candidate",
|
||||
executable: "/bin/candidate",
|
||||
arguments: ["candidate"],
|
||||
environment: { SIDE: "candidate" },
|
||||
},
|
||||
repeat_count: 3,
|
||||
freshness_policy: { max_capture_age_ms: 60_000 },
|
||||
required_dimensions: [
|
||||
"terminal",
|
||||
"interaction",
|
||||
"exit",
|
||||
"filesystem",
|
||||
"protocol",
|
||||
"process",
|
||||
"shim",
|
||||
],
|
||||
});
|
||||
|
||||
const policy = {
|
||||
enabled: true,
|
||||
executableRoots: ["/bin"],
|
||||
workingRoots: ["/tmp"],
|
||||
allowedEnvironment: ["SHARED", "SIDE"],
|
||||
allowExternalNetwork: false,
|
||||
};
|
||||
|
||||
describe("paired process experiments", () => {
|
||||
it("binds only declared side inputs onto the shared observation contract", () => {
|
||||
const parsed = experiment();
|
||||
const authority = bindProcessScenario(
|
||||
parsed.shared_scenario,
|
||||
parsed.authority,
|
||||
);
|
||||
const candidate = bindProcessScenario(
|
||||
parsed.shared_scenario,
|
||||
parsed.candidate,
|
||||
);
|
||||
expect(authority).toMatchObject({
|
||||
executable: "/bin/authority",
|
||||
arguments: ["shared"],
|
||||
environment: { SHARED: "yes", SIDE: "authority" },
|
||||
});
|
||||
expect(candidate).toMatchObject({
|
||||
executable: "/bin/candidate",
|
||||
arguments: ["candidate"],
|
||||
environment: { SHARED: "yes", SIDE: "candidate" },
|
||||
});
|
||||
});
|
||||
|
||||
it("runs same-side comparisons first and compares stable sides", async () => {
|
||||
const observedExecutables: string[] = [];
|
||||
const capture = parseProcessCapture(EMPTY_PROCESS_CAPTURE_EXAMPLE);
|
||||
const capturePort: ProcessCapturePort = {
|
||||
capture: (scenario) => {
|
||||
observedExecutables.push(scenario.executable);
|
||||
return Promise.resolve(ok(structuredClone(capture)));
|
||||
},
|
||||
};
|
||||
const result = await runPairedProcessExperiment(experiment(), policy, {
|
||||
capturePort,
|
||||
now: () => Date.parse("2026-01-01T00:00:01.000Z"),
|
||||
});
|
||||
expect(result.ok).toBe(true);
|
||||
if (!result.ok) return;
|
||||
expect(observedExecutables).toEqual([
|
||||
"/bin/authority",
|
||||
"/bin/authority",
|
||||
"/bin/authority",
|
||||
"/bin/candidate",
|
||||
"/bin/candidate",
|
||||
"/bin/candidate",
|
||||
]);
|
||||
expect(result.value.authority_repeatability.stable).toBe(true);
|
||||
expect(result.value.candidate_repeatability.stable).toBe(true);
|
||||
expect(result.value.cross_side?.status).toBe("unchanged");
|
||||
});
|
||||
|
||||
it("blocks cross-side claims when a candidate has a flaky exit", async () => {
|
||||
const base = parseProcessCapture(EMPTY_PROCESS_CAPTURE_EXAMPLE);
|
||||
let candidateRun = 0;
|
||||
const capturePort: ProcessCapturePort = {
|
||||
capture: (scenario) => {
|
||||
let capture = structuredClone(base);
|
||||
if (scenario.executable === "/bin/candidate") {
|
||||
candidateRun += 1;
|
||||
if (candidateRun === 2)
|
||||
capture = {
|
||||
...capture,
|
||||
exit: { code: 1, signal: null, reason: "exited" },
|
||||
};
|
||||
}
|
||||
return Promise.resolve(ok(capture));
|
||||
},
|
||||
};
|
||||
const result = await runPairedProcessExperiment(experiment(), policy, {
|
||||
capturePort,
|
||||
now: () => Date.parse("2026-01-01T00:00:01.000Z"),
|
||||
});
|
||||
expect(result.ok).toBe(true);
|
||||
if (!result.ok) return;
|
||||
expect(result.value.candidate_repeatability).toMatchObject({
|
||||
stable: false,
|
||||
classification: "flaky_exit",
|
||||
unstable_dimensions: ["exit"],
|
||||
});
|
||||
expect(result.value.cross_side).toBeNull();
|
||||
expect(result.value.cross_side_blocked_reason).toMatch(/unstable/u);
|
||||
});
|
||||
|
||||
it("distinguishes normalized timing variance from semantic output drift", () => {
|
||||
const base = parseProcessCapture(EMPTY_PROCESS_CAPTURE_EXAMPLE);
|
||||
const early = {
|
||||
...base,
|
||||
frames: [{ sequence: 0, at_ms: 10, data: "ready" }],
|
||||
};
|
||||
const late = {
|
||||
...base,
|
||||
frames: [{ sequence: 0, at_ms: 20, data: "ready" }],
|
||||
};
|
||||
expect(
|
||||
analyzeProcessRepeatability([early, late], ["terminal"]),
|
||||
).toMatchObject({
|
||||
stable: false,
|
||||
classification: "timing_variance",
|
||||
unstable_dimensions: ["terminal"],
|
||||
});
|
||||
const changed = {
|
||||
...base,
|
||||
frames: [{ sequence: 0, at_ms: 20, data: "failed" }],
|
||||
};
|
||||
expect(
|
||||
analyzeProcessRepeatability([early, changed], ["terminal"]),
|
||||
).toMatchObject({ classification: "nondeterministic_output" });
|
||||
});
|
||||
|
||||
it("stops before capture when the experiment is cancelled", async () => {
|
||||
const controller = new AbortController();
|
||||
controller.abort();
|
||||
const capturePort: ProcessCapturePort = {
|
||||
capture: () => {
|
||||
throw new Error("capture must not start after cancellation");
|
||||
},
|
||||
};
|
||||
|
||||
const result = await runPairedProcessExperiment(experiment(), policy, {
|
||||
capturePort,
|
||||
signal: controller.signal,
|
||||
});
|
||||
|
||||
expect(result).toMatchObject({
|
||||
ok: false,
|
||||
error: { _tag: "ProcessCaptureError", reason: "cancelled" },
|
||||
});
|
||||
});
|
||||
|
||||
it("blocks full cross-side output when only a subset was repeatable", async () => {
|
||||
const capture = parseProcessCapture(EMPTY_PROCESS_CAPTURE_EXAMPLE);
|
||||
const capturePort: ProcessCapturePort = {
|
||||
capture: () => Promise.resolve(ok(structuredClone(capture))),
|
||||
};
|
||||
const subset = processPairedExperimentSchema.parse({
|
||||
...experiment(),
|
||||
required_dimensions: ["exit"],
|
||||
});
|
||||
|
||||
const result = await runPairedProcessExperiment(subset, policy, {
|
||||
capturePort,
|
||||
});
|
||||
|
||||
expect(result).toMatchObject({
|
||||
ok: true,
|
||||
value: {
|
||||
cross_side: null,
|
||||
cross_side_blocked_reason: expect.stringMatching(/every returned/u),
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("compares the newest stable captures under the freshness policy", async () => {
|
||||
const base = parseProcessCapture(EMPTY_PROCESS_CAPTURE_EXAMPLE);
|
||||
let captureIndex = 0;
|
||||
const capturePort: ProcessCapturePort = {
|
||||
capture: () => {
|
||||
const completedAt =
|
||||
captureIndex === 0
|
||||
? "2026-01-01T00:00:00.000Z"
|
||||
: "2026-01-01T00:00:09.500Z";
|
||||
captureIndex += 1;
|
||||
return Promise.resolve(
|
||||
ok({
|
||||
...structuredClone(base),
|
||||
manifest: {
|
||||
...base.manifest,
|
||||
started_at: completedAt,
|
||||
completed_at: completedAt,
|
||||
},
|
||||
}),
|
||||
);
|
||||
},
|
||||
};
|
||||
const shortFreshness = processPairedExperimentSchema.parse({
|
||||
...experiment(),
|
||||
freshness_policy: { max_capture_age_ms: 1_000 },
|
||||
});
|
||||
|
||||
const result = await runPairedProcessExperiment(shortFreshness, policy, {
|
||||
capturePort,
|
||||
now: () => Date.parse("2026-01-01T00:00:10.000Z"),
|
||||
});
|
||||
|
||||
expect(result).toMatchObject({
|
||||
ok: true,
|
||||
value: { cross_side: { status: "unchanged" } },
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -54,7 +54,10 @@ describe("provider selection over MCP", () => {
|
||||
await mcp.connect(clientTransport);
|
||||
|
||||
const before = structured(
|
||||
await mcp.callTool({ name: "binary_session", arguments: {} }),
|
||||
await mcp.callTool({
|
||||
name: "binary_session",
|
||||
arguments: { detail: "full" },
|
||||
}),
|
||||
);
|
||||
expect(before.result).toMatchObject({
|
||||
open: false,
|
||||
@@ -117,7 +120,10 @@ describe("provider selection over MCP", () => {
|
||||
expect(starts).toEqual(["beta"]);
|
||||
|
||||
const status = structured(
|
||||
await mcp.callTool({ name: "binary_session", arguments: {} }),
|
||||
await mcp.callTool({
|
||||
name: "binary_session",
|
||||
arguments: { detail: "full" },
|
||||
}),
|
||||
);
|
||||
expect(status.result).toMatchObject({
|
||||
open: true,
|
||||
@@ -140,8 +146,12 @@ describe("provider selection over MCP", () => {
|
||||
error: { details: { selection_reason: "unknown_provider" } },
|
||||
});
|
||||
expect(
|
||||
structured(await mcp.callTool({ name: "binary_session", arguments: {} }))
|
||||
.result,
|
||||
structured(
|
||||
await mcp.callTool({
|
||||
name: "binary_session",
|
||||
arguments: { detail: "full" },
|
||||
}),
|
||||
).result,
|
||||
).toMatchObject({
|
||||
analysis_provider_binding: { provider: { id: "beta" } },
|
||||
});
|
||||
|
||||
@@ -15,6 +15,7 @@ import { BROWSER_TOOL_CONTRACTS } from "../src/contracts/browserToolContracts.js
|
||||
import { ELECTRON_TOOL_CONTRACTS } from "../src/contracts/electronToolContracts.js";
|
||||
import { APPLICATION_TOOL_CONTRACTS } from "../src/contracts/applicationToolContracts.js";
|
||||
import { SUPPORTED_CLIENT_DEFINITIONS } from "../src/application/SupportedClients.js";
|
||||
import { PRODUCT_IDENTITY } from "../src/identity.js";
|
||||
|
||||
const readmes = [
|
||||
"README.md",
|
||||
@@ -57,14 +58,15 @@ describe("localized README product facts", () => {
|
||||
"keeps commands and requirements aligned in %s",
|
||||
async (path) => {
|
||||
const content = await readFile(resolve(path), "utf8");
|
||||
expect(content).toContain("npx skills add morluto/rea");
|
||||
expect(content).toContain(
|
||||
"curl -fsSL https://raw.githubusercontent.com/morluto/rea/main/install.sh | bash",
|
||||
);
|
||||
expect(content).toContain("npx rea-agents setup");
|
||||
expect(content).toContain("npx -y rea-agents@latest doctor");
|
||||
expect(content).toContain("rea uninstall");
|
||||
expect(content).toContain('"args": ["-y", "rea-agents@latest", "mcp"]');
|
||||
expect(content).toContain(
|
||||
`"args": ["-y", "${PRODUCT_IDENTITY.registrationPackageSpecifier}", "mcp"]`,
|
||||
);
|
||||
expect(content).toContain("Node.js 22");
|
||||
expect(content).toContain("macOS 12");
|
||||
expect(content).toContain("Ubuntu 24.04");
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
import { mkdtemp, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
import {
|
||||
TextReader,
|
||||
Uint8ArrayReader,
|
||||
Uint8ArrayWriter,
|
||||
ZipWriter,
|
||||
} from "@zip.js/zip.js";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { runProviderAnalysis } from "../src/application/DirectAnalysis.js";
|
||||
import { parseEvidence } from "../src/domain/evidence.js";
|
||||
import {
|
||||
identifyRuntimes,
|
||||
runtimeIdentificationResultSchema,
|
||||
} from "../src/domain/runtimeIdentification.js";
|
||||
|
||||
describe("runtime identification", () => {
|
||||
it("identifies APK runtime families and exposes missing semantic providers", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-runtime-"));
|
||||
const path = join(root, "Fixture.apk");
|
||||
const writer = new ZipWriter(new Uint8ArrayWriter());
|
||||
await writer.add(
|
||||
"AndroidManifest.xml",
|
||||
new Uint8ArrayReader(Uint8Array.from([3, 0, 8, 0, 8, 0, 0, 0])),
|
||||
);
|
||||
await writer.add(
|
||||
"classes.dex",
|
||||
new Uint8ArrayReader(
|
||||
Uint8Array.from([...Buffer.from("dex\n035\0"), 0, 0, 0, 0]),
|
||||
),
|
||||
);
|
||||
await writer.add(
|
||||
"assets/Fixture.class",
|
||||
new Uint8ArrayReader(
|
||||
Uint8Array.from([0xca, 0xfe, 0xba, 0xbe, 0, 0, 0, 61]),
|
||||
),
|
||||
);
|
||||
await writer.add(
|
||||
"assets/module.wasm",
|
||||
new Uint8ArrayReader(Uint8Array.from([0, 0x61, 0x73, 0x6d, 1, 0, 0, 0])),
|
||||
);
|
||||
await writer.add("assets/main.js", new TextReader("bridge.call();"));
|
||||
await writer.add(
|
||||
"lib/arm64-v8a/libfixture.so",
|
||||
new Uint8ArrayReader(
|
||||
Uint8Array.from([0x7f, 0x45, 0x4c, 0x46, 2, 1, 1, 0]),
|
||||
),
|
||||
);
|
||||
await writeFile(path, await writer.close());
|
||||
|
||||
const inventory = parseEvidence(
|
||||
await runProviderAnalysis(path, "inventory_artifact", {
|
||||
node_limit: 100,
|
||||
occurrence_limit: 100,
|
||||
edge_limit: 100,
|
||||
}),
|
||||
);
|
||||
const first = identifyRuntimes({ inventory_evidence: [inventory] });
|
||||
const second = identifyRuntimes({ inventory_evidence: [inventory] });
|
||||
expect(first).toEqual(second);
|
||||
expect(runtimeIdentificationResultSchema.parse(first)).toMatchObject({
|
||||
root_format: "apk",
|
||||
coverage: {
|
||||
status: "complete-within-inventory",
|
||||
inventory_complete: true,
|
||||
omitted_observations: 0,
|
||||
},
|
||||
});
|
||||
expect(first.runtimes.map(({ family }) => family)).toEqual([
|
||||
"android",
|
||||
"javascript",
|
||||
"jvm",
|
||||
"native",
|
||||
"webassembly",
|
||||
]);
|
||||
expect(first.runtimes).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
family: "android",
|
||||
inspection: "available",
|
||||
provider_id: "rea-android-application",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
family: "jvm",
|
||||
inspection: "provider-missing",
|
||||
provider_id: null,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
family: "webassembly",
|
||||
inspection: "provider-missing",
|
||||
provider_id: null,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
family: "javascript",
|
||||
inspection: "available",
|
||||
provider_id: "rea-javascript-application",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
family: "native",
|
||||
inspection: "provider-selection-required",
|
||||
provider_id: null,
|
||||
}),
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
it("reports bounded runtime-observation truncation", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-runtime-limit-"));
|
||||
const path = join(root, "Fixture.apk");
|
||||
const writer = new ZipWriter(new Uint8ArrayWriter());
|
||||
await writer.add("one.js", new TextReader("one"));
|
||||
await writer.add("two.js", new TextReader("two"));
|
||||
await writeFile(path, await writer.close());
|
||||
const inventory = parseEvidence(
|
||||
await runProviderAnalysis(path, "inventory_artifact", {}),
|
||||
);
|
||||
const result = identifyRuntimes({
|
||||
inventory_evidence: [inventory],
|
||||
limits: { max_observations: 1 },
|
||||
});
|
||||
expect(result.coverage).toMatchObject({
|
||||
status: "truncated",
|
||||
omitted_observations: expect.any(Number),
|
||||
});
|
||||
expect(result.coverage.omitted_observations).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("does not route nested DEX content to the APK-only provider", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-runtime-dex-"));
|
||||
const path = join(root, "Fixture.zip");
|
||||
const writer = new ZipWriter(new Uint8ArrayWriter());
|
||||
await writer.add(
|
||||
"classes.dex",
|
||||
new Uint8ArrayReader(
|
||||
Uint8Array.from([...Buffer.from("dex\n035\0"), 0, 0, 0, 0]),
|
||||
),
|
||||
);
|
||||
await writeFile(path, await writer.close());
|
||||
|
||||
const inventory = parseEvidence(
|
||||
await runProviderAnalysis(path, "inventory_artifact", {}),
|
||||
);
|
||||
const result = identifyRuntimes({ inventory_evidence: [inventory] });
|
||||
|
||||
expect(result.runtimes).toContainEqual(
|
||||
expect.objectContaining({
|
||||
family: "android",
|
||||
inspection: "provider-selection-required",
|
||||
provider_id: null,
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -8,6 +8,7 @@ import { CATALOG_IDENTITY, CLI_COMMAND_NAMES } from "../src/catalogIdentity.js";
|
||||
import { PACKAGE_METADATA } from "../src/generatedPackageMetadata.js";
|
||||
import { PRODUCT_IDENTITY, SDK_IDENTITY } from "../src/identity.js";
|
||||
import { TOOL_CONTRACTS } from "../src/contracts/toolContracts.js";
|
||||
import { TOOL_KINDS } from "../src/contracts/toolContractTypes.js";
|
||||
import { createServer } from "../src/server/createServer.js";
|
||||
import { createServerIdentity } from "../src/serverIdentity.js";
|
||||
import { observed } from "./fixtures/analysisExecution.js";
|
||||
@@ -142,6 +143,16 @@ describe("server and catalog identity", () => {
|
||||
try {
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
const instructions = client.getInstructions();
|
||||
expect(instructions?.length).toBeLessThanOrEqual(512);
|
||||
expect(instructions).toContain(
|
||||
"ASAR/JavaScript -> analyze_javascript_application",
|
||||
);
|
||||
expect(instructions).toContain(
|
||||
"native binary/database -> open_binary, then binary_overview",
|
||||
);
|
||||
expect(instructions).toContain("Never repeat identical analysis");
|
||||
expect(instructions).toContain("cite Evidence IDs");
|
||||
const resource = await client.readResource({
|
||||
uri: "rea://server/identity",
|
||||
});
|
||||
@@ -158,7 +169,10 @@ describe("server and catalog identity", () => {
|
||||
});
|
||||
const status = await client.callTool({
|
||||
name: "binary_session",
|
||||
arguments: { expected_package_version: "1.2.0" },
|
||||
arguments: {
|
||||
detail: "full",
|
||||
expected_package_version: "1.2.0",
|
||||
},
|
||||
});
|
||||
expect(status.structuredContent).toMatchObject({
|
||||
result: {
|
||||
@@ -196,6 +210,67 @@ describe("server and catalog identity", () => {
|
||||
},
|
||||
},
|
||||
});
|
||||
const summary = await client.callTool({
|
||||
name: "binary_session",
|
||||
arguments: { expected_package_version: "1.2.0" },
|
||||
});
|
||||
expect(summary.structuredContent).toMatchObject({
|
||||
result: {
|
||||
view: "summary",
|
||||
open: false,
|
||||
target: null,
|
||||
alignment: { state: "mcp_server_restart_required" },
|
||||
recommended_actions: expect.any(Array),
|
||||
},
|
||||
});
|
||||
expect(JSON.stringify(summary.structuredContent)).not.toContain(
|
||||
"tool_availability",
|
||||
);
|
||||
const capabilities = await client.callTool({
|
||||
name: "binary_session",
|
||||
arguments: {
|
||||
detail: "capabilities",
|
||||
capability_family: "browser-provider",
|
||||
cursor: 0,
|
||||
limit: 1,
|
||||
},
|
||||
});
|
||||
expect(capabilities.structuredContent).toMatchObject({
|
||||
result: {
|
||||
view: "capabilities",
|
||||
capability_family: "browser-provider",
|
||||
capabilities: {
|
||||
items: [expect.objectContaining({ surface: "browser-provider" })],
|
||||
cursor: 0,
|
||||
limit: 1,
|
||||
total: expect.any(Number),
|
||||
next_cursor: expect.any(Number),
|
||||
has_more: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
for (const capabilityFamily of TOOL_KINDS) {
|
||||
const familyCapabilities = await client.callTool({
|
||||
name: "binary_session",
|
||||
arguments: {
|
||||
detail: "capabilities",
|
||||
capability_family: capabilityFamily,
|
||||
limit: 100,
|
||||
},
|
||||
});
|
||||
expect(familyCapabilities.structuredContent).toMatchObject({
|
||||
result: {
|
||||
view: "capabilities",
|
||||
capability_family: capabilityFamily,
|
||||
capabilities: {
|
||||
items: expect.arrayContaining([
|
||||
expect.objectContaining({ surface: capabilityFamily }),
|
||||
]),
|
||||
total: expect.any(Number),
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
await client.callTool({ name: "close_binary", arguments: {} });
|
||||
await expect.poll(() => toolListChanges).toBeGreaterThan(0);
|
||||
} finally {
|
||||
|
||||
@@ -86,7 +86,10 @@ describe("target-free MCP lifecycle", () => {
|
||||
.object({ result: z.object({ path: z.string(), sha256: z.string() }) })
|
||||
.parse(
|
||||
structured(
|
||||
await mcp.callTool({ name: "binary_session", arguments: {} }),
|
||||
await mcp.callTool({
|
||||
name: "binary_session",
|
||||
arguments: { detail: "full" },
|
||||
}),
|
||||
),
|
||||
).result,
|
||||
).toEqual({
|
||||
|
||||
@@ -31,6 +31,7 @@ class FakeSetupHost implements SetupHost {
|
||||
hopperReplaceRequests: boolean[] = [];
|
||||
configurations = 0;
|
||||
skillInstalls = 0;
|
||||
doctorCalls = 0;
|
||||
checkedHopperPaths: Array<string | undefined> = [];
|
||||
configuredProviderEnvironments: SetupProviderEnvironment[] = [];
|
||||
doctorHealthy: boolean | undefined;
|
||||
@@ -111,6 +112,7 @@ class FakeSetupHost implements SetupHost {
|
||||
hopperPath?: string;
|
||||
checks: readonly DoctorCheck[];
|
||||
}> => {
|
||||
this.doctorCalls += 1;
|
||||
const checks: DoctorCheck[] = [
|
||||
...(this.linuxDemoRuntimeMissing
|
||||
? ([
|
||||
@@ -211,6 +213,26 @@ describe("setup workflow", () => {
|
||||
expect(result.status).toBe("planned");
|
||||
expect(result.appliedActions).toEqual([]);
|
||||
expect(host.hopperInstalls).toBe(0);
|
||||
expect(host.doctorCalls).toBe(1);
|
||||
});
|
||||
|
||||
it("treats an empty interactive selection as cancellation", async () => {
|
||||
const host = new FakeSetupHost();
|
||||
host.clients = [{ name: "codex", configPath: "/codex.toml" }];
|
||||
|
||||
const result = await runSetup(
|
||||
{ ...options(false), structured: false },
|
||||
host,
|
||||
() => Promise.resolve({ approved: false, selectedActionIds: [] }),
|
||||
);
|
||||
|
||||
expect(result.status).toBe("planned");
|
||||
expect(result.plannedActions).toEqual([]);
|
||||
expect(result.appliedActions).toEqual([]);
|
||||
expect(host.configurations).toBe(0);
|
||||
expect(host.skillInstalls).toBe(0);
|
||||
expect(host.hopperInstalls).toBe(0);
|
||||
expect(host.doctorCalls).toBe(1);
|
||||
});
|
||||
|
||||
it("requires the Hopper flag for unattended setup", async () => {
|
||||
|
||||
@@ -12,6 +12,9 @@ import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { resolveClientConfigTransactionPath } from "../src/application/ClientConfigPath.js";
|
||||
import { configureJsonClient } from "../src/application/Setup.js";
|
||||
import { PRODUCT_IDENTITY } from "../src/identity.js";
|
||||
|
||||
const pinnedPackage = PRODUCT_IDENTITY.registrationPackageSpecifier;
|
||||
|
||||
let directory: string | undefined;
|
||||
afterEach(async () => {
|
||||
@@ -55,7 +58,7 @@ describe("JSON client configuration transaction", () => {
|
||||
other: { command: "other" },
|
||||
rea: {
|
||||
command: "npx",
|
||||
args: ["-y", "rea-agents@latest", "mcp"],
|
||||
args: ["-y", pinnedPackage, "mcp"],
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -79,7 +82,7 @@ describe("JSON client configuration transaction", () => {
|
||||
mcpServers: {
|
||||
rea: {
|
||||
command: "npx",
|
||||
args: ["-y", "rea-agents@latest", "mcp"],
|
||||
args: ["-y", pinnedPackage, "mcp"],
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -108,7 +111,7 @@ describe("JSON client configuration transaction", () => {
|
||||
const configPath = join(directory, "mcp.json");
|
||||
await writeFile(
|
||||
configPath,
|
||||
'{"mcpServers":{"rea":{"command":"npx","args":["-y","rea-agents@latest","mcp"]}}}\n',
|
||||
`${JSON.stringify({ mcpServers: { rea: { command: "npx", args: ["-y", pinnedPackage, "mcp"] } } })}\n`,
|
||||
);
|
||||
expect(await configureJsonClient({ name: "cursor", configPath })).toEqual({
|
||||
status: "unchanged",
|
||||
@@ -134,7 +137,7 @@ describe("JSON client configuration transaction", () => {
|
||||
mcpServers: {
|
||||
rea: {
|
||||
command: "npx",
|
||||
args: ["-y", "rea-agents@latest", "mcp"],
|
||||
args: ["-y", pinnedPackage, "mcp"],
|
||||
},
|
||||
other: { command: "other" },
|
||||
},
|
||||
@@ -156,7 +159,7 @@ describe("JSON client configuration transaction", () => {
|
||||
mcpServers: {
|
||||
rea: {
|
||||
command: "npx",
|
||||
args: ["-y", "rea-agents@latest", "mcp"],
|
||||
args: ["-y", pinnedPackage, "mcp"],
|
||||
env: { HOPPER_LAUNCHER_PATH: hopperPath },
|
||||
},
|
||||
},
|
||||
|
||||
@@ -89,6 +89,7 @@ describe("agent lifecycle", () => {
|
||||
expect(configured).toContain('model = "gpt-5"');
|
||||
expect(configured).toContain("[mcp_servers.rea]");
|
||||
expect(configured).toContain('command = "rea"');
|
||||
expect(configured).toContain("startup_timeout_sec = 30");
|
||||
expect(configured).toContain('GHIDRA_INSTALL_DIR = "/opt/ghidra"');
|
||||
expect(configured).toContain('JAVA_HOME = "/opt/jdk-21"');
|
||||
expect(
|
||||
|
||||
@@ -35,14 +35,23 @@ describe("canonical skill transaction", () => {
|
||||
"stale managed skill\n",
|
||||
);
|
||||
const installedSkill = await readFile(destination, "utf8");
|
||||
expect(installedSkill).toContain('version: "22"');
|
||||
expect(installedSkill).toContain('version: "23"');
|
||||
expect(installedSkill).toContain(
|
||||
"use normal repository tools and skip REA readiness",
|
||||
"use normal repository tools and do not run REA",
|
||||
);
|
||||
expect(installedSkill).toContain(
|
||||
`tool_count: ${String(TOOL_CONTRACTS.length)}`,
|
||||
);
|
||||
expect(await readFile(sibling, "utf8")).toBe("unrelated skill\n");
|
||||
expect(
|
||||
await readFile(
|
||||
join(
|
||||
home,
|
||||
".agents/skills/reverse-engineer-anything/references/javascript-applications.md",
|
||||
),
|
||||
"utf8",
|
||||
),
|
||||
).toContain("analyze_javascript_application");
|
||||
expect(await canonicalSkillNeedsInstall(home)).toBe(false);
|
||||
expect(await installCanonicalSkill(home)).toBe("unchanged");
|
||||
});
|
||||
|
||||
+18
-2
@@ -16,6 +16,8 @@ class FakeUpgradeHost implements UpgradeHost {
|
||||
installSucceeds = true;
|
||||
installs = 0;
|
||||
output: UpgradeOutput | undefined;
|
||||
syncResult: boolean | undefined = true;
|
||||
syncs = 0;
|
||||
|
||||
latestVersion = (): Promise<string | undefined> =>
|
||||
Promise.resolve(this.latest);
|
||||
@@ -29,6 +31,12 @@ class FakeUpgradeHost implements UpgradeHost {
|
||||
this.output = output;
|
||||
return Promise.resolve(this.installSucceeds);
|
||||
};
|
||||
syncAgentIntegration = (
|
||||
_output: UpgradeOutput,
|
||||
): Promise<boolean | undefined> => {
|
||||
this.syncs += 1;
|
||||
return Promise.resolve(this.syncResult);
|
||||
};
|
||||
}
|
||||
|
||||
describe("CLI upgrade", () => {
|
||||
@@ -54,11 +62,13 @@ describe("CLI upgrade", () => {
|
||||
versionCheck: "available",
|
||||
installMethod: "npm",
|
||||
command: "npm install --global rea-agents@latest",
|
||||
integrationSync: "setup_invoked",
|
||||
clientRestartRequired: true,
|
||||
remediation:
|
||||
"Rerun rea setup to refresh registrations and the skill, then restart clients that may retain an older MCP server.",
|
||||
"The updated setup journey was opened to align registrations and the skill. Restart clients whose approved registration changed.",
|
||||
});
|
||||
expect(host.installs).toBe(1);
|
||||
expect(host.syncs).toBe(1);
|
||||
});
|
||||
|
||||
it("does not mutate when the registry check is unavailable", async () => {
|
||||
@@ -119,8 +129,14 @@ describe("CLI upgrade", () => {
|
||||
|
||||
it("preserves stdout for an explicitly structured CLI response", async () => {
|
||||
const host = new FakeUpgradeHost();
|
||||
host.syncResult = undefined;
|
||||
|
||||
await runUpgrade("0.5.0", host, "structured");
|
||||
expect(await runUpgrade("0.5.0", host, "structured")).toMatchObject({
|
||||
status: "upgraded",
|
||||
integrationSync: "deferred",
|
||||
remediation:
|
||||
"Run rea setup --all-detected to align registrations and the skill, then restart clients that may retain an older MCP server.",
|
||||
});
|
||||
|
||||
expect(host.output).toBe("structured");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user