Skip to content

Commit 0c37c83

Browse files
committed
🐛 Press the Sidekick's own Stop, and read what this screen says
Seven recovery and lifecycle journeys were reaching for controls and rows this screen no longer draws where they looked. Both Stops. The entry draft wears one while its entry runs and the Sidekick wears its own, and `[stop]` found anywhere on the screen is the leftmost — the draft's. So M6 stopped nothing it meant to and timed out waiting for a Send, and PV3 stopped the person's entry rather than the generation it was about, which is what left a Promise pending after the case had given up. Both are pressed in the Sidekick's own column now. That column is asked of the size rather than found by the composer, because a composer is one thing it holds and not always the thing on top: the Sidekick's question opens a drawer over that pane, and its Stop is then a control of the drawer. Measured, with both on screen, the draft's was at column 94 and the Sidekick's at 105. Rest is read there too. A Send found anywhere says nothing about whether a generation finished, because the draft has one beside its field whatever the Sidekick is doing. The Sidekick's question announces itself with the control that opens it. The prose naming the agent belongs to the screen this one replaced, and the three MQ tiers waited for it before reaching a single one of their own assertions. And settlement is the rail's. `[ok]` and `1. [ok] entry-1` are catalog rows, and the catalog is a drawer somebody opens; the rail marks every entry this file holds with the state it reached, whether or not one is open. Same boundary, read where this screen puts it. Readers only: no production file is touched, and every functional assertion each tier was making is the one it still makes.
1 parent b767a32 commit 0c37c83

2 files changed

Lines changed: 118 additions & 41 deletions

File tree

‎packages/cli/tests/repl-sidekick-lifecycle.test.ts‎

Lines changed: 107 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,67 @@ import {
5555
MOUNTED_AGENT,
5656
mountedExecution,
5757
mountedReading,
58+
saidByPerson,
59+
saidBySidekick,
5860
sendMessage,
5961
settled,
62+
settledEntry,
6063
panePresented,
64+
screenOf,
65+
rowsShow,
6166
shows,
6267
typing,
6368
useMountedHost,
6469
useMountedRepl,
6570
} from "./fixtures/repl/issue-883/mounted-program.ts";
6671
import type { MountedRepl, Terminal } from "./fixtures/repl/issue-883/mounted-program.ts";
72+
import { workspaceConversationWidth } from "../src/repl/layout.ts";
73+
74+
/**
75+
* Where the Sidekick's own column begins, whatever is drawn over it.
76+
*
77+
* Asked of the size rather than found by the composer. A composer is one thing
78+
* that column holds and it is not always drawn in it: the Sidekick's question
79+
* opens a drawer over that pane, and its own Stop is then a control of the
80+
* drawer rather than a control beside the box. A narrow frame routes one
81+
* outlet, so where the Sidekick is being read the column is the frame.
82+
*/
83+
function sidekickEdge(terminal: Terminal): number {
84+
const width = workspaceConversationWidth(terminal.size);
85+
return width === undefined ? 0 : Math.max(0, terminal.size.columns - width);
86+
}
87+
88+
/**
89+
* The Sidekick's own Stop, pressed where it is.
90+
*
91+
* This screen has two. The entry draft wears one while its entry runs, in the
92+
* centre column, and it is the leftmost — so a press that went looking for
93+
* `[stop]` on the screen stops the document's work and never reaches the
94+
* generation it meant to. Measured: with both on screen the draft's was at
95+
* column 94 and the Sidekick's at 105.
96+
*/
97+
function* stopSidekick(terminal: Terminal): Operation<void> {
98+
yield* click(terminal, "[stop]", sidekickEdge(terminal));
99+
}
100+
101+
/**
102+
* Whether the Sidekick is at rest: its own Send offered, its own Stop gone.
103+
*
104+
* Both asked of its column. The entry draft has a Send beside its field and it
105+
* is there whatever the Sidekick is doing, so a Send found anywhere on the
106+
* screen says nothing about whether this generation has finished.
107+
*/
108+
function sidekickIdle(terminal: Terminal): boolean {
109+
const pane = sidekickRows(terminal);
110+
return rowsShow(pane, "[send]") && !rowsShow(pane, "[stop]");
111+
}
112+
113+
/** That column's own rows, which is where its controls are read. */
114+
function sidekickRows(terminal: Terminal): readonly string[] {
115+
const from = sidekickEdge(terminal);
116+
return screenOf(terminal).map((line) => line.slice(from));
117+
}
118+
67119
import {
68120
ENTRIES_FILE,
69121
PAIRED_DIRECTORY,
@@ -888,12 +940,12 @@ describe("Tier R6 — Stop, pressed on the screen", () => {
888940
yield* awaiting(repl.terminal, "the entry's output arriving", (one) =>
889941
shows(one, "the entry kept running"),
890942
);
891-
expect(shows(repl.terminal, "[stop]")).toBe(true);
943+
expect(rowsShow(sidekickRows(repl.terminal), "[stop]")).toBe(true);
892944

893-
// Stop, through its own control.
894-
yield* click(repl.terminal, "[stop]");
945+
// Stop, through its own control — the Sidekick's, in the pane that owns it.
946+
yield* stopSidekick(repl.terminal);
895947
yield* awaiting(repl.terminal, "Stop joining and the Sidekick coming to rest", (one) =>
896-
shows(one, "[send]"),
948+
sidekickIdle(one),
897949
);
898950

899951
// No turn followed. One message, one turn: whatever the entry does later,
@@ -922,21 +974,24 @@ describe("Tier R6 — Stop, pressed on the screen", () => {
922974
).toEqual(["REPL.Submit"]);
923975
// The chat a person was reading is still there, and so is the draft the
924976
// reply filled.
925-
expect(shows(repl.terminal, "you: run it")).toBe(true);
977+
expect(saidByPerson(repl.terminal, "run it")).toBe(true);
926978
expect(draftText(repl.terminal)).toBe("");
927979

928980
// The entry was never among what came down: it is still running, and it
929981
// settles when its own record lands rather than when Stop said so.
930982
expect(stopped.model.entries.map((entry) => entry.terminal)).toEqual([undefined]);
931983
closing.release();
932-
yield* awaiting(repl.terminal, "the entry settling on its own", (one) => shows(one, "[ok]"));
984+
// Settled, read from the History rail, which marks every entry this file
985+
// holds with the state it reached. `[ok]` is a catalog row, and the catalog
986+
// is a drawer nobody opened here.
987+
yield* settledEntry(repl.terminal, 1, "ok");
933988

934989
// And a later explicit message is possible: Stop ended the asking, not the
935990
// conversation.
936991
repl.fake.script({ reply: "<Output>Still here.</Output>\n" });
937992
yield* sendMessage(repl, "again");
938993
yield* awaiting(repl.terminal, "the next message being answered", (one) =>
939-
shows(one, `${MOUNTED_AGENT}: Still here.`),
994+
saidBySidekick(one, "Still here."),
940995
);
941996
expect(repl.fake.prompts).toHaveLength(2);
942997
});
@@ -951,15 +1006,17 @@ describe("Tier R6 — Stop, pressed on the screen", () => {
9511006

9521007
yield* sendMessage(repl, "stop me");
9531008
yield* repl.fake.holdingTurns(1);
954-
yield* click(repl.terminal, "[stop]");
1009+
yield* stopSidekick(repl.terminal);
9551010
yield* cancelling.reached;
9561011

9571012
// Stop is inside the teardown it asked for. The row still says the Sidekick
9581013
// is working, and there is no Send to start a successor with — a screen
9591014
// that offered one here would be claiming the Sidekick had stopped while it
960-
// was still unwinding.
961-
expect(shows(repl.terminal, "[stop]")).toBe(true);
962-
expect(shows(repl.terminal, "[send]")).toBe(false);
1015+
// was still unwinding. Asked of that pane: the entry draft has a Send of
1016+
// its own beside its field, and it is there whatever the Sidekick is doing.
1017+
const paneNow = sidekickRows(repl.terminal);
1018+
expect(rowsShow(paneNow, "[stop]")).toBe(true);
1019+
expect(rowsShow(paneNow, "[send]")).toBe(false);
9631020
expect(repl.fake.prompts).toHaveLength(1);
9641021

9651022
// And ordinary typing still works, because the join is on the screen's own
@@ -970,7 +1027,7 @@ describe("Tier R6 — Stop, pressed on the screen", () => {
9701027

9711028
cancelling.release();
9721029
yield* awaiting(repl.terminal, "Stop returning once its cleanup joined", (one) =>
973-
shows(one, "[send]"),
1030+
sidekickIdle(one),
9741031
);
9751032
expect(draftText(repl.terminal)).toBe("meanwhile");
9761033
expect(repl.fake.prompts).toHaveLength(1);
@@ -1089,7 +1146,11 @@ describe("Tier PV — generation that ended without a reply", () => {
10891146
// Stopped, with the provider's own cancellation held: this is what says
10901147
// Stop joined what it asked for rather than returning over the top of it.
10911148
const cancelling = repl.fake.holdCancellation();
1092-
yield* click(repl.terminal, "[stop]");
1149+
// The Sidekick's own Stop. This person's entry is running, so the draft is
1150+
// wearing a Stop too — and it is the leftmost, so a press that went looking
1151+
// for `[stop]` on the screen would stop the document's work and never reach
1152+
// the generation this row is about.
1153+
yield* stopSidekick(repl.terminal);
10931154
yield* cancelling.reached;
10941155
expect(repl.outcome()).toBe(undefined);
10951156
cancelling.release();
@@ -1123,7 +1184,7 @@ describe("Tier PV — generation that ended without a reply", () => {
11231184
host,
11241185
location: `xmd://repl/${execution}/entries`,
11251186
});
1126-
yield* awaiting(again.terminal, "the reopened chat", (one) => shows(one, "you: try it"));
1187+
yield* awaiting(again.terminal, "the reopened chat", (one) => saidByPerson(one, "try it"));
11271188
expect(shows(again.terminal, "(unfinished)")).toBe(false);
11281189
expect(shows(again.terminal, "As far as I")).toBe(false);
11291190
});
@@ -1147,8 +1208,8 @@ describe("Tier PV — generation that ended without a reply", () => {
11471208
repl.fake.script({ held: true, reply: "<Output>Unrecorded.</Output>\n" });
11481209
yield* sendMessage(repl, "unrecorded");
11491210
yield* repl.fake.holdingTurns(1);
1150-
yield* click(repl.terminal, "[stop]");
1151-
yield* awaiting(repl.terminal, "Stop finishing", (one) => shows(one, "[send]"));
1211+
yield* stopSidekick(repl.terminal);
1212+
yield* awaiting(repl.terminal, "Stop finishing", (one) => sidekickIdle(one));
11521213
const execution = yield* mountedExecution(repl);
11531214
yield* click(repl.terminal, "[exit]");
11541215
yield* awaited("the first command closing", () => repl.outcome() !== undefined);
@@ -1158,9 +1219,9 @@ describe("Tier PV — generation that ended without a reply", () => {
11581219
repl.fake.script({ reply: "<Output>First reply.</Output>\n" });
11591220
yield* sendMessage(repl, "saved");
11601221
yield* awaiting(repl.terminal, "the successful predecessor", (one) =>
1161-
shows(one, `${MOUNTED_AGENT}: First reply.`),
1222+
saidBySidekick(one, "First reply."),
11621223
);
1163-
yield* awaiting(repl.terminal, "the box being ready again", (one) => shows(one, "[send]"));
1224+
yield* awaiting(repl.terminal, "the box being ready again", (one) => sidekickIdle(one));
11641225
// Which response that reply was recorded as, and which turn it actually
11651226
// ran as — read out of the history the command wrote.
11661227
const preceding = (yield* mountedReading(repl)).chat.flatMap((record) =>
@@ -1365,7 +1426,10 @@ describe("Tier MQ — a Sidekick question, filled in and answered on the screen"
13651426
yield* typing(repl.terminal, "later");
13661427

13671428
yield* awaiting(repl.terminal, "the question announcing itself", (one) =>
1368-
shows(one, `${MOUNTED_AGENT} has a question.`),
1429+
// The notice this screen gives: the control that opens the question, in
1430+
// the pane that owns it. The prose naming the agent belongs to the
1431+
// screen this one replaced.
1432+
shows(one, "[answer sidekick]"),
13691433
);
13701434
yield* click(repl.terminal, "[answer sidekick]");
13711435
yield* awaiting(repl.terminal, "the form opening", (one) => shows(one, "[submit]"));
@@ -1399,7 +1463,7 @@ describe("Tier MQ — a Sidekick question, filled in and answered on the screen"
13991463
);
14001464
yield* activate(repl.terminal, "Sidekick");
14011465
yield* awaiting(repl.terminal, "the notice still in the pane", (one) =>
1402-
shows(one, `${MOUNTED_AGENT} has a question.`),
1466+
shows(one, "[answer sidekick]"),
14031467
);
14041468
yield* click(repl.terminal, "[answer sidekick]");
14051469
yield* awaiting(repl.terminal, "the form reopening", (one) => shows(one, "[submit]"));
@@ -1416,7 +1480,7 @@ describe("Tier MQ — a Sidekick question, filled in and answered on the screen"
14161480
yield* click(repl.terminal, "[submit]");
14171481

14181482
yield* awaiting(repl.terminal, "the reply answering once the question was", (one) =>
1419-
shows(one, `${MOUNTED_AGENT}: Thanks for deciding.`),
1483+
saidBySidekick(one, "Thanks for deciding."),
14201484
);
14211485
// The form and its way in are both gone, because the question is.
14221486
expect(shows(repl.terminal, "[submit]")).toBe(false);
@@ -1531,7 +1595,10 @@ describe("Tier MQ — two questions, two answers, and Stop", () => {
15311595

15321596
yield* sendMessage(repl, "go on?");
15331597
yield* awaiting(repl.terminal, "the Sidekick's question announcing itself", (one) =>
1534-
shows(one, `${MOUNTED_AGENT} has a question.`),
1598+
// The notice this screen gives: the control that opens the question, in
1599+
// the pane that owns it. The prose naming the agent belongs to the
1600+
// screen this one replaced.
1601+
shows(one, "[answer sidekick]"),
15351602
);
15361603

15371604
// The Sidekick's own, opened from its own pane and answered through its own
@@ -1544,7 +1611,7 @@ describe("Tier MQ — two questions, two answers, and Stop", () => {
15441611
repl.terminal.feed("\r");
15451612

15461613
yield* awaiting(repl.terminal, "the reply hearing it", (one) =>
1547-
shows(one, `${MOUNTED_AGENT}: Sidekick heard yes.`),
1614+
saidBySidekick(one, "Sidekick heard yes."),
15481615
);
15491616

15501617
// The entry's question is untouched: still waiting, still its own. Read
@@ -1586,7 +1653,10 @@ describe("Tier MQ — two questions, two answers, and Stop", () => {
15861653

15871654
yield* sendMessage(repl, "go on?");
15881655
yield* awaiting(repl.terminal, "the Sidekick's question announcing itself", (one) =>
1589-
shows(one, `${MOUNTED_AGENT} has a question.`),
1656+
// The notice this screen gives: the control that opens the question, in
1657+
// the pane that owns it. The prose naming the agent belongs to the
1658+
// screen this one replaced.
1659+
shows(one, "[answer sidekick]"),
15901660
);
15911661
// Open, and half filled in, so Stop is reaching a form somebody is using.
15921662
yield* click(repl.terminal, "[answer sidekick]");
@@ -1595,12 +1665,12 @@ describe("Tier MQ — two questions, two answers, and Stop", () => {
15951665

15961666
// Stop, through its own control. The form was open; it goes without an
15971667
// answer.
1598-
yield* click(repl.terminal, "[stop]");
1668+
yield* stopSidekick(repl.terminal);
15991669
yield* awaiting(repl.terminal, "Stop joining and the Sidekick coming to rest", (one) =>
1600-
shows(one, "[send]"),
1670+
sidekickIdle(one),
16011671
);
16021672
expect(shows(repl.terminal, "Shall I go on?")).toBe(false);
1603-
expect(shows(repl.terminal, `${MOUNTED_AGENT} has a question.`)).toBe(false);
1673+
expect(shows(repl.terminal, "[answer sidekick]")).toBe(false);
16041674

16051675
// Nothing was answered and nothing followed: the intent stands with no
16061676
// outcome beside it, which is what an interrupted question is.
@@ -1634,7 +1704,10 @@ describe("Tier MQ — two questions, two answers, and Stop", () => {
16341704
repl.fake.script({ reply: asks(SIDEKICK_ASKS, "Asking again.") });
16351705
yield* sendMessage(repl, "ask again");
16361706
yield* awaiting(repl.terminal, "the next question announcing itself", (one) =>
1637-
shows(one, `${MOUNTED_AGENT} has a question.`),
1707+
// The notice this screen gives: the control that opens the question, in
1708+
// the pane that owns it. The prose naming the agent belongs to the
1709+
// screen this one replaced.
1710+
shows(one, "[answer sidekick]"),
16381711
);
16391712
yield* click(repl.terminal, "[answer sidekick]");
16401713
yield* awaiting(repl.terminal, "the new form", (one) => shows(one, "Asking again."));
@@ -1692,7 +1765,10 @@ describe("Tier MQ — leaving with questions pending, and the cold reopen after"
16921765
// And the Sidekick's, opened and half filled in.
16931766
yield* sendMessage(repl, "shall you?");
16941767
yield* awaiting(repl.terminal, "the Sidekick's question announcing itself", (one) =>
1695-
shows(one, `${MOUNTED_AGENT} has a question.`),
1768+
// The notice this screen gives: the control that opens the question, in
1769+
// the pane that owns it. The prose naming the agent belongs to the
1770+
// screen this one replaced.
1771+
shows(one, "[answer sidekick]"),
16961772
);
16971773
yield* click(repl.terminal, "[answer sidekick]");
16981774
yield* awaiting(repl.terminal, "the form opening", (one) => shows(one, "Shall I?"));
@@ -1739,12 +1815,11 @@ describe("Tier MQ — leaving with questions pending, and the cold reopen after"
17391815
host,
17401816
location: `xmd://repl/${execution}/entries`,
17411817
});
1742-
expect(shows(again.terminal, `${MOUNTED_AGENT} has a question.`)).toBe(false);
17431818
expect(shows(again.terminal, "[answer sidekick]")).toBe(false);
17441819
expect(shows(again.terminal, "Shall I?")).toBe(false);
17451820
expect(shows(again.terminal, "[close]")).toBe(false);
17461821
// And the chat it does project holds what the stopped process wrote.
1747-
expect(shows(again.terminal, "you: shall you?")).toBe(true);
1822+
expect(saidByPerson(again.terminal, "shall you?")).toBe(true);
17481823
expect(host.fake.ensured).toHaveLength(before.ensured);
17491824
expect(host.fake.prompts).toHaveLength(before.prompts);
17501825
}
@@ -1861,7 +1936,7 @@ describe("Tier CFG — a preference being written when the command leaves", () =
18611936
yield* configure(repl);
18621937
yield* awaiting(repl.terminal, "the advertised models", (one) => shows(one, "Fast"));
18631938
yield* click(repl.terminal, "[close]", 96);
1864-
yield* awaiting(repl.terminal, "the pane again", (one) => shows(one, "[send]"));
1939+
yield* awaiting(repl.terminal, "the pane again", (one) => sidekickIdle(one));
18651940

18661941
// Somebody else's record held inside the host, so the writer is occupied
18671942
// by an append that is not this save's.

‎packages/cli/tests/repl-sidekick-recovery.test.ts‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ import {
7878
click,
7979
focusDraft,
8080
operationGate,
81+
settledEntry,
8182
shows,
8283
typing,
8384
useMountedRepl,
@@ -2188,12 +2189,12 @@ describe("Tier HI — a reopening reconciles against the acknowledged history",
21882189
yield* awaiting(repl.terminal, "the ordinary entry printing", (one) =>
21892190
shows(one, "an ordinary entry"),
21902191
);
2191-
// Settled, not merely printed: the catalog says so once the entry's
2192-
// outcome is in the journal, which is the boundary the reads below need.
2193-
const settledRow = `${row.entriesWhenFound.length + 1}. [ok]`;
2194-
yield* awaiting(repl.terminal, `the catalog showing ${settledRow}`, (one) =>
2195-
shows(one, settledRow),
2196-
);
2192+
// Settled, not merely printed: the boundary the reads below need is the
2193+
// entry's outcome being in the journal. Read from the History rail,
2194+
// which marks every entry this file holds with the state it reached —
2195+
// the catalog spells the same fact `[ok]`, and the catalog is a drawer
2196+
// nobody opened here.
2197+
yield* settledEntry(repl.terminal, row.entriesWhenFound.length + 1, "ok");
21972198

21982199
// The successor took the next slot with its own source, the finding was
21992200
// not written twice, and the reserved work was neither resubmitted nor
@@ -2605,9 +2606,10 @@ describe("975 — placement survives cold Submit reconciliation", () => {
26052606
yield* scoped(function* () {
26062607
const repl = yield* useMountedRepl({ host, location: coldLocation });
26072608
yield* awaited("the second cold continuation", () => observed.length === 3);
2608-
yield* awaiting(repl.terminal, "the continued suffix", (one) =>
2609-
shows(one, "1. [ok] entry-1"),
2610-
);
2609+
// The reserved entry ran and settled here, read from the History rail.
2610+
// `1. [ok] entry-1` is a catalog row, and the catalog is a drawer
2611+
// nobody opened in this reading.
2612+
yield* settledEntry(repl.terminal, 1, "ok");
26112613
expect(observed.at(-1)).toBe(where);
26122614
expect(yield* until(readFile(join(where, "suffix.md"), "utf8"))).toBe("continued");
26132615
expect(yield* cwd()).toBe(project);

0 commit comments

Comments
 (0)