






















@@ -1,3 +1,4 @@
1+import { AsyncLocalStorage } from "node:async_hooks";
12import { createHash } from "node:crypto";
23import fs from "node:fs/promises";
34import path from "node:path";
@@ -46,8 +47,8 @@ import {
4647resolveCodexAppServerAuthProfileIdForAgent,
4748} from "./auth-bridge.js";
4849import {
49-createCodexAppServerClientFactoryTestHooks,
5050defaultCodexAppServerClientFactory,
51+type CodexAppServerClientFactory,
5152} from "./client-factory.js";
5253import {
5354isCodexAppServerApprovalRequest,
@@ -126,8 +127,16 @@ const CODEX_BOOTSTRAP_CONTEXT_ORDER = new Map<string, number>([
126127type OpenClawCodingToolsOptions = NonNullable<
127128Parameters<(typeof import("openclaw/plugin-sdk/agent-harness"))["createOpenClawCodingTools"]>[0]
128129>;
130+type OpenClawCodingToolsFactory =
131+(typeof import("openclaw/plugin-sdk/agent-harness"))["createOpenClawCodingTools"];
129132130-let clientFactory = defaultCodexAppServerClientFactory;
133+const testClientFactoryStorage = new AsyncLocalStorage<CodexAppServerClientFactory | undefined>();
134+const clientFactory = defaultCodexAppServerClientFactory;
135+let openClawCodingToolsFactoryForTests: OpenClawCodingToolsFactory | undefined;
136+137+function resolveCodexAppServerClientFactory(): CodexAppServerClientFactory {
138+return testClientFactoryStorage.getStore() ?? clientFactory;
139+}
131140132141function emitCodexAppServerEvent(
133142params: EmbeddedRunAttemptParams,
@@ -351,7 +360,7 @@ export async function runCodexAppServerAttempt(
351360} = {},
352361): Promise<EmbeddedRunAttemptResult> {
353362const attemptStartedAt = Date.now();
354-const attemptClientFactory = clientFactory;
363+const attemptClientFactory = resolveCodexAppServerClientFactory();
355364const pluginConfig = readCodexPluginConfig(options.pluginConfig);
356365const appServer = resolveCodexAppServerRuntimeOptions({ pluginConfig });
357366const resolvedWorkspace = resolveUserPath(params.workspaceDir);
@@ -1478,7 +1487,9 @@ async function buildDynamicTools(input: DynamicToolBuildParams) {
14781487}
14791488const modelHasVision = params.model.input?.includes("image") ?? false;
14801489const agentDir = params.agentDir ?? resolveAgentDir(params.config ?? {}, input.sessionAgentId);
1481-const { createOpenClawCodingTools } = await import("openclaw/plugin-sdk/agent-harness");
1490+const createOpenClawCodingTools =
1491+openClawCodingToolsFactoryForTests ??
1492+(await import("openclaw/plugin-sdk/agent-harness")).createOpenClawCodingTools;
14821493const allTools = createOpenClawCodingTools({
14831494agentId: input.sessionAgentId,
14841495 ...buildEmbeddedAttemptToolRunContext(params),
@@ -1963,7 +1974,16 @@ export const __testing = {
19631974 buildDynamicTools,
19641975 filterToolsForVisionInputs,
19651976 handleDynamicToolCallWithTimeout,
1966- ...createCodexAppServerClientFactoryTestHooks((factory) => {
1967-clientFactory = factory;
1968-}),
1977+setOpenClawCodingToolsFactoryForTests(factory: OpenClawCodingToolsFactory): void {
1978+openClawCodingToolsFactoryForTests = factory;
1979+},
1980+resetOpenClawCodingToolsFactoryForTests(): void {
1981+openClawCodingToolsFactoryForTests = undefined;
1982+},
1983+setCodexAppServerClientFactoryForTests(factory: CodexAppServerClientFactory): void {
1984+testClientFactoryStorage.enterWith(factory);
1985+},
1986+resetCodexAppServerClientFactoryForTests(): void {
1987+testClientFactoryStorage.enterWith(undefined);
1988+},
19691989} as const;
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。