test: guard gateway object helpers · openclaw/openclaw@18c56ef
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -25,17 +25,19 @@ function requireFallbackSeed(
|
25 | 25 | } |
26 | 26 | |
27 | 27 | function expectFields(value: unknown, expected: Record<string, unknown>): void { |
28 | | -expect(value).toBeTypeOf("object"); |
29 | | -expect(value).not.toBeNull(); |
| 28 | +if (!value || typeof value !== "object") { |
| 29 | +throw new Error("expected fields object"); |
| 30 | +} |
30 | 31 | const record = value as Record<string, unknown>; |
31 | 32 | for (const [key, expectedValue] of Object.entries(expected)) { |
32 | 33 | expect(record[key], key).toEqual(expectedValue); |
33 | 34 | } |
34 | 35 | } |
35 | 36 | |
36 | 37 | function readRecord(value: unknown): Record<string, unknown> { |
37 | | -expect(value).toBeTypeOf("object"); |
38 | | -expect(value).not.toBeNull(); |
| 38 | +if (!value || typeof value !== "object") { |
| 39 | +throw new Error("expected record"); |
| 40 | +} |
39 | 41 | return value as Record<string, unknown>; |
40 | 42 | } |
41 | 43 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -109,8 +109,9 @@ function createCronConfig(name: string): OpenClawConfig {
|
109 | 109 | } |
110 | 110 | |
111 | 111 | function requireRecord(value: unknown, label: string): Record<string, unknown> { |
112 | | -expect(value, label).toBeTypeOf("object"); |
113 | | -expect(value, label).not.toBeNull(); |
| 112 | +if (!value || typeof value !== "object") { |
| 113 | +throw new Error(`expected ${label}`); |
| 114 | +} |
114 | 115 | return value as Record<string, unknown>; |
115 | 116 | } |
116 | 117 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -49,8 +49,9 @@ function requireNonEmptyString(value: unknown, message: string): string {
|
49 | 49 | } |
50 | 50 | |
51 | 51 | function expectFields(value: unknown, expected: Record<string, unknown>): void { |
52 | | -expect(value).toBeTypeOf("object"); |
53 | | -expect(value).not.toBeNull(); |
| 52 | +if (!value || typeof value !== "object") { |
| 53 | +throw new Error("expected fields object"); |
| 54 | +} |
54 | 55 | const record = value as Record<string, unknown>; |
55 | 56 | for (const [key, expectedValue] of Object.entries(expected)) { |
56 | 57 | expect(record[key], key).toEqual(expectedValue); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -90,8 +90,9 @@ function findMessageWithIdempotencyKey(
|
90 | 90 | } |
91 | 91 | |
92 | 92 | function expectRecord(value: unknown, label: string): Record<string, unknown> { |
93 | | -expect(typeof value).toBe("object"); |
94 | | -expect(value, label).not.toBeNull(); |
| 93 | +if (!value || typeof value !== "object") { |
| 94 | +throw new Error(`expected ${label}`); |
| 95 | +} |
95 | 96 | return value as Record<string, unknown>; |
96 | 97 | } |
97 | 98 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -47,8 +47,9 @@ type MockCallSource = {
|
47 | 47 | }; |
48 | 48 | |
49 | 49 | function requireRecord(value: unknown, label: string): Record<string, unknown> { |
50 | | -expect(value, label).toBeTypeOf("object"); |
51 | | -expect(value, label).not.toBeNull(); |
| 50 | +if (!value || typeof value !== "object") { |
| 51 | +throw new Error(`expected ${label}`); |
| 52 | +} |
52 | 53 | return value as Record<string, unknown>; |
53 | 54 | } |
54 | 55 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -183,8 +183,9 @@ function buildCtx(): NodeEventContext {
|
183 | 183 | } |
184 | 184 | |
185 | 185 | function expectFields(value: unknown, expected: Record<string, unknown>): void { |
186 | | -expect(value).toBeTypeOf("object"); |
187 | | -expect(value).not.toBeNull(); |
| 186 | +if (!value || typeof value !== "object") { |
| 187 | +throw new Error("expected fields object"); |
| 188 | +} |
188 | 189 | const record = value as Record<string, unknown>; |
189 | 190 | for (const [key, expectedValue] of Object.entries(expected)) { |
190 | 191 | expect(record[key], key).toEqual(expectedValue); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -20,8 +20,9 @@ import {
|
20 | 20 | const { createSessionStoreDir, openClient } = setupGatewaySessionsTestHarness(); |
21 | 21 | |
22 | 22 | function expectObject(value: unknown) { |
23 | | -expect(typeof value).toBe("object"); |
24 | | -expect(value).not.toBeNull(); |
| 23 | +if (!value || typeof value !== "object") { |
| 24 | +throw new Error("expected object"); |
| 25 | +} |
25 | 26 | } |
26 | 27 | |
27 | 28 | test("sessions.delete rejects main and aborts active runs", async () => { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -79,8 +79,9 @@ function createMonitorHarness(params?: { cpuMsPerWallMs?: number; utilization?:
|
79 | 79 | } |
80 | 80 | |
81 | 81 | function expectSnapshotFields(snapshot: unknown, expected: Record<string, unknown>) { |
82 | | -expect(typeof snapshot).toBe("object"); |
83 | | -expect(snapshot).not.toBeNull(); |
| 82 | +if (!snapshot || typeof snapshot !== "object") { |
| 83 | +throw new Error("expected event loop health snapshot"); |
| 84 | +} |
84 | 85 | const actual = snapshot as Record<string, unknown>; |
85 | 86 | for (const [key, value] of Object.entries(expected)) { |
86 | 87 | expect(actual[key]).toEqual(value); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -84,8 +84,9 @@ function requireString(value: string | undefined, label: string): string {
|
84 | 84 | } |
85 | 85 | |
86 | 86 | function expectFields(value: unknown, expected: Record<string, unknown>): void { |
87 | | -expect(value).toBeTypeOf("object"); |
88 | | -expect(value).not.toBeNull(); |
| 87 | +if (!value || typeof value !== "object") { |
| 88 | +throw new Error("expected fields object"); |
| 89 | +} |
89 | 90 | const record = value as Record<string, unknown>; |
90 | 91 | for (const [key, expectedValue] of Object.entries(expected)) { |
91 | 92 | expect(record[key], key).toEqual(expectedValue); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。