fix(ui): exclude null part from OpenCode JSONL detection

Greptile flagged that `record.part !== undefined` also accepts
`part: null` (null !== undefined is true), so arbitrary JSON like
{"type":"text","part":null} would lock the parser onto the OpenCode
path. Real OpenCode events always carry a sessionID string or a non-null
part payload, so tighten the guard and add a regression test.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Jannes StubbemannandClaude Fable 5 committed 2026-07-04 20:01:15 +02:00
1 parent cdacb6b5bd
commit 15663725bb
2 files changed
+15 -2

No files matched your search

@@ -61,6 +61,18 @@ describe("process adapter transcript parsing (OpenCode JSONL detection)", () =>
expect(stdoutTexts.some((t) => t.includes('"type"'))).toBe(false);
});
it("does not lock on for JSON with a matching type but a null part", () => {
const chunks: RunLogChunk[] = [
{
ts,
stream: "stdout",
chunk: JSON.stringify({ type: "text", part: null }) + "\n" + "still plain\n",
},
];
const entries = buildTranscript(chunks, processUIAdapter);
expect(entries.every((e) => e.kind === "stdout")).toBe(true);
});
it("leaves genuinely non-JSONL process output as raw stdout", () => {
const chunks: RunLogChunk[] = [
{ ts, stream: "stdout", chunk: "plain line one\nplain line two\n" },
+3 -2
View File
@@ -26,8 +26,9 @@ function isOpenCodeJsonlLine(line: string): boolean {
const record = parsed as Record<string, unknown>;
if (typeof record.type !== "string" || !OPENCODE_EVENT_TYPES.has(record.type)) return false;
// Guard against arbitrary JSON that merely happens to carry a matching `type`:
// real OpenCode events always carry a `sessionID` string or a `part` payload.
return typeof record.sessionID === "string" || record.part !== undefined;
// real OpenCode events always carry a `sessionID` string or a non-null `part`
// payload (`part: null` is not a real OpenCode shape, so don't lock on for it).
return typeof record.sessionID === "string" || (record.part !== undefined && record.part !== null);
}
/**