refactor: clean runtime env helper types

This commit is contained in:
Peter Steinberger
2026-04-28 00:02:20 +01:00
parent ccc9dd5eef
commit da6d8940a0

View File

@@ -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 });
}