test: guard command object helpers · openclaw/openclaw@905861c
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -124,8 +124,9 @@ function listConfiguredAccountIds(
|
124 | 124 | } |
125 | 125 | |
126 | 126 | function requireRecord(value: unknown, label: string): Record<string, unknown> { |
127 | | -expect(value, label).toBeTypeOf("object"); |
128 | | -expect(value, label).not.toBeNull(); |
| 127 | +if (!value || typeof value !== "object") { |
| 128 | +throw new Error(`expected ${label}`); |
| 129 | +} |
129 | 130 | return value as Record<string, unknown>; |
130 | 131 | } |
131 | 132 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -202,8 +202,9 @@ function setupBaseWizardState(config: OpenClawConfig = {}) {
|
202 | 202 | } |
203 | 203 | |
204 | 204 | function requireRecord(value: unknown, label: string): Record<string, unknown> { |
205 | | -expect(value, label).toBeTypeOf("object"); |
206 | | -expect(value, label).not.toBeNull(); |
| 205 | +if (!value || typeof value !== "object") { |
| 206 | +throw new Error(`expected ${label}`); |
| 207 | +} |
207 | 208 | return value as Record<string, unknown>; |
208 | 209 | } |
209 | 210 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -195,8 +195,9 @@ function createGatewayCommand(entrypoint: string) {
|
195 | 195 | } |
196 | 196 | |
197 | 197 | function requireRecord(value: unknown, label: string): Record<string, unknown> { |
198 | | -expect(value, label).toBeTypeOf("object"); |
199 | | -expect(value, label).not.toBeNull(); |
| 198 | +if (!value || typeof value !== "object") { |
| 199 | +throw new Error(`expected ${label}`); |
| 200 | +} |
200 | 201 | return value as Record<string, unknown>; |
201 | 202 | } |
202 | 203 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -31,7 +31,6 @@ async function readRequiredPersistedInstalledPluginIndex(
|
31 | 31 | stateDir: string, |
32 | 32 | ): Promise<InstalledPluginIndex> { |
33 | 33 | const persisted = await readPersistedInstalledPluginIndex({ stateDir }); |
34 | | -expect(persisted).not.toBeNull(); |
35 | 34 | if (!persisted) { |
36 | 35 | throw new Error("Expected persisted installed plugin index"); |
37 | 36 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -115,7 +115,6 @@ describe("detectLinuxSdBackedStateDir", () => {
|
115 | 115 | }, |
116 | 116 | }); |
117 | 117 | |
118 | | -expect(result).not.toBeNull(); |
119 | 118 | if (result === null) { |
120 | 119 | throw new Error("Expected Linux state storage warning details"); |
121 | 120 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -656,7 +656,6 @@ describe("legacy migrate heartbeat config", () => {
|
656 | 656 | }); |
657 | 657 | |
658 | 658 | expect(res.changes).toStrictEqual(["Removed empty top-level heartbeat."]); |
659 | | -expect(res.config).not.toBeNull(); |
660 | 659 | if (res.config === null) { |
661 | 660 | throw new Error("Expected migrated config"); |
662 | 661 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -151,8 +151,6 @@ function expectItemStatus(
|
151 | 151 | } |
152 | 152 | |
153 | 153 | function requireRecord(value: unknown, label: string): Record<string, unknown> { |
154 | | -expect(typeof value).toBe("object"); |
155 | | -expect(value).not.toBeNull(); |
156 | 154 | if (typeof value !== "object" || value === null) { |
157 | 155 | throw new Error(`${label} was not an object`); |
158 | 156 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -170,8 +170,9 @@ type MockCallSource = {
|
170 | 170 | }; |
171 | 171 | |
172 | 172 | function requireRecord(value: unknown, label: string): Record<string, unknown> { |
173 | | -expect(value, label).toBeTypeOf("object"); |
174 | | -expect(value, label).not.toBeNull(); |
| 173 | +if (!value || typeof value !== "object") { |
| 174 | +throw new Error(`expected ${label}`); |
| 175 | +} |
175 | 176 | return value as Record<string, unknown>; |
176 | 177 | } |
177 | 178 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -136,15 +136,17 @@ function expectRowFields(
|
136 | 136 | |
137 | 137 | function modelRegistryOptions(index = 0): Record<string, unknown> { |
138 | 138 | const options = mocks.loadModelRegistry.mock.calls[index]?.[1]; |
139 | | -expect(options).toBeTypeOf("object"); |
140 | | -expect(options).not.toBeNull(); |
| 139 | +if (!options || typeof options !== "object") { |
| 140 | +throw new Error(`expected model registry options ${index}`); |
| 141 | +} |
141 | 142 | return options as Record<string, unknown>; |
142 | 143 | } |
143 | 144 | |
144 | 145 | function providerCatalogOptions(index = 0): Record<string, unknown> { |
145 | 146 | const options = mocks.loadProviderCatalogModelsForList.mock.calls[index]?.[0]; |
146 | | -expect(options).toBeTypeOf("object"); |
147 | | -expect(options).not.toBeNull(); |
| 147 | +if (!options || typeof options !== "object") { |
| 148 | +throw new Error(`expected provider catalog options ${index}`); |
| 149 | +} |
148 | 150 | return options as Record<string, unknown>; |
149 | 151 | } |
150 | 152 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -264,8 +264,6 @@ function createRuntime() {
|
264 | 264 | } |
265 | 265 | |
266 | 266 | function requireRecord(value: unknown, label: string): Record<string, unknown> { |
267 | | -expect(typeof value).toBe("object"); |
268 | | -expect(value).not.toBeNull(); |
269 | 267 | if (typeof value !== "object" || value === null) { |
270 | 268 | throw new Error(`${label} was not an object`); |
271 | 269 | } |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。