test: guard oc-path null results · openclaw/openclaw@07f4b71
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
File tree
extensions/oc-path/src/oc-path/tests
| Original file line number | Diff line number | Diff line change |
|---|
@@ -87,19 +87,19 @@ describe("resolveJsonlToUniversal — file-relative line metadata (regression)",
|
87 | 87 | it("resolves L2/event with line=2 (not 1)", () => { |
88 | 88 | const { ast } = parseJsonl(log); |
89 | 89 | const m = resolveOcPath(ast, parseOcPath("oc://session.jsonl/L2/event")); |
90 | | -expect(m).not.toBeNull(); |
91 | | -if (m !== null) { |
92 | | -expect(m.line).toBe(2); |
| 90 | +if (m === null) { |
| 91 | +throw new Error("expected L2/event match"); |
93 | 92 | } |
| 93 | +expect(m.line).toBe(2); |
94 | 94 | }); |
95 | 95 | |
96 | 96 | it("resolves L4/event with line=4", () => { |
97 | 97 | const { ast } = parseJsonl(log); |
98 | 98 | const m = resolveOcPath(ast, parseOcPath("oc://session.jsonl/L4/event")); |
99 | | -expect(m).not.toBeNull(); |
100 | | -if (m !== null) { |
101 | | -expect(m.line).toBe(4); |
| 99 | +if (m === null) { |
| 100 | +throw new Error("expected L4/event match"); |
102 | 101 | } |
| 102 | +expect(m.line).toBe(4); |
103 | 103 | }); |
104 | 104 | |
105 | 105 | it("findOcPaths over wildcard surfaces correct file-relative lines", () => { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -126,7 +126,9 @@ describe("cross-cutting", () => {
|
126 | 126 | ]; |
127 | 127 | for (const path of cases) { |
128 | 128 | const m = resolveOcPath(ast, path); |
129 | | -expect(m, `failed for ${JSON.stringify(path)}`).not.toBeNull(); |
| 129 | +if (m === null) { |
| 130 | +throw new Error(`failed for ${JSON.stringify(path)}`); |
| 131 | +} |
130 | 132 | } |
131 | 133 | }); |
132 | 134 | }); |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -15,8 +15,10 @@ function rt(raw: string): string {
|
15 | 15 | */ |
16 | 16 | function assertParseable(raw: string): JsoncValue { |
17 | 17 | const result = parseJsonc(raw); |
18 | | -expect(result.ast.root).not.toBeNull(); |
19 | | -return result.ast.root as JsoncValue; |
| 18 | +if (result.ast.root === null) { |
| 19 | +throw new Error("expected parseable JSONC root"); |
| 20 | +} |
| 21 | +return result.ast.root; |
20 | 22 | } |
21 | 23 | |
22 | 24 | /** |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -87,8 +87,10 @@ describe("oc-path-resolver-edges", () => {
|
87 | 87 | section: "tools", |
88 | 88 | item: "gh", |
89 | 89 | }); |
90 | | -expect(m).not.toBeNull(); |
91 | | -if (m?.kind === "item") { |
| 90 | +if (m === null) { |
| 91 | +throw new Error("expected tools item match"); |
| 92 | +} |
| 93 | +if (m.kind === "item") { |
92 | 94 | expect(m.node.kv?.value).toBe("GitHub CLI"); |
93 | 95 | } |
94 | 96 | }); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。