File size: 938 Bytes
253e783
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import type { RunResult } from "./invoke-types.js";
import "./invoke.js";

type NodeHostInvokeTestApi = {
  clarifyNodeExecCwdSpawnError(error: NodeJS.ErrnoException, cwd: string | undefined): string;
  runCommand(
    argv: string[],
    cwd: string | undefined,
    env: Record<string, string> | undefined,
    timeoutMs: number | undefined,
    signal?: AbortSignal,
    assertCurrent?: () => void,
  ): Promise<RunResult>;
};

function getTestApi(): NodeHostInvokeTestApi {
  return (globalThis as Record<PropertyKey, unknown>)[
    Symbol.for("openclaw.nodeHostInvokeTestApi")
  ] as NodeHostInvokeTestApi;
}

export const testing: NodeHostInvokeTestApi = {
  clarifyNodeExecCwdSpawnError(error, cwd) {
    return getTestApi().clarifyNodeExecCwdSpawnError(error, cwd);
  },
  runCommand(argv, cwd, env, timeoutMs, signal, assertCurrent) {
    return getTestApi().runCommand(argv, cwd, env, timeoutMs, signal, assertCurrent);
  },
};