惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
V2EX
aimingoo的专栏
aimingoo的专栏
S
SegmentFault 最新的问题
博客园_首页
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
IT之家
IT之家
博客园 - 【当耐特】
月光博客
月光博客
C
Check Point Blog
T
The Blog of Author Tim Ferriss
罗磊的独立博客
博客园 - Franky
MongoDB | Blog
MongoDB | Blog
H
Help Net Security
Microsoft Security Blog
Microsoft Security Blog
B
Blog
阮一峰的网络日志
阮一峰的网络日志
腾讯CDC
美团技术团队
N
Netflix TechBlog - Medium
Stack Overflow Blog
Stack Overflow Blog
Y
Y Combinator Blog
L
LangChain Blog
The Cloudflare Blog

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(agents): route plugin approvals through transport cha...
849261680 · 2026-06-20 · via Recent Commits to openclaw:main
1+

import fs from "node:fs/promises";

12

/**

23

* Integration-style tests for before_tool_call behavior.

34

* Covers loop detection, diagnostics, plugin approval, and skill telemetry

@@ -27,6 +28,7 @@ import {

2728

runBeforeToolCallHook,

2829

wrapToolWithBeforeToolCallHook,

2930

} from "./agent-tools.before-tool-call.js";

31+

import { createOpenClawCodingTools } from "./agent-tools.js";

3032

import { CRITICAL_THRESHOLD } from "./tool-loop-detection.js";

3133

import type { AnyAgentTool } from "./tools/common.js";

3234

import { callGatewayTool } from "./tools/gateway.js";

@@ -1844,6 +1846,106 @@ describe("before_tool_call requireApproval handling", () => {

1844184618451847

expect(onResolution).toHaveBeenCalledWith("cancelled");

18461848

});

1849+1850+

it("forwards turn source routing fields from ctx to plugin.approval.request", async () => {

1851+

hookRunner.runBeforeToolCall.mockResolvedValue({

1852+

requireApproval: {

1853+

title: "Channel-routed approval",

1854+

description: "Must route to telegram",

1855+

pluginId: "my-plugin",

1856+

},

1857+

});

1858+1859+

mockCallGateway.mockResolvedValueOnce({ id: "route-id-1", status: "accepted" });

1860+

mockCallGateway.mockResolvedValueOnce({ id: "route-id-1", decision: "allow-once" });

1861+1862+

await runBeforeToolCallHook({

1863+

toolName: "fetch",

1864+

params: { url: "https://example.com" },

1865+

ctx: {

1866+

agentId: "main",

1867+

sessionKey: "main",

1868+

turnSourceChannel: "telegram",

1869+

turnSourceTo: "-100123456789",

1870+

turnSourceAccountId: "acct-42",

1871+

turnSourceThreadId: 9001,

1872+

},

1873+

});

1874+1875+

const requestCall = requireGatewayCall(0);

1876+

expect(requestCall[0]).toBe("plugin.approval.request");

1877+

const requestParams = requireRecord(requestCall[2], "approval request params");

1878+

expect(requestParams.turnSourceChannel).toBe("telegram");

1879+

expect(requestParams.turnSourceTo).toBe("-100123456789");

1880+

expect(requestParams.turnSourceAccountId).toBe("acct-42");

1881+

expect(requestParams.turnSourceThreadId).toBe(9001);

1882+

});

1883+1884+

it("uses the transport channel when tool policy provider differs", async () => {

1885+

hookRunner.runBeforeToolCall.mockResolvedValue({

1886+

requireApproval: {

1887+

title: "Transport routed approval",

1888+

description: "Must use the transport channel",

1889+

pluginId: "my-plugin",

1890+

},

1891+

});

1892+1893+

const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-hook-route-"));

1894+

await fs.writeFile(path.join(tempDir, "note.txt"), "hello");

1895+

mockCallGateway.mockResolvedValueOnce({ id: "transport-route-id", status: "accepted" });

1896+

mockCallGateway.mockResolvedValueOnce({

1897+

id: "transport-route-id",

1898+

decision: "allow-once",

1899+

});

1900+1901+

const tools = createOpenClawCodingTools({

1902+

workspaceDir: tempDir,

1903+

messageProvider: "discord-voice",

1904+

messageChannel: "discord",

1905+

currentChannelId: "native-channel-1",

1906+

currentMessagingTarget: "channel:deliverable-1",

1907+

agentAccountId: "acct-1",

1908+

currentThreadTs: "thread-1",

1909+

});

1910+

const readTool = tools.find((tool) => tool.name === "read");

1911+

if (!readTool) {

1912+

throw new Error("missing read tool");

1913+

}

1914+

await readTool.execute("tool-hook-route", { path: "note.txt" }, undefined, undefined);

1915+1916+

const requestCall = requireGatewayCall(0);

1917+

expect(requestCall[0]).toBe("plugin.approval.request");

1918+

const requestParams = requireRecord(requestCall[2], "approval request params");

1919+

expect(requestParams.turnSourceChannel).toBe("discord");

1920+

expect(requestParams.turnSourceTo).toBe("channel:deliverable-1");

1921+

expect(requestParams.turnSourceAccountId).toBe("acct-1");

1922+

expect(requestParams.turnSourceThreadId).toBe("thread-1");

1923+

});

1924+1925+

it("omits turn source routing fields when ctx does not carry them", async () => {

1926+

hookRunner.runBeforeToolCall.mockResolvedValue({

1927+

requireApproval: {

1928+

title: "No route ctx",

1929+

description: "Local-only approval",

1930+

},

1931+

});

1932+1933+

mockCallGateway.mockResolvedValueOnce({ id: "no-route-id", status: "accepted" });

1934+

mockCallGateway.mockResolvedValueOnce({ id: "no-route-id", decision: "allow-once" });

1935+1936+

await runBeforeToolCallHook({

1937+

toolName: "bash",

1938+

params: {},

1939+

ctx: { agentId: "main", sessionKey: "main" },

1940+

});

1941+1942+

const requestCall = requireGatewayCall(0);

1943+

const requestParams = requireRecord(requestCall[2], "approval request params");

1944+

expect(requestParams.turnSourceChannel).toBeUndefined();

1945+

expect(requestParams.turnSourceTo).toBeUndefined();

1946+

expect(requestParams.turnSourceAccountId).toBeUndefined();

1947+

expect(requestParams.turnSourceThreadId).toBeUndefined();

1948+

});

18471949

});

1848195018491951

describe("before_tool_call tool content private-data capture", () => {