Skip to content
Merged
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
40 changes: 27 additions & 13 deletions packages/cli/tests/repl-wheel-burst.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { expect } from "@executablemd/test-support/expect";
import { scoped, sleep } from "effection";
import type { Operation } from "effection";
import { useReplPage } from "./support/repl-page.ts";
import type { ReplPage, ScreenCell } from "./support/repl-page.ts";
import { composerHolds, intoComposer, paneLines } from "./support/screen-journeys.ts";
import type { ReplPage, ScreenCell, ScreenReading } from "./support/repl-page.ts";
import { draftHolds, intoComposer, intoDraft, paneLines } from "./support/screen-journeys.ts";
import { generateTypingHistory } from "./support/typing-history.ts";

const SIZE = { columns: 160, rows: 36 };
Expand Down Expand Up @@ -52,6 +52,13 @@ function chatRows(page: ReplPage): number[] {
return shown;
}

// The generated TAIL lines the Sidekick chat shows, right of the Draft pane.
function tailLines(reading: ScreenReading): string[] {
return paneLines(reading).flatMap(
(row) => row.slice(row.lastIndexOf("│") + 1).match(/TAIL-(?:LINE|END)-\d+/g) ?? [],
);
}

// A labelled turn row left of the Sidekick pane.
function transcriptCell(page: ReplPage): ScreenCell {
const rows = page.screen().rows;
Expand Down Expand Up @@ -130,28 +137,35 @@ describe("wheel bursts in one input chunk", () => {
});

it("a tick that clears a staged refusal moves the next one within the freed capacity", function* () {
const reason =
"Permission to start was declined because the chosen fixture rejected this request. ";
const request = "Please refuse this request";
const footer = "! Permission to start was declined";
// Each dotted segment is one probed path segment, so each stays within a file name.
const name = ["Unknown", "Missing", "Absent"].map((at) => at + "Component".repeat(27));
const request = `<${name.join(".")} />`;
const footer = "! this entry cannot run here: Cannot resolve component:";
const cell = { column: 140, row: 13 };

function* endpoints(move: typeof burst) {
return yield* scoped(function* () {
const page = yield* useReplPage({ size: SIZE });
yield* generateTypingHistory(page, 2, 80);
yield* intoComposer(page);
// The staged refusal frees more rows than one tick moves when it clears.
page.repl.fake.script({ reply: "", failure: reason.repeat(8) });
// The name alone wraps the staged refusal past the searched paths, which
// vary by platform, so clearing it frees more rows than one tick moves.
yield* intoDraft(page);
yield* page.type(request);
yield* page.until("the request in Message", (one) => composerHolds(one, request));
const drafted = yield* page.until("the unknown component in Draft", (one) =>
draftHolds(one, "/>"),
);
const before = tailLines(drafted);
yield* page.key("Enter");
yield* page.until("the staged refusal", (one) => one.shows(footer));
const start = paneLines(page.screen());
const refused = yield* page.until("the staged refusal", (one) => one.shows(footer));
const start = tailLines(refused);
expect(start.length + 3).toBeLessThan(before.length);

yield* move(page, "up", cell, 2);
expect(page.screen().shows(footer)).toBe(false);
return { start, end: paneLines(page.screen()) };
const end = tailLines(page.screen());
expect(end.length).toBeGreaterThan(start.length);
expect(end[0]).not.toBe(start[0]);
return { start, end };
});
}

Expand Down
Loading