Files
reverse-engineering-anything/src/cli/playwrightTraceCommand.ts
T

65 lines
2.2 KiB
TypeScript

import type { Logger } from "pino";
import { PLAYWRIGHT_TRACE_TOOL_CONTRACTS } from "../contracts/playwrightTraceToolContracts.js";
import {
PLAYWRIGHT_TRACE_OPERATION as operation,
PLAYWRIGHT_TRACE_PROVIDER,
} from "../domain/playwrightTrace/playwrightTrace.js";
import { contractNamed } from "./contractCliDescription.js";
import { registerContractCommand } from "./contractCommand.js";
import {
deliverWithService,
createArtifactInspectionService,
} from "./contractCommandRunners.js";
import type { CliInstance } from "./types.js";
/** Standard one-shot publication keeps complete inventory Evidence for later offline pages. */
export const registerPlaywrightTraceCommand = (
cli: CliInstance,
logger: Logger,
environment: Readonly<Record<string, string | undefined>> = process.env,
): void =>
registerContractCommand(
cli,
logger,
contractNamed(PLAYWRIGHT_TRACE_TOOL_CONTRACTS, operation),
{
description:
"Inventory local saved Playwright v10 trace ZIP events offline without launching a browser",
positionals: ["path"],
callerPaths: ["path"],
evidenceDelivery: true,
viewDelivery: { invalidJson: "view must be valid JSON" },
jsonText: ["trace_limits"],
fields: {
path: { description: "Local Playwright trace ZIP path" },
view: {
description:
"JSON playwright-trace page; requires --detail summary and --evidence_output",
},
},
},
deliverWithService(
() => createPlaywrightTraceService(environment),
PLAYWRIGHT_TRACE_PROVIDER.id,
),
);
/** One-shot trace inventory that owns the archive it opens. */
const createPlaywrightTraceService = (
environment: Readonly<Record<string, string | undefined>>,
) =>
createArtifactInspectionService(
PLAYWRIGHT_TRACE_PROVIDER,
operation,
async (input, resources, signal) => {
const { PlaywrightTraceService } =
await import("../application/playwrightTrace/PlaywrightTraceService.js");
const { PlaywrightTraceDecoder } =
await import("../browser/history/playwrightTrace/PlaywrightTraceDecoder.js");
return new PlaywrightTraceService(
new PlaywrightTraceDecoder(resources, environment),
).inspect(input, signal);
},
);