Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/unit/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,14 @@ export function stripAnsi(text: string): string {
return stripTerminalSequences(text);
}

export function getRenderedLine(lines: string[], match: (plain: string) => boolean): string {
export function getRenderedLine(lines: readonly string[], match: (plain: string) => boolean): string {
const line = lines.find((candidate) => match(stripAnsi(candidate)));
assertPresent(line);
expect(line).not.toBe("");
return line;
}

export function getLineContaining(lines: string[], text: string): string {
export function getLineContaining(lines: readonly string[], text: string): string {
const line = lines.find((candidate) => candidate.includes(text));
assertPresent(line);
expect(line).not.toBe("");
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/model-groups-tui.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ const LEFT = "\u001b[D";
const BACKSPACE = "\u007f";
const LEFT_SS3 = "\u001bOD";

function press(c: { handleInput?: (data: string) => void; render?: (width: number) => string[] }, ...inputs: string[]): void {
function press(c: { handleInput?: (data: string) => void; render?: (width: number) => readonly string[] }, ...inputs: string[]): void {
for (const input of inputs) {
c.render?.(100);
c.handleInput?.(input);
Expand All @@ -153,23 +153,23 @@ if (FAKE_CURSOR_PARTS.length !== 2 || FAKE_CURSOR_PARTS[0] === "") {
}
const FAKE_CURSOR_START = FAKE_CURSOR_PARTS[0];

function rendered(c: { render: (width: number) => string[] }, width = 100): string {
function rendered(c: { render: (width: number) => readonly string[] }, width = 100): string {
return c.render(width).join("\n");
}

function findSelectedRow(c: { render: (width: number) => string[] }): string | undefined {
function findSelectedRow(c: { render: (width: number) => readonly string[] }): string | undefined {
return stripAnsi(rendered(c))
.split("\n")
.find((line) => line.includes("→"));
}

function selectedRow(c: { render: (width: number) => string[] }): string {
function selectedRow(c: { render: (width: number) => readonly string[] }): string {
const row = findSelectedRow(c);
assertPresent(row, "the rendered screen has a selected row marked →");
return row;
}

function selectRenderedLabel(c: { handleInput?: (data: string) => void; render: (width: number) => string[] }, label: string): void {
function selectRenderedLabel(c: { handleInput?: (data: string) => void; render: (width: number) => readonly string[] }, label: string): void {
for (let i = 0; i < 32; i++) {
// A screen without a selected row is not this label yet: keep pressing DOWN.
if (findSelectedRow(c)?.includes(label) === true) {
Expand All @@ -192,7 +192,7 @@ function openAddModelWizard(c: Parameters<typeof selectRenderedLabel>[0]): void
press(c, ENTER); // EDITOR → WIZARD_PROVIDER
}

function pressAndRender(c: { handleInput?: (data: string) => void; render: (width: number) => string[] }, ...inputs: string[]): void {
function pressAndRender(c: { handleInput?: (data: string) => void; render: (width: number) => readonly string[] }, ...inputs: string[]): void {
for (const input of inputs) {
c.render(100);
c.handleInput?.(input);
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/render-snapshots.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ const SNAPSHOT_DIR = join(__dirname, "..", "snapshots");
// ── Render test backend ───────────────────────────────────────────────

class RenderTestBackend {
lines: string[] = [];
render(component: { render(w: number): string[] }, width = 80): this {
lines: readonly string[] = [];
render(component: { render(w: number): readonly string[] }, width = 80): this {
this.lines = component.render(width);
return this;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/spawn-render.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ test("collapsed nested spawn render keeps all text blocks from the last assistan
expect(lines).toContainEqual(expect.stringContaining("second"));
});

async function renderCollapsedPreview(text: string, width: number): Promise<string[]> {
async function renderCollapsedPreview(text: string, width: number): Promise<readonly string[]> {
const state = createState();
const childSpawnTool = await makeChildSpawnTool(state);
state.childSessions.set("tool-call-1", createSession([{ role: "assistant", content: [{ type: "text", text }] }]));
Expand Down
Loading