mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 11:43:20 +00:00
* perf(mcp): advertise large output union alternatives as shared definitions inspect_analysis_view's advertised output schema held every view result inline in one union definition, which the MCP SDK's default validator compiled into one function: about 1.7 s CPU and 500 MiB peak. Large union alternatives now become definitions of their own and identical definitions are merged, at the owning output projection. Tests that check results against the advertised output contract now compile that schema instead of a separate inline projection, which overflowed the main-thread stack under forked workers. * perf(tests): run source test projects in forked workers (#11016) Thread workers of the source lane share one process, which grew to 3.8-5.0 GiB; forked workers keep each heap separate so the largest process stays near 1.2-1.8 GiB. * test(mcp): select the analysis view contract from its family
138 lines
4.3 KiB
TypeScript
138 lines
4.3 KiB
TypeScript
import { expect, it } from "vitest";
|
|
import { Ajv2020 } from "ajv/dist/2020.js";
|
|
|
|
import { projectAnalysisView } from "../domain/analysisView/analysisView.js";
|
|
import {
|
|
binaryLayoutSummaryViewResultSchema,
|
|
javascriptApplicationSummaryViewResultSchema,
|
|
} from "../domain/analysisView/analysisViewResult.js";
|
|
import { analysisViewRequestSchema } from "../domain/analysisView/analysisViewRequest.js";
|
|
import {
|
|
analysisViewCaptureEvidence,
|
|
analysisViewJavaScriptEvidence,
|
|
analysisViewLayoutEvidence,
|
|
environmentStateCaptureFixture,
|
|
} from "../../tests/fixtures/analysisView.js";
|
|
import { toolContract } from "./toolContracts.js";
|
|
import { advertisedOutputJsonSchema } from "./toolSchemaMetadata.js";
|
|
|
|
const projectSummary = (parent: {
|
|
readonly evidence_id: string;
|
|
readonly predicate_type: string;
|
|
readonly operation: string;
|
|
readonly normalized_result: unknown;
|
|
readonly limitations: readonly string[];
|
|
}) =>
|
|
projectAnalysisView(
|
|
{
|
|
predicateType: parent.predicate_type,
|
|
evidenceId: parent.evidence_id,
|
|
operation: parent.operation,
|
|
normalizedResult: parent.normalized_result,
|
|
limitations: parent.limitations,
|
|
},
|
|
{ kind: "summary" },
|
|
);
|
|
|
|
it("advertises only that operation's summary from analysis detail outputs", () => {
|
|
const layout = projectSummary(analysisViewLayoutEvidence());
|
|
const javascript = projectSummary(analysisViewJavaScriptEvidence());
|
|
if (!layout.ok || !javascript.ok) throw new Error("Expected summaries");
|
|
expect(
|
|
binaryLayoutSummaryViewResultSchema.safeParse(layout.value).success,
|
|
).toBe(true);
|
|
expect(
|
|
javascriptApplicationSummaryViewResultSchema.safeParse(javascript.value)
|
|
.success,
|
|
).toBe(true);
|
|
expect(
|
|
binaryLayoutSummaryViewResultSchema.safeParse(javascript.value).success,
|
|
).toBe(false);
|
|
|
|
const ajv = new Ajv2020({
|
|
strict: false,
|
|
validateFormats: false,
|
|
inlineRefs: false,
|
|
code: { optimize: false },
|
|
});
|
|
const validators = Object.fromEntries(
|
|
(
|
|
[
|
|
"inspect_binary_layout",
|
|
"analyze_javascript_application",
|
|
"inspect_analysis_view",
|
|
] as const
|
|
).map((name) => [
|
|
name,
|
|
ajv.compile(advertisedOutputJsonSchema(toolContract(name))),
|
|
]),
|
|
);
|
|
const layoutReceipt = {
|
|
...analysisViewLayoutEvidence(),
|
|
normalized_result: layout.value,
|
|
};
|
|
const javascriptReceipt = {
|
|
...analysisViewJavaScriptEvidence(),
|
|
normalized_result: javascript.value,
|
|
};
|
|
expect(validators.inspect_binary_layout!(layoutReceipt)).toBe(true);
|
|
expect(validators.analyze_javascript_application!(javascriptReceipt)).toBe(
|
|
true,
|
|
);
|
|
const parent = analysisViewCaptureEvidence(environmentStateCaptureFixture());
|
|
const captureParent = {
|
|
predicateType: parent.predicate_type,
|
|
evidenceId: parent.evidence_id,
|
|
operation: parent.operation,
|
|
normalizedResult: parent.normalized_result,
|
|
parameters: parent.parameters,
|
|
subject: parent.subject,
|
|
limitations: parent.limitations,
|
|
};
|
|
const captureSummary = projectAnalysisView(captureParent, {
|
|
kind: "summary",
|
|
});
|
|
if (!captureSummary.ok) throw captureSummary.error;
|
|
const captureReceipt = { ...parent, normalized_result: captureSummary.value };
|
|
expect(validators.inspect_analysis_view!(captureReceipt)).toBe(true);
|
|
expect(
|
|
validators.inspect_binary_layout!({
|
|
...layoutReceipt,
|
|
normalized_result: captureSummary.value,
|
|
}),
|
|
).toBe(false);
|
|
expect(
|
|
validators.analyze_javascript_application!({
|
|
...javascriptReceipt,
|
|
normalized_result: captureSummary.value,
|
|
}),
|
|
).toBe(false);
|
|
for (const kind of [
|
|
"api-surface",
|
|
"environment-manifest",
|
|
"environment-state",
|
|
] as const) {
|
|
const projected = projectAnalysisView(
|
|
captureParent,
|
|
analysisViewRequestSchema.parse({ kind }),
|
|
);
|
|
if (!projected.ok) throw projected.error;
|
|
const receipt = { ...parent, normalized_result: projected.value };
|
|
expect(validators.inspect_analysis_view!(receipt), kind).toBe(true);
|
|
expect(
|
|
validators.inspect_binary_layout!({
|
|
...layoutReceipt,
|
|
normalized_result: projected.value,
|
|
}),
|
|
kind,
|
|
).toBe(false);
|
|
expect(
|
|
validators.analyze_javascript_application!({
|
|
...javascriptReceipt,
|
|
normalized_result: projected.value,
|
|
}),
|
|
kind,
|
|
).toBe(false);
|
|
}
|
|
});
|