Skip to content

Commit 21c930a

Browse files
authored
Attribute native Agent document test journals (#1382)
1 parent c084b7c commit 21c930a

3 files changed

Lines changed: 33 additions & 11 deletions

File tree

‎packages/acp/tests/loaded-copy.test.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
* provider's own copy every one of those values is foreign — exactly as a
2222
* canonical request is to a provider loaded with another copy.
2323
*/
24-
import { describe, it } from "@executablemd/test-support/bdd";
24+
import { beforeEach, describe, it } from "@executablemd/test-support/bdd";
2525
import { expect } from "@executablemd/test-support/expect";
26+
import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal";
2627
import { ensure, resource, scoped, until } from "effection";
2728
import type { Operation, Result } from "effection";
2829
import { ensureDir, rm, writeTextFile } from "@effectionx/fs";
@@ -588,6 +589,8 @@ function useForeignPublicConsumer(): Operation<
588589
}
589590

590591
describe("Session information", { sanitizeOps: false, sanitizeResources: false }, () => {
592+
beforeEach(journalBeforeEach("packages/acp/tests/loaded-copy.test.ts"));
593+
591594
it("SI: a separate Core's public configured first started event observes native confirmation", function* () {
592595
const run = yield* useForeignPublicConsumer();
593596
const current = yield* world(true);
@@ -629,7 +632,7 @@ describe("Session information", { sanitizeOps: false, sanitizeResources: false }
629632
},
630633
},
631634
});
632-
const journal = new InMemoryStream();
635+
const journal = yield* useJournalStream(doc);
633636
yield* scoped(function* () {
634637
yield* run(factory, doc, journal, function* (stage, session, configuration) {
635638
if (stage === "resolved") {

‎packages/acp/tests/released-runtime.test.ts‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { describe, it } from "@executablemd/test-support/bdd";
1+
import { beforeEach, describe, it } from "@executablemd/test-support/bdd";
22
import { expect } from "@executablemd/test-support/expect";
3+
import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal";
34
import {
45
scoped,
56
allSettled,
@@ -57,6 +58,8 @@ import Capture, {
5758
props as captureProps,
5859
} from "../../../examples/adversarial-implementation/components/Ticket/Capture.ts";
5960

61+
const OWNER = "packages/acp/tests/released-runtime.test.ts";
62+
6063
function* runtimeWorld() {
6164
const current = yield* world();
6265
const runtime = createAcpRuntime({
@@ -78,6 +81,7 @@ function* runtimeWorld() {
7881
}
7982

8083
describe("Session information", { sanitizeOps: false, sanitizeResources: false }, () => {
84+
beforeEach(journalBeforeEach(OWNER));
8185
it("SI: standard public configured sessions retain loading identity through close and load", function* () {
8286
const current = yield* world(true);
8387
yield* writeTextFile(current.agent, STANDARD_AGENT_SOURCE);
@@ -184,7 +188,7 @@ describe("Session information", { sanitizeOps: false, sanitizeResources: false }
184188
`<Agent name="scribe"><Session name="review" model="selected" effort="xhigh"><Prompt text="${text}" /></Session></Agent>`,
185189
);
186190
yield* useNormalizedOutput();
187-
const journal = new InMemoryStream();
191+
const journal = yield* useJournalStream(doc);
188192
const execution = yield* executeInstalled({ path: doc, stream: journal }, [
189193
{ components: agentIdentityComponents() },
190194
]);
@@ -249,6 +253,8 @@ describe(
249253
"Unconfirmed Session information",
250254
{ sanitizeOps: false, sanitizeResources: false },
251255
() => {
256+
beforeEach(journalBeforeEach(OWNER));
257+
252258
it("a real strong first attempt without acceptance exposes no identity or started event", function* () {
253259
const current = yield* world(true);
254260
let retained = 0;
@@ -314,7 +320,8 @@ describe(
314320
doc,
315321
'<Agent name="scribe"><Session name="uncertain" model="selected"><Prompt text="no-accept" /></Session></Agent>',
316322
);
317-
const execution = yield* executeInstalled({ path: doc, stream: new InMemoryStream() }, [
323+
const journal = yield* useJournalStream(doc);
324+
const execution = yield* executeInstalled({ path: doc, stream: journal }, [
318325
{ components: agentIdentityComponents() },
319326
]);
320327
const output = yield* execution.output;
@@ -346,6 +353,8 @@ describe(
346353
"released ACPX production consumers",
347354
{ sanitizeOps: false, sanitizeResources: false },
348355
() => {
356+
beforeEach(journalBeforeEach(OWNER));
357+
349358
it("workflow role deny lists and environment survive a cold session reopen", function* () {
350359
const current = yield* world();
351360
const controls = {
@@ -513,7 +522,7 @@ describe(
513522
);
514523
expect(yield* retainedSession(current.store, "provider")).toBe(undefined);
515524
yield* useNormalizedOutput();
516-
const journal = new InMemoryStream();
525+
const journal = yield* useJournalStream(doc);
517526
const execution = yield* executeInstalled({ path: doc, stream: journal }, [
518527
{ components: agentIdentityComponents() },
519528
]);
@@ -1158,6 +1167,8 @@ describe(
11581167
"resume retention: standard retained-session refusal",
11591168
{ sanitizeOps: false, sanitizeResources: false },
11601169
() => {
1170+
beforeEach(journalBeforeEach(OWNER));
1171+
11611172
for (const [failure, stage, detail] of [
11621173
["fail-load", "runtime-turn", "Release the active writer before reconnecting."],
11631174
["fail-load", "runtime-turn", undefined],
@@ -1281,7 +1292,7 @@ describe(
12811292
: `<Agent name="scribe"><Session name="review"><Prompt text="${text}" /></Session></Agent>`,
12821293
);
12831294
yield* useNormalizedOutput();
1284-
const journal = new InMemoryStream();
1295+
const journal = yield* useJournalStream(doc);
12851296
const execution = yield* executeInstalled({ path: doc, stream: journal }, [
12861297
{ components: agentIdentityComponents() },
12871298
]);

‎packages/agent/tests/agent-session-launch.test.ts‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
* child — so the ordering, the retained records and the refusals are the
1010
* production ones, with only the provider's own product replaced.
1111
*/
12-
import { describe, it } from "@executablemd/test-support/bdd";
12+
import { beforeEach, describe, it } from "@executablemd/test-support/bdd";
1313
import { expect } from "@executablemd/test-support/expect";
14+
import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal";
1415
import { InMemoryStream } from "@executablemd/durable-streams";
1516
import type { DurableEvent } from "@executablemd/durable-streams";
1617
import { ensure, scoped, spawn, until, withResolvers } from "effection";
@@ -51,6 +52,7 @@ import type { NativeLaunchOutcome, NativeLaunchRequest } from "@executablemd/run
5152
import type { Json } from "../../core/src/types.ts";
5253

5354
const ALPHABET = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
55+
const OWNER = "packages/agent/tests/agent-session-launch.test.ts";
5456

5557
/** A synthetic GitHub token, format-realistic and assembled here. */
5658
const CANARY = ["ghp", "_", ALPHABET.slice(0, 36)].join("");
@@ -367,7 +369,6 @@ interface Run {
367369
function* runDoc(doc: string, options: RunOptions = {}): Operation<Run> {
368370
const stub = options.stub ?? createLaunchStub();
369371
const launcher: LauncherLog = { reserved: 0, flushed: 0, requests: [], notices: [], order: [] };
370-
const stream = options.stream ?? new InMemoryStream();
371372
const owned = options.dir === undefined;
372373
const dir = options.dir ?? path.join(os.tmpdir(), `xmd-sl-${randomUUID()}`);
373374
yield* ensureDir(dir);
@@ -382,6 +383,7 @@ function* runDoc(doc: string, options: RunOptions = {}): Operation<Run> {
382383
}
383384
const docPath = path.join(dir, "doc.md");
384385
yield* writeTextFile(docPath, doc);
386+
const stream = options.stream ?? (yield* useJournalStream(docPath));
385387
// The document's own directory is the contextual cwd, so an authored
386388
// relative path resolves the way it would for someone running xmd there.
387389
yield* API.Env.around({
@@ -562,6 +564,7 @@ function retainedPhases(events: DurableEvent[]): string[] {
562564
const LAUNCH = "<Session.Launch>\nYou are the implementor.\n</Session.Launch>\n";
563565

564566
describe("Tier SL — native session launch", () => {
567+
beforeEach(journalBeforeEach(OWNER));
565568
it("SL1: without a provider the launch fails, and nothing is reserved or spawned", function* () {
566569
const launcher: LauncherLog = { reserved: 0, flushed: 0, requests: [], notices: [], order: [] };
567570
const dir = path.join(os.tmpdir(), `xmd-sl-${randomUUID()}`);
@@ -576,7 +579,7 @@ describe("Tier SL — native session launch", () => {
576579
// Registered, but with no root provider: `prompt()` and `launch()` alike
577580
// fall through to the base handlers.
578581
yield* installAgentComponents();
579-
const execution = yield* execute({ path: docPath, stream: new InMemoryStream() });
582+
const execution = yield* execute({ path: docPath, stream: yield* useJournalStream(docPath) });
580583
const subscription = yield* execution.output;
581584
let next = yield* subscription.next();
582585
while (!next.done) {
@@ -620,7 +623,7 @@ describe("Tier SL — native session launch", () => {
620623
options: { defaultAgent: "stub-agent", permissionMode: "deny-all" },
621624
},
622625
});
623-
const execution = yield* execute({ path: docPath, stream: new InMemoryStream() });
626+
const execution = yield* execute({ path: docPath, stream: yield* useJournalStream(docPath) });
624627
const subscription = yield* execution.output;
625628
let next = yield* subscription.next();
626629
while (!next.done) {
@@ -937,6 +940,7 @@ describe("Tier SL — native session launch", () => {
937940
* managed to return.
938941
*/
939942
describe("Tier FS — the final public launch surface", () => {
943+
beforeEach(journalBeforeEach(OWNER));
940944
it("FS1: middleware that returns a completion without delegating settles nothing", function* () {
941945
// The original exploit, on the surface that replaced it. The handler sees
942946
// the request, does not pass it on, and answers with a complete-looking
@@ -1448,6 +1452,7 @@ const OWED: MaterializationPlan = {
14481452
};
14491453

14501454
describe("Tier MR — retaining and replaying the materialization turn", () => {
1455+
beforeEach(journalBeforeEach(OWNER));
14511456
function owing(overrides: Partial<LaunchStub> = {}): LaunchStub {
14521457
return createLaunchStub({ materialization: OWED, ...overrides });
14531458
}
@@ -1763,6 +1768,7 @@ const CONFIGURED_LAUNCH = [
17631768
].join("\n");
17641769

17651770
describe("Tier SC — configured native launch", () => {
1771+
beforeEach(journalBeforeEach(OWNER));
17661772
it("SC1: the routed use and the retained preparation carry the same two values", function* () {
17671773
const run = yield* runDoc(CONFIGURED_LAUNCH, { declareSession: true });
17681774

@@ -1834,6 +1840,7 @@ describe("Tier SC — configured native launch", () => {
18341840
* that route rather than the element the launch was written inside.
18351841
*/
18361842
describe("Tier SC — the final routed Session decides a launch", () => {
1843+
beforeEach(journalBeforeEach(OWNER));
18371844
it("SC20: narrowing the request to the raw session runs unconfigured", function* () {
18381845
const run = yield* runDoc(CONFIGURED_LAUNCH, {
18391846
declareSession: true,
@@ -1990,6 +1997,7 @@ describe("Tier SJ — configuration in a retained preparation", () => {
19901997
* these rows own is the durable sequence around it.
19911998
*/
19921999
describe("Tier SR — configured launch replay", () => {
2000+
beforeEach(journalBeforeEach(OWNER));
19932001
it("SR1: a provider that cannot configure the conversation stops at the preparation", function* () {
19942002
const run = yield* runDoc(CONFIGURED_LAUNCH, {
19952003
declareSession: true,

0 commit comments

Comments
 (0)