test: guard support helper assertions · openclaw/openclaw@5f00135
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -98,7 +98,9 @@ function createDeferred(): { promise: Promise<void>; resolve: () => void } {
|
98 | 98 | } |
99 | 99 | |
100 | 100 | function expectRecordFields(record: unknown, expected: Record<string, unknown>) { |
101 | | -expect(record).toBeDefined(); |
| 101 | +if (!record || typeof record !== "object") { |
| 102 | +throw new Error("Expected record"); |
| 103 | +} |
102 | 104 | const actual = record as Record<string, unknown>; |
103 | 105 | for (const [key, value] of Object.entries(expected)) { |
104 | 106 | expect(actual[key]).toEqual(value); |
@@ -136,7 +138,9 @@ function findMockCallFields(mock: ReturnType<typeof vi.fn>, expected: Record<str
|
136 | 138 | } |
137 | 139 | |
138 | 140 | function expectMockCallFields(mock: ReturnType<typeof vi.fn>, expected: Record<string, unknown>) { |
139 | | -expect(findMockCallFields(mock, expected)).toBeDefined(); |
| 141 | +if (!findMockCallFields(mock, expected)) { |
| 142 | +throw new Error(`Expected mock call ${JSON.stringify(expected)}`); |
| 143 | +} |
140 | 144 | } |
141 | 145 | |
142 | 146 | function expectNoMockCallFields(mock: ReturnType<typeof vi.fn>, expected: Record<string, unknown>) { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -336,7 +336,6 @@ describe("acp translator stable lifecycle handlers", () => {
|
336 | 336 | const result = await agent.resumeSession(createResumeSessionRequest("agent:main:work")); |
337 | 337 | |
338 | 338 | expect(result.modes?.currentModeId).toBe("adaptive"); |
339 | | -expect(result.configOptions).toBeDefined(); |
340 | 339 | if (!result.configOptions) { |
341 | 340 | throw new Error("expected resume session config options"); |
342 | 341 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -139,9 +139,11 @@ function configOptions(value: unknown) {
|
139 | 139 | |
140 | 140 | function expectConfigOption(options: unknown, id: string, fields: Record<string, unknown>) { |
141 | 141 | const option = configOptions(options).find((candidate) => candidate.id === id); |
142 | | -expect(option, `config option ${id}`).toBeDefined(); |
| 142 | +if (!option) { |
| 143 | +throw new Error(`Expected config option ${id}`); |
| 144 | +} |
143 | 145 | for (const [field, value] of Object.entries(fields)) { |
144 | | -expect(option?.[field]).toEqual(value); |
| 146 | +expect(option[field]).toEqual(value); |
145 | 147 | } |
146 | 148 | } |
147 | 149 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -592,7 +592,6 @@ describe("commands registry args", () => {
|
592 | 592 | }; |
593 | 593 | |
594 | 594 | const args = parseCommandArgs(command, "set foo bar baz"); |
595 | | -expect(args).toBeDefined(); |
596 | 595 | if (!args) { |
597 | 596 | throw new Error("Expected parsed command args"); |
598 | 597 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -236,7 +236,6 @@ async function expectNextRunUsesTargetSession(
|
236 | 236 | const runParams = params.runEmbeddedPiAgentMock.mock.calls[0]?.[0] as |
237 | 237 | | Record<string, unknown> |
238 | 238 | | undefined; |
239 | | -expect(runParams).toBeDefined(); |
240 | 239 | if (!runParams) { |
241 | 240 | throw new Error("expected embedded PI agent call params"); |
242 | 241 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -43,7 +43,6 @@ function expectAuditRecord(
|
43 | 43 | |
44 | 44 | function requireFirstMockCall(mock: unknown, label: string): unknown[] { |
45 | 45 | const call = (mock as { mock?: { calls?: unknown[][] } }).mock?.calls?.[0]; |
46 | | -expect(call).toBeDefined(); |
47 | 46 | if (!call) { |
48 | 47 | throw new Error(`missing ${label} call`); |
49 | 48 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -80,8 +80,10 @@ function makePluginRegistry(overrides: Partial<PluginRegistry> = {}): PluginRegi
|
80 | 80 | |
81 | 81 | function callArg<T>(mock: { mock: { calls: unknown[][] } }, index = 0, _type?: (value: T) => T): T { |
82 | 82 | const call = mock.mock.calls[index]; |
83 | | -expect(call).toBeDefined(); |
84 | | -return call?.[0] as T; |
| 83 | +if (!call) { |
| 84 | +throw new Error(`Expected mock call ${index}`); |
| 85 | +} |
| 86 | +return call[0] as T; |
85 | 87 | } |
86 | 88 | |
87 | 89 | function expectExternalCatalogInstallCall(index = 0) { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -24,7 +24,9 @@ vi.mock("./channel-resolution.js", () => ({
|
24 | 24 | |
25 | 25 | function mockCallArg(mock: { mock: { calls: unknown[][] } }, index = 0): unknown { |
26 | 26 | const call = mock.mock.calls[index]; |
27 | | -expect(call).toBeDefined(); |
| 27 | +if (!call) { |
| 28 | +throw new Error(`Expected mock call ${index}`); |
| 29 | +} |
28 | 30 | return call[0]; |
29 | 31 | } |
30 | 32 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -94,7 +94,6 @@ function requireMatchingRecord(
|
94 | 94 | const record = item as Record<string, unknown>; |
95 | 95 | return Object.entries(fields).every(([key, value]) => Object.is(record[key], value)); |
96 | 96 | }); |
97 | | -expect(found).toBeDefined(); |
98 | 97 | if (!found) { |
99 | 98 | throw new Error(`missing ${label}`); |
100 | 99 | } |
@@ -104,7 +103,6 @@ function requireMatchingRecord(
|
104 | 103 | function requireFirstMockCallArg(mock: unknown, label: string) { |
105 | 104 | const calls = (mock as { mock?: { calls?: unknown[][] } }).mock?.calls; |
106 | 105 | const call = calls?.[0]; |
107 | | -expect(call).toBeDefined(); |
108 | 106 | if (!call) { |
109 | 107 | throw new Error(`missing ${label} call`); |
110 | 108 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -553,7 +553,9 @@ describe("handleSystemRunInvoke mac app exec host routing", () => {
|
553 | 553 | }); |
554 | 554 | |
555 | 555 | const shellWrapperCall = requireMacExecHostCall(shellWrapperInvoke.runViaMacAppExecHost); |
556 | | -expect(shellWrapperCall.approvals).toBeDefined(); |
| 556 | +if (shellWrapperCall.approvals === undefined) { |
| 557 | +throw new Error("Expected shell-wrapper approvals"); |
| 558 | +} |
557 | 559 | expect(shellWrapperCall.request?.command).toEqual([ |
558 | 560 | "/bin/sh", |
559 | 561 | "-lc", |
@@ -621,7 +623,9 @@ describe("handleSystemRunInvoke mac app exec host routing", () => {
|
621 | 623 | const canonicalCwd = fs.realpathSync(tmp); |
622 | 624 | expect(invoke.runCommand).not.toHaveBeenCalled(); |
623 | 625 | const macHostCall = requireMacExecHostCall(invoke.runViaMacAppExecHost); |
624 | | -expect(macHostCall.approvals).toBeDefined(); |
| 626 | +if (macHostCall.approvals === undefined) { |
| 627 | +throw new Error("Expected Mac host approvals"); |
| 628 | +} |
625 | 629 | expect(macHostCall.request?.command).toEqual(["env", "sh", "-c", "echo SAFE"]); |
626 | 630 | expect(macHostCall.request?.rawCommand).toBe('env sh -c "echo SAFE"'); |
627 | 631 | expect(macHostCall.request?.cwd).toBe(canonicalCwd); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。