test: guard oc-path null results

This commit is contained in:
Peter Steinberger
2026-05-11 21:26:58 +01:00
parent c6668deb44
commit 07f4b7130f
4 changed files with 17 additions and 11 deletions

View File

@@ -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", () => {

View File

@@ -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)}`);
}
}
});
});

View File

@@ -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;
}
/**

View File

@@ -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");
}
});