refactor: clean runtime env helper types · openclaw/openclaw@da6d894
steipete
·
2026-04-28
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | import type { OutputRuntimeEnv } from "openclaw/plugin-sdk/runtime"; |
2 | 2 | import { vi } from "vitest"; |
3 | 3 | |
4 | | -export function createRuntimeEnv(options?: { throwOnExit?: boolean }): OutputRuntimeEnv { |
| 4 | +type RuntimeEnvOptions = { |
| 5 | +throwOnExit?: boolean; |
| 6 | +}; |
| 7 | + |
| 8 | +type TypedRuntimeEnvOptions<TRuntime extends OutputRuntimeEnv> = RuntimeEnvOptions & { |
| 9 | +readonly __runtimeShape?: (runtime: TRuntime) => void; |
| 10 | +}; |
| 11 | + |
| 12 | +export function createRuntimeEnv(options?: RuntimeEnvOptions): OutputRuntimeEnv { |
5 | 13 | const throwOnExit = options?.throwOnExit ?? true; |
6 | 14 | return { |
7 | 15 | log: vi.fn(), |
@@ -16,16 +24,18 @@ export function createRuntimeEnv(options?: { throwOnExit?: boolean }): OutputRun
|
16 | 24 | }; |
17 | 25 | } |
18 | 26 | |
19 | | -// oxlint-disable-next-line typescript/no-unnecessary-type-parameters -- Test helper lets plugin suites ascribe runtime extension shape. |
20 | | -export function createTypedRuntimeEnv<TRuntime>(options?: { throwOnExit?: boolean }): TRuntime { |
| 27 | +export function createTypedRuntimeEnv<TRuntime extends OutputRuntimeEnv>( |
| 28 | +options?: TypedRuntimeEnvOptions<TRuntime>, |
| 29 | +): TRuntime { |
21 | 30 | return createRuntimeEnv(options) as TRuntime; |
22 | 31 | } |
23 | 32 | |
24 | 33 | export function createNonExitingRuntimeEnv(): OutputRuntimeEnv { |
25 | 34 | return createRuntimeEnv({ throwOnExit: false }); |
26 | 35 | } |
27 | 36 | |
28 | | -// oxlint-disable-next-line typescript/no-unnecessary-type-parameters -- Test helper lets plugin suites ascribe runtime extension shape. |
29 | | -export function createNonExitingTypedRuntimeEnv<TRuntime>(): TRuntime { |
30 | | -return createTypedRuntimeEnv<TRuntime>({ throwOnExit: false }); |
| 37 | +export function createNonExitingTypedRuntimeEnv<TRuntime extends OutputRuntimeEnv>( |
| 38 | +runtimeShape?: (runtime: TRuntime) => void, |
| 39 | +): TRuntime { |
| 40 | +return createTypedRuntimeEnv<TRuntime>({ throwOnExit: false, __runtimeShape: runtimeShape }); |
31 | 41 | } |
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。