test: fix check contract type drift

This commit is contained in:
Peter Steinberger
2026-03-16 18:37:49 -07:00
parent e554eee541
commit 8a10903cf7
2 changed files with 21 additions and 5 deletions

View File

@@ -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) {

View File

@@ -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<string> {
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();
}