Skip to content

Commit 2036b7c

Browse files
authored
Restack journal migration #1379 on main (#1379)
1 parent d84d1cc commit 2036b7c

6 files changed

Lines changed: 112 additions & 30 deletions

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

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
* at once. Nothing here substitutes a bare `<Prompt>` for that.
1616
*/
1717

18-
import { beforeAll, describe, it } from "@executablemd/test-support/bdd";
18+
import { beforeAll, beforeEach, describe, it } from "@executablemd/test-support/bdd";
19+
import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal";
1920
import { expect } from "@executablemd/test-support/expect";
2021
import {
2122
all,
@@ -2068,9 +2069,13 @@ function resequenced(events: readonly DurableEvent[], sequence: number): Durable
20682069

20692070
describe("EA1 — one chronology of entries, each counting its own Prompts", () => {
20702071
beforeAll(() => useTempFileCompiler());
2072+
beforeEach(journalBeforeEach(OWNER));
20712073

20722074
it("EA1: two entries each retain sequence 0, ordered by entry and then sequence", function* () {
2073-
const holder = execution();
2075+
const holder: ReplExecution = {
2076+
id: "agent-kernel",
2077+
stream: yield* useJournalStream(INLINE_SOURCE_PATH),
2078+
};
20742079
const stub = createStub();
20752080
yield* scoped(function* () {
20762081
yield* useStub(stub);
@@ -2097,7 +2102,10 @@ describe("EA1 — one chronology of entries, each counting its own Prompts", ()
20972102
});
20982103

20992104
it("EA1: two prompts in one entry claiming one sequence refuse the whole projection", function* () {
2100-
const holder = execution();
2105+
const holder: ReplExecution = {
2106+
id: "agent-kernel",
2107+
stream: yield* useJournalStream(INLINE_SOURCE_PATH),
2108+
};
21012109
const stub = createStub();
21022110
yield* scoped(function* () {
21032111
yield* useStub(stub);
@@ -2115,7 +2123,10 @@ describe("EA1 — one chronology of entries, each counting its own Prompts", ()
21152123
});
21162124

21172125
it("EA1: a live turn carries the entry that began it, and keeps it on publication", function* () {
2118-
const holder = execution();
2126+
const holder: ReplExecution = {
2127+
id: "agent-kernel",
2128+
stream: yield* useJournalStream(INLINE_SOURCE_PATH),
2129+
};
21192130
const stub = createStub({ one: { gated: true }, two: { gated: true } });
21202131
yield* scoped(function* () {
21212132
yield* useStub(stub);
@@ -2169,7 +2180,10 @@ describe("EA1 — one chronology of entries, each counting its own Prompts", ()
21692180
});
21702181

21712182
it("EA1: one conversation spans two entries, and naming an entry does not narrow it", function* () {
2172-
const holder = execution();
2183+
const holder: ReplExecution = {
2184+
id: "agent-kernel",
2185+
stream: yield* useJournalStream(INLINE_SOURCE_PATH),
2186+
};
21732187
const stub = createStub();
21742188
yield* scoped(function* () {
21752189
yield* useStub(stub);
@@ -2292,9 +2306,13 @@ function* useStopping(stop: Signal): Operation<void> {
22922306

22932307
describe("EL2 — an entry's live Agent state is retired with its execution", () => {
22942308
beforeAll(() => useTempFileCompiler());
2309+
beforeEach(journalBeforeEach(OWNER));
22952310

22962311
it("EL2: a cancelled turn is retired with its entry, and the next entry runs clean", function* () {
2297-
const holder = execution();
2312+
const holder: ReplExecution = {
2313+
id: "agent-kernel",
2314+
stream: yield* useJournalStream(INLINE_SOURCE_PATH),
2315+
};
22982316
const stub = createStub({ held: { gated: true }, two: { gated: true } });
22992317
const stop = signal();
23002318
yield* scoped(function* () {
@@ -2356,7 +2374,10 @@ describe("EL2 — an entry's live Agent state is retired with its execution", ()
23562374
});
23572375

23582376
it("EL2: cleanup keeps a published slot and removes only the unpublished one", function* () {
2359-
const holder = execution();
2377+
const holder: ReplExecution = {
2378+
id: "agent-kernel",
2379+
stream: yield* useJournalStream(INLINE_SOURCE_PATH),
2380+
};
23602381
const stub = createStub({
23612382
done: { gated: true },
23622383
held: { gated: true },
@@ -2436,7 +2457,10 @@ describe("EL2 — an entry's live Agent state is retired with its execution", ()
24362457
});
24372458

24382459
it("EL2: a request held by a cancelled entry crosses nothing into its successor", function* () {
2439-
const holder = execution();
2460+
const holder: ReplExecution = {
2461+
id: "agent-kernel",
2462+
stream: yield* useJournalStream(INLINE_SOURCE_PATH),
2463+
};
24402464
const stub = createStub({
24412465
asks: { permission: { toolCallId: "entry-one", kind: "write", title: "Write once?" } },
24422466
next: { permission: { toolCallId: "entry-two", kind: "write", title: "Write again?" } },
@@ -2590,9 +2614,13 @@ function eachCallOwnsItsTurn(model: ReplModel): void {
25902614

25912615
describe("R1 — one component called in two branches", () => {
25922616
beforeAll(() => useTempFileCompiler());
2617+
beforeEach(journalBeforeEach(OWNER));
25932618

25942619
it("R1: each call keeps its own turn, the next entry is admitted, and a cold read repeats nothing", function* () {
2595-
const holder = execution();
2620+
const holder: ReplExecution = {
2621+
id: "agent-kernel",
2622+
stream: yield* useJournalStream(INLINE_SOURCE_PATH),
2623+
};
25962624
let written: string[] = [];
25972625
yield* scoped(function* () {
25982626
const stub = createStub({ same: { deltas: ["reply"] } });

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515

1616
import { beforeAll, beforeEach, describe, it } from "@executablemd/test-support/bdd";
17-
import { journalBeforeEach } from "@executablemd/test-support/failure-journal";
17+
import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal";
1818
import { expect } from "@executablemd/test-support/expect";
1919
import { race, scoped, sleep, until as untilResolved, useScope, withResolvers } from "effection";
2020
import type { Operation, Result, Stream } from "effection";
@@ -474,8 +474,8 @@ function installations(): readonly ExecutionInstallation[] {
474474
return [{ components: agentIdentityComponents() }];
475475
}
476476

477-
function execution(): ReplExecution {
478-
return { id: "agent-interface", stream: new InMemoryStream([]) };
477+
function execution(stream: InMemoryStream): ReplExecution {
478+
return { id: "agent-interface", stream };
479479
}
480480

481481
/** The session, or the refusal that means there is nothing to drive. */
@@ -935,27 +935,29 @@ function* asking(
935935
script: Record<string, Script>,
936936
permissionMode: PermissionMode = "approve-reads",
937937
source: string = THREE_SPAWNS,
938-
holder = execution(),
938+
holder?: ReplExecution,
939939
): Operation<{
940940
readonly session: ReplSession;
941941
readonly stub: Stub;
942942
readonly holder: ReplExecution;
943943
}> {
944+
const actualHolder = holder ?? execution(yield* useJournalStream(INLINE_SOURCE_PATH));
944945
const stub = createStub(script);
945946
yield* useStub(stub);
946947
const session = granted(
947948
yield* submitReplEntry({
948-
execution: holder,
949+
execution: actualHolder,
949950
installations: installations(),
950951
generated: ordinaryGeneratedSelection(),
951952
permissionMode,
952953
source,
953954
}),
954955
);
955-
return { session, stub, holder };
956+
return { session, stub, holder: actualHolder };
956957
}
957958

958959
describe("U1 — one chronology, filtered, undisturbed by the background", () => {
960+
beforeEach(journalBeforeEach(OWNER));
959961
beforeAll(() => useTempFileCompiler());
960962

961963
it("U1: retained, streaming and queued turns show together, in scheduling order", () =>
@@ -3518,6 +3520,7 @@ function onePromptAt(text: string): string {
35183520
}
35193521

35203522
describe("U1 — a row's rectangle does not bound its text (#875 R1)", () => {
3523+
beforeEach(journalBeforeEach(OWNER));
35213524
beforeAll(() => useTempFileCompiler());
35223525

35233526
/** A prompt longer than any sidebar this product draws. */
@@ -3578,11 +3581,12 @@ describe("U1 — a row's rectangle does not bound its text (#875 R1)", () => {
35783581

35793582
describe("U9 — two entries whose Prompts share one durable name", () => {
35803583
beforeAll(() => useTempFileCompiler());
3584+
beforeEach(journalBeforeEach(OWNER));
35813585

35823586
it("U9: each entry's turn shows once and resolves to its own record", function* () {
35833587
const stub = createStub({ two: { unrecorded: true } });
35843588
yield* useStub(stub);
3585-
const holder = execution();
3589+
const holder = execution(yield* useJournalStream(INLINE_SOURCE_PATH));
35863590
const session = granted(
35873591
yield* submitReplEntry({
35883592
execution: holder,
@@ -3676,6 +3680,7 @@ function* catalogLabel(view: ReplView, entry: string): Operation<string> {
36763680

36773681
describe("EU1 — selecting an entry moves the transcript locus and nothing else", () => {
36783682
beforeAll(() => useTempFileCompiler());
3683+
beforeEach(journalBeforeEach(OWNER));
36793684

36803685
/** Two entries, each with one recorded turn in one provider conversation. */
36813686
function* twoRecordedEntries(): Operation<{
@@ -3685,7 +3690,7 @@ describe("EU1 — selecting an entry moves the transcript locus and nothing else
36853690
}> {
36863691
const stub = createStub({ two: { unrecorded: true } });
36873692
yield* useStub(stub);
3688-
const holder = execution();
3693+
const holder = execution(yield* useJournalStream(INLINE_SOURCE_PATH));
36893694
const session = granted(
36903695
yield* submitReplEntry({
36913696
execution: holder,
@@ -4049,6 +4054,7 @@ describe("EU1 — selecting an entry moves the transcript locus and nothing else
40494054
*/
40504055
describe("U2 — a pending permission announces itself without taking the screen", () => {
40514056
beforeAll(() => useTempFileCompiler());
4057+
beforeEach(journalBeforeEach(OWNER));
40524058

40534059
it("UI14: the frame says a permission waits in Sessions, and changes no route or focus", function* () {
40544060
const { session } = yield* asking({
@@ -4282,6 +4288,7 @@ describe("U2 — a draft outlives a permission and is still editable", () => {
42824288
* Both profiles, because wide-only evidence is what let the medium case through.
42834289
*/
42844290
describe("Tier BP4 — the widened sidebar holds its longest rows whole", () => {
4291+
beforeEach(journalBeforeEach(OWNER));
42854292
/** The longest state this product writes for a turn, and the widest control. */
42864293
const LONGEST_STATE = "completed, not recorded yet";
42874294
const FILTERED = "All conversations (filtered)";
@@ -4362,6 +4369,7 @@ describe("Tier BP4 — the widened sidebar holds its longest rows whole", () =>
43624369

43634370
describe("PV2: Transcript groups and logical reveal", () => {
43644371
beforeAll(() => useTempFileCompiler());
4372+
beforeEach(journalBeforeEach(OWNER));
43654373
it("choices and a permission child contain arrows; hidden turns mount only when revealed", function* () {
43664374
const scripts = Object.fromEntries(
43674375
Array.from({ length: 10 }, (_, at): [string, Script] => [

‎packages/cli/tests/repl-entries.test.ts‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* no run produces.
2020
*/
2121

22-
import { beforeAll, describe, it } from "@executablemd/test-support/bdd";
22+
import { beforeAll, beforeEach, describe, it } from "@executablemd/test-support/bdd";
2323
import { expect } from "@executablemd/test-support/expect";
2424
import { captureReplEntry } from "./fixtures/repl/failure-journal.ts";
2525
import {
@@ -39,6 +39,7 @@ import {
3939
serializeDurableEvent,
4040
} from "@executablemd/durable-streams";
4141
import type { DurableEvent, DurableStream, Json } from "@executablemd/durable-streams";
42+
import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal";
4243
import { API } from "@executablemd/runtime";
4344
import {
4445
createScope,
@@ -1254,6 +1255,7 @@ function* countPerformed(): Operation<Performed> {
12541255

12551256
describe("REPL entries: one session, one entry task, in turn", () => {
12561257
beforeAll(() => useTempFileCompiler());
1258+
beforeEach(journalBeforeEach(OWNER));
12571259

12581260
const firstTask = "EL1: the first entry starts exactly one task";
12591261
it(firstTask, () =>
@@ -1308,7 +1310,10 @@ describe("REPL entries: one session, one entry task, in turn", () => {
13081310
);
13091311

13101312
it("EL1: terminal and unjoined still refuses; the join lets the next one start", function* () {
1311-
const holder = replExecution();
1313+
const holder: ReplExecution = {
1314+
id: "entries",
1315+
stream: yield* useJournalStream(INLINE_SOURCE_PATH),
1316+
};
13121317
const entered = gate();
13131318
const release = gate();
13141319
try {
@@ -1357,7 +1362,10 @@ describe("REPL entries: one session, one entry task, in turn", () => {
13571362
});
13581363

13591364
it("EL1: a later entry receives only what earlier entries durably published", function* () {
1360-
const holder = replExecution();
1365+
const holder: ReplExecution = {
1366+
id: "entries",
1367+
stream: yield* useJournalStream(INLINE_SOURCE_PATH),
1368+
};
13611369
yield* scoped(function* () {
13621370
const session = opened(yield* submitReplEntry({ execution: holder, source: FIRST }));
13631371
yield* session.join();
@@ -1380,7 +1388,10 @@ describe("REPL entries: one session, one entry task, in turn", () => {
13801388
});
13811389

13821390
it("EL1: a failed entry permits the next one; an interrupted one permits none", function* () {
1383-
const holder = replExecution();
1391+
const holder: ReplExecution = {
1392+
id: "entries",
1393+
stream: yield* useJournalStream(INLINE_SOURCE_PATH),
1394+
};
13841395
yield* scoped(function* () {
13851396
const session = opened(yield* submitReplEntry({ execution: holder, source: FIRST }));
13861397
yield* session.join();
@@ -1404,7 +1415,10 @@ describe("REPL entries: one session, one entry task, in turn", () => {
14041415
// Measured rather than assumed: cancelling a held REPL entry appends no
14051416
// terminal record at all, so what it leaves is an *unfinished* entry — and
14061417
// nothing may follow one of those.
1407-
const interrupted = replExecution();
1418+
const interrupted: ReplExecution = {
1419+
id: "entries",
1420+
stream: yield* useJournalStream(INLINE_SOURCE_PATH),
1421+
};
14081422
yield* scoped(function* () {
14091423
const session = opened(yield* submitReplEntry({ execution: interrupted, source: ASKS }));
14101424
yield* asking(session);

‎packages/cli/tests/repl-execution.test.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
* once and never after its owner is gone.
1414
*/
1515

16-
import { beforeAll, describe, it } from "@executablemd/test-support/bdd";
16+
import { beforeAll, beforeEach, describe, it } from "@executablemd/test-support/bdd";
17+
import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal";
1718
import { expect } from "@executablemd/test-support/expect";
1819
import { INLINE_SOURCE_PATH, useTempFileCompiler } from "@executablemd/core";
1920
import { InMemoryStream, serializeDurableEvent } from "@executablemd/durable-streams";
@@ -1227,6 +1228,8 @@ describe(SELECTION_SUITE, () => {
12271228
});
12281229

12291230
describe("execution initialization in REPL entries", () => {
1231+
beforeEach(journalBeforeEach(OWNER));
1232+
12301233
it("EI-REPL: two entries own fresh state below the same session attachment", function* () {
12311234
const State = createContext<object | undefined>("executablemd.test.repl.init", undefined);
12321235
const initialized: object[] = [];
@@ -1247,8 +1250,12 @@ describe("execution initialization in REPL entries", () => {
12471250
yield* next(request);
12481251
},
12491252
});
1253+
const sessionExecution: ReplExecution = {
1254+
id: "kf39sla2",
1255+
stream: yield* useJournalStream(INLINE_SOURCE_PATH),
1256+
};
12501257
const session = opened(
1251-
yield* submitReplEntry({ ...options(execution()), source: "first entry\n" }),
1258+
yield* submitReplEntry({ ...options(sessionExecution), source: "first entry\n" }),
12521259
);
12531260
yield* session.join();
12541261
const submitted = yield* session.submit("second entry\n");

‎packages/cli/tests/repl-headless.test.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { captureTestJournal, journalBeforeEach } from "@executablemd/test-support/failure-journal";
1+
import {
2+
captureTestJournal,
3+
journalBeforeEach,
4+
useJournalStream,
5+
} from "@executablemd/test-support/failure-journal";
26
import { Plugin } from "@executablemd/core/api";
37
import type { ReplPluginInstallation } from "../api.ts";
48
import { useSidekickAttachment } from "../src/sidekick-acp/server.ts";
@@ -827,7 +831,7 @@ function* useManagedRecoveryChild(publicationFailure: { armed: boolean }) {
827831
path,
828832
'<Agent name="xmd"><Session><XMD.Session as="child" /><Json value={child} /></Session></Agent>',
829833
);
830-
const execution = yield* executeInstalled({ path, stream: new InMemoryStream() }, [
834+
const execution = yield* executeInstalled({ path, stream: yield* useJournalStream(path) }, [
831835
children.installation,
832836
{
833837
components: agentIdentityComponents(),

0 commit comments

Comments
 (0)