test: type cli test mocks · openclaw/openclaw@5c2487d
shakkernerd
·
2026-06-16
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -31,7 +31,13 @@ const runGatewayLoop = vi.fn(async ({ start }: { start: GatewayLoopStart }) => {
|
31 | 31 | const normalizeStateDirEnv = vi.fn((_env?: NodeJS.ProcessEnv) => undefined); |
32 | 32 | const pinConfigDir = vi.fn((_env?: NodeJS.ProcessEnv) => undefined); |
33 | 33 | const pinRuntimePaths = vi.fn((_env?: NodeJS.ProcessEnv) => undefined); |
34 | | -const loadGlobalRuntimeDotEnvFiles = vi.fn((_opts?: unknown) => undefined); |
| 34 | +type RuntimeDotEnvLoadResult = { |
| 35 | +gatewayEnvAppliedKeys: string[]; |
| 36 | +stateEnvAppliedKeys: string[]; |
| 37 | +}; |
| 38 | +const loadGlobalRuntimeDotEnvFiles = vi.fn< |
| 39 | +(_opts?: unknown) => RuntimeDotEnvLoadResult | undefined |
| 40 | +>(() => undefined); |
35 | 41 | const beforeRun = vi.fn(async () => { |
36 | 42 | callOrder.push("bootstrap"); |
37 | 43 | }); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -10,7 +10,14 @@ const DISCORD_REPO_INSTALL_SPEC = repoInstallSpec("discord");
|
10 | 10 | |
11 | 11 | const setVerboseMock = vi.fn(); |
12 | 12 | const emitCliBannerMock = vi.fn(); |
13 | | -const ensureConfigReadyMock = vi.fn(async () => {}); |
| 13 | +type EnsureConfigReadyOptions = { |
| 14 | +beforeStateMigrations?: () => Promise<boolean>; |
| 15 | +commandPath?: string[]; |
| 16 | +requireConfig?: boolean; |
| 17 | +}; |
| 18 | +const ensureConfigReadyMock = vi.fn<(_opts: EnsureConfigReadyOptions) => Promise<void>>( |
| 19 | +async () => {}, |
| 20 | +); |
14 | 21 | const ensurePluginRegistryLoadedMock = vi.fn(); |
15 | 22 | const routeLogsToStderrMock = vi.fn(); |
16 | 23 | const prepareGatewayRunBootstrapMock = vi.fn(async () => true); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -77,8 +77,18 @@ const runCrestodianMock = vi.hoisted(() =>
|
77 | 77 | vi.fn<(options?: unknown) => Promise<void>>(async () => {}), |
78 | 78 | ); |
79 | 79 | const commanderParseAsyncMock = vi.hoisted(() => vi.fn(async () => {})); |
80 | | -const addGatewayRunCommandMock = vi.hoisted(() => vi.fn((command: unknown) => command)); |
81 | | -const ensureCliExecutionBootstrapMock = vi.hoisted(() => vi.fn(async () => {})); |
| 80 | +type GatewayRunCommandHooks = { |
| 81 | +beforeRun?: (opts: { reset?: boolean }) => Promise<void>; |
| 82 | +}; |
| 83 | +type CliExecutionBootstrapOptions = { |
| 84 | +beforeStateMigrations?: () => Promise<boolean>; |
| 85 | +}; |
| 86 | +const addGatewayRunCommandMock = vi.hoisted(() => |
| 87 | +vi.fn<(command: unknown, hooks?: GatewayRunCommandHooks) => unknown>((command) => command), |
| 88 | +); |
| 89 | +const ensureCliExecutionBootstrapMock = vi.hoisted(() => |
| 90 | +vi.fn<(_opts: CliExecutionBootstrapOptions) => Promise<void>>(async () => {}), |
| 91 | +); |
82 | 92 | const emitCliBannerMock = vi.hoisted(() => vi.fn()); |
83 | 93 | const enableConsoleCaptureMock = vi.hoisted(() => vi.fn()); |
84 | 94 | const progressDoneMock = vi.hoisted(() => vi.fn()); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -52,7 +52,9 @@ describe("runDoctorConfigPreflight state migration", () => {
|
52 | 52 | }); |
53 | 53 | |
54 | 54 | it("runs the startup guard immediately before the first state mutation", async () => { |
55 | | -const beforeStateMigrations = vi.fn(async () => true); |
| 55 | +const beforeStateMigrations = vi.fn<(_snapshot?: unknown) => Promise<boolean>>( |
| 56 | +async () => true, |
| 57 | +); |
56 | 58 | |
57 | 59 | await runDoctorConfigPreflight({ |
58 | 60 | migrateLegacyConfig: false, |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -405,7 +405,7 @@ describe("shell env fallback", () => {
|
405 | 405 | exec: (() => |
406 | 406 | Buffer.from( |
407 | 407 | "OPENAI_API_KEY=openai-shell\0ANTHROPIC_API_KEY=anthropic-shell\0", |
408 | | -)) as Parameters<typeof loadShellEnvFallback>[0]["exec"], |
| 408 | +)) as unknown as Parameters<typeof loadShellEnvFallback>[0]["exec"], |
409 | 409 | }); |
410 | 410 | |
411 | 411 | clearShellEnvAppliedKeys(["OPENAI_API_KEY"]); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。