mirror of
https://github.com/morluto/rea
synced 2026-10-26 06:16:17 -04:00
refactor(tests): separate fixtures and registration groups
This commit is contained in:
@@ -238,45 +238,47 @@ class FakeSession implements BrowserScenarioSessionPort {
|
||||
}
|
||||
}
|
||||
|
||||
const capturedResponseBodyEvents = (): readonly BrowserScenarioEvent[] => [
|
||||
{
|
||||
sequence: 1,
|
||||
step_index: 0,
|
||||
kind: "response",
|
||||
transaction_id: "request-1",
|
||||
redirected_from_transaction_id: null,
|
||||
method: "GET",
|
||||
url: sanitizeBrowserUrl("https://app.example.test/main.js"),
|
||||
resource_type: "script",
|
||||
header_names: [],
|
||||
status: 200,
|
||||
failure: null,
|
||||
},
|
||||
{
|
||||
sequence: 2,
|
||||
step_index: 0,
|
||||
kind: "network-content",
|
||||
transaction_id: "request-1",
|
||||
source_event_sequence: 1,
|
||||
phase: "response",
|
||||
headers: { state: "not_requested" },
|
||||
body: {
|
||||
state: "captured",
|
||||
representation: "playwright-response-body-bytes",
|
||||
encoding: "base64",
|
||||
content: "",
|
||||
bytes: 0,
|
||||
sha256:
|
||||
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
|
||||
media_type: "text/javascript",
|
||||
redacted: false,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
describe("PlaywrightBrowserScenarioProvider", () => {
|
||||
it("reports response-body provenance uncertainty without marking event coverage missing", async () => {
|
||||
const session = new FakeSession("launch");
|
||||
const selected = scenario();
|
||||
session.eventItems = [
|
||||
{
|
||||
sequence: 1,
|
||||
step_index: 0,
|
||||
kind: "response",
|
||||
transaction_id: "request-1",
|
||||
redirected_from_transaction_id: null,
|
||||
method: "GET",
|
||||
url: sanitizeBrowserUrl("https://app.example.test/main.js"),
|
||||
resource_type: "script",
|
||||
header_names: [],
|
||||
status: 200,
|
||||
failure: null,
|
||||
},
|
||||
{
|
||||
sequence: 2,
|
||||
step_index: 0,
|
||||
kind: "network-content",
|
||||
transaction_id: "request-1",
|
||||
source_event_sequence: 1,
|
||||
phase: "response",
|
||||
headers: { state: "not_requested" },
|
||||
body: {
|
||||
state: "captured",
|
||||
representation: "playwright-response-body-bytes",
|
||||
encoding: "base64",
|
||||
content: "",
|
||||
bytes: 0,
|
||||
sha256:
|
||||
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
|
||||
media_type: "text/javascript",
|
||||
redacted: false,
|
||||
},
|
||||
},
|
||||
];
|
||||
session.eventItems = capturedResponseBodyEvents();
|
||||
const input = browserScenarioSchema.parse({
|
||||
...selected,
|
||||
capture: {
|
||||
|
||||
@@ -156,7 +156,9 @@ describe("tRPC procedure recognition", () => {
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("tRPC procedure recognition", () => {
|
||||
it("recognizes vanilla client calls and link URLs only in sources carrying a tRPC marker", () => {
|
||||
expect(
|
||||
rpcEndpoints(`
|
||||
|
||||
@@ -55,6 +55,39 @@ async function capturePassivePair(
|
||||
};
|
||||
}
|
||||
|
||||
function invalidComparisonInputs(
|
||||
passive: Awaited<ReturnType<typeof capturePassivePair>>,
|
||||
scenario: (typeof contract.examples)[number]["input"],
|
||||
) {
|
||||
const scenarioCapture = browserScenarioCaptureSchema.parse(
|
||||
scenario.before_scenario,
|
||||
);
|
||||
return [
|
||||
{},
|
||||
{ before: passive.before },
|
||||
{ before: { inspection: {} }, after: passive.after },
|
||||
{
|
||||
before: passive.before,
|
||||
after: { ...passive.after, webmcp: {} },
|
||||
},
|
||||
{ before_scenario: {}, after_scenario: {} },
|
||||
{ before_scenario: scenario.before_scenario },
|
||||
{ ...passive, unexpected: true },
|
||||
{
|
||||
...scenario,
|
||||
before_scenario: { ...scenarioCapture, steps: [{}] },
|
||||
},
|
||||
{
|
||||
...scenario,
|
||||
normalization: {
|
||||
rules: [
|
||||
{ rule_id: "bad", artifacts: [], match: "x", replacement: "y" },
|
||||
],
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
describe("browser comparison input boundary", () => {
|
||||
it("advertises producer captures and agrees with SDK validation on both comparison families", async () => {
|
||||
const browser = await startFakeCdpBrowser({ sensitiveShapes: true });
|
||||
@@ -105,33 +138,7 @@ describe("browser comparison input boundary", () => {
|
||||
const withoutNormalization = Object.fromEntries(
|
||||
Object.entries(scenario).filter(([key]) => key !== "normalization"),
|
||||
);
|
||||
const scenarioCapture = browserScenarioCaptureSchema.parse(
|
||||
scenario.before_scenario,
|
||||
);
|
||||
const invalid = [
|
||||
{},
|
||||
{ before: passive.before },
|
||||
{ before: { inspection: {} }, after: passive.after },
|
||||
{
|
||||
before: passive.before,
|
||||
after: { ...passive.after, webmcp: {} },
|
||||
},
|
||||
{ before_scenario: {}, after_scenario: {} },
|
||||
{ before_scenario: scenario.before_scenario },
|
||||
{ ...passive, unexpected: true },
|
||||
{
|
||||
...scenario,
|
||||
before_scenario: { ...scenarioCapture, steps: [{}] },
|
||||
},
|
||||
{
|
||||
...scenario,
|
||||
normalization: {
|
||||
rules: [
|
||||
{ rule_id: "bad", artifacts: [], match: "x", replacement: "y" },
|
||||
],
|
||||
},
|
||||
},
|
||||
];
|
||||
const invalid = invalidComparisonInputs(passive, scenario);
|
||||
// Strict clients reject combinators and dependentRequired, so the
|
||||
// projection states the groups in its description and leaves group
|
||||
// completeness and exclusion to the canonical runtime parser.
|
||||
|
||||
@@ -37,6 +37,14 @@ describe("JavaScript runtime observation MCP tools", () => {
|
||||
);
|
||||
});
|
||||
|
||||
registerRuntimeParameterContract(resources);
|
||||
registerRuntimeMetadataContract();
|
||||
registerRetainedRuntimeEvidence(resources, temporary);
|
||||
});
|
||||
|
||||
function registerRuntimeParameterContract(
|
||||
resources: Array<{ close(): Promise<unknown> }>,
|
||||
): void {
|
||||
test("attributes V8 role and target disagreements to the parameter that differs", async () => {
|
||||
const session = createTestBinarySession(() => {
|
||||
throw new Error("No provider expected");
|
||||
@@ -118,7 +126,9 @@ describe("JavaScript runtime observation MCP tools", () => {
|
||||
}
|
||||
await client.ping();
|
||||
});
|
||||
}
|
||||
|
||||
function registerRuntimeMetadataContract(): void {
|
||||
test("accepts long caller windows and complete observation metadata", () => {
|
||||
const repeated = (count: number): string[] =>
|
||||
Array.from({ length: count }, (_, index) => `item-${index}`);
|
||||
@@ -190,7 +200,12 @@ describe("JavaScript runtime observation MCP tools", () => {
|
||||
}),
|
||||
).toMatchObject({ unknowns, limitations });
|
||||
});
|
||||
}
|
||||
|
||||
function registerRetainedRuntimeEvidence(
|
||||
resources: Array<{ close(): Promise<unknown> }>,
|
||||
temporary: string[],
|
||||
): void {
|
||||
test("lists and observes one target as retained Evidence", async () => {
|
||||
const root = await createTestTempDirectory("rea-v8-mcp-");
|
||||
temporary.push(root);
|
||||
@@ -255,7 +270,7 @@ describe("JavaScript runtime observation MCP tools", () => {
|
||||
expect(direct.ok).toBe(true);
|
||||
if (direct.ok) expect(evidenceId).toBe(direct.value.evidence_id);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const assertSdkObservationSchema = async (
|
||||
client: Client,
|
||||
|
||||
@@ -61,6 +61,12 @@ afterEach(async () => {
|
||||
});
|
||||
|
||||
describe("guided prompts over MCP", () => {
|
||||
registerPromptDiscoveryParameterContract();
|
||||
registerPromptRenderingContracts();
|
||||
registerPromptInputContracts();
|
||||
});
|
||||
|
||||
function registerPromptDiscoveryParameterContract(): void {
|
||||
it("classifies malformed discovery parameters separately from handler failures", async () => {
|
||||
const session = fixtureSession();
|
||||
const server = createServer({ kind: "session", session });
|
||||
@@ -126,6 +132,9 @@ describe("guided prompts over MCP", () => {
|
||||
error: { code: -32603, message: "injected internal failure" },
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function registerPromptRenderingContracts(): void {
|
||||
it("lists and renders all workflows without changing the tool inventory", async () => {
|
||||
const session = fixtureSession();
|
||||
const client = await connect(createServer({ kind: "session", session }));
|
||||
@@ -232,7 +241,9 @@ describe("guided prompts over MCP", () => {
|
||||
expect(content.text).not.toContain("Run the caller-provided scenario");
|
||||
expect(executions).toBe(0);
|
||||
});
|
||||
}
|
||||
|
||||
function registerPromptInputContracts(): void {
|
||||
it("rejects invalid prompt requests and safely handles non-completable arguments", async () => {
|
||||
let executions = 0;
|
||||
const session = fixtureSession(() => {
|
||||
@@ -283,7 +294,7 @@ describe("guided prompts over MCP", () => {
|
||||
});
|
||||
expect(executions).toBe(0);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
it("preserves caller-selected paths and verbatim crash signals", async () => {
|
||||
const directory = await createTestTempDirectory("rea-prompt-exact-context-");
|
||||
|
||||
@@ -605,25 +605,21 @@ describe("LLDB process exit while output is still open", () => {
|
||||
);
|
||||
});
|
||||
|
||||
describe("LLDB process exit at output-close loop completion", () => {
|
||||
for (const abort of [false, true])
|
||||
it.skipIf(process.platform === "win32")(
|
||||
`retains completed trace facts after output closure (cancelled=${String(abort)})`,
|
||||
async () => {
|
||||
const fixtureRoot = await mkdtemp(
|
||||
join(tmpdir(), "rea-lldb-complete-output-"),
|
||||
);
|
||||
const fakeLldb = join(fixtureRoot, "fake-lldb");
|
||||
const completed = {
|
||||
...successfulTracerOutput,
|
||||
target_output: {
|
||||
...successfulTracerOutput.target_output,
|
||||
stdout_bytes: 2,
|
||||
},
|
||||
};
|
||||
await writeFile(
|
||||
fakeLldb,
|
||||
`#!${process.execPath}
|
||||
const completedOutputCloseFixture = async () => {
|
||||
const fixtureRoot = await mkdtemp(
|
||||
join(tmpdir(), "rea-lldb-complete-output-"),
|
||||
);
|
||||
const fakeLldb = join(fixtureRoot, "fake-lldb");
|
||||
const completed = {
|
||||
...successfulTracerOutput,
|
||||
target_output: {
|
||||
...successfulTracerOutput.target_output,
|
||||
stdout_bytes: 2,
|
||||
},
|
||||
};
|
||||
await writeFile(
|
||||
fakeLldb,
|
||||
`#!${process.execPath}
|
||||
const fs = require("node:fs");
|
||||
const { spawnSync } = require("node:child_process");
|
||||
const command = process.argv.at(-1);
|
||||
@@ -639,8 +635,18 @@ fs.writeFileSync(config.observation_path, JSON.stringify({ kind: "event", event:
|
||||
fs.writeFileSync(config.result_path, JSON.stringify(result));
|
||||
process.exit(0);
|
||||
`,
|
||||
{ mode: 0o700 },
|
||||
);
|
||||
{ mode: 0o700 },
|
||||
);
|
||||
return { fixtureRoot, fakeLldb, completed };
|
||||
};
|
||||
|
||||
describe("LLDB process exit at output-close loop completion", () => {
|
||||
for (const abort of [false, true])
|
||||
it.skipIf(process.platform === "win32")(
|
||||
`retains completed trace facts after output closure (cancelled=${String(abort)})`,
|
||||
async () => {
|
||||
const { fixtureRoot, fakeLldb, completed } =
|
||||
await completedOutputCloseFixture();
|
||||
const controller = new AbortController();
|
||||
const reason = { requested: "stop after completed output closure" };
|
||||
let interrupted = false;
|
||||
|
||||
Reference in New Issue
Block a user