test: guard core sdk null helpers · openclaw/openclaw@32b8925
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -28,8 +28,9 @@ describe("acp prompt cwd prefix", () => {
|
28 | 28 | const call = requestSpy.mock.calls[index]; |
29 | 29 | expect(call?.[0]).toBe("chat.send"); |
30 | 30 | expect(call?.[2]).toEqual({ timeoutMs: null }); |
31 | | -expect(typeof call?.[1]).toBe("object"); |
32 | | -expect(call?.[1]).not.toBeNull(); |
| 31 | +if (!call?.[1] || typeof call[1] !== "object") { |
| 32 | +throw new Error(`expected chat.send payload ${index}`); |
| 33 | +} |
33 | 34 | return call?.[1] as Record<string, unknown>; |
34 | 35 | } |
35 | 36 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -127,8 +127,9 @@ async function expectOversizedPromptRejected(params: { sessionId: string; text:
|
127 | 127 | type MockCallSource = { mock: { calls: Array<Array<unknown>> } }; |
128 | 128 | |
129 | 129 | function requireRecord(value: unknown, label: string): Record<string, unknown> { |
130 | | -expect(value, label).toBeTypeOf("object"); |
131 | | -expect(value, label).not.toBeNull(); |
| 130 | +if (!value || typeof value !== "object") { |
| 131 | +throw new Error(`expected ${label}`); |
| 132 | +} |
132 | 133 | return value as Record<string, unknown>; |
133 | 134 | } |
134 | 135 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -47,8 +47,9 @@ function asRecord(value: unknown): Record<string, unknown> {
|
47 | 47 | } |
48 | 48 | |
49 | 49 | function expectRecord(value: unknown, label: string): Record<string, unknown> { |
50 | | -expect(value, label).not.toBeNull(); |
51 | | -expect(typeof value, label).toBe("object"); |
| 50 | +if (!value || typeof value !== "object") { |
| 51 | +throw new Error(`expected ${label}`); |
| 52 | +} |
52 | 53 | expect(Array.isArray(value), label).toBe(false); |
53 | 54 | return value as Record<string, unknown>; |
54 | 55 | } |
@@ -59,8 +60,10 @@ function readString(value: unknown): string | null {
|
59 | 60 | |
60 | 61 | function expectNonEmptyString(value: unknown, label: string): string { |
61 | 62 | const text = readString(value); |
62 | | -expect(text, label).not.toBeNull(); |
63 | | -return text as string; |
| 63 | +if (text === null) { |
| 64 | +throw new Error(`expected ${label}`); |
| 65 | +} |
| 66 | +return text; |
64 | 67 | } |
65 | 68 | |
66 | 69 | function readStringArray(value: unknown): string[] { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -71,7 +71,6 @@ describe("applyPluginNodeInvokePolicy", () => {
|
71 | 71 | params: { path: "/tmp/x" }, |
72 | 72 | }); |
73 | 73 | |
74 | | -expect(result).not.toBeNull(); |
75 | 74 | if (result === null) { |
76 | 75 | throw new Error("expected plugin policy failure"); |
77 | 76 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -156,8 +156,6 @@ describe("agent event handler", () => {
|
156 | 156 | } |
157 | 157 | |
158 | 158 | function requireRecord(value: unknown, label: string): Record<string, unknown> { |
159 | | -expect(typeof value).toBe("object"); |
160 | | -expect(value).not.toBeNull(); |
161 | 159 | if (typeof value !== "object" || value === null) { |
162 | 160 | throw new Error(`${label} was not an object`); |
163 | 161 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -114,8 +114,9 @@ function buildBasicSessionTranscript(
|
114 | 114 | } |
115 | 115 | |
116 | 116 | function requireRecord(value: unknown, label: string): Record<string, unknown> { |
117 | | -expect(value, label).toBeTypeOf("object"); |
118 | | -expect(value, label).not.toBeNull(); |
| 117 | +if (!value || typeof value !== "object") { |
| 118 | +throw new Error(`expected ${label}`); |
| 119 | +} |
119 | 120 | return value as Record<string, unknown>; |
120 | 121 | } |
121 | 122 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -11,8 +11,9 @@ import {
|
11 | 11 | } from "./diagnostic-stability.js"; |
12 | 12 | |
13 | 13 | function expectFields(value: unknown, expected: Record<string, unknown>): void { |
14 | | -expect(value).toBeTypeOf("object"); |
15 | | -expect(value).not.toBeNull(); |
| 14 | +if (!value || typeof value !== "object") { |
| 15 | +throw new Error("expected fields object"); |
| 16 | +} |
16 | 17 | const record = value as Record<string, unknown>; |
17 | 18 | for (const [key, expectedValue] of Object.entries(expected)) { |
18 | 19 | expect(record[key], key).toEqual(expectedValue); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -64,8 +64,6 @@ function countMatching<T>(items: readonly T[], predicate: (item: T) => boolean)
|
64 | 64 | } |
65 | 65 | |
66 | 66 | function requireRecord(value: unknown, label: string): Record<string, unknown> { |
67 | | -expect(typeof value).toBe("object"); |
68 | | -expect(value).not.toBeNull(); |
69 | 67 | if (typeof value !== "object" || value === null) { |
70 | 68 | throw new Error(`${label} was not an object`); |
71 | 69 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -165,7 +165,6 @@ describe("discord plugin-sdk facade", () => {
|
165 | 165 | expect(callParams.agentId).toBe("agent"); |
166 | 166 | expect(callParams.cfg).toBe(mocks.runtimeConfig); |
167 | 167 | expect(callParams.childSessionKey).toBe("child"); |
168 | | -expect(binding).not.toBeNull(); |
169 | 168 | if (!binding) { |
170 | 169 | throw new Error("expected Discord subagent binding"); |
171 | 170 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -9,8 +9,9 @@ import {
|
9 | 9 | } from "./provider-model-shared.js"; |
10 | 10 | |
11 | 11 | function expectFields(value: unknown, expected: Record<string, unknown>): void { |
12 | | -expect(value).toBeTypeOf("object"); |
13 | | -expect(value).not.toBeNull(); |
| 12 | +if (!value || typeof value !== "object") { |
| 13 | +throw new Error("expected fields object"); |
| 14 | +} |
14 | 15 | const record = value as Record<string, unknown>; |
15 | 16 | for (const [key, expectedValue] of Object.entries(expected)) { |
16 | 17 | expect(record[key], key).toEqual(expectedValue); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。