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

推荐订阅源

Recent Announcements
Recent Announcements
J
Java Code Geeks
雷峰网
雷峰网
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
腾讯CDC
博客园 - 司徒正美
B
Blog RSS Feed
博客园 - 三生石上(FineUI控件)
I
InfoQ
N
Netflix TechBlog - Medium
L
LangChain Blog
博客园_首页
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Tailwind CSS Blog
MyScale Blog
MyScale Blog
美团技术团队
The Cloudflare Blog
爱范儿
爱范儿
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
H
Help Net Security
Martin Fowler
Martin Fowler
V
Visual Studio 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(qa): reject non-object mock Anthropic JSON · openclaw...
vincentkoc · 2026-06-21 · via Recent Commits to openclaw:main

File tree

  • extensions/qa-lab/src/providers/mock-openai

Original file line numberDiff line numberDiff line change

@@ -4240,7 +4240,7 @@ describe("qa mock openai server", () => {

42404240

expect(body).not.toContain("HEARTBEAT_OK");

42414241

});

42424242
4243-

it("rejects malformed Anthropic /v1/messages JSON with an invalid_request_error", async () => {

4243+

it("rejects malformed or non-object Anthropic /v1/messages JSON", async () => {

42444244

const server = await startQaMockOpenAiServer({

42454245

host: "127.0.0.1",

42464246

port: 0,

@@ -4249,20 +4249,25 @@ describe("qa mock openai server", () => {

42494249

await server.stop();

42504250

});

42514251
4252-

const response = await fetch(`${server.baseUrl}/v1/messages`, {

4253-

method: "POST",

4254-

headers: { "content-type": "application/json" },

4255-

body: '{"model":"claude-opus-4-8","messages":[',

4256-

});

4252+

for (const rawBody of ['{"model":"claude-opus-4-8","messages":[', "null", "[]", '"text"']) {

4253+

const response = await fetch(`${server.baseUrl}/v1/messages`, {

4254+

method: "POST",

4255+

headers: { "content-type": "application/json" },

4256+

body: rawBody,

4257+

});

4258+
4259+

expect(response.status).toBe(400);

4260+

const body = (await response.json()) as {

4261+

type: string;

4262+

error: { type: string; message: string };

4263+

};

4264+

expect(body.type).toBe("error");

4265+

expect(body.error.type).toBe("invalid_request_error");

4266+

expect(body.error.message).toContain("Malformed JSON body");

4267+

}

42574268
4258-

expect(response.status).toBe(400);

4259-

const body = (await response.json()) as {

4260-

type: string;

4261-

error: { type: string; message: string };

4262-

};

4263-

expect(body.type).toBe("error");

4264-

expect(body.error.type).toBe("invalid_request_error");

4265-

expect(body.error.message).toContain("Malformed JSON body");

4269+

const health = await fetch(`${server.baseUrl}/healthz`);

4270+

expect(health.status).toBe(200);

42664271

});

42674272
42684273

it("rejects malformed OpenAI-compatible JSON without crashing the mock server", async () => {

Original file line numberDiff line numberDiff line change

@@ -228,7 +228,7 @@ function readBody(req: IncomingMessage): Promise<string> {

228228

});

229229

}

230230
231-

function parseOpenAiJsonBody(raw: string): Record<string, unknown> | null {

231+

function parseJsonObjectBody(raw: string): Record<string, unknown> | null {

232232

try {

233233

const parsed = raw ? (JSON.parse(raw) as unknown) : {};

234234

return parsed && typeof parsed === "object" && !Array.isArray(parsed)

@@ -3438,7 +3438,7 @@ export async function startQaMockOpenAiServer(params?: { host?: string; port?: n

34383438

}

34393439

if (req.method === "POST" && url.pathname === "/v1/images/generations") {

34403440

const raw = await readBody(req);

3441-

const body = parseOpenAiJsonBody(raw);

3441+

const body = parseJsonObjectBody(raw);

34423442

if (!body) {

34433443

writeOpenAiMalformedJsonError(res, "OpenAI Images");

34443444

return;

@@ -3466,7 +3466,7 @@ export async function startQaMockOpenAiServer(params?: { host?: string; port?: n

34663466

}

34673467

if (req.method === "POST" && url.pathname === "/v1/embeddings") {

34683468

const raw = await readBody(req);

3469-

const body = parseOpenAiJsonBody(raw);

3469+

const body = parseJsonObjectBody(raw);

34703470

if (!body) {

34713471

writeOpenAiMalformedJsonError(res, "OpenAI Embeddings");

34723472

return;

@@ -3492,7 +3492,7 @@ export async function startQaMockOpenAiServer(params?: { host?: string; port?: n

34923492

}

34933493

if (req.method === "POST" && url.pathname === "/v1/responses") {

34943494

const raw = await readBody(req);

3495-

const body = parseOpenAiJsonBody(raw);

3495+

const body = parseJsonObjectBody(raw);

34963496

if (!body) {

34973497

writeOpenAiMalformedJsonError(res, "OpenAI Responses");

34983498

return;

@@ -3534,10 +3534,8 @@ export async function startQaMockOpenAiServer(params?: { host?: string; port?: n

35343534

}

35353535

if (req.method === "POST" && url.pathname === "/v1/messages") {

35363536

const raw = await readBody(req);

3537-

let body: AnthropicMessagesRequest;

3538-

try {

3539-

body = raw ? (JSON.parse(raw) as AnthropicMessagesRequest) : {};

3540-

} catch {

3537+

const body = parseJsonObjectBody(raw) as AnthropicMessagesRequest | null;

3538+

if (!body) {

35413539

writeJson(res, 400, {

35423540

type: "error",

35433541

error: {