mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 16:10:49 +00:00
test: share channel summary fixtures
This commit is contained in:
@@ -4,6 +4,14 @@ import { setActivePluginRegistry } from "../plugins/runtime.js";
|
|||||||
import { createTestRegistry } from "../test-utils/channel-plugins.js";
|
import { createTestRegistry } from "../test-utils/channel-plugins.js";
|
||||||
import { buildChannelSummary } from "./channel-summary.js";
|
import { buildChannelSummary } from "./channel-summary.js";
|
||||||
|
|
||||||
|
const isFixtureAccountConfigured = (account: unknown) =>
|
||||||
|
Boolean((account as { configured?: boolean }).configured);
|
||||||
|
const isFixtureAccountEnabled = (account: unknown) =>
|
||||||
|
Boolean((account as { enabled?: boolean }).enabled);
|
||||||
|
const summaryPluginActions = {
|
||||||
|
describeMessageTool: () => ({ actions: ["send"] as const }),
|
||||||
|
};
|
||||||
|
|
||||||
function makeSlackHttpSummaryPlugin(): ChannelPlugin {
|
function makeSlackHttpSummaryPlugin(): ChannelPlugin {
|
||||||
return {
|
return {
|
||||||
id: "slack",
|
id: "slack",
|
||||||
@@ -53,12 +61,10 @@ function makeSlackHttpSummaryPlugin(): ChannelPlugin {
|
|||||||
botTokenSource: "config",
|
botTokenSource: "config",
|
||||||
botTokenStatus: "available",
|
botTokenStatus: "available",
|
||||||
}),
|
}),
|
||||||
isConfigured: (account) => Boolean((account as { configured?: boolean }).configured),
|
isConfigured: isFixtureAccountConfigured,
|
||||||
isEnabled: () => true,
|
isEnabled: () => true,
|
||||||
},
|
},
|
||||||
actions: {
|
actions: summaryPluginActions,
|
||||||
describeMessageTool: () => ({ actions: ["send"] }),
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,6 +75,17 @@ function makeTelegramSummaryPlugin(params: {
|
|||||||
authAgeMs?: number;
|
authAgeMs?: number;
|
||||||
allowFrom?: string[];
|
allowFrom?: string[];
|
||||||
}): ChannelPlugin {
|
}): ChannelPlugin {
|
||||||
|
const getAccount = () => ({
|
||||||
|
accountId: "primary",
|
||||||
|
name: "Main Bot",
|
||||||
|
enabled: params.enabled,
|
||||||
|
configured: params.configured,
|
||||||
|
linked: params.linked,
|
||||||
|
allowFrom: params.allowFrom ?? [],
|
||||||
|
dmPolicy: "mutuals",
|
||||||
|
tokenSource: "env",
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: "telegram",
|
id: "telegram",
|
||||||
meta: {
|
meta: {
|
||||||
@@ -82,28 +99,10 @@ function makeTelegramSummaryPlugin(params: {
|
|||||||
config: {
|
config: {
|
||||||
listAccountIds: () => ["primary"],
|
listAccountIds: () => ["primary"],
|
||||||
defaultAccountId: () => "primary",
|
defaultAccountId: () => "primary",
|
||||||
inspectAccount: () => ({
|
inspectAccount: getAccount,
|
||||||
accountId: "primary",
|
resolveAccount: getAccount,
|
||||||
name: "Main Bot",
|
isConfigured: isFixtureAccountConfigured,
|
||||||
enabled: params.enabled,
|
isEnabled: isFixtureAccountEnabled,
|
||||||
configured: params.configured,
|
|
||||||
linked: params.linked,
|
|
||||||
allowFrom: params.allowFrom ?? [],
|
|
||||||
dmPolicy: "mutuals",
|
|
||||||
tokenSource: "env",
|
|
||||||
}),
|
|
||||||
resolveAccount: () => ({
|
|
||||||
accountId: "primary",
|
|
||||||
name: "Main Bot",
|
|
||||||
enabled: params.enabled,
|
|
||||||
configured: params.configured,
|
|
||||||
linked: params.linked,
|
|
||||||
allowFrom: params.allowFrom ?? [],
|
|
||||||
dmPolicy: "mutuals",
|
|
||||||
tokenSource: "env",
|
|
||||||
}),
|
|
||||||
isConfigured: (account) => Boolean((account as { configured?: boolean }).configured),
|
|
||||||
isEnabled: (account) => Boolean((account as { enabled?: boolean }).enabled),
|
|
||||||
formatAllowFrom: () => ["alice", "bob", "carol"],
|
formatAllowFrom: () => ["alice", "bob", "carol"],
|
||||||
},
|
},
|
||||||
status: {
|
status: {
|
||||||
@@ -114,13 +113,23 @@ function makeTelegramSummaryPlugin(params: {
|
|||||||
self: { e164: "+15551234567" },
|
self: { e164: "+15551234567" },
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
actions: {
|
actions: summaryPluginActions,
|
||||||
describeMessageTool: () => ({ actions: ["send"] }),
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function makeSignalSummaryPlugin(params: { enabled: boolean; configured: boolean }): ChannelPlugin {
|
function makeSignalSummaryPlugin(params: { enabled: boolean; configured: boolean }): ChannelPlugin {
|
||||||
|
const getAccount = () => ({
|
||||||
|
accountId: "desktop",
|
||||||
|
name: "Desktop",
|
||||||
|
enabled: params.enabled,
|
||||||
|
configured: params.configured,
|
||||||
|
appTokenSource: "env",
|
||||||
|
baseUrl: "https://signal.example.test",
|
||||||
|
port: 31337,
|
||||||
|
cliPath: "/usr/local/bin/signal-cli",
|
||||||
|
dbPath: "/tmp/signal.db",
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: "signal",
|
id: "signal",
|
||||||
meta: {
|
meta: {
|
||||||
@@ -134,34 +143,12 @@ function makeSignalSummaryPlugin(params: { enabled: boolean; configured: boolean
|
|||||||
config: {
|
config: {
|
||||||
listAccountIds: () => ["desktop"],
|
listAccountIds: () => ["desktop"],
|
||||||
defaultAccountId: () => "desktop",
|
defaultAccountId: () => "desktop",
|
||||||
inspectAccount: () => ({
|
inspectAccount: getAccount,
|
||||||
accountId: "desktop",
|
resolveAccount: getAccount,
|
||||||
name: "Desktop",
|
isConfigured: isFixtureAccountConfigured,
|
||||||
enabled: params.enabled,
|
isEnabled: isFixtureAccountEnabled,
|
||||||
configured: params.configured,
|
|
||||||
appTokenSource: "env",
|
|
||||||
baseUrl: "https://signal.example.test",
|
|
||||||
port: 31337,
|
|
||||||
cliPath: "/usr/local/bin/signal-cli",
|
|
||||||
dbPath: "/tmp/signal.db",
|
|
||||||
}),
|
|
||||||
resolveAccount: () => ({
|
|
||||||
accountId: "desktop",
|
|
||||||
name: "Desktop",
|
|
||||||
enabled: params.enabled,
|
|
||||||
configured: params.configured,
|
|
||||||
appTokenSource: "env",
|
|
||||||
baseUrl: "https://signal.example.test",
|
|
||||||
port: 31337,
|
|
||||||
cliPath: "/usr/local/bin/signal-cli",
|
|
||||||
dbPath: "/tmp/signal.db",
|
|
||||||
}),
|
|
||||||
isConfigured: (account) => Boolean((account as { configured?: boolean }).configured),
|
|
||||||
isEnabled: (account) => Boolean((account as { enabled?: boolean }).enabled),
|
|
||||||
},
|
|
||||||
actions: {
|
|
||||||
describeMessageTool: () => ({ actions: ["send"] }),
|
|
||||||
},
|
},
|
||||||
|
actions: summaryPluginActions,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,6 +158,12 @@ function makeFallbackSummaryPlugin(params: {
|
|||||||
accountIds?: string[];
|
accountIds?: string[];
|
||||||
defaultAccountId?: string;
|
defaultAccountId?: string;
|
||||||
}): ChannelPlugin {
|
}): ChannelPlugin {
|
||||||
|
const getAccount = (_cfg: unknown, accountId?: string | null) => ({
|
||||||
|
accountId,
|
||||||
|
enabled: params.enabled,
|
||||||
|
configured: params.configured,
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: "fallback-plugin",
|
id: "fallback-plugin",
|
||||||
meta: {
|
meta: {
|
||||||
@@ -184,22 +177,12 @@ function makeFallbackSummaryPlugin(params: {
|
|||||||
config: {
|
config: {
|
||||||
listAccountIds: () => params.accountIds ?? [],
|
listAccountIds: () => params.accountIds ?? [],
|
||||||
defaultAccountId: () => params.defaultAccountId ?? "default",
|
defaultAccountId: () => params.defaultAccountId ?? "default",
|
||||||
inspectAccount: (_cfg, accountId) => ({
|
inspectAccount: getAccount,
|
||||||
accountId,
|
resolveAccount: getAccount,
|
||||||
enabled: params.enabled,
|
isConfigured: isFixtureAccountConfigured,
|
||||||
configured: params.configured,
|
isEnabled: isFixtureAccountEnabled,
|
||||||
}),
|
|
||||||
resolveAccount: (_cfg, accountId) => ({
|
|
||||||
accountId,
|
|
||||||
enabled: params.enabled,
|
|
||||||
configured: params.configured,
|
|
||||||
}),
|
|
||||||
isConfigured: (account) => Boolean((account as { configured?: boolean }).configured),
|
|
||||||
isEnabled: (account) => Boolean((account as { enabled?: boolean }).enabled),
|
|
||||||
},
|
|
||||||
actions: {
|
|
||||||
describeMessageTool: () => ({ actions: ["send"] }),
|
|
||||||
},
|
},
|
||||||
|
actions: summaryPluginActions,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user