mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 06:30:42 +00:00
test: trim runtime import surfaces
This commit is contained in:
@@ -2,7 +2,7 @@ import crypto from "node:crypto";
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { clearConfigCache, clearRuntimeConfigSnapshot } from "../config/io.js";
|
||||
import { sendMessage } from "../infra/outbound/message.js";
|
||||
import { buildSystemRunPreparePayload } from "../test-utils/system-run-prepare-payload.js";
|
||||
@@ -221,13 +221,20 @@ describe("exec approvals", () => {
|
||||
let previousUserProfile: string | undefined;
|
||||
let previousBundledPluginsDir: string | undefined;
|
||||
let previousDisableBundledPlugins: string | undefined;
|
||||
let tempRoot = "";
|
||||
let tempCaseIndex = 0;
|
||||
|
||||
beforeAll(async () => {
|
||||
tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-exec-approvals-"));
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
previousHome = process.env.HOME;
|
||||
previousUserProfile = process.env.USERPROFILE;
|
||||
previousBundledPluginsDir = process.env.OPENCLAW_BUNDLED_PLUGINS_DIR;
|
||||
previousDisableBundledPlugins = process.env.OPENCLAW_DISABLE_BUNDLED_PLUGINS;
|
||||
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-test-"));
|
||||
const tempDir = path.join(tempRoot, `case-${++tempCaseIndex}`);
|
||||
await fs.mkdir(tempDir, { recursive: true });
|
||||
process.env.HOME = tempDir;
|
||||
// Windows uses USERPROFILE for os.homedir()
|
||||
process.env.USERPROFILE = tempDir;
|
||||
@@ -263,6 +270,12 @@ describe("exec approvals", () => {
|
||||
}
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
if (tempRoot) {
|
||||
await fs.rm(tempRoot, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it("reuses approval id as the node runId", async () => {
|
||||
let invokeParams: unknown;
|
||||
let agentParams: unknown;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { afterAll, describe, expect, it } from "vitest";
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
import type { OpenClawConfig } from "../../config/types.openclaw.js";
|
||||
import {
|
||||
createBundleMcpTempHarness,
|
||||
createBundleProbePlugin,
|
||||
|
||||
@@ -9,20 +9,14 @@ import {
|
||||
withTempEnv,
|
||||
} from "./models-config.e2e-harness.js";
|
||||
|
||||
vi.mock("../plugins/provider-runtime.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("../plugins/provider-runtime.js")>(
|
||||
"../plugins/provider-runtime.js",
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
applyProviderConfigDefaultsWithPlugin: (config: OpenClawConfig) => config,
|
||||
applyProviderNativeStreamingUsageCompatWithPlugin: () => undefined,
|
||||
normalizeProviderConfigWithPlugin: () => undefined,
|
||||
resetProviderRuntimeHookCacheForTest: () => undefined,
|
||||
resolveProviderConfigApiKeyWithPlugin: () => undefined,
|
||||
resolveProviderSyntheticAuthWithPlugin: () => undefined,
|
||||
};
|
||||
});
|
||||
vi.mock("../plugins/provider-runtime.js", () => ({
|
||||
applyProviderConfigDefaultsWithPlugin: (config: OpenClawConfig) => config,
|
||||
applyProviderNativeStreamingUsageCompatWithPlugin: () => undefined,
|
||||
normalizeProviderConfigWithPlugin: () => undefined,
|
||||
resetProviderRuntimeHookCacheForTest: () => undefined,
|
||||
resolveProviderConfigApiKeyWithPlugin: () => undefined,
|
||||
resolveProviderSyntheticAuthWithPlugin: () => undefined,
|
||||
}));
|
||||
|
||||
vi.mock("./models-config.providers.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("./models-config.providers.js")>(
|
||||
|
||||
@@ -9,7 +9,6 @@ import {
|
||||
normalizeReservedToolNames,
|
||||
TOOL_NAME_SEPARATOR,
|
||||
} from "./pi-bundle-mcp-names.js";
|
||||
import { createSessionMcpRuntime } from "./pi-bundle-mcp-runtime.js";
|
||||
import type { BundleMcpToolRuntime, SessionMcpRuntime } from "./pi-bundle-mcp-types.js";
|
||||
|
||||
function toAgentToolResult(params: {
|
||||
@@ -131,6 +130,7 @@ export async function createBundleMcpToolRuntime(params: {
|
||||
cfg?: OpenClawConfig;
|
||||
reservedToolNames?: Iterable<string>;
|
||||
}): Promise<BundleMcpToolRuntime> {
|
||||
const { createSessionMcpRuntime } = await import("./pi-bundle-mcp-runtime.js");
|
||||
const runtime = createSessionMcpRuntime({
|
||||
sessionId: `bundle-mcp:${crypto.randomUUID()}`,
|
||||
workspaceDir: params.workspaceDir,
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import path from "node:path";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
createBundleMcpToolRuntime,
|
||||
materializeBundleMcpToolsForRun,
|
||||
} from "./pi-bundle-mcp-materialize.js";
|
||||
import {
|
||||
cleanupBundleMcpHarness,
|
||||
makeTempDir,
|
||||
startSseProbeServer,
|
||||
writeBundleProbeMcpServer,
|
||||
} from "./pi-bundle-mcp-test-harness.js";
|
||||
import {
|
||||
createBundleMcpToolRuntime,
|
||||
materializeBundleMcpToolsForRun,
|
||||
} from "./pi-bundle-mcp-tools.js";
|
||||
import type { McpCatalogTool } from "./pi-bundle-mcp-types.js";
|
||||
import type { SessionMcpRuntime } from "./pi-bundle-mcp-types.js";
|
||||
|
||||
|
||||
@@ -205,7 +205,7 @@ describe("acquireSessionWriteLock", () => {
|
||||
|
||||
it("watchdog releases stale in-process locks", async () => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-lock-"));
|
||||
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
||||
const stderrSpy = vi.spyOn(process.stderr, "write").mockImplementation(() => true);
|
||||
try {
|
||||
const sessionFile = path.join(root, "session.jsonl");
|
||||
const lockPath = `${sessionFile}.lock`;
|
||||
@@ -229,7 +229,7 @@ describe("acquireSessionWriteLock", () => {
|
||||
secondLock: lockB,
|
||||
});
|
||||
} finally {
|
||||
warnSpy.mockRestore();
|
||||
stderrSpy.mockRestore();
|
||||
await fs.rm(root, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user