mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-06 05:51:15 +08:00
test: guard oc-path null results
This commit is contained in:
@@ -87,19 +87,19 @@ describe("resolveJsonlToUniversal — file-relative line metadata (regression)",
|
||||
it("resolves L2/event with line=2 (not 1)", () => {
|
||||
const { ast } = parseJsonl(log);
|
||||
const m = resolveOcPath(ast, parseOcPath("oc://session.jsonl/L2/event"));
|
||||
expect(m).not.toBeNull();
|
||||
if (m !== null) {
|
||||
expect(m.line).toBe(2);
|
||||
if (m === null) {
|
||||
throw new Error("expected L2/event match");
|
||||
}
|
||||
expect(m.line).toBe(2);
|
||||
});
|
||||
|
||||
it("resolves L4/event with line=4", () => {
|
||||
const { ast } = parseJsonl(log);
|
||||
const m = resolveOcPath(ast, parseOcPath("oc://session.jsonl/L4/event"));
|
||||
expect(m).not.toBeNull();
|
||||
if (m !== null) {
|
||||
expect(m.line).toBe(4);
|
||||
if (m === null) {
|
||||
throw new Error("expected L4/event match");
|
||||
}
|
||||
expect(m.line).toBe(4);
|
||||
});
|
||||
|
||||
it("findOcPaths over wildcard surfaces correct file-relative lines", () => {
|
||||
|
||||
@@ -126,7 +126,9 @@ describe("cross-cutting", () => {
|
||||
];
|
||||
for (const path of cases) {
|
||||
const m = resolveOcPath(ast, path);
|
||||
expect(m, `failed for ${JSON.stringify(path)}`).not.toBeNull();
|
||||
if (m === null) {
|
||||
throw new Error(`failed for ${JSON.stringify(path)}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -15,8 +15,10 @@ function rt(raw: string): string {
|
||||
*/
|
||||
function assertParseable(raw: string): JsoncValue {
|
||||
const result = parseJsonc(raw);
|
||||
expect(result.ast.root).not.toBeNull();
|
||||
return result.ast.root as JsoncValue;
|
||||
if (result.ast.root === null) {
|
||||
throw new Error("expected parseable JSONC root");
|
||||
}
|
||||
return result.ast.root;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -87,8 +87,10 @@ describe("oc-path-resolver-edges", () => {
|
||||
section: "tools",
|
||||
item: "gh",
|
||||
});
|
||||
expect(m).not.toBeNull();
|
||||
if (m?.kind === "item") {
|
||||
if (m === null) {
|
||||
throw new Error("expected tools item match");
|
||||
}
|
||||
if (m.kind === "item") {
|
||||
expect(m.node.kv?.value).toBe("GitHub CLI");
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user