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

推荐订阅源

V
Visual Studio Blog
D
DataBreaches.Net
博客园 - 三生石上(FineUI控件)
博客园_首页
T
Tailwind CSS Blog
美团技术团队
Hugging Face - Blog
Hugging Face - Blog
博客园 - 叶小钗
大猫的无限游戏
大猫的无限游戏
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
云风的 BLOG
云风的 BLOG
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 聂微东
S
SegmentFault 最新的问题
小众软件
小众软件
酷 壳 – CoolShell
酷 壳 – CoolShell
N
Netflix TechBlog - Medium
Jina AI
Jina AI
WordPress大学
WordPress大学
U
Unit 42
J
Java Code Geeks
Blog — PlanetScale
Blog — PlanetScale
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
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: clear browser act command broad matchers · openclaw...
steipete · 2026-05-10 · via Recent Commits to openclaw:main

@@ -112,6 +112,44 @@ async function withSymlinkPathEscape<T>(params: {

112112

}

113113

}

114114115+

type MockWithCalls = { mock: { calls: unknown[][] } };

116+117+

function isRecord(value: unknown): value is Record<string, unknown> {

118+

return typeof value === "object" && value !== null && !Array.isArray(value);

119+

}

120+121+

function requireRecord(value: unknown, label: string): Record<string, unknown> {

122+

if (!isRecord(value)) {

123+

throw new Error(`expected ${label} to be an object`);

124+

}

125+

return value;

126+

}

127+128+

function expectRecordFields(value: unknown, label: string, expected: Record<string, unknown>) {

129+

const record = requireRecord(value, label);

130+

for (const [key, expectedValue] of Object.entries(expected)) {

131+

expect(record[key]).toEqual(expectedValue);

132+

}

133+

}

134+135+

function requireMockArg(mock: MockWithCalls, callIndex = 0, argIndex = 0) {

136+

return requireRecord(mock.mock.calls[callIndex]?.[argIndex], "mock call argument");

137+

}

138+139+

function expectBrowserCallFields(

140+

mock: MockWithCalls,

141+

expected: Record<string, unknown>,

142+

callIndex = 0,

143+

) {

144+

const arg = requireMockArg(mock, callIndex);

145+

expect(typeof arg.cdpUrl).toBe("string");

146+

expectRecordFields(arg, "browser call argument", expected);

147+

}

148+149+

function expectOkResult(result: unknown) {

150+

expect(requireRecord(result, "response").ok).toBe(true);

151+

}

152+115153

describe("browser control server", () => {

116154

installAgentContractHooks();

117155

@@ -128,14 +166,11 @@ describe("browser control server", () => {

128166

values: ["a", "b"],

129167

});

130168

expect(select.ok).toBe(true);

131-

expect(pwMocks.selectOptionViaPlaywright).toHaveBeenCalledWith(

132-

expect.objectContaining({

133-

cdpUrl: expect.any(String),

134-

targetId: "abcd1234",

135-

ref: "5",

136-

values: ["a", "b"],

137-

}),

138-

);

169+

expectBrowserCallFields(pwMocks.selectOptionViaPlaywright, {

170+

targetId: "abcd1234",

171+

ref: "5",

172+

values: ["a", "b"],

173+

});

139174140175

const fillCases: Array<{

141176

input: Record<string, unknown>;

@@ -160,12 +195,13 @@ describe("browser control server", () => {

160195

fields: [input],

161196

});

162197

expect(fill.ok).toBe(true);

163-

expect(pwMocks.fillFormViaPlaywright).toHaveBeenCalledWith(

164-

expect.objectContaining({

165-

cdpUrl: expect.any(String),

198+

expectBrowserCallFields(

199+

pwMocks.fillFormViaPlaywright,

200+

{

166201

targetId: "abcd1234",

167202

fields: [expected],

168-

}),

203+

},

204+

pwMocks.fillFormViaPlaywright.mock.calls.length - 1,

169205

);

170206

}

171207

@@ -175,14 +211,11 @@ describe("browser control server", () => {

175211

height: 600,

176212

});

177213

expect(resize.ok).toBe(true);

178-

expect(pwMocks.resizeViewportViaPlaywright).toHaveBeenCalledWith(

179-

expect.objectContaining({

180-

cdpUrl: expect.any(String),

181-

targetId: "abcd1234",

182-

width: 800,

183-

height: 600,

184-

}),

185-

);

214+

expectBrowserCallFields(pwMocks.resizeViewportViaPlaywright, {

215+

targetId: "abcd1234",

216+

width: 800,

217+

height: 600,

218+

});

186219187220

const resizeZero = await postJson<{ error?: string; code?: string }>(`${base}/act`, {

188221

kind: "resize",

@@ -207,29 +240,26 @@ describe("browser control server", () => {

207240

timeMs: 5,

208241

});

209242

expect(wait.ok).toBe(true);

210-

expect(pwMocks.waitForViaPlaywright).toHaveBeenCalledWith(

211-

expect.objectContaining({

212-

cdpUrl: state.cdpBaseUrl,

213-

targetId: "abcd1234",

214-

timeMs: 5,

215-

}),

216-

);

243+

expectBrowserCallFields(pwMocks.waitForViaPlaywright, {

244+

cdpUrl: state.cdpBaseUrl,

245+

targetId: "abcd1234",

246+

timeMs: 5,

247+

});

217248218249

const evalRes = await postJson<{ ok: boolean; result?: string }>(`${base}/act`, {

219250

kind: "evaluate",

220251

fn: "() => 1",

221252

});

222253

expect(evalRes.ok).toBe(true);

223254

expect(evalRes.result).toBe("ok");

224-

expect(pwMocks.evaluateViaPlaywright).toHaveBeenCalledWith(

225-

expect.objectContaining({

226-

cdpUrl: state.cdpBaseUrl,

227-

targetId: "abcd1234",

228-

fn: "() => 1",

229-

ref: undefined,

230-

signal: expect.any(AbortSignal),

231-

}),

232-

);

255+

const evalCall = requireMockArg(pwMocks.evaluateViaPlaywright);

256+

expectRecordFields(evalCall, "evaluate call", {

257+

cdpUrl: state.cdpBaseUrl,

258+

targetId: "abcd1234",

259+

fn: "() => 1",

260+

ref: undefined,

261+

});

262+

expect(evalCall.signal).toBeInstanceOf(AbortSignal);

233263

},

234264

slowTimeoutMs,

235265

);

@@ -252,26 +282,23 @@ describe("browser control server", () => {

252282

);

253283254284

expect(batchRes.ok).toBe(true);

255-

expect(pwMocks.batchViaPlaywright).toHaveBeenCalledWith(

256-

expect.objectContaining({

257-

cdpUrl: expect.any(String),

258-

targetId: "abcd1234",

259-

stopOnError: false,

260-

evaluateEnabled: true,

261-

actions: [

262-

{

263-

kind: "click",

264-

selector: "button.save",

265-

doubleClick: true,

266-

delayMs: 25,

267-

},

268-

{

269-

kind: "wait",

270-

fn: "() => window.ready === true",

271-

},

272-

],

273-

}),

274-

);

285+

expectBrowserCallFields(pwMocks.batchViaPlaywright, {

286+

targetId: "abcd1234",

287+

stopOnError: false,

288+

evaluateEnabled: true,

289+

actions: [

290+

{

291+

kind: "click",

292+

selector: "button.save",

293+

doubleClick: true,

294+

delayMs: 25,

295+

},

296+

{

297+

kind: "wait",

298+

fn: "() => window.ready === true",

299+

},

300+

],

301+

});

275302

},

276303

slowTimeoutMs,

277304

);

@@ -290,22 +317,20 @@ describe("browser control server", () => {

290317

});

291318292319

expect(batchRes.ok).toBe(true);

293-

expect(pwMocks.batchViaPlaywright).toHaveBeenCalledWith(

294-

expect.objectContaining({

295-

actions: [

296-

{

297-

kind: "type",

298-

selector: "input.name",

299-

text: " padded ",

300-

},

301-

{

302-

kind: "type",

303-

selector: "input.clearable",

304-

text: "",

305-

},

306-

],

307-

}),

308-

);

320+

expectRecordFields(requireMockArg(pwMocks.batchViaPlaywright), "batch call", {

321+

actions: [

322+

{

323+

kind: "type",

324+

selector: "input.name",

325+

text: " padded ",

326+

},

327+

{

328+

kind: "type",

329+

selector: "input.clearable",

330+

text: "",

331+

},

332+

],

333+

});

309334

},

310335

slowTimeoutMs,

311336

);

@@ -383,59 +408,56 @@ describe("browser control server", () => {

383408

paths: ["a.txt"],

384409

timeoutMs: 1234,

385410

});

386-

expect(upload).toMatchObject({ ok: true });

387-

expect(pwMocks.armFileUploadViaPlaywright).toHaveBeenCalledWith(

388-

expect.objectContaining({

389-

cdpUrl: expect.any(String),

390-

targetId: "abcd1234",

391-

// The server resolves paths (which adds a drive letter on Windows for `\\tmp\\...` style roots).

392-

paths: [path.resolve(DEFAULT_UPLOAD_DIR, "a.txt")],

393-

timeoutMs: 1234,

394-

}),

395-

);

411+

expectOkResult(upload);

412+

expectBrowserCallFields(pwMocks.armFileUploadViaPlaywright, {

413+

targetId: "abcd1234",

414+

// The server resolves paths (which adds a drive letter on Windows for `\\tmp\\...` style roots).

415+

paths: [path.resolve(DEFAULT_UPLOAD_DIR, "a.txt")],

416+

timeoutMs: 1234,

417+

});

396418397419

const uploadWithRef = await postJson(`${base}/hooks/file-chooser`, {

398420

paths: ["b.txt"],

399421

ref: "e12",

400422

});

401-

expect(uploadWithRef).toMatchObject({ ok: true });

423+

expectOkResult(uploadWithRef);

402424403425

const uploadWithInputRef = await postJson(`${base}/hooks/file-chooser`, {

404426

paths: ["c.txt"],

405427

inputRef: "e99",

406428

});

407-

expect(uploadWithInputRef).toMatchObject({ ok: true });

429+

expectOkResult(uploadWithInputRef);

408430409431

const uploadWithElement = await postJson(`${base}/hooks/file-chooser`, {

410432

paths: ["d.txt"],

411433

element: "input[type=file]",

412434

});

413-

expect(uploadWithElement).toMatchObject({ ok: true });

435+

expectOkResult(uploadWithElement);

414436415437

const dialog = await postJson(`${base}/hooks/dialog`, {

416438

accept: true,

417439

timeoutMs: 5678,

418440

});

419-

expect(dialog).toMatchObject({ ok: true });

441+

expectOkResult(dialog);

420442421443

const waitDownload = await postJson(`${base}/wait/download`, {

422444

path: "report.pdf",

423445

timeoutMs: 1111,

424446

});

425-

expect(waitDownload).toMatchObject({ ok: true });

447+

expectOkResult(waitDownload);

426448427449

const download = await postJson(`${base}/download`, {

428450

ref: "e12",

429451

path: "report.pdf",

430452

});

431-

expect(download).toMatchObject({ ok: true });

453+

expectOkResult(download);

432454433455

const responseBody = await postJson(`${base}/response/body`, {

434456

url: "**/api/data",

435457

timeoutMs: 2222,

436458

maxChars: 10,

437459

});

438-

expect(responseBody).toMatchObject({ ok: true });

460+

expectOkResult(responseBody);

439461440462

const consoleRes = (await realFetch(`${base}/console?level=error`).then((r) => r.json())) as {

441463

ok: boolean;

@@ -455,13 +477,11 @@ describe("browser control server", () => {

455477

});

456478

expect(shot.ok).toBe(true);

457479

expect(typeof shot.path).toBe("string");

458-

expect(pwMocks.takeScreenshotViaPlaywright).toHaveBeenCalledWith(

459-

expect.objectContaining({

460-

element: "body",

461-

type: "jpeg",

462-

timeoutMs: 3333,

463-

}),

464-

);

480+

expectRecordFields(requireMockArg(pwMocks.takeScreenshotViaPlaywright), "screenshot call", {

481+

element: "body",

482+

type: "jpeg",

483+

timeoutMs: 3333,

484+

});

465485

});

466486467487

it("blocks file chooser traversal / absolute paths outside uploads dir", async () => {

@@ -507,13 +527,12 @@ describe("browser control server", () => {

507527

});

508528

expect(res.ok).toBe(true);

509529

expect(res.path).toContain("safe-trace.zip");

510-

expect(pwMocks.traceStopViaPlaywright).toHaveBeenCalledWith(

511-

expect.objectContaining({

512-

cdpUrl: expect.any(String),

513-

targetId: "abcd1234",

514-

path: expect.stringContaining("safe-trace.zip"),

515-

}),

516-

);

530+

const traceCall = requireMockArg(pwMocks.traceStopViaPlaywright);

531+

expect(typeof traceCall.cdpUrl).toBe("string");

532+

expectRecordFields(traceCall, "trace stop call", {

533+

targetId: "abcd1234",

534+

});

535+

expect(String(traceCall.path)).toContain("safe-trace.zip");

517536

});

518537519538

it.each(guardedCurrentTabRouteCases)(

@@ -615,13 +634,12 @@ describe("browser control server", () => {

615634

},

616635

);

617636

expect(res.ok).toBe(true);

618-

expect(pwMocks.waitForDownloadViaPlaywright).toHaveBeenCalledWith(

619-

expect.objectContaining({

620-

cdpUrl: expect.any(String),

621-

targetId: "abcd1234",

622-

path: expect.stringContaining("safe-wait.pdf"),

623-

}),

624-

);

637+

const waitCall = requireMockArg(pwMocks.waitForDownloadViaPlaywright);

638+

expect(typeof waitCall.cdpUrl).toBe("string");

639+

expectRecordFields(waitCall, "wait download call", {

640+

targetId: "abcd1234",

641+

});

642+

expect(String(waitCall.path)).toContain("safe-wait.pdf");

625643

});

626644627645

it("download accepts in-root relative output path", async () => {

@@ -631,13 +649,12 @@ describe("browser control server", () => {

631649

path: "safe-download.pdf",

632650

});

633651

expect(res.ok).toBe(true);

634-

expect(pwMocks.downloadViaPlaywright).toHaveBeenCalledWith(

635-

expect.objectContaining({

636-

cdpUrl: expect.any(String),

637-

targetId: "abcd1234",

638-

ref: "e12",

639-

path: expect.stringContaining("safe-download.pdf"),

640-

}),

641-

);

652+

const downloadCall = requireMockArg(pwMocks.downloadViaPlaywright);

653+

expect(typeof downloadCall.cdpUrl).toBe("string");

654+

expectRecordFields(downloadCall, "download call", {

655+

targetId: "abcd1234",

656+

ref: "e12",

657+

});

658+

expect(String(downloadCall.path)).toContain("safe-download.pdf");

642659

});

643660

});