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

推荐订阅源

大猫的无限游戏
大猫的无限游戏
J
Java Code Geeks
小众软件
小众软件
D
Docker
腾讯CDC
H
Hackread – Cybersecurity News, Data Breaches, AI and More
V
V2EX
博客园 - 叶小钗
GbyAI
GbyAI
Microsoft Azure Blog
Microsoft Azure Blog
Stack Overflow Blog
Stack Overflow Blog
B
Blog RSS Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 【当耐特】
IT之家
IT之家
博客园 - 司徒正美
M
MIT News - Artificial intelligence
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
罗磊的独立博客
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
L
LangChain Blog
阮一峰的网络日志
阮一峰的网络日志
C
Check Point 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(qqbot): guard channel api fetches · openclaw/openclaw...
vincentkoc · 2026-06-19 · via Recent Commits to openclaw:main
1+

// Qqbot tests cover channel-api tool behavior.

2+

import { afterEach, describe, expect, it, vi } from "vitest";

3+4+

const fetchWithSsrFGuardMock = vi.hoisted(() => vi.fn());

5+6+

vi.mock("openclaw/plugin-sdk/ssrf-runtime", async (importOriginal) => {

7+

const actual = await importOriginal<typeof import("openclaw/plugin-sdk/ssrf-runtime")>();

8+

return {

9+

...actual,

10+

fetchWithSsrFGuard: fetchWithSsrFGuardMock,

11+

};

12+

});

13+14+

import { executeChannelApi } from "./channel-api.js";

15+16+

function cancelTrackedResponse(

17+

text: string,

18+

init: ResponseInit,

19+

): {

20+

response: Response;

21+

wasCanceled: () => boolean;

22+

} {

23+

let canceled = false;

24+

const stream = new ReadableStream<Uint8Array>({

25+

start(controller) {

26+

controller.enqueue(new TextEncoder().encode(text));

27+

},

28+

cancel() {

29+

canceled = true;

30+

},

31+

});

32+

return {

33+

response: new Response(stream, init),

34+

wasCanceled: () => canceled,

35+

};

36+

}

37+38+

describe("executeChannelApi", () => {

39+

afterEach(() => {

40+

vi.restoreAllMocks();

41+

fetchWithSsrFGuardMock.mockReset();

42+

});

43+44+

it("uses guarded QQ API fetches and releases successful responses", async () => {

45+

const release = vi.fn(async () => {});

46+

fetchWithSsrFGuardMock.mockResolvedValueOnce({

47+

response: new Response(JSON.stringify({ id: "guild-1" }), { status: 200 }),

48+

release,

49+

});

50+51+

const result = await executeChannelApi(

52+

{ method: "GET", path: "/users/@me/guilds", query: { limit: "1" } },

53+

{ accessToken: "token-1" },

54+

);

55+56+

expect(result.details).toEqual({

57+

success: true,

58+

status: 200,

59+

path: "/users/@me/guilds",

60+

data: { id: "guild-1" },

61+

});

62+

expect(release).toHaveBeenCalledTimes(1);

63+

expect(fetchWithSsrFGuardMock).toHaveBeenCalledWith({

64+

url: "https://api.sgroup.qq.com/users/@me/guilds?limit=1",

65+

init: {

66+

method: "GET",

67+

headers: {

68+

Authorization: "QQBot token-1",

69+

"Content-Type": "application/json",

70+

},

71+

signal: expect.any(AbortSignal),

72+

},

73+

auditContext: "qqbot-channel-api",

74+

policy: {

75+

hostnameAllowlist: ["api.sgroup.qq.com"],

76+

allowRfc2544BenchmarkRange: true,

77+

},

78+

});

79+

});

80+81+

it("bounds error bodies without using response.text()", async () => {

82+

const release = vi.fn(async () => {});

83+

const tracked = cancelTrackedResponse(`${"channel api unavailable ".repeat(1024)}tail`, {

84+

status: 503,

85+

statusText: "Service Unavailable",

86+

headers: { "content-type": "text/plain" },

87+

});

88+

const textSpy = vi.spyOn(tracked.response, "text").mockRejectedValue(new Error("unbounded"));

89+

fetchWithSsrFGuardMock.mockResolvedValueOnce({

90+

response: tracked.response,

91+

release,

92+

});

93+94+

const result = await executeChannelApi(

95+

{ method: "GET", path: "/guilds/123/channels" },

96+

{ accessToken: "token-1" },

97+

);

98+99+

expect(result.details).toMatchObject({

100+

error: "503 Service Unavailable",

101+

status: 503,

102+

path: "/guilds/123/channels",

103+

});

104+

expect(JSON.stringify(result.details)).toContain("channel api unavailable");

105+

expect(JSON.stringify(result.details)).not.toContain("tail");

106+

expect(tracked.wasCanceled()).toBe(true);

107+

expect(textSpy).not.toHaveBeenCalled();

108+

expect(release).toHaveBeenCalledTimes(1);

109+

});

110+

});