Files
clh02467605 d646a4e780 refactor(e2e): update test routes and streamline command handling
- Replaced hardcoded command paths with dynamic route mappings in E2E tests.
- Enhanced documentation for command testing, specifying minimum route requirements.
- Consolidated command path management into `topic-routes.ts` for better maintainability.
- Updated various E2E test cases to utilize the new routing structure, ensuring consistency across tests.
- Removed redundant helper functions and improved test clarity by directly referencing route exports.
2026-07-10 15:55:53 +08:00

30 lines
1001 B
TypeScript

import * as cmd from "bailian-cli-commands";
import type { AnyCommand } from "bailian-cli-core";
import { createCli } from "bailian-cli-runtime";
import { E2E_HARNESS_IDENTITY } from "./identity.ts";
interface RouteSpec {
path: string;
export: string;
}
function buildRoutesFromEnv(): Record<string, AnyCommand> {
const raw = process.env.BAILIAN_E2E_ROUTES;
if (!raw?.trim()) {
throw new Error("BAILIAN_E2E_ROUTES is required for commands E2E harness");
}
const spec = JSON.parse(raw) as RouteSpec[];
const routes: Record<string, AnyCommand> = {};
const lib = cmd as Record<string, unknown>;
for (const { path, export: exportName } of spec) {
const command = lib[exportName];
if (typeof command !== "object" || command === null || !("run" in command)) {
throw new Error(`Unknown bailian-cli-commands export: ${exportName}`);
}
routes[path] = command as AnyCommand;
}
return routes;
}
void createCli(buildRoutesFromEnv(), E2E_HARNESS_IDENTITY).run();