Skip to content

Commit f186281

Browse files
test(web): cover configured ghostty scrollback
The direct ABI regression proves Ghostty retention behavior but supplies its own byte budget, so it cannot catch a regression in the app constructor. Exercise the real GhosttyTerminalCore creation and write path with a smaller 1,200-line case, while preserving the direct ABI coverage. Generated with GPT-5.6-Sol via Codex harness.
1 parent 2c4734c commit f186281

2 files changed

Lines changed: 66 additions & 2 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// @effect-diagnostics nodeBuiltinImport:off -- exercises the checked-in WASM artifacts.
2+
import * as NodeFS from "node:fs";
3+
import * as NodeURL from "node:url";
4+
5+
import { afterEach, describe, expect, it, vi } from "vite-plus/test";
6+
7+
import { GhosttyTerminalCore, type GhosttyTheme } from "./core";
8+
9+
vi.mock("./vendor/ghostty-vt.wasm?url", () => ({ default: "test://ghostty-vt.wasm" }));
10+
vi.mock("./vendor/ghostty-write-pty.wasm?url&no-inline", () => ({
11+
default: "test://ghostty-write-pty.wasm",
12+
}));
13+
14+
const testTheme: GhosttyTheme = {
15+
foreground: { r: 255, g: 255, b: 255 },
16+
background: { r: 0, g: 0, b: 0 },
17+
cursor: { r: 255, g: 255, b: 255 },
18+
};
19+
20+
const wasmPaths = {
21+
"ghostty-vt.wasm": NodeURL.fileURLToPath(new URL("./vendor/ghostty-vt.wasm", import.meta.url)),
22+
"ghostty-write-pty.wasm": NodeURL.fileURLToPath(
23+
new URL("./vendor/ghostty-write-pty.wasm", import.meta.url),
24+
),
25+
} as const;
26+
27+
async function serveVendoredWasm(input: string | URL | Request): Promise<Response> {
28+
const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
29+
const filename = Object.keys(wasmPaths).find((candidate) => url.includes(candidate));
30+
if (!filename) return new Response(null, { status: 404 });
31+
32+
const bytes = NodeFS.readFileSync(wasmPaths[filename as keyof typeof wasmPaths]);
33+
return new Response(Uint8Array.from(bytes).buffer);
34+
}
35+
36+
describe("GhosttyTerminalCore", () => {
37+
afterEach(() => vi.unstubAllGlobals());
38+
39+
it("retains history through the app's configured scrollback budget", async () => {
40+
vi.stubGlobal("fetch", serveVendoredWasm);
41+
const core = await GhosttyTerminalCore.create(80, 10, 8, 16, testTheme, () => {});
42+
43+
try {
44+
core.write(Array.from({ length: 1_200 }, (_, index) => `${index + 1}\r\n`).join(""));
45+
const scrollbar = core.scrollbarState();
46+
if (!scrollbar) throw new Error("libghostty-vt did not return scrollbar state");
47+
48+
// This scenario retained only 602 rows with the previous 10,000-byte
49+
// configuration. The byte budget does not promise an exact row count.
50+
expect(scrollbar.total - scrollbar.len).toBeGreaterThan(1_000);
51+
} finally {
52+
core.dispose();
53+
}
54+
});
55+
});

‎apps/web/src/terminal/ghostty/runtimeAbi.test.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1+
// @effect-diagnostics nodeBuiltinImport:off -- exercises the checked-in WASM artifacts.
2+
import * as NodeFS from "node:fs";
3+
import * as NodeURL from "node:url";
4+
15
import { describe, expect, it } from "vite-plus/test";
26

3-
import wasmDataUrl from "./vendor/ghostty-vt.wasm?inline";
4-
import writePtyWasmDataUrl from "./vendor/ghostty-write-pty.wasm?inline";
57
import pinnedVersion from "../../../../../native/libghostty-vt/VERSION?raw";
68
import { ghosttyKeyForCode } from "./keyCodes";
79

810
type WasmFunction = (...args: number[]) => number;
911

12+
const wasmDataUrl = `data:application/wasm;base64,${NodeFS.readFileSync(
13+
NodeURL.fileURLToPath(new URL("./vendor/ghostty-vt.wasm", import.meta.url)),
14+
).toString("base64")}`;
15+
const writePtyWasmDataUrl = `data:application/wasm;base64,${NodeFS.readFileSync(
16+
NodeURL.fileURLToPath(new URL("./vendor/ghostty-write-pty.wasm", import.meta.url)),
17+
).toString("base64")}`;
18+
1019
function decodeWasmDataUrl(dataUrl: string): Uint8Array {
1120
const encoded = dataUrl.split(",", 2)[1];
1221
if (!encoded) throw new Error("The vendored Ghostty WASM data URL is invalid");

0 commit comments

Comments
 (0)