test: guard core agent null helpers · openclaw/openclaw@baa2776
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -93,8 +93,6 @@ async function readSessionFileJsonLines<T>(sessionFile: string): Promise<T[]> {
|
93 | 93 | } |
94 | 94 | |
95 | 95 | function requireRecord(value: unknown, label: string): Record<string, unknown> { |
96 | | -expect(typeof value).toBe("object"); |
97 | | -expect(value).not.toBeNull(); |
98 | 96 | if (typeof value !== "object" || value === null) { |
99 | 97 | throw new Error(`${label} was not an object`); |
100 | 98 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -30,8 +30,6 @@ const overrideBoundaryAwareStreamFnOnce = (streamFn: StreamFn): void => {
|
30 | 30 | }; |
31 | 31 | |
32 | 32 | function requireRecord(value: unknown, label: string): Record<string, unknown> { |
33 | | -expect(value).toBeTypeOf("object"); |
34 | | -expect(value).not.toBeNull(); |
35 | 33 | if (!value || typeof value !== "object" || Array.isArray(value)) { |
36 | 34 | throw new Error(`expected ${label} to be an object`); |
37 | 35 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -27,7 +27,6 @@ async function expectPathMissing(targetPath: string): Promise<void> {
|
27 | 27 | function expectBudgetResult( |
28 | 28 | result: Awaited<ReturnType<typeof enforceSessionDiskBudget>>, |
29 | 29 | ): asserts result is NonNullable<Awaited<ReturnType<typeof enforceSessionDiskBudget>>> { |
30 | | -expect(result).not.toBeNull(); |
31 | 30 | if (result === null) { |
32 | 31 | throw new Error("expected disk budget enforcement result"); |
33 | 32 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -132,7 +132,6 @@ describe("Crestodian assistant", () => {
|
132 | 132 | removeTempDir: async () => {}, |
133 | 133 | }, |
134 | 134 | }); |
135 | | -expect(result).not.toBeNull(); |
136 | 135 | if (result === null) { |
137 | 136 | throw new Error("Expected planner result"); |
138 | 137 | } |
@@ -214,7 +213,6 @@ describe("Crestodian assistant", () => {
|
214 | 213 | removeTempDir: async () => {}, |
215 | 214 | }, |
216 | 215 | }); |
217 | | -expect(result).not.toBeNull(); |
218 | 216 | if (result === null) { |
219 | 217 | throw new Error("Expected planner result"); |
220 | 218 | } |
@@ -266,7 +264,6 @@ describe("Crestodian assistant", () => {
|
266 | 264 | removeTempDir: async () => {}, |
267 | 265 | }, |
268 | 266 | }); |
269 | | -expect(result).not.toBeNull(); |
270 | 267 | if (result === null) { |
271 | 268 | throw new Error("Expected planner result"); |
272 | 269 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -17,8 +17,6 @@ function parseLastJsonLine(raw: string): unknown {
|
17 | 17 | } |
18 | 18 | |
19 | 19 | function requireRecord(value: unknown, label: string): Record<string, unknown> { |
20 | | -expect(typeof value).toBe("object"); |
21 | | -expect(value).not.toBeNull(); |
22 | 20 | if (typeof value !== "object" || value === null) { |
23 | 21 | throw new Error(`${label} was not an object`); |
24 | 22 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -99,9 +99,10 @@ describeLive("Crestodian live rescue channel smoke", () => {
|
99 | 99 | |
100 | 100 | const config = JSON.parse(await fs.readFile(configPath, "utf8")) as OpenClawConfig; |
101 | 101 | const defaultModel = config.agents?.defaults?.model; |
102 | | -expect(typeof defaultModel).toBe("object"); |
103 | | -expect(defaultModel).not.toBeNull(); |
104 | | -expect((defaultModel as { primary?: unknown }).primary).toBe("openai/gpt-5.5"); |
| 102 | +if (!defaultModel || typeof defaultModel !== "object") { |
| 103 | +throw new Error("expected default model object"); |
| 104 | +} |
| 105 | +expect(defaultModel.primary).toBe("openai/gpt-5.5"); |
105 | 106 | const auditPath = path.join(tempDir, "audit", "crestodian.jsonl"); |
106 | 107 | const auditLines = (await fs.readFile(auditPath, "utf8")).trim().split("\n"); |
107 | 108 | expect(auditLines.some((line) => line.includes('"operation":"config.setDefaultModel"'))).toBe( |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -68,7 +68,8 @@ describe("runCrestodianTui", () => {
|
68 | 68 | expect(options.historyLimit).toBe(200); |
69 | 69 | expect(options.config).toEqual({}); |
70 | 70 | expect(options.title).toBe("openclaw crestodian"); |
71 | | -expect(typeof options.backend).toBe("object"); |
72 | | -expect(options.backend).not.toBeNull(); |
| 71 | +if (!options.backend || typeof options.backend !== "object") { |
| 72 | +throw new Error("expected crestodian TUI backend"); |
| 73 | +} |
73 | 74 | }); |
74 | 75 | }); |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -184,8 +184,9 @@ function makeBaseParams(overrides: {
|
184 | 184 | } |
185 | 185 | |
186 | 186 | function requireRecord(value: unknown, label: string): Record<string, unknown> { |
187 | | -expect(value, label).toBeTypeOf("object"); |
188 | | -expect(value, label).not.toBeNull(); |
| 187 | +if (!value || typeof value !== "object") { |
| 188 | +throw new Error(`expected ${label}`); |
| 189 | +} |
189 | 190 | return value as Record<string, unknown>; |
190 | 191 | } |
191 | 192 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -13,7 +13,6 @@ import {
|
13 | 13 | type CliRespawnPlan = NonNullable<ReturnType<typeof buildCliRespawnPlan>>; |
14 | 14 | |
15 | 15 | function expectCliRespawnPlan(plan: ReturnType<typeof buildCliRespawnPlan>): CliRespawnPlan { |
16 | | -expect(plan).not.toBeNull(); |
17 | 16 | if (plan === null) { |
18 | 17 | throw new Error("Expected CLI respawn plan"); |
19 | 18 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -81,7 +81,9 @@ vi.mock("./channel-tools.js", () => ({
|
81 | 81 | |
82 | 82 | async function waitForTransport(): Promise<{ onclose?: (() => void) | undefined }> { |
83 | 83 | await vi.waitFor(() => { |
84 | | -expect(transportState.lastTransport).not.toBeNull(); |
| 84 | +if (transportState.lastTransport === null) { |
| 85 | +throw new Error("MCP stdio transport was not created"); |
| 86 | +} |
85 | 87 | }); |
86 | 88 | if (!transportState.lastTransport) { |
87 | 89 | throw new Error("MCP stdio transport was not created"); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。