|
3 | 3 | * copy the transcript child list to find the open row. |
4 | 4 | */ |
5 | 5 | import { describe, expect, test } from "bun:test"; |
6 | | -import { CodeRenderable, type BaseRenderable } from "@opentui/core"; |
| 6 | +import { |
| 7 | + CodeRenderable, |
| 8 | + MarkdownRenderable, |
| 9 | + type BaseRenderable, |
| 10 | +} from "@opentui/core"; |
7 | 11 | import { withTestRenderer } from "./harness"; |
8 | 12 | import { codeLinkArmWalks } from "./code-links"; |
9 | 13 | import { appendStreamRow, replaceStreamRowAt } from "./shell/chrome"; |
@@ -147,4 +151,59 @@ describe("streaming retext work", () => { |
147 | 151 | { width: 80, height: 24 }, |
148 | 152 | ); |
149 | 153 | }); |
| 154 | + |
| 155 | + test("a fence added under a stable list still arms that code node", async () => { |
| 156 | + await withTestRenderer( |
| 157 | + async (h) => { |
| 158 | + const shell = createAppShell(h.renderer, SHELL_OPTS); |
| 159 | + try { |
| 160 | + appendStreamRow(shell, { |
| 161 | + role: "assistant", |
| 162 | + streaming: true, |
| 163 | + text: "- intro", |
| 164 | + }); |
| 165 | + await h.renderOnce(); |
| 166 | + const row = transcriptRowChildren(shell)[0]; |
| 167 | + if (row === undefined) throw new Error("row missing"); |
| 168 | + const markdown = row |
| 169 | + .getChildren() |
| 170 | + .find((child) => child instanceof MarkdownRenderable); |
| 171 | + if (!(markdown instanceof MarkdownRenderable)) { |
| 172 | + throw new Error("markdown missing"); |
| 173 | + } |
| 174 | + // OpenTUI keeps one list box and inserts the fence under it. The |
| 175 | + // first retext arms that box; the fence must still be walked. |
| 176 | + markdown.internalBlockMode = "top-level"; |
| 177 | + replaceStreamRowAt(shell, 0, { |
| 178 | + role: "assistant", |
| 179 | + streaming: true, |
| 180 | + text: "- intro", |
| 181 | + }); |
| 182 | + const list = markdown.getChildren()[0]; |
| 183 | + if (list === undefined || list instanceof CodeRenderable) { |
| 184 | + throw new Error("list box missing"); |
| 185 | + } |
| 186 | + const before = codeLinkArmWalks(); |
| 187 | + replaceStreamRowAt(shell, 0, { |
| 188 | + role: "assistant", |
| 189 | + streaming: true, |
| 190 | + text: "- intro\n\n ```\n https://example.com\n ```", |
| 191 | + }); |
| 192 | + expect(markdown.getChildren()[0]).toBe(list); |
| 193 | + const codes = codeNodes(row); |
| 194 | + const fence = codes.find( |
| 195 | + (code) => |
| 196 | + code.onChunks === undefined || code.filetype !== "markdown", |
| 197 | + ); |
| 198 | + expect(fence).toBeDefined(); |
| 199 | + expect(fence?.onChunks).toBeDefined(); |
| 200 | + expect(fence?.onHighlight).toBeDefined(); |
| 201 | + expect(codeLinkArmWalks()).toBeGreaterThan(before); |
| 202 | + } finally { |
| 203 | + shell.dispose(); |
| 204 | + } |
| 205 | + }, |
| 206 | + { width: 80, height: 24 }, |
| 207 | + ); |
| 208 | + }); |
150 | 209 | }); |
0 commit comments