test: guard extension helper null checks · openclaw/openclaw@6eccb0d
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
File tree
browser/src/browser/routes
| Original file line number | Diff line number | Diff line change |
|---|
@@ -107,8 +107,9 @@ function getActPostHandler() {
|
107 | 107 | } |
108 | 108 | |
109 | 109 | function requireRecord(value: unknown, label: string): Record<string, unknown> { |
110 | | -expect(value, label).toBeTypeOf("object"); |
111 | | -expect(value, label).not.toBeNull(); |
| 110 | +if (!value || typeof value !== "object") { |
| 111 | +throw new Error(`expected ${label}`); |
| 112 | +} |
112 | 113 | return value as Record<string, unknown>; |
113 | 114 | } |
114 | 115 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -35,8 +35,6 @@ async function expectSetupErrorStatus(
|
35 | 35 | } |
36 | 36 | |
37 | 37 | function requireRecord(value: unknown, label: string): Record<string, unknown> { |
38 | | -expect(typeof value).toBe("object"); |
39 | | -expect(value).not.toBeNull(); |
40 | 38 | if (typeof value !== "object" || value === null) { |
41 | 39 | throw new Error(`${label} was not an object`); |
42 | 40 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -69,8 +69,9 @@ function expectInputText(text: string) {
|
69 | 69 | } |
70 | 70 | |
71 | 71 | function requireRecord(value: unknown, label: string): Record<string, unknown> { |
72 | | -expect(value, label).toBeTypeOf("object"); |
73 | | -expect(value, label).not.toBeNull(); |
| 72 | +if (!value || typeof value !== "object") { |
| 73 | +throw new Error(`expected ${label}`); |
| 74 | +} |
74 | 75 | return value as Record<string, unknown>; |
75 | 76 | } |
76 | 77 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -21,8 +21,6 @@ function createContractTool(overrides: Partial<AnyAgentTool>): AnyAgentTool {
|
21 | 21 | } |
22 | 22 | |
23 | 23 | function requireRecord(value: unknown, label: string): Record<string, unknown> { |
24 | | -expect(typeof value).toBe("object"); |
25 | | -expect(value).not.toBeNull(); |
26 | 24 | if (typeof value !== "object" || value === null) { |
27 | 25 | throw new Error(`${label} was not an object`); |
28 | 26 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -50,8 +50,9 @@ function compileManifestConfigSchema() {
|
50 | 50 | } |
51 | 51 | |
52 | 52 | function requireRecord(value: unknown, label: string): Record<string, unknown> { |
53 | | -expect(value, label).toBeTypeOf("object"); |
54 | | -expect(value, label).not.toBeNull(); |
| 53 | +if (!value || typeof value !== "object") { |
| 54 | +throw new Error(`expected ${label}`); |
| 55 | +} |
55 | 56 | return value as Record<string, unknown>; |
56 | 57 | } |
57 | 58 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1282,7 +1282,6 @@ describe("handleFeishuMessage command authorization", () => {
|
1282 | 1282 | expect(finalized.OriginatingTo).toBe("chat:oc-group"); |
1283 | 1283 | expect(finalized.SenderId).toBe("ou-allowed"); |
1284 | 1284 | const groupSessionKey = resolveGroupSessionKey(finalized as never); |
1285 | | -expect(groupSessionKey).not.toBeNull(); |
1286 | 1285 | if (!groupSessionKey) { |
1287 | 1286 | throw new Error("Expected group session key"); |
1288 | 1287 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -64,8 +64,9 @@ type ToolResultWithDetails = {
|
64 | 64 | const WORKSPACE_ROOT = path.resolve("/workspace"); |
65 | 65 | |
66 | 66 | function requireRecord(value: unknown, label: string): Record<string, unknown> { |
67 | | -expect(value, label).toBeTypeOf("object"); |
68 | | -expect(value, label).not.toBeNull(); |
| 67 | +if (!value || typeof value !== "object") { |
| 68 | +throw new Error(`expected ${label}`); |
| 69 | +} |
69 | 70 | return value as Record<string, unknown>; |
70 | 71 | } |
71 | 72 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -108,8 +108,6 @@ function createCtx(overrides: {
|
108 | 108 | } |
109 | 109 | |
110 | 110 | function requireRecord(value: unknown, label: string): Record<string, unknown> { |
111 | | -expect(typeof value).toBe("object"); |
112 | | -expect(value).not.toBeNull(); |
113 | 111 | if (typeof value !== "object" || value === null) { |
114 | 112 | throw new Error(`${label} was not an object`); |
115 | 113 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -51,8 +51,6 @@ function withConfig(fileTransfer: Record<string, unknown> | undefined) {
|
51 | 51 | } |
52 | 52 | |
53 | 53 | function expectResultFields(result: unknown, fields: Record<string, unknown>) { |
54 | | -expect(typeof result).toBe("object"); |
55 | | -expect(result).not.toBeNull(); |
56 | 54 | if (typeof result !== "object" || result === null) { |
57 | 55 | throw new Error("policy result was not an object"); |
58 | 56 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -47,8 +47,6 @@ class MockMatrixClient {
|
47 | 47 | } |
48 | 48 | |
49 | 49 | function requireRecord(value: unknown, label: string): Record<string, unknown> { |
50 | | -expect(typeof value).toBe("object"); |
51 | | -expect(value).not.toBeNull(); |
52 | 50 | if (typeof value !== "object" || value === null) { |
53 | 51 | throw new Error(`${label} was not an object`); |
54 | 52 | } |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。