mirror of
https://github.com/morluto/rea
synced 2026-10-26 14:25:49 -04:00
eeb83f6581
Load browser composition after CLI scenario validation and load Git support only for local reference trees with Git metadata. Preserve default outputs and actual command behavior. Refs #1065. Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
64 lines
2.4 KiB
TypeScript
64 lines
2.4 KiB
TypeScript
import { Cli } from "incur";
|
|
import { z } from "zod";
|
|
|
|
import { captureBrowserScenario } from "./application/BrowserScenarioCaptureService.js";
|
|
import { CLI_COMMANDS } from "./cliCommandNames.js";
|
|
import { parseCliJsonInput, resolveCliJsonPaths } from "./cliJsonInput.js";
|
|
import { logCliCommand } from "./cliLogging.js";
|
|
import { AnalysisInputError } from "./domain/analysisErrorCore.js";
|
|
import { projectAnalysisError } from "./domain/analysisErrorProjection.js";
|
|
import { projectInputIssues } from "./domain/inputIssueProjection.js";
|
|
import { browserScenarioSchema } from "./domain/browserScenario.js";
|
|
import type { JsonValue } from "./domain/jsonValue.js";
|
|
import type { Logger } from "pino";
|
|
|
|
const OPERATION = "capture_browser_scenario";
|
|
|
|
/** Register the one-shot controlled browser scenario command. */
|
|
export const registerBrowserScenarioCommands = (
|
|
cli: ReturnType<typeof Cli.create>,
|
|
logger: Logger,
|
|
environment: Readonly<Record<string, string | undefined>>,
|
|
): void => {
|
|
cli.command(CLI_COMMANDS.captureBrowserScenario, {
|
|
description:
|
|
"Run one bounded Playwright browser scenario and return Evidence",
|
|
args: z.object({
|
|
inputJson: z
|
|
.string()
|
|
.describe("Inline browser scenario JSON or JSON file path"),
|
|
}),
|
|
run: ({ args }) =>
|
|
logCliCommand(logger, CLI_COMMANDS.captureBrowserScenario, async () => {
|
|
const input = await parseCliJsonInput(args.inputJson, OPERATION);
|
|
if (!input.ok) return input.error;
|
|
const scenario = browserScenarioSchema.safeParse(
|
|
resolveCliJsonPaths(input.value, [["browser", "executable_path"]]),
|
|
);
|
|
if (!scenario.success)
|
|
return cliError(
|
|
new AnalysisInputError(
|
|
OPERATION,
|
|
{ cause: scenario.error },
|
|
projectInputIssues(scenario.error.issues, input.value),
|
|
),
|
|
);
|
|
// Load Playwright only for this command, not during CLI startup.
|
|
const { createBrowserScenarioProvider } =
|
|
await import("./composition/browserScenario.js");
|
|
const result = await captureBrowserScenario(
|
|
createBrowserScenarioProvider(environment),
|
|
scenario.data,
|
|
);
|
|
return result.ok ? result.value : cliError(result.error);
|
|
}),
|
|
});
|
|
};
|
|
|
|
const cliError = (
|
|
error: Parameters<typeof projectAnalysisError>[0],
|
|
): JsonValue => ({
|
|
error: "Browser scenario capture failed",
|
|
...projectAnalysisError(error),
|
|
});
|