test(perf): slim channel directory contracts

This commit is contained in:
Peter Steinberger
2026-05-06 19:18:53 +01:00
parent 2d97dcebb5
commit 90b69cac02
2 changed files with 32 additions and 18 deletions

View File

@@ -11,7 +11,7 @@ import {
createComputedAccountStatusAdapter,
createDefaultChannelRuntimeState,
} from "openclaw/plugin-sdk/status-helpers";
import { googlechatMessageActions } from "./actions.js";
import { extractToolSend } from "openclaw/plugin-sdk/tool-send";
import { googleChatApprovalAuth } from "./approval-auth.js";
import {
formatAllowFromEntry,
@@ -35,7 +35,9 @@ import {
resolveGoogleChatConfigAccessorAccount,
resolveDefaultGoogleChatAccountId,
resolveGoogleChatAccount,
listGoogleChatAccountIds,
type ChannelMessageActionAdapter,
type ChannelMessageActionName,
type ChannelStatusIssue,
type ResolvedGoogleChatAccount,
} from "./channel.deps.runtime.js";
@@ -97,9 +99,27 @@ const googleChatConfigAdapter = createScopedChannelConfigAdapter<
});
const googlechatActions: ChannelMessageActionAdapter = {
describeMessageTool: (ctx) => googlechatMessageActions.describeMessageTool?.(ctx) ?? null,
extractToolSend: (ctx) => googlechatMessageActions.extractToolSend?.(ctx) ?? null,
describeMessageTool: ({ cfg, accountId }) => {
const accounts = accountId
? [resolveGoogleChatAccount({ cfg, accountId })].filter(
(account) => account.enabled && account.credentialSource !== "none",
)
: listGoogleChatAccountIds(cfg)
.map((id) => resolveGoogleChatAccount({ cfg, accountId: id }))
.filter((account) => account.enabled && account.credentialSource !== "none");
if (accounts.length === 0) {
return null;
}
const actions = new Set<ChannelMessageActionName>(["send", "upload-file"]);
if (accounts.some((account) => account.config.actions?.reactions !== false)) {
actions.add("react");
actions.add("reactions");
}
return { actions: Array.from(actions) };
},
extractToolSend: ({ args }) => extractToolSend(args, "sendMessage"),
handleAction: async (ctx) => {
const { googlechatMessageActions } = await import("./actions.js");
if (!googlechatMessageActions.handleAction) {
throw new Error("Google Chat actions are not available.");
}

View File

@@ -9,16 +9,11 @@ import type {
} from "../../types.core.js";
import type { ChannelPlugin } from "../../types.js";
let contractRuntime: RuntimeEnv | undefined;
async function getDirectoryContractRuntime(): Promise<RuntimeEnv> {
if (contractRuntime) {
return contractRuntime;
}
const { createNonExitingRuntime } = await import("../../../../runtime.js");
contractRuntime = createNonExitingRuntime();
return contractRuntime;
}
const contractRuntime = new Proxy(Object.create(null), {
get(_target, property) {
throw new Error(`Directory contract unexpectedly accessed runtime.${String(property)}`);
},
}) as RuntimeEnv;
function expectDirectoryEntryShape(entry: ChannelDirectoryEntry) {
expect(["user", "group", "channel"]).toContain(entry.kind);
@@ -193,11 +188,10 @@ export async function expectChannelDirectoryBaseContract(params: {
if (params.coverage === "presence") {
return;
}
const runtime = await getDirectoryContractRuntime();
const self = await directory?.self?.({
cfg,
accountId,
runtime,
runtime: contractRuntime,
});
if (self) {
expectDirectoryEntryShape(self);
@@ -209,7 +203,7 @@ export async function expectChannelDirectoryBaseContract(params: {
accountId,
query: "",
limit: 5,
runtime,
runtime: contractRuntime,
})) ?? [];
expect(Array.isArray(peers)).toBe(true);
for (const peer of peers) {
@@ -222,7 +216,7 @@ export async function expectChannelDirectoryBaseContract(params: {
accountId,
query: "",
limit: 5,
runtime,
runtime: contractRuntime,
})) ?? [];
expect(Array.isArray(groups)).toBe(true);
for (const group of groups) {
@@ -235,7 +229,7 @@ export async function expectChannelDirectoryBaseContract(params: {
accountId,
groupId: groups[0].id,
limit: 5,
runtime,
runtime: contractRuntime,
});
expect(Array.isArray(members)).toBe(true);
for (const member of members) {