From 7f316091c679039c96f7b6795691480d8d5f5a74 Mon Sep 17 00:00:00 2001 From: Taras Mankovski Date: Tue, 17 Nov 2026 07:59:55 -0500 Subject: [PATCH] Capture failure journals across guarded test executions Replay the reviewed #1358 patch onto squash-merged #1357. --- .../acp/tests/agent-certification.test.ts | 55 ++-- packages/agent/tests/package-boundary.test.ts | 64 +++-- .../cli/tests/plan-command-document.test.ts | 72 +++-- packages/cli/tests/repl-model.test.ts | 252 ++++++++++-------- packages/cli/tests/testing-activation.test.ts | 116 ++++---- .../tests/upgrade-command-document.test.ts | 11 +- .../core/tests/code-block-component.test.ts | 81 ++++-- packages/core/tests/compiler-boundary.test.ts | 27 +- .../tests/component-invocation-hooks.test.ts | 83 +++--- packages/core/tests/eval-durable.test.ts | 13 +- packages/core/tests/eval-persist.test.ts | 20 +- packages/core/tests/exec-timeout.test.ts | 64 +++-- .../core/tests/host-generated-root.test.ts | 55 ++-- packages/core/tests/parse-components.test.ts | 60 +++-- packages/core/tests/props-binding.test.ts | 28 +- packages/core/tests/root-composition.test.ts | 63 +++-- packages/core/tests/root-props.test.ts | 175 +++++------- packages/git/tests/git-add.test.ts | 9 +- packages/git/tests/git-commit-read.test.ts | 9 +- packages/git/tests/git-commit.test.ts | 9 +- packages/git/tests/git-switch.test.ts | 9 +- packages/git/tests/github-activation.test.ts | 20 +- .../tests/github-workflow-activation.test.ts | 22 +- .../git/tests/run-composition-lazy.test.ts | 23 +- .../tests/cross-package-resolution.test.ts | 50 ++-- .../testing/tests/testing-activation.test.ts | 146 ++++++---- 26 files changed, 924 insertions(+), 612 deletions(-) diff --git a/packages/acp/tests/agent-certification.test.ts b/packages/acp/tests/agent-certification.test.ts index f1ba5c1ee..f0d4eb71a 100644 --- a/packages/acp/tests/agent-certification.test.ts +++ b/packages/acp/tests/agent-certification.test.ts @@ -1,3 +1,4 @@ +import { captureTestJournal } from "@executablemd/test-support/failure-journal"; import { describe, it } from "@executablemd/test-support/bdd"; import { expect } from "@executablemd/test-support/expect"; import { ensure, scoped, spawn, withResolvers } from "effection"; @@ -208,31 +209,39 @@ describe( }); for (const setting of ["model", "effort"]) { for (const kind of ["absent", "mismatch"]) { - it(`reports exact ${setting} ${kind} evidence before any Prompt`, function* () { + const name = `reports exact ${setting} ${kind} evidence before any Prompt`; + it(name, function* () { yield* withCertificationFixture(function* (f) { - const mode = kind + "-" + setting; - const report = reportFor(f.command(mode)); - const failures: unknown[] = []; - const value = setting === "model" ? "selected" : "high"; - const result = yield* document( - f, - mode, - ``, - report, - failures, - ); - expect(result.ok).toBe(false); - expect(failures).toEqual([ - { - reason: kind === "absent" ? "selector-unavailable" : "configuration-mismatch", - setting, + yield* captureTestJournal( + { owner: "packages/acp/tests/agent-certification.test.ts", name }, + join(f.dir, "document.md"), + function* (stream) { + const mode = kind + "-" + setting; + const report = reportFor(f.command(mode)); + const failures: unknown[] = []; + const value = setting === "model" ? "selected" : "high"; + const result = yield* document( + f, + mode, + ``, + report, + failures, + stream, + ); + expect(result.ok).toBe(false); + expect(failures).toEqual([ + { + reason: kind === "absent" ? "selector-unavailable" : "configuration-mismatch", + setting, + }, + ]); + const row = + setting === "model" ? report.capabilities.model : report.capabilities.effort; + expect(row.outcome).toBe(kind === "absent" ? "unsupported" : "failure"); + expect((yield* f.methods()).includes("session/prompt")).toBe(false); + expect(JSON.stringify(report)).not.toContain("must not send"); }, - ]); - const row = - setting === "model" ? report.capabilities.model : report.capabilities.effort; - expect(row.outcome).toBe(kind === "absent" ? "unsupported" : "failure"); - expect((yield* f.methods()).includes("session/prompt")).toBe(false); - expect(JSON.stringify(report)).not.toContain("must not send"); + ); }); }); } diff --git a/packages/agent/tests/package-boundary.test.ts b/packages/agent/tests/package-boundary.test.ts index 0c4e074ca..0d90829f1 100644 --- a/packages/agent/tests/package-boundary.test.ts +++ b/packages/agent/tests/package-boundary.test.ts @@ -1,3 +1,4 @@ +import { captureTestJournal } from "@executablemd/test-support/failure-journal"; /** * Tier PB — the boundary between Core and the Agent package. * @@ -18,7 +19,6 @@ import { randomUUID } from "node:crypto"; import * as os from "node:os"; import * as path from "node:path"; import { fileURLToPath } from "node:url"; -import { InMemoryStream } from "@executablemd/durable-streams"; import { execute } from "@executablemd/core"; import type { DocumentExecution, Json } from "@executablemd/core"; import { Agent } from "@executablemd/agent/api"; @@ -84,10 +84,10 @@ const echo: AgentProviderFactory = function* (options) { }; function* run( + dir: string, doc: string, start: (docPath: string) => Operation, ): Operation<{ output: string; result: Result }> { - const dir = path.join(os.tmpdir(), `xmd-pb-${randomUUID()}`); yield* ensureDir(dir); return yield* scoped(function* () { yield* ensure(() => rm(dir, { recursive: true, force: true })); @@ -103,6 +103,8 @@ function* run( }); } +const OWNER = "packages/agent/tests/package-boundary.test.ts"; + const DOCUMENT = '\n\n\n'; describe("Tier PB — Core resolves no Agent package", () => { @@ -135,34 +137,50 @@ describe("Tier PB — Core resolves no Agent package", () => { } }); - it("PB4: a Core-only execution cannot resolve the Agent vocabulary", function* () { + const vocabulary = "PB4: a Core-only execution cannot resolve the Agent vocabulary"; + it(vocabulary, function* () { for (const [doc, name] of [ [DOCUMENT, "Session"], ['\n', "Prompt"], ] as const) { - const { output, result } = yield* run(doc, (docPath) => - execute({ path: docPath, stream: new InMemoryStream() }), + const dir = path.join(os.tmpdir(), `xmd-pb-${randomUUID()}`); + yield* captureTestJournal( + { owner: OWNER, name: vocabulary }, + path.join(dir, "doc.md"), + function* (stream) { + const { output, result } = yield* run(dir, doc, (docPath) => + execute({ path: docPath, stream }), + ); + expect(output).not.toContain("[hello]"); + expect(!result.ok && result.error.message).toContain(`Cannot resolve component: ${name}`); + }, ); - expect(output).not.toContain("[hello]"); - expect(!result.ok && result.error.message).toContain(`Cannot resolve component: ${name}`); } }); - it("PB5: the Agent package installed over Core answers the same document", function* () { - const { output, result } = yield* run(DOCUMENT, function* (docPath) { - yield* installAgentComponents({ - rootProvider: { - factory: echo, - options: { defaultAgent: "pb", permissionMode: "deny-all" }, - }, - }); - return yield* executeInstalled({ path: docPath, stream: new InMemoryStream() }, [ - { components: agentIdentityComponents() }, - ]); - }); - if (!result.ok) { - throw result.error; - } - expect(output).toContain("[hello]"); + const positiveCase = "PB5: the Agent package installed over Core answers the same document"; + it(positiveCase, function* () { + const dir = path.join(os.tmpdir(), `xmd-pb-${randomUUID()}`); + yield* captureTestJournal( + { owner: OWNER, name: positiveCase }, + path.join(dir, "doc.md"), + function* (stream) { + const { output, result } = yield* run(dir, DOCUMENT, function* (docPath) { + yield* installAgentComponents({ + rootProvider: { + factory: echo, + options: { defaultAgent: "pb", permissionMode: "deny-all" }, + }, + }); + return yield* executeInstalled({ path: docPath, stream }, [ + { components: agentIdentityComponents() }, + ]); + }); + if (!result.ok) { + throw result.error; + } + expect(output).toContain("[hello]"); + }, + ); }); }); diff --git a/packages/cli/tests/plan-command-document.test.ts b/packages/cli/tests/plan-command-document.test.ts index 17b8626b9..8427e51d9 100644 --- a/packages/cli/tests/plan-command-document.test.ts +++ b/packages/cli/tests/plan-command-document.test.ts @@ -1,3 +1,4 @@ +import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal"; /** * The packaged plan command document, executed as itself. * @@ -18,7 +19,7 @@ * so what a row observes is the channel a person actually watches rather than a * transcript assembled afterwards. */ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; import { expect } from "@executablemd/test-support/expect"; import { ensure, scoped, sleep, spawn, useScope, withResolvers } from "effection"; import type { Operation } from "effection"; @@ -175,7 +176,10 @@ interface RunOptions { symbols?: SyntaxSymbols; } -function* runDocument(options: RunOptions = {}): Operation { +function* runDocument( + options: RunOptions = {}, + stream: InMemoryStream | undefined = undefined, +): Operation { const source = yield* readPackagedDocument(PLAN_COMMAND_DOCUMENT); let value: Json | undefined; @@ -235,7 +239,7 @@ function* runDocument(options: RunOptions = {}): Operation { const execution = yield* executeInstalled( { ...retainedSource(PLAN_COMMAND_IDENTITY, source), - stream: new InMemoryStream(), + stream: stream ?? (yield* useJournalStream(PLAN_COMMAND_IDENTITY)), includes: [], secretDetection: true, props: { @@ -340,7 +344,10 @@ function unattributed(chunks: readonly string[]): string[] { return kept; } +const OWNER = "packages/cli/tests/plan-command-document.test.ts"; + describe("the packaged plan command document", () => { + beforeEach(journalBeforeEach(OWNER)); it("C2: returns the approved candidate's exact bytes and never reaches exhaustion", function* () { const run = yield* useWorkingDirectory(function* () { return yield* runDocument(); @@ -744,6 +751,7 @@ describe("the packaged plan command document", () => { * through the captured operation — there is no other way to reach it. */ describe("Tier PI — read-only information requests", () => { + beforeEach(journalBeforeEach(OWNER)); /** One request that binds all three reads and renders a chosen object. */ const COMPOSED = [ '', @@ -1015,13 +1023,16 @@ describe("Tier PI — read-only information requests", () => { }); it("PI1: named documentation comes back, then an ordinary Plan", function* () { - const run = yield* runDocument({ - // Two of the three names this case's vocabulary has, asked for together. - // The third is the control: a selection that returned it would be a - // catalog injection wearing a selection's clothes. - turns: [{ reply: '\n' }, { reply: CANDIDATE }], - symbols: SELECTABLE, - }); + const run = yield* runDocument( + { + // Two of the three names this case's vocabulary has, asked for together. + // The third is the control: a selection that returned it would be a + // catalog injection wearing a selection's clothes. + turns: [{ reply: '\n' }, { reply: CANDIDATE }], + symbols: SELECTABLE, + }, + undefined, + ); expect(run.failure).toBe(undefined); const asked = run.prompts[0] ?? ""; @@ -1040,9 +1051,12 @@ describe("Tier PI — read-only information requests", () => { }); it("PI10: an unknown documented name is one retry, not a stopped invocation", function* () { - const run = yield* runDocument({ - turns: [{ reply: '\n' }, { reply: CANDIDATE }], - }); + const run = yield* runDocument( + { + turns: [{ reply: '\n' }, { reply: CANDIDATE }], + }, + undefined, + ); // Recoverable: the workflow asked again rather than ending, and the reason // quotes only the name the candidate itself wrote. @@ -1055,14 +1069,17 @@ describe("Tier PI — read-only information requests", () => { it("PI2: an empty match renders as an empty array", function* () { const files = recordedFiles({ "notes.md": "the retained note\n" }); - const run = yield* runDocument({ - turns: [ - { reply: '\n\n' }, - { reply: CANDIDATE }, - ], - generated: { File: ["self-closing"], Glob: ["self-closing"], Syntax: ["self-closing"] }, - files, - }); + const run = yield* runDocument( + { + turns: [ + { reply: '\n\n' }, + { reply: CANDIDATE }, + ], + generated: { File: ["self-closing"], Glob: ["self-closing"], Syntax: ["self-closing"] }, + files, + }, + undefined, + ); expect(run.failure).toBe(undefined); // The search ran and found nothing, and nothing is a result rather than a @@ -1316,11 +1333,14 @@ describe("Tier PI — read-only information requests", () => { it("PI3: a titled draft is never evaluated", function* () { const files = recordedFiles({ "notes.md": "the retained note\n" }); - const run = yield* runDocument({ - turns: [{ reply: CANDIDATE }], - generated: { File: ["self-closing"], Glob: ["self-closing"], Syntax: ["self-closing"] }, - files, - }); + const run = yield* runDocument( + { + turns: [{ reply: CANDIDATE }], + generated: { File: ["self-closing"], Glob: ["self-closing"], Syntax: ["self-closing"] }, + files, + }, + undefined, + ); expect(run.failure).toBe(undefined); // One turn, no evaluation, no information phase at all. diff --git a/packages/cli/tests/repl-model.test.ts b/packages/cli/tests/repl-model.test.ts index 01e71df20..a07d1b0df 100644 --- a/packages/cli/tests/repl-model.test.ts +++ b/packages/cli/tests/repl-model.test.ts @@ -1480,90 +1480,114 @@ describe("REPL model: which call of a repeated source owns its work", () => { }); }); +const SOURCE_OWNER = "packages/cli/tests/repl-model.test.ts"; + describe("REPL source ownership by import coordinate (#976)", () => { beforeAll(() => useTempFileCompiler()); it("SO1: sequential nested calls keep their own answers at every prefix and after serialization", function* () { - const run = yield* ownerRun(); - expect(run.output.trim()).toBe("first/second"); - for (let end = 1; end <= run.events.length; end++) { - const events = run.events.slice(0, end); - const model = projected(events); - expect(projected(copied(events))).toEqual(model); - const wrappers = only(model)?.scopes ?? []; - for (const [index, wrapper] of wrappers.entries()) { - const leaf = wrapper.scopes[0]; - expect(leaf?.name ?? "OwnerLeaf").toBe("OwnerLeaf"); - for (const question of leaf?.elicitations ?? []) { - expect(question).toMatchObject({ answer: index === 0 ? "first" : "second" }); + yield* captureTestJournal( + { + owner: SOURCE_OWNER, + name: "SO1: sequential nested calls keep their own answers at every prefix and after serialization", + }, + "", + function* (stream) { + const run = yield* ownerRun(undefined, stream); + expect(run.output.trim()).toBe("first/second"); + for (let end = 1; end <= run.events.length; end++) { + const events = run.events.slice(0, end); + const model = projected(events); + expect(projected(copied(events))).toEqual(model); + const wrappers = only(model)?.scopes ?? []; + for (const [index, wrapper] of wrappers.entries()) { + const leaf = wrapper.scopes[0]; + expect(leaf?.name ?? "OwnerLeaf").toBe("OwnerLeaf"); + for (const question of leaf?.elicitations ?? []) { + expect(question).toMatchObject({ answer: index === 0 ? "first" : "second" }); + } + } } - } - } - const leafImports = run.events.filter( - (event) => event.type === "yield" && event.description.name === "OwnerLeaf", + const leafImports = run.events.filter( + (event) => event.type === "yield" && event.description.name === "OwnerLeaf", + ); + expect( + leafImports.map((event) => + event.type === "yield" ? event.description[OWNER_FIELD] : undefined, + ), + ).toEqual([ + { coroutineId: "root", index: 1 }, + { coroutineId: "root", index: 5 }, + ]); + const entry = only(projected(run.events)); + expect(entry?.scopes.map((wrapper) => wrapper.scopes.map((leaf) => leaf.name))).toEqual([ + ["OwnerLeaf"], + ["OwnerLeaf"], + ]); + expect(entry?.bindings).toEqual([ + { name: "first", value: "first" }, + { name: "second", value: "second" }, + ]); + }, ); - expect( - leafImports.map((event) => - event.type === "yield" ? event.description[OWNER_FIELD] : undefined, - ), - ).toEqual([ - { coroutineId: "root", index: 1 }, - { coroutineId: "root", index: 5 }, - ]); - const entry = only(projected(run.events)); - expect(entry?.scopes.map((wrapper) => wrapper.scopes.map((leaf) => leaf.name))).toEqual([ - ["OwnerLeaf"], - ["OwnerLeaf"], - ]); - expect(entry?.bindings).toEqual([ - { name: "first", value: "first" }, - { name: "second", value: "second" }, - ]); }); it("SO2: repeated loop sites and caller Content keep their lexical source owner", function* () { - const source = - '\n'; - const run = yield* ownerRun(source); - const entry = only(projected(run.events)); - expect(entry?.scopes.map((scope) => scope.name)).toEqual([ - "OwnerWrapper", - "OwnerWrapper", - "OwnerContent", - "OwnerWrapper", - ]); - expect(entry?.scopes[2].scopes).toEqual([]); - expect( - entry?.scopes - .filter((scope) => scope.name === "OwnerWrapper") - .map((scope) => scope.scopes[0]?.elicitations[0]), - ).toMatchObject([{ answer: "same" }, { answer: "same" }, { answer: "caller" }]); - const wrappers = run.events.filter( - (event) => event.type === "yield" && event.description.name === "OwnerWrapper", - ); - expect(wrappers).toHaveLength(3); - const yields = run.events.filter((event) => event.type === "yield"); - const wrapperCoordinates = yields.flatMap((event, index) => - event.description.name === "OwnerWrapper" ? [{ coroutineId: event.coroutineId, index }] : [], - ); - const leafOwners = yields - .filter((event) => event.description.name === "OwnerLeaf") - .map((event) => event.description[OWNER_FIELD]); - expect(leafOwners).toEqual(wrapperCoordinates); - expect( - wrappers[0].type === "yield" && wrappers[0].description["executablemd.source-position"], - ).toEqual( - wrappers[1].type === "yield" && wrappers[1].description["executablemd.source-position"], - ); + yield* captureTestJournal( + { + owner: SOURCE_OWNER, + name: "SO2: repeated loop sites and caller Content keep their lexical source owner", + }, + "", + function* (stream) { + const source = + '\n'; + const run = yield* ownerRun(source, stream); + const entry = only(projected(run.events)); + expect(entry?.scopes.map((scope) => scope.name)).toEqual([ + "OwnerWrapper", + "OwnerWrapper", + "OwnerContent", + "OwnerWrapper", + ]); + expect(entry?.scopes[2].scopes).toEqual([]); + expect( + entry?.scopes + .filter((scope) => scope.name === "OwnerWrapper") + .map((scope) => scope.scopes[0]?.elicitations[0]), + ).toMatchObject([{ answer: "same" }, { answer: "same" }, { answer: "caller" }]); + const wrappers = run.events.filter( + (event) => event.type === "yield" && event.description.name === "OwnerWrapper", + ); + expect(wrappers).toHaveLength(3); + const yields = run.events.filter((event) => event.type === "yield"); + const wrapperCoordinates = yields.flatMap((event, index) => + event.description.name === "OwnerWrapper" + ? [{ coroutineId: event.coroutineId, index }] + : [], + ); + const leafOwners = yields + .filter((event) => event.description.name === "OwnerLeaf") + .map((event) => event.description[OWNER_FIELD]); + expect(leafOwners).toEqual(wrapperCoordinates); + expect( + wrappers[0].type === "yield" && wrappers[0].description["executablemd.source-position"], + ).toEqual( + wrappers[1].type === "yield" && wrappers[1].description["executablemd.source-position"], + ); - for (const event of wrappers) { - if (event.type === "yield") { - expect(event.description[OWNER_FIELD]).toEqual({ coroutineId: "root", index: 0 }); - } - } + for (const event of wrappers) { + if (event.type === "yield") { + expect(event.description[OWNER_FIELD]).toEqual({ coroutineId: "root", index: 0 }); + } + } + }, + ); }); - it("SO7: ordinary middleware copies preserve evaluated blocks' source ownership", function* () { + const copiedSource = + "SO7: ordinary middleware copies preserve evaluated blocks' source ownership"; + it(copiedSource, function* () { const source = [ '', '', @@ -1575,46 +1599,50 @@ describe("REPL source ownership by import coordinate (#976)", () => { "{first}/{second}", ].join("\n"); for (const copy of [false, true]) { - yield* scoped(function* () { - let forwarded = 0; - if (copy) { - yield* Component.around({ - *applyModifiers([modifiers, block], next) { - forwarded += 1; - return yield* next(modifiers, { ...block }); - }, - }); - } - const run = yield* ownerRun(source); - expect(run.output.trim()).toBe("first/second"); - expect(forwarded).toBe(copy ? 3 : 0); - const evaluations = run.events.filter( - (event) => event.type === "yield" && event.description.type === "eval", - ); - expect( - evaluations.map((event) => - event.type === "yield" ? event.description[OWNER_FIELD] : undefined, - ), - ).toEqual([ - { coroutineId: "root", index: 1 }, - { coroutineId: "root", index: 3 }, - { coroutineId: "root", index: 0 }, - ]); - for (let end = 1; end <= run.events.length; end++) { - const prefix = run.events.slice(0, end); - expect(projected(copied(prefix))).toEqual(projected(prefix)); - } - const entry = only(projected(copied(run.events))); - if (entry === undefined) { - throw new Error("the journal admits one entry"); - } - expect(entry.scopes.map((scope) => scope.bindings)).toEqual([ - [{ name: "value", value: "first" }], - [{ name: "value", value: "second" }], - [], - ]); - expect(binding(entry, "callerValue")).toBe("caller"); - }); + yield* captureTestJournal( + { owner: SOURCE_OWNER, name: copiedSource }, + "", + function* (stream) { + let forwarded = 0; + if (copy) { + yield* Component.around({ + *applyModifiers([modifiers, block], next) { + forwarded += 1; + return yield* next(modifiers, { ...block }); + }, + }); + } + const run = yield* ownerRun(source, stream); + expect(run.output.trim()).toBe("first/second"); + expect(forwarded).toBe(copy ? 3 : 0); + const evaluations = run.events.filter( + (event) => event.type === "yield" && event.description.type === "eval", + ); + expect( + evaluations.map((event) => + event.type === "yield" ? event.description[OWNER_FIELD] : undefined, + ), + ).toEqual([ + { coroutineId: "root", index: 1 }, + { coroutineId: "root", index: 3 }, + { coroutineId: "root", index: 0 }, + ]); + for (let end = 1; end <= run.events.length; end++) { + const prefix = run.events.slice(0, end); + expect(projected(copied(prefix))).toEqual(projected(prefix)); + } + const entry = only(projected(copied(run.events))); + if (entry === undefined) { + throw new Error("the journal admits one entry"); + } + expect(entry.scopes.map((scope) => scope.bindings)).toEqual([ + [{ name: "value", value: "first" }], + [{ name: "value", value: "second" }], + [], + ]); + expect(binding(entry, "callerValue")).toBe("caller"); + }, + ); } }); diff --git a/packages/cli/tests/testing-activation.test.ts b/packages/cli/tests/testing-activation.test.ts index aecda746a..6d4c94151 100644 --- a/packages/cli/tests/testing-activation.test.ts +++ b/packages/cli/tests/testing-activation.test.ts @@ -14,7 +14,6 @@ import { expect } from "@executablemd/test-support/expect"; import { scoped } from "effection"; import type { Operation } from "effection"; import { createApi } from "@effectionx/context-api"; -import { InMemoryStream } from "@executablemd/durable-streams"; import type { DurableEvent } from "@executablemd/durable-streams"; import { inlineSource, registerComponents, useTempFileCompiler } from "@executablemd/core"; import type { Json } from "@executablemd/core"; @@ -23,6 +22,9 @@ import { retainedWorkflowInstallation } from "@executablemd/workflow"; import { GitQuery } from "@executablemd/git/api"; import { installTestingComponents } from "@executablemd/testing"; import type { TestResult } from "@executablemd/testing"; +import { captureTestJournal } from "@executablemd/test-support/failure-journal"; + +const OWNER = "packages/cli/tests/testing-activation.test.ts"; const RUN = Object.freeze({ runId: "issue-523", @@ -53,61 +55,71 @@ function publicTestPolicy() { describe("workflow installation and testing activation", () => { it("refuses a the installation did not activate, before its body runs", function* () { - const sentinels: string[] = []; - const results: TestResult[] = []; - const stream = new InMemoryStream(); + yield* captureTestJournal( + { + owner: OWNER, + name: "refuses a the installation did not activate, before its body runs", + }, + "", + function* (stream) { + const sentinels: string[] = []; + const results: TestResult[] = []; - const outcome = yield* scoped(function* () { - yield* useTempFileCompiler(); - yield* useForbiddenGit(); - yield* registerComponents([ - { - name: "Sentinel", - origin: "issue-523", - props: { type: "object", properties: {}, additionalProperties: false }, - // deno-lint-ignore require-yield - *fn(): Operation { - sentinels.push("body"); - return ""; - }, - }, - ]); - const policy = publicTestPolicy(); - yield* policy.around({ - *record([result], next) { - results.push(result); - yield* next(result); - }, - }); + const outcome = yield* scoped(function* () { + yield* useTempFileCompiler(); + yield* useForbiddenGit(); + yield* registerComponents([ + { + name: "Sentinel", + origin: "issue-523", + props: { type: "object", properties: {}, additionalProperties: false }, + // deno-lint-ignore require-yield + *fn(): Operation { + sentinels.push("body"); + return ""; + }, + }, + ]); + const policy = publicTestPolicy(); + yield* policy.around({ + *record([result], next) { + results.push(result); + yield* next(result); + }, + }); - // The whole of the composition: components registered, testing mode on, - // and a trusted host installation that is not a testing session. - yield* installTestingComponents(); - yield* policy.around({ testing: () => true }); + // The whole of the composition: components registered, testing mode on, + // and a trusted host installation that is not a testing session. + yield* installTestingComponents(); + yield* policy.around({ testing: () => true }); - const execution = yield* executeInstalled( - { - ...inlineSource('\n'), - stream, - }, - [retainedWorkflowInstallation(RUN)], - ); - return yield* execution; - }); + const execution = yield* executeInstalled( + { + ...inlineSource('\n'), + stream, + }, + [retainedWorkflowInstallation(RUN)], + ); + return yield* execution; + }); - expect(sentinels).toEqual([]); - expect(outcome.ok).toBe(false); - if (!outcome.ok) { - expect(outcome.error.message).toContain("complete testing activation"); - } - expect(results).toEqual([]); + expect(sentinels).toEqual([]); + expect(outcome.ok).toBe(false); + if (!outcome.ok) { + expect(outcome.error.message).toContain("complete testing activation"); + } + expect(results).toEqual([]); - // The run itself was prepared and journaled; what it holds is the workflow's - // own record and no test result. - const events: DurableEvent[] = yield* stream.readAll(); - expect(events.length).toBeGreaterThan(0); - expect( - events.filter((event) => event.type === "yield" && event.description.type === "test_result"), - ).toEqual([]); + // The run itself was prepared and journaled; what it holds is the workflow's + // own record and no test result. + const events: DurableEvent[] = yield* stream.readAll(); + expect(events.length).toBeGreaterThan(0); + expect( + events.filter( + (event) => event.type === "yield" && event.description.type === "test_result", + ), + ).toEqual([]); + }, + ); }); }); diff --git a/packages/cli/tests/upgrade-command-document.test.ts b/packages/cli/tests/upgrade-command-document.test.ts index 9dcd18ff4..e2ebdb1f6 100644 --- a/packages/cli/tests/upgrade-command-document.test.ts +++ b/packages/cli/tests/upgrade-command-document.test.ts @@ -1,3 +1,5 @@ +import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal"; +import { UPGRADE_COMMAND_IDENTITY } from "../src/upgrade.ts"; /** * Tier UG — the packaged upgrade command document, executed as itself. * @@ -20,7 +22,7 @@ * The include list is empty on purpose. Repository component search must not be * able to supply `If`, `Return`, `Fail` or either upgrade component. */ -import { beforeAll, describe, it } from "@executablemd/test-support/bdd"; +import { beforeAll, beforeEach, describe, it } from "@executablemd/test-support/bdd"; import { expect } from "@executablemd/test-support/expect"; import { scoped } from "effection"; import type { Operation } from "effection"; @@ -262,7 +264,7 @@ function* refuseHostCapabilities(): Operation { }); } -function* upgrade(scenario: Scenario): Operation { +function* upgrade(scenario: Scenario, stream?: InMemoryStream): Operation { const run: Run = { releaseReads: [], downloads: [], @@ -308,7 +310,7 @@ function* upgrade(scenario: Scenario): Operation { allowPrerelease: scenario.allowPrerelease === true, }, assembly, - stream: new InMemoryStream(), + stream: stream ?? (yield* useJournalStream(UPGRADE_COMMAND_IDENTITY)), // deno-lint-ignore require-yield *consume(chunk) { chunks.push(chunk); @@ -348,7 +350,10 @@ function transcript(run: Run): string[] { .filter((line) => line.length > 0); } +const OWNER = "packages/cli/tests/upgrade-command-document.test.ts"; + describe("Tier UG — the packaged upgrade command document", () => { + beforeEach(journalBeforeEach(OWNER)); beforeAll(() => useTempFileCompiler()); it("UG1: an authorized install renders its milestones in source order", function* () { diff --git a/packages/core/tests/code-block-component.test.ts b/packages/core/tests/code-block-component.test.ts index fac4774ac..8ef3c8b44 100644 --- a/packages/core/tests/code-block-component.test.ts +++ b/packages/core/tests/code-block-component.test.ts @@ -23,7 +23,7 @@ * inferred. */ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; import { expect } from "@executablemd/test-support/expect"; import { scoped } from "effection"; import type { Operation } from "effection"; @@ -34,6 +34,9 @@ import { collect } from "../src/collect.ts"; import { execute } from "../src/execute.ts"; import { registerComponents } from "../src/components/registration.ts"; import type { Json } from "../src/types.ts"; +import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal"; + +const OWNER = "packages/core/tests/code-block-component.test.ts"; interface Run { /** Everything the document emitted, before any output middleware. */ @@ -52,7 +55,11 @@ function reported(result: Run): string { } /** Run `source` as the document, with `values` reachable through ``. */ -function run(source: string, values: Record = {}): Operation { +function run( + stream: InMemoryStream | undefined, + source: string, + values: Record = {}, +): Operation { return scoped(function* () { const probed: string[] = []; let tripped = 0; @@ -100,7 +107,10 @@ function run(source: string, values: Record = {}): Operation = {}): Operation` invocation renders, with nothing around it. */ -function* directly(value: string, attributes = ""): Operation { - return yield* run(``, { v: value }); +function* directly( + stream: InMemoryStream | undefined, + value: string, + attributes = "", +): Operation { + return yield* run(undefined, ``, { + v: value, + }); } /** The exact string `as` bound, at the capture boundary. */ -function* captured(value: string, attributes = ""): Operation { +function* captured( + stream: InMemoryStream | undefined, + value: string, + attributes = "", +): Operation { const result = yield* run( + stream, ``, { v: value }, ); @@ -129,24 +150,26 @@ function* captured(value: string, attributes = ""): Operation { } describe("Tier CB — the envelope", () => { + beforeEach(journalBeforeEach(OWNER)); it("CB1: an empty value is three backticks, two line feeds and nothing else", function* () { - const result = yield* directly(""); + const result = yield* directly(undefined, ""); expect(result.failure).toBe(""); expect(result.output).toBe("```\n\n```"); - expect(yield* captured("")).toBe("```\n\n```"); + expect(yield* captured(undefined, "")).toBe("```\n\n```"); }); it("CB1: ordinary Markdown keeps its own lines, and gains no final line feed", function* () { const value = "# Title\n\n- one\n- two"; - const result = yield* directly(value); + const result = yield* directly(undefined, value); expect(result.output).toBe("```\n# Title\n\n- one\n- two\n```"); - expect(yield* captured(value)).toBe("```\n# Title\n\n- one\n- two\n```"); + expect(yield* captured(undefined, value)).toBe("```\n# Title\n\n- one\n- two\n```"); }); it("CB1: the block lands where the element was written", function* () { const result = yield* run( + undefined, 'before\n\n\n\nafter\n', { v: "shown" }, ); @@ -159,6 +182,7 @@ describe("Tier CB — the envelope", () => { }); describe("Tier CB — the fence the value cannot close", () => { + beforeEach(journalBeforeEach(OWNER)); it("CB2: the fence is the longest backtick run plus one, never fewer than three", function* () { const cases: ReadonlyArray = [ ["no backticks at all", 3], @@ -174,7 +198,7 @@ describe("Tier CB — the fence the value cannot close", () => { ]; for (const [value, length] of cases) { - const block = yield* captured(value); + const block = yield* captured(undefined, value); const fence = "`".repeat(length); expect(block).toBe(`${fence}\n${value}\n${fence}`); @@ -187,8 +211,8 @@ describe("Tier CB — the fence the value cannot close", () => { it("CB2: a run broken by any other character is two runs, not one", function* () { // Counting backticks without resetting would read five here and open a // six-backtick fence. - expect(yield* captured("```\n``")).toBe("````\n```\n``\n````"); - expect(yield* captured("``x``x``")).toBe("```\n``x``x``\n```"); + expect(yield* captured(undefined, "```\n``")).toBe("````\n```\n``\n````"); + expect(yield* captured(undefined, "``x``x``")).toBe("```\n``x``x``\n```"); }); }); @@ -203,7 +227,7 @@ describe("Tier CB — the value is not read for anything else", () => { "`` two `````` six", "trailing spaces ", ].join("\n"); - const block = yield* captured(value); + const block = yield* captured(undefined, value); // The value's longest run is six backticks, so the fence is seven. const fence = "`".repeat(7); @@ -219,15 +243,16 @@ describe("Tier CB — the value is not read for anything else", () => { }); describe("Tier CB — the language token", () => { + beforeEach(journalBeforeEach(OWNER)); it("CB4: an omitted language leaves the opening fence bare", function* () { - expect((yield* captured("plain")).split("\n")[0]).toBe("```"); + expect((yield* captured(undefined, "plain")).split("\n")[0]).toBe("```"); }); it("CB4: every accepted token renders on the opening fence, unchanged", function* () { const accepted = ["markdown", "md", "json", "shell-session", "c++", "c#", "F", "x1._+#-"]; for (const language of accepted) { - const result = yield* directly("body", ` language="${language}"`); + const result = yield* directly(undefined, "body", ` language="${language}"`); expect(result.failure).toBe(""); expect(result.output).toBe("```" + language + "\nbody\n```"); @@ -261,6 +286,7 @@ describe("Tier CB — the language token", () => { for (const language of refused) { const result = yield* run( + undefined, '', { v: "body", lang: language }, ); @@ -274,8 +300,9 @@ describe("Tier CB — the language token", () => { }); describe("Tier CB — the invocation is refused before the body", () => { + beforeEach(journalBeforeEach(OWNER)); it("CB5: a missing value is the engine's own required-prop refusal", function* () { - const result = yield* run(""); + const result = yield* run(undefined, ""); expect(reported(result)).toContain("Prop validation failed for "); expect(reported(result)).toContain("value"); @@ -284,7 +311,7 @@ describe("Tier CB — the invocation is refused before the body", () => { it("CB5: a non-string value is refused rather than coerced", function* () { for (const value of ["42", "true", "null", "{ text: 'x' }", "['x']"]) { - const result = yield* run(``); + const result = yield* run(undefined, ``); expect(reported(result)).toContain("Prop validation failed for "); expect(result.output).not.toContain("```"); @@ -292,7 +319,7 @@ describe("Tier CB — the invocation is refused before the body", () => { }); it("CB5: an unknown prop is refused, and nothing renders", function* () { - const result = yield* directly("body", ' fence="~~~"'); + const result = yield* directly(undefined, "body", ' fence="~~~"'); expect(reported(result)).toContain("Prop validation failed for "); expect(reported(result)).toContain("fence"); @@ -301,6 +328,7 @@ describe("Tier CB — the invocation is refused before the body", () => { it("CB5: paired content is refused by form, and the content never expands", function* () { const result = yield* run( + undefined, '', { v: "body" }, ); @@ -312,9 +340,13 @@ describe("Tier CB — the invocation is refused before the body", () => { }); it("CB5: empty paired content is still the paired form", function* () { - const result = yield* run('', { - v: "body", - }); + const result = yield* run( + undefined, + '', + { + v: "body", + }, + ); expect(reported(result)).toContain(""); expect(result.output).not.toContain("```"); @@ -338,7 +370,7 @@ const HOSTILE = [ describe("Tier CB — inertness and capture", () => { it("CB6: candidate-like content is shown, not run, and not escaped", function* () { - const result = yield* directly(HOSTILE); + const result = yield* directly(undefined, HOSTILE); expect(result.failure).toBe(""); expect(result.tripped).toBe(0); @@ -351,8 +383,9 @@ describe("Tier CB — inertness and capture", () => { }); it("CB6: `as` binds that exact string and emits nothing where it was written", function* () { - const direct = yield* directly(HOSTILE); + const direct = yield* directly(undefined, HOSTILE); const result = yield* run( + undefined, 'beforeafter', { v: HOSTILE }, ); diff --git a/packages/core/tests/compiler-boundary.test.ts b/packages/core/tests/compiler-boundary.test.ts index 4dfb4c1a1..11c8361d6 100644 --- a/packages/core/tests/compiler-boundary.test.ts +++ b/packages/core/tests/compiler-boundary.test.ts @@ -6,30 +6,40 @@ * no compiler, one with eval blocks says so plainly when none is installed, * and a compiler the caller installed is the one that runs. */ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; import { expect } from "@executablemd/test-support/expect"; import type { Operation } from "effection"; -import { InMemoryStream } from "@executablemd/durable-streams"; +import type { InMemoryStream } from "@executablemd/durable-streams"; +import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal"; import { useStubFs } from "@executablemd/runtime/test"; import { API } from "@executablemd/runtime"; import { asText, completion } from "./helpers.ts"; +const OWNER = "packages/core/tests/compiler-boundary.test.ts"; /** What the run said: its rendered text, or the failure it reported. */ -function* runDoc(source: string): Operation { +function* runDoc(stream: InMemoryStream | undefined, source: string): Operation { yield* useStubFs({ "doc.md": source }); - const result = yield* completion({ path: "doc.md", stream: new InMemoryStream() }); + const result = yield* completion({ + path: "doc.md", + stream: stream ?? (yield* useJournalStream("doc.md")), + }); return result.ok ? asText(result.value) : result.error.message; } describe("Tier CB — compiler boundary", () => { + beforeEach(journalBeforeEach(OWNER)); + it("CB1: a document without eval blocks runs with no compiler installed", function* () { - const output = yield* runDoc("# Plain\n\nJust prose, no fences.\n"); + const output = yield* runDoc(undefined, "# Plain\n\nJust prose, no fences.\n"); expect(output).toContain("Just prose, no fences."); expect(output).not.toContain("ERROR"); }); it("CB2: an eval block without compiler middleware reports that explicitly", function* () { - const output = yield* runDoc(["# Doc", "", "```js eval", "env.x = 1;", "```", ""].join("\n")); + const output = yield* runDoc( + undefined, + ["# Doc", "", "```js eval", "env.x = 1;", "```", ""].join("\n"), + ); expect(output).toContain("compiler not installed"); expect(output).toContain("API.Env.around()"); }); @@ -48,7 +58,10 @@ describe("Tier CB — compiler boundary", () => { { at: "min" }, ); - const output = yield* runDoc(["# Doc", "", "```js eval", "env.x = 1;", "```", ""].join("\n")); + const output = yield* runDoc( + undefined, + ["# Doc", "", "```js eval", "env.x = 1;", "```", ""].join("\n"), + ); expect(output).not.toContain("compiler not installed"); expect(compiled).toHaveLength(1); expect(compiled[0]).toContain("env.x = 1;"); diff --git a/packages/core/tests/component-invocation-hooks.test.ts b/packages/core/tests/component-invocation-hooks.test.ts index ce12a620f..c5fd57f8b 100644 --- a/packages/core/tests/component-invocation-hooks.test.ts +++ b/packages/core/tests/component-invocation-hooks.test.ts @@ -23,12 +23,13 @@ import type { import { retainedSource } from "../src/root-source.ts"; import { useHeldHost } from "./support/held-host.ts"; +const owner = "packages/core/tests/component-invocation-hooks.test.ts"; + const props = { type: "object", properties: {}, additionalProperties: false }; function declaration(body: () => Operation, name = "Observed"): IdentityComponent { return { name, origin: "test://observation", props, factory: () => body }; } -function* run(source: string, installation: ExecutionInstallation) { - const stream = new InMemoryStream(); +function* run(source: string, installation: ExecutionInstallation, stream = new InMemoryStream()) { const execution = yield* executeInstalled({ ...retainedSource("hooks.md", source), stream }, [ installation, ]); @@ -40,7 +41,7 @@ function* text(): Operation { } describe("Installation-owned component observation", () => { - beforeEach(journalBeforeEach("packages/core/tests/component-invocation-hooks.test.ts")); + beforeEach(journalBeforeEach(owner)); it("R4a/R6: preserves dual-form dispatch, generated identity and accepted values", function* () { const stream = yield* useJournalStream("hooks.md"); @@ -429,7 +430,10 @@ describe("Installation-owned component observation", () => { }); describe("Invocation observation settlement", () => { + beforeEach(journalBeforeEach(owner)); + it("R4a: successful component cleanup and after cleanup precede caller continuation", function* () { + const stream = yield* useJournalStream("hooks.md"); const cleaning = withResolvers(); const release = withResolvers(); const notified = withResolvers(); @@ -437,26 +441,30 @@ describe("Invocation observation settlement", () => { let after = false; let continued = false; const execution = yield* spawn(function* () { - const result = yield* run('', { - components: [ - declaration(function* () { - yield* ensure(function* () { - cleaning.resolve(); - yield* release.operation; - }); - return { actual: true }; - }), - ], - componentInvocations: { - *after(_observation, result, cancelled) { - after = true; - expect(result.ok && result.value).toEqual({ actual: true }); - expect(cancelled).toBe(false); - yield* ensure(() => afterRelease.operation); - notified.resolve(); + const result = yield* run( + '', + { + components: [ + declaration(function* () { + yield* ensure(function* () { + cleaning.resolve(); + yield* release.operation; + }); + return { actual: true }; + }), + ], + componentInvocations: { + *after(_observation, result, cancelled) { + after = true; + expect(result.ok && result.value).toEqual({ actual: true }); + expect(cancelled).toBe(false); + yield* ensure(() => afterRelease.operation); + notified.resolve(); + }, }, }, - }); + stream, + ); expect(result.result.ok).toBe(true); continued = true; }); @@ -471,6 +479,7 @@ describe("Invocation observation settlement", () => { }); it("R4d: nested notifications unwind and outer after survives inner after failure", function* () { + const stream = yield* useJournalStream("hooks.md"); const order: string[] = []; const failure = new Error("inner after"); const components = [ @@ -479,22 +488,26 @@ describe("Invocation observation settlement", () => { }, "Outer"), declaration(text, "Inner"), ]; - const result = yield* run("", { - components, - componentInvocations: { - *before(observation) { - order.push(`before:${observation.component}`); - yield* sleep(0); - }, - *after(observation) { - order.push(`after:${observation.component}`); - if (observation.component === "Inner") { - throw failure; - } - yield* sleep(0); + const result = yield* run( + "", + { + components, + componentInvocations: { + *before(observation) { + order.push(`before:${observation.component}`); + yield* sleep(0); + }, + *after(observation) { + order.push(`after:${observation.component}`); + if (observation.component === "Inner") { + throw failure; + } + yield* sleep(0); + }, }, }, - }); + stream, + ); expect(result.result.ok).toBe(false); expect(order).toEqual(["before:Outer", "before:Inner", "after:Inner", "after:Outer"]); }); diff --git a/packages/core/tests/eval-durable.test.ts b/packages/core/tests/eval-durable.test.ts index a56d1d1f6..458d093d4 100644 --- a/packages/core/tests/eval-durable.test.ts +++ b/packages/core/tests/eval-durable.test.ts @@ -6,7 +6,8 @@ * * Uses InMemoryStream for journaling and API.Fs/API.Process middleware for I/O stubs. */ -import { describe, it, beforeAll } from "@executablemd/test-support/bdd"; +import { describe, it, beforeAll, beforeEach } from "@executablemd/test-support/bdd"; +import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal"; import { useTempFileCompiler } from "../src/temp-file-compiler.ts"; import { expect } from "@executablemd/test-support/expect"; import { InMemoryStream } from "@executablemd/durable-streams"; @@ -14,12 +15,14 @@ import { useStubFs, useEchoExec } from "@executablemd/runtime/test"; import { execute } from "../src/execute.ts"; import { collect } from "../src/collect.ts"; import { completion, failureMessage } from "./helpers.ts"; +const owner = "packages/core/tests/eval-durable.test.ts"; describe("Tier T4 — eval factory and journal integration", () => { beforeAll(() => useTempFileCompiler()); + beforeEach(journalBeforeEach(owner)); // T31: Golden run — journal entry written with serializable exports it("T31: golden run — journal records eval entry", function* () { - const stream = new InMemoryStream(); + const stream = yield* useJournalStream("test.md"); const files = { "test.md": "```js eval\nconst x = 42;\n```\n", }; @@ -112,7 +115,7 @@ describe("Tier T4 — eval factory and journal integration", () => { // T36: Serializable binding — present in journal result it("T36: serializable binding present in journal", function* () { - const stream = new InMemoryStream(); + const stream = yield* useJournalStream("test.md"); const files = { "test.md": '```js eval\nconst port = 3000;\nconst host = "localhost";\n```\n', }; @@ -132,7 +135,7 @@ describe("Tier T4 — eval factory and journal integration", () => { // T37: Non-serializable binding — absent from journal, present live it("T37: non-serializable binding omitted from journal", function* () { - const stream = new InMemoryStream(); + const stream = yield* useJournalStream("test.md"); const files = { "test.md": "```js eval\nconst fn = () => 42;\nconst x = 1;\n```\n", }; @@ -153,7 +156,7 @@ describe("Tier T4 — eval factory and journal integration", () => { // T-import-1: eval block with user import — runs through full pipeline it("T-import-1: eval block with user import runs correctly", function* () { - const stream = new InMemoryStream(); + const stream = yield* useJournalStream("test.md"); // Import from a well-known Deno/Node built-in to avoid needing // an actual package. We use a self-contained data: URI import // that's resolvable at runtime. diff --git a/packages/core/tests/eval-persist.test.ts b/packages/core/tests/eval-persist.test.ts index da61060e0..f1246c731 100644 --- a/packages/core/tests/eval-persist.test.ts +++ b/packages/core/tests/eval-persist.test.ts @@ -7,7 +7,8 @@ * Note: In v1, persist delegates directly to next() — actual * resource retention via evalScope.eval() is deferred to v2. */ -import { describe, it, beforeAll } from "@executablemd/test-support/bdd"; +import { describe, it, beforeAll, beforeEach } from "@executablemd/test-support/bdd"; +import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal"; import { useTempFileCompiler } from "../src/temp-file-compiler.ts"; import { expect } from "@executablemd/test-support/expect"; import { InMemoryStream } from "@executablemd/durable-streams"; @@ -18,11 +19,14 @@ import { asText } from "./helpers.ts"; import { unbox } from "effection"; import type { Result } from "effection"; +const owner = "packages/core/tests/eval-persist.test.ts"; + describe("Tier T6 — persist modifier", () => { beforeAll(() => useTempFileCompiler()); + beforeEach(journalBeforeEach(owner)); // T43: eval without persist → block completes normally it("T43: eval without persist → block completes", function* () { - const stream = new InMemoryStream(); + const stream = yield* useJournalStream("test.md"); yield* useStubFs({ "test.md": "```js eval\nconst x = 42;\n```\n", }); @@ -43,7 +47,7 @@ describe("Tier T6 — persist modifier", () => { // T44: persist eval → block completes normally it("T44: persist eval → block completes normally", function* () { - const stream = new InMemoryStream(); + const stream = yield* useJournalStream("test.md"); yield* useStubFs({ "test.md": "```js persist eval\nconst server = 'running';\n```\n", }); @@ -64,7 +68,7 @@ describe("Tier T6 — persist modifier", () => { // T45: persist eval followed by eval → bindings available it("T45: persist eval followed by eval → bindings available", function* () { - const stream = new InMemoryStream(); + const stream = yield* useJournalStream("test.md"); yield* useStubFs({ "test.md": "```js persist eval\nconst server = 'started';\n```\n\n```js eval\nconst status = server;\n```\n", @@ -135,7 +139,7 @@ describe("Tier T6 — persist modifier", () => { // L2: without persist, a resource a block spawns is torn down when the block // completes — the negative that gives L3 its meaning. it("L2: a non-persist eval block's resource is gone by the next block", function* () { - const stream = new InMemoryStream(); + const stream = yield* useJournalStream("test.md"); yield* useStubFs({ "test.md": [ "```js eval", @@ -163,7 +167,7 @@ describe("Tier T6 — persist modifier", () => { // L3: a persist resource belongs to the invocation, so a block after the // component sees it gone while the document is still running. it("L3: a persist resource stops when the invocation completes", function* () { - const stream = new InMemoryStream(); + const stream = yield* useJournalStream("doc.md"); yield* useStubFs({ "components/Holder.md": [ "```js persist eval", @@ -195,7 +199,7 @@ describe("Tier T6 — persist modifier", () => { // retained for itself — even though the component retained that one after // projecting, which is the order a single scope would release in reverse. it("L8: a projected persist resource stops before the component's own", function* () { - const stream = new InMemoryStream(); + const stream = yield* useJournalStream("doc.md"); yield* useStubFs({ "components/Holder.md": [ "", @@ -241,7 +245,7 @@ describe("Tier T6 — persist modifier", () => { // A background task spawned in a persist eval block sets status.ready // after 10ms. The next eval block uses when() to converge on it. it("T49b: persist eval retains spawned resource across blocks", function* () { - const stream = new InMemoryStream(); + const stream = yield* useJournalStream("test.md"); yield* useStubFs({ "test.md": [ "```js persist eval", diff --git a/packages/core/tests/exec-timeout.test.ts b/packages/core/tests/exec-timeout.test.ts index 8584b868b..1d47eadb6 100644 --- a/packages/core/tests/exec-timeout.test.ts +++ b/packages/core/tests/exec-timeout.test.ts @@ -9,16 +9,18 @@ * these cases are what stop the local contract from being reimplemented as a * scan of the info string somewhere else in the chain. */ -import { describe, it, beforeAll } from "@executablemd/test-support/bdd"; +import { describe, it, beforeAll, beforeEach } from "@executablemd/test-support/bdd"; +import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { scoped } from "effection"; import type { Operation } from "effection"; -import { InMemoryStream } from "@executablemd/durable-streams"; +import type { InMemoryStream } from "@executablemd/durable-streams"; import { ephemeral } from "@executablemd/durable-streams"; import { API, Config, timeoutExec } from "@executablemd/runtime"; import type { ConfigApi } from "@executablemd/runtime"; import { useStubFs } from "@executablemd/runtime/test"; import { execute } from "../src/execute.ts"; +import { captureTestJournal } from "@executablemd/test-support/failure-journal"; import { collect } from "../src/collect.ts"; import { useTempFileCompiler } from "../src/temp-file-compiler.ts"; import type { ModifierFactory } from "../src/modifiers.ts"; @@ -35,6 +37,7 @@ interface Run { } function* run( + stream: InMemoryStream, body: string, options: { config?: Partial; modifiers?: Record } = {}, ): Operation { @@ -61,7 +64,7 @@ function* run( }); const execution = yield* execute({ path: "test.md", - stream: new InMemoryStream(), + stream, ...(options.modifiers ? { modifiers: options.modifiers } : {}), }); const result = yield* execution; @@ -80,23 +83,34 @@ function observer(seen: Record, key: string): Modifi const block = (info: string, command = "work") => `\`\`\`${info}\n${command}\n\`\`\`\n`; +const OWNER = "packages/core/tests/exec-timeout.test.ts"; + describe("Tier XE — exec block timeouts", () => { beforeAll(() => useTempFileCompiler()); + beforeEach(journalBeforeEach(OWNER)); it("XE1: a block nobody bounded runs with no timeout at all", function* () { - const { timeouts } = yield* run(block("bash exec")); + const stream = yield* useJournalStream("test.md"); + const { timeouts } = yield* run(stream, block("bash exec")); expect(timeouts).toEqual([undefined]); }); it("XE2: the run's exec default bounds every block", function* () { - const { timeouts } = yield* run(`${block("bash exec")}\n${block("bash exec", "again")}`, { - config: { timeoutExec: 5_000 }, - }); + const stream = yield* useJournalStream("test.md"); + const { timeouts } = yield* run( + stream, + `${block("bash exec")}\n${block("bash exec", "again")}`, + { + config: { timeoutExec: 5_000 }, + }, + ); expect(timeouts).toEqual([5_000, 5_000]); }); it("XE3: a declared duration overrides the default for that block alone", function* () { + const stream = yield* useJournalStream("test.md"); const { timeouts } = yield* run( + stream, `${block("bash timeout=250ms exec")}\n${block("bash exec", "again")}`, { config: { timeoutExec: 5_000 } }, ); @@ -104,40 +118,49 @@ describe("Tier XE — exec block timeouts", () => { }); it("XE4: a bare timeout takes the run's exec default", function* () { - const { timeouts } = yield* run(block("bash timeout exec"), { + const stream = yield* useJournalStream("test.md"); + const { timeouts } = yield* run(stream, block("bash timeout exec"), { config: { timeoutExec: 5_000 }, }); expect(timeouts).toEqual([5_000]); }); it("XE5: a bare timeout with no configured default refuses before the process starts", function* () { - const { output, timeouts } = yield* run(block("bash timeout exec")); + const stream = yield* useJournalStream("test.md"); + const { output, timeouts } = yield* run(stream, block("bash timeout exec")); expect(timeouts).toEqual([]); expect(output).toContain("names no duration"); expect(output).toContain("--timeout-exec"); }); it("XE6: `timeout=` is an empty duration, not a bare timeout", function* () { - const { output, timeouts } = yield* run(block("bash timeout= exec"), { + const stream = yield* useJournalStream("test.md"); + const { output, timeouts } = yield* run(stream, block("bash timeout= exec"), { config: { timeoutExec: 5_000 }, }); expect(timeouts).toEqual([]); expect(output).toContain("must be a duration"); }); - it("XE7: a malformed duration refuses before the process starts", function* () { + const malformed = "XE7: a malformed duration refuses before the process starts"; + it(malformed, function* () { for (const info of ["bash timeout=abc exec", "bash timeout=0s exec", "bash timeout=-5s exec"]) { - const { output, timeouts } = yield* run(block(info), { config: { timeoutExec: 5_000 } }); - expect({ info, timeouts }).toEqual({ info, timeouts: [] }); - expect(output).toContain("must be a duration"); + yield* captureTestJournal({ owner: OWNER, name: malformed }, "test.md", function* (stream) { + const { output, timeouts } = yield* run(stream, block(info), { + config: { timeoutExec: 5_000 }, + }); + expect({ info, timeouts }).toEqual({ info, timeouts: [] }); + expect(output).toContain("must be a duration"); + }); } }); it("XE8: a timeout after the terminal is unreachable, so it is never applied", function* () { + const stream = yield* useJournalStream("test.md"); // `exec` is terminal and never calls next(), so this modifier's factory is // built but its middleware never runs — a malformed duration behind it // cannot fail a run it was never part of. - const { output, timeouts } = yield* run(block("bash exec timeout=nonsense"), { + const { output, timeouts } = yield* run(stream, block("bash exec timeout=nonsense"), { config: { timeoutExec: 5_000 }, }); expect(timeouts).toEqual([5_000]); @@ -145,15 +168,17 @@ describe("Tier XE — exec block timeouts", () => { }); it("XE9: nested timeouts follow wrapper order — the innermost reaches the terminal", function* () { - const { timeouts } = yield* run(block("bash timeout=5s timeout=250ms exec"), { + const stream = yield* useJournalStream("test.md"); + const { timeouts } = yield* run(stream, block("bash timeout=5s timeout=250ms exec"), { config: { timeoutExec: 9_000 }, }); expect(timeouts).toEqual([250]); }); it("XE10: middleware outside the timeout sees the run's default, inside sees the block's", function* () { + const stream = yield* useJournalStream("test.md"); const seen: Record = {}; - const { timeouts } = yield* run(block("bash outer timeout=250ms inner exec"), { + const { timeouts } = yield* run(stream, block("bash outer timeout=250ms inner exec"), { config: { timeoutExec: 5_000 }, modifiers: { outer: observer(seen, "outer"), inner: observer(seen, "inner") }, }); @@ -162,8 +187,9 @@ describe("Tier XE — exec block timeouts", () => { }); it("XE11: replacing the timeout factory leaves no built-in behavior behind", function* () { + const stream = yield* useJournalStream("test.md"); const seen: Record = {}; - const { timeouts } = yield* run(block("bash timeout=250ms exec"), { + const { timeouts } = yield* run(stream, block("bash timeout=250ms exec"), { config: { timeoutExec: 5_000 }, modifiers: { timeout: observer(seen, "replacement") }, }); @@ -174,7 +200,9 @@ describe("Tier XE — exec block timeouts", () => { }); it("XE12: a block's declaration does not leak to the block after it", function* () { + const stream = yield* useJournalStream("test.md"); const { timeouts } = yield* run( + stream, `${block("bash timeout=250ms exec")}\n${block("bash timeout=1s exec", "again")}\n${block( "bash exec", "third", diff --git a/packages/core/tests/host-generated-root.test.ts b/packages/core/tests/host-generated-root.test.ts index a5b26cf71..eceaca358 100644 --- a/packages/core/tests/host-generated-root.test.ts +++ b/packages/core/tests/host-generated-root.test.ts @@ -471,6 +471,7 @@ function rendered(answer: Result): GeneratedXmdRootResul describe("Tier E1 — only a live trusted handle evaluates a root", () => { beforeAll(() => useTempFileCompiler()); + beforeEach(journalBeforeEach(OWNER)); it("E1a: a handle evaluates from its caller with no conversation and no durable context", function* () { const stream = new InMemoryStream(); @@ -576,7 +577,7 @@ describe("Tier E1 — only a live trusted handle evaluates a root", () => { }); it("E1c: a completed handle refuses without component work or reopening", function* () { - const stream = new InMemoryStream(); + const stream = yield* useJournalStream(HELD_ROOT_PATH); const invoked: string[] = []; const held: { execution?: HostExecution } = {}; const run = yield* withHeldHost( @@ -689,7 +690,7 @@ describe("Tier E3 — the documentation this execution captured", () => { beforeAll(() => useTempFileCompiler()); it("E3a: a named lookup renders a package chapter the root does not admit", function* () { - const stream = new InMemoryStream(); + const stream = yield* useJournalStream(HELD_ROOT_PATH); const counted = { reads: 0 }; const marked: string[] = []; const invoked: string[] = []; @@ -1014,9 +1015,10 @@ function holding( describe("Tier E5 — cancelling joins before anything else starts", () => { beforeAll(() => useTempFileCompiler()); + beforeEach(journalBeforeEach(OWNER)); it("E5a: a cancelled evaluation holds the caller's halt until its cleanup joins", function* () { - const stream = new InMemoryStream(); + const stream = yield* useJournalStream(HELD_ROOT_PATH); const order: string[] = []; const invoked: string[] = []; const reached = withResolvers(); @@ -1090,8 +1092,8 @@ describe("Tier E5 — cancelling joins before anything else starts", () => { ).toBe(false); }); - it("E5b: closing the execution joins a held evaluation before closure completes", () => - captureTestJournal( + it("E5b: closing the execution joins a held evaluation before closure completes", function* () { + yield* captureTestJournal( { owner: OWNER, name: "E5b: closing the execution joins a held evaluation before closure completes", @@ -1159,7 +1161,8 @@ describe("Tier E5 — cancelling joins before anything else starts", () => { expect(after.ok).toBe(false); expect(invoked).toEqual([]); }, - )); + ); + }); }); describe("Tier E6 — reopening without replaying a response", () => { @@ -1422,9 +1425,10 @@ function failingMain(): NonNullable[number] describe("Tier E7 — which failures stay the run's", () => { beforeAll(() => useTempFileCompiler()); + beforeEach(journalBeforeEach(OWNER)); - it("E7a: an ordinary control failure is a Result carrying the real partial render", () => - captureTestJournal( + it("E7a: an ordinary control failure is a Result carrying the real partial render", function* () { + yield* captureTestJournal( { owner: OWNER, name: "E7a: an ordinary control failure is a Result carrying the real partial render", @@ -1453,7 +1457,8 @@ describe("Tier E7 — which failures stay the run's", () => { expect(error?.partial?.output).toContain("before the failure"); expect(invoked).toEqual(["boomed"]); }, - )); + ); + }); it("E7b: a persistence failure stays itself, and the run does not succeed", function* () { const stream = new InMemoryStream(); @@ -1496,8 +1501,8 @@ describe("Tier E7 — which failures stay the run's", () => { expect(invoked).toEqual([]); }); - it("E7c: a teardown failure stays itself, and the run does not succeed", () => - captureTestJournal( + it("E7c: a teardown failure stays itself, and the run does not succeed", function* () { + yield* captureTestJournal( { owner: OWNER, name: "E7c: a teardown failure stays itself, and the run does not succeed" }, HELD_ROOT_PATH, function* (stream) { @@ -1523,7 +1528,8 @@ describe("Tier E7 — which failures stay the run's", () => { expect(String((caught.raised as Error).message)).toContain("cleanup"); expect(caught.completion?.ok).toBe(false); }, - )); + ); + }); it("E7d: a fatal evaluation outranks the ordinary failure the document went on to have", function* () { const stream = new InMemoryStream(); @@ -1624,8 +1630,8 @@ describe("Tier E7 — which failures stay the run's", () => { expect(run.completion.ok).toBe(false); }); - it("E7f: an authoritative evaluation failure of no classified kind is still the run's", () => - captureTestJournal( + it("E7f: an authoritative evaluation failure of no classified kind is still the run's", function* () { + yield* captureTestJournal( { owner: OWNER, name: "E7f: an authoritative evaluation failure of no classified kind is still the run's", @@ -1665,10 +1671,11 @@ describe("Tier E7 — which failures stay the run's", () => { expect(run.completion.ok).toBe(false); expect(run.completion.ok ? undefined : run.completion.error).toBe(caught.raised); }, - )); + ); + }); - it("E7g: the same failure is the run's when the document succeeded — by identity", () => - captureTestJournal( + it("E7g: the same failure is the run's when the document succeeded — by identity", function* () { + yield* captureTestJournal( { owner: OWNER, name: "E7g: the same failure is the run's when the document succeeded — by identity", @@ -1698,7 +1705,8 @@ describe("Tier E7 — which failures stay the run's", () => { expect(run.completion.ok).toBe(false); expect(run.completion.ok ? undefined : run.completion.error).toBe(caught.raised); }, - )); + ); + }); }); /** @@ -1750,6 +1758,7 @@ function occurrences(text: string, needle: string): number { } describe("Tier E8 — the captured selection holds canonical Syntax once", () => { + beforeEach(journalBeforeEach(OWNER)); beforeAll(() => useTempFileCompiler()); /** @@ -1762,7 +1771,7 @@ describe("Tier E8 — the captured selection holds canonical Syntax once", () => * only a real capture produces. */ it("E8a: a host that selected Syntax evaluates, and retains one Syntax row", function* () { - const stream = new InMemoryStream(); + const stream = yield* useJournalStream(HELD_ROOT_PATH); const invoked: string[] = []; const answered: { output?: string } = {}; const run = yield* withHeldHost( @@ -1793,7 +1802,7 @@ describe("Tier E8 — the captured selection holds canonical Syntax once", () => }); it("E8b: a host that selected none of it reaches core's own, also once", function* () { - const stream = new InMemoryStream(); + const stream = yield* useJournalStream(HELD_ROOT_PATH); const invoked: string[] = []; const answered: { output?: string } = {}; const run = yield* withHeldHost( @@ -1834,7 +1843,7 @@ describe("Tier E9 — an availability refusal is the call's answer", () => { * failures (E7) keep their authority; these two are not among them. */ it("E9a: a host that selected no generated components refuses, and its document completes", function* () { - const stream = new InMemoryStream(); + const stream = yield* useJournalStream(HELD_ROOT_PATH); const answer: { value?: Result } = {}; const run = yield* withHeldHost({ stream }, function* (open) { answer.value = yield* open.execution.evaluateGeneratedXmdRoot( @@ -1854,7 +1863,7 @@ describe("Tier E9 — an availability refusal is the call's answer", () => { }); it("E9b: a class this host installed nothing for refuses, and its document completes", function* () { - const stream = new InMemoryStream(); + const stream = yield* useJournalStream(HELD_ROOT_PATH); const invoked: string[] = []; const answer: { value?: Result } = {}; const run = yield* withHeldHost( @@ -1878,7 +1887,7 @@ describe("Tier E9 — an availability refusal is the call's answer", () => { }); it("E9c: a class this host did install answers, and its document completes", function* () { - const stream = new InMemoryStream(); + const stream = yield* useJournalStream(HELD_ROOT_PATH); const invoked: string[] = []; const answer: { value?: Result } = {}; const run = yield* withHeldHost( diff --git a/packages/core/tests/parse-components.test.ts b/packages/core/tests/parse-components.test.ts index 523a90de0..2c6d3b627 100644 --- a/packages/core/tests/parse-components.test.ts +++ b/packages/core/tests/parse-components.test.ts @@ -7,7 +7,8 @@ * what a failure carries, what propagates through, and that a replay repeats * none of it. */ -import { describe, it, beforeAll } from "@executablemd/test-support/bdd"; +import { describe, it, beforeAll, beforeEach } from "@executablemd/test-support/bdd"; +import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal"; import { expect } from "@executablemd/test-support/expect"; import { ensure, scoped, sleep, spawn, withResolvers } from "effection"; import type { Operation } from "effection"; @@ -20,6 +21,7 @@ import { Execution, execute } from "../src/execute.ts"; import { collect } from "../src/collect.ts"; import { useTempFileCompiler } from "../src/temp-file-compiler.ts"; import type { Json } from "../src/types.ts"; +const owner = "packages/core/tests/parse-components.test.ts"; interface Run { /** Rendered output, or the failure message when the document aborted. */ @@ -37,7 +39,7 @@ interface Run { * A document failure is captured rather than thrown: several cases are about * *what* the failure says, and about what did not happen before it. */ -function run(source: string): Operation { +function run(journal: InMemoryStream | undefined, source: string): Operation { return scoped(function* () { const commands: string[] = []; yield* API.Process.around({ @@ -49,7 +51,7 @@ function run(source: string): Operation { }); yield* useStubFs({ "doc.md": source }); - const stream = new InMemoryStream(); + const stream = journal ?? new InMemoryStream(); const result = yield* execute({ path: "doc.md", stream }); const outcome = yield* result; const events = stream.snapshot(); @@ -105,44 +107,53 @@ const SCHEMA_INVALID = `{ "a": 1 } { beforeAll(() => useTempFileCompiler()); + beforeEach(journalBeforeEach(owner)); it("PC1: schema is required", function* () { - const { output } = yield* run(`1`); + const stream = yield* useJournalStream("doc.md"); + const { output } = yield* run(stream, `1`); expect(output).toContain("Parse"); expect(output).toContain("schema"); }); it("PC2: a capture name is required", function* () { - const { output } = yield* run(`{ "a": "x" }`); + const stream = yield* useJournalStream("doc.md"); + const { output } = yield* run(stream, `{ "a": "x" }`); expect(output).toContain("must be invoked"); expect(output).toContain('as="binding"'); }); it("PC3: schema text that is not JSON fails", function* () { - const { output } = yield* run(`1`); + const stream = yield* useJournalStream("doc.md"); + const { output } = yield* run(stream, `1`); expect(output).toContain("schema text is not JSON"); }); it("PC4: a schema that is not a valid draft-07 schema fails", function* () { - const { output } = yield* run(`1`); + const stream = yield* useJournalStream("doc.md"); + const { output } = yield* run(stream, `1`); expect(output).toContain("not a valid draft-07 JSON Schema"); }); it("PC5: an asynchronous schema is rejected", function* () { + const stream = yield* useJournalStream("doc.md"); const { output } = yield* run( + stream, `{ }`, ); expect(output).toContain("asynchronous schema"); }); it("PC6: a schema that is not an object is rejected", function* () { - const { output } = yield* run(`1`); + const stream = yield* useJournalStream("doc.md"); + const { output } = yield* run(stream, `1`); expect(output).toContain("must be a JSON Schema object"); }); // The whole point of compiling first: an unusable schema must not let the // document do work whose result it would then refuse to judge. it("PC7: the schema compiles before any child effect runs", function* () { + const stream = yield* useJournalStream("doc.md"); const source = [ ``, "", @@ -152,12 +163,13 @@ describe("Tier PC — Parse and SafeParse", { sanitizeOps: false, sanitizeResour "", "", ].join("\n"); - const { output, commands } = yield* run(source); + const { output, commands } = yield* run(stream, source); expect(output).toContain("not a valid draft-07 JSON Schema"); expect(commands).toEqual([]); }); it("PC8: SafeParse compiles before child effects too", function* () { + const stream = yield* useJournalStream("doc.md"); const source = [ ``, "", @@ -167,14 +179,16 @@ describe("Tier PC — Parse and SafeParse", { sanitizeOps: false, sanitizeResour "", "", ].join("\n"); - const { output, commands } = yield* run(source); + const { output, commands } = yield* run(stream, source); expect(output).toContain("asynchronous schema"); expect(commands).toEqual([]); }); // SafeParse absorbs JSON syntax and instance validation, and nothing else. it("PC9: a child failure propagates through SafeParse unchanged", function* () { + const stream = yield* useJournalStream("doc.md"); const { output } = yield* run( + stream, ``, ); expect(output).toContain("Missing"); @@ -182,14 +196,19 @@ describe("Tier PC — Parse and SafeParse", { sanitizeOps: false, sanitizeResour }); it("PC10: a Parse failure names the component and carries its issues", function* () { - const { output } = yield* run(`{ "a": 1 }\n`); + const stream = yield* useJournalStream("doc.md"); + const { output } = yield* run( + stream, + `{ "a": 1 }\n`, + ); expect(output).toContain("Parse"); expect(output).toContain("content failed its schema"); expect(output).toContain("must be string"); }); it("PC10: content the schema rejects fails the document and stops later work", function* () { - const { output, failed, commands, events } = yield* run(laterEffect(SCHEMA_INVALID)); + const stream = yield* useJournalStream("doc.md"); + const { output, failed, commands, events } = yield* run(stream, laterEffect(SCHEMA_INVALID)); expect(failed).toBe(true); expect(output).toContain("Parse"); expect(output).toContain("content failed its schema"); @@ -204,12 +223,14 @@ describe("Tier PC — Parse and SafeParse", { sanitizeOps: false, sanitizeResour }); it("PC11: malformed JSON is reported as a parse failure", function* () { - const { output } = yield* run(`nope`); + const stream = yield* useJournalStream("doc.md"); + const { output } = yield* run(stream, `nope`); expect(output).toContain("content is not JSON"); }); it("PC11: malformed JSON fails the document and stops later work", function* () { - const { output, failed, commands, events } = yield* run(laterEffect(MALFORMED)); + const stream = yield* useJournalStream("doc.md"); + const { output, failed, commands, events } = yield* run(stream, laterEffect(MALFORMED)); expect(failed).toBe(true); expect(output).toContain("Parse"); expect(output).toContain("content is not JSON"); @@ -305,7 +326,8 @@ describe("Tier PC — Parse and SafeParse", { sanitizeOps: false, sanitizeResour "", "", ].join("\n"); - const { output, failed, commands, events } = yield* run(source); + const stream = yield* useJournalStream("doc.md"); + const { output, failed, commands, events } = yield* run(stream, source); expect(failed).toBe(false); expect(output).toContain(`INPUT ${content}|${keyword}|${path}`); expect(commands).toHaveLength(1); @@ -315,6 +337,7 @@ describe("Tier PC — Parse and SafeParse", { sanitizeOps: false, sanitizeResour }); it("PC11c: an authored PrintErrors region recovers from a Parse failure", function* () { + const stream = yield* useJournalStream("doc.md"); const source = [ "", "", @@ -329,7 +352,7 @@ describe("Tier PC — Parse and SafeParse", { sanitizeOps: false, sanitizeResour "```", "", ].join("\n"); - const { output, failed, commands, events } = yield* run(source); + const { output, failed, commands, events } = yield* run(stream, source); expect(failed).toBe(false); expect(output).toContain("content failed its schema"); expect(output).toContain("must be string"); @@ -340,18 +363,21 @@ describe("Tier PC — Parse and SafeParse", { sanitizeOps: false, sanitizeResour }); it("PC12: neither component renders output", function* () { + const stream = yield* useJournalStream("doc.md"); const source = [ `1`, `2`, "done", ].join("\n\n"); - const { output, failed } = yield* run(source); + const { output, failed } = yield* run(stream, source); expect(failed).toBe(false); expect(output.trim()).toBe("done"); }); it("PC13: an external reference fails with the documented limit", function* () { + const stream = yield* useJournalStream("doc.md"); const { output } = yield* run( + stream, `1`, ); expect(output).toContain("could not resolve a schema reference"); diff --git a/packages/core/tests/props-binding.test.ts b/packages/core/tests/props-binding.test.ts index 0003e50d3..cda716bf9 100644 --- a/packages/core/tests/props-binding.test.ts +++ b/packages/core/tests/props-binding.test.ts @@ -1,6 +1,6 @@ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; import { expect } from "@executablemd/test-support/expect"; -import { InMemoryStream } from "@executablemd/durable-streams"; +import type { InMemoryStream } from "@executablemd/durable-streams"; import type { Json } from "@executablemd/durable-streams"; import { useEchoExec, useStubFs } from "@executablemd/runtime/test"; import { forEach } from "@effectionx/stream-helpers"; @@ -9,8 +9,12 @@ import { beforeAll } from "@executablemd/test-support/bdd"; import { useTempFileCompiler } from "../src/temp-file-compiler.ts"; import type { Operation, Result } from "effection"; import { Stdio } from "@effectionx/process"; +import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal"; + +const OWNER = "packages/core/tests/props-binding.test.ts"; function* runDocument( + stream: InMemoryStream | undefined, files: Record, props?: Record, ): Operation { @@ -25,7 +29,11 @@ function* runDocument( displayed += decoder.decode(bytes); }, }); - const execution = yield* execute({ path: "root.md", stream: new InMemoryStream(), props }); + const execution = yield* execute({ + path: "root.md", + stream: stream ?? (yield* useJournalStream("root.md")), + props, + }); const output = yield* forEach(function* () {}, execution.output); const result = yield* execution; return { output, displayed, result }; @@ -60,9 +68,11 @@ const ROOT_PROPS = [ ].join("\n"); describe("props binding", () => { + beforeEach(journalBeforeEach(OWNER)); beforeAll(() => useTempFileCompiler()); it("installs root props for text, eval, expression, and executable interpolation", function* () { const { output, displayed, result } = yield* runDocument( + undefined, { "root.md": [ ROOT_PROPS, @@ -92,6 +102,7 @@ describe("props binding", () => { it("keeps eval-created locals independent from props", function* () { const { output, displayed } = yield* runDocument( + undefined, { "root.md": [ ROOT_PROPS, @@ -113,6 +124,7 @@ describe("props binding", () => { it("does not begin body effects for invalid root props", function* () { const { output, displayed, result } = yield* runDocument( + undefined, { "root.md": [ROOT_PROPS, "", "```bash exec", "echo BODY_EFFECT", "```", ""].join("\n"), }, @@ -125,6 +137,7 @@ describe("props binding", () => { it("uses caller props for projected content and callee props for authored content", function* () { const { output, displayed, result } = yield* runDocument( + undefined, { "root.md": [ ROOT_PROPS, @@ -201,6 +214,7 @@ describe("props binding", () => { it("restores the enclosing props binding after scoped and nested expansion", function* () { const { output, displayed, result } = yield* runDocument( + undefined, { "root.md": [ ROOT_PROPS, @@ -250,7 +264,7 @@ describe("props binding", () => { }); it("uses one validated object for the props binding and text interpolation", function* () { - const { output, displayed, result } = yield* runDocument({ + const { output, displayed, result } = yield* runDocument(undefined, { "root.md": '\n', "Mutator.md": [ "---", @@ -279,7 +293,7 @@ describe("props binding", () => { }); it("uses defaults before root and Markdown-component body effects", function* () { - const { output, displayed, result } = yield* runDocument({ + const { output, displayed, result } = yield* runDocument(undefined, { "root.md": [ "---", "props:", @@ -319,7 +333,7 @@ describe("props binding", () => { }); it("does not begin a Markdown-component body effect for invalid props", function* () { - const { output, displayed, result } = yield* runDocument({ + const { output, displayed, result } = yield* runDocument(undefined, { "root.md": "\n", "Invalid.md": [ "---", @@ -348,6 +362,7 @@ describe("props binding", () => { it("uses one shadowed props binding for text, eval, and exec, then restores it", function* () { const { output, displayed, result } = yield* runDocument( + undefined, { "root.md": [ROOT_PROPS, "", "", "after={props.name}", ""].join("\n"), "Shadow.md": [ @@ -384,6 +399,7 @@ describe("props binding", () => { it("allows an authored props binding to shadow the namespace locally", function* () { const { output, displayed, result } = yield* runDocument( + undefined, { "root.md": [ROOT_PROPS, "", 'shadowed{props} {props.name}', ""].join( "\n", diff --git a/packages/core/tests/root-composition.test.ts b/packages/core/tests/root-composition.test.ts index a209bac58..b94c94b38 100644 --- a/packages/core/tests/root-composition.test.ts +++ b/packages/core/tests/root-composition.test.ts @@ -12,7 +12,7 @@ * composition that quietly changes a document nobody asked to change. */ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; import { expect } from "@executablemd/test-support/expect"; import { scoped } from "effection"; import type { Operation } from "effection"; @@ -24,15 +24,22 @@ import { inlineSource } from "../src/root-source.ts"; import { registerComponents } from "../src/components/registration.ts"; import { getExpansion } from "../src/expansion.ts"; import { Document, RootMetadata } from "../api.ts"; +import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal"; + +const OWNER = "packages/core/tests/root-composition.test.ts"; const NO_PROPS = { type: "object", properties: {}, additionalProperties: false }; /** Render one inline root, with whatever this scope installed around it. */ -function* render(source: string, props?: Record): Operation { +function* render( + stream: InMemoryStream | undefined, + source: string, + props?: Record, +): Operation { const value = yield* collect( yield* execute({ ...inlineSource(source), - stream: new InMemoryStream(), + stream: stream ?? (yield* useJournalStream("")), ...(props === undefined ? {} : { props }), }), ); @@ -40,10 +47,14 @@ function* render(source: string, props?: Record): Operation): Operation { +function* settled( + stream: InMemoryStream | undefined, + source: string, + props?: Record, +): Operation { const execution = yield* execute({ ...inlineSource(source), - stream: new InMemoryStream(), + stream: stream ?? (yield* useJournalStream("")), ...(props === undefined ? {} : { props }), }); yield* collect(execution); @@ -52,9 +63,9 @@ function* settled(source: string, props?: Record): Operation } /** Render one inline root, or the failure it raised, as text. */ -function* rendered(source: string): Operation { +function* rendered(stream: InMemoryStream | undefined, source: string): Operation { try { - return yield* render(source); + return yield* render(undefined, source); } catch (error) { return error instanceof Error ? error.message : String(error); } @@ -92,9 +103,10 @@ function* useEnvelope(before: string, after: string): Operation { const ROOT = ["# Heading", "", "body text", ""].join("\n"); describe("RC1 — with no document middleware the root is the root", () => { + beforeEach(journalBeforeEach(OWNER)); it("renders exactly what executing the document directly renders", function* () { - expect(yield* render(ROOT)).toBe(yield* scoped(() => render(ROOT))); - expect(yield* render(ROOT)).toContain("body text"); + expect(yield* render(undefined, ROOT)).toBe(yield* scoped(() => render(undefined, ROOT))); + expect(yield* render(undefined, ROOT)).toContain("body text"); }); it("keeps the document's own props, returns and value", function* () { @@ -111,15 +123,16 @@ describe("RC1 — with no document middleware the root is the root", () => { "", "", ].join("\n"); - expect(yield* settled(source, { who: "caller" })).toBe("caller"); + expect(yield* settled(undefined, source, { who: "caller" })).toBe("caller"); }); }); describe("RC2 — a wrapper composes around the projected document", () => { + beforeEach(journalBeforeEach(OWNER)); it("renders the envelope with the original document inside it", function* () { const output = yield* scoped(function* () { yield* useEnvelope("before\n\n", "\n\nafter"); - return yield* render(ROOT); + return yield* render(undefined, ROOT); }); expect(output).toContain("before"); expect(output).toContain("body text"); @@ -132,7 +145,7 @@ describe("RC2 — a wrapper composes around the projected document", () => { const output = yield* scoped(function* () { yield* useEnvelope("one open\n\n", "\n\none close"); yield* useEnvelope("two open\n\n", "\n\ntwo close"); - return yield* render(ROOT); + return yield* render(undefined, ROOT); }); const order = ["one open", "two open", "body text", "two close", "one close"]; const positions = order.map((token) => output.indexOf(token)); @@ -147,25 +160,26 @@ describe("RC2 — a wrapper composes around the projected document", () => { return `${yield* next()}\n\n${yield* next()}`; }, }); - return yield* render("once\n"); + return yield* render(undefined, "once\n"); }); expect(output.split("once").length - 1).toBe(2); }); }); describe("RC3 — projection preserves the document's own identity", () => { + beforeEach(journalBeforeEach(OWNER)); it("reports the authored source position, not a position in the envelope", function* () { const source = ["# Heading", "", "", ""].join("\n"); const plain: { id: string; path?: string; line?: number }[] = []; yield* scoped(function* () { yield* useProbe(plain); - yield* render(source); + yield* render(undefined, source); }); const wrapped: { id: string; path?: string; line?: number }[] = []; yield* scoped(function* () { yield* useProbe(wrapped); yield* useEnvelope("envelope line one\n\nenvelope line two\n\n", "\n\ntail\n"); - yield* render(source); + yield* render(undefined, source); }); expect(plain).toHaveLength(1); expect(wrapped).toHaveLength(1); @@ -180,19 +194,20 @@ describe("RC3 — projection preserves the document's own identity", () => { // Nothing in the document's own segments is ever read for a placeholder: // only the envelope this engine scanned is. So an author who writes the // name reaches component resolution, and there is no component there. - const output = yield* rendered("\n"); + const output = yield* rendered(undefined, "\n"); expect(output).not.toContain("\n"); expect(output).toMatch(/Document/); }); }); describe("RC4 — the document's own contract survives a wrapper", () => { + beforeEach(journalBeforeEach(OWNER)); it("keeps selecting what renders", function* () { const source = ["hidden", "", "", "", "selected", "", "", ""].join("\n"); - const plain = yield* render(source); + const plain = yield* render(undefined, source); const wrapped = yield* scoped(function* () { yield* useEnvelope("envelope\n\n", ""); - return yield* render(source); + return yield* render(undefined, source); }); expect(plain).toContain("selected"); expect(plain).not.toContain("hidden"); @@ -214,21 +229,22 @@ describe("RC4 — the document's own contract survives a wrapper", () => { ].join("\n"); const value = yield* scoped(function* () { yield* useEnvelope("envelope\n\n", ""); - return yield* settled(source); + return yield* settled(undefined, source); }); expect(value).toBe("settled"); }); }); describe("RC5 — RootMetadata changes the root's metadata and nothing else", () => { + beforeEach(journalBeforeEach(OWNER)); it("composes the record the document's own interpolation reads", function* () { const source = ["---", "title: authored", "---", "", "title is {meta.title}", ""].join("\n"); - expect(yield* render(source)).toContain("title is authored"); + expect(yield* render(undefined, source)).toContain("title is authored"); const composed = yield* scoped(function* () { yield* RootMetadata.around({ metadata: (_args, next) => ({ ...next(), title: "composed" }), }); - return yield* render(source); + return yield* render(undefined, source); }); expect(composed).toContain("title is composed"); }); @@ -247,7 +263,7 @@ describe("RC5 — RootMetadata changes the root's metadata and nothing else", () }, }, ]); - return yield* render(["root {meta.title}", "", "", ""].join("\n")); + return yield* render(undefined, ["root {meta.title}", "", "", ""].join("\n")); }); expect(composed).toContain("root composed"); expect(composed).toContain("inner body"); @@ -257,6 +273,7 @@ describe("RC5 — RootMetadata changes the root's metadata and nothing else", () }); describe("RC6 — a wrapper is held to the same structure a document is", () => { + beforeEach(journalBeforeEach(OWNER)); it("diagnoses an envelope whose own structure a document could not write", function* () { // `` in a text body is a structural violation wherever it is // written, and the composed body is what the preflight walks — so a wrapper @@ -264,7 +281,7 @@ describe("RC6 — a wrapper is held to the same structure a document is", () => // own body never runs. const failure = yield* scoped(function* () { yield* useEnvelope('\n\n', ""); - return yield* rendered(ROOT); + return yield* rendered(undefined, ROOT); }); expect(failure).toContain(""); expect(failure).not.toContain("body text"); diff --git a/packages/core/tests/root-props.test.ts b/packages/core/tests/root-props.test.ts index 535dfdbdf..07e0bf457 100644 --- a/packages/core/tests/root-props.test.ts +++ b/packages/core/tests/root-props.test.ts @@ -5,8 +5,11 @@ * validated and defaulted before any body effect, then available through * `{props.name}`, bare binding interpolation, and eval blocks. */ - -import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal"; +import { + captureTestJournal, + journalBeforeEach, + useJournalStream, +} from "@executablemd/test-support/failure-journal"; import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; import { expect } from "@executablemd/test-support/expect"; import { InMemoryStream } from "@executablemd/durable-streams"; @@ -82,8 +85,12 @@ const NESTED_CONCISE = [ "", ].join("\n"); -function* runPath(path: string, props?: Record, stream = new InMemoryStream()) { - const execution = yield* execute({ path, stream, props }); +function* runPath(path: string, props?: Record, stream?: InMemoryStream) { + const execution = yield* execute({ + path, + stream: stream ?? (yield* useJournalStream(path)), + props, + }); const output = yield* forEach(function* () {}, execution.output); const result = yield* execution; return { output, result }; @@ -96,7 +103,7 @@ function* runDoc( stream?: InMemoryStream, ) { yield* useStubFs(files); - return yield* runPath(path, props, stream); + return yield* runPath(path, props); } const OWNER = "packages/core/tests/root-props.test.ts"; @@ -104,16 +111,10 @@ const OWNER = "packages/core/tests/root-props.test.ts"; describe("Tier RP — root document properties", () => { beforeEach(journalBeforeEach(OWNER)); it("RP1: supplied props reach interpolation without bare prop bindings", function* () { - const stream = yield* useJournalStream("hello.md"); - const { output, result } = yield* runDoc( - { "hello.md": GREETING }, - "hello.md", - { - name: "Ada", - loud: true, - }, - stream, - ); + const { output, result } = yield* runDoc({ "hello.md": GREETING }, "hello.md", { + name: "Ada", + loud: true, + }); expect(result.ok).toBe(true); expect(output).toContain("Hello, Ada!"); expect(output).toContain("loud=true"); @@ -121,52 +122,32 @@ describe("Tier RP — root document properties", () => { }); it("RP2: schema defaults apply to the root", function* () { - const stream = yield* useJournalStream("hello.md"); - const { output } = yield* runDoc({ "hello.md": GREETING }, "hello.md", { name: "Ada" }, stream); + const { output } = yield* runDoc({ "hello.md": GREETING }, "hello.md", { name: "Ada" }); expect(output).toContain("loud=false"); }); it("RP3: a missing required property prevents every body effect", function* () { - const stream = yield* useJournalStream("doc.md"); - const { output, result } = yield* runDoc({ "doc.md": SIDE_EFFECT }, "doc.md", {}, stream); + const { output, result } = yield* runDoc({ "doc.md": SIDE_EFFECT }, "doc.md", {}); expect(result.ok).toBe(false); expect(output).not.toContain("SIDE_EFFECT_MARKER"); }); it("RP4: an invalid property prevents every body effect", function* () { - const stream = yield* useJournalStream("doc.md"); - const { output, result } = yield* runDoc( - { "doc.md": SIDE_EFFECT }, - "doc.md", - { name: 12 }, - stream, - ); + const { output, result } = yield* runDoc({ "doc.md": SIDE_EFFECT }, "doc.md", { name: 12 }); expect(result.ok).toBe(false); expect(output).not.toContain("SIDE_EFFECT_MARKER"); }); it("RP5: an undeclared property is rejected by the root schema", function* () { - const stream = yield* useJournalStream("doc.md"); - const { result } = yield* runDoc( - { "doc.md": SIDE_EFFECT }, - "doc.md", - { - name: "Ada", - nope: 1, - }, - stream, - ); + const { result } = yield* runDoc({ "doc.md": SIDE_EFFECT }, "doc.md", { + name: "Ada", + nope: 1, + }); expect(result.ok).toBe(false); }); it("RP6: a document without props keeps its existing behavior", function* () { - const stream = yield* useJournalStream("plain.md"); - const { output, result } = yield* runDoc( - { "plain.md": NO_PROPS }, - "plain.md", - undefined, - stream, - ); + const { output, result } = yield* runDoc({ "plain.md": NO_PROPS }, "plain.md", undefined); expect(result.ok).toBe(true); expect(output).toContain("PLAIN_MARKER"); }); @@ -237,7 +218,8 @@ describe("Tier RI — document inspection", () => { expect(failed).toBe(true); }); - it("RI6: inspection and execution agree on which roots are markdown", function* () { + const extensions = "RI6: inspection and execution agree on which roots are markdown"; + it(extensions, function* () { // Execution parses any non-TypeScript root as markdown, so inspection // must not require a `.md` suffix. const names = ["README", "notes.markdown", "doc.md"]; @@ -247,15 +229,17 @@ describe("Tier RI — document inspection", () => { const info = yield* inspectDocument({ path: name }); expect(info.props).toMatchObject({ required: ["name"] }); - const execution = yield* execute({ - path: name, - stream: new InMemoryStream(), - props: { name: "Ada" }, + yield* captureTestJournal({ owner: OWNER, name: extensions }, name, function* (stream) { + const execution = yield* execute({ + path: name, + stream, + props: { name: "Ada" }, + }); + const output = yield* forEach(function* () {}, execution.output); + const result = yield* execution; + expect(result.ok).toBe(true); + expect(output).toContain("Hello, Ada!"); }); - const output = yield* forEach(function* () {}, execution.output); - const result = yield* execution; - expect(result.ok).toBe(true); - expect(output).toContain("Hello, Ada!"); } }); }); @@ -263,84 +247,71 @@ describe("Tier RI — document inspection", () => { describe("Tier RS — concise props declarations", () => { beforeEach(journalBeforeEach(OWNER)); it("RS1: a concise root receives props and applies defaults", function* () { - const stream = yield* useJournalStream("hello.md"); - const { output, result } = yield* runDoc( - { "hello.md": GREETING_CONCISE }, - "hello.md", - { - name: "Ada", - }, - stream, - ); + const { output, result } = yield* runDoc({ "hello.md": GREETING_CONCISE }, "hello.md", { + name: "Ada", + }); expect(result.ok).toBe(true); expect(output).toContain("Hello, Ada!"); expect(output).toContain("loud=false"); expect(output).toContain("bare={name}"); }); - it("RS2: the concise and full spellings behave identically", function* () { + const comparison = "RS2: the concise and full spellings behave identically"; + it(comparison, function* () { yield* useStubFs({ "concise.md": GREETING_CONCISE, "full.md": GREETING }); - const concise = yield* runPath("concise.md", { name: "Ada", loud: true }); - const full = yield* runPath("full.md", { name: "Ada", loud: true }); - expect(concise.output).toBe(full.output); + const label = { owner: OWNER, name: comparison }; + yield* captureTestJournal(label, "concise.md", function* (conciseStream) { + const concise = yield* runPath("concise.md", { name: "Ada", loud: true }, conciseStream); + yield* captureTestJournal(label, "full.md", function* (fullStream) { + const full = yield* runPath("full.md", { name: "Ada", loud: true }, fullStream); + expect(concise.output).toBe(full.output); + }); + }); }); it("RS3: a missing required property prevents every body effect", function* () { - const stream = yield* useJournalStream("hello.md"); - const { output, result } = yield* runDoc( - { "hello.md": GREETING_CONCISE }, - "hello.md", - {}, - stream, - ); + const { output, result } = yield* runDoc({ "hello.md": GREETING_CONCISE }, "hello.md", {}); expect(result.ok).toBe(false); expect(output).not.toContain("Hello"); }); it("RS4: the implicit closed object rejects an undeclared property", function* () { - const stream = yield* useJournalStream("hello.md"); - const { result } = yield* runDoc( - { "hello.md": GREETING_CONCISE }, - "hello.md", - { - name: "Ada", - nope: 1, - }, - stream, - ); + const { result } = yield* runDoc({ "hello.md": GREETING_CONCISE }, "hello.md", { + name: "Ada", + nope: 1, + }); expect(result.ok).toBe(false); }); it("RS5: object defaults fill recursively", function* () { - const stream = yield* useJournalStream("nested.md"); - const { output, result } = yield* runDoc( - { "nested.md": NESTED_CONCISE }, - "nested.md", - {}, - stream, - ); + const { output, result } = yield* runDoc({ "nested.md": NESTED_CONCISE }, "nested.md", {}); expect(result.ok).toBe(true); expect(output).toContain("port=8080"); }); - it("RS6: an imported concise component validates props like the root", function* () { + const imported = "RS6: an imported concise component validates props like the root"; + it(imported, function* () { yield* useStubFs({ "supplied.md": '\n', "omitted.md": "\n", "Greeting.md": GREETING_CONCISE, }); - const supplied = yield* runPath("supplied.md"); - expect(supplied.result.ok).toBe(true); - expect(supplied.output).toContain("Hello, Ada!"); - - // Nothing recovers the component's prop failure, so it is the run's own - // outcome and the component renders nothing. - const omitted = yield* runPath("omitted.md"); - expect(omitted.result.ok).toBe(false); - const reported = omitted.result.ok ? "" : omitted.result.error.message; - expect(reported).toContain("Prop validation failed for "); - expect(reported).toContain("must have required property 'name'"); - expect(omitted.output).not.toContain("Hello, "); + const label = { owner: OWNER, name: imported }; + yield* captureTestJournal(label, "supplied.md", function* (stream) { + const supplied = yield* runPath("supplied.md", undefined, stream); + expect(supplied.result.ok).toBe(true); + expect(supplied.output).toContain("Hello, Ada!"); + }); + yield* captureTestJournal(label, "omitted.md", function* (stream) { + // Nothing recovers the component's prop failure, so it is the run's own + // outcome and the component renders nothing. + const omitted = yield* runPath("omitted.md", undefined, stream); + expect(omitted.result.ok).toBe(false); + const reported = omitted.result.ok ? "" : omitted.result.error.message; + expect(reported).toContain("Prop validation failed for "); + expect(reported).toContain("must have required property 'name'"); + expect(omitted.output).not.toContain("Hello, "); + }); }); it("RS7: inspection returns the normalized schema", function* () { diff --git a/packages/git/tests/git-add.test.ts b/packages/git/tests/git-add.test.ts index ae56ac225..c5c7cd754 100644 --- a/packages/git/tests/git-add.test.ts +++ b/packages/git/tests/git-add.test.ts @@ -9,12 +9,11 @@ * says what. */ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; import { expect } from "@executablemd/test-support/expect"; import { registerComponents } from "@executablemd/core"; import { collect, execute, inlineSource } from "@executablemd/core"; import type { ComponentRegistration } from "@executablemd/core"; -import { InMemoryStream } from "@executablemd/durable-streams"; import type { Json } from "@executablemd/durable-streams"; import { scoped, sleep, spawn, until, withResolvers } from "effection"; import { tmpdir } from "node:os"; @@ -64,6 +63,9 @@ import { subcommands, } from "./support/composition.ts"; import { gitPluginAdmissions } from "./support/composition.ts"; +import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal"; + +const OWNER = "packages/git/tests/git-add.test.ts"; /** * A tracked file at the root, one in a subdirectory, and one more of each. @@ -465,6 +467,7 @@ describe("workflow Git.Add invocation", () => { }); describe("workflow Git.Add selection", () => { + beforeEach(journalBeforeEach(OWNER)); it("stages inside the linked Worktree the working directory selects", function* () { const root = yield* useStorageRoot(); const remote = yield* useBareRemote(REMOTE); @@ -606,7 +609,7 @@ describe("workflow Git.Add selection", () => { return yield* collect( yield* execute({ ...inlineSource(``), - stream: new InMemoryStream(), + stream: yield* useJournalStream(""), }), ); }), diff --git a/packages/git/tests/git-commit-read.test.ts b/packages/git/tests/git-commit-read.test.ts index 2f5367a18..095898259 100644 --- a/packages/git/tests/git-commit-read.test.ts +++ b/packages/git/tests/git-commit-read.test.ts @@ -12,10 +12,9 @@ * that it changed nothing while asking. */ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; import { expect } from "@executablemd/test-support/expect"; import type { Json } from "@executablemd/durable-streams"; -import { InMemoryStream } from "@executablemd/durable-streams"; import { scoped, until } from "effection"; import type { Operation } from "effection"; import { spawnSync } from "node:child_process"; @@ -36,6 +35,9 @@ import { denoCommitVerifier } from "../src/deno/run-composition/verification.ts" import type { CommitVerifier } from "../src/deno/run-composition/verification.ts"; import { capturingProbe } from "./support/observations.ts"; import { raised, runOrdinaryDocument, useManagedRoot } from "./support/run-composition.ts"; +import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal"; + +const OWNER = "packages/git/tests/git-commit-read.test.ts"; /** Whether this host can sign and verify the SSH fixture commits at all. */ const SSH_KEYGEN = spawnSync("ssh-keygen", ["-?"]).error === undefined; @@ -750,6 +752,7 @@ const SUPPLIED_SELECTION: RepositorySelection = Object.freeze({ }); describe("GCR6 — the selected checkout answers, and nothing changes (A6)", () => { + beforeEach(journalBeforeEach(OWNER)); it("selects each sibling checkout's own commit", function* () { const fixture = yield* useCommitFixture(); const linked = join(fixture.root, "..", "linked"); @@ -817,7 +820,7 @@ describe("GCR6 — the selected checkout answers, and nothing changes (A6)", () return yield* collect( yield* execute({ ...inlineSource(`\n`), - stream: new InMemoryStream(), + stream: yield* useJournalStream(""), }), ); }), diff --git a/packages/git/tests/git-commit.test.ts b/packages/git/tests/git-commit.test.ts index 59a82025a..23f4118cf 100644 --- a/packages/git/tests/git-commit.test.ts +++ b/packages/git/tests/git-commit.test.ts @@ -8,11 +8,10 @@ * says what this provider believes, and only the object says what Git did. */ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; import { expect } from "@executablemd/test-support/expect"; import { collect, execute, inlineSource, registerComponents } from "@executablemd/core"; import type { ComponentRegistration } from "@executablemd/core"; -import { InMemoryStream } from "@executablemd/durable-streams"; import type { Json } from "@executablemd/durable-streams"; import { scoped, sleep, spawn, suspend, until, withResolvers } from "effection"; import type { Operation } from "effection"; @@ -74,6 +73,9 @@ import { gitPluginAdmissions } from "./support/composition.ts"; import { dropRootClose } from "./support/replay.ts"; import type { RepositorySelection } from "@executablemd/git/api"; +import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal"; + +const OWNER = "packages/git/tests/git-commit.test.ts"; /** One tracked file at the root and one in a subdirectory. */ const REMOTE = { commits: [ @@ -785,6 +787,7 @@ describe("workflow Git.Commit leading content", () => { }); describe("workflow Git.Commit selection", () => { + beforeEach(journalBeforeEach(OWNER)); it("commits in the linked Worktree the working directory selects", function* () { const root = yield* useStorageRoot(); const remote = yield* useBareRemote(REMOTE); @@ -947,7 +950,7 @@ describe("workflow Git.Commit selection", () => { return yield* collect( yield* execute({ ...inlineSource(``), - stream: new InMemoryStream(), + stream: yield* useJournalStream(""), }), ); }), diff --git a/packages/git/tests/git-switch.test.ts b/packages/git/tests/git-switch.test.ts index bcd58e10b..076ca46dd 100644 --- a/packages/git/tests/git-switch.test.ts +++ b/packages/git/tests/git-switch.test.ts @@ -12,12 +12,11 @@ * nothing. */ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; import { expect } from "@executablemd/test-support/expect"; import { content, registerComponents } from "@executablemd/core"; import type { ComponentRegistration } from "@executablemd/core"; import { collect, execute, inlineSource } from "@executablemd/core"; -import { InMemoryStream } from "@executablemd/durable-streams"; import type { Json } from "@executablemd/durable-streams"; import { scoped, until } from "effection"; import { readTextFile, writeTextFile } from "@effectionx/fs"; @@ -74,6 +73,9 @@ import { committedRoot, dropRootClose, latestRoot, publishedRoots } from "./supp import { filteredRepositoryIdentity } from "../src/composition/selection.ts"; import { type RepositorySelection } from "@executablemd/git/api"; +import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal"; + +const OWNER = "packages/git/tests/git-switch.test.ts"; /** * Two branches whose content differs, plus one file that does not. * @@ -489,6 +491,7 @@ describe("workflow Git.Switch", () => { }); describe("workflow Git.Switch selection", () => { + beforeEach(journalBeforeEach(OWNER)); it("selects the enclosing checkout from a directory inside it", function* () { const root = yield* useStorageRoot(); const remote = yield* useBareRemote(REMOTE); @@ -719,7 +722,7 @@ describe("workflow Git.Switch selection", () => { return yield* collect( yield* execute({ ...inlineSource(``), - stream: new InMemoryStream(), + stream: yield* useJournalStream(""), }), ); }), diff --git a/packages/git/tests/github-activation.test.ts b/packages/git/tests/github-activation.test.ts index 6901bb359..03cf4d046 100644 --- a/packages/git/tests/github-activation.test.ts +++ b/packages/git/tests/github-activation.test.ts @@ -23,14 +23,14 @@ * read still gets its answer. */ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; import { expect } from "@executablemd/test-support/expect"; import { scoped } from "effection"; import { API } from "@executablemd/runtime"; import type { Operation } from "effection"; import { collect, inlineSource } from "@executablemd/core"; import { executeInstalled } from "@executablemd/core/host"; -import { InMemoryStream } from "@executablemd/durable-streams"; +import type { InMemoryStream } from "@executablemd/durable-streams"; import { gitPlugin } from "../src/plugin.ts"; import { IssueApi } from "@executablemd/git/api"; import { GITHUB, useGitHubIssues } from "../src/deno/issue/github.ts"; @@ -44,6 +44,9 @@ import type { } from "../src/deno/composition/github.ts"; import { GITHUB_ISSUES_ENV } from "../src/deno/issue/configuration.ts"; import { fakeGitHubAccess, gitHubStore } from "./support/github.ts"; +import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal"; + +const OWNER = "packages/git/tests/github-activation.test.ts"; /** Where every step this suite watches records itself, in the order it happened. */ type Step = "configuration" | "source" | "open" | "credential" | "transport"; @@ -153,21 +156,22 @@ function reviewing(steps: Step[]): (endpoint?: string) => GitHubSource { } /** One document, executed with the bundled Plugin installed and nothing else. */ -function* document(source: string): Operation { - const stream = new InMemoryStream(); +function* document(stream: InMemoryStream | undefined, source: string): Operation { const install = gitPlugin.install; if (install === undefined) { throw new Error("the Git Plugin installed nothing"); } const contribution = yield* install.call(gitPlugin, { command: "run", args: ["run"] }); return yield* collect( - yield* executeInstalled({ ...inlineSource(source), stream }, [ - { admissions: [...(contribution?.admissions ?? [])] }, - ]), + yield* executeInstalled( + { ...inlineSource(source), stream: stream ?? (yield* useJournalStream("")) }, + [{ admissions: [...(contribution?.admissions ?? [])] }], + ), ); } describe("what installing the bundled GitHub adapter costs", () => { + beforeEach(journalBeforeEach(OWNER)); it("reads no configuration when the Plugin is installed and nothing is invoked", function* () { // The whole contribution — declarations and admissions — with every // outward boundary refusing. Installation is the thing under test. @@ -200,7 +204,7 @@ describe("what installing the bundled GitHub adapter costs", () => { }, }), }); - return yield* document("nothing here reaches a service\n"); + return yield* document(undefined, "nothing here reaches a service\n"); }); expect(String(rendered)).toContain("nothing here reaches a service"); }); diff --git a/packages/git/tests/github-workflow-activation.test.ts b/packages/git/tests/github-workflow-activation.test.ts index ed5196a42..6e758f2a8 100644 --- a/packages/git/tests/github-workflow-activation.test.ts +++ b/packages/git/tests/github-workflow-activation.test.ts @@ -17,7 +17,7 @@ * and describes the Plan component under the same refusing boundary. */ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; import { expect } from "@executablemd/test-support/expect"; import { scoped } from "effection"; import type { Operation } from "effection"; @@ -26,7 +26,7 @@ import { useRunComposition } from "../src/deno/run-composition/provider.ts"; import { gitPlugin } from "../src/plugin.ts"; import { collect, inlineSource } from "@executablemd/core"; import { executeInstalled } from "@executablemd/core/host"; -import { InMemoryStream } from "@executablemd/durable-streams"; +import type { InMemoryStream } from "@executablemd/durable-streams"; import { useTempDirectory } from "@executablemd/test-support/temp"; import type { GitHubSource } from "../src/deno/composition/github.ts"; import { runWorkflowDocument } from "./support/composition.ts"; @@ -37,6 +37,9 @@ import { withExecutorRun, withRunHost, } from "../../workflow/tests/support/storage.ts"; +import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal"; + +const OWNER = "packages/git/tests/github-workflow-activation.test.ts"; /** A transport factory that refuses to be built at all. */ function forbidden(): GitHubSource { @@ -59,21 +62,22 @@ function* refusing(): Operation { } /** One document, executed with the bundled Plugin installed and nothing else. */ -function* document(source: string): Operation { - const stream = new InMemoryStream(); +function* document(stream: InMemoryStream | undefined, source: string): Operation { const install = gitPlugin.install; if (install === undefined) { throw new Error("the Git Plugin installed nothing"); } const contribution = yield* install.call(gitPlugin, { command: "run", args: ["run"] }); return yield* collect( - yield* executeInstalled({ ...inlineSource(source), stream }, [ - { admissions: [...(contribution?.admissions ?? [])] }, - ]), + yield* executeInstalled( + { ...inlineSource(source), stream: stream ?? (yield* useJournalStream("")) }, + [{ admissions: [...(contribution?.admissions ?? [])] }], + ), ); } describe("the bundled profile, assembled", () => { + beforeEach(journalBeforeEach(OWNER)); it("installs the whole ordinary-run profile without reading any of it", function* () { // The real assembly this time, not the adapters alone: `useRunComposition` // is what `xmd run` installs, and it brings the repository provider, the @@ -88,7 +92,7 @@ describe("the bundled profile, assembled", () => { gitHubIssues: { host: forbidden }, gitHubPullRequests: { host: forbidden }, }); - return yield* document("a plain document that reaches nothing\n"); + return yield* document(undefined, "a plain document that reaches nothing\n"); }); expect(String(rendered)).toContain("a plain document that reaches nothing"); }); @@ -105,7 +109,7 @@ describe("the bundled profile, assembled", () => { gitHubIssues: { host: forbidden }, gitHubPullRequests: { host: forbidden }, }); - return yield* document('local work only\n'); + return yield* document(undefined, 'local work only\n'); }); expect(String(rendered)).toContain("local work only"); }); diff --git a/packages/git/tests/run-composition-lazy.test.ts b/packages/git/tests/run-composition-lazy.test.ts index 0f391f1ac..59a7caa79 100644 --- a/packages/git/tests/run-composition-lazy.test.ts +++ b/packages/git/tests/run-composition-lazy.test.ts @@ -16,7 +16,7 @@ * capability acquires it *once*, however many times it is asked for. */ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; import { expect } from "@executablemd/test-support/expect"; import { all, scoped, spawn } from "effection"; import type { Operation } from "effection"; @@ -30,12 +30,15 @@ import { repositoryOperationsOver } from "../src/deno/repository-operations.ts"; import type { DenoRepositoryOperations } from "../deno.ts"; import type { HelperAssembly } from "../credential-helper.ts"; import { collect, execute, inlineSource } from "@executablemd/core"; -import { InMemoryStream } from "@executablemd/durable-streams"; +import type { InMemoryStream } from "@executablemd/durable-streams"; import { useHostFiles } from "@executablemd/runtime"; import { useRunComposition } from "../src/deno/run-composition/provider.ts"; import { useCompositionComponents } from "../src/composition/installation.ts"; import { Repository } from "@executablemd/git/api"; import type { RepositoryHost, GitInvocation, GitOutcome } from "../src/deno/composition/host.ts"; +import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal"; + +const OWNER = "packages/git/tests/run-composition-lazy.test.ts"; /** Every acquisition this provider can make, counted where it happens. */ interface Acquisitions { @@ -76,7 +79,11 @@ function counting(seen: Acquisitions, directory: string): RepositoryHost { } /** One document, run with the provider installed over a counting host. */ -function* run(source: string, seen: Acquisitions): Operation { +function* run( + stream: InMemoryStream | undefined, + source: string, + seen: Acquisitions, +): Operation { const directory = yield* useTempDirectory("xmd-lazy"); const root = yield* useTempDirectory("xmd-lazy-root"); return String( @@ -96,13 +103,17 @@ function* run(source: string, seen: Acquisitions): Operation { }, }); return yield* collect( - yield* execute({ ...inlineSource(source), stream: new InMemoryStream() }), + yield* execute({ + ...inlineSource(source), + stream: stream ?? (yield* useJournalStream("")), + }), ); }), ); } describe("what the ordinary repository provider acquires, and when", () => { + beforeEach(journalBeforeEach(OWNER)); it("acquires nothing at installation", function* () { const seen = counters(); const directory = yield* useTempDirectory("xmd-lazy"); @@ -115,7 +126,7 @@ describe("what the ordinary repository provider acquires, and when", () => { it("acquires nothing for a document that writes no repository component", function* () { const seen = counters(); - const rendered = yield* run("a plain document\n", seen); + const rendered = yield* run(undefined, "a plain document\n", seen); // The document really ran — an empty render would satisfy every count. expect(rendered).toContain("a plain document"); expect(seen).toEqual({ directories: 0, commands: [], identities: 0 }); @@ -123,7 +134,7 @@ describe("what the ordinary repository provider acquires, and when", () => { it("acquires no repository capability for a bare ", function* () { const seen = counters(); - const rendered = yield* run('local work only\n', seen); + const rendered = yield* run(undefined, 'local work only\n', seen); expect(rendered).toContain("local work only"); // `` makes a directory. It selects no repository, runs no `git`, opens // no session and reads no identity. diff --git a/packages/test-agent/tests/cross-package-resolution.test.ts b/packages/test-agent/tests/cross-package-resolution.test.ts index ec3243bc3..3f0da9937 100644 --- a/packages/test-agent/tests/cross-package-resolution.test.ts +++ b/packages/test-agent/tests/cross-package-resolution.test.ts @@ -1,3 +1,8 @@ +import { + captureTestJournal, + journalBeforeEach, + useJournalStream, +} from "@executablemd/test-support/failure-journal"; /** * Tier XP — cross-package resolution (issue #202 acceptance). * @@ -15,7 +20,7 @@ * execution does not reveal. */ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeEach, describe, it } from "@executablemd/test-support/bdd"; import { executeInstalled } from "@executablemd/core/host"; import { expect } from "@executablemd/test-support/expect"; import { ensure, resource, scoped, until } from "effection"; @@ -24,7 +29,7 @@ import { ensureDir, rm, writeTextFile } from "@effectionx/fs"; import { mkdtemp, realpath } from "node:fs/promises"; import { tmpdir } from "node:os"; import { dirname, join } from "node:path"; -import { InMemoryStream } from "@executablemd/durable-streams"; +import type { InMemoryStream } from "@executablemd/durable-streams"; import { collect, Component, @@ -155,7 +160,7 @@ function* writeStandIns(workspace: string): Operation { } /** Execute a document invoking every registered name, and return its text. */ -function runDocument(workspace: string, order: Order): Operation { +function runDocument(workspace: string, order: Order, stream: InMemoryStream): Operation { return scoped(function* () { const path = join(workspace, "doc.md"); // Self-closing, so nothing is handed content to expand. @@ -163,7 +168,7 @@ function runDocument(workspace: string, order: Order): Operation { yield* useTempFileCompiler(); yield* installAll(order); const output = yield* collect( - yield* executeInstalled({ path, stream: new InMemoryStream(), includes: [workspace] }, [ + yield* executeInstalled({ path, stream, includes: [workspace] }, [ { components: agentIdentityComponents() }, ]), ); @@ -216,7 +221,10 @@ function describeOrigin(info: ComponentInfo): string { } } +const OWNER = "packages/test-agent/tests/cross-package-resolution.test.ts"; + describe("Tier XP — cross-package resolution", () => { + beforeEach(journalBeforeEach(OWNER)); /** * The inventory below is what every other case iterates, so a name missing * from it is coverage silently not taken. Comparing against the live registry @@ -237,9 +245,10 @@ describe("Tier XP — cross-package resolution", () => { it("XP1: a repository component runs in place of every registered default", function* () { const workspace = yield* useWorkspace(); + const stream = yield* useJournalStream(join(workspace, "doc.md")); yield* writeStandIns(workspace); - const output = yield* runDocument(workspace, "agent-first"); + const output = yield* runDocument(workspace, "agent-first", stream); // Rendered output, not a resolver answer: each marker is evidence that the // repository file is what executed for that name. @@ -248,19 +257,29 @@ describe("Tier XP — cross-package resolution", () => { } }); - it("XP2: which installer ran first changes nothing about what executed", function* () { + const orderCase = "XP2: which installer ran first changes nothing about what executed"; + it(orderCase, function* () { const workspace = yield* useWorkspace(); yield* writeStandIns(workspace); - const first = yield* runDocument(workspace, "agent-first"); - const second = yield* runDocument(workspace, "test-agent-first"); + const source = join(workspace, "doc.md"); + yield* captureTestJournal({ owner: OWNER, name: orderCase }, source, function* (stream) { + const first = yield* runDocument(workspace, "agent-first", stream); + yield* captureTestJournal( + { owner: OWNER, name: orderCase }, + source, + function* (secondStream) { + const second = yield* runDocument(workspace, "test-agent-first", secondStream); - // Installation order is not a resolution mechanism, so the two runs produce - // the same document — not merely the same set of resolved origins. - expect(second).toBe(first); - for (const name of REGISTERED) { - expect(second).toContain(marker(name)); - } + // Installation order is not a resolution mechanism, so the two runs produce + // the same document — not merely the same set of resolved origins. + expect(second).toBe(first); + for (const name of REGISTERED) { + expect(second).toContain(marker(name)); + } + }, + ); + }); }); it("XP3: each package's names carry that package's origin, and none is reserved", function* () { @@ -286,6 +305,7 @@ describe("Tier XP — cross-package resolution", () => { const workspace = yield* useWorkspace(); yield* writeTextFile(join(workspace, "Each.md"), "SHOULD NOT RENDER\n"); const path = join(workspace, "doc.md"); + const stream = yield* useJournalStream(path); yield* writeTextFile(path, '[{n}]\n'); const observed = yield* scoped(function* () { @@ -295,7 +315,7 @@ describe("Tier XP — cross-package resolution", () => { info: yield* inspectComponent({ name: "Each", includes: [workspace] }), output: String( yield* collect( - yield* executeInstalled({ path, stream: new InMemoryStream(), includes: [workspace] }, [ + yield* executeInstalled({ path, stream, includes: [workspace] }, [ { components: agentIdentityComponents() }, ]), ), diff --git a/packages/testing/tests/testing-activation.test.ts b/packages/testing/tests/testing-activation.test.ts index 190725bb6..91c7fc58d 100644 --- a/packages/testing/tests/testing-activation.test.ts +++ b/packages/testing/tests/testing-activation.test.ts @@ -9,6 +9,7 @@ * and "no results" is the vacuous failure mode rather than the evidence. */ +import { captureTestJournal } from "@executablemd/test-support/failure-journal"; import { describe, it, beforeAll } from "@executablemd/test-support/bdd"; import { expect } from "@executablemd/test-support/expect"; import { scoped } from "effection"; @@ -112,6 +113,8 @@ function useSentinel(sentinels: string[]): Operation { ]); } +const OWNER = "packages/testing/tests/testing-activation.test.ts"; + /** * Run `document` under a composition of the caller's choosing. * @@ -420,79 +423,112 @@ describe("complete testing activation", () => { // The control, in the identical middleware order: a handler that delegates // observes the behavior and changes nothing about it. it("leaves an ordinary TestBehavior handler composing under a complete session", function* () { - const behavior = loadedCopyBehaviorApi(); - const observed: string[] = []; - const attempt = yield* runComposed( - '\n', - (function* () { - yield* behavior.around({ - *test([props], next) { - observed.push(String(props.name)); - return yield* next(props); - }, - }); - yield* useTesting(); - })(), + yield* captureTestJournal( + { + owner: OWNER, + name: "leaves an ordinary TestBehavior handler composing under a complete session", + }, + "README.md", + function* (stream) { + const behavior = loadedCopyBehaviorApi(); + const observed: string[] = []; + const attempt = yield* runComposed( + '\n', + (function* () { + yield* behavior.around({ + *test([props], next) { + observed.push(String(props.name)); + return yield* next(props); + }, + }); + yield* useTesting(); + })(), + stream, + ); + expect(observed).toEqual(["t"]); + expect(attempt.sentinels).toEqual(["body"]); + expect(attempt.completion.ok).toBe(true); + expect(attempt.results.map((result) => [result.name, result.status])).toEqual([ + ["t", "pass"], + ]); + expect(testResultEvents(attempt.events)).toHaveLength(1); + }, ); - expect(observed).toEqual(["t"]); - expect(attempt.sentinels).toEqual(["body"]); - expect(attempt.completion.ok).toBe(true); - expect(attempt.results.map((result) => [result.name, result.status])).toEqual([["t", "pass"]]); - expect(testResultEvents(attempt.events)).toHaveLength(1); }); // The other direction: under a real session the same public surface keeps // working, and observes results in discovery order. it("leaves loaded-copy policy and recording composition working", function* () { - const attempt = yield* runComposed( - [ - '', - '', - "", - ].join("\n"), - useTesting(), + yield* captureTestJournal( + { owner: OWNER, name: "leaves loaded-copy policy and recording composition working" }, + "README.md", + function* (stream) { + const attempt = yield* runComposed( + [ + '', + '', + "", + ].join("\n"), + useTesting(), + stream, + ); + expect(attempt.completion.ok).toBe(true); + expect(attempt.sentinels).toEqual(["first", "second"]); + expect(attempt.results.map((result) => [result.name, result.status])).toEqual([ + ["first", "pass"], + ["second", "pass"], + ]); + expect(testResultEvents(attempt.events)).toHaveLength(2); + }, ); - expect(attempt.completion.ok).toBe(true); - expect(attempt.sentinels).toEqual(["first", "second"]); - expect(attempt.results.map((result) => [result.name, result.status])).toEqual([ - ["first", "pass"], - ["second", "pass"], - ]); - expect(testResultEvents(attempt.events)).toHaveLength(2); }); // Narrowing is what the public boolean is for, and it still works: a policy // that answers `false` leaves the test inactive rather than refused. it("lets public policy narrow testing to false under a complete session", function* () { - const attempt = yield* runComposed( - '\n', - (function* () { - yield* useTesting(); - const policy = loadedCopyTestApi(); - yield* policy.around({ testing: () => false }); - })(), + yield* captureTestJournal( + { owner: OWNER, name: "lets public policy narrow testing to false under a complete session" }, + "README.md", + function* (stream) { + const attempt = yield* runComposed( + '\n', + (function* () { + yield* useTesting(); + const policy = loadedCopyTestApi(); + yield* policy.around({ testing: () => false }); + })(), + stream, + ); + expect(attempt.sentinels).toEqual([]); + expect(attempt.results).toEqual([]); + // No tests were discovered, which is the session's own outcome — not the + // activation refusal. + expect(errorOf(attempt)?.message).toContain("no tests were discovered"); + }, ); - expect(attempt.sentinels).toEqual([]); - expect(attempt.results).toEqual([]); - // No tests were discovered, which is the session's own outcome — not the - // activation refusal. - expect(errorOf(attempt)?.message).toContain("no tests were discovered"); }); // An ended boundary's credential is retired, so a `` written after it // is refused exactly as one written before it. it("expires with the boundary that established it", function* () { - const attempt = yield* runComposed( - [ - "", - '', - "", - '', - "", - ].join("\n"), - incompleteActivation(), + yield* captureTestJournal( + { owner: OWNER, name: "expires with the boundary that established it" }, + "README.md", + function* (stream) { + const attempt = yield* runComposed( + [ + "", + '', + "", + '', + "", + ].join("\n"), + incompleteActivation(), + stream, + ); + expect(attempt.sentinels).toEqual(["inside"]); + expect(errorOf(attempt)?.message).toContain(REFUSAL); + }, ); - expect(attempt.sentinels).toEqual(["inside"]); - expect(errorOf(attempt)?.message).toContain(REFUSAL); }); });