mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 04:10:24 +00:00
test: inject thread-safe gateway and ACP seams
This commit is contained in:
@@ -151,6 +151,7 @@ async function executeSend(params: {
|
||||
}) {
|
||||
const tool = createMessageTool({
|
||||
config: {} as never,
|
||||
runMessageAction: mocks.runMessageAction as never,
|
||||
...params.toolOptions,
|
||||
});
|
||||
await tool.execute("1", {
|
||||
@@ -187,6 +188,9 @@ describe("message tool secret scoping", () => {
|
||||
const tool = createMessageTool({
|
||||
currentChannelProvider: "discord",
|
||||
agentAccountId: "ops",
|
||||
loadConfig: mocks.loadConfig as never,
|
||||
resolveCommandSecretRefsViaGateway: mocks.resolveCommandSecretRefsViaGateway as never,
|
||||
runMessageAction: mocks.runMessageAction as never,
|
||||
});
|
||||
|
||||
await tool.execute("1", {
|
||||
@@ -216,6 +220,7 @@ describe("message tool agent routing", () => {
|
||||
const tool = createMessageTool({
|
||||
agentSessionKey: "agent:alpha:main",
|
||||
config: {} as never,
|
||||
runMessageAction: mocks.runMessageAction as never,
|
||||
});
|
||||
|
||||
await tool.execute("1", {
|
||||
|
||||
@@ -386,6 +386,9 @@ type MessageToolOptions = {
|
||||
agentSessionKey?: string;
|
||||
sessionId?: string;
|
||||
config?: OpenClawConfig;
|
||||
loadConfig?: () => OpenClawConfig;
|
||||
resolveCommandSecretRefsViaGateway?: typeof resolveCommandSecretRefsViaGateway;
|
||||
runMessageAction?: typeof runMessageAction;
|
||||
currentChannelId?: string;
|
||||
currentChannelProvider?: string;
|
||||
currentThreadTs?: string;
|
||||
@@ -621,6 +624,10 @@ function buildMessageToolDescription(options?: {
|
||||
}
|
||||
|
||||
export function createMessageTool(options?: MessageToolOptions): AnyAgentTool {
|
||||
const loadConfigForTool = options?.loadConfig ?? loadConfig;
|
||||
const resolveSecretRefsForTool =
|
||||
options?.resolveCommandSecretRefsViaGateway ?? resolveCommandSecretRefsViaGateway;
|
||||
const runMessageActionForTool = options?.runMessageAction ?? runMessageAction;
|
||||
const agentAccountId = resolveAgentAccountId(options?.agentAccountId);
|
||||
const resolvedAgentId = options?.agentSessionKey
|
||||
? resolveSessionAgentId({
|
||||
@@ -683,7 +690,7 @@ export function createMessageTool(options?: MessageToolOptions): AnyAgentTool {
|
||||
}) as ChannelMessageActionName;
|
||||
let cfg = options?.config;
|
||||
if (!cfg) {
|
||||
const loadedRaw = loadConfig();
|
||||
const loadedRaw = loadConfigForTool();
|
||||
const scope = resolveMessageSecretScope({
|
||||
channel: params.channel,
|
||||
target: params.target,
|
||||
@@ -698,7 +705,7 @@ export function createMessageTool(options?: MessageToolOptions): AnyAgentTool {
|
||||
accountId: scope.accountId,
|
||||
});
|
||||
cfg = (
|
||||
await resolveCommandSecretRefsViaGateway({
|
||||
await resolveSecretRefsForTool({
|
||||
config: loadedRaw,
|
||||
commandName: "tools.message",
|
||||
targetIds: scopedTargets.targetIds,
|
||||
@@ -765,7 +772,7 @@ export function createMessageTool(options?: MessageToolOptions): AnyAgentTool {
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const result = await runMessageAction({
|
||||
const result = await runMessageActionForTool({
|
||||
cfg,
|
||||
action,
|
||||
params,
|
||||
|
||||
Reference in New Issue
Block a user