Skip to content

Commit 0d568ea

Browse files
authored
Restack journal migration #1384 on main (#1384)
1 parent 609d6f5 commit 0d568ea

3 files changed

Lines changed: 85 additions & 35 deletions

File tree

‎packages/cli/tests/adversarial-session-continuity.test.ts‎

Lines changed: 57 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { describe, it } from "@executablemd/test-support/bdd";
1+
import { beforeEach, describe, it } from "@executablemd/test-support/bdd";
2+
import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal";
23
import { ensureDir, readTextFile, rm, writeTextFile } from "@effectionx/fs";
34
import { expect } from "@executablemd/test-support/expect";
45
import { useComponentModuleLoader } from "@executablemd/test-support/host";
@@ -36,6 +37,7 @@ import PhaseSession, {
3637
} from "../../../examples/adversarial-implementation/components/Phase/Session.ts";
3738

3839
const pair = z.strictObject({ kind: z.string(), value: z.string() });
40+
const OWNER = "packages/cli/tests/adversarial-session-continuity.test.ts";
3941
const receipt = z.strictObject({
4042
schema: z.literal("phase-session.v2"),
4143
agent: z.string(),
@@ -486,7 +488,11 @@ interface ReviewWorld {
486488
store: FakeStore;
487489
delivery: Record<string, Json>;
488490
asked: unknown[];
489-
run(source: string, props: Record<string, Json>): Operation<{ ok: boolean; text: string }>;
491+
run(
492+
source: string,
493+
props: Record<string, Json>,
494+
stream?: InMemoryStream,
495+
): Operation<{ ok: boolean; text: string }>;
490496
}
491497

492498
function* reviewWorld(fake: FakeAcp, create = fake.create): Operation<ReviewWorld> {
@@ -507,7 +513,7 @@ function* reviewWorld(fake: FakeAcp, create = fake.create): Operation<ReviewWorl
507513
inputs: [{ path: "accepted.md", content: "The original accepted behavior." }],
508514
required: ["independent-review", "required-ci", "main-health"],
509515
};
510-
function run(source: string, props: Record<string, Json>) {
516+
function run(source: string, props: Record<string, Json>, stream?: InMemoryStream) {
511517
return scoped(function* () {
512518
yield* useHostFiles();
513519
yield* useComponentModuleLoader();
@@ -539,7 +545,12 @@ function* reviewWorld(fake: FakeAcp, create = fake.create): Operation<ReviewWorl
539545
const doc = join(root, `document-${randomUUID()}.md`);
540546
yield* writeTextFile(doc, `---\nprops: {type: object}\n---\n${source}`);
541547
const executed = yield* executeInstalled(
542-
{ path: doc, stream: new InMemoryStream(), includes: [components], props },
548+
{
549+
path: doc,
550+
stream: stream ?? (yield* useJournalStream(doc)),
551+
includes: [components],
552+
props,
553+
},
543554
[{ components: agentIdentityComponents(), *install() {} }],
544555
);
545556
try {
@@ -576,6 +587,8 @@ const continuedRoleSource =
576587
'<Phase.Role role="implementor" session="controlled-owner" assignment={{...props.assignment,sessionEstablished:true}} />';
577588

578589
describe("production workflow provider scope", () => {
590+
beforeEach(journalBeforeEach(OWNER));
591+
579592
it("applies controls through each actual Claude role and retains them across cold reentry", function* () {
580593
for (const role of ["phase", "foundation", "preparation", "delivery"]) {
581594
const fake = createFakeAcp();
@@ -860,6 +873,8 @@ describe(
860873
"production independent review over the registered acpx factory",
861874
{ sanitizeOps: false, sanitizeResources: false },
862875
() => {
876+
beforeEach(journalBeforeEach(OWNER));
877+
863878
it("configures the advertised exact Fable model and effort, and omits a null effort", function* () {
864879
for (const effort of ["high", null]) {
865880
const fake = createFakeAcp();
@@ -922,18 +937,22 @@ describe(
922937
);
923938
const harness = yield* reviewWorld(fake);
924939
const attempt = join(harness.root, "delivery", "attempt");
925-
const ran = yield* harness.run(roleSource, {
926-
delivery: harness.delivery,
927-
revision,
928-
reviewer: {
929-
provider: "claude",
930-
model: "fable",
931-
effort: variant === "refused" ? "high" : null,
932-
session: "independent",
940+
const ran = yield* harness.run(
941+
roleSource,
942+
{
943+
delivery: harness.delivery,
944+
revision,
945+
reviewer: {
946+
provider: "claude",
947+
model: "fable",
948+
effort: variant === "refused" ? "high" : null,
949+
session: "independent",
950+
},
951+
choices: ["fable"],
952+
attempt,
933953
},
934-
choices: ["fable"],
935-
attempt,
936-
});
954+
new InMemoryStream(),
955+
);
937956
expect(ran.ok).toBe(true);
938957
const settled = outcome.parse(
939958
JSON.parse(yield* readTextFile(join(attempt, "outcome.json"))),
@@ -965,7 +984,7 @@ describe(
965984
const gate = closeGate(fake);
966985
const harness = yield* reviewWorld(fake, gate.create);
967986
const task = yield* spawn(() =>
968-
harness.run(reviewSource, { delivery: harness.delivery, revision }),
987+
harness.run(reviewSource, { delivery: harness.delivery, revision }, new InMemoryStream()),
969988
);
970989
yield* gate.reached.operation;
971990
expect(fake.turns).toHaveLength(1);
@@ -1014,7 +1033,7 @@ describe(
10141033
const gate = closeGate(fake);
10151034
const harness = yield* reviewWorld(fake, gate.create);
10161035
const task = yield* spawn(() =>
1017-
harness.run(reviewSource, { delivery: harness.delivery, revision }),
1036+
harness.run(reviewSource, { delivery: harness.delivery, revision }, new InMemoryStream()),
10181037
);
10191038
yield* gate.reached.operation;
10201039
expect(fake.turns.map((_, index) => agentOf(fake, index))).toEqual(["claude"]);
@@ -1072,7 +1091,11 @@ describe(
10721091
fake.configuration(catalog(["fable", "gpt-6-astra"]));
10731092
fake.script({ reply: "", cancelled: true });
10741093
const harness = yield* reviewWorld(fake);
1075-
const ran = yield* harness.run(reviewSource, { delivery: harness.delivery, revision });
1094+
const ran = yield* harness.run(
1095+
reviewSource,
1096+
{ delivery: harness.delivery, revision },
1097+
new InMemoryStream(),
1098+
);
10761099
expect(ran.ok).toBe(true);
10771100
expect(fake.turns.map((_, index) => agentOf(fake, index))).toEqual(["claude"]);
10781101
const attempt = join(harness.delivery.directory as string, `review-${revision}`);
@@ -1104,13 +1127,17 @@ describe(
11041127
);
11051128
function* reviewAt(sha: string) {
11061129
const attempt = join(harness.delivery.directory as string, `review-${sha}`);
1107-
const ran = yield* harness.run(roleSource, {
1108-
delivery: harness.delivery,
1109-
revision: sha,
1110-
reviewer,
1111-
choices: ["fable"],
1112-
attempt,
1113-
});
1130+
const ran = yield* harness.run(
1131+
roleSource,
1132+
{
1133+
delivery: harness.delivery,
1134+
revision: sha,
1135+
reviewer,
1136+
choices: ["fable"],
1137+
attempt,
1138+
},
1139+
new InMemoryStream(),
1140+
);
11141141
return { ran, attempt };
11151142
}
11161143
fake.configuration(catalog(["claude-opus"]));
@@ -1155,7 +1182,11 @@ describe(
11551182
});
11561183
fake.closeFailure = new Error("the review provider would not close");
11571184
const harness = yield* reviewWorld(fake);
1158-
const ran = yield* harness.run(reviewSource, { delivery: harness.delivery, revision });
1185+
const ran = yield* harness.run(
1186+
reviewSource,
1187+
{ delivery: harness.delivery, revision },
1188+
new InMemoryStream(),
1189+
);
11591190
expect(ran.ok).toBe(false);
11601191
expect(ran.text).toContain("agent provider teardown failed");
11611192
expect(fake.closes).toContain("scope teardown");

‎packages/cli/tests/compiled-upgrade.test.ts‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
* runtime and raced against a real Deno child, and no other runtime has one.
2020
* The portable half — every branch of the policy — is Tier UG.
2121
*/
22-
import { beforeAll, describe, it } from "@executablemd/test-support/bdd";
22+
import { beforeAll, beforeEach, describe, it } from "@executablemd/test-support/bdd";
23+
import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal";
2324
import { expect } from "@executablemd/test-support/expect";
2425
import { call, createContext, ensure, scoped, sleep, spawn, until } from "effection";
2526
import type { Operation, Result } from "effection";
@@ -54,9 +55,8 @@ import type {
5455
UpgradeResponse,
5556
} from "../src/compiled-upgrade.ts";
5657
import { releaseTargetFor, RELEASE_TARGETS } from "../src/release-targets.ts";
57-
import { runUpgrade } from "../src/upgrade.ts";
58+
import { runUpgrade, UPGRADE_COMMAND_IDENTITY } from "../src/upgrade.ts";
5859
import type { UpgradeAssembly, UpgradeCommand } from "../src/upgrade.ts";
59-
import { InMemoryStream } from "@executablemd/durable-streams";
6060

6161
/**
6262
* The exit continuation `exit()` reaches for. `main()` installs one under this
@@ -78,6 +78,7 @@ const DELIVERY = "https://release-assets.githubusercontent.com/xmd";
7878
* executed: the candidate this suite stages is a real script the host runs.
7979
*/
8080
const PLATFORM = { platform: "linux", architecture: "x64" };
81+
const OWNER = "packages/cli/tests/compiled-upgrade.test.ts";
8182
const TARGET = "x86_64-unknown-linux-gnu";
8283
const ASSET = `xmd-${TARGET}`;
8384
const INSTALLED = "0.10.2";
@@ -244,16 +245,16 @@ function scripted(routes: Record<string, Route>, requested: string[]) {
244245
* The cases below are about what happens to the installation, not about what
245246
* the reader sees; Tier UG owns the transcript.
246247
*/
247-
function upgradeWith(assembly: UpgradeAssembly): Operation<Result<void>> {
248-
return runUpgrade({
248+
function* upgradeWith(assembly: UpgradeAssembly): Operation<Result<void>> {
249+
return yield* runUpgrade({
249250
command: {
250251
requestedTag: null,
251252
status: false,
252253
allowDowngrade: false,
253254
allowPrerelease: false,
254255
},
255256
assembly,
256-
stream: new InMemoryStream(),
257+
stream: yield* useJournalStream(UPGRADE_COMMAND_IDENTITY),
257258
// deno-lint-ignore require-yield
258259
*consume() {},
259260
});
@@ -307,7 +308,7 @@ function* run(options: Attempt, dir: string, exe: string): Operation<Outcome> {
307308
...options.command,
308309
},
309310
assembly,
310-
stream: new InMemoryStream(),
311+
stream: yield* useJournalStream(UPGRADE_COMMAND_IDENTITY),
311312
// deno-lint-ignore require-yield
312313
*consume(chunk) {
313314
chunks.push(chunk);
@@ -343,6 +344,7 @@ describe(
343344
"Tier UH — the compiled upgrade host",
344345
{ sanitizeOps: false, sanitizeResources: false },
345346
() => {
347+
beforeEach(journalBeforeEach(OWNER));
346348
beforeAll(() => useTempFileCompiler());
347349

348350
it("UH1: every platform maps to the exact artifact the release publishes", function* () {

‎packages/cli/tests/plan-component.test.ts‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
* created. No live agent, browser, or network belongs in this evidence.
1414
*/
1515

16-
import { describe, it } from "@executablemd/test-support/bdd";
16+
import { beforeEach, describe, it } from "@executablemd/test-support/bdd";
17+
import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal";
1718
import { expect } from "@executablemd/test-support/expect";
1819
import { ensure, scoped, spawn, suspend, until, withResolvers } from "effection";
1920
import type { Operation } from "effection";
@@ -64,6 +65,7 @@ function* raised<T>(operation: Operation<T>): Operation<string> {
6465
}
6566

6667
const ROOT = "document.md";
68+
const OWNER = "packages/cli/tests/plan-component.test.ts";
6769

6870
/** A Plan the coding agent replies with, and that admission accepts. */
6971
const PLAN = ["# Say hello", "", "This document greets you.", "", "Hello.", ""].join("\n");
@@ -149,7 +151,7 @@ function* runDocument(options: {
149151
normalized?: boolean;
150152
}): Operation<Run> {
151153
const root = options.root ?? (yield* planWriterRoot());
152-
const stream = options.stream ?? new InMemoryStream();
154+
const stream = options.stream ?? (yield* useJournalStream(ROOT));
153155
const harness =
154156
options.harness ??
155157
(yield* planDeclarationHarness({
@@ -262,6 +264,8 @@ function isPrompt(event: DurableEvent): boolean {
262264
}
263265

264266
describe("Tier PC — <Plan> in an ordinary document", () => {
267+
beforeEach(journalBeforeEach(OWNER));
268+
265269
it("PC1: the body is the Prompt, and the approved bytes arrive under `as`", function* () {
266270
yield* useWorkingDirectory(function* (dir) {
267271
// A file only the caller's permissions can read, written into the Prompt.
@@ -379,6 +383,7 @@ describe("Tier PC — <Plan> in an ordinary document", () => {
379383
source: ['<Plan as="approved"> </Plan>', ""].join("\n"),
380384
root,
381385
reviews: [],
386+
stream: new InMemoryStream(),
382387
});
383388

384389
expect(run.failure).toContain("<Plan> requires its body to render a non-empty Prompt.");
@@ -414,6 +419,7 @@ describe("Tier PC — <Plan> in an ordinary document", () => {
414419
source: ['<Plan as="approved">Write a program.</Plan>', ""].join("\n"),
415420
root,
416421
reviews: [],
422+
stream: new InMemoryStream(),
417423
stack: {
418424
provider: "not-acpx",
419425
defaultAgent: AGENT,
@@ -447,6 +453,7 @@ describe("Tier PC — <Plan> in an ordinary document", () => {
447453
const run = yield* runDocument({
448454
source: [`<${name} as="x" />`, ""].join("\n"),
449455
reviews: [],
456+
stream: new InMemoryStream(),
450457
});
451458
expect(run.failure).toContain(`Cannot resolve component: ${name}`);
452459
}
@@ -456,6 +463,7 @@ describe("Tier PC — <Plan> in an ordinary document", () => {
456463
const open = yield* runDocument({
457464
source: ['<Syntax as="x" />', "{x}", ""].join("\n"),
458465
reviews: [],
466+
stream: new InMemoryStream(),
459467
});
460468
expect(open.failure).toBeUndefined();
461469
expect(open.output).toContain("### `<File>`");
@@ -625,6 +633,7 @@ describe("Tier PC — <Plan> in an ordinary document", () => {
625633
files: ([operation], next) => (operation === "read" ? false : next(operation)),
626634
});
627635
},
636+
stream: new InMemoryStream(),
628637
});
629638

630639
// Authorship finished: the refusal was feedback rather than a failure.
@@ -804,6 +813,7 @@ describe("Tier PC — <Plan> in an ordinary document", () => {
804813
reviews: [],
805814
generated: reading(),
806815
files,
816+
stream: new InMemoryStream(),
807817
}),
808818
),
809819
);
@@ -961,6 +971,7 @@ describe("Tier PC — <Plan> in an ordinary document", () => {
961971
reviews: [],
962972
generated: reading(),
963973
files: files,
974+
stream: new InMemoryStream(),
964975
});
965976

966977
expect(run.failure).toBe(undefined);
@@ -1229,6 +1240,7 @@ describe("Tier PC — <Plan> in an ordinary document", () => {
12291240
source: ['<CheckDraft source="x" as="check" />', ""].join("\n"),
12301241
includes: [dir],
12311242
reviews: [],
1243+
stream: new InMemoryStream(),
12321244
});
12331245
expect(run.failure).toContain("Cannot resolve component: CheckDraft");
12341246
expect(run.output).not.toContain("the repository file ran.");
@@ -1388,6 +1400,7 @@ describe("Tier PC — <Plan> in an ordinary document", () => {
13881400
source: ['<Plan as="approved">Write a program.</Plan>', ""].join("\n"),
13891401
reply: PLAN,
13901402
reviews: ["Stop"],
1403+
stream: new InMemoryStream(),
13911404
});
13921405

13931406
expect(run.failure).toBe("Plan authorship stopped at your request. No Plan was returned.");
@@ -1977,6 +1990,8 @@ describe("Tier PC — <Plan> in an ordinary document", () => {
19771990
* type either of them shares.
19781991
*/
19791992
describe("Tier FE — Plan produces text, Evaluate runs it", () => {
1993+
beforeEach(journalBeforeEach(OWNER));
1994+
19801995
/** One selected read, over a recorder these rows can count. */
19811996
function profile(): GeneratedSelection {
19821997
return { File: ["self-closing"] };
@@ -2318,6 +2333,8 @@ describe("Tier FE — Plan produces text, Evaluate runs it", () => {
23182333
* declaration they are — which an execution reads before it admits either.
23192334
*/
23202335
describe("Tier MDK — the Plan declarations state their kind", () => {
2336+
beforeEach(journalBeforeEach(OWNER));
2337+
23212338
it("MDK2: both constructors state kind component for the same packaged bytes", function* () {
23222339
yield* useWorkingDirectory(function* (dir) {
23232340
const harness = yield* planDeclarationHarness({

0 commit comments

Comments
 (0)