* 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)
71 lines
2.4 KiB
TypeScript
71 lines
2.4 KiB
TypeScript
import { z } from "incur";
|
|
import { createWebModuleTraceService } from "../composition/webModules.js";
|
|
import { CLI_COMMANDS } from "../cliCommandNames.js";
|
|
import { logCliCommand } from "../cliLogging.js";
|
|
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
|
import type { Logger } from "../logger.js";
|
|
import type { CliInstance } from "./types.js";
|
|
import { withCommandCancellation } from "./commandCancellation.js";
|
|
|
|
/** Expose the same selected-context module trace through the CLI. */
|
|
export const registerWebModuleCommands = (
|
|
cli: CliInstance,
|
|
logger: Logger,
|
|
environment: Readonly<Record<string, string | undefined>>,
|
|
): void => {
|
|
const service = createWebModuleTraceService(environment);
|
|
cli.command(CLI_COMMANDS.traceWebModuleImports, {
|
|
description:
|
|
"Trace one captured script's native imports to URLs and captured source candidates",
|
|
args: z.object({
|
|
manifestPath: z
|
|
.string()
|
|
.describe("Absolute export_web_scripts manifest path"),
|
|
scriptIndex: z.coerce
|
|
.number()
|
|
.int()
|
|
.min(0)
|
|
.describe("Zero-based manifest script index"),
|
|
}),
|
|
options: z.object({
|
|
importerUrl: z
|
|
.string()
|
|
.optional()
|
|
.describe("Explicit HTTP(S) importer URL"),
|
|
importMapPath: z
|
|
.string()
|
|
.optional()
|
|
.describe("Absolute local import-map JSON"),
|
|
importMapBaseUrl: z
|
|
.string()
|
|
.optional()
|
|
.describe("HTTP(S) import-map base URL"),
|
|
}),
|
|
run: ({ args, options }) =>
|
|
withCommandCancellation((signal) =>
|
|
logCliCommand(logger, CLI_COMMANDS.traceWebModuleImports, async () => {
|
|
const result = await service.trace(
|
|
{
|
|
manifest_path: args.manifestPath,
|
|
script_index: args.scriptIndex,
|
|
...(options.importerUrl === undefined
|
|
? {}
|
|
: { importer_url: options.importerUrl }),
|
|
...(options.importMapPath === undefined &&
|
|
options.importMapBaseUrl === undefined
|
|
? {}
|
|
: {
|
|
import_map: {
|
|
path: options.importMapPath,
|
|
base_url: options.importMapBaseUrl,
|
|
},
|
|
}),
|
|
},
|
|
{ signal },
|
|
);
|
|
return result.ok ? result.value : projectAnalysisError(result.error);
|
|
}),
|
|
),
|
|
});
|
|
};
|