From 8a10903cf7118fc685cc5d4885aa94fad70ee679 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 16 Mar 2026 18:37:49 -0700 Subject: [PATCH] test: fix check contract type drift --- src/channels/plugins/contracts/suites.ts | 8 +++++++- src/plugins/bundle-mcp.test.ts | 18 ++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/channels/plugins/contracts/suites.ts b/src/channels/plugins/contracts/suites.ts index 90d852e7923..cfd4e17eeff 100644 --- a/src/channels/plugins/contracts/suites.ts +++ b/src/channels/plugins/contracts/suites.ts @@ -9,6 +9,7 @@ import type { SessionBindingCapabilities, SessionBindingRecord, } from "../../../infra/outbound/session-binding-service.js"; +import { createNonExitingRuntime } from "../../../runtime.js"; import { normalizeChatType } from "../../chat-type.js"; import { resolveConversationLabel } from "../../conversation-label.js"; import { validateSenderIdentity } from "../../sender-identity.js"; @@ -31,6 +32,8 @@ function sortStrings(values: readonly string[]) { return [...values].toSorted((left, right) => left.localeCompare(right)); } +const contractRuntime = createNonExitingRuntime(); + function expectDirectoryEntryShape(entry: ChannelDirectoryEntry) { expect(["user", "group", "channel"]).toContain(entry.kind); expect(typeof entry.id).toBe("string"); @@ -404,6 +407,7 @@ export function installChannelDirectoryContractSuite(params: { const self = await directory?.self?.({ cfg: {} as OpenClawConfig, accountId: "default", + runtime: contractRuntime, }); if (self) { expectDirectoryEntryShape(self); @@ -415,6 +419,7 @@ export function installChannelDirectoryContractSuite(params: { accountId: "default", query: "", limit: 5, + runtime: contractRuntime, })) ?? []; expect(Array.isArray(peers)).toBe(true); for (const peer of peers) { @@ -427,6 +432,7 @@ export function installChannelDirectoryContractSuite(params: { accountId: "default", query: "", limit: 5, + runtime: contractRuntime, })) ?? []; expect(Array.isArray(groups)).toBe(true); for (const group of groups) { @@ -438,8 +444,8 @@ export function installChannelDirectoryContractSuite(params: { cfg: {} as OpenClawConfig, accountId: "default", groupId: groups[0].id, - query: "", limit: 5, + runtime: contractRuntime, }); expect(Array.isArray(members)).toBe(true); for (const member of members) { diff --git a/src/plugins/bundle-mcp.test.ts b/src/plugins/bundle-mcp.test.ts index 4285b64e660..939580f9cfe 100644 --- a/src/plugins/bundle-mcp.test.ts +++ b/src/plugins/bundle-mcp.test.ts @@ -4,11 +4,16 @@ import path from "node:path"; import { afterEach, describe, expect, it } from "vitest"; import type { OpenClawConfig } from "../config/config.js"; import { captureEnv } from "../test-utils/env.js"; +import { isRecord } from "../utils.js"; import { loadEnabledBundleMcpConfig } from "./bundle-mcp.js"; import { clearPluginManifestRegistryCache } from "./manifest-registry.js"; const tempDirs: string[] = []; +function getServerArgs(value: unknown): unknown[] | undefined { + return isRecord(value) && Array.isArray(value.args) ? value.args : undefined; +} + async function createTempDir(prefix: string): Promise { const dir = await fs.mkdtemp(path.join(os.tmpdir(), prefix)); tempDirs.push(dir); @@ -73,13 +78,18 @@ describe("loadEnabledBundleMcpConfig", () => { cfg: config, }); const resolvedServerPath = await fs.realpath(serverPath); - const loadedServerPath = loaded.config.mcpServers.bundleProbe?.args?.[0]; + const loadedServer = loaded.config.mcpServers.bundleProbe; + const loadedArgs = getServerArgs(loadedServer); + const loadedServerPath = typeof loadedArgs?.[0] === "string" ? loadedArgs[0] : undefined; expect(loaded.diagnostics).toEqual([]); - expect(loaded.config.mcpServers.bundleProbe?.command).toBe("node"); - expect(loaded.config.mcpServers.bundleProbe?.args).toHaveLength(1); + expect(isRecord(loadedServer) ? loadedServer.command : undefined).toBe("node"); + expect(loadedArgs).toHaveLength(1); expect(loadedServerPath).toBeDefined(); - expect(await fs.realpath(loadedServerPath as string)).toBe(resolvedServerPath); + if (!loadedServerPath) { + throw new Error("expected bundled MCP args to include the server path"); + } + expect(await fs.realpath(loadedServerPath)).toBe(resolvedServerPath); } finally { env.restore(); }