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

推荐订阅源

WordPress大学
WordPress大学
GbyAI
GbyAI
P
Proofpoint News Feed
B
Blog
MyScale Blog
MyScale Blog
V
V2EX
B
Blog RSS Feed
Microsoft Security Blog
Microsoft Security Blog
量子位
Jina AI
Jina AI
博客园 - 叶小钗
Recent Announcements
Recent Announcements
有赞技术团队
有赞技术团队
罗磊的独立博客
L
LangChain Blog
I
InfoQ
云风的 BLOG
云风的 BLOG
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
人人都是产品经理
人人都是产品经理
小众软件
小众软件
V
Visual Studio 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
test: tighten http common assertions · openclaw/openclaw@...
steipete · 2026-05-11 · via Recent Commits to openclaw:main

@@ -34,6 +34,22 @@ beforeEach(() => {

3434

resetDiagnosticEventsForTest();

3535

});

363637+

function headerNames(setHeader: ReturnType<typeof vi.fn>): string[] {

38+

return setHeader.mock.calls

39+

.map((call) => call[0])

40+

.filter((name): name is string => typeof name === "string");

41+

}

42+43+

function expectHeaderNotSet(setHeader: ReturnType<typeof vi.fn>, name: string): void {

44+

expect(headerNames(setHeader)).not.toContain(name);

45+

}

46+47+

function mockCallRecord(mock: ReturnType<typeof vi.fn>, index: number): unknown[] {

48+

const call = mock.mock.calls[index];

49+

expect(call).toBeTruthy();

50+

return call ?? [];

51+

}

52+3753

describe("setDefaultSecurityHeaders", () => {

3854

it("sets X-Content-Type-Options", () => {

3955

const { res, setHeader } = makeMockHttpResponse();

@@ -70,19 +86,19 @@ describe("setDefaultSecurityHeaders", () => {

7086

it("does not set Strict-Transport-Security when not provided", () => {

7187

const { res, setHeader } = makeMockHttpResponse();

7288

setDefaultSecurityHeaders(res);

73-

expect(setHeader).not.toHaveBeenCalledWith("Strict-Transport-Security", expect.anything());

89+

expectHeaderNotSet(setHeader, "Strict-Transport-Security");

7490

});

75917692

it("does not set Strict-Transport-Security for empty string", () => {

7793

const { res, setHeader } = makeMockHttpResponse();

7894

setDefaultSecurityHeaders(res, { strictTransportSecurity: "" });

79-

expect(setHeader).not.toHaveBeenCalledWith("Strict-Transport-Security", expect.anything());

95+

expectHeaderNotSet(setHeader, "Strict-Transport-Security");

8096

});

81978298

it("does not set Strict-Transport-Security when opts is omitted", () => {

8399

const { res, setHeader } = makeMockHttpResponse();

84100

setDefaultSecurityHeaders(res, undefined);

85-

expect(setHeader).not.toHaveBeenCalledWith("Strict-Transport-Security", expect.anything());

101+

expectHeaderNotSet(setHeader, "Strict-Transport-Security");

86102

});

87103

});

88104

@@ -138,7 +154,7 @@ describe("sendRateLimited", () => {

138154

const { res, setHeader, end } = makeMockHttpResponse();

139155

sendRateLimited(res);

140156

expect(res.statusCode).toBe(429);

141-

expect(setHeader).not.toHaveBeenCalledWith("Retry-After", expect.anything());

157+

expectHeaderNotSet(setHeader, "Retry-After");

142158

expect(end).toHaveBeenCalledWith(

143159

JSON.stringify({

144160

error: {

@@ -153,14 +169,14 @@ describe("sendRateLimited", () => {

153169

const { res, setHeader } = makeMockHttpResponse();

154170

sendRateLimited(res, 0);

155171

expect(res.statusCode).toBe(429);

156-

expect(setHeader).not.toHaveBeenCalledWith("Retry-After", expect.anything());

172+

expectHeaderNotSet(setHeader, "Retry-After");

157173

});

158174159175

it("responds with 429 and no Retry-After when retryAfterMs is negative", () => {

160176

const { res, setHeader } = makeMockHttpResponse();

161177

sendRateLimited(res, -500);

162178

expect(res.statusCode).toBe(429);

163-

expect(setHeader).not.toHaveBeenCalledWith("Retry-After", expect.anything());

179+

expectHeaderNotSet(setHeader, "Retry-After");

164180

});

165181166182

it("sets Retry-After (seconds, ceiled) when retryAfterMs is positive", () => {

@@ -209,9 +225,10 @@ describe("readJsonBodyOrError", () => {

209225

it("returns the parsed body on success", async () => {

210226

readJsonBodyMock.mockResolvedValueOnce({ ok: true, value: { hello: "world" } });

211227

const { res } = makeMockHttpResponse();

212-

const result = await readJsonBodyOrError(makeRequest(), res, 1024);

228+

const req = makeRequest();

229+

const result = await readJsonBodyOrError(req, res, 1024);

213230

expect(result).toEqual({ hello: "world" });

214-

expect(readJsonBodyMock).toHaveBeenCalledWith(expect.anything(), 1024);

231+

expect(readJsonBodyMock).toHaveBeenCalledWith(req, 1024);

215232

});

216233217234

it("responds with 413 when the body is too large", async () => {

@@ -229,16 +246,12 @@ describe("readJsonBodyOrError", () => {

229246

error: { message: "Payload too large", type: "invalid_request_error" },

230247

}),

231248

);

232-

expect(events).toContainEqual(

233-

expect.objectContaining({

234-

type: "payload.large",

235-

surface: "gateway.http.json",

236-

action: "rejected",

237-

bytes: 2048,

238-

limitBytes: 1024,

239-

reason: "json_body_limit",

240-

}),

241-

);

249+

const event = events.find((entry) => entry.type === "payload.large");

250+

expect(event?.surface).toBe("gateway.http.json");

251+

expect(event?.action).toBe("rejected");

252+

expect(event?.bytes).toBe(2048);

253+

expect(event?.limitBytes).toBe(1024);

254+

expect(event?.reason).toBe("json_body_limit");

242255

});

243256244257

it("responds with 408 when the request body times out", async () => {

@@ -366,8 +379,12 @@ describe("watchClientDisconnect", () => {

366379

const { req, res } = buildReqRes(reqSocket, resSocket);

367380

const controller = new AbortController();

368381

watchClientDisconnect(req, res, controller);

369-

expect(reqOn).toHaveBeenCalledWith("close", expect.any(Function));

370-

expect(resOn).toHaveBeenCalledWith("close", expect.any(Function));

382+

const reqOnCall = mockCallRecord(reqOn, 0);

383+

const resOnCall = mockCallRecord(resOn, 0);

384+

expect(reqOnCall[0]).toBe("close");

385+

expect(typeof reqOnCall[1]).toBe("function");

386+

expect(resOnCall[0]).toBe("close");

387+

expect(typeof resOnCall[1]).toBe("function");

371388

});

372389373390

it("cleanup detaches the close listener from each socket", () => {