test: type cli test mocks

This commit is contained in:
Shakker
2026-06-15 19:34:16 +01:00
parent c40db057da
commit 5c2487dc9a
5 changed files with 31 additions and 6 deletions
@@ -31,7 +31,13 @@ const runGatewayLoop = vi.fn(async ({ start }: { start: GatewayLoopStart }) => {
const normalizeStateDirEnv = vi.fn((_env?: NodeJS.ProcessEnv) => undefined);
const pinConfigDir = vi.fn((_env?: NodeJS.ProcessEnv) => undefined);
const pinRuntimePaths = vi.fn((_env?: NodeJS.ProcessEnv) => undefined);
const loadGlobalRuntimeDotEnvFiles = vi.fn((_opts?: unknown) => undefined);
type RuntimeDotEnvLoadResult = {
gatewayEnvAppliedKeys: string[];
stateEnvAppliedKeys: string[];
};
const loadGlobalRuntimeDotEnvFiles = vi.fn<
(_opts?: unknown) => RuntimeDotEnvLoadResult | undefined
>(() => undefined);
const beforeRun = vi.fn(async () => {
callOrder.push("bootstrap");
});
+8 -1
View File
@@ -10,7 +10,14 @@ const DISCORD_REPO_INSTALL_SPEC = repoInstallSpec("discord");
const setVerboseMock = vi.fn();
const emitCliBannerMock = vi.fn();
const ensureConfigReadyMock = vi.fn(async () => {});
type EnsureConfigReadyOptions = {
beforeStateMigrations?: () => Promise<boolean>;
commandPath?: string[];
requireConfig?: boolean;
};
const ensureConfigReadyMock = vi.fn<(_opts: EnsureConfigReadyOptions) => Promise<void>>(
async () => {},
);
const ensurePluginRegistryLoadedMock = vi.fn();
const routeLogsToStderrMock = vi.fn();
const prepareGatewayRunBootstrapMock = vi.fn(async () => true);
+12 -2
View File
@@ -77,8 +77,18 @@ const runCrestodianMock = vi.hoisted(() =>
vi.fn<(options?: unknown) => Promise<void>>(async () => {}),
);
const commanderParseAsyncMock = vi.hoisted(() => vi.fn(async () => {}));
const addGatewayRunCommandMock = vi.hoisted(() => vi.fn((command: unknown) => command));
const ensureCliExecutionBootstrapMock = vi.hoisted(() => vi.fn(async () => {}));
type GatewayRunCommandHooks = {
beforeRun?: (opts: { reset?: boolean }) => Promise<void>;
};
type CliExecutionBootstrapOptions = {
beforeStateMigrations?: () => Promise<boolean>;
};
const addGatewayRunCommandMock = vi.hoisted(() =>
vi.fn<(command: unknown, hooks?: GatewayRunCommandHooks) => unknown>((command) => command),
);
const ensureCliExecutionBootstrapMock = vi.hoisted(() =>
vi.fn<(_opts: CliExecutionBootstrapOptions) => Promise<void>>(async () => {}),
);
const emitCliBannerMock = vi.hoisted(() => vi.fn());
const enableConsoleCaptureMock = vi.hoisted(() => vi.fn());
const progressDoneMock = vi.hoisted(() => vi.fn());
@@ -52,7 +52,9 @@ describe("runDoctorConfigPreflight state migration", () => {
});
it("runs the startup guard immediately before the first state mutation", async () => {
const beforeStateMigrations = vi.fn(async () => true);
const beforeStateMigrations = vi.fn<(_snapshot?: unknown) => Promise<boolean>>(
async () => true,
);
await runDoctorConfigPreflight({
migrateLegacyConfig: false,
+1 -1
View File
@@ -405,7 +405,7 @@ describe("shell env fallback", () => {
exec: (() =>
Buffer.from(
"OPENAI_API_KEY=openai-shell\0ANTHROPIC_API_KEY=anthropic-shell\0",
)) as Parameters<typeof loadShellEnvFallback>[0]["exec"],
)) as unknown as Parameters<typeof loadShellEnvFallback>[0]["exec"],
});
clearShellEnvAppliedKeys(["OPENAI_API_KEY"]);