* fix(build): emit no runtime imports for type-only bindings
Under verbatimModuleSyntax, an import whose specifiers all carry inline
`type` modifiers compiles to `import {} from "..."`, a side-effect import
that still resolves and evaluates the module. 78 compiled modules carried
one, including `import {} from "playwright-core"` in the browser scenario
session, which loaded Playwright's module graph at MCP startup.
Use top-level `import type` for these bindings and enable oxlint's
typescript/no-import-type-side-effects rule so the pattern cannot return.
Refs #1685
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* perf(mcp): load Playwright when a scenario launches, not at startup
The browser scenario and Electron active providers are constructed before
the stdio server serves, and both bound Playwright's launchers at module
load. Resolve `chromium` and `_electron` from playwright-core when a
capture opens instead, as the web module resolver already does.
MCP startup now resolves 1,312 modules (4,902 resolutions) instead of
1,598 (6,076) before reading the first request, and no longer loads
playwright-core. Provider construction, the tool catalog, and capability
inventory are unchanged.
A boundary test spawns the stdio server, initializes, lists tools, and
asserts playwright-core and isomorphic-git were not resolved; the CLI
probe now exercises the real launch path to prove detection.
Closes #1685
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
91 lines
3.1 KiB
TypeScript
91 lines
3.1 KiB
TypeScript
import { resolve } from "node:path";
|
|
import { z } from "zod";
|
|
|
|
import { AnalysisProtocolError } from "../../domain/analysisErrorCore.js";
|
|
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
|
import type { Evidence } from "../../domain/evidence.js";
|
|
import { analysisInputErrorFromIssues } from "../../domain/inputIssueProjection.js";
|
|
import {
|
|
parseRuntimeReconciliationInput,
|
|
reconcileJavaScriptRuntime,
|
|
type ParsedRuntimeReconciliationInput,
|
|
} from "../../domain/javascript/javascriptRuntimeReconciliation.js";
|
|
import { reconcileJavaScriptRuntimeInputSchema } from "../../domain/javascript/javascriptRuntimeReconciliationSchemas.js";
|
|
import { err, ok, type Result } from "../../domain/result.js";
|
|
import { createJavaScriptRuntimeReconciliationEvidence } from "./JavaScriptRuntimeReconciliationEvidence.js";
|
|
|
|
const OPERATION = "reconcile_javascript_runtime" as const;
|
|
|
|
/** Derive a combined JAG from verified static and passive-runtime Evidence. */
|
|
export const reconcileJavaScriptRuntimeEvidence = (
|
|
rawInput: unknown,
|
|
): Result<Evidence, AnalysisError> => {
|
|
const parsed = reconcileJavaScriptRuntimeInputSchema.safeParse(rawInput);
|
|
if (!parsed.success)
|
|
return err(
|
|
analysisInputErrorFromIssues(OPERATION, parsed.error.issues, rawInput),
|
|
);
|
|
return reconcileJavaScriptRuntimeEvidenceValidated(parsed.data);
|
|
};
|
|
|
|
/** Reconcile input already parsed by a trusted adapter boundary. */
|
|
export const reconcileJavaScriptRuntimeEvidenceValidated = (
|
|
parsedInput: z.output<typeof reconcileJavaScriptRuntimeInputSchema>,
|
|
): Result<Evidence, AnalysisError> => {
|
|
let parsed: ParsedRuntimeReconciliationInput;
|
|
try {
|
|
parsed = parseRuntimeReconciliationInput(
|
|
normalizeRuntimeMappingRoots(parsedInput),
|
|
);
|
|
} catch (cause: unknown) {
|
|
if (cause instanceof z.ZodError)
|
|
return err(
|
|
analysisInputErrorFromIssues(OPERATION, cause.issues, parsedInput),
|
|
);
|
|
return err(
|
|
new AnalysisProtocolError(
|
|
"JavaScript runtime reconciliation input parsing failed",
|
|
{ cause },
|
|
),
|
|
);
|
|
}
|
|
|
|
try {
|
|
const result = reconcileJavaScriptRuntime(parsed);
|
|
return ok(
|
|
createJavaScriptRuntimeReconciliationEvidence(parsed.input, result),
|
|
);
|
|
} catch (cause: unknown) {
|
|
return err(
|
|
new AnalysisProtocolError(
|
|
"JavaScript runtime reconciliation produced an invalid result",
|
|
{ cause },
|
|
),
|
|
);
|
|
}
|
|
};
|
|
|
|
const normalizeRuntimeMappingRoots = (
|
|
input: z.output<typeof reconcileJavaScriptRuntimeInputSchema>,
|
|
): z.output<typeof reconcileJavaScriptRuntimeInputSchema> => ({
|
|
...input,
|
|
static_layers: input.static_layers.map((layer) => ({
|
|
...layer,
|
|
runtime_mappings: layer.runtime_mappings.map((mapping) =>
|
|
mapping.kind === "file-root"
|
|
? {
|
|
...mapping,
|
|
root: isPortableAbsolutePath(mapping.root)
|
|
? mapping.root
|
|
: resolve(mapping.root),
|
|
}
|
|
: mapping,
|
|
),
|
|
})),
|
|
});
|
|
|
|
const isPortableAbsolutePath = (path: string): boolean =>
|
|
path.startsWith("/") ||
|
|
/^[a-z]:[\\/]/iu.test(path) ||
|
|
/^(?:\\\\|\/\/)[^\\/]+[\\/][^\\/]+(?:[\\/]|$)/u.test(path);
|