mirror of
https://fastgit.cc/github.com/openclaw/openclaw
synced 2026-05-01 06:36:23 +08:00
refactor: clean runtime env helper types
This commit is contained in:
@@ -1,7 +1,15 @@
|
||||
import type { OutputRuntimeEnv } from "openclaw/plugin-sdk/runtime";
|
||||
import { vi } from "vitest";
|
||||
|
||||
export function createRuntimeEnv(options?: { throwOnExit?: boolean }): OutputRuntimeEnv {
|
||||
type RuntimeEnvOptions = {
|
||||
throwOnExit?: boolean;
|
||||
};
|
||||
|
||||
type TypedRuntimeEnvOptions<TRuntime extends OutputRuntimeEnv> = RuntimeEnvOptions & {
|
||||
readonly __runtimeShape?: (runtime: TRuntime) => void;
|
||||
};
|
||||
|
||||
export function createRuntimeEnv(options?: RuntimeEnvOptions): OutputRuntimeEnv {
|
||||
const throwOnExit = options?.throwOnExit ?? true;
|
||||
return {
|
||||
log: vi.fn(),
|
||||
@@ -16,8 +24,9 @@ export function createRuntimeEnv(options?: { throwOnExit?: boolean }): OutputRun
|
||||
};
|
||||
}
|
||||
|
||||
// oxlint-disable-next-line typescript/no-unnecessary-type-parameters -- Test helper lets plugin suites ascribe runtime extension shape.
|
||||
export function createTypedRuntimeEnv<TRuntime>(options?: { throwOnExit?: boolean }): TRuntime {
|
||||
export function createTypedRuntimeEnv<TRuntime extends OutputRuntimeEnv>(
|
||||
options?: TypedRuntimeEnvOptions<TRuntime>,
|
||||
): TRuntime {
|
||||
return createRuntimeEnv(options) as TRuntime;
|
||||
}
|
||||
|
||||
@@ -25,7 +34,8 @@ export function createNonExitingRuntimeEnv(): OutputRuntimeEnv {
|
||||
return createRuntimeEnv({ throwOnExit: false });
|
||||
}
|
||||
|
||||
// oxlint-disable-next-line typescript/no-unnecessary-type-parameters -- Test helper lets plugin suites ascribe runtime extension shape.
|
||||
export function createNonExitingTypedRuntimeEnv<TRuntime>(): TRuntime {
|
||||
return createTypedRuntimeEnv<TRuntime>({ throwOnExit: false });
|
||||
export function createNonExitingTypedRuntimeEnv<TRuntime extends OutputRuntimeEnv>(
|
||||
runtimeShape?: (runtime: TRuntime) => void,
|
||||
): TRuntime {
|
||||
return createTypedRuntimeEnv<TRuntime>({ throwOnExit: false, __runtimeShape: runtimeShape });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user