From 76167fed09588650b229cc3609915e8ee2375c36 Mon Sep 17 00:00:00 2001 From: Taras Mankovski Date: Tue, 17 Nov 2026 18:38:38 -0500 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=90=9B=20Keep=20mounted=20REPL=20fail?= =?UTF-8?q?ure=20journals=20before=20their=20roots=20are=20removed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A mounted REPL host stores its paired entry and Sidekick histories as real files in a temporary root that is removed when the case's scope ends, so a failed case's saver found nothing to keep. useMountedHost now registers the root with the case's journal resource as soon as it owns it; the JSONL files are read when that scope unwinds, before the root's removal, kept in memory, and written beside the case identity only when the case fails. Mounted suites opt into per-case attribution with beforeEach(journalBeforeEach) and keep their plain it bodies. A child-process regression covers a passing case, a late assertion, a case deadline that cancels a turn in flight, and a nested and an outer root beside an in-memory journal, under each runtime. Co-Authored-By: Claude Opus 5.5 --- .../repl-bench/tests/mounted-typing.test.ts | 6 +- packages/cli/src/test-diagnostics.ts | 55 ++++-- .../tests/fixtures/mounted-failure-journal.ts | 184 ++++++++++++++++++ .../cli/tests/mounted-failure-journal.test.ts | 171 ++++++++++++++++ packages/cli/tests/plugin-modules.test.ts | 6 +- .../cli/tests/repl-agent-interface.test.ts | 8 +- packages/cli/tests/repl-agent-journey.test.ts | 12 +- packages/cli/tests/repl-asset-import.test.ts | 7 +- packages/cli/tests/repl-exec-output.test.ts | 8 +- packages/cli/tests/repl-focus-regions.test.ts | 11 +- .../cli/tests/repl-headless-attach.test.ts | 10 +- .../cli/tests/repl-headless-clients.test.ts | 7 +- .../repl-headless-submit-process.test.ts | 6 +- .../cli/tests/repl-headless-submit.test.ts | 6 +- packages/cli/tests/repl-headless.test.ts | 9 +- packages/cli/tests/repl-journey.test.ts | 23 ++- .../cli/tests/repl-layout-admission.test.ts | 7 +- packages/cli/tests/repl-page.test.ts | 9 +- packages/cli/tests/repl-paged-history.test.ts | 6 +- packages/cli/tests/repl-plugin.test.ts | 6 +- .../cli/tests/repl-presentation-style.test.ts | 10 +- packages/cli/tests/repl-project-files.test.ts | 10 +- .../cli/tests/repl-project-recovery.test.ts | 7 +- .../cli/tests/repl-restore-progress.test.ts | 6 +- packages/cli/tests/repl-sidekick-acp.test.ts | 8 +- .../tests/repl-sidekick-configuration.test.ts | 11 +- .../cli/tests/repl-sidekick-dispatch.test.ts | 6 +- .../cli/tests/repl-sidekick-journey.test.ts | 16 +- .../cli/tests/repl-sidekick-lifecycle.test.ts | 14 +- .../tests/repl-sidekick-presentation.test.ts | 29 ++- .../cli/tests/repl-sidekick-recovery.test.ts | 11 +- .../cli/tests/repl-sidekick-testing.test.ts | 10 +- .../cli/tests/repl-sidekick-typing.test.ts | 10 +- packages/cli/tests/repl-task-tabs.test.ts | 6 +- packages/cli/tests/repl-terminal.test.ts | 9 +- packages/cli/tests/repl-todo-journey.test.ts | 8 +- packages/cli/tests/repl-todo-recovery.test.ts | 6 +- .../cli/tests/repl-unfinished-entry.test.ts | 6 +- packages/cli/tests/repl-wheel-burst.test.ts | 6 +- .../cli/tests/repl-wheel-migration.test.ts | 6 +- packages/cli/tests/repl-wheel-scroll.test.ts | 6 +- .../tests/retained-repository-local.test.ts | 6 +- .../retained-repository-selection.test.ts | 6 +- packages/cli/tests/support/mounted-repl.ts | 10 +- packages/test-support/failure-journal.ts | 127 +++++++++--- 45 files changed, 826 insertions(+), 81 deletions(-) create mode 100644 packages/cli/tests/fixtures/mounted-failure-journal.ts create mode 100644 packages/cli/tests/mounted-failure-journal.test.ts diff --git a/examples/repl-bench/tests/mounted-typing.test.ts b/examples/repl-bench/tests/mounted-typing.test.ts index 9a6b73d13..6d51c53f3 100644 --- a/examples/repl-bench/tests/mounted-typing.test.ts +++ b/examples/repl-bench/tests/mounted-typing.test.ts @@ -1,4 +1,5 @@ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import type { Operation } from "effection"; import { useReplPage } from "../../../packages/cli/tests/support/repl-page.ts"; @@ -11,6 +12,8 @@ import { generateTypingHistory } from "../../../packages/cli/tests/support/typin import { EDITS, VIEWPORT, WARMUP, WORKLOADS } from "../lib/typing-latency-report.ts"; import type { TypingSample } from "../lib/typing-latency-report.ts"; +const OWNER = "examples/repl-bench/tests/mounted-typing.test.ts"; + const MARKER = "XMD:"; const CHARACTERS = "abcdefghijklmnopqrstuvwxyz".repeat(2).slice(0, EDITS); const revision = Deno.env.get("XMD_TYPING_BENCH_REVISION"); @@ -62,6 +65,7 @@ function* sampleTyping(page: ReplPage): Operation { if (revision !== undefined) { describe("mounted REPL typing latency", () => { + beforeEach(journalBeforeEach(OWNER)); for (const workload of WORKLOADS) { it(workload.name, function* () { const page = yield* useReplPage({ size: VIEWPORT }); diff --git a/packages/cli/src/test-diagnostics.ts b/packages/cli/src/test-diagnostics.ts index acf72adbe..b6e08d6d8 100644 --- a/packages/cli/src/test-diagnostics.ts +++ b/packages/cli/src/test-diagnostics.ts @@ -32,7 +32,7 @@ import type { DurableEvent } from "@executablemd/durable-streams"; import { Test, testing } from "@executablemd/testing"; import type { FailureJournalHost, TestResult } from "@executablemd/testing"; import { randomUUID } from "node:crypto"; -import { isAbsolute, join, relative, resolve, sep } from "node:path"; +import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path"; import { deliverWhole } from "./stdout-delivery.ts"; import type { DeliverySink } from "./stdout-delivery.ts"; @@ -79,6 +79,20 @@ export interface ExecutionDiagnostics { observe(): Operation; /** Saves this execution's journal when `failed` says its outcome failed. */ journal(failed: (value: T) => boolean): FailureJournalHost; + /** + * Saves journal files a host wrote for this execution, with their original + * text, beneath one directory named like this execution's journal. + * + * `path` is each file's place beneath the storage root, so two files of one + * root keep the names that tell them apart. + */ + saveFiles(files: readonly SavedJournalFile[]): Operation; +} + +/** One journal file as its host wrote it. */ +export interface SavedJournalFile { + readonly path: string; + readonly text: string; } /** @@ -167,6 +181,22 @@ function testDiagnosticsAt( const displayedSource = shown(source); const named = `${kind} ${ordinal} ${displayedSource}${profile === undefined ? "" : ` (${profile})`}`; const context = kind === "root" ? "" : `${named}: `; + function* identify(files?: readonly string[]): Operation { + yield* ensureDir(directory); + if (attribution !== undefined) { + yield* writeTextFile( + `${stem}.case.json`, + JSON.stringify({ + ...attribution, + kind, + ordinal, + source: displayedSource, + profile, + files, + }) + "\n", + ); + } + } return { observe: () => observe( @@ -186,19 +216,7 @@ function testDiagnosticsAt( journal: (failed: (value: T) => boolean): FailureJournalHost => ({ failed, *save(events: readonly DurableEvent[]) { - yield* ensureDir(directory); - if (attribution !== undefined) { - yield* writeTextFile( - `${stem}.case.json`, - JSON.stringify({ - ...attribution, - kind, - ordinal, - source: displayedSource, - profile, - }) + "\n", - ); - } + yield* identify(); yield* writeTextFile(file, events.map(serializeDurableEvent).join("")); emit(`journal saved: ${file} (${named})`); }, @@ -207,6 +225,15 @@ function testDiagnosticsAt( emit(`journal not saved for ${named}: ${error.message}`); }, }), + *saveFiles(files: readonly SavedJournalFile[]) { + yield* identify(files.map(({ path }) => path)); + for (const { path, text } of files) { + const target = join(stem, path); + yield* ensureDir(dirname(target)); + yield* writeTextFile(target, text); + } + emit(`journal saved: ${stem} (${named})`); + }, }; }, delivery: () => delivery, diff --git a/packages/cli/tests/fixtures/mounted-failure-journal.ts b/packages/cli/tests/fixtures/mounted-failure-journal.ts new file mode 100644 index 000000000..a6ac739d9 --- /dev/null +++ b/packages/cli/tests/fixtures/mounted-failure-journal.ts @@ -0,0 +1,184 @@ +/** + * Synthetic mounted cases for `mounted-failure-journal.test.ts`, run as a child + * test file under the parent's own runtime. + * + * Each case drives the real mounted REPL over real file storage and copies what + * that storage held to `XMD_MOUNTED_WITNESS`, outside the directory its host + * removes, so the parent can compare a saved failure journal with the bytes the + * command actually wrote. Each case also records, after its whole teardown has + * run, which data roots it mounted and whether each still exists. + */ + +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { expect } from "@executablemd/test-support/expect"; +import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal"; +import { exists, readTextFile, walk, writeTextFile, ensureDir } from "@effectionx/fs"; +import { API, env } from "@executablemd/runtime"; +import { each, ensure, race, scoped, sleep } from "effection"; +import type { Operation } from "effection"; +import { dirname, join, relative } from "node:path"; + +import { useReplPage } from "../support/repl-page.ts"; +import type { ReplPage } from "../support/repl-page.ts"; +import { awaited } from "../support/mounted-repl.ts"; +import { asked, intoDraft, sendMessage, typed } from "../support/screen-journeys.ts"; +import { useTemporary } from "./repl/issue-883/sidekick-harness.ts"; + +const OWNER = "packages/cli/tests/fixtures/mounted-failure-journal.ts"; + +const WIDE = { columns: 160, rows: 36 }; + +/** How long the deadline case waits for a reply its turn never sends. */ +const CASE_DEADLINE_MS = 500; + +/** One case's witness directory, and the roots it mounted, in mount order. */ +interface Witness { + readonly directory: string; + readonly roots: string[]; +} + +function* witnessDirectory(name: string): Operation { + const base = yield* env("XMD_MOUNTED_WITNESS"); + if (!base) { + throw new Error("The mounted journal witness needs a witness directory."); + } + return join(base, name); +} + +function witness(name: string, body: (witnessed: Witness) => Operation): void { + describe("mounted journal " + name, () => { + beforeEach(function* () { + const root = yield* env("XMD_TEST_ARTIFACTS"); + if (!root) { + throw new Error("The mounted journal witness needs an artifact root."); + } + yield* API.Env.around({ + *env([variable], next) { + return variable === "XMD_TEST_ARTIFACTS" ? join(root, name) : yield* next(variable); + }, + }); + }); + beforeEach(journalBeforeEach(OWNER)); + it(name, function* () { + const witnessed: Witness = { directory: yield* witnessDirectory(name), roots: [] }; + // Registered before any host, so it runs once every mounted scope has + // unwound: what it records is the state teardown actually left. + yield* ensure(function* () { + const roots: { root: string; exists: boolean }[] = []; + for (const root of witnessed.roots) { + roots.push({ root, exists: yield* exists(root) }); + } + yield* ensureDir(witnessed.directory); + yield* writeTextFile( + join(witnessed.directory, "teardown.json"), + JSON.stringify({ joined: true, roots }) + "\n", + ); + }); + yield* body(witnessed); + }); + }); +} + +/** Copy the JSONL files beneath this root, as the command left them. */ +function* copyJournals(witnessed: Witness, ordinal: number, root: string): Operation { + const target = join(witnessed.directory, `root-${ordinal}`); + yield* ensureDir(target); + for (const entry of yield* each(walk(root, { includeDirs: false, match: [/\.jsonl$/] }))) { + const copy = join(target, relative(root, entry.path)); + yield* ensureDir(dirname(copy)); + yield* writeTextFile(copy, yield* readTextFile(entry.path)); + yield* each.next(); + } +} + +/** Mount the real command and remember the root it stores its histories in. */ +function* mounted( + witnessed: Witness, + options: Parameters[0] = {}, +): Operation<{ page: ReplPage; ordinal: number }> { + const page = yield* useReplPage({ size: WIDE, ...options }); + witnessed.roots.push(page.repl.root); + return { page, ordinal: witnessed.roots.length }; +} + +/** + * One Sidekick exchange and one entry of a person's own, both settled. + * + * The message spells `word` in lower case so that only the reply draws it. + */ +function* exchange(page: ReplPage, word: string): Operation { + page.repl.fake.script({ reply: `${word}\n` }); + yield* asked(page, `reply ${word.toLowerCase()}`, word); + yield* intoDraft(page); + yield* typed(page, `entry ${word}`); + yield* page.key("Enter"); + yield* page.until("the entry settling", (one) => one.shows("1 ✓")); +} + +/** Leave the command and wait for it to return. */ +function* exit(page: ReplPage): Operation { + yield* page.press("[exit]"); + yield* awaited("Exit joined", () => page.repl.outcome() !== undefined); + expect(page.repl.outcome()?.ok).toBe(true); +} + +witness("passing page", function* (witnessed) { + const { page, ordinal } = yield* mounted(witnessed); + yield* exchange(page, "PASSING"); + yield* exit(page); + yield* copyJournals(witnessed, ordinal, page.repl.root); +}); + +witness("late assertion", function* (witnessed) { + const { page, ordinal } = yield* mounted(witnessed); + yield* exchange(page, "ASSERTED"); + yield* exit(page); + yield* copyJournals(witnessed, ordinal, page.repl.root); + expect("the mounted command returned").toBe("deliberate mounted late assertion"); +}); + +witness("deadline", function* (witnessed) { + // A root this case supplies, so the copy can be taken at the latest moment + // before removal: after the host's own retention and before the directory goes. + const dataRoot = yield* useTemporary("xmd-mounted-witness-"); + let root: string | undefined; + yield* ensure(function* () { + if (root !== undefined) { + yield* copyJournals(witnessed, 1, root); + } + }); + const { page } = yield* mounted(witnessed, { dataRoot }); + root = page.repl.root; + yield* exchange(page, "STARTED"); + page.repl.fake.script({ manual: true }); + yield* sendMessage(page, "never answered"); + yield* page.repl.fake.startedTurns(2); + yield* race([ + page.until("a reply its turn never sends", (one) => one.shows("NEVER SENT")), + (function* (): Operation { + yield* sleep(CASE_DEADLINE_MS); + throw new Error(`deliberate mounted deadline after ${CASE_DEADLINE_MS}ms`); + })(), + ]); +}); + +witness("multiple roots", function* (witnessed) { + const stream = yield* useJournalStream("synthetic/in-memory.md"); + yield* stream.append({ + type: "close", + coroutineId: "root", + result: { status: "ok", value: null }, + }); + yield* scoped(function* () { + const { page, ordinal } = yield* mounted(witnessed); + yield* exchange(page, "NESTED"); + yield* exit(page); + yield* copyJournals(witnessed, ordinal, page.repl.root); + }); + expect(yield* exists(witnessed.roots[0])).toBe(false); + const { page, ordinal } = yield* mounted(witnessed); + yield* exchange(page, "OUTER"); + yield* exit(page); + yield* copyJournals(witnessed, ordinal, page.repl.root); + expect("both mounted roots returned").toBe("deliberate multiple-root assertion"); +}); diff --git a/packages/cli/tests/mounted-failure-journal.test.ts b/packages/cli/tests/mounted-failure-journal.test.ts new file mode 100644 index 000000000..f4398211a --- /dev/null +++ b/packages/cli/tests/mounted-failure-journal.test.ts @@ -0,0 +1,171 @@ +/** + * A mounted REPL case that fails keeps the histories its host wrote. + * + * The mounted host stores its paired entry and Sidekick histories as real files + * in a directory it removes when the case's scope ends. These rows run the + * synthetic cases in `fixtures/mounted-failure-journal.ts` as a child test file + * under this runtime, join it, and compare each saved journal with the copy the + * child took of what the command actually wrote: a passing case uploads + * nothing, and an assertion after a successful run, a case deadline that + * cancels a turn in flight, and a case with a nested and an outer root each + * leave their own attributed files after the directories are gone. + */ + +import { describe, it } from "@executablemd/test-support/bdd"; +import { expect } from "@executablemd/test-support/expect"; +import { cliRuntime, runShell, shellQuote } from "@executablemd/test-support/launch"; +import { useTempDirectory } from "@executablemd/test-support/temp"; +import { exists, readdir, readTextFile, walk } from "@effectionx/fs"; +import { parseDurableEvent } from "@executablemd/durable-streams"; +import { each } from "effection"; +import type { Operation } from "effection"; +import { join, relative } from "node:path"; +import { execPath } from "node:process"; +import { fileURLToPath } from "node:url"; + +const OWNER = "packages/cli/tests/fixtures/mounted-failure-journal.ts"; + +/** Every file beneath a directory, by its path inside it, with its text. */ +function* contents(directory: string): Operation> { + const found: Record = {}; + for (const entry of yield* each(walk(directory, { includeDirs: false }))) { + found[relative(directory, entry.path)] = yield* readTextFile(entry.path); + yield* each.next(); + } + return found; +} + +/** What the child recorded once a case's whole teardown had run. */ +function* teardown(witness: string): Operation<{ root: string; exists: boolean }[]> { + const recorded: unknown = JSON.parse(yield* readTextFile(join(witness, "teardown.json"))); + if ( + recorded === null || + typeof recorded !== "object" || + !("joined" in recorded) || + recorded.joined !== true || + !("roots" in recorded) || + !Array.isArray(recorded.roots) + ) { + throw new Error(`The child recorded no joined teardown: ${JSON.stringify(recorded)}`); + } + return recorded.roots.map((one: unknown) => { + if ( + one === null || + typeof one !== "object" || + !("root" in one) || + typeof one.root !== "string" || + !("exists" in one) || + typeof one.exists !== "boolean" + ) { + throw new Error(`The child recorded an unreadable root: ${JSON.stringify(one)}`); + } + return { root: one.root, exists: one.exists }; + }); +} + +describe("mounted REPL failure journals", () => { + it("keeps each failed case's actual paired histories after its roots are removed", function* () { + const artifacts = yield* useTempDirectory("xmd-mounted-journal-artifacts-"); + const witnesses = yield* useTempDirectory("xmd-mounted-journal-witness-"); + const cwd = fileURLToPath(new URL("../../../", import.meta.url)); + const runtime = cliRuntime(); + const flags = { + deno: ["test", "--allow-all", "--frozen"], + node: ["--import", "tsx", "--test", "--test-reporter=spec", "--test-concurrency=1"], + bun: ["test", "--timeout=120000"], + }[runtime]; + const command = [execPath, ...flags, "./" + OWNER].map(shellQuote).join(" "); + const result = yield* runShell("exec " + command, { + cwd, + timeout: 240_000, + env: { + XMD_TEST_ARTIFACTS: artifacts, + XMD_MOUNTED_WITNESS: witnesses, + TSX_TSCONFIG_PATH: join(cwd, "tsconfig.node.json"), + NO_COLOR: "1", + }, + }).join(); + const output = result.stdout + result.stderr; + if (result.code !== 1) { + throw new Error(`Expected the fixture to exit with 1, received ${result.code}.\n${output}`); + } + expect(output).toMatch(/(?:✔|\(pass\)).*passing page|passing page \.\.\. ok/); + expect(output).toContain('Expected: "deliberate mounted late assertion"'); + expect(output).toContain("deliberate mounted deadline after 500ms"); + expect(output).toContain('Expected: "deliberate multiple-root assertion"'); + + // A passing case unwound the same way and created nothing to upload. + expect(yield* exists(join(artifacts, "passing page"))).toBe(false); + const passed = yield* teardown(join(witnesses, "passing page")); + expect(passed.map((one) => one.exists)).toEqual([false]); + + for (const [name, words, memory] of [ + ["late assertion", ["ASSERTED"], false], + ["deadline", ["STARTED"], false], + ["multiple roots", ["NESTED", "OUTER"], true], + ] as const) { + const witness = join(witnesses, name); + const roots = yield* teardown(witness); + expect(roots.map((one) => one.exists)).toEqual(words.map(() => false)); + + const invocations = yield* readdir(join(artifacts, name)); + expect(invocations).toHaveLength(1); + const directory = join(artifacts, name, invocations[0]); + // The in-memory root opened first is saved beside the mounted ones. + const offset = memory ? 1 : 0; + if (memory) { + expect(JSON.parse(yield* readTextFile(join(directory, "root-1.case.json")))).toEqual({ + owner: OWNER, + name, + suite: "mounted journal " + name, + kind: "root", + ordinal: 1, + source: "synthetic/in-memory.md", + }); + expect( + parseDurableEvent((yield* readTextFile(join(directory, "root-1.jsonl"))).trimEnd()), + ).toMatchObject({ ok: true, value: { type: "close", coroutineId: "root" } }); + } + + const executions = new Set(); + for (const [index, word] of words.entries()) { + const ordinal = index + 1 + offset; + const saved = yield* contents(join(directory, `root-${ordinal}`)); + const copied = yield* contents(join(witness, `root-${index + 1}`)); + // Byte for byte what the command wrote, and nothing it did not. + expect(saved).toEqual(copied); + const files = Object.keys(saved).sort(); + expect(files).toHaveLength(2); + const [entries, sidekick] = files; + expect(entries).toMatch(/^v1\/[0-9a-f]+\/entries\.jsonl$/); + expect(sidekick).toBe(entries.replace(/entries\.jsonl$/, "sidekick.jsonl")); + executions.add(entries.split("/")[1]); + expect(saved[entries]).toContain(`entry ${word}`); + expect(saved[sidekick]).toContain(`reply ${word.toLowerCase()}`); + expect( + JSON.parse(yield* readTextFile(join(directory, `root-${ordinal}.case.json`))), + ).toEqual({ + owner: OWNER, + name, + suite: "mounted journal " + name, + kind: "root", + ordinal, + source: roots[index].root, + files, + }); + expect(output).toContain( + `journal saved: ${join(directory, `root-${ordinal}`)} (root ${ordinal} ${roots[index].root})`, + ); + } + expect(executions.size).toBe(words.length); + expect((yield* readdir(directory)).sort()).toEqual( + Array.from({ length: words.length + offset }, (_, index) => [ + `root-${index + 1}${memory && index === 0 ? ".jsonl" : ""}`, + `root-${index + 1}.case.json`, + ]) + .flat() + .sort(), + ); + } + }); +}); diff --git a/packages/cli/tests/plugin-modules.test.ts b/packages/cli/tests/plugin-modules.test.ts index e3e8b3514..6ec367515 100644 --- a/packages/cli/tests/plugin-modules.test.ts +++ b/packages/cli/tests/plugin-modules.test.ts @@ -15,10 +15,13 @@ import { usePluginProgram } from "./support/plugin-program.ts"; * it from any host — which is the whole point, because no shard runs the CLI on * Windows. */ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { classifyPluginSpecifier, resolvePluginSpecifier } from "../src/host-plugin-modules.ts"; +const OWNER = "packages/cli/tests/plugin-modules.test.ts"; + describe("PM1 — a Windows path is a path, on every host", () => { // deno-lint-ignore require-yield it("reads a drive prefix as a filesystem path rather than a scheme", function* () { @@ -127,6 +130,7 @@ describe("PM3 — resolution follows the classification", () => { }); describe("REPL Plugin author API", () => { + beforeEach(journalBeforeEach(OWNER)); it("R8: imports the public API and executes the selected author example", function* () { const { Repl } = yield* until(import("@executablemd/cli/api")); expect(Repl.operations.initialize).toBeDefined(); diff --git a/packages/cli/tests/repl-agent-interface.test.ts b/packages/cli/tests/repl-agent-interface.test.ts index 46a5d56a3..e47d0be7b 100644 --- a/packages/cli/tests/repl-agent-interface.test.ts +++ b/packages/cli/tests/repl-agent-interface.test.ts @@ -13,7 +13,8 @@ * session, a screenshot for a frame, or a bare `` for a conversation. */ -import { beforeAll, describe, it } from "@executablemd/test-support/bdd"; +import { beforeAll, beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { race, scoped, sleep, until as untilResolved, useScope, withResolvers } from "effection"; import type { Operation, Result, Stream } from "effection"; @@ -114,6 +115,8 @@ import { } from "./support/screen-journeys.ts"; import { readScreen } from "./support/terminal-screen.ts"; +const OWNER = "packages/cli/tests/repl-agent-interface.test.ts"; + /** The widest accepted frame, stated here because layout keeps it private. */ const WIDE = { columns: 160, rows: 36 }; const MEDIUM = { columns: 120, rows: 30 }; @@ -1996,6 +1999,7 @@ describe("U3 — what each accepted frame mounts, and nothing else", () => { const TURN_FACT_SUFFIXES = [":whose", ":text", ":stop", ":failed"]; describe("U2 — the program performs a permission, end to end", () => { + beforeEach(journalBeforeEach(OWNER)); beforeAll(() => useTempFileCompiler()); it("U2: choosing through the running program settles the request and closes its drawer", function* () { @@ -2109,6 +2113,7 @@ describe("U2 — the program performs a permission, end to end", () => { }); describe("U4 — the loop wakes for Agent work", () => { + beforeEach(journalBeforeEach(OWNER)); beforeAll(() => useTempFileCompiler()); it("U4: queued, streaming and a waiting request each repaint on their own", function* () { @@ -3769,6 +3774,7 @@ function* admittedSources(hostRoot: string): Operation { * region with every control on the screen. */ describe("U2 — a draft outlives a permission and is still editable", () => { + beforeEach(journalBeforeEach(OWNER)); beforeAll(() => useTempFileCompiler()); for (const size of [{ columns: 160, rows: 36 }, NARROW]) { diff --git a/packages/cli/tests/repl-agent-journey.test.ts b/packages/cli/tests/repl-agent-journey.test.ts index 509eec215..b69602050 100644 --- a/packages/cli/tests/repl-agent-journey.test.ts +++ b/packages/cli/tests/repl-agent-journey.test.ts @@ -1,5 +1,6 @@ import { installTodoSource } from "../src/node-todo-source.ts"; -import { beforeAll, describe, it } from "@executablemd/test-support/bdd"; +import { beforeAll, beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { scoped, sleep, spawn, suspend, until as untilResolved, withResolvers } from "effection"; import type { Operation } from "effection"; @@ -66,6 +67,8 @@ import { projectRepl } from "../src/repl/model.ts"; import { REPL_DIRECTORY } from "../src/repl/storage.ts"; import { pairedReplRepository } from "../src/repl/sidekick/repository.ts"; +const OWNER = "packages/cli/tests/repl-agent-journey.test.ts"; + const STORY = [ '', " ", @@ -166,6 +169,7 @@ const WIDE: ReplTerminalSize = { columns: 200, rows: 140 }; const TALL: ReplTerminalSize = { columns: 200, rows: 60 }; describe("J1 — the Story, from one entry to one README", () => { + beforeEach(journalBeforeEach(OWNER)); beforeAll(() => useTempFileCompiler()); it("J1: the packaged Plan is reviewed in the drawer, and its program asks, previews and writes", function* () { @@ -334,6 +338,7 @@ describe("J1 — the Story, from one entry to one README", () => { }); describe("C1 — the command line this REPL runs under", () => { + beforeEach(journalBeforeEach(OWNER)); beforeAll(() => useTempFileCompiler()); it("C1: the five options settle into one immutable profile", function* () { @@ -528,6 +533,7 @@ function* selectedProfile( } describe("A2–A5 — the selected REPL component environment", () => { + beforeEach(journalBeforeEach(OWNER)); beforeAll(() => useTempFileCompiler()); it("A2/A5: one detached ordered selection describes vocabulary, protected names and environment", function* () { @@ -731,6 +737,7 @@ describe("A2–A5 — the selected REPL component environment", () => { }); describe("J3 — durable truth, and a cold process over it", () => { + beforeEach(journalBeforeEach(OWNER)); beforeAll(() => useTempFileCompiler()); it("J3: a fresh command scope reconstructs the whole Story from the Journal alone", function* () { @@ -1061,6 +1068,7 @@ describe("J3 — durable truth, and a cold process over it", () => { }); describe("J2 — three conversations at once, through the terminal", () => { + beforeEach(journalBeforeEach(OWNER)); beforeAll(() => useTempFileCompiler()); it("J2: complete, streaming and queued are one frame, and filtering changes only Sessions", function* () { @@ -1158,6 +1166,7 @@ describe("J2 — three conversations at once, through the terminal", () => { }); describe("J2 — a filter and a draft across a resize (#875 R1)", () => { + beforeEach(journalBeforeEach(OWNER)); beforeAll(() => useTempFileCompiler()); const TYPED = "and then this one"; @@ -1286,6 +1295,7 @@ function* failing(body: () => Operation): Operation { } describe("X1 — how this command ends, with work still in flight", () => { + beforeEach(journalBeforeEach(OWNER)); beforeAll(() => useTempFileCompiler()); function* inFlight(fake: FakeAcp, hostRoot: string, waitingFor: string): Operation { diff --git a/packages/cli/tests/repl-asset-import.test.ts b/packages/cli/tests/repl-asset-import.test.ts index 31fe1797c..a5232622e 100644 --- a/packages/cli/tests/repl-asset-import.test.ts +++ b/packages/cli/tests/repl-asset-import.test.ts @@ -1,4 +1,5 @@ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { copyFile, @@ -27,6 +28,8 @@ import { records, useHarness, useTemporary } from "./fixtures/repl/issue-883/sid import type { Harness } from "./fixtures/repl/issue-883/sidekick-harness.ts"; import type { ReplElicitations, ReplQuestion } from "../src/repl/elicitation.ts"; +const OWNER = "packages/cli/tests/repl-asset-import.test.ts"; + const BINARY = new Uint8Array([0, 255, 128, 195, 40, 13, 10, 65]); function nativeGate() { @@ -407,6 +410,7 @@ import { } from "./support/screen-journeys.ts"; describe("mounted asset import", () => { + beforeEach(journalBeforeEach(OWNER)); it("A1/A2/A4: the form begins empty, closes unanswered, and approves the actual workspace", function* () { const { source, bytes } = yield* fixture(new TextEncoder().encode("mounted ü text")); const io = yield* instrument(); @@ -715,6 +719,7 @@ import { API, hostFilesHandler, useHostFiles } from "@executablemd/runtime"; import { useNormalizedOutput } from "@executablemd/core"; describe("asset import acknowledgement and independent owners", () => { + beforeEach(journalBeforeEach(OWNER)); it("A8: a failed import outcome append supplies no success or passive retry", function* () { const { source } = yield* fixture(); const held = yield* useHarness(); diff --git a/packages/cli/tests/repl-exec-output.test.ts b/packages/cli/tests/repl-exec-output.test.ts index 86349f954..99dec18ae 100644 --- a/packages/cli/tests/repl-exec-output.test.ts +++ b/packages/cli/tests/repl-exec-output.test.ts @@ -1,4 +1,5 @@ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { useTempDirectory } from "@executablemd/test-support/temp"; import { exists, writeTextFile } from "@effectionx/fs"; @@ -17,7 +18,10 @@ import type { ReplPage } from "./support/repl-page.ts"; import { awaitedFact, mountedReading } from "./support/mounted-repl.ts"; import { intoComposer, pasteDraft, sidekickIdle } from "./support/screen-journeys.ts"; +const OWNER = "packages/cli/tests/repl-exec-output.test.ts"; + describe("E3 retained command output", () => { + beforeEach(journalBeforeEach(OWNER)); it("retains captured control bytes in output, bindings, and command records", function* () { const received = "PROBE\x1b[2JTAIL\rEND"; yield* API.Process.around({ @@ -65,6 +69,7 @@ function* submit(page: ReplPage, source: string, order = 1): Operation { } describe("REPL foreground command presentation E1", () => { + beforeEach(journalBeforeEach(OWNER)); it("E1: contains both real child streams in the producing entry before exit", function* () { const directory = yield* useTempDirectory("repl-output-"); const release = join(directory, "release"); @@ -128,6 +133,7 @@ describe("REPL foreground command presentation E1", () => { }); describe("REPL command routing, containment and history E2–E5", () => { + beforeEach(journalBeforeEach(OWNER)); it("E2: retains bound, captured, and silent command results", function* () { const page = yield* useReplPage({ size: { columns: 160, rows: 52 } }); yield* submit( diff --git a/packages/cli/tests/repl-focus-regions.test.ts b/packages/cli/tests/repl-focus-regions.test.ts index 0c0f288ba..92ecb5a79 100644 --- a/packages/cli/tests/repl-focus-regions.test.ts +++ b/packages/cli/tests/repl-focus-regions.test.ts @@ -1,5 +1,6 @@ import type { ScreenReading } from "./support/repl-page.ts"; -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { REPL_PALETTE } from "../src/repl/presentation-style.ts"; import { sleep } from "effection"; @@ -28,6 +29,8 @@ import { REFERENCE_DIRECTORY } from "./fixtures/repl/reference.ts"; import { useReplPage } from "./support/repl-page.ts"; import type { PageKey, ReplPage } from "./support/repl-page.ts"; +const OWNER = "packages/cli/tests/repl-focus-regions.test.ts"; + const WIDE = { columns: 160, rows: 36 }; const MEDIUM = { columns: 120, rows: 30 }; const NARROW = { columns: 72, rows: 20 }; @@ -52,6 +55,7 @@ function* draftFocus(page: ReplPage): Operation { } describe("REPL focus regions: the normal screen", () => { + beforeEach(journalBeforeEach(OWNER)); for (const size of [WIDE, MEDIUM]) { it(`R1/R2: fixed region entries deliver Draft and Message input at ${size.columns}x${size.rows}`, function* () { const page = yield* useReplPage({ size }); @@ -133,6 +137,7 @@ describe("REPL focus regions: the normal screen", () => { }); describe("REPL focus regions: Unicode caret editing", () => { + beforeEach(journalBeforeEach(OWNER)); it("PV3: Draft and Message edit at independent carets across rows, focus and resize", function* () { const page = yield* useReplPage({ size: MEDIUM }); yield* draftFocus(page); @@ -180,6 +185,7 @@ describe("REPL focus regions: Unicode caret editing", () => { }); describe("REPL focus regions: reading and narrow recovery", () => { + beforeEach(journalBeforeEach(OWNER)); it("PV5: the selected reading reaches both boundaries without activating or editing", function* () { const page = yield* useReplPage({ size: MEDIUM }); yield* draftFocus(page); @@ -255,6 +261,7 @@ describe("REPL focus regions: reading and narrow recovery", () => { }); describe("REPL focus regions: the catalog drawer at the narrow size", () => { + beforeEach(journalBeforeEach(OWNER)); it("R5: nested arrows reveal hidden entries, fixed Content entry and modal close restore", function* () { const page = yield* useReplPage({ size: NARROW, includes: [REFERENCE_DIRECTORY] }); yield* draftFocus(page); @@ -620,6 +627,7 @@ describe("REPL focus regions: logical drawer reveal", () => { }); describe("REPL focus regions: background input ownership", () => { + beforeEach(journalBeforeEach(OWNER)); it("PV7: a reply and question leave a middle Message caret and Draft untouched", function* () { const page = yield* useReplPage({ size: MEDIUM }); yield* draftFocus(page); @@ -656,6 +664,7 @@ describe("REPL focus regions: background input ownership", () => { }); describe("REPL focus regions: Sidekick reading keys", () => { + beforeEach(journalBeforeEach(OWNER)); it("PV5: Home/End and pages preserve an unsent Message while output arrives", function* () { const page = yield* useReplPage({ size: MEDIUM }); yield* draftFocus(page); diff --git a/packages/cli/tests/repl-headless-attach.test.ts b/packages/cli/tests/repl-headless-attach.test.ts index 09a8bb35b..4bbe1376a 100644 --- a/packages/cli/tests/repl-headless-attach.test.ts +++ b/packages/cli/tests/repl-headless-attach.test.ts @@ -1,5 +1,6 @@ import { readTextFile } from "@effectionx/fs"; -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { createSignal, ensure, race, scoped, sleep, spawn } from "effection"; import type { Operation, Scope } from "effection"; @@ -20,9 +21,12 @@ import { XmdResponse } from "@executablemd/acp"; import { childAddressPath } from "../src/headless/host.ts"; import { pairedLocation, readSidekickRecords } from "../src/repl/sidekick/history.ts"; +const OWNER = "packages/cli/tests/repl-headless-attach.test.ts"; + type AppliedFrames = WeakMap Operation>; describe("987 — fresh child recovery reference", () => { + beforeEach(journalBeforeEach(OWNER)); it("keeps host readiness pending while an applied acknowledgement is held", function* () { const held = yield* useHeadlessFixture(); const gate = held.input.holdNextAcknowledgement(); @@ -368,6 +372,7 @@ function locateInBindings(terminal: Terminal, label: string): { row: number; col } describe("headless renderer lifetime", () => { + beforeEach(journalBeforeEach(OWNER)); it("releases every detached renderer scope while the exact child remains live", function* () { const live = new Set(); const parents = new WeakMap(); @@ -450,6 +455,7 @@ describe("headless renderer lifetime", () => { }); describe("headless live UI", () => { + beforeEach(journalBeforeEach(OWNER)); it("C3: Control-C typed while the attached first frame is still being written detaches", function* () { const held = yield* useHeadlessFixture(); const prompts = held.host.fake.prompts.length; @@ -1183,6 +1189,7 @@ describe("headless live UI", () => { }); describe("protected input through capable ACP pipes", () => { + beforeEach(journalBeforeEach(OWNER)); it("preserves the marker in the embedded callback and returns only a safe child result", function* () { let marked = false; const held = yield* useHeadlessFixture((input) => { @@ -1226,6 +1233,7 @@ describe("protected input through capable ACP pipes", () => { }); describe("marked ACP absence", () => { + beforeEach(journalBeforeEach(OWNER)); it("withdraws a marked question through the current no-form branch without opening a parent form", function* () { let callbacks = 0; const held = yield* useHeadlessFixture( diff --git a/packages/cli/tests/repl-headless-clients.test.ts b/packages/cli/tests/repl-headless-clients.test.ts index d4e7334db..893084725 100644 --- a/packages/cli/tests/repl-headless-clients.test.ts +++ b/packages/cli/tests/repl-headless-clients.test.ts @@ -1,4 +1,5 @@ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { ensure, race, scoped, sleep, spawn, suspend, useScope, withResolvers } from "effection"; import type { Operation } from "effection"; @@ -22,6 +23,8 @@ import { Elicitation } from "@executablemd/core"; import type { Scope } from "effection"; import type { AgentPromptEvent } from "@executablemd/agent/api"; +const OWNER = "packages/cli/tests/repl-headless-clients.test.ts"; + const conditional = { type: "object", additionalProperties: false, @@ -39,6 +42,7 @@ function entryResponse(source: string): string { } describe("headless presentation lifetime", () => { + beforeEach(journalBeforeEach(OWNER)); it("releases more than 64 UI-resolved presentations after callbacks join and preserves an in-flight stale response", function* () { const held = yield* useHeadlessFixture(); const questions = yield* useReplElicitation(); @@ -189,6 +193,7 @@ describe("headless presentation lifetime", () => { }); describe("headless child ACP clients", () => { + beforeEach(journalBeforeEach(OWNER)); it("H5: every closed response variant closes only its correlated presentation and retirement proves no answer", function* () { const issue = { instancePath: "/reason", diff --git a/packages/cli/tests/repl-headless-submit-process.test.ts b/packages/cli/tests/repl-headless-submit-process.test.ts index fc3e3a28e..58fa89d09 100644 --- a/packages/cli/tests/repl-headless-submit-process.test.ts +++ b/packages/cli/tests/repl-headless-submit-process.test.ts @@ -1,4 +1,5 @@ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { cliCommand } from "@executablemd/test-support/launch"; import { ensure, race, sleep, withResolvers } from "effection"; @@ -14,6 +15,8 @@ import { platformDataRoot } from "../src/repl-assembly.ts"; import { ReplEntryHost } from "../src/repl-entry-installation.ts"; import { SubmitRecord } from "../src/sidekick-acp/protocol.ts"; +const OWNER = "packages/cli/tests/repl-headless-submit-process.test.ts"; + function within(operation: Operation, evidence: () => unknown): Operation { return race([ operation, @@ -135,6 +138,7 @@ const QUESTION = 'Continue?'; describe("first SIGINT at the submit host boundary", () => { + beforeEach(journalBeforeEach(OWNER)); it("G: joins a blocked stdin read on the first SIGINT while its writer stays open", function* () { const home = yield* useTemporary("xmd-submit-process-home-"); const fixture = yield* useHeadlessFixture( diff --git a/packages/cli/tests/repl-headless-submit.test.ts b/packages/cli/tests/repl-headless-submit.test.ts index d11219dd7..d1d793d49 100644 --- a/packages/cli/tests/repl-headless-submit.test.ts +++ b/packages/cli/tests/repl-headless-submit.test.ts @@ -1,4 +1,5 @@ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { Err, Ok, ensure, race, scoped, sleep, spawn, suspend, withResolvers } from "effection"; import type { Operation } from "effection"; @@ -25,6 +26,8 @@ import { useSecretScannerFactory } from "../../core/src/secrets/policy.ts"; import { recordingTerminal } from "./support/mounted-repl.ts"; import { attachChildUi } from "../src/headless/ui.ts"; +const OWNER = "packages/cli/tests/repl-headless-submit.test.ts"; + type Fixture = ReturnType extends Operation ? T : never; function gate() { const entered = withResolvers(); @@ -111,6 +114,7 @@ const HOLD = '---\nreturns: {type: object}\n---\n\n'; describe("direct headless submission", () => { + beforeEach(journalBeforeEach(OWNER)); it("A: transfers a complete large UTF-8 program once, with consumption credit, values and project placement", function* () { const directory = yield* useTemporary("xmd-direct-project-"); yield* API.Env.around( diff --git a/packages/cli/tests/repl-headless.test.ts b/packages/cli/tests/repl-headless.test.ts index eb00623ba..f238ba669 100644 --- a/packages/cli/tests/repl-headless.test.ts +++ b/packages/cli/tests/repl-headless.test.ts @@ -3,7 +3,8 @@ import type { ReplPluginInstallation } from "../api.ts"; import { useSidekickAttachment } from "../src/sidekick-acp/server.ts"; import { attachChildUi } from "../src/headless/ui.ts"; import { sidekickAssembly } from "../src/repl/sidekick/assembly.ts"; -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { ensure, Err, race, scoped, sleep, spawn, suspend, until, withResolvers } from "effection"; import { API } from "@executablemd/runtime"; @@ -29,7 +30,10 @@ import { join } from "node:path"; import { makeRegistry, makeStore } from "./support/fake-acp.ts"; import { chmod, mkdtemp, realpath } from "node:fs/promises"; +const OWNER = "packages/cli/tests/repl-headless.test.ts"; + describe("parent-owned headless REPL", () => { + beforeEach(journalBeforeEach(OWNER)); it("H3: disconnect after accepted work reconnects exactly without resubmitting its effect", function* () { const held = yield* useHeadlessFixture(); const source = '{once}'; @@ -841,6 +845,7 @@ function* useManagedRecoveryChild(publicationFailure: { armed: boolean }) { } describe("987 — owned reference disposition", () => { + beforeEach(journalBeforeEach(OWNER)); for (const cut of ["publication", "active-unwind"]) { it(`keeps authoritative selection and reference lifetime at ${cut}`, function* () { const publication = { armed: false }; @@ -918,6 +923,7 @@ describe("987 — owned reference disposition", () => { }); describe("987 — original child input ownership", () => { + beforeEach(journalBeforeEach(OWNER)); it("keeps an entry question through inspection, UI detach and same-original recovery", function* () { const held = yield* useManagedRecoveryChild({ armed: false }); held.host.fake.script({ reply: "" }); @@ -999,6 +1005,7 @@ describe("987 — original child input ownership", () => { }); describe("REPL Plugin session ownership", () => { + beforeEach(journalBeforeEach(OWNER)); it("R2: parent and child initialize once; UI and history reads initialize nothing", function* () { const workspaces: string[] = []; const stopped: string[] = []; diff --git a/packages/cli/tests/repl-journey.test.ts b/packages/cli/tests/repl-journey.test.ts index 5b8e42390..aa79f8154 100644 --- a/packages/cli/tests/repl-journey.test.ts +++ b/packages/cli/tests/repl-journey.test.ts @@ -1,6 +1,7 @@ /** The mounted REPL journey, driven by terminal input and visible outcomes. */ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { ReplClock } from "../src/repl/frame.ts"; import { ReplHost } from "../src/repl/host.ts"; @@ -51,10 +52,13 @@ import { pasteDraft, } from "./support/screen-journeys.ts"; +const OWNER = "packages/cli/tests/repl-journey.test.ts"; + const WIDE = { columns: 160, rows: 36 }; const NARROW = { columns: 72, rows: 20 }; describe("REPL journey: a person drives the running command", () => { + beforeEach(journalBeforeEach(OWNER)); it("submits a Draft through the terminal and sees its settled History mark", function* () { const page = yield* useReplPage({ size: WIDE }); yield* pasteDraft(page, 'output("one done");'); @@ -151,6 +155,7 @@ const SECOND_COLD = '```js eval\nconst carried = `${token}-again`;\n```\n\nTwo: {carried}\n\n\n'; describe("REPL retained readings across every terminal size", () => { + beforeEach(journalBeforeEach(OWNER)); it("TL10: every size and a refusal keep the nested reading, and a cold open restores it", function* () { const dataRoot = yield* useTemporary("xmd-tl10-"); let path = ""; @@ -271,6 +276,7 @@ describe("REPL retained readings across every terminal size", () => { }); describe("REPL startup below the minimum terminal size", () => { + beforeEach(journalBeforeEach(OWNER)); it("J1: a terminal below the minimum refuses, and recovers when it grows", function* () { const terminal = yield* scoped(function* () { const page = yield* useReplPage({ size: { columns: 40, rows: 10 } }); @@ -354,6 +360,7 @@ function released(terminal: MountedRepl["terminal"]): void { } describe("REPL original admission and terminal exit claims", () => { + beforeEach(journalBeforeEach(OWNER)); it("J1: pasting the reference entry puts all of it in the draft and the location", function* () { const page = yield* referencePage(); const source = yield* referenceSource(); @@ -551,6 +558,7 @@ function* leaveRefusal(page: ReplPage) { } describe("REPL original refusals before replay and terminal ownership", () => { + beforeEach(journalBeforeEach(OWNER)); it("J1: Control-C leaves a refusal, and it is still a refusal", function* () { const { page } = yield* corruptPage(); expect(page.screen().shows("cannot read")).toBe(true); @@ -723,6 +731,7 @@ function* missingEntryRefusal() { } describe("REPL original retained readings and navigation", () => { + beforeEach(journalBeforeEach(OWNER)); it("J1: a second process reconstructs the view from the URL and the journal alone", function* () { const dataRoot = yield* useTemporary("xmd-binding-cold-"); let path = ""; @@ -883,6 +892,7 @@ function* interactionCost(page: ReplPage, send: () => Operation): Operatio } describe("REPL original interaction costs and visible exit routes", () => { + beforeEach(journalBeforeEach(OWNER)); for (const lines of [12, 222]) { it(`RS3: typing and traversing beside a ${lines}-line entry read the size a fixed number of times`, function* () { const page = yield* referencePage(); @@ -1076,6 +1086,7 @@ function* resumeOnce( } describe("REPL original pause-before-admission boundaries", () => { + beforeEach(journalBeforeEach(OWNER)); for (const size of [WIDE, { columns: 120, rows: 30 }, NARROW]) { it(`PPA2/PPA5: Pause is offered, requested and applied to the exact entry at ${size.columns}x${size.rows}`, function* () { const host = yield* useMountedHost({ includes: [REFERENCE_DIRECTORY] }); @@ -1429,6 +1440,7 @@ function* answerGo(page: ReplPage): Operation { } describe("REPL original live output and entry lifecycle", () => { + beforeEach(journalBeforeEach(OWNER)); it("J1: text the Journal has not settled is drawn while the run is held", function* () { const host = yield* useMountedHost(); const release = withResolvers(); @@ -1593,6 +1605,7 @@ function directions(one: ScreenReading): string { } describe("REPL original first-use paths and question ownership", () => { + beforeEach(journalBeforeEach(OWNER)); for (const size of [WIDE, NARROW]) { it( size.columns === 72 @@ -1766,6 +1779,7 @@ describe("REPL original first-use paths and question ownership", () => { }); describe("REPL original completed-screen lifecycle", () => { + beforeEach(journalBeforeEach(OWNER)); it("reads typing, diffs and every profile off completed presentations", function* () { yield* ReplHost.around( { @@ -1997,6 +2011,7 @@ function* fourEntries(page: ReplPage): Operation { } describe("REPL original complete History and cold catalog", () => { + beforeEach(journalBeforeEach(OWNER)); it("H5: the drawer reaches them all, and four resizes keep the reading", function* () { const page = yield* referencePage(); yield* fourEntries(page); @@ -2249,6 +2264,7 @@ function referencePageFor(dataRoot: string): Operation { } describe("REPL original visible guidance and controlled typing", () => { + beforeEach(journalBeforeEach(OWNER)); it("UI1: the visible History controls remain navigable at both sizes", function* () { for (const size of [WIDE, NARROW]) { yield* scoped(function* () { @@ -2345,6 +2361,7 @@ describe("REPL original visible guidance and controlled typing", () => { }); describe("REPL original held reading and canonical startup", () => { + beforeEach(journalBeforeEach(OWNER)); it("J1: run, hold at a gate, inspect a prefix, return live, continue, answer, settle", function* () { const host = yield* useMountedHost({ includes: [REFERENCE_DIRECTORY] }); const gate = preparationGate(); @@ -2405,6 +2422,7 @@ describe("REPL original held reading and canonical startup", () => { }); describe("REPL original presentation acknowledgement", () => { + beforeEach(journalBeforeEach(OWNER)); it("J1: a frame is not acknowledged until it has been presented", function* () { const host = yield* useMountedHost({ includes: [REFERENCE_DIRECTORY] }); const pending: Array<() => void> = []; @@ -2498,6 +2516,7 @@ function* retainedAnswerLines(page: ReplPage): Operation<{ first: string[]; seen } describe("REPL original retained schema and generated evidence", () => { + beforeEach(journalBeforeEach(OWNER)); it("J1: a recorded question reopens its whole schema and answer without work", function* () { const dataRoot = yield* useTemporary("xmd-recorded-answer-cold-"); const kept = yield* scoped(function* () { @@ -2606,6 +2625,7 @@ describe("REPL original retained schema and generated evidence", () => { }); describe("REPL original question arrival on another reading", () => { + beforeEach(journalBeforeEach(OWNER)); it("UI3: a question on Sessions moves nothing, and is reached by activating it", function* () { for (const size of [WIDE, NARROW]) { yield* scoped(function* () { @@ -2655,6 +2675,7 @@ describe("REPL original question arrival on another reading", () => { }); describe("REPL original surface and entry selection marks", () => { + beforeEach(journalBeforeEach(OWNER)); it("UI1: the active surface and the selected entry are marked in the frame", function* () { for (const size of [WIDE, NARROW]) { yield* scoped(function* () { diff --git a/packages/cli/tests/repl-layout-admission.test.ts b/packages/cli/tests/repl-layout-admission.test.ts index be4dfd90d..000f525b0 100644 --- a/packages/cli/tests/repl-layout-admission.test.ts +++ b/packages/cli/tests/repl-layout-admission.test.ts @@ -18,7 +18,8 @@ import { parseTodo } from "../src/repl/todo/document.ts"; * told and from nothing else. */ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { Elicitation, collect, inlineSource, useTempFileCompiler } from "@executablemd/core"; import { executeInstalled } from "@executablemd/core/host"; @@ -67,6 +68,8 @@ import { useReplPage } from "./support/repl-page.ts"; import type { ReplPage } from "./support/repl-page.ts"; import { entrySettles, intoDraft, pasteDraft } from "./support/screen-journeys.ts"; +const OWNER = "packages/cli/tests/repl-layout-admission.test.ts"; + /** * The two cells in front of a control's label that its focus marker draws in. * @@ -585,6 +588,7 @@ describe("REPL layout: what an action row admits", () => { }); describe("REPL layout: what a shrinking reading leaves behind", () => { + beforeEach(journalBeforeEach(OWNER)); /** One journal whose whole reading is the long one, and one that is short. */ function* readings(): Operation<{ long: ReplModel; short: ReplModel }> { return { @@ -1754,6 +1758,7 @@ describe("Owned Transcript control geometry", () => { }); describe("accepted rendered scrolling guidance", () => { + beforeEach(journalBeforeEach(OWNER)); for (const size of [MEDIUM, NARROW]) { it(`Content and reading help fit whole at ${size.columns}x${size.rows}`, function* () { const page = yield* useReplPage({ size }); diff --git a/packages/cli/tests/repl-page.test.ts b/packages/cli/tests/repl-page.test.ts index 615f9ed76..3952ade82 100644 --- a/packages/cli/tests/repl-page.test.ts +++ b/packages/cli/tests/repl-page.test.ts @@ -12,7 +12,8 @@ * actually draws; nothing here asks the command where it put something. */ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import type { Operation } from "effection"; @@ -21,6 +22,8 @@ import type { ReplPage, ScreenCell, ScreenScope } from "./support/repl-page.ts"; import { awaited } from "./support/mounted-repl.ts"; import { intoDraft } from "./support/screen-journeys.ts"; +const OWNER = "packages/cli/tests/repl-page.test.ts"; + const WIDE = { columns: 160, rows: 36 }; const NARROW = { columns: 72, rows: 20 }; const BELOW = { columns: 60, rows: 15 }; @@ -68,6 +71,7 @@ function* typed(page: ReplPage, text: string): Operation { } describe("REPL page — two Sends, told apart by what is drawn beside them", () => { + beforeEach(journalBeforeEach(OWNER)); it("resolves each Send within its scope and refuses an ambiguous Send", function* () { const page = yield* useReplPage({ size: WIDE }); @@ -123,6 +127,7 @@ describe("REPL page — two Sends, told apart by what is drawn beside them", () }); describe("REPL page — resize, a modal, and writes that never land", () => { + beforeEach(journalBeforeEach(OWNER)); it("keeps the draft across every size and refuses a pane the size removed", function* () { const page = yield* useReplPage({ size: WIDE }); yield* intoDraft(page); @@ -174,6 +179,7 @@ describe("REPL page — resize, a modal, and writes that never land", () => { }); describe("REPL page — a column is a terminal cell, not a string offset", () => { + beforeEach(journalBeforeEach(OWNER)); it("locates a label after a wide glyph at the cell it is really drawn in", function* () { const page = yield* useReplPage({ size: WIDE }); yield* intoDraft(page); @@ -264,6 +270,7 @@ function* asked(page: ReplPage, text: string, shown: string): Operation { } describe("REPL page — reaching a field the claim names, by keyboard", () => { + beforeEach(journalBeforeEach(OWNER)); it("puts a person's own entry in the Draft after a Sidekick exchange", function* () { const page = yield* useReplPage({ size: WIDE }); page.repl.fake.script({ reply: "AUTHORED\n" }); diff --git a/packages/cli/tests/repl-paged-history.test.ts b/packages/cli/tests/repl-paged-history.test.ts index f3a4f951b..35b43e15a 100644 --- a/packages/cli/tests/repl-paged-history.test.ts +++ b/packages/cli/tests/repl-paged-history.test.ts @@ -1,4 +1,5 @@ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { useTempDirectory } from "@executablemd/test-support/temp"; import { Elicitation, INLINE_SOURCE_PATH } from "@executablemd/core"; @@ -29,6 +30,8 @@ import { awaited, useMountedHost } from "./support/mounted-repl.ts"; import { useReplPage } from "./support/repl-page.ts"; import { DRAFT_VALUE, pasteDraft, SIDEKICK_PANE } from "./support/screen-journeys.ts"; +const OWNER = "packages/cli/tests/repl-paged-history.test.ts"; + function admission(content: string): DurableEvent { return { type: "yield", @@ -77,6 +80,7 @@ function* useWriter(): Operation { } describe("Paged REPL history", () => { + beforeEach(journalBeforeEach(OWNER)); it("matches the whole projection at each position and finds older binding publishers", function* () { const path = join(yield* useTempDirectory("xmd-pages-"), "entries.jsonl"); const records: DurableEvent[] = [ diff --git a/packages/cli/tests/repl-plugin.test.ts b/packages/cli/tests/repl-plugin.test.ts index d9a80832b..0f263c1e1 100644 --- a/packages/cli/tests/repl-plugin.test.ts +++ b/packages/cli/tests/repl-plugin.test.ts @@ -1,4 +1,5 @@ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { createContext, ensure, scoped, sleep, spawn, suspend, withResolvers } from "effection"; import type { Operation } from "effection"; @@ -13,6 +14,8 @@ import { useReplLiveScreen } from "../src/repl/live-screen.ts"; import { usePluginProgram } from "./support/plugin-program.ts"; import { useMountedHost } from "./support/mounted-repl.ts"; +const OWNER = "packages/cli/tests/repl-plugin.test.ts"; + const Session = createContext<{ workspace: string; calls: number }>("test.repl-plugin.session"); const props = { type: "object", properties: {}, additionalProperties: false }; function fixture(name: string, events: string[], counts: { factories: number }) { @@ -75,6 +78,7 @@ function fixture(name: string, events: string[], counts: { factories: number }) } describe("Selected REPL Plugin contributions", () => { + beforeEach(journalBeforeEach(OWNER)); it("R1/R5: collection and descriptions start no service; ordered setup shares session state", function* () { const events: string[] = []; const counts = { factories: 0 }; diff --git a/packages/cli/tests/repl-presentation-style.test.ts b/packages/cli/tests/repl-presentation-style.test.ts index d2b012a58..5036b5ac5 100644 --- a/packages/cli/tests/repl-presentation-style.test.ts +++ b/packages/cli/tests/repl-presentation-style.test.ts @@ -21,7 +21,8 @@ import { parseTodo } from "../src/repl/todo/document.ts"; * chose. */ -import { beforeAll, describe, it } from "@executablemd/test-support/bdd"; +import { beforeAll, beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { close, fit, open, text } from "../generated/tty/mod.js"; import { @@ -153,6 +154,8 @@ import { submitReplEntry } from "../src/repl/session.ts"; import type { ReplSession } from "../src/repl/session.ts"; import type { CellStyle, Observed, Presenter, TerminalGrid } from "./fixtures/repl/presentation.ts"; +const OWNER = "packages/cli/tests/repl-presentation-style.test.ts"; + const WIDE: ReplTerminalSize = { columns: 160, rows: 36 }; const MEDIUM: ReplTerminalSize = { columns: 120, rows: 30 }; /** The large frame the History rows drive, where the drawer sits lower. */ @@ -5211,6 +5214,7 @@ function stagedView(model: ReplModel, size: ReplTerminalSize): ReplView { * to keep; the archive's own inks are the appearance rows above. */ describe("Checkpoint #971 — the workspace screen at 160x36", () => { + beforeEach(journalBeforeEach(OWNER)); beforeAll(() => useTempFileCompiler()); it("C1/C2: every surface is placed whole, wraps inside its region and keeps its styles", function* () { @@ -5723,6 +5727,7 @@ describe("Checkpoint #971 — the workspace screen at 160x36", () => { }); describe("Checkpoint #971 A2 — the workspace at the two smaller sizes", () => { + beforeEach(journalBeforeEach(OWNER)); beforeAll(() => useTempFileCompiler()); it("A2: every size places whole controls inside the frame and keeps its routes", function* () { @@ -5959,6 +5964,7 @@ describe("Checkpoint #971 A2 — the workspace at the two smaller sizes", () => * Whether it looks right is the image review's answer, not a test's. */ describe("Checkpoint #971 A4 — current outcomes, work and the waiting question", () => { + beforeEach(journalBeforeEach(OWNER)); it("A4: every outcome, work identity and the waiting question read from the current screen", function* () { const page = yield* reachOutcomes(WIDE); const { model } = yield* settledReading(page.repl); @@ -6059,6 +6065,7 @@ describe("Checkpoint #971 A4 — current outcomes, work and the waiting question * */ describe("Checkpoint #971 R2 — current chat windows and outcomes", () => { + beforeEach(journalBeforeEach(OWNER)); it("R2: current chat traversal reads every outcome and keeps its composer", function* () { const page = yield* reachOutcomes(WIDE); // The size whose conversation still holds more than it shows. @@ -6096,6 +6103,7 @@ describe("Checkpoint #971 R2 — current chat windows and outcomes", () => { }); describe("REPL presentation: the screen says what is placed", () => { + beforeEach(journalBeforeEach(OWNER)); it("keeps the shell and its readable surfaces at the supported sizes", function* () { const page = yield* useReplPage({ size: WIDE }); yield* page.type("\x074"); diff --git a/packages/cli/tests/repl-project-files.test.ts b/packages/cli/tests/repl-project-files.test.ts index 58a7bd566..951d3bfd9 100644 --- a/packages/cli/tests/repl-project-files.test.ts +++ b/packages/cli/tests/repl-project-files.test.ts @@ -8,7 +8,8 @@ import { InMemoryStream } from "@executablemd/durable-streams"; import { collect, inlineSource, registerComponents } from "@executablemd/core"; import { executeInstalled } from "@executablemd/core/host"; import { replRepositoryInstallation } from "../src/repl/repositories/deno/provider.ts"; -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { ensureDir, readTextFile, writeTextFile, exists } from "@effectionx/fs"; import { @@ -42,11 +43,14 @@ import type { ReplPage, ScreenReading } from "./support/repl-page.ts"; import { settledReading } from "./support/mounted-history.ts"; import { pairedLocation } from "../src/repl/sidekick/history.ts"; +const OWNER = "packages/cli/tests/repl-project-files.test.ts"; + function submit(source: string): string { return `{code}`; } describe("1113: project files through the mounted Sidekick", () => { + beforeEach(journalBeforeEach(OWNER)); it("1113: submitted work starts in P, scopes session source and assets, and restores sibling cwd", function* () { const project = yield* useTemporary("1113-project-"); const host = yield* useMountedHost({ projectCwd: project, hostFiles: true }); @@ -288,6 +292,7 @@ describe("1113: transformed Files requests", () => { }); describe("1113: executable capture teaching", () => { + beforeEach(journalBeforeEach(OWNER)); it("1113: runs the complete shipped passive-source response and reads the exact entry output", function* () { const project = yield* useTemporary("1113-capture-"); const page = yield* useReplPage({ projectCwd: project, hostFiles: true }); @@ -323,6 +328,7 @@ describe("1113: executable capture teaching", () => { }); describe("1113: session scopes retain their restrictions", () => { + beforeEach(journalBeforeEach(OWNER)); it("1113 M1: outer Content keeps AssetDir write denial after middleware redirects into P", function* () { const project = yield* useTemporary("1113-asset-redirect-project-"); const redirects: { @@ -613,6 +619,7 @@ function* reportPagingFailure( } describe("1113: receipt-directed exact output paging", () => { + beforeEach(journalBeforeEach(OWNER)); it("1113: follows the receipt's entry and each returned next argument until exact output is complete", function* () { const project = yield* useTemporary("1113-output-"); const page = yield* useReplPage({ projectCwd: project, hostFiles: true }); @@ -781,6 +788,7 @@ describe("1113: receipt-directed exact output paging", () => { }); describe("1113: project selection belongs to the actual entry", () => { + beforeEach(journalBeforeEach(OWNER)); it("1113: a fresh response and both entry origins observe P while storage is elsewhere", function* () { const project = yield* useTemporary("1113-owner-project-"); const page = yield* useReplPage({ projectCwd: project, hostFiles: true }); diff --git a/packages/cli/tests/repl-project-recovery.test.ts b/packages/cli/tests/repl-project-recovery.test.ts index ffbad5270..2b348950e 100644 --- a/packages/cli/tests/repl-project-recovery.test.ts +++ b/packages/cli/tests/repl-project-recovery.test.ts @@ -11,7 +11,8 @@ import { runXmd } from "../src/cli.ts"; import { Elicitation } from "@executablemd/core"; import { Plugin } from "@executablemd/core/api"; import { unsupportedWorkflowHost } from "../src/workflow.ts"; -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { readTextFile, writeTextFile, exists, rm, ensureDir } from "@effectionx/fs"; import { API, cwd, Permissions } from "@executablemd/runtime"; @@ -35,6 +36,8 @@ import { import { useReplPage } from "./support/repl-page.ts"; import { pasteDraft, sendMessage } from "./support/screen-journeys.ts"; +const OWNER = "packages/cli/tests/repl-project-recovery.test.ts"; + function columnOf(cells: readonly string[], label: string): number { const offset = cells.join("").indexOf(label); let text = 0; @@ -103,6 +106,7 @@ function* saved(sidekick = false) { } describe("1113: project placement before live recovery", () => { + beforeEach(journalBeforeEach(OWNER)); it("1113: records the strict pair and needs no answer at the original root or an alias", function* () { const held = yield* saved(); const reopened = yield* held.host.repository.open(held.id); @@ -530,6 +534,7 @@ describe("1113: project placement before live recovery", () => { }); describe("1113: unavailable access and conflicting placement", () => { + beforeEach(journalBeforeEach(OWNER)); it("1113: diagnoses an access refusal without offering another path", function* () { const directory = yield* useTemporary("1113-inaccessible-"); let accessed = ""; diff --git a/packages/cli/tests/repl-restore-progress.test.ts b/packages/cli/tests/repl-restore-progress.test.ts index b4d6d861c..c0ddc5411 100644 --- a/packages/cli/tests/repl-restore-progress.test.ts +++ b/packages/cli/tests/repl-restore-progress.test.ts @@ -2,7 +2,8 @@ import process from "node:process"; import { readTextFile, writeTextFile } from "@effectionx/fs"; import { Agent, AgentProviders } from "@executablemd/agent/api"; import { API } from "@executablemd/runtime"; -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { createContext, ensure, race, scoped, sleep, spawn, withResolvers } from "effection"; import type { Operation } from "effection"; @@ -18,6 +19,8 @@ import type { Terminal } from "./support/mounted-repl.ts"; import { invalidRestoreEntries, savedRestoreFixture } from "./support/restore-progress.ts"; import type { RetainedRestoreFixture } from "./support/restore-progress.ts"; +const OWNER = "packages/cli/tests/repl-restore-progress.test.ts"; + const WIDE = { columns: 160, rows: 36 }; const MEDIUM = { columns: 120, rows: 30 }; const NARROW = { columns: 72, rows: 20 }; @@ -221,6 +224,7 @@ function settled( } describe("#1037 cold restore progress", () => { + beforeEach(journalBeforeEach(OWNER)); it("draws projected rounds, resizes, then waits for Sidekick before opening the original view", function* () { const held = yield* savedRestoreFixture(yield* useMountedHost(), 155); const rounds = gate(); diff --git a/packages/cli/tests/repl-sidekick-acp.test.ts b/packages/cli/tests/repl-sidekick-acp.test.ts index 609865f24..5515005cc 100644 --- a/packages/cli/tests/repl-sidekick-acp.test.ts +++ b/packages/cli/tests/repl-sidekick-acp.test.ts @@ -6,7 +6,8 @@ import { sidekickCeilingInstallation, } from "../src/repl/sidekick/profile.ts"; import { runSidekickCommand } from "../src/sidekick-acp/command.ts"; -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { cliCommand, cliShellCommand, shellQuote } from "@executablemd/test-support/launch"; import { readTextFile, writeTextFile } from "@effectionx/fs"; @@ -100,6 +101,8 @@ import { journalReplyBound, } from "../src/sidekick-acp/protocol.ts"; +const OWNER = "packages/cli/tests/repl-sidekick-acp.test.ts"; + const ROOT = fileURLToPath(new URL("../../../", import.meta.url)); const attachResult = z.object({ attachment: z.string() }).strict(); const message = z @@ -2500,6 +2503,7 @@ describe("A5: a peer the listener accepts after teardown begins", () => { }); describe("ACP startup bootstrap", () => { + beforeEach(journalBeforeEach(OWNER)); it("creates a real initial message without UI input and joins the first external prompt", function* () { yield* usePosixSidekickTransport(process.platform); const home = yield* until(realpath(yield* useTemporary("xmd-acp-startup-"))); @@ -3653,6 +3657,7 @@ describe("ACP82: the file this publication keeps open", () => { }); describe("resume presentation in mounted Sidekick chat", () => { + beforeEach(journalBeforeEach(OWNER)); const actionable = "Release first."; const credential = ["ghp", "_", "abcdefghijklmnopqrstuvwxyz0123456789"].join(""); const remedy = "could not be resumed"; @@ -3794,6 +3799,7 @@ describe("resume presentation in mounted Sidekick chat", () => { }); describe("Follow: joined mixed-origin queue handoff", () => { + beforeEach(journalBeforeEach(OWNER)); it("Follow: mounted UI and delivered ACP stay FIFO behind entry and generated-control cleanup", function* () { yield* usePosixSidekickTransport(process.platform); const home = yield* publishingHome("xmd-follow-queue-"); diff --git a/packages/cli/tests/repl-sidekick-configuration.test.ts b/packages/cli/tests/repl-sidekick-configuration.test.ts index 72c37c239..4f440c8c2 100644 --- a/packages/cli/tests/repl-sidekick-configuration.test.ts +++ b/packages/cli/tests/repl-sidekick-configuration.test.ts @@ -19,7 +19,8 @@ * association rather than a conversation's agent. */ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { ensure, Ok, scoped, sleep, spawn } from "effection"; import type { Operation, Result, Task } from "effection"; @@ -156,6 +157,8 @@ import { createRepositoryRoot, runPhase } from "./fixtures/repl/issue-883/host.t import { AGENT, useHarness, useTemporary } from "./fixtures/repl/issue-883/sidekick-harness.ts"; import type { Harness } from "./fixtures/repl/issue-883/sidekick-harness.ts"; +const OWNER = "packages/cli/tests/repl-sidekick-configuration.test.ts"; + /** A second agent, named explicitly rather than defaulted to. */ const OTHER = "other-sidekick"; @@ -905,6 +908,7 @@ function outside(page: ReplPage): string[] { } describe("Tier CFG — Configure in the Sidekick's pane", () => { + beforeEach(journalBeforeEach(OWNER)); /** What this agent offers, and what each of its models offers for effort. */ const ADVERTISED = { model: { @@ -1504,6 +1508,7 @@ describe("Tier CFG — Configure in the Sidekick's pane", () => { * agent's choices goes with the replacement. */ describe("Tier CFG — replacing the Sidekick's agent", () => { + beforeEach(journalBeforeEach(OWNER)); const ADVERTISED = { model: { selected: "balanced", @@ -1869,6 +1874,7 @@ describe("Tier CFG — replacing the Sidekick's agent", () => { * explicit job does to another. */ describe("Tier CFG — one order for everything this conversation writes", () => { + beforeEach(journalBeforeEach(OWNER)); const ADVERTISED = { model: { selected: "balanced", @@ -2033,6 +2039,7 @@ describe("Tier CFG — one order for everything this conversation writes", () => }); describe("Tier CFG — Retry for a request whose turn failed", () => { + beforeEach(journalBeforeEach(OWNER)); it("CFG5: Retry sends the saved request again, not whatever is in the box", function* () { const page = yield* useReplPage(); const repl = page.repl; @@ -2220,6 +2227,7 @@ describe("Tier CFG — Retry for a request whose turn failed", () => { * exercising every flag and the interactive screen at once is not this row. */ describe("Tier TE — the two configured agents each do their own work", () => { + beforeEach(journalBeforeEach(OWNER)); /** One entry asking one Agent, naming no agent: the default is the subject. */ const ASKING = ['', '', ""].join("\n"); @@ -2295,6 +2303,7 @@ describe("Tier TE — the two configured agents each do their own work", () => { * field, so these rows drive the width of a notice the way a person does. */ describe("Configure notice fitting", () => { + beforeEach(journalBeforeEach(OWNER)); /** What the agent in these rows advertises, so the drawer has choices to draw. */ const ADVERTISED = { model: { diff --git a/packages/cli/tests/repl-sidekick-dispatch.test.ts b/packages/cli/tests/repl-sidekick-dispatch.test.ts index f77fbc576..32cb02aca 100644 --- a/packages/cli/tests/repl-sidekick-dispatch.test.ts +++ b/packages/cli/tests/repl-sidekick-dispatch.test.ts @@ -1,4 +1,5 @@ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { ensure, Ok, scoped, spawn, suspend, withResolvers } from "effection"; import type { Operation, Result } from "effection"; @@ -34,6 +35,8 @@ import { sidekickIdle, } from "./support/screen-journeys.ts"; +const OWNER = "packages/cli/tests/repl-sidekick-dispatch.test.ts"; + function service( held: Harness, admission = createSidekickAdmission(), @@ -78,6 +81,7 @@ function fills(source: string): string { } describe("shared Sidekick dispatch", () => { + beforeEach(journalBeforeEach(OWNER)); for (const busy of [false, true]) { it(`keeps one pasted Message at its caret while ${busy ? "busy" : "idle"}`, function* () { const page = yield* useReplPage(); diff --git a/packages/cli/tests/repl-sidekick-journey.test.ts b/packages/cli/tests/repl-sidekick-journey.test.ts index f5080263e..26fc23bd9 100644 --- a/packages/cli/tests/repl-sidekick-journey.test.ts +++ b/packages/cli/tests/repl-sidekick-journey.test.ts @@ -36,7 +36,8 @@ import { pairedLocation } from "../src/repl/sidekick/history.ts"; import { encodeLocation } from "../src/repl/route.ts"; import { initialState } from "../src/repl/application.ts"; -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { allSettled, @@ -120,6 +121,8 @@ import { unwrapped, } from "./support/screen-journeys.ts"; +const OWNER = "packages/cli/tests/repl-sidekick-journey.test.ts"; + /** * The orientation an older build left on a conversation it completed a turn of. * @@ -1216,6 +1219,7 @@ function* composedChat(repl: MountedRepl): Operation { * item then becomes the evaluated reply. */ describe("Tier PV — a response in flight, shown as it arrives", () => { + beforeEach(journalBeforeEach(OWNER)); /** * A reply whose text arrives in pieces, with candidate controls in it. * @@ -1710,6 +1714,7 @@ const GATED_ENTRY_REPLY = [ ].join("\n"); describe("Tier R5 — a mounted message prepares and submits a real entry", () => { + beforeEach(journalBeforeEach(OWNER)); it("M3: the message a person sends runs its entry, and is answered about it", function* () { const page = yield* useReplPage(); const repl = page.repl; @@ -2052,6 +2057,7 @@ describe("Tier R5 — a mounted message prepares and submits a real entry", () = * both arms identically. */ describe("Tier TE — a published binding becomes real greetings, and then a real table", () => { + beforeEach(journalBeforeEach(OWNER)); /** What the first arm publishes. */ const FIRST = ["Ada", "Grace", "Linus"]; /** The same arm with one name replaced, and nothing else changed. */ @@ -2301,6 +2307,7 @@ describe("Tier TE — a published binding becomes real greetings, and then a rea * authors becomes a second real entry while the first stays exactly as it failed. */ describe("Tier TE — a failed entry is corrected as a new entry", () => { + beforeEach(journalBeforeEach(OWNER)); it("TE2: the failure goes back to its owner, which submits a corrected entry", function* () { const page = yield* useReplPage(); const repl = page.repl; @@ -3410,6 +3417,7 @@ describe("Tier EI — four reads make a saved failure diagnosable", () => { }); describe("975 — the shipped session component journey", () => { + beforeEach(journalBeforeEach(OWNER)); it("creates, discovers and invokes a component, then reopens without work", function* () { yield* Permissions.around( { files: ([operation], next) => (operation === "absolute" ? true : next(operation)) }, @@ -3662,6 +3670,7 @@ describe("975 — entry cwd ends with its actual owner", () => { }); describe("975 — configured-first lookup and unchanged permissions", () => { + beforeEach(journalBeforeEach(OWNER)); function submitSource(source: string): string { return ( '\n```xmd\n' + @@ -4001,6 +4010,7 @@ function followSubmission(source: string): string { } describe("Follow: submitted rounds in the running command", () => { + beforeEach(journalBeforeEach(OWNER)); it("Follow: one mounted Send carries completed, failed and Entry Stop output from exact joined entries", function* () { const asking = withResolvers(); yield* Elicitation.around({ @@ -4569,6 +4579,7 @@ Session body ${version}.`, }); describe("993 mounted nested Output journeys", () => { + beforeEach(journalBeforeEach(OWNER)); for (const ready of [true, false]) { it(`W1: an actual Draft entry selects branch ${ready} and only that marker`, function* () { const workspace = yield* useTemporary("nested-repl-"); @@ -4764,6 +4775,7 @@ describe("993 mounted nested Output journeys", () => { }); describe("Contributed Sidekick controls", () => { + beforeEach(journalBeforeEach(OWNER)); it("keeps contributed entry-only Cwd authored while omitting generated selection and vocabulary", function* () { let calls = 0; const plugin = Plugin({ @@ -5155,6 +5167,7 @@ describe("protected Sidekick question feedback", () => { }); describe("1183 — a follow-up sent during live automatic feedback", () => { + beforeEach(journalBeforeEach(OWNER)); it("A1/A2: queues visibly behind the held feedback and starts once on the same conversation", function* () { const page = yield* useReplPage(); const FOLLOW_UP = "When that finishes, explain the changes."; @@ -5222,6 +5235,7 @@ describe("1183 — a follow-up sent during live automatic feedback", () => { * entry's Output all keep the punctuation around it. */ describe("1342 — written Markdown in the chat and in entry Output", () => { + beforeEach(journalBeforeEach(OWNER)); const WIDE_SIZE = { columns: 160, rows: 36 }; const NARROW_SIZE = { columns: 72, rows: 20 }; const ENTRY_MARKDOWN = [ diff --git a/packages/cli/tests/repl-sidekick-lifecycle.test.ts b/packages/cli/tests/repl-sidekick-lifecycle.test.ts index c73c1318d..fa179d817 100644 --- a/packages/cli/tests/repl-sidekick-lifecycle.test.ts +++ b/packages/cli/tests/repl-sidekick-lifecycle.test.ts @@ -25,7 +25,8 @@ import type { Contributions } from "./fixtures/repl/contributed-plugin.ts"; * owner, an answer and a withdrawal whether or not anything is drawing it. */ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import type { SidekickOperation } from "../src/repl/sidekick/model.ts"; import { ensure, Ok, sleep, spawn, suspend, until, withResolvers } from "effection"; @@ -101,6 +102,8 @@ import { join } from "node:path"; import { readFile } from "node:fs/promises"; import type { SidekickRecord } from "../src/repl/sidekick/history.ts"; +const OWNER = "packages/cli/tests/repl-sidekick-lifecycle.test.ts"; + /** * Real time for an assertion that something did not happen. * @@ -932,6 +935,7 @@ describe("Tier R6 — a reply asks, and the Sidekick owns the answer", () => { * said as one, and only as much of one as was actually saved. */ describe("Tier PV — generation that ended without a reply", () => { + beforeEach(journalBeforeEach(OWNER)); /** A candidate that says something and then asks for work to be done. */ const CANDIDATE = [ "As far as I got.\n", @@ -1204,6 +1208,7 @@ describe("Tier PV — generation that ended without a reply", () => { }); describe("Tier R6 — leaving, with Sidekick work in flight", () => { + beforeEach(journalBeforeEach(OWNER)); /** An entry that publishes nothing and stays open until it is torn down. */ const SUSPENDS = ["```js eval", "yield* suspend();", "```", ""].join("\n"); @@ -1315,6 +1320,7 @@ describe("Tier R6 — leaving, with Sidekick work in flight", () => { * terminal sends are text there, and only a plain Enter sends. */ describe("Control-C and newlines in the message box", () => { + beforeEach(journalBeforeEach(OWNER)); function* composing(text: string): Operation { const page = yield* useReplPage(); yield* intoComposer(page); @@ -1514,6 +1520,7 @@ describe("Control-C and newlines in the message box", () => { * tree, with only the terminal and the transport replaced. */ describe("Tier MQ — a Sidekick question, filled in and answered on the screen", () => { + beforeEach(journalBeforeEach(OWNER)); /** A choice, and a reason long enough that a short one is a real refusal. */ const REVIEW = { type: "object", @@ -1685,6 +1692,7 @@ describe("Tier MQ — a Sidekick question, filled in and answered on the screen" * answers, and a Stop that withdraws one without inventing an answer to either. */ describe("Tier MQ — two questions, two answers, and Stop", () => { + beforeEach(journalBeforeEach(OWNER)); /** Overlapping field names, so an answer reaching the wrong form would show. */ const SIDEKICK_ASKS = { type: "object", @@ -1854,6 +1862,7 @@ describe("Tier MQ — two questions, two answers, and Stop", () => { * leaves a readable account of what it was in the middle of. */ describe("Tier MQ — leaving with questions pending, and the cold reopen after", () => { + beforeEach(journalBeforeEach(OWNER)); const ASKS = { type: "object", properties: { choice: { type: "string", enum: ["yes", "no"] } }, @@ -1985,6 +1994,7 @@ describe("Tier MQ — leaving with questions pending, and the cold reopen after" * written nothing publishes nothing. */ describe("Tier CFG — a preference being written when the command leaves", () => { + beforeEach(journalBeforeEach(OWNER)); const ADVERTISED = { model: { selected: "balanced", @@ -2177,6 +2187,7 @@ describe("Tier CFG — a preference being written when the command leaves", () = }); describe("Follow: mounted Stop owns continuation", () => { + beforeEach(journalBeforeEach(OWNER)); it("Follow: Sidekick Stop preserves the setting and a late entry result cannot restart the Send", function* () { const entered = withResolvers(); const release = withResolvers(); @@ -2249,6 +2260,7 @@ describe("Follow: mounted Stop owns continuation", () => { }); describe("Contributed control acknowledgement and teardown", () => { + beforeEach(journalBeforeEach(OWNER)); it("R4f: intent acknowledgement and joined cleanup precede outcome and feedback", function* () { const counts: Contributions = { initialized: 0, conversations: 0, closed: 0, calls: [] }; const gate = appendGate(); diff --git a/packages/cli/tests/repl-sidekick-presentation.test.ts b/packages/cli/tests/repl-sidekick-presentation.test.ts index 06b9400c1..494ee6271 100644 --- a/packages/cli/tests/repl-sidekick-presentation.test.ts +++ b/packages/cli/tests/repl-sidekick-presentation.test.ts @@ -33,7 +33,8 @@ import type { SidekickRecord } from "../src/repl/sidekick/history.ts"; import { awaitedFact } from "./support/mounted-repl.ts"; import { settledReading } from "./support/mounted-history.ts"; import type { ReplPage, ScreenReading } from "./support/repl-page.ts"; -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import type { Operation } from "effection"; import { expect } from "@executablemd/test-support/expect"; @@ -69,6 +70,8 @@ import { typed, } from "./support/screen-journeys.ts"; +const OWNER = "packages/cli/tests/repl-sidekick-presentation.test.ts"; + const WIDE = { columns: 160, rows: 36 }; const NARROW = { columns: 72, rows: 20 }; @@ -140,6 +143,7 @@ function* focusMessage(page: ReplPage): Operation { } describe("987 — mounted original recovery", () => { + beforeEach(journalBeforeEach(OWNER)); for (const size of [WIDE, { columns: 120, rows: 30 }, NARROW]) { it(`reads actual saved multiline entry feedback by keyboard at ${size.columns} columns`, function* () { const page = yield* useReplPage({ size: WIDE }); @@ -294,6 +298,7 @@ describe("987 — mounted original recovery", () => { }); describe("Sidekick presentation: visible work owns its controls", () => { + beforeEach(journalBeforeEach(OWNER)); it("sends one message through the Sidekick pane and reads the reply", function* () { const page = yield* useReplPage({ size: WIDE }); page.repl.fake.script({ reply: "Noted.\n" }); @@ -367,6 +372,7 @@ function* exchange(page: ReplPage, text: string, answer: string): Operation { + beforeEach(journalBeforeEach(OWNER)); it("CF1: a message with its own lines keeps every one of them when the next arrives", function* () { const page = yield* useReplPage({ size: WIDE }); const wide = "a-very-long-line-that-cannot-fit-this-pane-and-must-be-cut-across-rows"; @@ -514,6 +520,7 @@ function sendComposed(page: ReplPage): Operation { } describe("Sidekick acquisition, durable handoff and acknowledgements", () => { + beforeEach(journalBeforeEach(OWNER)); it("M1: a fresh command shows its Sidekick, asks the agent nothing, and focuses Message", function* () { const page = yield* useReplPage({ size: WIDE }); const first = page.screen(); @@ -752,6 +759,7 @@ function entryTrail(reading: ScreenReading): string { } describe("Sidekick texts and reading across every profile", () => { + beforeEach(journalBeforeEach(OWNER)); it("M7: all three profiles keep both texts, the footer and one body", function* () { const page = yield* useReplPage(); yield* draftText(page, "note"); @@ -916,6 +924,7 @@ function* submittedUnderEdit( } describe("Sidekick submission held to the current Draft", () => { + beforeEach(journalBeforeEach(OWNER)); it("M-P2: a Draft edit during preflight admits no stale entry, and the edit survives", function* () { const result = yield* submittedUnderEdit(true); expect(result.entries).toEqual([]); @@ -999,6 +1008,7 @@ function* filledQuestion(): Operation { } describe("Sidekick question announcement and modal ownership", () => { + beforeEach(journalBeforeEach(OWNER)); it("MQ1: the notice arrives with nothing pressed, and only opening shows the form", function* () { const gate = appendGate(); const page = yield* useReplPage({ gate }); @@ -1079,6 +1089,7 @@ function* configured(page: ReplPage): Operation { } describe("PV3/PV4: question and Configure editing", () => { + beforeEach(journalBeforeEach(OWNER)); it("keeps each value's middle caret across close and a held History drawer", function* () { const page = yield* useReplPage(); page.repl.fake.configuration(ADVERTISED); @@ -1139,6 +1150,7 @@ describe("PV3/PV4: question and Configure editing", () => { }); describe("Configure keyboard, retained values and window ownership", () => { + beforeEach(journalBeforeEach(OWNER)); it("CFG6: local arrows reach Configure choices, and Close or Escape return to its opener", function* () { const page = yield* useReplPage(); page.repl.fake.configuration(ADVERTISED); @@ -1361,6 +1373,7 @@ function* backToCurrent(page: ReplPage, reply = "Newer answer."): Operation { + beforeEach(journalBeforeEach(OWNER)); it("SS1: both sections hold their own work, settled in the order each finishes", function* () { const page = yield* useReplPage(); page.repl.fake.script({ held: true, reply: "ENTRY-DONE" }); @@ -1627,6 +1640,7 @@ function* questionThroughKeyboard(explicit: boolean): Operation { } describe("Sidekick resize ownership", () => { + beforeEach(journalBeforeEach(OWNER)); it("Q-P1: a form hidden by a resize does not consume Draft typing", function* () { const page = yield* questionThroughKeyboard(false); const narrow = yield* page.resize(NARROW); @@ -1720,6 +1734,7 @@ function atSize(page: ReplPage, size: { columns: number; rows: number }): Operat } describe("Sidekick drawers across every supported size", () => { + beforeEach(journalBeforeEach(OWNER)); it("MQ4: the form stays inside its own pane at every size, and survives a refusal", function* () { const page = yield* useReplPage(); yield* draftText(page, "mine"); @@ -1864,6 +1879,7 @@ function* refusedLocation(host: MountedHost, location: string): Operation { + beforeEach(journalBeforeEach(OWNER)); it("SS2: a current failure read beside an older chat leaves its items alone", function* () { const page = yield* useReplPage(); yield* twoChats(page, true); @@ -2194,6 +2210,7 @@ function* appendBoundary(stopped: boolean): Operation { } describe("Sidekick original provider membership and cancelled append", () => { + beforeEach(journalBeforeEach(OWNER)); it("SS3: Stop before the canonical append leaves the key local and nothing saved", function* () { yield* appendBoundary(true); }); @@ -2347,6 +2364,7 @@ function* populateChat(page: ReplPage, count: number, prefix = "SAID"): Operatio } describe("Sidekick original multiline composer ownership", () => { + beforeEach(journalBeforeEach(OWNER)); it("MC5: the value wraps into rows of its own, and the chat gives them room", function* () { const page = yield* useReplPage(); yield* populateChat(page, 10); @@ -2574,6 +2592,7 @@ function* historicalSubmit(historical: boolean, failed: boolean): Operation { + beforeEach(journalBeforeEach(OWNER)); for (const arm of [ { name: "opened at the first entry", historical: true }, { name: "control: opened at the head", historical: false }, @@ -2733,6 +2752,7 @@ function* twoOverflowingChats(page: ReplPage): Operation { } describe("Sidekick original independent readings and streaming rows", () => { + beforeEach(journalBeforeEach(OWNER)); it("CF-P1: scrolling an older chat leaves the current chat's own reading alone", function* () { const page = yield* useReplPage(); yield* twoOverflowingChats(page); @@ -2849,6 +2869,7 @@ describe("Sidekick original independent readings and streaming rows", () => { }); describe("Sidekick original interrupted identities and native input routes", () => { + beforeEach(journalBeforeEach(OWNER)); it("SS6: an interrupted first message leaves every later row its own identity", function* () { const host = yield* useMountedHost(); const first = yield* useReplPage({ host }); @@ -3062,6 +3083,7 @@ function* readSilentAndSpoken(page: ReplPage): Operation { } describe("Sidekick original reveal and cold decision coverage", () => { + beforeEach(journalBeforeEach(OWNER)); it("SS4: a turn past the chat's window is revealed, and this screen keeps its own", function* () { const page = yield* useReplPage(); page.repl.fake.configuration(ADVERTISED); @@ -3176,6 +3198,7 @@ describe("Sidekick original reveal and cold decision coverage", () => { }); describe("Sidekick original populated chat profiles", () => { + beforeEach(journalBeforeEach(OWNER)); it("SS7: three profiles keep a populated older reading, its window and the way home", function* () { const page = yield* useReplPage(); page.repl.fake.configuration(ADVERTISED); @@ -3240,6 +3263,7 @@ describe("Sidekick original populated chat profiles", () => { }); describe("Sidekick original independent body controls", () => { + beforeEach(journalBeforeEach(OWNER)); it("BP3: both bodies stay usable through their own controls, and narrow gains no inset", function* () { const page = yield* useReplPage(); page.repl.fake.script({ reply: "ENTRY-REPLY" }); @@ -3278,6 +3302,7 @@ describe("Sidekick original independent body controls", () => { }); describe("Follow: the running command owns the mounted control", () => { + beforeEach(journalBeforeEach(OWNER)); for (const size of PROFILES) { it(`Follow: keyboard and pointer at ${size.columns}x${size.rows} retain the live setting`, function* () { const page = yield* useReplPage(); @@ -3341,6 +3366,7 @@ describe("Follow: the running command owns the mounted control", () => { }); describe("1137 — recovery stays among the fixed conversation controls", () => { + beforeEach(journalBeforeEach(OWNER)); const LONG = Array.from( { length: 60 }, (_, at) => `LONG${String(at + 1).padStart(2, "0")} retained reply row`, @@ -3449,6 +3475,7 @@ describe("1137 — recovery stays among the fixed conversation controls", () => }); describe("Retained Sidekick token usage", () => { + beforeEach(journalBeforeEach(OWNER)); const USAGE_OFF = "[ ] Show token usage"; const USAGE_ON = "[x] Show token usage"; diff --git a/packages/cli/tests/repl-sidekick-recovery.test.ts b/packages/cli/tests/repl-sidekick-recovery.test.ts index bb670c4b8..59b769901 100644 --- a/packages/cli/tests/repl-sidekick-recovery.test.ts +++ b/packages/cli/tests/repl-sidekick-recovery.test.ts @@ -39,7 +39,8 @@ import { pairedLocation } from "../src/repl/sidekick/history.ts"; import { useHarness } from "./fixtures/repl/issue-883/sidekick-harness.ts"; import { useTemporary } from "./fixtures/repl/issue-883/sidekick-harness.ts"; -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { mkdir, readFile, writeFile } from "node:fs/promises"; import { join } from "node:path"; @@ -142,6 +143,8 @@ import { initialState } from "../src/repl/application.ts"; import { projectRepl } from "../src/repl/model.ts"; import type { ReplEntry } from "../src/repl/model.ts"; +const OWNER = "packages/cli/tests/repl-sidekick-recovery.test.ts"; + const CHAT = "chat-1"; const AGENT = "scribe"; @@ -2693,6 +2696,7 @@ describe("Tier SS — what a saved Sidekick turn establishes about itself", () = * with a list this file chose. */ describe("Tier HI — a reopening reconciles against the acknowledged history", () => { + beforeEach(journalBeforeEach(OWNER)); const FIRST = "First prior.\n"; const SECOND = "Second prior.\n"; /** What the next ordinary entry says, distinct from the reserved source. */ @@ -3217,6 +3221,7 @@ describe("Tier IN5 — a saved EntryOutput result keeps its own renderer", () => }); describe("975 — placement survives cold Submit reconciliation", () => { + beforeEach(journalBeforeEach(OWNER)); for (const marked of [true, false]) { it(`975: ${marked ? "legacy workspace-marked" : "project-placed"} entry resumes in its owned directory`, function* () { const project = yield* useTemporary("xmd-placement-project-"); @@ -3806,6 +3811,7 @@ describe("987 — joined recovery before canonical feedback publication", () => }); describe("987 — actual child reference recording faults", () => { + beforeEach(journalBeforeEach(OWNER)); for (const cut of ["offered", "acknowledged", "activation", "activation-uncertain"]) { it(`sends nothing and retains fatal recording precedence at ${cut}`, function* () { const failure = new Error(`Reference recording failure: ${cut}`); @@ -4061,6 +4067,7 @@ describe("987 — exact missing original and deliberate fallback", () => { }); describe("987 — root whole-set reconciliation", () => { + beforeEach(journalBeforeEach(OWNER)); for (const interrupted of [false, true]) { it(`reconciles the acknowledged head while inspecting older History${interrupted ? " across the first outcome cut" : ""}`, function* () { const host = yield* useMountedHost(); @@ -4919,6 +4926,7 @@ describe("1183 — the exact live feedback request is the only exception", () => }); describe("resume retention and mounted retained recovery corrections", () => { + beforeEach(journalBeforeEach(OWNER)); const savedText = "Continue the exact saved instruction."; const oldText = "Original chat remains readable."; const entryText = "An established entry remains readable."; @@ -5202,6 +5210,7 @@ describe("resume retention and mounted retained recovery corrections", () => { }); describe("1311 — a completed reply that secret detection withholds", () => { + beforeEach(journalBeforeEach(OWNER)); const refused = 'authorization: "Use a separate approval for this example issue #34"'; function showsWithheldReply(screen: ScreenReading): boolean { diff --git a/packages/cli/tests/repl-sidekick-testing.test.ts b/packages/cli/tests/repl-sidekick-testing.test.ts index d474882ff..e95e06beb 100644 --- a/packages/cli/tests/repl-sidekick-testing.test.ts +++ b/packages/cli/tests/repl-sidekick-testing.test.ts @@ -4,7 +4,8 @@ import { planComponentDescription } from "../src/plan-component.ts"; import { BUNDLED_PLUGIN } from "../src/run-profile.ts"; import { DurablePersistenceError } from "@executablemd/durable-streams"; import { submitForSidekick } from "../src/repl/sidekick/admission.ts"; -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { useComponentModuleLoader } from "@executablemd/test-support/host"; import { ensureDir, exists, readTextFile, rm, writeTextFile } from "@effectionx/fs"; @@ -61,6 +62,8 @@ import { stopSidekick, } from "./support/screen-journeys.ts"; +const OWNER = "packages/cli/tests/repl-sidekick-testing.test.ts"; + const reportSchema = z .object({ path: z.string(), @@ -149,6 +152,7 @@ function passing(name = "real assertion", expected = "yes"): string { } describe("REPL.Test accepted journeys", () => { + beforeEach(journalBeforeEach(OWNER)); it("R1: authors, fails, fixes and reuses ordinary Markdown without executing its creation", function* () { const { page, repl, workspace } = yield* mounted(); const chapter = yield* readGuideChapter("Entries"); @@ -320,6 +324,7 @@ describe("REPL.Test accepted journeys", () => { }); describe("REPL.Test selection, display and isolation", () => { + beforeEach(journalBeforeEach(OWNER)); it("R4: preserves configured selection, immutable declarations, document isolation and explicit display", function* () { const configured = yield* useTemporary("xmd-testing-includes-"); yield* writeTextFile(join(configured, "Greeting.md"), "configured greeting"); @@ -463,6 +468,7 @@ function* holdModule( } describe("REPL.Test admission and joined lifetime", () => { + beforeEach(journalBeforeEach(OWNER)); it("R5: refuses both submitters and a second test throughout response cancellation and gated cleanup", function* () { yield* useHostFiles(); yield* useComponentModuleLoader(); @@ -667,6 +673,7 @@ describe("REPL.Test admission and joined lifetime", () => { }); describe("REPL.Test retained and fatal outcomes", () => { + beforeEach(journalBeforeEach(OWNER)); it("R6: reopen inspection keeps completed reports inert and unmatched work unknown until a new explicit request", function* () { yield* useComponentModuleLoader(); const gate = appendGate(); @@ -888,6 +895,7 @@ describe("REPL.Test retained and fatal outcomes", () => { }); describe("1113: session tests use bounded fixtures", () => { + beforeEach(journalBeforeEach(OWNER)); it("1113: keeps test cwd at S and permits components fixtures while refusing private session bytes", function* () { yield* useComponentModuleLoader(); const host = yield* useMountedHost({ diff --git a/packages/cli/tests/repl-sidekick-typing.test.ts b/packages/cli/tests/repl-sidekick-typing.test.ts index 70b0860fb..59c8cf536 100644 --- a/packages/cli/tests/repl-sidekick-typing.test.ts +++ b/packages/cli/tests/repl-sidekick-typing.test.ts @@ -1,4 +1,5 @@ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { scoped } from "effection"; import type { Operation } from "effection"; @@ -40,9 +41,12 @@ import { settledReading } from "./support/mounted-history.ts"; import { useReplPage } from "./support/repl-page.ts"; import { generateTypingHistory, typingView } from "./support/typing-history.ts"; +const OWNER = "packages/cli/tests/repl-sidekick-typing.test.ts"; + const WIDE = { columns: 160, rows: 36 }; describe("1048 — prepare only admitted chat descriptions", () => { + beforeEach(journalBeforeEach(OWNER)); it("constructs the admitted range over all passes independently of off-screen history", function* () { const counts: number[] = []; for (const rounds of [2, 12]) { @@ -114,6 +118,7 @@ describe("1048 — prepare only admitted chat descriptions", () => { }); describe("1048 — selected chat preparation", () => { + beforeEach(journalBeforeEach(OWNER)); it("matches fresh preparation after changed source facts and keeps one geometry", function* () { const page = yield* useReplPage({ size: WIDE }); const read = yield* generateTypingHistory(page, 2, 32); @@ -265,6 +270,7 @@ describe("1048 — selected chat preparation", () => { }); describe("1048 — generated retained output", () => { + beforeEach(journalBeforeEach(OWNER)); it("reads early, middle and tail output after resizing without consuming either draft", function* () { const page = yield* useReplPage({ size: WIDE }); const read = yield* generateTypingHistory(page, 2, 32, true); @@ -374,6 +380,7 @@ describe("1048 — generated retained output", () => { }); describe("1048 — reuse Transcript facts", () => { + beforeEach(journalBeforeEach(OWNER)); it("invalidates consumed source facts while retaining only the current sequence", function* () { const page = yield* useReplPage({ size: WIDE }); const read = yield* generateTypingHistory(page, 2, 32); @@ -633,6 +640,7 @@ describe("1048 — reuse Transcript facts", () => { * again — which a count of renders or a warm machine could not show. */ describe("1342 — formatted bodies are kept for the frames that ask again", () => { + beforeEach(journalBeforeEach(OWNER)); function spied() { const real = createMarkdownStore(); const answers: { readonly source: string; readonly lines: readonly ReplMarkdownLine[] }[] = []; diff --git a/packages/cli/tests/repl-task-tabs.test.ts b/packages/cli/tests/repl-task-tabs.test.ts index b51469107..654902b50 100644 --- a/packages/cli/tests/repl-task-tabs.test.ts +++ b/packages/cli/tests/repl-task-tabs.test.ts @@ -1,5 +1,6 @@ import { sleep } from "effection"; -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { writeTextFile } from "@effectionx/fs"; import { useReplPage } from "./support/repl-page.ts"; @@ -10,6 +11,8 @@ import { awaitedFact } from "./support/mounted-repl.ts"; import { pairedLocation } from "../src/repl/sidekick/history.ts"; import { REPL_PALETTE } from "../src/repl/presentation-style.ts"; +const OWNER = "packages/cli/tests/repl-task-tabs.test.ts"; + function capture(page: ReplPage, name: string): void { const screen = page.repl.terminal.screen; if (screen === undefined) { @@ -33,6 +36,7 @@ for (const size of [ { columns: 72, rows: 20 }, ]) { describe(`Sidekick and TODO tabs at ${size.columns}x${size.rows}`, () => { + beforeEach(journalBeforeEach(OWNER)); it("switches only on human selection and retains drafts, item controls and held queue work", function* () { const page = yield* useReplPage({ size }); yield* draftText(page, "kept entry"); diff --git a/packages/cli/tests/repl-terminal.test.ts b/packages/cli/tests/repl-terminal.test.ts index 99169d217..1f7fe420a 100644 --- a/packages/cli/tests/repl-terminal.test.ts +++ b/packages/cli/tests/repl-terminal.test.ts @@ -13,7 +13,8 @@ * is Slice E's turn. */ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { useTempFileCompiler } from "@executablemd/core"; import { @@ -85,6 +86,8 @@ import { railMark, } from "./support/screen-journeys.ts"; +const OWNER = "packages/cli/tests/repl-terminal.test.ts"; + const WIDE: ReplTerminalSize = { columns: 160, rows: 36 }; const MEDIUM: ReplTerminalSize = { columns: 120, rows: 30 }; const NARROW: ReplTerminalSize = { columns: 72, rows: 20 }; @@ -2002,6 +2005,7 @@ function framed(text: string): Uint8Array { } describe("REPL bracketed paste", () => { + beforeEach(journalBeforeEach(OWNER)); const payload = "first\n\n\t é界🙂\nlast\n"; for (const separator of ["\r", "\n", "\r\n"]) { it(`keeps framed ${JSON.stringify(separator)} as text only`, function* () { @@ -2115,6 +2119,7 @@ describe("REPL newline keys, from recorded terminal bytes", () => { }); describe("REPL terminal: what the host normalizes, and what it refuses to guess", () => { + beforeEach(journalBeforeEach(OWNER)); it("I1: a key becomes a normalized event and a mouse press becomes a position", function* () { const terminal = recordingTerminal(); yield* terminal.install(); @@ -2604,6 +2609,7 @@ describe("REPL terminal: what the host normalizes, and what it refuses to guess" }); describe("REPL terminal: what a drawer covers, and what it cannot reach", () => { + beforeEach(journalBeforeEach(OWNER)); it("TL6: a drawer is visible with its way out while the footer remains readable", function* () { const page = yield* useReplPage({ size: WIDE }); yield* page.press("[history]"); @@ -3045,6 +3051,7 @@ function* submitPast(page: ReplPage, order: number): Operation { } describe("REPL terminal: History past the row-full point (#1017)", () => { + beforeEach(journalBeforeEach(OWNER)); it("keeps every action reachable and preserves results, selection and the draft", function* () { const page = yield* useReplPage({ size: WIDE }); yield* page.type("\x074"); diff --git a/packages/cli/tests/repl-todo-journey.test.ts b/packages/cli/tests/repl-todo-journey.test.ts index d1b07912a..d14e8bcf5 100644 --- a/packages/cli/tests/repl-todo-journey.test.ts +++ b/packages/cli/tests/repl-todo-journey.test.ts @@ -1,6 +1,7 @@ import { sleep } from "effection"; import type { Operation } from "effection"; -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { readTextFile, writeTextFile } from "@effectionx/fs"; import { API } from "@executablemd/runtime"; @@ -12,6 +13,8 @@ import { pairedLocation } from "../src/repl/sidekick/history.ts"; import type { ReplPage, ScreenReading } from "./support/repl-page.ts"; import { TODO_WAKE } from "../src/repl/todo/wake.ts"; +const OWNER = "packages/cli/tests/repl-todo-journey.test.ts"; + /** * Whether the inert last task is the focused one, by its own row and rows. * @@ -173,6 +176,7 @@ for (const size of [ { columns: 72, rows: 20 }, ]) { describe(`Shared TODO terminal at ${size.columns}x${size.rows}`, () => { + beforeEach(journalBeforeEach(OWNER)); it("creates a shared task and keeps it when switching tabs", function* () { const page = yield* useReplPage({ size }); if (size.columns < 120) { @@ -458,6 +462,7 @@ for (const size of [ } describe("TODO human semantic actions", () => { + beforeEach(journalBeforeEach(OWNER)); it("adds, renames, completes, reopens, reorders and removes through mounted controls", function* () { const page = yield* useReplPage(); let inputCount = 0; @@ -635,6 +640,7 @@ describe("TODO human semantic actions", () => { }); describe("TODO background task focus", () => { + beforeEach(journalBeforeEach(OWNER)); it("keeps the surviving target and its local actions after an external prepend", function* () { const page = yield* useReplPage(); yield* intoComposer(page); diff --git a/packages/cli/tests/repl-todo-recovery.test.ts b/packages/cli/tests/repl-todo-recovery.test.ts index e7f011da4..91c205d07 100644 --- a/packages/cli/tests/repl-todo-recovery.test.ts +++ b/packages/cli/tests/repl-todo-recovery.test.ts @@ -1,4 +1,5 @@ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { ensure, scoped, spawn, suspend, withResolvers } from "effection"; import { readTextFile, writeTextFile } from "@effectionx/fs"; @@ -10,7 +11,10 @@ import { settledReading } from "./support/mounted-history.ts"; import { pairedLocation } from "../src/repl/sidekick/history.ts"; import { todoWakeEligible } from "../src/repl/todo/wake.ts"; +const OWNER = "packages/cli/tests/repl-todo-recovery.test.ts"; + describe("TODO logical runtime recovery", () => { + beforeEach(journalBeforeEach(OWNER)); it("restores only file state and initializes once per open logical runtime", function* () { let initialized = 0; let cleaned = 0; diff --git a/packages/cli/tests/repl-unfinished-entry.test.ts b/packages/cli/tests/repl-unfinished-entry.test.ts index 418231609..a976f68a8 100644 --- a/packages/cli/tests/repl-unfinished-entry.test.ts +++ b/packages/cli/tests/repl-unfinished-entry.test.ts @@ -1,5 +1,5 @@ -import { describe, it } from "@executablemd/test-support/bdd"; -import { captureTestJournal } from "@executablemd/test-support/failure-journal"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { captureTestJournal, journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { cliCommand, cliRuntime } from "@executablemd/test-support/launch"; import { expect } from "@executablemd/test-support/expect"; import { @@ -513,6 +513,7 @@ function* delegatedRepositoryWitness() { } describe(REPOSITORY_SUITE, () => { + beforeEach(journalBeforeEach(OWNER)); it(REPOSITORY_TEST, function* () { if (cliRuntime() === "deno") { // E3's real subdirectory control and the fatal witness own separate roots. @@ -526,6 +527,7 @@ describe(REPOSITORY_SUITE, () => { }); describe("joined entry diagnostics", () => { + beforeEach(journalBeforeEach(OWNER)); it("E3/E4/E5: exact earlier outcomes coexist with a live idle entry and joined Stop cleanup", function* () { const cleanup = gate(); yield* ensure(cleanup.release); diff --git a/packages/cli/tests/repl-wheel-burst.test.ts b/packages/cli/tests/repl-wheel-burst.test.ts index b4b3fb023..1e26fb1ab 100644 --- a/packages/cli/tests/repl-wheel-burst.test.ts +++ b/packages/cli/tests/repl-wheel-burst.test.ts @@ -1,4 +1,5 @@ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { scoped, sleep } from "effection"; import type { Operation } from "effection"; @@ -7,6 +8,8 @@ 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 OWNER = "packages/cli/tests/repl-wheel-burst.test.ts"; + const SIZE = { columns: 160, rows: 36 }; function report(direction: "up" | "down", at: ScreenCell): string { @@ -82,6 +85,7 @@ function* typed(page: ReplPage, text: string): Operation { } describe("wheel bursts in one input chunk", () => { + beforeEach(journalBeforeEach(OWNER)); it("Sidekick chat reaches the sequential endpoint and keeps follow", function* () { const page = yield* useReplPage({ size: SIZE }); yield* intoComposer(page); diff --git a/packages/cli/tests/repl-wheel-migration.test.ts b/packages/cli/tests/repl-wheel-migration.test.ts index b4fafe546..b4fcb1e9f 100644 --- a/packages/cli/tests/repl-wheel-migration.test.ts +++ b/packages/cli/tests/repl-wheel-migration.test.ts @@ -1,4 +1,5 @@ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { sleep } from "effection"; import type { Operation } from "effection"; @@ -16,6 +17,8 @@ import { import { awaitedFact, OTHER_MOUNTED_AGENT } from "./support/mounted-repl.ts"; import { REFERENCE_DIRECTORY } from "./fixtures/repl/reference.ts"; +const OWNER = "packages/cli/tests/repl-wheel-migration.test.ts"; + function* key(page: ReplPage, name: PageKey): Operation { const before = page.screen().index; yield* page.key(name); @@ -97,6 +100,7 @@ function absentButtons(page: ReplPage): void { } describe("wheel remaining migration journeys", () => { + beforeEach(journalBeforeEach(OWNER)); it("keeps permission focus through scrolling and acknowledges a held presentation", function* () { const page = yield* useReplPage({ size: { columns: 120, rows: 30 } }); const explanation = Array.from( diff --git a/packages/cli/tests/repl-wheel-scroll.test.ts b/packages/cli/tests/repl-wheel-scroll.test.ts index f057c832e..b24897b88 100644 --- a/packages/cli/tests/repl-wheel-scroll.test.ts +++ b/packages/cli/tests/repl-wheel-scroll.test.ts @@ -1,4 +1,5 @@ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { sleep, spawn, withResolvers } from "effection"; import type { Operation } from "effection"; @@ -7,6 +8,8 @@ import { useReplPage } from "./support/repl-page.ts"; import type { PageKey, ReplPage, ScreenCell } from "./support/repl-page.ts"; import { draftText, intoComposer, intoDraft, SIDEKICK_PANE } from "./support/screen-journeys.ts"; +const OWNER = "packages/cli/tests/repl-wheel-scroll.test.ts"; + function* key(page: ReplPage, name: PageKey): Operation { const before = page.screen().index; yield* page.key(name); @@ -75,6 +78,7 @@ function* transcriptThrough(page: ReplPage, last: number): Operation { } describe("wheel real consumers", () => { + beforeEach(journalBeforeEach(OWNER)); it("permission explanation is readable in both directions without deciding", function* () { const page = yield* useReplPage({ size: { columns: 120, rows: 30 } }); const explanation = [ diff --git a/packages/cli/tests/retained-repository-local.test.ts b/packages/cli/tests/retained-repository-local.test.ts index b73a86d85..652e3bfb3 100644 --- a/packages/cli/tests/retained-repository-local.test.ts +++ b/packages/cli/tests/retained-repository-local.test.ts @@ -17,7 +17,8 @@ * them assert is what a *second* open of one history does. */ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { allSettled, @@ -86,6 +87,8 @@ import { useReplFileRecorder } from "../src/repl/repositories/deno/files.ts"; import { workspaceMountInstallation } from "../src/repl/workspace-mount-installation.ts"; import type { ReplLocalValue } from "../src/repl/repositories/records.ts"; +const OWNER = "packages/cli/tests/retained-repository-local.test.ts"; + interface Fixture { readonly root: string; readonly checkout: string; @@ -1297,6 +1300,7 @@ describe("one entry's local file work", () => { }); describe("975 — native Git keeps project selection and refuses an outside cwd", () => { + beforeEach(journalBeforeEach(OWNER)); it("reads the launch project and refuses native Git outside its selected checkout", function* () { yield* Permissions.around( { files: ([operation], next) => (operation === "absolute" ? true : next(operation)) }, diff --git a/packages/cli/tests/retained-repository-selection.test.ts b/packages/cli/tests/retained-repository-selection.test.ts index 7a3cac74e..0d9d3523d 100644 --- a/packages/cli/tests/retained-repository-selection.test.ts +++ b/packages/cli/tests/retained-repository-selection.test.ts @@ -19,7 +19,8 @@ * because what most of them assert is what a *second* open of one history does. */ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; +import { journalBeforeEach } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { cliCommand } from "@executablemd/test-support/launch"; import { @@ -81,6 +82,8 @@ import type { ReplPlacementRecord } from "../src/repl/repositories/placement-rec import { REPL_REPOSITORY_LOCAL } from "../src/repl/repositories/records.ts"; import { repositorySlot, worktreeSlot } from "@executablemd/git/deno"; +const OWNER = "packages/cli/tests/retained-repository-selection.test.ts"; + interface Fixture { /** The scenario's own directory: source repository, managed root and HOME. */ readonly root: string; @@ -1191,6 +1194,7 @@ function* slotBytes(path: string): Operation { } describe("1113: repositories use the selected project and configured managed root", () => { + beforeEach(journalBeforeEach(OWNER)); it("acquires, reads, reopens and reuses saved source with different repository inputs", function* () { const fixture = yield* useFixture(); const chapter = yield* readGuideChapter("Entries"); diff --git a/packages/cli/tests/support/mounted-repl.ts b/packages/cli/tests/support/mounted-repl.ts index 946505545..e446e2d7e 100644 --- a/packages/cli/tests/support/mounted-repl.ts +++ b/packages/cli/tests/support/mounted-repl.ts @@ -44,6 +44,7 @@ import type { AcpxProviderDependencies } from "@executablemd/acp"; import { useTempFileCompiler, useNormalizedOutput } from "@executablemd/core"; import { createFakeAcp, makeRegistry, makeStore } from "./fake-acp.ts"; import type { FakeAcp } from "./fake-acp.ts"; +import { retainJournalFiles } from "@executablemd/test-support/failure-journal"; import { useTemporary } from "../fixtures/repl/issue-883/sidekick-harness.ts"; import { useTerminalScreen } from "./terminal-screen.ts"; import type { TerminalScreen } from "./terminal-screen.ts"; @@ -763,6 +764,12 @@ export function* useMountedHost( // harness without it would run entries that fail for a reason no row is about. yield* useTempFileCompiler(); const dataRoot = options.dataRoot ?? (yield* useTemporary("xmd-repl-mounted-")); + // The directory the command itself resolves, so a case that writes a file for + // the command to find writes it where the command actually looks. + const root = join(dataRoot, ...REPL_DIRECTORY); + // Before anything that writes there, so this case's command has unwound when + // its histories are read and they are read before the root is removed. + yield* retainJournalFiles(root, root); yield* useNodeReplProjectAccess(); yield* installTodoSource(); yield* installReplHost({ @@ -837,9 +844,6 @@ export function* useMountedHost( planWriterRoot: yield* useTemporary("xmd-repl-mounted-plan-"), }, ); - // The directory the command itself resolves, so a case that writes a file for - // the command to find writes it where the command actually looks. - const root = join(dataRoot, ...REPL_DIRECTORY); return { root, fake, diff --git a/packages/test-support/failure-journal.ts b/packages/test-support/failure-journal.ts index 8bddc323a..3403addf9 100644 --- a/packages/test-support/failure-journal.ts +++ b/packages/test-support/failure-journal.ts @@ -1,24 +1,44 @@ -import { createContext, resource, scoped } from "effection"; -import type { Operation } from "effection"; +import { createContext, each, ensure, Err, Ok, resource, scoped } from "effection"; +import type { Operation, Result } from "effection"; +import { exists, readTextFile, walk } from "@effectionx/fs"; +import { relative } from "node:path"; import { InMemoryStream } from "@executablemd/durable-streams"; import type { DurableEvent } from "@executablemd/durable-streams"; import { withFailureJournal } from "@executablemd/testing"; import process from "node:process"; import { prepareTestDiagnostics, useTestDiagnostics } from "../cli/src/test-diagnostics.ts"; -import type { JournalCase, TestDiagnostics } from "../cli/src/test-diagnostics.ts"; +import type { + JournalCase, + SavedJournalFile, + TestDiagnostics, +} from "../cli/src/test-diagnostics.ts"; import type { DeliverySink } from "../cli/src/stdout-delivery.ts"; import { CaseOutcome } from "./case-outcome.ts"; import type { CaseSetup } from "./case-outcome.ts"; -const CaseJournals = createContext<(source: string) => InMemoryStream>( - "@executablemd/test-support/case-journals", -); +/** A case's file-backed journals, read before the fixture that owns them deletes them. */ +interface RetainedFiles { + read?: Result; +} + +type CaseRoot = + | { readonly source: string; readonly stream: InMemoryStream } + | { readonly source: string; readonly files: RetainedFiles }; + +interface CaseRoots { + stream(source: string): InMemoryStream; + files(source: string): RetainedFiles; +} + +const CaseJournals = createContext("@executablemd/test-support/case-journals"); /** * Give ordinary cases fresh attributed roots with one suite setup. For example, * the held-host witness registers `beforeEach(journalBeforeEach(OWNER))`. Its * fixture selects `request.stream ?? (yield* useJournalStream(document.path))`. - * Keep explicit replay and private inputs at the fixture that owns them. + * A fixture whose host writes journal files registers their directory with + * {@link retainJournalFiles}. Keep explicit replay and private inputs at the + * fixture that owns them. */ export function journalBeforeEach(owner: string): CaseSetup { return { @@ -30,7 +50,7 @@ export function journalBeforeEach(owner: string): CaseSetup { }; } -function useCaseJournals(owner: string): Operation<(source: string) => InMemoryStream> { +function useCaseJournals(owner: string): Operation { return resource(function* (provide) { const outcome = yield* CaseOutcome.expect(); const openDiagnostics = yield* prepareTestDiagnostics(process.stderr, { @@ -38,12 +58,19 @@ function useCaseJournals(owner: string): Operation<(source: string) => InMemoryS name: outcome.name, suite: outcome.suite, }); - const roots: Array<{ source: string; stream: InMemoryStream }> = []; + const roots: CaseRoot[] = []; try { - yield* provide((source) => { - const stream = new InMemoryStream(); - roots.push({ source, stream }); - return stream; + yield* provide({ + stream(source) { + const stream = new InMemoryStream(); + roots.push({ source, stream }); + return stream; + }, + files(source) { + const files: RetainedFiles = {}; + roots.push({ source, files }); + return files; + }, }); } finally { // The adapter can reject after destroying the entire case scope. @@ -56,17 +83,30 @@ function useCaseJournals(owner: string): Operation<(source: string) => InMemoryS function* saveCaseJournals( openDiagnostics: () => Operation, - roots: readonly { source: string; stream: InMemoryStream }[], + roots: readonly CaseRoot[], ): Operation { const diagnostics = yield* openDiagnostics(); - for (const { source, stream } of roots) { - const host = diagnostics.execution("root", source).journal(() => false); - const events = yield* stream.readAll(); - if (events.length === 0) { - continue; - } + for (const root of roots) { + const execution = diagnostics.execution("root", root.source); + const host = execution.journal(() => false); try { - yield* host.save(events); + if ("stream" in root) { + const events = yield* root.stream.readAll(); + if (events.length > 0) { + yield* host.save(events); + } + continue; + } + const read = root.files.read; + if (read === undefined) { + throw new Error("its files were never read before their owner ended"); + } + if (!read.ok) { + throw read.error; + } + if (read.value.length > 0) { + yield* execution.saveFiles(read.value); + } } catch (error) { yield* host.reportSaveFailure(error instanceof Error ? error : new Error(String(error))); } @@ -75,8 +115,49 @@ function* saveCaseJournals( /** Open a fresh journal at the actual source of an independent execution. */ export function* useJournalStream(source: string): Operation { - const open = yield* CaseJournals.get(); - return open === undefined ? new InMemoryStream() : open(source); + const roots = yield* CaseJournals.get(); + return roots === undefined ? new InMemoryStream() : roots.stream(source); +} + +/** + * Keep the JSONL journals a fixture's host writes beneath `directory` for this + * case's failure save. + * + * Call it once the fixture owns the directory and before the work that writes + * there begins. The files are read, with their original text, when the calling + * scope ends: after everything acquired later in that scope has been torn down + * and before anything acquired earlier — such as the directory's own removal — + * runs. A passing case discards what was read, and a failed case saves each + * file beneath the registration's own execution name, keeping its path inside + * `directory`. Outside an attributed case this registers nothing. + */ +export function* retainJournalFiles(source: string, directory: string): Operation { + const roots = yield* CaseJournals.get(); + if (roots === undefined) { + return; + } + const retained = roots.files(source); + yield* ensure(function* () { + try { + retained.read = Ok(yield* readJournalFiles(directory)); + } catch (error) { + retained.read = Err(error instanceof Error ? error : new Error(String(error))); + } + }); +} + +function* readJournalFiles(directory: string): Operation { + if (!(yield* exists(directory))) { + return []; + } + const files: SavedJournalFile[] = []; + for (const entry of yield* each(walk(directory, { includeDirs: false, match: [/\.jsonl$/] }))) { + files.push({ path: relative(directory, entry.path), text: yield* readTextFile(entry.path) }); + yield* each.next(); + } + return files.sort((left, right) => + left.path < right.path ? -1 : left.path > right.path ? 1 : 0, + ); } /** From c3f8961c26419ccbcdb92336c016b0d1a03334dc Mon Sep 17 00:00:00 2001 From: Taras Mankovski Date: Tue, 17 Nov 2026 19:49:16 -0500 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=90=9B=20Read=20only=20mounted=20hist?= =?UTF-8?q?ories,=20after=20the=20host's=20appends=20settle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A mounted host's failure snapshot copied every JSONL file beneath its root, which included an execution's authored assets and components. The host now supplies its own snapshot operation to retainJournalFiles: each paired execution's entries and Sidekick files and each direct legacy history, read as UTF-8 text. Halting a task that asked for an append abandons its wait but not the write already scheduled, so a held append could land after the histories were read or the root removed. The mounted host now keeps its outstanding appends and its teardown waits for each to settle before the snapshot and the removal. SS6 holds its never-written response with the operation gate, which a halt takes back, rather than as a write the host would wait on. The child fixture declares plain describe and it cases, with the witness set up in beforeEach, and adds a held append whose release comes from outside the waiting scope, authored files beside a pair, a second session and a legacy history in a supplied root, and nested attribution. Co-Authored-By: Claude Opus 5.5 --- packages/cli/src/test-diagnostics.ts | 4 +- .../tests/fixtures/mounted-failure-journal.ts | 350 ++++++++++++------ .../cli/tests/mounted-failure-journal.test.ts | 258 +++++++++---- .../tests/repl-sidekick-presentation.test.ts | 8 +- packages/cli/tests/support/mounted-repl.ts | 99 ++++- packages/test-support/failure-journal.ts | 67 ++-- 6 files changed, 555 insertions(+), 231 deletions(-) diff --git a/packages/cli/src/test-diagnostics.ts b/packages/cli/src/test-diagnostics.ts index b6e08d6d8..280ab68fc 100644 --- a/packages/cli/src/test-diagnostics.ts +++ b/packages/cli/src/test-diagnostics.ts @@ -80,8 +80,8 @@ export interface ExecutionDiagnostics { /** Saves this execution's journal when `failed` says its outcome failed. */ journal(failed: (value: T) => boolean): FailureJournalHost; /** - * Saves journal files a host wrote for this execution, with their original - * text, beneath one directory named like this execution's journal. + * Saves journal files a host wrote for this execution, as the UTF-8 text + * they held, beneath one directory named like this execution's journal. * * `path` is each file's place beneath the storage root, so two files of one * root keep the names that tell them apart. diff --git a/packages/cli/tests/fixtures/mounted-failure-journal.ts b/packages/cli/tests/fixtures/mounted-failure-journal.ts index a6ac739d9..065285528 100644 --- a/packages/cli/tests/fixtures/mounted-failure-journal.ts +++ b/packages/cli/tests/fixtures/mounted-failure-journal.ts @@ -2,26 +2,29 @@ * Synthetic mounted cases for `mounted-failure-journal.test.ts`, run as a child * test file under the parent's own runtime. * - * Each case drives the real mounted REPL over real file storage and copies what - * that storage held to `XMD_MOUNTED_WITNESS`, outside the directory its host - * removes, so the parent can compare a saved failure journal with the bytes the - * command actually wrote. Each case also records, after its whole teardown has - * run, which data roots it mounted and whether each still exists. + * Each case drives the real mounted REPL over real file storage and copies the + * histories that storage held to `XMD_MOUNTED_WITNESS`, outside the directory + * its host removes, so the parent can compare a saved failure journal with what + * the command actually wrote. Each case also records, from its own teardown + * after every mounted scope has unwound, which data roots it mounted and + * whether each still exists. */ import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; import { expect } from "@executablemd/test-support/expect"; import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal"; -import { exists, readTextFile, walk, writeTextFile, ensureDir } from "@effectionx/fs"; +import { exists, readTextFile, writeTextFile, ensureDir } from "@effectionx/fs"; import { API, env } from "@executablemd/runtime"; -import { each, ensure, race, scoped, sleep } from "effection"; +import { createContext, ensure, race, scoped, sleep, spawn, withResolvers } from "effection"; import type { Operation } from "effection"; -import { dirname, join, relative } from "node:path"; +import { dirname, join } from "node:path"; import { useReplPage } from "../support/repl-page.ts"; import type { ReplPage } from "../support/repl-page.ts"; -import { awaited } from "../support/mounted-repl.ts"; +import { appendGate, awaited, mountedExecution, useMountedHost } from "../support/mounted-repl.ts"; import { asked, intoDraft, sendMessage, typed } from "../support/screen-journeys.ts"; +import { pairedLocation, SIDEKICK_FILE } from "../../src/repl/sidekick/history.ts"; +import { executionPath } from "../../src/repl/journal.ts"; import { useTemporary } from "./repl/issue-883/sidekick-harness.ts"; const OWNER = "packages/cli/tests/fixtures/mounted-failure-journal.ts"; @@ -31,74 +34,94 @@ const WIDE = { columns: 160, rows: 36 }; /** How long the deadline case waits for a reply its turn never sends. */ const CASE_DEADLINE_MS = 500; +/** + * How long the held append stays held once its case has failed, so the host's + * teardown is demonstrably waiting on it rather than merely not yet reached. + */ +const HELD_MS = 300; + +/** A session another run left beside this one, under an identifier that is not hex. */ +const SECOND_SESSION = "Second_session-1"; + +/** A direct legacy history beside the paired ones. */ +const LEGACY_SESSION = "Legacy-Run_2"; + +/** + * Non-ASCII text, and a final record a write left unfinished: no newline, and + * ending in a multi-byte character that is still whole. + */ +const LEGACY_TEXT = + '{"type":"close","coroutineId":"root","result":{"status":"ok","value":"é☃"}}\n' + + '{"type":"yield","coroutineId":"root","partial":"naïve ☃'; + /** One case's witness directory, and the roots it mounted, in mount order. */ interface Witness { readonly directory: string; readonly roots: string[]; } -function* witnessDirectory(name: string): Operation { - const base = yield* env("XMD_MOUNTED_WITNESS"); - if (!base) { - throw new Error("The mounted journal witness needs a witness directory."); - } - return join(base, name); -} +const Witnessed = createContext("mounted-failure-journal/witness"); -function witness(name: string, body: (witnessed: Witness) => Operation): void { - describe("mounted journal " + name, () => { - beforeEach(function* () { - const root = yield* env("XMD_TEST_ARTIFACTS"); - if (!root) { - throw new Error("The mounted journal witness needs an artifact root."); - } - yield* API.Env.around({ - *env([variable], next) { - return variable === "XMD_TEST_ARTIFACTS" ? join(root, name) : yield* next(variable); - }, - }); +/** + * This case's witness, its own artifact directory, and the record its teardown + * leaves once every mounted scope it opened has unwound. + */ +function witnessCase(name: string): () => Operation { + return function* () { + const artifacts = yield* env("XMD_TEST_ARTIFACTS"); + const witnesses = yield* env("XMD_MOUNTED_WITNESS"); + if (!artifacts || !witnesses) { + throw new Error("The mounted journal witness needs an artifact and a witness directory."); + } + yield* API.Env.around({ + *env([variable], next) { + return variable === "XMD_TEST_ARTIFACTS" ? join(artifacts, name) : yield* next(variable); + }, }); - beforeEach(journalBeforeEach(OWNER)); - it(name, function* () { - const witnessed: Witness = { directory: yield* witnessDirectory(name), roots: [] }; - // Registered before any host, so it runs once every mounted scope has - // unwound: what it records is the state teardown actually left. - yield* ensure(function* () { - const roots: { root: string; exists: boolean }[] = []; - for (const root of witnessed.roots) { - roots.push({ root, exists: yield* exists(root) }); - } - yield* ensureDir(witnessed.directory); - yield* writeTextFile( - join(witnessed.directory, "teardown.json"), - JSON.stringify({ joined: true, roots }) + "\n", - ); - }); - yield* body(witnessed); + const witness: Witness = { directory: join(witnesses, name), roots: [] }; + yield* Witnessed.set(witness); + // Acquired before the case body, so it runs after everything the body + // acquired: what it records is the state that teardown actually left. + yield* ensure(function* () { + const roots: { root: string; exists: boolean }[] = []; + for (const root of witness.roots) { + roots.push({ root, exists: yield* exists(root) }); + } + yield* writeWitness(witness, "teardown.json", JSON.stringify({ roots }) + "\n"); }); - }); + }; } -/** Copy the JSONL files beneath this root, as the command left them. */ -function* copyJournals(witnessed: Witness, ordinal: number, root: string): Operation { - const target = join(witnessed.directory, `root-${ordinal}`); - yield* ensureDir(target); - for (const entry of yield* each(walk(root, { includeDirs: false, match: [/\.jsonl$/] }))) { - const copy = join(target, relative(root, entry.path)); - yield* ensureDir(dirname(copy)); - yield* writeTextFile(copy, yield* readTextFile(entry.path)); - yield* each.next(); +function* writeWitness(witness: Witness, path: string, text: string): Operation { + const target = join(witness.directory, path); + yield* ensureDir(dirname(target)); + yield* writeTextFile(target, text); +} + +/** Copy this root's paired histories of `execution`, as the command left them. */ +function* copyPair(ordinal: number, root: string, execution: string): Operation { + const witness = yield* Witnessed.expect(); + const location = pairedLocation(root, execution); + for (const [name, path] of [ + ["entries.jsonl", location.entries], + ["sidekick.jsonl", location.sidekick], + ]) { + yield* writeWitness( + witness, + join(`root-${ordinal}`, "v1", execution, name), + yield* readTextFile(path), + ); } } /** Mount the real command and remember the root it stores its histories in. */ function* mounted( - witnessed: Witness, options: Parameters[0] = {}, ): Operation<{ page: ReplPage; ordinal: number }> { + const witness = yield* Witnessed.expect(); const page = yield* useReplPage({ size: WIDE, ...options }); - witnessed.roots.push(page.repl.root); - return { page, ordinal: witnessed.roots.length }; + witness.roots.push(page.repl.root); + return { page, ordinal: witness.roots.length }; } /** @@ -122,63 +145,174 @@ function* exit(page: ReplPage): Operation { expect(page.repl.outcome()?.ok).toBe(true); } -witness("passing page", function* (witnessed) { - const { page, ordinal } = yield* mounted(witnessed); - yield* exchange(page, "PASSING"); - yield* exit(page); - yield* copyJournals(witnessed, ordinal, page.repl.root); +/** Write a synthetic file beneath a mounted root. */ +function* plant(root: string, path: string, text: string): Operation { + yield* ensureDir(dirname(join(root, path))); + yield* writeTextFile(join(root, path), text); +} + +describe("mounted journal passing page", () => { + beforeEach(witnessCase("passing page")); + beforeEach(journalBeforeEach(OWNER)); + + it("passing page", function* () { + const { page, ordinal } = yield* mounted(); + yield* exchange(page, "PASSING"); + yield* exit(page); + yield* copyPair(ordinal, page.repl.root, yield* mountedExecution(page.repl)); + }); +}); + +describe("mounted journal late assertion", () => { + beforeEach(witnessCase("late assertion")); + beforeEach(journalBeforeEach(OWNER)); + + it("late assertion", function* () { + const { page, ordinal } = yield* mounted(); + yield* exchange(page, "ASSERTED"); + yield* exit(page); + const execution = yield* mountedExecution(page.repl); + yield* copyPair(ordinal, page.repl.root, execution); + // An execution's own authored inputs, named like journals, which are not history. + yield* plant(page.repl.root, join("v1", execution, "assets", "authored.jsonl"), "{}\n"); + yield* plant(page.repl.root, join("v1", execution, "components", "authored.jsonl"), "{}\n"); + expect("the mounted command returned").toBe("deliberate mounted late assertion"); + }); }); -witness("late assertion", function* (witnessed) { - const { page, ordinal } = yield* mounted(witnessed); - yield* exchange(page, "ASSERTED"); - yield* exit(page); - yield* copyJournals(witnessed, ordinal, page.repl.root); - expect("the mounted command returned").toBe("deliberate mounted late assertion"); +describe("mounted journal deadline", () => { + beforeEach(witnessCase("deadline")); + beforeEach(journalBeforeEach(OWNER)); + + it("deadline", function* () { + // A root this case supplies, so the copy can be taken at the latest moment + // before removal: after the host's own retention and before the directory goes. + const dataRoot = yield* useTemporary("xmd-mounted-witness-"); + let root: string | undefined; + yield* ensure(function* () { + if (root !== undefined) { + yield* copyPair(1, root, yield* mountedExecution(page.repl)); + } + }); + const { page } = yield* mounted({ dataRoot }); + root = page.repl.root; + yield* exchange(page, "STARTED"); + page.repl.fake.script({ manual: true }); + yield* sendMessage(page, "never answered"); + yield* page.repl.fake.startedTurns(2); + yield* race([ + page.until("a reply its turn never sends", (one) => one.shows("NEVER SENT")), + (function* (): Operation { + yield* sleep(CASE_DEADLINE_MS); + throw new Error(`deliberate mounted deadline after ${CASE_DEADLINE_MS}ms`); + })(), + ]); + }); }); -witness("deadline", function* (witnessed) { - // A root this case supplies, so the copy can be taken at the latest moment - // before removal: after the host's own retention and before the directory goes. - const dataRoot = yield* useTemporary("xmd-mounted-witness-"); - let root: string | undefined; - yield* ensure(function* () { - if (root !== undefined) { - yield* copyJournals(witnessed, 1, root); +describe("mounted journal held append", () => { + beforeEach(witnessCase("held append")); + beforeEach(journalBeforeEach(OWNER)); + + it("held append", function* () { + const witness = yield* Witnessed.expect(); + const gate = appendGate(); + let record: string | undefined; + const held = gate.holdNext((path, appended) => { + if (!path.endsWith(SIDEKICK_FILE) || !appended.includes('"kind":"response"')) { + return false; + } + record = appended; + return true; + }); + const failing = withResolvers(); + let root = ""; + let closed = false; + // Owned by the case rather than the host, so the release comes from outside + // the scope whose teardown is waiting for it. + const controller = yield* spawn(function* () { + yield* held.started(); + yield* failing.operation; + yield* sleep(HELD_MS); + const observed = { rootWhileHeld: yield* exists(root), closedWhileHeld: closed }; + held.release(); + return observed; + }); + let failure: unknown; + try { + yield* scoped(function* () { + const host = yield* useMountedHost({ gate }); + const { page } = yield* mounted({ host }); + root = page.repl.root; + yield* exchange(page, "BEFORE"); + page.repl.fake.script({ reply: "HELD\n" }); + yield* sendMessage(page, "reply held"); + yield* held.started(); + failing.resolve(); + throw new Error("deliberate held append cancellation"); + }); + } catch (error) { + failure = error; } + closed = true; + const observed = yield* controller; + yield* writeWitness( + witness, + "held.json", + JSON.stringify({ + ...observed, + record, + reached: gate.reached.filter((path) => path.endsWith(SIDEKICK_FILE)).length, + rootAfterClose: yield* exists(root), + }) + "\n", + ); + throw failure; }); - const { page } = yield* mounted(witnessed, { dataRoot }); - root = page.repl.root; - yield* exchange(page, "STARTED"); - page.repl.fake.script({ manual: true }); - yield* sendMessage(page, "never answered"); - yield* page.repl.fake.startedTurns(2); - yield* race([ - page.until("a reply its turn never sends", (one) => one.shows("NEVER SENT")), - (function* (): Operation { - yield* sleep(CASE_DEADLINE_MS); - throw new Error(`deliberate mounted deadline after ${CASE_DEADLINE_MS}ms`); - })(), - ]); }); -witness("multiple roots", function* (witnessed) { - const stream = yield* useJournalStream("synthetic/in-memory.md"); - yield* stream.append({ - type: "close", - coroutineId: "root", - result: { status: "ok", value: null }, - }); - yield* scoped(function* () { - const { page, ordinal } = yield* mounted(witnessed); - yield* exchange(page, "NESTED"); - yield* exit(page); - yield* copyJournals(witnessed, ordinal, page.repl.root); +describe("mounted journal multiple roots", () => { + beforeEach(witnessCase("multiple roots")); + beforeEach(journalBeforeEach(OWNER)); + + describe("nested setup", () => { + beforeEach(journalBeforeEach(OWNER)); + + it("multiple roots", function* () { + const witness = yield* Witnessed.expect(); + const stream = yield* useJournalStream("synthetic/in-memory.md"); + yield* stream.append({ + type: "close", + coroutineId: "root", + result: { status: "ok", value: null }, + }); + yield* scoped(function* () { + const { page, ordinal } = yield* mounted(); + yield* exchange(page, "NESTED"); + yield* exit(page); + yield* copyPair(ordinal, page.repl.root, yield* mountedExecution(page.repl)); + }); + expect(yield* exists(witness.roots[0])).toBe(false); + + // A root this case supplies and removes itself, holding a second session + // and a direct legacy history beside the command's own. + const dataRoot = yield* useTemporary("xmd-mounted-supplied-"); + const { page, ordinal } = yield* mounted({ dataRoot }); + yield* exchange(page, "OUTER"); + yield* exit(page); + const root = page.repl.root; + const execution = yield* mountedExecution(page.repl); + yield* copyPair(ordinal, root, execution); + const second = pairedLocation(root, SECOND_SESSION); + for (const [path, text] of [ + [second.entries, '{"synthetic":"entries ü"}\n'], + [second.sidekick, '{"synthetic":"sidekick ü"}\n'], + [executionPath(root, LEGACY_SESSION), LEGACY_TEXT], + ]) { + const inside = path.slice(root.length + 1); + yield* plant(root, inside, text); + yield* writeWitness(witness, join(`root-${ordinal}`, inside), text); + } + expect("both mounted roots returned").toBe("deliberate multiple-root assertion"); + }); }); - expect(yield* exists(witnessed.roots[0])).toBe(false); - const { page, ordinal } = yield* mounted(witnessed); - yield* exchange(page, "OUTER"); - yield* exit(page); - yield* copyJournals(witnessed, ordinal, page.repl.root); - expect("both mounted roots returned").toBe("deliberate multiple-root assertion"); }); diff --git a/packages/cli/tests/mounted-failure-journal.test.ts b/packages/cli/tests/mounted-failure-journal.test.ts index f4398211a..d5037e403 100644 --- a/packages/cli/tests/mounted-failure-journal.test.ts +++ b/packages/cli/tests/mounted-failure-journal.test.ts @@ -6,9 +6,12 @@ * synthetic cases in `fixtures/mounted-failure-journal.ts` as a child test file * under this runtime, join it, and compare each saved journal with the copy the * child took of what the command actually wrote: a passing case uploads - * nothing, and an assertion after a successful run, a case deadline that - * cancels a turn in flight, and a case with a nested and an outer root each - * leave their own attributed files after the directories are gone. + * nothing; an assertion after a successful run keeps its pair and none of the + * execution's authored files; a case deadline that cancels a turn in flight + * keeps what that turn wrote; an append still held when its case fails is + * written before the histories are read and the root is removed; and a case + * with a nested and a supplied root under nested attribution keeps each root + * apart, with every session and legacy history the supplied root held. */ import { describe, it } from "@executablemd/test-support/bdd"; @@ -35,18 +38,20 @@ function* contents(directory: string): Operation> { return found; } +function* readJson(path: string): Operation { + return JSON.parse(yield* readTextFile(path)); +} + /** What the child recorded once a case's whole teardown had run. */ function* teardown(witness: string): Operation<{ root: string; exists: boolean }[]> { - const recorded: unknown = JSON.parse(yield* readTextFile(join(witness, "teardown.json"))); + const recorded = yield* readJson(join(witness, "teardown.json")); if ( recorded === null || typeof recorded !== "object" || - !("joined" in recorded) || - recorded.joined !== true || !("roots" in recorded) || !Array.isArray(recorded.roots) ) { - throw new Error(`The child recorded no joined teardown: ${JSON.stringify(recorded)}`); + throw new Error(`The child recorded no teardown: ${JSON.stringify(recorded)}`); } return recorded.roots.map((one: unknown) => { if ( @@ -63,6 +68,50 @@ function* teardown(witness: string): Operation<{ root: string; exists: boolean } }); } +/** The one invocation directory a failed case saved into. */ +function* invocation(artifacts: string, name: string): Operation { + const invocations = yield* readdir(join(artifacts, name)); + expect(invocations).toHaveLength(1); + return join(artifacts, name, invocations[0]); +} + +/** The paired entry and Sidekick paths among a saved root's files. */ +function pairs(files: readonly string[]): { entries: string; sidekick: string }[] { + return files + .filter((path) => /^v1\/[0-9a-f]+\/entries\.jsonl$/.test(path)) + .map((entries) => ({ + entries, + sidekick: entries.replace(/entries\.jsonl$/, "sidekick.jsonl"), + })); +} + +/** + * One saved mounted root: its files equal the child's witness copy, its + * metadata names this case and the root, and the run reported the save. + */ +function* savedRoot( + directory: string, + ordinal: number, + witness: string, + copy: number, + identity: { name: string; suite: string; source: string }, + output: string, +): Operation> { + const saved = yield* contents(join(directory, `root-${ordinal}`)); + expect(saved).toEqual(yield* contents(join(witness, `root-${copy}`))); + expect(yield* readJson(join(directory, `root-${ordinal}.case.json`))).toEqual({ + owner: OWNER, + ...identity, + kind: "root", + ordinal, + files: Object.keys(saved).sort(), + }); + expect(output).toContain( + `journal saved: ${join(directory, `root-${ordinal}`)} (root ${ordinal} ${identity.source})`, + ); + return saved; +} + describe("mounted REPL failure journals", () => { it("keeps each failed case's actual paired histories after its roots are removed", function* () { const artifacts = yield* useTempDirectory("xmd-mounted-journal-artifacts-"); @@ -92,79 +141,148 @@ describe("mounted REPL failure journals", () => { expect(output).toMatch(/(?:✔|\(pass\)).*passing page|passing page \.\.\. ok/); expect(output).toContain('Expected: "deliberate mounted late assertion"'); expect(output).toContain("deliberate mounted deadline after 500ms"); + expect(output).toContain("deliberate held append cancellation"); expect(output).toContain('Expected: "deliberate multiple-root assertion"'); // A passing case unwound the same way and created nothing to upload. expect(yield* exists(join(artifacts, "passing page"))).toBe(false); - const passed = yield* teardown(join(witnesses, "passing page")); - expect(passed.map((one) => one.exists)).toEqual([false]); + expect((yield* teardown(join(witnesses, "passing page"))).map((one) => one.exists)).toEqual([ + false, + ]); - for (const [name, words, memory] of [ - ["late assertion", ["ASSERTED"], false], - ["deadline", ["STARTED"], false], - ["multiple roots", ["NESTED", "OUTER"], true], + for (const [name, word] of [ + ["late assertion", "ASSERTED"], + ["deadline", "STARTED"], ] as const) { const witness = join(witnesses, name); - const roots = yield* teardown(witness); - expect(roots.map((one) => one.exists)).toEqual(words.map(() => false)); + const [root] = yield* teardown(witness); + expect(root.exists).toBe(false); + const directory = yield* invocation(artifacts, name); + expect((yield* readdir(directory)).sort()).toEqual(["root-1", "root-1.case.json"]); + const saved = yield* savedRoot( + directory, + 1, + witness, + 1, + { name, suite: "mounted journal " + name, source: root.root }, + output, + ); + // Only the pair: an execution's authored assets and components stay behind. + const [pair] = pairs(Object.keys(saved)); + expect(Object.keys(saved).sort()).toEqual([pair.entries, pair.sidekick]); + expect(saved[pair.entries]).toContain(`entry ${word}`); + expect(saved[pair.sidekick]).toContain(`reply ${word.toLowerCase()}`); + } - const invocations = yield* readdir(join(artifacts, name)); - expect(invocations).toHaveLength(1); - const directory = join(artifacts, name, invocations[0]); - // The in-memory root opened first is saved beside the mounted ones. - const offset = memory ? 1 : 0; - if (memory) { - expect(JSON.parse(yield* readTextFile(join(directory, "root-1.case.json")))).toEqual({ - owner: OWNER, - name, - suite: "mounted journal " + name, - kind: "root", - ordinal: 1, - source: "synthetic/in-memory.md", - }); - expect( - parseDurableEvent((yield* readTextFile(join(directory, "root-1.jsonl"))).trimEnd()), - ).toMatchObject({ ok: true, value: { type: "close", coroutineId: "root" } }); + // The held append was still waiting when its case failed: the host's + // teardown waited for it, then read the histories, then removed the root. + { + const name = "held append"; + const witness = join(witnesses, name); + const [root] = yield* teardown(witness); + expect(root.exists).toBe(false); + const held = yield* readJson(join(witness, "held.json")); + expect(held).toMatchObject({ + rootWhileHeld: true, + closedWhileHeld: false, + rootAfterClose: false, + }); + if ( + held === null || + typeof held !== "object" || + !("record" in held) || + typeof held.record !== "string" + ) { + throw new Error(`The child recorded no held record: ${JSON.stringify(held)}`); } + const directory = yield* invocation(artifacts, name); + expect((yield* readdir(directory)).sort()).toEqual(["root-1", "root-1.case.json"]); + const saved = yield* contents(join(directory, "root-1")); + const [pair] = pairs(Object.keys(saved)); + expect(Object.keys(saved).sort()).toEqual([pair.entries, pair.sidekick]); + expect(saved[pair.entries]).toContain("entry BEFORE"); + expect(saved[pair.sidekick]).toContain("reply before"); + expect(saved[pair.sidekick].endsWith(held.record)).toBe(true); + expect(yield* readJson(join(directory, "root-1.case.json"))).toEqual({ + owner: OWNER, + name, + suite: "mounted journal " + name, + kind: "root", + ordinal: 1, + source: root.root, + files: [pair.entries, pair.sidekick], + }); + } - const executions = new Set(); - for (const [index, word] of words.entries()) { - const ordinal = index + 1 + offset; - const saved = yield* contents(join(directory, `root-${ordinal}`)); - const copied = yield* contents(join(witness, `root-${index + 1}`)); - // Byte for byte what the command wrote, and nothing it did not. - expect(saved).toEqual(copied); - const files = Object.keys(saved).sort(); - expect(files).toHaveLength(2); - const [entries, sidekick] = files; - expect(entries).toMatch(/^v1\/[0-9a-f]+\/entries\.jsonl$/); - expect(sidekick).toBe(entries.replace(/entries\.jsonl$/, "sidekick.jsonl")); - executions.add(entries.split("/")[1]); - expect(saved[entries]).toContain(`entry ${word}`); - expect(saved[sidekick]).toContain(`reply ${word.toLowerCase()}`); - expect( - JSON.parse(yield* readTextFile(join(directory, `root-${ordinal}.case.json`))), - ).toEqual({ - owner: OWNER, - name, - suite: "mounted journal " + name, - kind: "root", - ordinal, - source: roots[index].root, - files, - }); - expect(output).toContain( - `journal saved: ${join(directory, `root-${ordinal}`)} (root ${ordinal} ${roots[index].root})`, - ); - } - expect(executions.size).toBe(words.length); - expect((yield* readdir(directory)).sort()).toEqual( - Array.from({ length: words.length + offset }, (_, index) => [ - `root-${index + 1}${memory && index === 0 ? ".jsonl" : ""}`, - `root-${index + 1}.case.json`, - ]) - .flat() - .sort(), + // An in-memory root, a nested mounted root released before the assertion + // and a supplied root, each saved apart under the case that opened them. + { + const name = "multiple roots"; + const suite = "mounted journal multiple roots > nested setup"; + const witness = join(witnesses, name); + const roots = yield* teardown(witness); + expect(roots.map((one) => one.exists)).toEqual([false, false]); + const directory = yield* invocation(artifacts, name); + expect((yield* readdir(directory)).sort()).toEqual([ + "root-1.case.json", + "root-1.jsonl", + "root-2", + "root-2.case.json", + "root-3", + "root-3.case.json", + ]); + expect(yield* readJson(join(directory, "root-1.case.json"))).toEqual({ + owner: OWNER, + name, + suite, + kind: "root", + ordinal: 1, + source: "synthetic/in-memory.md", + }); + expect( + parseDurableEvent((yield* readTextFile(join(directory, "root-1.jsonl"))).trimEnd()), + ).toMatchObject({ ok: true, value: { type: "close", coroutineId: "root" } }); + + const nested = yield* savedRoot( + directory, + 2, + witness, + 1, + { name, suite, source: roots[0].root }, + output, + ); + const [nestedPair] = pairs(Object.keys(nested)); + expect(Object.keys(nested).sort()).toEqual([nestedPair.entries, nestedPair.sidekick]); + expect(nested[nestedPair.entries]).toContain("entry NESTED"); + + const supplied = yield* savedRoot( + directory, + 3, + witness, + 2, + { name, suite, source: roots[1].root }, + output, + ); + const [outerPair] = pairs(Object.keys(supplied)); + expect(Object.keys(supplied).sort()).toEqual( + [ + "Legacy-Run_2.jsonl", + outerPair.entries, + outerPair.sidekick, + "v1/Second_session-1/entries.jsonl", + "v1/Second_session-1/sidekick.jsonl", + ].sort(), + ); + expect(supplied[outerPair.entries]).toContain("entry OUTER"); + expect(nestedPair.entries).not.toBe(outerPair.entries); + // Non-ASCII text and an unfinished final record, kept as the UTF-8 they were. + const legacy = supplied["Legacy-Run_2.jsonl"]; + expect(legacy).toContain("é☃"); + expect(legacy.endsWith('"partial":"naïve ☃')).toBe(true); + expect(new TextEncoder().encode(legacy)).toEqual( + new TextEncoder().encode( + yield* readTextFile(join(witness, "root-2", "Legacy-Run_2.jsonl")), + ), ); } }); diff --git a/packages/cli/tests/repl-sidekick-presentation.test.ts b/packages/cli/tests/repl-sidekick-presentation.test.ts index 494ee6271..16ee04b6d 100644 --- a/packages/cli/tests/repl-sidekick-presentation.test.ts +++ b/packages/cli/tests/repl-sidekick-presentation.test.ts @@ -2916,14 +2916,16 @@ describe("Sidekick original interrupted identities and native input routes", () it("SS6: a real automatic turn nobody answered opens as its own inert anchor", function* () { const dataRoot = yield* useTemporary("xmd-ss6-inert-"); - const gate = appendGate(); + // Held as an operation, so closing the host takes the response back rather + // than leaving a write for the host's teardown to wait on. + const operations = operationGate(); const execution = yield* scoped(function* () { - const host = yield* useMountedHost({ dataRoot, gate }); + const host = yield* useMountedHost({ dataRoot, operations }); const page = yield* useReplPage({ host }); page.repl.fake.script({ reply: "First answer.\n\n" }); page.repl.fake.script({ reply: "\n" }); let seen = 0; - const held = gate.holdNext( + const held = operations.holdNext( (path, record) => path.endsWith(SIDEKICK_FILE) && record.includes('"kind":"response"') && ++seen === 2, ); diff --git a/packages/cli/tests/support/mounted-repl.ts b/packages/cli/tests/support/mounted-repl.ts index e446e2d7e..2089c793c 100644 --- a/packages/cli/tests/support/mounted-repl.ts +++ b/packages/cli/tests/support/mounted-repl.ts @@ -15,8 +15,9 @@ import { installTodoSource } from "../../src/node-todo-source.ts"; import { action, ensure, resource, sleep, spawn, until, withResolvers } from "effection"; import type { Operation, Result, Stream, Subscription } from "effection"; import { appendFile, open as openFile, readdir } from "node:fs/promises"; -import { join } from "node:path"; +import { join, relative } from "node:path"; import { randomBytes } from "node:crypto"; +import { exists, FsApi, readTextFile } from "@effectionx/fs"; import { installReplHost } from "../../src/repl-assembly.ts"; import { ReplHost } from "../../src/repl/host.ts"; @@ -31,7 +32,10 @@ import { resolveAgentStack } from "../../src/agent-stack.ts"; import { NO_PLUGINS, installPlugins } from "../../src/plugin-host.ts"; import { todoPlugin, todoPluginDeclaresFor } from "../../src/repl/todo/plugin.ts"; import { pairedReplRepository } from "../../src/repl/sidekick/repository.ts"; -import { PAIRED_DIRECTORY } from "../../src/repl/sidekick/history.ts"; +import { PAIRED_DIRECTORY, pairedLocation } from "../../src/repl/sidekick/history.ts"; +import { executionPath } from "../../src/repl/journal.ts"; +import { isOpaqueExecution } from "../../src/repl/route.ts"; +import type { SavedJournalFile } from "../../src/test-diagnostics.ts"; import type { SidekickRecord } from "../../src/repl/sidekick/history.ts"; import { projectRepl } from "../../src/repl/model.ts"; import type { ReplModel } from "../../src/repl/model.ts"; @@ -635,6 +639,77 @@ export function operationGate(): OperationGate { }; } +/** + * The histories a mounted command writes beneath `root`, as UTF-8 text: each + * paired execution's entries and Sidekick files, and each direct legacy file. + * + * Named files only, because an execution's directory also holds its authored + * assets and components, which are inputs rather than history. + */ +function* mountedJournals(root: string): Operation { + if (!(yield* exists(root))) { + return []; + } + const paths: string[] = []; + for (const entry of yield* FsApi.operations.readdirDirents(root)) { + const execution = entry.name.slice(0, -".jsonl".length); + if (entry.isFile() && entry.name.endsWith(".jsonl") && isOpaqueExecution(execution)) { + paths.push(executionPath(root, execution)); + } + } + const paired = join(root, PAIRED_DIRECTORY); + if (yield* exists(paired)) { + for (const entry of yield* FsApi.operations.readdirDirents(paired)) { + if (entry.isDirectory() && isOpaqueExecution(entry.name)) { + const location = pairedLocation(root, entry.name); + paths.push(location.entries, location.sidekick); + } + } + } + const files: SavedJournalFile[] = []; + for (const path of paths.sort()) { + if ((yield* exists(path)) && (yield* FsApi.operations.stat(path)).isFile()) { + files.push({ path: relative(root, path), text: yield* readTextFile(path) }); + } + } + return files; +} + +/** The appends a mounted host has handed out and not yet seen settle. */ +interface OutstandingAppends { + /** Hold `append` until it settles, and hand it back unchanged. */ + track(append: Promise): Promise; +} + +/** + * Keep the host's appends inside the host's lifetime. + * + * Halting the task that asked for an append abandons its wait but not the + * write, which is already scheduled. Teardown waits for every outstanding one + * to settle — written or refused, without retrying or reporting it — so nothing + * acquired earlier, such as reading or removing the storage, races a write. + */ +function useOutstandingAppends(): Operation { + return resource(function* (provide) { + const outstanding = new Set>(); + yield* ensure(function* () { + while (outstanding.size > 0) { + yield* until(Promise.all(outstanding)); + } + }); + yield* provide({ + track(append) { + const settled: Promise = append.then( + () => outstanding.delete(settled), + () => outstanding.delete(settled), + ); + outstanding.add(settled); + return append; + }, + }); + }); +} + /** One mounted command, and everything a case needs to drive and read it. */ export interface MountedRepl { @@ -767,9 +842,11 @@ export function* useMountedHost( // The directory the command itself resolves, so a case that writes a file for // the command to find writes it where the command actually looks. const root = join(dataRoot, ...REPL_DIRECTORY); - // Before anything that writes there, so this case's command has unwound when - // its histories are read and they are read before the root is removed. - yield* retainJournalFiles(root, root); + // Before anything that writes there, so this case's command has unwound and + // its appends have settled when its histories are read, and they are read + // before the root is removed. + yield* retainJournalFiles(root, mountedJournals(root)); + const appends = yield* useOutstandingAppends(); yield* useNodeReplProjectAccess(); yield* installTodoSource(); yield* installReplHost({ @@ -783,11 +860,13 @@ export function* useMountedHost( appendRecord: (path, record) => { const held = gate?.around(path, record); const written = (held ?? Promise.resolve()).then(() => appendFile(path, record)); - return gate === undefined - ? written - : written.then(() => { - gate.reached.push(path); - }); + return appends.track( + gate === undefined + ? written + : written.then(() => { + gate.reached.push(path); + }), + ); }, }); // Over the installed implementation, at the instrumentation band, so the diff --git a/packages/test-support/failure-journal.ts b/packages/test-support/failure-journal.ts index 3403addf9..07f41f4e8 100644 --- a/packages/test-support/failure-journal.ts +++ b/packages/test-support/failure-journal.ts @@ -1,7 +1,5 @@ -import { createContext, each, ensure, Err, Ok, resource, scoped } from "effection"; +import { createContext, ensure, Err, Ok, resource, scoped } from "effection"; import type { Operation, Result } from "effection"; -import { exists, readTextFile, walk } from "@effectionx/fs"; -import { relative } from "node:path"; import { InMemoryStream } from "@executablemd/durable-streams"; import type { DurableEvent } from "@executablemd/durable-streams"; import { withFailureJournal } from "@executablemd/testing"; @@ -36,7 +34,7 @@ const CaseJournals = createContext("@executablemd/test-support/case-j * Give ordinary cases fresh attributed roots with one suite setup. For example, * the held-host witness registers `beforeEach(journalBeforeEach(OWNER))`. Its * fixture selects `request.stream ?? (yield* useJournalStream(document.path))`. - * A fixture whose host writes journal files registers their directory with + * A fixture whose host writes journal files registers how to read them with * {@link retainJournalFiles}. Keep explicit replay and private inputs at the * fixture that owns them. */ @@ -120,46 +118,39 @@ export function* useJournalStream(source: string): Operation { } /** - * Keep the JSONL journals a fixture's host writes beneath `directory` for this - * case's failure save. + * Keep the journal files a fixture's host writes for this case's failure save. * - * Call it once the fixture owns the directory and before the work that writes - * there begins. The files are read, with their original text, when the calling - * scope ends: after everything acquired later in that scope has been torn down - * and before anything acquired earlier — such as the directory's own removal — - * runs. A passing case discards what was read, and a failed case saves each - * file beneath the registration's own execution name, keeping its path inside - * `directory`. Outside an attributed case this registers nothing. + * `snapshot` is the owner's own operation for reading them, because only the + * owner knows which of its files are journals. Acquire this once the fixture + * owns the storage and before the work that writes there begins: `snapshot` + * runs when this resource is torn down, after everything the calling scope + * acquired later and before anything it acquired earlier — such as the + * storage's own removal. A passing case discards what was read, and a failed + * case saves each file beneath the registration's own execution name, keeping + * its `path`. Outside an attributed case `snapshot` never runs. */ -export function* retainJournalFiles(source: string, directory: string): Operation { - const roots = yield* CaseJournals.get(); - if (roots === undefined) { - return; - } - const retained = roots.files(source); - yield* ensure(function* () { - try { - retained.read = Ok(yield* readJournalFiles(directory)); - } catch (error) { - retained.read = Err(error instanceof Error ? error : new Error(String(error))); +export function retainJournalFiles( + source: string, + snapshot: Operation, +): Operation { + return resource(function* (provide) { + const roots = yield* CaseJournals.get(); + if (roots === undefined) { + yield* provide(); + return; } + const retained = roots.files(source); + yield* ensure(function* () { + try { + retained.read = Ok(yield* snapshot); + } catch (error) { + retained.read = Err(error instanceof Error ? error : new Error(String(error))); + } + }); + yield* provide(); }); } -function* readJournalFiles(directory: string): Operation { - if (!(yield* exists(directory))) { - return []; - } - const files: SavedJournalFile[] = []; - for (const entry of yield* each(walk(directory, { includeDirs: false, match: [/\.jsonl$/] }))) { - files.push({ path: relative(directory, entry.path), text: yield* readTextFile(entry.path) }); - yield* each.next(); - } - return files.sort((left, right) => - left.path < right.path ? -1 : left.path > right.path ? 1 : 0, - ); -} - /** * Protect a repository test's fresh guarded execution and its assertions. * Pass the outer case's declared name and repository-relative file as the From 106d380bb4beb52f8c6ef68ba539f2a3a307ac0d Mon Sep 17 00:00:00 2001 From: Taras Mankovski Date: Tue, 17 Nov 2026 20:41:11 -0500 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=90=9B=20Release=20PV3's=20cancellati?= =?UTF-8?q?on=20hold=20and=20R4f's=20cleanup=20gate=20on=20exceptional=20e?= =?UTF-8?q?xit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A failed assertion after Stop reached the held provider cancellation, or after the contributed component's cleanup started, left that gate held, so the host could not settle and the case's failure never surfaced. Each owner now releases its gate in a finally while keeping its normal release point. Co-Authored-By: Claude Opus 5.5 --- .../cli/tests/repl-sidekick-lifecycle.test.ts | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/cli/tests/repl-sidekick-lifecycle.test.ts b/packages/cli/tests/repl-sidekick-lifecycle.test.ts index e043be39a..7896aed07 100644 --- a/packages/cli/tests/repl-sidekick-lifecycle.test.ts +++ b/packages/cli/tests/repl-sidekick-lifecycle.test.ts @@ -1046,14 +1046,18 @@ describe("Tier PV — generation that ended without a reply", () => { // Stop joined what it asked for rather than returning over the top of it. expect(page.screen().shows("[x] Follow")).toBe(true); const cancelling = repl.fake.holdCancellation(); - // The Sidekick's own Stop. This person's entry is running, so the draft is - // wearing a Stop too — and it is the leftmost, so a press that went looking - // for `[stop]` on the screen would stop the document's work and never reach - // the generation this row is about. - yield* stopSidekick(page); - yield* cancelling.reached; - expect(repl.outcome()).toBe(undefined); - cancelling.release(); + try { + // The Sidekick's own Stop. This person's entry is running, so the draft is + // wearing a Stop too — and it is the leftmost, so a press that went looking + // for `[stop]` on the screen would stop the document's work and never reach + // the generation this row is about. + yield* stopSidekick(page); + yield* cancelling.reached; + expect(repl.outcome()).toBe(undefined); + cancelling.release(); + } finally { + cancelling.release(); + } // What the agent said stays, as the attempt it is — and it claims nothing: // no turn, no response, no acceptance, no recorded failure. @@ -2301,9 +2305,9 @@ describe("Contributed control acknowledgement and teardown", () => { record.includes('"kind":"control"') && record.includes('"component":"Contributed"'), ); const outcome = gate.holdNext((_path, record) => record.includes('"kind":"control-outcome"')); + const release = withResolvers(); try { const cleaning = withResolvers(); - const release = withResolvers(); counts.cleanup = function* () { cleaning.resolve(); yield* release.operation; @@ -2336,6 +2340,7 @@ describe("Contributed control acknowledgement and teardown", () => { ).toHaveLength(1); } finally { intent.release(); + release.resolve(); outcome.release(); } }); From c4098d631d8a3bba7b01cfc2d7679a16fa472ec7 Mon Sep 17 00:00:00 2001 From: Taras Mankovski Date: Tue, 17 Nov 2026 21:06:05 -0500 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=90=9B=20Retain=20journals=20for=20th?= =?UTF-8?q?e=20owned=20footer,=20History=20and=20single-field=20inventory?= =?UTF-8?q?=20cases?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- packages/cli/tests/repl-layout-admission.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/cli/tests/repl-layout-admission.test.ts b/packages/cli/tests/repl-layout-admission.test.ts index 54ed05bce..2756fb82c 100644 --- a/packages/cli/tests/repl-layout-admission.test.ts +++ b/packages/cli/tests/repl-layout-admission.test.ts @@ -1619,6 +1619,7 @@ describe("Owned narrow guidance and pane navigation routes", () => { }); describe("Owned footer, History and single-field inventory", () => { + beforeEach(journalBeforeEach(OWNER)); it("keeps the full execution refusal readable from the narrow identity header", function* () { // The long search path ends row five with a supplementary letter. const cutoff = "\u{10400}";