Skip to content
Merged
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
30 changes: 30 additions & 0 deletions packages/cli/tests/fixtures/repl/failure-journal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { Operation } from "effection";
import process from "node:process";
import { captureTestJournal } from "@executablemd/test-support/failure-journal";
import type { JournalCase } from "../../../src/test-diagnostics.ts";
import type { DeliverySink } from "../../../src/stdout-delivery.ts";
import { partitionEntrySegments } from "../../../src/repl/entries.ts";
import type { ReplExecution } from "../../../src/repl/journal.ts";

/** Capture the admission owned by a synthetic, single-entry REPL fixture. */
export function captureReplEntry(
testCase: JournalCase,
id: string,
source: string,
body: (holder: ReplExecution) => Operation<void>,
sink: DeliverySink = process.stderr,
): Operation<void> {
return captureTestJournal(testCase, source, (stream) => body({ id, stream }), {
sink,
selectEvents(events) {
const partition = partitionEntrySegments(events);
if (!partition.ok) {
throw partition.error;
}
if (partition.value.length > 1) {
throw new Error("fixture execution holds more than one admitted entry");
}
return partition.value[0]?.events ?? [];
},
});
}
21 changes: 2 additions & 19 deletions packages/cli/tests/repl-execution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { join } from "node:path";
import process from "node:process";
import { Writable } from "node:stream";
import { partitionEntrySegments, ROOT_IMPORT } from "../src/repl/entries.ts";
import { captureTestJournal } from "@executablemd/test-support/failure-journal";
import { captureReplEntry } from "./fixtures/repl/failure-journal.ts";
import type { DeliverySink } from "../src/stdout-delivery.ts";

import { useTempDirectory } from "@executablemd/test-support/temp";
Expand Down Expand Up @@ -255,24 +255,7 @@ function captureEntry(
body: (holder: ReplExecution) => Operation<void>,
sink: DeliverySink = process.stderr,
): Operation<void> {
return captureTestJournal(
{ owner: OWNER, suite, name },
source,
(stream) => body({ id: "kf39sla2", stream }),
{
sink,
selectEvents(events) {
const partition = partitionEntrySegments(events);
if (!partition.ok) {
throw partition.error;
}
if (partition.value.length > 1) {
throw new Error("fixture execution holds more than one admitted entry");
}
return partition.value[0]?.events ?? [];
},
},
);
return captureReplEntry({ owner: OWNER, suite, name }, "kf39sla2", source, body, sink);
}

function admitReferenceEntry(
Expand Down
123 changes: 73 additions & 50 deletions packages/cli/tests/repl-history.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ import { beforeAll, describe, it } from "@executablemd/test-support/bdd";
import { expect } from "@executablemd/test-support/expect";
import { ensure, scoped, sleep } from "effection";
import type { Operation, Result } from "effection";
import { useTempFileCompiler } from "@executablemd/core";
import { INLINE_SOURCE_PATH, useTempFileCompiler } from "@executablemd/core";
import { InMemoryStream } from "@executablemd/durable-streams";

import { captureReplEntry } from "./fixtures/repl/failure-journal.ts";
import { openReplSession } from "../src/repl/session.ts";
import type { ReplSession } from "../src/repl/session.ts";
import type { ReplExecution } from "../src/repl/journal.ts";
Expand Down Expand Up @@ -366,57 +367,79 @@ describe("H3 — the head is derived from retained facts and owned work", () =>
});
});

describe("H3 — the head a real session publishes", () => {
beforeAll(() => useTempFileCompiler());

it("is empty before an entry, live while one runs, settled once it has", function* () {
const session = opened(yield* openReplSession({ execution: execution() }));
// Nothing retained and nothing owned.
expect(session.navigation.head).toBe("empty");
expect(session.navigation.checkpoints).toEqual([]);
const HEAD_SUITE = "H3 — the head a real session publishes";

accepted(yield* session.submit('<Json value={1} as="a" />\n'));
// Owned work, from before its first record exists.
expect(session.navigation.head).toBe("live");

yield* session.join();
yield* sleep(0);
// The outcome is retained and nothing of the entry is still standing.
expect(session.navigation.head).toBe("settled");
expect(session.navigation.checkpoints.map((one) => one.kind)).toContain("entry");
expect(session.navigation.checkpoints.map((one) => one.kind)).toContain("terminal");
});
describe(HEAD_SUITE, () => {
beforeAll(() => useTempFileCompiler());

it("is SETTLING while the outcome is retained and the entry is still coming down", function* () {
// The window a reader watching a run end is actually in: the root closed,
// and this process still owns what the entry acquired. A head taken from
// the root Close alone would call this finished.
let duringRelease: string | undefined;
let held: ReplSession | undefined;
const session = opened(
yield* openReplSession({
execution: execution(),
installations: [
{
*install(): Operation<void> {
yield* ensure(() => {
duringRelease = held?.navigation.head;
});
},
},
],
}),
);
held = session;
accepted(yield* session.submit('<Json value={1} as="a" />\n'));
yield* session.join();
yield* sleep(0);
// Read at the moment this entry's own installation was released, which
// is after its outcome was recorded and before its work was finished.
expect(duringRelease).toBe("settling");
// And neutral once it is down, however it went.
expect(session.navigation.head).toBe("settled");
});
it("is empty before an entry, live while one runs, settled once it has", () =>
captureReplEntry(
{
owner: "packages/cli/tests/repl-history.test.ts",
suite: HEAD_SUITE,
name: "is empty before an entry, live while one runs, settled once it has",
},
"history",
INLINE_SOURCE_PATH,
function* (holder) {
const session = opened(yield* openReplSession({ execution: holder }));
// Nothing retained and nothing owned.
expect(session.navigation.head).toBe("empty");
expect(session.navigation.checkpoints).toEqual([]);

accepted(yield* session.submit('<Json value={1} as="a" />\n'));
// Owned work, from before its first record exists.
expect(session.navigation.head).toBe("live");

yield* session.join();
yield* sleep(0);
// The outcome is retained and nothing of the entry is still standing.
expect(session.navigation.head).toBe("settled");
expect(session.navigation.checkpoints.map((one) => one.kind)).toContain("entry");
expect(session.navigation.checkpoints.map((one) => one.kind)).toContain("terminal");
},
));

it("is SETTLING while the outcome is retained and the entry is still coming down", () =>
captureReplEntry(
{
owner: "packages/cli/tests/repl-history.test.ts",
suite: HEAD_SUITE,
name: "is SETTLING while the outcome is retained and the entry is still coming down",
},
"history",
INLINE_SOURCE_PATH,
function* (holder) {
// The window a reader watching a run end is actually in: the root closed,
// and this process still owns what the entry acquired. A head taken from
// the root Close alone would call this finished.
let duringRelease: string | undefined;
let held: ReplSession | undefined;
const session = opened(
yield* openReplSession({
execution: holder,
installations: [
{
*install(): Operation<void> {
yield* ensure(() => {
duringRelease = held?.navigation.head;
});
},
},
],
}),
);
held = session;
accepted(yield* session.submit('<Json value={1} as="a" />\n'));
yield* session.join();
yield* sleep(0);
// Read at the moment this entry's own installation was released, which
// is after its outcome was recorded and before its work was finished.
expect(duringRelease).toBe("settling");
// And neutral once it is down, however it went.
expect(session.navigation.head).toBe("settled");
},
));

it("carries no payload from the entry it is describing", function* () {
const session = opened(yield* openReplSession({ execution: execution() }));
Expand Down
Loading
Loading