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