mirror of
https://github.com/morluto/rea.git
synced 2026-10-12 02:19:24 +00:00
* feat(browser): trace captured website module imports Compose verified exported scripts, inert native import syntax and a narrow Chromium resolution port. Preserve query/fragment identity, import-map context, all reported capture candidates and explicit unknown execution. Share named CLI/MCP contracts and retain native reports, diagnostics and cleanup failures. Add focused boundary regressions and a real module-loading oracle to the existing conditional Chrome lane. No captured application code is executed by module tracing, and no selected website asset is refetched. Refs #851, #774 Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis) Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing) * fix(browser): preserve module contexts and source bindings Keep capture completeness inline, validate actual source text against its digest, and separate unsupported URL contexts from malformed input. Use the importer origin for native module resolution and the selected map base independently, including mixed HTTP/HTTPS and escaped HTML attributes. Refs #851, #774 Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis) Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing)
73 lines
2.8 KiB
TypeScript
73 lines
2.8 KiB
TypeScript
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { expect, onTestFinished } from "vitest";
|
|
import { createWebModuleTraceService } from "../../src/composition/webModules.js";
|
|
import { createServer } from "../../src/server/createServer.js";
|
|
import { createTestBinarySession } from "../fixtures/binarySession.js";
|
|
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
|
|
import { webModuleArtifactsFixture } from "../fixtures/webModuleTrace.js";
|
|
import { cliTest } from "../support/cli/cliFixture.js";
|
|
|
|
cliTest(
|
|
"accepts zero-based numeric source indices and returns the same engine-free CLI/MCP trace",
|
|
async ({ cli }) => {
|
|
const root = await createTestTempDirectory("rea-module-cli-");
|
|
const artifacts = webModuleArtifactsFixture("import(name)");
|
|
const manifest = {
|
|
...artifacts.manifest,
|
|
output_directory: root,
|
|
analysis_input: { input_path: join(root, "files"), format: "directory" },
|
|
};
|
|
await mkdir(join(root, "files", "modules"), { recursive: true });
|
|
await writeFile(
|
|
join(root, "files", "modules", "main.js"),
|
|
artifacts.source,
|
|
);
|
|
const manifestPath = join(root, "manifest.json");
|
|
await writeFile(manifestPath, JSON.stringify(manifest));
|
|
const environment = {
|
|
REA_LOG_LEVEL: "silent",
|
|
REA_BROWSER_EXECUTABLE: "relative-missing-browser",
|
|
};
|
|
const cliResponse = await cli.run({
|
|
arguments: ["trace-web-module-imports", manifestPath, "0", "--json"],
|
|
environment,
|
|
timeoutMs: 15000,
|
|
});
|
|
expect(cliResponse.exitCode).toBe(0);
|
|
expect(cliResponse.json).toMatchObject({
|
|
normalized_result: {
|
|
engine: null,
|
|
source: { script_index: 0 },
|
|
imports: [
|
|
{ resolution: { state: "unknown", reason: "computed-specifier" } },
|
|
],
|
|
},
|
|
});
|
|
const session = createTestBinarySession(() => {
|
|
throw new Error("no binary acquisition");
|
|
});
|
|
const server = createServer(session, session, {
|
|
webModuleTrace: createWebModuleTraceService(environment),
|
|
});
|
|
const client = new Client({ name: "module-cli-parity", version: "1" });
|
|
onTestFinished(async () => {
|
|
await client.close();
|
|
await server.close();
|
|
await session.close();
|
|
});
|
|
const [clientTransport, serverTransport] =
|
|
InMemoryTransport.createLinkedPair();
|
|
await server.connect(serverTransport);
|
|
await client.connect(clientTransport);
|
|
const response = await client.callTool({
|
|
name: "trace_web_module_imports",
|
|
arguments: { manifest_path: manifestPath, script_index: 0 },
|
|
});
|
|
expect(response.isError).not.toBe(true);
|
|
const expected = cliResponse.json;
|
|
expect(response.structuredContent).toMatchObject({ evidence: expected });
|
|
},
|
|
);
|