Files
rea/tests/composition/analysis-sessions/compositeProvider.test.ts
T
morlutoGitHubDevin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
e91c8c39c2 refactor(test): colocate pure-domain tests and reduce test debt (#471)
* refactor(test): colocate pure-domain tests and reduce test debt

Move focused immutable domain/contracts/adapter tests from
tests/composition/** beside their production owners under src/** as
colocated *.test.ts/*.fixture.ts, and relocate persistence-shaped
composition tests under tests/boundary/filesystem/**. Update import
paths, the Vitest project topology (shared worker context for pure
domain/contracts and recording-port service projects), the test
migration ledger, testing docs, and AGENTS.md to match.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* docs: remove test migration ledger

The cutover is complete and the ledger is no longer referenced anywhere
in source, scripts, or the docs gate. Drop the standalone artifact.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* docs: clean up stale migration artifacts

Remove empty directories left by the test migration and replace the
"final cutover" language in docs/testing.md with standing PR guidance
that no longer references the completed migration.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix: repair CI failures from schema, knip, and stale generated artifacts

Three root causes fixed:

1. catalog-schemas.mjs: valuesAt only traversed anyOf from Zod's
   toJSONSchema, not oneOf. The webScreenshotDiffSchema change to a
   discriminated union produces oneOf, so the product catalog generator
   could not derive the web_screenshot_diff schema version. Add oneOf
   traversal.

2. conformancePackage.ts: the test rewrite removed the only imports of
   ScenarioManifest, ReplayPlan, ShimPlan, and ExpectedEvidence, making
   them unused exports that knip flags. Remove the dead type aliases.

3. Regenerate stale artifacts (product catalog, MCP tool catalog, skill
   metadata, conformance manifest) that drifted from the source changes.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

---------

Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-08-10 14:57:44 +08:00

221 lines
6.9 KiB
TypeScript

import { writeFile } from "node:fs/promises";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
import { createTestBinarySession } from "../../fixtures/binarySession.js";
import { CompositeProvider } from "../../../src/application/CompositeProvider.js";
import type {
AnalysisOperation,
AnalysisProvider,
CapabilityDescriptor,
ProviderIdentity,
} from "../../../src/application/AnalysisProvider.js";
import { createAnalysisExecution } from "../../../src/application/AnalysisProvider.js";
import type { BinaryTarget } from "../../../src/domain/binaryTarget.js";
import { ok } from "../../../src/domain/result.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
const target: BinaryTarget = {
path: "/fixture",
kind: "database",
format: "analysis-database",
sha256: "0".repeat(64),
};
describe("composite analysis provider", () => {
it("routes disjoint operations and does not start children during health", async () => {
const hopperCalls: string[] = [];
const nativeCalls: string[] = [];
const hopper = provider("hopper", "address_name", hopperCalls);
const native = provider("native", "analyze_function", nativeCalls);
const composite = new CompositeProvider([hopper, native]);
const client = composite.createClient(target);
expect(await client.execute("health", {})).toEqual({
ok: true,
value: {
result: null,
rawResult: null,
provider: {
id: "composite:hopper+native",
name: "REA composite analysis provider",
version: null,
},
limitations: [],
locations: [],
subject: null,
},
});
expect(hopperCalls).toEqual([]);
expect(nativeCalls).toEqual([]);
expect(await client.execute("address_name", {})).toEqual({
ok: true,
value: createAnalysisExecution("hopper:address_name", hopper.identity()),
});
expect(await client.execute("analyze_function", {})).toEqual({
ok: true,
value: createAnalysisExecution(
"native:analyze_function",
native.identity(),
),
});
expect(hopperCalls).toEqual(["address_name"]);
expect(nativeCalls).toEqual(["analyze_function"]);
expect(await client.execute("list_names", {})).toMatchObject({
ok: false,
error: { _tag: "AnalysisCapabilityUnavailableError" },
});
});
it("publishes exact operation provenance and rejects ambiguous routes", () => {
const hopper = provider("hopper", "address_name", []);
const native = provider("native", "analyze_function", []);
const session = createTestBinarySession(
new CompositeProvider([hopper, native]),
);
expect(session.providerIdentity("address_name").id).toBe("hopper");
expect(session.providerIdentity("analyze_function").id).toBe("native");
expect(session.providerIdentity("binary_overview").id).toBe("hopper");
expect(session.providerIdentity().id).toBe("composite:hopper+native");
expect(
() =>
new CompositeProvider([
hopper,
provider("duplicate", "address_name", []),
]),
).toThrow(/Multiple providers declare operation address_name/u);
});
it("retains lineage snapshots from two lazily started dynamic providers", async () => {
const directory = await createTestTempDirectory("rea-composite-lineage-");
const targetPath = join(directory, "fixture.hop");
await writeFile(targetPath, "fixture");
const first = dynamicProvider("first", "address_name", 100);
const second = dynamicProvider("second", "analyze_function", 200);
const session = createTestBinarySession(
new CompositeProvider([second, first]),
);
expect((await session.open(targetPath)).ok).toBe(true);
expect(await session.execute("address_name", {})).toMatchObject({
ok: true,
});
expect(await session.execute("analyze_function", {})).toMatchObject({
ok: true,
});
expect(session.status()).toMatchObject({
analysis_run: {
process_lineage: {
status: "snapshots",
snapshots: [
{
provider: { id: "first" },
observation: {
status: "verified",
observed_at: "2026-07-22T10:00:00.000Z",
launcher_pid: 100,
},
},
{
provider: { id: "second" },
observation: {
status: "verified",
observed_at: "2026-07-22T10:00:00.000Z",
launcher_pid: 200,
},
},
],
},
},
});
await session.close();
});
});
const dynamicProvider = (
id: string,
operation: Exclude<AnalysisOperation, "health">,
launcherPid: number,
): AnalysisProvider => {
const identity: ProviderIdentity = { id, name: id, version: "1" };
return {
identity: () => identity,
capabilities: () => [capability(identity, operation)],
createClient: (_target, _profile, context) => {
if (context === undefined)
throw new Error("missing analysis run context");
return {
execute: (called) =>
Promise.resolve(
ok(createAnalysisExecution(`${id}:${called}`, identity)),
),
runtimeLineageSnapshots: () => [
{
provider: identity,
observation: {
status: "verified",
observedAt: "2026-07-22T10:00:00.000Z",
lineage: {
schemaVersion: 1,
runId: context.runId,
launcherPid,
launcherParentPid: 1,
processGroupId: launcherPid,
descendants: [],
},
},
},
],
close: () => Promise.resolve(),
};
},
};
};
const provider = (
id: string,
operation: Exclude<AnalysisOperation, "health">,
calls: string[],
): AnalysisProvider => {
const identity: ProviderIdentity = { id, name: id, version: "1" };
return {
identity: () => identity,
capabilities: () => [capability(identity, operation)],
createClient: () => ({
execute: (called) => {
calls.push(called);
return Promise.resolve(
ok(createAnalysisExecution(`${id}:${called}`, identity)),
);
},
close: () => Promise.resolve(),
}),
};
};
const capability = (
providerIdentity: ProviderIdentity,
operation: Exclude<AnalysisOperation, "health">,
): CapabilityDescriptor => ({
provider: providerIdentity,
operation,
inputContractVersion: 1,
outputContractVersion: 1,
available: true,
reason: null,
pagination: "none",
exhaustive: true,
effects: {
mutatesArtifact: false,
launchesProcess: true,
mayShowUi: false,
mayAccessNetwork: false,
mayWriteFilesystem: false,
changesPermissions: false,
requiresRoot: false,
},
limits: { maxResults: null, maxPayloadBytes: 1_000_000, timeoutMs: 5_000 },
limitations: [],
});