From da6d8940a00a3b5602e45916149d165bb00250b2 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 28 Apr 2026 00:02:20 +0100 Subject: [PATCH] refactor: clean runtime env helper types --- src/test-utils/plugin-runtime-env.ts | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/test-utils/plugin-runtime-env.ts b/src/test-utils/plugin-runtime-env.ts index cb993f567be..f9482fc1d90 100644 --- a/src/test-utils/plugin-runtime-env.ts +++ b/src/test-utils/plugin-runtime-env.ts @@ -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 = 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(options?: { throwOnExit?: boolean }): TRuntime { +export function createTypedRuntimeEnv( + options?: TypedRuntimeEnvOptions, +): 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 { - return createTypedRuntimeEnv({ throwOnExit: false }); +export function createNonExitingTypedRuntimeEnv( + runtimeShape?: (runtime: TRuntime) => void, +): TRuntime { + return createTypedRuntimeEnv({ throwOnExit: false, __runtimeShape: runtimeShape }); }