Skip to content

Commit dcd156d

Browse files
committed
🐛 Find what erased the rows, and read the screen where each fact is stated
Three red files from the delivery CI, and what each of them turned out to be. `repl-include-pty` was blamed on the harness. It is not the harness: this host allocates its pty through tmux and reads the pane with tmux's own emulator, so no replay is involved at all. The pane's raw bytes were captured with `pipe-pane` and put through an independent emulator, which produced the same holes — a History rail reading ` ✓` and directions reading `Read for Entry 2`. In the middle of one frame the stream carries `ESC[0G ESC[2K ESC[J`: a progress-line clear that erases the cursor's row and every row beneath it. This renderer writes diffs. It had already written those rows, nothing told it they had gone, and it did not write them again. That sequence appears four times at the head of every such stream, before the command enters the alternate screen, and nowhere in this repository's sources. It is the runtime's own progress writer on the terminal the command owns. The Deno launcher is quiet now, which stops it and says nothing the command itself would have said. The intermittent `repl-repositories-pty` failure is most likely the same thing arriving at a less convenient moment; it is recorded as issue #1007 with both outputs, and a green repeat does not close it. The rest of that file reaches the catalog where the catalog now is — a drawer over the reading, opened by `Entries`, with an entry's scopes as its rows — and the Bindings pane by the name the screen gives it. U6's draft repaint keeps the surface it was always proved on: this suite builds its views without staging a workspace, so the composition it draws is the one that keeps the Draft in the footer at every surface, and the Draft it asked for is there. What was obsolete was the oracle, not the place. The two drafts now differ by a thirty-cell tail rather than by one digit of a hidden-line count, so the newest row really shrinks and the fresh-versus-diff comparison is about erasure; the row's whole allocation is read from the committed map and compared cell for cell including its padding, rather than inferred from the length of a padded label; and the turn control it ends on is proved to be the same turn under a pointer and under the keyboard, not merely the same kind of act. `repl-agent-journey` is partly reconciled: its conversations are behind the Transcript's own selector now, and which one a reading is filtered to is what that selector says rather than a marked row of a column this composition does not draw. Four of its eight pass, from three. The rest are named in the report.
1 parent 552bd15 commit dcd156d

6 files changed

Lines changed: 160 additions & 61 deletions

File tree

‎packages/cli/src/repl/application.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7609,8 +7609,13 @@ function detail(value: Json): readonly string[] {
76097609
* a clip that keeps no remainder. Every row carries the indent the one row had,
76107610
* so a wrapped notice still reads as one thing set in from the drawer's edge. A
76117611
* word wider than the room keeps its own row rather than being cut inside
7612-
* itself: there is no break to use, and half a word says less than a word that
7613-
* runs to the edge.
7612+
* itself: there is no break to use, half a word says less than a word that runs
7613+
* to the edge — and because nothing is ever cut inside a word, no grapheme is
7614+
* divided here at all.
7615+
*
7616+
* Budgeted the way the rest of this module budgets a row: `fitLabel` and
7617+
* `fitLine` beside it count the same units, and the engine-measured, grapheme
7618+
* cutting pass is an Operation that a pure row builder has no way to ask.
76147619
*/
76157620
function sentenceRows(text: string, width: number, indent = " "): readonly string[] {
76167621
const room = width - indent.length;

‎packages/cli/src/sidekick-acp/posix.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@ function closeSocket(socket: Socket): Operation<void> {
6969
* host saw it and the other did not.
7070
*
7171
* So the moment the file came into existence is part of its identity. An
72-
* unchanged file keeps it, and a file created after another was unlinked
73-
* cannot share it. Where a filesystem reports no creation time both readings
74-
* carry the same substitute and this is the pair it always was.
72+
* unchanged file keeps it — measured, two readings of one untouched file agree
73+
* — and a file created after another was unlinked cannot share it. Stricter
74+
* rather than looser: it can only ever leave a name alone, never remove one
75+
* this owner did not publish. Where a filesystem reports no creation time both
76+
* readings carry the same substitute and this is the pair it always was.
7577
*/
7678
function same(a: Stats, b: Stats): boolean {
7779
return a.dev === b.dev && a.ino === b.ino && a.birthtimeMs === b.birthtimeMs;

‎packages/cli/tests/repl-agent-interface.test.ts‎

Lines changed: 85 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -771,15 +771,6 @@ function* painted(
771771
return (yield* drawn(tree, view, renderer)).bytes;
772772
}
773773

774-
/** The row this screen is drawing the draft on. */
775-
function draftRowIn(rows: readonly string[]): string {
776-
const found = rows.find((row) => row.includes(DRAFT_PROMPT));
777-
if (found === undefined) {
778-
throw new Error("the screen is drawing no draft row");
779-
}
780-
return found;
781-
}
782-
783774
/**
784775
* What the draft row is called, which is how this suite finds it.
785776
*
@@ -2445,71 +2436,125 @@ describe("U6 — the Sessions reading is windowed", () => {
24452436
yield* until(session, "all three Prompts being observed", () => observed(session) === 3);
24462437
yield* until(session, "one turn being recorded", () => recorded(session) === 1);
24472438

2448-
// Two drafts whose line counts have different numbers of digits, so the row
2449-
// that says how many lines are hidden gets shorter as the draft does. The
2450-
// draft is the row of this screen whose length changes, and these are two
2451-
// separate facts about it: what the terminal ends up showing, and what this
2452-
// application described for it to show.
2439+
// Two drafts whose newest visible text really shrinks. Two that differed
2440+
// only in how many identical lines they hide would leave the drawn row
2441+
// nearly unchanged and prove no erasure of anything a reader can see: the
2442+
// long tail here is thirty cells the short draft has to take back.
24532443
const standing = onSessions(session);
2454-
const longer = withDraft(standing, "x\n".repeat(1200));
2455-
const shorter = withDraft(standing, "x\n".repeat(999));
2456-
2444+
const LONGER = `${"x\n".repeat(1200)}longer text with removable tail`;
2445+
const SHORTER = `${"x\n".repeat(999)}y`;
2446+
const longer = withDraft(standing, LONGER);
2447+
const shorter = withDraft(standing, SHORTER);
2448+
2449+
// One renderer and one mounted tree for both commits, with nothing
2450+
// clearing, resetting or resizing between them: the second frame is the
2451+
// diff that the first one is the ground for.
24572452
const tree = yield* useReplTree<ReplAction>();
24582453
const renderer = yield* useReplRenderer(NARROW);
24592454
/** Everything written to this one terminal, in order. */
24602455
const written: Uint8Array[] = [];
24612456

24622457
const first = reading(longer, session, NARROW);
2463-
written.push(yield* painted(renderer, tree, first));
2464-
expect(draftRowIn(screenFrom(written))).toContain("[1200 lines]");
2458+
const longFrame = yield* drawn(tree, first, renderer);
2459+
written.push(longFrame.bytes);
2460+
// Read now rather than later: this is the cell the tree is holding, and the
2461+
// next commit replaces it.
2462+
const before = longFrame.cell("footer:input") ?? "";
2463+
expect(before).toContain("[1200 lines]");
2464+
expect(before).toContain("longer text with removable tail");
2465+
const longScreen = screenFrom(written);
24652466

24662467
// The same terminal, drawn again, with nothing clearing it between the two.
2467-
// What comes back is the shorter count and nothing of the longer one.
24682468
const second = reading(shorter, session, NARROW);
2469-
written.push(yield* painted(renderer, tree, second));
2470-
2471-
const after = draftRowIn(screenFrom(written));
2469+
const shortFrame = yield* drawn(tree, second, renderer);
2470+
written.push(shortFrame.bytes);
2471+
const after = shortFrame.cell("footer:input") ?? "";
24722472
expect(after).toContain("[999 lines]");
24732473
expect(after).not.toContain("1200");
2474+
expect(after).not.toContain("removable tail");
2475+
2476+
const shortScreen = screenFrom(written);
2477+
// The two screens really differ, which is what makes the comparison below
2478+
// an assertion about erasure rather than a tautology.
2479+
expect(shortScreen).not.toEqual(longScreen);
24742480

24752481
// Cell for cell, what a renderer that had never drawn the longer reading
24762482
// produces for the shorter one — blanks and all. This is the assertion that
2477-
// discriminates: a row that kept the tail of the count it used to carry
2478-
// reads the same as this one until the two screens are compared.
2483+
// discriminates: a row that kept the tail of what it used to carry reads
2484+
// the same as this one until the two screens are compared.
24792485
const fresh = yield* scoped(function* (): Operation<readonly string[]> {
24802486
const other = yield* useReplRenderer(NARROW);
24812487
const otherTree = yield* useReplTree<ReplAction>();
24822488
return screenFrom([yield* painted(other, otherTree, reading(shorter, session, NARROW))]);
24832489
});
2484-
expect(screenFrom(written)).toEqual(fresh);
2485-
2486-
// And the row this application described is itself a complete row, as wide
2487-
// as the ones around it — the full-width contract the draft shares with
2488-
// every other row of its region, rather than one inherited from whatever
2489-
// draws it.
2490-
const drafted = (yield* describedBy(second)).find((one) => one.key === "footer:input");
2491-
expect(drafted).toBeDefined();
2492-
expect((drafted?.label ?? "").length).toBeGreaterThanOrEqual(NARROW.columns - 2);
2490+
expect(shortScreen).toEqual(fresh);
2491+
2492+
// And the row this application described occupies the whole rectangle the
2493+
// frame gave it. Read from the committed manifest and the copied map rather
2494+
// than from the length of a padded label: what a label says about itself is
2495+
// not where it was placed, and the cells past the text are exactly where a
2496+
// shorter draft would leave old glyphs behind.
2497+
const placed = flatten(shortFrame.committed.manifest.root).filter(
2498+
(box) => box.key === "footer:input",
2499+
);
2500+
// One box for this row in the whole committed tree, so the rectangle below
2501+
// is the row's own allocation and not one of two.
2502+
expect(placed).toHaveLength(1);
2503+
const bounds = shortFrame.boundsOf("footer:input");
2504+
expect(bounds).toBeDefined();
2505+
const box = bounds ?? { x: 0, y: 0, width: 0, height: 0 };
2506+
// Whole cells, which is the only geometry this product draws at all.
2507+
for (const measure of [box.x, box.y, box.width, box.height]) {
2508+
expect(Number.isInteger(measure)).toBe(true);
2509+
}
2510+
expect(box.height).toBe(1);
2511+
const footer = shortFrame.region("footer");
2512+
expect(footer).toBeDefined();
2513+
const inside = footer ?? { x: 0, y: 0, width: 0, height: 0 };
2514+
expect(box.x).toBeGreaterThanOrEqual(inside.x);
2515+
expect(box.y).toBeGreaterThanOrEqual(inside.y);
2516+
expect(box.x + box.width).toBeLessThanOrEqual(inside.x + inside.width);
2517+
expect(box.y + box.height).toBeLessThanOrEqual(inside.y + inside.height);
2518+
/** The cells of this row's own allocation, text and padding alike. */
2519+
const allocated = (rows: readonly string[]): string =>
2520+
(rows[box.y] ?? "").padEnd(box.x + box.width, " ").slice(box.x, box.x + box.width);
2521+
expect(allocated(shortScreen)).toBe(allocated(fresh));
2522+
expect(allocated(shortScreen)).not.toContain("removable tail");
2523+
expect(allocated(longScreen)).not.toBe(allocated(shortScreen));
2524+
// One target for this row, and it is the field itself.
2525+
expect(shortFrame.targetable("footer:input")).toBe(true);
2526+
expect(shortFrame.keys.filter((key) => key === "footer:input")).toHaveLength(1);
24932527

24942528
// The dedicated location is drawn nowhere, and reserves nothing: a draft
24952529
// this long would otherwise be the longest thing on the screen.
24962530
expect((yield* describedBy(second)).filter((one) => one.key.startsWith("location:"))).toEqual(
24972531
[],
24982532
);
2499-
expect(screenFrom(written).some((row) => row.includes("xmd://"))).toBe(false);
2500-
// And the route itself is unchanged: hidden is not dropped.
2533+
expect(shortScreen.some((row) => row.includes("xmd://"))).toBe(false);
2534+
// And the route itself is unchanged: hidden is not dropped, and the whole
2535+
// multiline draft with its authored blank lines is still what it was.
25012536
expect(second.location).toBe(encodeLocation(second.state.route));
2537+
expect(second.state.draft).toBe(SHORTER);
2538+
expect(second.state.route.draft).toBe(SHORTER);
25022539

25032540
// And the screen is still one a person can use: both ways off it, and a
25042541
// control of the reading itself.
2505-
const usable = yield* drawn(tree, second);
25062542
for (const key of ["sessions:heading", "entries:heading"]) {
2507-
expect(usable.targetable(key)).toBe(true);
2543+
expect(shortFrame.targetable(key)).toBe(true);
25082544
}
2509-
const outlet = usable.keys.filter(
2510-
(key) => key.startsWith("sessions:turn:") && usable.targetable(key),
2545+
const outlet = shortFrame.keys.filter(
2546+
(key) => key.startsWith("sessions:turn:") && shortFrame.targetable(key),
25112547
);
25122548
expect(outlet.length).toBeGreaterThan(0);
2549+
2550+
// That control is the one it says it is. A pointer and the keyboard reach
2551+
// the same mounted node, so the two answer with the same action — the same
2552+
// turn, not merely the same kind of act.
2553+
const turn = outlet[0] ?? "";
2554+
const pointer = yield* pointed(tree, shortFrame, turn);
2555+
yield* focusTo(tree, turn);
2556+
expect(keyed(tree)).toBe(turn);
2557+
expect(yield* activate(tree)).toEqual(pointer);
25132558
});
25142559

25152560
it("U6: the first press after a resize moves the window, not the stored number", function* () {

‎packages/cli/tests/repl-agent-journey.test.ts‎

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,6 +1365,10 @@ describe("J2 — three conversations at once, through the terminal", () => {
13651365
// recognized as a conversation control on a sidebar too narrow for a key.
13661366
const digest = (fake.turns[0]?.handle.sessionKey ?? "").split(":")[2] ?? "";
13671367
expect(digest).not.toBe("");
1368+
// The conversations are behind the Transcript's own selector now: one
1369+
// list, and the choices that filter it are shown when the control saying
1370+
// so is activated. Opening it is how a person reaches them.
1371+
yield* click(terminal, "All sessions");
13681372
yield* awaiting("no conversation was ever offered", function* () {
13691373
yield* settled(10);
13701374
return conversationRows(terminal, digest).length > 0;
@@ -1518,6 +1522,10 @@ describe("J2 — a filter and a draft across a resize (#875 R1)", () => {
15181522
// 1. A conversation filter, chosen by pointing at the row it is drawn in.
15191523
const digest = (live.turns[0]?.handle.sessionKey ?? "").split(":")[2] ?? "";
15201524
expect(digest).not.toBe("");
1525+
// The conversations are behind the Transcript's own selector now: one
1526+
// list, and the choices that filter it are shown when the control saying
1527+
// so is activated. Opening it is how a person reaches them.
1528+
yield* click(terminal, "All sessions");
15211529
yield* awaiting("no conversation was ever offered", function* () {
15221530
yield* settled(10);
15231531
return conversationRows(terminal, digest).length > 0;
@@ -1699,6 +1707,10 @@ describe("J2 — what filtering Sessions leaves on the screen (#875 R1)", () =>
16991707

17001708
const digest = (fake.turns[0]?.handle.sessionKey ?? "").split(":")[2] ?? "";
17011709
expect(digest).not.toBe("");
1710+
// The conversations are behind the Transcript's own selector now: one
1711+
// list, and the choices that filter it are shown when the control saying
1712+
// so is activated. Opening it is how a person reaches them.
1713+
yield* click(terminal, "All sessions");
17021714
yield* awaiting("no conversation was ever offered", function* () {
17031715
yield* settled(10);
17041716
return conversationRows(terminal, digest).length > 0;
@@ -2587,22 +2599,35 @@ const SIDEBAR = sidebarWidth({ columns: 160, rows: 36 }) ?? 0;
25872599

25882600
/** The conversation this screen is filtered by, as the route states it. */
25892601
function sessionOf(terminal: Terminal): string | undefined {
2590-
// The conversation the reading is filtered to is the one its own row marks:
2591-
// two columns of focus cue, the list's indent, then the filter's own `>`.
2592-
//
2593-
// Read from inside the sidebar's body, past the accepted two-cell gutter: the
2594-
// gutter is layout that holds no text, so the row begins where the body does
2595-
// rather than where the column does.
2602+
// The conversation this reading is filtered to is what the Transcript's own
2603+
// selector says. There is one list now, and the control that opens its
2604+
// choices carries the name of whichever was chosen — so the filter is read
2605+
// where the screen states it rather than from a marked row of a column this
2606+
// composition does not draw. `All sessions` is the unfiltered reading, which
2607+
// is no conversation at all.
2608+
// Found by the mark that says it opens rather than by the row it is on: a
2609+
// name too long for the title's remaining room is given a row of its own
2610+
// beneath it, and the selector is the only thing in this column wearing that
2611+
// mark either way.
25962612
for (const line of screenOf(terminal)) {
2597-
const column = (line.split("\u2502")[0] ?? "").slice(BODY_GUTTER);
2598-
const match = /^[>\s]\s {2}>\s(\S.*?)\s*$/.exec(column);
2599-
if (match !== null) {
2600-
return match[1];
2613+
const column = (line.split("\u2502")[0] ?? "").trimEnd();
2614+
if (!column.endsWith(SELECTOR_MARK)) {
2615+
continue;
26012616
}
2617+
const label = column
2618+
.slice(0, column.length - SELECTOR_MARK.length)
2619+
.replace(new RegExp(`^\\s*${TRANSCRIPT_TITLE}`), "")
2620+
.trim();
2621+
return label === "" || label === ALL_SESSIONS ? undefined : label;
26022622
}
26032623
return undefined;
26042624
}
26052625

2626+
/** What the staged Transcript calls itself, its selector's mark, and no filter. */
2627+
const TRANSCRIPT_TITLE = "TRANSCRIPT";
2628+
const SELECTOR_MARK = "\u25be";
2629+
const ALL_SESSIONS = "All sessions";
2630+
26062631
/**
26072632
* The conversation rows the Sessions surface offers to filter by, in order.
26082633
*

‎packages/cli/tests/repl-include-pty.test.ts‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ describe("REPL includes through the production source terminal", () => {
215215
yield* scoped(function* () {
216216
const pty = yield* allocate(line([location, ...includes]), home);
217217
yield* showing(pty, "Ready for Entry 3", REACH_MS);
218+
// The catalog is a drawer on this screen: `Entries` is what opens it, and
219+
// the row that selects the first entry is inside it.
220+
yield* click(pty, "Entries");
221+
yield* showing(pty, "1. [ok]", ACT_MS);
218222
yield* click(pty, "1. [ok]");
219223
yield* showing(pty, "First greeting rendered.", ACT_MS);
220224
yield* showing(pty, "External-only rendered.", ACT_MS);
@@ -316,10 +320,11 @@ describe("REPL sequential source owners through a real terminal (#976)", () => {
316320
function* activateKey(pty: Pty, label: string, occurrence = 0): Operation<void> {
317321
for (let step = 0; step < 160; step++) {
318322
const screen = yield* pty.shows();
319-
const matching = screen.filter((line) => {
320-
const at = line.indexOf(label);
321-
return at >= 0 && (!label.startsWith("component ") || at < 36);
322-
});
323+
// Every row holding this label, in the order the screen draws them.
324+
// The catalog is a drawer now rather than a column of its own, so the
325+
// column a row lands in no longer tells its copy from another's: the
326+
// occurrence does.
327+
const matching = screen.filter((line) => line.includes(label));
323328
const row = matching[occurrence];
324329
const focused = label.startsWith("component ")
325330
? row !== undefined && row.slice(0, row.indexOf(label)).includes(">")
@@ -349,18 +354,27 @@ describe("REPL sequential source owners through a real terminal (#976)", () => {
349354
`focus never reached ${label} (${occurrence}): ${JSON.stringify(yield* pty.shows())}`,
350355
);
351356
}
357+
/** Open the Entries catalog, which is a drawer over the reading. */
358+
function* openCatalog(pty: Pty): Operation<void> {
359+
yield* activateKey(pty, "Entries");
360+
yield* showing(pty, "1. [ok]", ACT_MS);
361+
}
352362
function* inspect(pty: Pty): Operation<void> {
353363
for (const [index, expected] of ["first", "second"].entries()) {
364+
// The scopes an entry holds are rows of its catalog, under the entry
365+
// itself — and choosing one closes the drawer, so each pass opens it.
366+
yield* openCatalog(pty);
354367
yield* activateKey(pty, "component OwnerLeaf", index);
355368
yield* showingAcross(pty, '<OwnerWrapper input="first"', ACT_MS);
356369
yield* showingAcross(pty, '<OwnerWrapper input="second"', ACT_MS);
357-
yield* activateKey(pty, "Bindings");
370+
yield* activateKey(pty, "BINDINGS");
358371
yield* activateKey(pty, "answered");
359372
yield* showing(pty, "[close]", ACT_MS);
360373
yield* showing(pty, JSON.stringify(expected), ACT_MS);
361374
yield* pty.type("\x1b");
362375
yield* sleep(150);
363376
}
377+
yield* openCatalog(pty);
364378
yield* activateKey(pty, "1. [ok]");
365379
yield* showing(pty, "first/second", ACT_MS);
366380
for (const name of ["first", "second"]) {

‎packages/test-support/launch.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,15 @@ export function cliRuntime(): "deno" | "bun" | "node" {
3333

3434
export function cliBase(): string[] {
3535
if (Reflect.has(globalThis, "Deno")) {
36-
return [process.execPath, "run", "--allow-all", entry("deno")];
36+
// Quiet, because this runtime writes its own progress to the same terminal
37+
// the command owns. Measured on a pty: `\x1b[0G\x1b[2K\x1b[J` arrived in
38+
// the middle of a full-screen frame, erasing the cursor's row and every row
39+
// below it — the History rail and the directions — and the command's diff
40+
// renderer, which had already written them and was never told, did not
41+
// write them again. The rows came back blank in tmux's own emulator and in
42+
// an independent replay of the same bytes alike. It suppresses nothing the
43+
// command itself says.
44+
return [process.execPath, "run", "--quiet", "--allow-all", entry("deno")];
3745
}
3846
if (Reflect.has(globalThis, "Bun")) {
3947
return [process.execPath, entry("bun")];

0 commit comments

Comments
 (0)