test: remove redundant defined guards · openclaw/openclaw@4da1152
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1806,7 +1806,6 @@ describe("memory cli", () => {
|
1806 | 1806 | const entries = Object.values(store.entries ?? {}); |
1807 | 1807 | expect(entries).toHaveLength(1); |
1808 | 1808 | const entry = entries[0]; |
1809 | | -expect(entry).toBeDefined(); |
1810 | 1809 | if (!entry) { |
1811 | 1810 | throw new Error("Expected short-term recall entry"); |
1812 | 1811 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -445,9 +445,8 @@ describe("createTelegramBot", () => {
|
445 | 445 | const sequentializer = sequentializeSpy.mock.results[0]?.value as |
446 | 446 | | TelegramMiddleware |
447 | 447 | | undefined; |
448 | | -expect(sequentializer).toBeDefined(); |
449 | 448 | if (!sequentializer) { |
450 | | -return; |
| 449 | +throw new Error("Expected sequentialize middleware"); |
451 | 450 | } |
452 | 451 | |
453 | 452 | const topicCtx = (threadId: number, updateId: number) => { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -416,7 +416,6 @@ describe("RealtimeCallHandler path routing", () => {
|
416 | 416 | await waitForRealtimeTest(() => { |
417 | 417 | const events = processEvent.mock.calls.map(([event]) => event as NormalizedEvent); |
418 | 418 | const ended = events.find((event) => event.type === "call.ended"); |
419 | | -expect(ended).toBeDefined(); |
420 | 419 | if (ended?.type !== "call.ended") { |
421 | 420 | throw new Error("expected realtime stop to emit call.ended"); |
422 | 421 | } |
@@ -704,12 +703,14 @@ describe("RealtimeCallHandler path routing", () => {
|
704 | 703 | const workingCall = submitToolResult.mock.calls.find( |
705 | 704 | ([callId]) => callId === "consult-call", |
706 | 705 | ); |
707 | | -expect(workingCall).toBeDefined(); |
708 | | -const payload = workingCall?.[1] as Record<string, unknown> | undefined; |
| 706 | +if (!workingCall) { |
| 707 | +throw new Error("expected consult-call tool result"); |
| 708 | +} |
| 709 | +const payload = workingCall[1] as Record<string, unknown> | undefined; |
709 | 710 | expect(payload?.status).toBe("working"); |
710 | 711 | expect(payload?.tool).toBe("openclaw_agent_consult"); |
711 | 712 | expect(typeof payload?.message).toBe("string"); |
712 | | -expect(workingCall?.[2]).toEqual({ willContinue: true }); |
| 713 | +expect(workingCall[2]).toEqual({ willContinue: true }); |
713 | 714 | }); |
714 | 715 | expect(submitToolResult).toHaveBeenCalledTimes(1); |
715 | 716 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -126,7 +126,6 @@ describe("subscribeEmbeddedPiSession", () => {
|
126 | 126 | expected: { text: string; mediaUrls?: string[] }, |
127 | 127 | ): void { |
128 | 128 | const payload = findBlockReplyPayload(onBlockReply, expected.text); |
129 | | -expect(payload).toBeDefined(); |
130 | 129 | if (!payload) { |
131 | 130 | throw new Error(`Expected block reply text: ${expected.text}`); |
132 | 131 | } |
@@ -145,7 +144,9 @@ describe("subscribeEmbeddedPiSession", () => {
|
145 | 144 | item.livenessState === expected.livenessState && |
146 | 145 | item.replayInvalid === expected.replayInvalid, |
147 | 146 | ); |
148 | | -expect(payload).toBeDefined(); |
| 147 | +if (!payload) { |
| 148 | +throw new Error(`Expected lifecycle payload for phase ${expected.phase}`); |
| 149 | +} |
149 | 150 | } |
150 | 151 | |
151 | 152 | it("captures usage from completions timings on done events", () => { |
@@ -1057,8 +1058,10 @@ describe("subscribeEmbeddedPiSession", () => {
|
1057 | 1058 | // Look for lifecycle:error event |
1058 | 1059 | const lifecycleError = findLifecycleErrorAgentEvent(onAgentEvent.mock.calls); |
1059 | 1060 | |
1060 | | -expect(lifecycleError).toBeDefined(); |
1061 | | -const error = (lifecycleError?.data as { error?: unknown } | undefined)?.error; |
| 1061 | +if (!lifecycleError) { |
| 1062 | +throw new Error("Expected lifecycle error event"); |
| 1063 | +} |
| 1064 | +const error = (lifecycleError.data as { error?: unknown } | undefined)?.error; |
1062 | 1065 | expect(typeof error).toBe("string"); |
1063 | 1066 | expect(error).toContain("API rate limit reached"); |
1064 | 1067 | }); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -276,8 +276,6 @@ describe("backup commands", () => {
|
276 | 276 | |
277 | 277 | const stateAsset = result.assets.find((asset) => asset.kind === "state"); |
278 | 278 | const workspaceAsset = result.assets.find((asset) => asset.kind === "workspace"); |
279 | | -expect(stateAsset).toBeDefined(); |
280 | | -expect(workspaceAsset).toBeDefined(); |
281 | 279 | if (!stateAsset || !workspaceAsset) { |
282 | 280 | throw new Error("Expected backup assets to include state and workspace entries."); |
283 | 281 | } |
@@ -329,8 +327,6 @@ describe("backup commands", () => {
|
329 | 327 | ) => { |
330 | 328 | const manifestPath = entryPaths[0]; |
331 | 329 | const stateRoot = entryPaths[1]; |
332 | | -expect(manifestPath).toBeDefined(); |
333 | | -expect(stateRoot).toBeDefined(); |
334 | 330 | if (!manifestPath || !stateRoot) { |
335 | 331 | throw new Error("backup test expected manifest and state entries"); |
336 | 332 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -131,7 +131,6 @@ function expectSummaryFields(
|
131 | 131 | |
132 | 132 | function requireItem(items: MigrationItem[], id: string): MigrationItem { |
133 | 133 | const item = items.find((candidate) => candidate.id === id); |
134 | | -expect(item).toBeDefined(); |
135 | 134 | if (!item) { |
136 | 135 | throw new Error(`missing migration item ${id}`); |
137 | 136 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -290,7 +290,6 @@ function requireProvider(providers: unknown, provider: string) {
|
290 | 290 | const entry = requireArray(providers, "auth providers").find( |
291 | 291 | (candidate) => requireRecord(candidate, "auth provider").provider === provider, |
292 | 292 | ); |
293 | | -expect(entry).toBeDefined(); |
294 | 293 | if (!entry) { |
295 | 294 | throw new Error(`missing provider ${provider}`); |
296 | 295 | } |
@@ -301,7 +300,6 @@ function requireProfile(profiles: unknown, profileId: string) {
|
301 | 300 | const entry = requireArray(profiles, "auth profiles").find( |
302 | 301 | (candidate) => requireRecord(candidate, "auth profile").profileId === profileId, |
303 | 302 | ); |
304 | | -expect(entry).toBeDefined(); |
305 | 303 | if (!entry) { |
306 | 304 | throw new Error(`missing profile ${profileId}`); |
307 | 305 | } |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。