Files
rea/scripts/fixtures/browser-script-site.mjs
N0zoM1z0 472b72a530 feat(web): export captured scripts for JavaScript application analysis (#801)
* feat(web): export captured scripts for JavaScript application analysis

Add capture adapters, conservative source path projection, verified exclusive publication and a shared CLI/MCP workflow. Retain source identities, missing content and competing URL versions in a complete manifest for existing static analysis.

Refs: #774
Closes: #799
Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis)
Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing)

* test(web): include script export in independent effect audit

Register the new contract family in the independent inventory audit and verify the filesystem, session, network and idempotence metadata of the named export contract.

Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis)
Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing)

* fix(web): preserve capture limitation values in export manifests

Align the export boundary with passive capture’s string contract instead of rejecting an admitted empty limitation. Cover the publisher boundary and regenerate canonical schemas and identities.

Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis)
Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing)
2026-10-07 05:24:32 +08:00

50 lines
1.8 KiB
JavaScript

import { createServer } from "node:http";
/** Independently authored modules and competing query variants for export verification. */
export async function startBrowserScriptSite() {
const assets = new Map([
[
"/app/main.js",
"import { sourceMarker } from './lib/dep.js'; export const result = sourceMarker; document.body.dataset.ready = 'true';\n",
],
[
"/app/lib/dep.js",
"export const sourceMarker = 'independent-source-marker';\n",
],
["/variant.js?v=1", "globalThis.variantOne = 'query-variant-one';\n"],
["/variant.js?v=2", "globalThis.variantTwo = 'query-variant-two';\n"],
]);
const counts = new Map();
const server = createServer((request, response) => {
counts.set(request.url, (counts.get(request.url) ?? 0) + 1);
const source = assets.get(request.url);
if (source !== undefined) {
response.setHeader("content-type", "text/javascript; charset=utf-8");
response.end(source);
return;
}
response.setHeader("content-type", "text/html; charset=utf-8");
response.end(
'<!doctype html><html><body><script src="/variant.js?v=1"></script><script src="/variant.js?v=2"></script><script type="module" src="/app/main.js"></script></body></html>',
);
});
await new Promise((resolve, reject) => {
server.once("error", reject);
server.listen(0, "127.0.0.1", resolve);
});
const address = server.address();
if (address === null || typeof address === "string")
throw new Error("Script fixture did not bind a port");
return {
origin: `http://127.0.0.1:${address.port}`,
assets,
counts,
close: () =>
new Promise((resolve, reject) =>
server.close((cause) =>
cause === undefined ? resolve() : reject(cause),
),
),
};
}