test: guard sandbox skills mock calls · openclaw/openclaw@80a9072
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -36,7 +36,7 @@ function requireApprovalRequestCall(label: string): {
|
36 | 36 | request: Record<string, unknown>; |
37 | 37 | options: Record<string, unknown>; |
38 | 38 | } { |
39 | | -const call = mockCallGatewayTool.mock.calls[0]; |
| 39 | +const call = mockCallGatewayTool.mock.calls.at(0); |
40 | 40 | if (!call) { |
41 | 41 | throw new Error(`expected ${label}`); |
42 | 42 | } |
@@ -52,7 +52,7 @@ function requireBeforeToolCall(
|
52 | 52 | mock: ReturnType<typeof vi.fn<HookRunner["runBeforeToolCall"]>>, |
53 | 53 | label: string, |
54 | 54 | ): Parameters<HookRunner["runBeforeToolCall"]> { |
55 | | -const call = mock.mock.calls[0]; |
| 55 | +const call = mock.mock.calls.at(0); |
56 | 56 | if (!call) { |
57 | 57 | throw new Error(`expected ${label}`); |
58 | 58 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -44,7 +44,7 @@ describe("createOpenClawCodingTools cron scope", () => {
|
44 | 44 | }); |
45 | 45 | |
46 | 46 | expect(tools.map((tool) => tool.name)).toContain("cron"); |
47 | | -const [options] = mocks.createOpenClawToolsOptions.mock.calls[0] ?? []; |
| 47 | +const [options] = mocks.createOpenClawToolsOptions.mock.calls.at(0) ?? []; |
48 | 48 | expect(options?.cronSelfRemoveOnlyJobId).toBe("job-current"); |
49 | 49 | }); |
50 | 50 | |
@@ -55,7 +55,7 @@ describe("createOpenClawCodingTools cron scope", () => {
|
55 | 55 | senderIsOwner: true, |
56 | 56 | }); |
57 | 57 | |
58 | | -const [options] = mocks.createOpenClawToolsOptions.mock.calls[0] ?? []; |
| 58 | +const [options] = mocks.createOpenClawToolsOptions.mock.calls.at(0) ?? []; |
59 | 59 | expect(options?.cronSelfRemoveOnlyJobId).toBeUndefined(); |
60 | 60 | }); |
61 | 61 | }); |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -101,7 +101,7 @@ describe("listSandboxBrowsers", () => {
|
101 | 101 | it("compares browser runtimes against sandbox.browser.image", async () => { |
102 | 102 | const results = await listSandboxBrowsers(); |
103 | 103 | |
104 | | -const describeInput = backendMocks.describeRuntime.mock.calls[0]?.[0] as |
| 104 | +const describeInput = backendMocks.describeRuntime.mock.calls.at(0)?.[0] as |
105 | 105 | | { agentId?: string; entry?: { configLabelKind?: string } } |
106 | 106 | | undefined; |
107 | 107 | expect(describeInput?.agentId).toBe("coder"); |
@@ -115,7 +115,7 @@ describe("listSandboxBrowsers", () => {
|
115 | 115 | it("removes browser runtimes with BrowserImage config label kind", async () => { |
116 | 116 | await removeSandboxBrowserContainer("browser-1"); |
117 | 117 | |
118 | | -const removeInput = backendMocks.removeRuntime.mock.calls[0]?.[0] as |
| 118 | +const removeInput = backendMocks.removeRuntime.mock.calls.at(0)?.[0] as |
119 | 119 | | { |
120 | 120 | entry?: { |
121 | 121 | containerName?: string; |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -89,7 +89,7 @@ describe("ssh subprocess env sanitization", () => {
|
89 | 89 | remoteCommand: "true", |
90 | 90 | }); |
91 | 91 | |
92 | | -const spawnOptions = spawnMock.mock.calls[0]?.[2] as SpawnOptions | undefined; |
| 92 | +const spawnOptions = spawnMock.mock.calls.at(0)?.[2] as SpawnOptions | undefined; |
93 | 93 | const env = spawnOptions?.env; |
94 | 94 | expect(env?.OPENAI_API_KEY).toBeUndefined(); |
95 | 95 | expect(env?.LANG).toBe("en_US.UTF-8"); |
@@ -113,7 +113,7 @@ describe("ssh subprocess env sanitization", () => {
|
113 | 113 | remoteDir: "/remote/workspace", |
114 | 114 | }); |
115 | 115 | |
116 | | -const sshSpawnOptions = spawnMock.mock.calls[1]?.[2] as SpawnOptions | undefined; |
| 116 | +const sshSpawnOptions = spawnMock.mock.calls.at(1)?.[2] as SpawnOptions | undefined; |
117 | 117 | const env = sshSpawnOptions?.env; |
118 | 118 | expect(env?.ANTHROPIC_API_KEY).toBeUndefined(); |
119 | 119 | expect(env?.NODE_ENV).toBe("test"); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -287,7 +287,7 @@ describe("installSkill code safety scanning", () => {
|
287 | 287 | |
288 | 288 | expect(result.ok).toBe(true); |
289 | 289 | expect(handler).toHaveBeenCalledTimes(1); |
290 | | -const payload = handler.mock.calls[0]?.[0] as |
| 290 | +const payload = handler.mock.calls.at(0)?.[0] as |
291 | 291 | | { |
292 | 292 | targetName?: string; |
293 | 293 | targetType?: string; |
@@ -316,7 +316,7 @@ describe("installSkill code safety scanning", () => {
|
316 | 316 | expect(payload?.skill?.installId).toBe("deps"); |
317 | 317 | expect(payload?.skill?.installSpec?.kind).toBe("node"); |
318 | 318 | expect(payload?.skill?.installSpec?.package).toBe("example-package"); |
319 | | -expect(handler.mock.calls[0]?.[1]).toEqual({ |
| 319 | +expect(handler.mock.calls.at(0)?.[1]).toEqual({ |
320 | 320 | origin: "openclaw-workspace", |
321 | 321 | targetType: "skill", |
322 | 322 | requestKind: "skill-install", |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。