mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 07:10:43 +00:00
test(agents): trim hot replay approval suites
This commit is contained in:
@@ -4,7 +4,10 @@ import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { clearConfigCache, clearRuntimeConfigSnapshot } from "../config/config.js";
|
||||
import { sendMessage } from "../infra/outbound/message.js";
|
||||
import { buildSystemRunPreparePayload } from "../test-utils/system-run-prepare-payload.js";
|
||||
import { createExecTool } from "./bash-tools.exec.js";
|
||||
import { callGatewayTool } from "./tools/gateway.js";
|
||||
|
||||
vi.mock("./tools/gateway.js", () => ({
|
||||
callGatewayTool: vi.fn(),
|
||||
@@ -22,10 +25,6 @@ vi.mock("../infra/outbound/message.js", () => ({
|
||||
sendMessage: vi.fn(async () => ({ ok: true })),
|
||||
}));
|
||||
|
||||
let callGatewayTool: typeof import("./tools/gateway.js").callGatewayTool;
|
||||
let createExecTool: typeof import("./bash-tools.exec.js").createExecTool;
|
||||
let sendMessage: typeof import("../infra/outbound/message.js").sendMessage;
|
||||
|
||||
function buildPreparedSystemRunPayload(rawInvokeParams: unknown) {
|
||||
const invoke = (rawInvokeParams ?? {}) as {
|
||||
params?: {
|
||||
@@ -224,7 +223,6 @@ describe("exec approvals", () => {
|
||||
let previousDisableBundledPlugins: string | undefined;
|
||||
|
||||
beforeEach(async () => {
|
||||
vi.resetModules();
|
||||
previousHome = process.env.HOME;
|
||||
previousUserProfile = process.env.USERPROFILE;
|
||||
previousBundledPluginsDir = process.env.OPENCLAW_BUNDLED_PLUGINS_DIR;
|
||||
@@ -235,9 +233,6 @@ describe("exec approvals", () => {
|
||||
process.env.USERPROFILE = tempDir;
|
||||
delete process.env.OPENCLAW_BUNDLED_PLUGINS_DIR;
|
||||
process.env.OPENCLAW_DISABLE_BUNDLED_PLUGINS = "1";
|
||||
({ callGatewayTool } = await import("./tools/gateway.js"));
|
||||
({ createExecTool } = await import("./bash-tools.exec.js"));
|
||||
({ sendMessage } = await import("../infra/outbound/message.js"));
|
||||
vi.mocked(callGatewayTool).mockReset();
|
||||
vi.mocked(sendMessage).mockClear();
|
||||
});
|
||||
|
||||
@@ -143,42 +143,7 @@ type WrapProviderStreamFnParams = Parameters<
|
||||
typeof import("../plugins/provider-hook-runtime.js").wrapProviderStreamFn
|
||||
>[0];
|
||||
|
||||
function createTestOpenAIProviderWrapper(
|
||||
params: WrapProviderStreamFnParams,
|
||||
withDefaultTransport: boolean,
|
||||
): StreamFn {
|
||||
let streamFn = params.context.streamFn;
|
||||
if (withDefaultTransport) {
|
||||
streamFn = createOpenAIDefaultTransportWrapper(streamFn);
|
||||
}
|
||||
streamFn = createOpenAIAttributionHeadersWrapper(streamFn);
|
||||
|
||||
if (resolveOpenAIFastMode(params.context.extraParams)) {
|
||||
streamFn = createOpenAIFastModeWrapper(streamFn);
|
||||
}
|
||||
|
||||
const serviceTier = resolveOpenAIServiceTier(params.context.extraParams);
|
||||
if (serviceTier) {
|
||||
streamFn = createOpenAIServiceTierWrapper(streamFn, serviceTier);
|
||||
}
|
||||
|
||||
const textVerbosity = resolveOpenAITextVerbosity(params.context.extraParams);
|
||||
if (textVerbosity) {
|
||||
streamFn = createOpenAITextVerbosityWrapper(streamFn, textVerbosity);
|
||||
}
|
||||
|
||||
streamFn = createCodexNativeWebSearchWrapper(streamFn, {
|
||||
config: params.context.config,
|
||||
agentDir: params.context.agentDir,
|
||||
});
|
||||
streamFn = createOpenAIStringContentWrapper(streamFn);
|
||||
return createOpenAIResponsesContextManagementWrapper(
|
||||
createOpenAIReasoningCompatibilityWrapper(streamFn),
|
||||
params.context.extraParams,
|
||||
);
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
function installFullProviderRuntimeDepsForTest() {
|
||||
extraParamsTesting.setProviderRuntimeDepsForTest({
|
||||
prepareProviderExtraParams: (params) => {
|
||||
if (params.provider !== "openai-codex") {
|
||||
@@ -262,6 +227,57 @@ beforeEach(() => {
|
||||
return params.context.streamFn;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function withMinimalProviderRuntimeDepsForTest<T>(run: () => T): T {
|
||||
extraParamsTesting.setProviderRuntimeDepsForTest({
|
||||
prepareProviderExtraParams: () => undefined,
|
||||
wrapProviderStreamFn: (params) => params.context.streamFn,
|
||||
});
|
||||
try {
|
||||
return run();
|
||||
} finally {
|
||||
installFullProviderRuntimeDepsForTest();
|
||||
}
|
||||
}
|
||||
|
||||
function createTestOpenAIProviderWrapper(
|
||||
params: WrapProviderStreamFnParams,
|
||||
withDefaultTransport: boolean,
|
||||
): StreamFn {
|
||||
let streamFn = params.context.streamFn;
|
||||
if (withDefaultTransport) {
|
||||
streamFn = createOpenAIDefaultTransportWrapper(streamFn);
|
||||
}
|
||||
streamFn = createOpenAIAttributionHeadersWrapper(streamFn);
|
||||
|
||||
if (resolveOpenAIFastMode(params.context.extraParams)) {
|
||||
streamFn = createOpenAIFastModeWrapper(streamFn);
|
||||
}
|
||||
|
||||
const serviceTier = resolveOpenAIServiceTier(params.context.extraParams);
|
||||
if (serviceTier) {
|
||||
streamFn = createOpenAIServiceTierWrapper(streamFn, serviceTier);
|
||||
}
|
||||
|
||||
const textVerbosity = resolveOpenAITextVerbosity(params.context.extraParams);
|
||||
if (textVerbosity) {
|
||||
streamFn = createOpenAITextVerbosityWrapper(streamFn, textVerbosity);
|
||||
}
|
||||
|
||||
streamFn = createCodexNativeWebSearchWrapper(streamFn, {
|
||||
config: params.context.config,
|
||||
agentDir: params.context.agentDir,
|
||||
});
|
||||
streamFn = createOpenAIStringContentWrapper(streamFn);
|
||||
return createOpenAIResponsesContextManagementWrapper(
|
||||
createOpenAIReasoningCompatibilityWrapper(streamFn),
|
||||
params.context.extraParams,
|
||||
);
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
installFullProviderRuntimeDepsForTest();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -362,22 +378,24 @@ describe("applyExtraParamsToAgent", () => {
|
||||
extraParamsOverride?: Record<string, unknown>;
|
||||
payload?: Record<string, unknown>;
|
||||
}) {
|
||||
const payload = params.payload ?? {};
|
||||
const baseStreamFn: StreamFn = (model, _context, options) => {
|
||||
options?.onPayload?.(payload, model);
|
||||
return {} as ReturnType<StreamFn>;
|
||||
};
|
||||
const agent = { streamFn: baseStreamFn };
|
||||
applyExtraParamsToAgent(
|
||||
agent,
|
||||
params.cfg as Parameters<typeof applyExtraParamsToAgent>[1],
|
||||
params.applyProvider,
|
||||
params.applyModelId,
|
||||
params.extraParamsOverride,
|
||||
);
|
||||
const context: Context = { messages: [] };
|
||||
void agent.streamFn?.(params.model, context, {});
|
||||
return payload;
|
||||
return withMinimalProviderRuntimeDepsForTest(() => {
|
||||
const payload = params.payload ?? {};
|
||||
const baseStreamFn: StreamFn = (model, _context, options) => {
|
||||
options?.onPayload?.(payload, model);
|
||||
return {} as ReturnType<StreamFn>;
|
||||
};
|
||||
const agent = { streamFn: baseStreamFn };
|
||||
applyExtraParamsToAgent(
|
||||
agent,
|
||||
params.cfg as Parameters<typeof applyExtraParamsToAgent>[1],
|
||||
params.applyProvider,
|
||||
params.applyModelId,
|
||||
params.extraParamsOverride,
|
||||
);
|
||||
const context: Context = { messages: [] };
|
||||
void agent.streamFn?.(params.model, context, {});
|
||||
return payload;
|
||||
});
|
||||
}
|
||||
|
||||
function runToolPayloadMutationCase(params: {
|
||||
|
||||
Reference in New Issue
Block a user