Skip to content

Commit 6c4a5ea

Browse files
authored
Attribute inline Issue and repository test journals (#1380) (#1380)
1 parent 301de7b commit 6c4a5ea

2 files changed

Lines changed: 67 additions & 34 deletions

File tree

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

Lines changed: 59 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
* looks at.
1515
*/
1616

17-
import { describe, it } from "@executablemd/test-support/bdd";
17+
import { beforeEach, describe, it } from "@executablemd/test-support/bdd";
1818
import { expect } from "@executablemd/test-support/expect";
19+
import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal";
1920
import { ensure, resource, scoped, spawn, suspend, until, withResolvers } from "effection";
2021
import type { Operation, Result } from "effection";
2122
import { exists, writeTextFile } from "@effectionx/fs";
@@ -755,6 +756,7 @@ const QUESTION =
755756
'<Elicit schema={{ type: "object", properties: { decision: { type: "string" } }, required: ["decision"], additionalProperties: false }} as="answer">Continue?</Elicit>';
756757

757758
describe("how a REPL entry gets its issues", () => {
759+
beforeEach(journalBeforeEach(OWNER));
758760
it("E1: composes public middleware once, under the key the request itself names", () =>
759761
captureReplEntry(
760762
{
@@ -844,7 +846,7 @@ describe("how a REPL entry gets its issues", () => {
844846
QUESTION,
845847
].join("\n");
846848

847-
const first = execution("execution-1");
849+
const first = { id: "execution-1", stream: yield* useJournalStream(INLINE_SOURCE_PATH) };
848850
const left = yield* submit(fixture, two, first, {
849851
host: entryHost(fixture, seen),
850852
leave: true,
@@ -873,7 +875,7 @@ describe("how a REPL entry gets its issues", () => {
873875

874876
// Another execution's first entry, with identical text: its own owner, its
875877
// own sites, its own issues.
876-
const other = execution("execution-2");
878+
const other = { id: "execution-2", stream: yield* useJournalStream(INLINE_SOURCE_PATH) };
877879
yield* submit(fixture, two, other, { host: entryHost(fixture, seen), leave: true });
878880
expect(fixture.server.issues.length).toBe(4);
879881
const everything = bodies(fixture.server);
@@ -886,7 +888,7 @@ describe("how a REPL entry gets its issues", () => {
886888
it("E2: a successor entry of one execution is not the entry before it", function* (): Operation<void> {
887889
const fixture = yield* useFixture();
888890
const seen = counted();
889-
const run = execution("execution-1");
891+
const run = { id: "execution-1", stream: yield* useJournalStream(INLINE_SOURCE_PATH) };
890892

891893
yield* scoped(function* (): Operation<void> {
892894
yield* useNodeReplHost(run.id);
@@ -918,19 +920,29 @@ describe("how a REPL entry gets its issues", () => {
918920

919921
it("E2: no replaceable answer moves the owner, the site or the key", function* (): Operation<void> {
920922
const fixture = yield* useFixture();
921-
const plain = yield* submit(fixture, FILES_ONE, execution("execution-1"), {
922-
host: entryHost(fixture, counted()),
923-
});
923+
const plain = yield* submit(
924+
fixture,
925+
FILES_ONE,
926+
{ id: "execution-1", stream: yield* useJournalStream(INLINE_SOURCE_PATH) },
927+
{
928+
host: entryHost(fixture, counted()),
929+
},
930+
);
924931
expect(plain.outcome?.ok).toBe(true);
925932

926933
// The same entry of a second execution, with a middleware that rewrites
927934
// the issue it is handed. What it sends changes and what names the work
928935
// does not: the site is the same site, and only the owner differs, because
929936
// the execution does.
930-
const second = yield* submit(fixture, FILES_ONE, execution("execution-2"), {
931-
host: entryHost(fixture, counted()),
932-
installations: [observingChain({ calls: [] }, "Rewritten")],
933-
});
937+
const second = yield* submit(
938+
fixture,
939+
FILES_ONE,
940+
{ id: "execution-2", stream: yield* useJournalStream(INLINE_SOURCE_PATH) },
941+
{
942+
host: entryHost(fixture, counted()),
943+
installations: [observingChain({ calls: [] }, "Rewritten")],
944+
},
945+
);
934946
expect(second.outcome?.ok).toBe(true);
935947

936948
const site = (events: readonly DurableEvent[]): string | undefined =>
@@ -1069,7 +1081,7 @@ describe("how a REPL entry gets its issues", () => {
10691081
const fixture = yield* useFixture();
10701082
const seen = counted();
10711083
const source = [FILES_ONE, QUESTION].join("\n");
1072-
const run = execution("execution-1");
1084+
const run = { id: "execution-1", stream: yield* useJournalStream(INLINE_SOURCE_PATH) };
10731085

10741086
const left = yield* submit(fixture, source, run, {
10751087
host: entryHost(fixture, seen),
@@ -1204,7 +1216,7 @@ describe("how a REPL entry gets its issues", () => {
12041216

12051217
it("E5: a settled history installs no issue host and reaches nothing", function* (): Operation<void> {
12061218
const fixture = yield* useFixture();
1207-
const run = execution("execution-1");
1219+
const run = { id: "execution-1", stream: yield* useJournalStream(INLINE_SOURCE_PATH) };
12081220
const ran = yield* submit(fixture, FILES_ONE, run, { host: entryHost(fixture, counted()) });
12091221
expect(ran.outcome?.ok).toBe(true);
12101222
const before = paths(fixture.server).length;
@@ -1295,20 +1307,31 @@ describe("how a REPL entry gets its issues", () => {
12951307

12961308
// Neither form: the entry's own implementation refuses this, which is what
12971309
// makes the next run's success evidence that a different component ran.
1298-
const refused = yield* submit(fixture, '<Issue as="local" />', execution("execution-1"), {
1299-
host: entryHost(fixture, counted()),
1300-
includes: [local],
1301-
});
1310+
const localSource = '<Issue as="local" />';
1311+
const refused = yield* submit(
1312+
fixture,
1313+
localSource,
1314+
{ id: "execution-1", stream: yield* useJournalStream(INLINE_SOURCE_PATH) },
1315+
{
1316+
host: entryHost(fixture, counted()),
1317+
includes: [local],
1318+
},
1319+
);
13021320
expect(refused.outcome?.ok).toBe(false);
13031321
expect(String(refused.outcome?.ok === false ? refused.outcome.error.message : "")).toContain(
13041322
"either reads an issue",
13051323
);
13061324

13071325
yield* writeTextFile(join(local, "Issue.md"), "a repository component ran\n");
1308-
const overridden = yield* submit(fixture, '<Issue as="local" />', execution("execution-2"), {
1309-
host: entryHost(fixture, counted()),
1310-
includes: [local],
1311-
});
1326+
const overridden = yield* submit(
1327+
fixture,
1328+
localSource,
1329+
{ id: "execution-2", stream: yield* useJournalStream(INLINE_SOURCE_PATH) },
1330+
{
1331+
host: entryHost(fixture, counted()),
1332+
includes: [local],
1333+
},
1334+
);
13121335

13131336
// A repository file outranks a registered default, and this one is a
13141337
// default — so the entry's implementation is not reached, files nothing and
@@ -1320,7 +1343,7 @@ describe("how a REPL entry gets its issues", () => {
13201343

13211344
it("E5: a frozen position installs no issue host and reaches nothing", function* (): Operation<void> {
13221345
const fixture = yield* useFixture();
1323-
const run = execution("execution-1");
1346+
const run = { id: "execution-1", stream: yield* useJournalStream(INLINE_SOURCE_PATH) };
13241347
const passive = counted();
13251348

13261349
const marker = yield* scoped(function* (): Operation<string> {
@@ -1380,7 +1403,7 @@ describe("how a REPL entry gets its issues", () => {
13801403
QUESTION,
13811404
].join("\n");
13821405

1383-
const run = execution("execution-1");
1406+
const run = { id: "execution-1", stream: yield* useJournalStream(INLINE_SOURCE_PATH) };
13841407
const left = yield* submit(fixture, source, run, {
13851408
host: entryHost(fixture, seen),
13861409
installations: [answeringChain(chain, ANSWERED)],
@@ -1441,7 +1464,7 @@ describe("how a REPL entry gets its issues", () => {
14411464
QUESTION,
14421465
].join("\n");
14431466

1444-
const run = execution("execution-1");
1467+
const run = { id: "execution-1", stream: yield* useJournalStream(INLINE_SOURCE_PATH) };
14451468
const left = yield* submit(fixture, source, run, {
14461469
host: entryHost(fixture, seen),
14471470
leave: true,
@@ -1605,7 +1628,10 @@ describe("how a REPL entry gets its issues", () => {
16051628

16061629
// No entry host: `<Issue>` is still declared by the Plugin for this
16071630
// command, and reaching it is the ordinary missing-provider refusal.
1608-
const without = yield* submit(fixture, FILES_ONE, execution("execution-1"));
1631+
const without = yield* submit(fixture, FILES_ONE, {
1632+
id: "execution-1",
1633+
stream: yield* useJournalStream(INLINE_SOURCE_PATH),
1634+
});
16091635
expect(without.outcome?.ok).toBe(false);
16101636
expect(String(without.outcome?.ok === false ? without.outcome.error.message : "")).toContain(
16111637
"no Issue provider is installed",
@@ -1615,9 +1641,14 @@ describe("how a REPL entry gets its issues", () => {
16151641

16161642
// With one, the entry's own implementation answers instead — one retained
16171643
// record, and one issue at the tracker.
1618-
const with_ = yield* submit(fixture, FILES_ONE, execution("execution-2"), {
1619-
host: entryHost(fixture, seen),
1620-
});
1644+
const with_ = yield* submit(
1645+
fixture,
1646+
FILES_ONE,
1647+
{ id: "execution-2", stream: yield* useJournalStream(INLINE_SOURCE_PATH) },
1648+
{
1649+
host: entryHost(fixture, seen),
1650+
},
1651+
);
16211652
expect(with_.outcome?.ok).toBe(true);
16221653
expect(issueRecords(with_.events).length).toBe(1);
16231654
expect(urls(with_.events)).toEqual([`${TRACKER}/issues/1`]);

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
* one's are.
1818
*/
1919

20-
import { describe, it } from "@executablemd/test-support/bdd";
20+
import { beforeEach, describe, it } from "@executablemd/test-support/bdd";
2121
import { expect } from "@executablemd/test-support/expect";
22+
import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal";
2223
import { ensure, Err, resource, scoped, until } from "effection";
2324
import type { Operation, Result } from "effection";
2425
import { ensureDir, exists, readTextFile, rm } from "@effectionx/fs";
@@ -306,10 +307,10 @@ function* submit(
306307
}
307308

308309
describe("how a REPL entry gets its repository behavior", () => {
310+
beforeEach(journalBeforeEach(OWNER));
309311
it("retains an admitted fragment's write and delete, and replays them", function* () {
310312
const fixture = yield* useFixture();
311313
const counted: Counted = { initialized: 0 };
312-
const run = execution();
313314
// A fragment that writes, a fragment that deletes, and a question nobody
314315
// answers — which is what leaves the entry unfinished, so reopening it is a
315316
// continuation rather than a reading of a settled history.
@@ -318,6 +319,7 @@ describe("how a REPL entry gets its repository behavior", () => {
318319
`<Evaluate text={${JSON.stringify('<File.Delete path="seed.md" />\n')}} allow={["write"]} />`,
319320
'<Elicit schema={{ type: "object", properties: { decision: { type: "string" } }, required: ["decision"], additionalProperties: false }} as="answer">Continue?</Elicit>',
320321
].join("\n");
322+
const run = { id: "execution-1", stream: yield* useJournalStream(INLINE_SOURCE_PATH) };
321323

322324
const events = yield* scoped(function* () {
323325
yield* useNodeReplHost("execution-1");
@@ -615,8 +617,8 @@ describe("how a REPL entry gets its repository behavior", () => {
615617
it("E7: keeps two entries' equal records in their own segments", function* () {
616618
const fixture = yield* useFixture();
617619
const counted: Counted = { initialized: 0 };
618-
const run = execution();
619620
const source = '<File path="same.md">same</File>';
621+
const run = { id: "execution-1", stream: yield* useJournalStream(INLINE_SOURCE_PATH) };
620622

621623
yield* submit(fixture, source, run, counted);
622624
// Removed between the two entries, so whether the second one performed its
@@ -642,7 +644,6 @@ describe("how a REPL entry gets its repository behavior", () => {
642644
it("E6: retains a generated read's text, and answers it after the file changes", function* () {
643645
const fixture = yield* useFixture();
644646
const counted: Counted = { initialized: 0 };
645-
const run = execution();
646647
// A fragment reads a file in the checkout, then the entry stops at a
647648
// question — so the read is completed and the entry is not. The fragment
648649
// binds the text rather than interpolating it: a generated fragment may not
@@ -651,6 +652,7 @@ describe("how a REPL entry gets its repository behavior", () => {
651652
`<Evaluate text={${JSON.stringify('<File path="seed.md" as="held" />\n')}} allow={["read"]} />`,
652653
'<Elicit schema={{ type: "object", properties: { decision: { type: "string" } }, required: ["decision"], additionalProperties: false }} as="answer">Continue?</Elicit>',
653654
].join("\n");
655+
const run = { id: "execution-1", stream: yield* useJournalStream(INLINE_SOURCE_PATH) };
654656

655657
const events = yield* scoped(function* () {
656658
yield* useNodeReplHost("execution-1");
@@ -741,7 +743,7 @@ describe("how a REPL entry gets its repository behavior", () => {
741743
it("prepares nothing for a settled history nobody is continuing", function* () {
742744
const fixture = yield* useFixture();
743745
const counted: Counted = { initialized: 0 };
744-
const run = execution();
746+
const run = { id: "execution-1", stream: yield* useJournalStream(INLINE_SOURCE_PATH) };
745747
const events = yield* submit(fixture, SETTLED_ENTRY, run, counted);
746748
expect(counted.initialized).toBe(1);
747749

@@ -769,12 +771,12 @@ describe("how a REPL entry gets its repository behavior", () => {
769771
it("E7: refuses a history whose own record it cannot read, before new work", function* () {
770772
const fixture = yield* useFixture();
771773
const counted: Counted = { initialized: 0 };
772-
const run = execution();
773774
const source = [
774775
'<File path="recorded.md">recorded</File>',
775776
'<Elicit schema={{ type: "object", properties: { decision: { type: "string" } }, required: ["decision"], additionalProperties: false }} as="answer">Continue?</Elicit>',
776777
'<File path="after.md">after</File>',
777778
].join("\n");
779+
const run = { id: "execution-1", stream: yield* useJournalStream(INLINE_SOURCE_PATH) };
778780

779781
const events = yield* scoped(function* () {
780782
yield* useNodeReplHost("execution-1");

0 commit comments

Comments
 (0)