Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@durable-streams/server": "npm:@durable-streams/server@^0.3.8",
"@executablemd/test-support/bdd": "./packages/test-support/bdd.ts",
"@executablemd/test-support/expect": "./packages/test-support/expect.ts",
"@executablemd/test-support/failure-journal": "./packages/test-support/failure-journal.ts",
"@executablemd/test-support/journal": "./packages/test-support/journal.ts",
"@executablemd/test-support/launch": "./packages/test-support/launch.ts",
"@effectionx/test-adapter": "npm:@effectionx/test-adapter@0.7.4",
Expand Down
27 changes: 19 additions & 8 deletions packages/acp/tests/acceptance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* `rootProvider` seam drives the full Agent → session → prompt → teardown
* lifecycle. Fake ACPX runtime, no subprocess.
*/
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 } from "effection";
import { ensureDir, rm, writeTextFile } from "@effectionx/fs";
Expand All @@ -14,10 +14,11 @@ import { Agent } from "@executablemd/agent/api";
import { agentIdentityComponents, installAgentComponents } from "@executablemd/agent/host";
import { executeInstalled } from "@executablemd/core/host";
import type { AgentSessionRequest } from "@executablemd/agent/api";
import { InMemoryStream } from "@executablemd/durable-streams";
import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal";
import { createAcpxProvider } from "../mod.ts";
import { createFakeRuntime, makeRegistry, makeStore, useFlatWorld } from "./helpers.ts";

const OWNER = "packages/acp/tests/acceptance.test.ts";
const CWD = "/work";
const DOC = [
'<Agent name="gemini">',
Expand All @@ -29,7 +30,9 @@ const DOC = [
].join("\n");

describe("Tier XA — ACPX provider through the rootProvider seam", () => {
it("XA1: agent availability → session → normalized prompt → structured teardown", function* () {
beforeEach(journalBeforeEach(OWNER));
const lifecycle = "XA1: agent availability → session → normalized prompt → structured teardown";
it(lifecycle, function* () {
const harness = createFakeRuntime();
const dir = path.join(os.tmpdir(), `xmd-acp-accept-${randomUUID()}`);
yield* ensureDir(dir);
Expand All @@ -38,6 +41,7 @@ describe("Tier XA — ACPX provider through the rootProvider seam", () => {
const docPath = path.join(dir, "doc.md");
yield* writeTextFile(docPath, DOC);

const stream = yield* useJournalStream(docPath);
const result = yield* scoped(function* () {
yield* useFlatWorld(CWD);
yield* installAgentComponents({
Expand All @@ -53,7 +57,7 @@ describe("Tier XA — ACPX provider through the rootProvider seam", () => {

// `<Session>` names durable work after its own invocation, so the host
// declares it to the execution rather than registering it.
const execution = yield* executeInstalled({ path: docPath, stream: new InMemoryStream() }, [
const execution = yield* executeInstalled({ path: docPath, stream }, [
{ components: agentIdentityComponents() },
]);
const subscription = yield* execution.output;
Expand Down Expand Up @@ -89,7 +93,10 @@ describe("Tier XA — ACPX provider through the rootProvider seam", () => {
* through the coordinator delivered to this provider.
*/
describe("Tier WAP — same-named sibling Sessions", () => {
it('WAP7: two sibling <Session name="review"> sites name two identities the middleware cannot touch', function* () {
beforeEach(journalBeforeEach(OWNER));
const siblings =
'WAP7: two sibling <Session name="review"> sites name two identities the middleware cannot touch';
it(siblings, function* () {
const harness = createFakeRuntime();
const requests: Array<{ session: string | undefined; sessionIdentity?: string }> = [];
/** The session keys this host was asked to retain, in order. */
Expand All @@ -115,6 +122,7 @@ describe("Tier WAP — same-named sibling Sessions", () => {
].join("\n"),
);

const stream = yield* useJournalStream(docPath);
yield* scoped(function* () {
yield* useFlatWorld(CWD);
yield* installAgentComponents({
Expand Down Expand Up @@ -165,7 +173,7 @@ describe("Tier WAP — same-named sibling Sessions", () => {

// `<Session>` names durable work after its own invocation, so the host
// declares it to the execution rather than registering it.
const execution = yield* executeInstalled({ path: docPath, stream: new InMemoryStream() }, [
const execution = yield* executeInstalled({ path: docPath, stream }, [
{ components: agentIdentityComponents() },
]);
const subscription = yield* execution.output;
Expand Down Expand Up @@ -194,7 +202,9 @@ describe("Tier WAP — same-named sibling Sessions", () => {
expect(recorded).toEqual(requests.map((request) => `session:${request.sessionIdentity}`));
});

it("WAP7: a request kept from the first Session cannot be routed for the second", function* () {
const retainedRequest =
"WAP7: a request kept from the first Session cannot be routed for the second";
it(retainedRequest, function* () {
const harness = createFakeRuntime();
const requests: Array<string | undefined> = [];
/** The session keys this host was asked to retain, in order. */
Expand All @@ -221,6 +231,7 @@ describe("Tier WAP — same-named sibling Sessions", () => {
].join("\n"),
);

const stream = yield* useJournalStream(docPath);
yield* scoped(function* () {
yield* useFlatWorld(CWD);
yield* installAgentComponents({
Expand Down Expand Up @@ -267,7 +278,7 @@ describe("Tier WAP — same-named sibling Sessions", () => {

// `<Session>` names durable work after its own invocation, so the host
// declares it to the execution rather than registering it.
const execution = yield* executeInstalled({ path: docPath, stream: new InMemoryStream() }, [
const execution = yield* executeInstalled({ path: docPath, stream }, [
{ components: agentIdentityComponents() },
]);
const subscription = yield* execution.output;
Expand Down
67 changes: 42 additions & 25 deletions packages/agent/tests/agent-components.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* `installAgentComponents`'s `rootProvider` seam — no real provider,
* subprocess, or provider selection.
*/
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 { ensure, scoped } from "effection";
Expand All @@ -28,6 +28,9 @@ import type { AgentProviderFactory } from "../src/provider-api.ts";
import { installAgentComponents } from "../src/components.ts";
import { Component } from "../../core/src/component-api.ts";
import type { Json } from "@executablemd/core";
import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal";

const OWNER = "packages/agent/tests/agent-components.test.ts";

interface StubResponse {
status?: "completed" | "failed" | "cancelled";
Expand Down Expand Up @@ -102,7 +105,11 @@ function createStubStream(
sessionKey: `stub:${typeof options?.session === "string" ? options.session : "default"}`,
cwd: "/stub",
};
const call: StubPromptCall = { content, agent, sessionKey: session.sessionKey };
const call: StubPromptCall = {
content,
agent,
sessionKey: session.sessionKey,
};
if (options?.timeout !== undefined) {
call.timeout = options.timeout;
}
Expand Down Expand Up @@ -146,15 +153,16 @@ function* installStub(stub: Stub): Operation<void> {

function* runDoc(
doc: string,
stream: InMemoryStream,
providedStream?: InMemoryStream,
dir = path.join(os.tmpdir(), `xmd-ac-test-${randomUUID()}`),
): Operation<{ output: string; result: Result<Json> }> {
const dir = path.join(os.tmpdir(), `xmd-ac-test-${randomUUID()}`);
yield* ensureDir(dir);
return yield* scoped(function* () {
yield* ensure(() => rm(dir, { recursive: true, force: true }));

const docPath = path.join(dir, "doc.md");
yield* writeTextFile(docPath, doc);
const stream = providedStream ?? (yield* useJournalStream(docPath));
// `<Session>` names durable work after its own invocation, so the host
// declares it to the execution rather than registering it.
const execution = yield* executeInstalled({ path: docPath, stream }, [
Expand All @@ -170,14 +178,14 @@ function* runDoc(
});
}

describe("Tier AC — agent components", () => {
const SUITE = "Tier AC — agent components";

describe(SUITE, () => {
beforeEach(journalBeforeEach(OWNER));
it("AC1: wrapper <Prompt> always sends rendered children, untrimmed", function* () {
const stub = createStubProvider();
yield* installStub(stub);
const { output, result } = yield* runDoc(
'<Prompt text="fallback">\nSay hello\n</Prompt>\n',
new InMemoryStream(),
);
const { output, result } = yield* runDoc('<Prompt text="fallback">\nSay hello\n</Prompt>\n');
expect(result.ok).toBe(true);
expect(stub.promptCalls.length).toBe(1);
const sent = stub.promptCalls[0]!.content;
Expand All @@ -190,7 +198,7 @@ describe("Tier AC — agent components", () => {
it("AC2: empty wrapper children win over the text prop", function* () {
const stub = createStubProvider();
yield* installStub(stub);
const { result } = yield* runDoc('<Prompt text="fallback"></Prompt>\n', new InMemoryStream());
const { result } = yield* runDoc('<Prompt text="fallback"></Prompt>\n');
expect(result.ok).toBe(true);
expect(stub.promptCalls.length).toBe(1);
expect(stub.promptCalls[0]!.content).toBe("");
Expand All @@ -199,7 +207,7 @@ describe("Tier AC — agent components", () => {
it("AC3: self-closing <Prompt> falls back to the text prop", function* () {
const stub = createStubProvider();
yield* installStub(stub);
const { output, result } = yield* runDoc('<Prompt text="hello" />\n', new InMemoryStream());
const { output, result } = yield* runDoc('<Prompt text="hello" />\n');
expect(result.ok).toBe(true);
expect(stub.promptCalls[0]!.content).toBe("hello");
expect(output).toContain("[stub-agent:stub:default:hello]");
Expand All @@ -212,7 +220,7 @@ describe("Tier AC — agent components", () => {
it("AC19: the removed prompt prop is rejected as an unknown prop", function* () {
const stub = createStubProvider();
yield* installStub(stub);
const { result } = yield* runDoc('<Prompt prompt="hello" />\n', new InMemoryStream());
const { result } = yield* runDoc('<Prompt prompt="hello" />\n');
expect(result.ok).toBe(false);
expect(stub.promptCalls.length).toBe(0);
const reported = result.ok ? "" : result.error.message;
Expand All @@ -232,10 +240,7 @@ describe("Tier AC — agent components", () => {
});
// Written in a region that prints, because what this pins is that the
// diagnostic is observed once and rendered once — which needs it rendered.
const { output } = yield* runDoc(
'<PrintErrors>\n<Prompt prompt="hello" />\n</PrintErrors>\n',
new InMemoryStream(),
);
const { output } = yield* runDoc('<PrintErrors>\n<Prompt prompt="hello" />\n</PrintErrors>\n');
expect(observed).toHaveLength(1);
expect(observed[0]).toContain("Prop validation failed for <Prompt />");
expect(output.match(/<Prompt \/>/g)).toHaveLength(1);
Expand Down Expand Up @@ -278,7 +283,6 @@ describe("Tier AC — agent components", () => {
yield* installStub(stub);
const { output, result } = yield* runDoc(
'<Prompt text="hi" as="answer" />\n\nCaptured: {answer}\n',
new InMemoryStream(),
);
expect(result.ok).toBe(true);
expect(output).toContain("Captured: [stub-agent:stub:default:hi]");
Expand All @@ -298,7 +302,7 @@ describe("Tier AC — agent components", () => {
'<Prompt text="two" agent="agent-three" session="named" timeout="500ms" />',
"",
].join("\n");
const { result } = yield* runDoc(doc, new InMemoryStream());
const { result } = yield* runDoc(doc);
expect(result.ok).toBe(true);
expect(stub.promptCalls.length).toBe(2);
expect(stub.promptCalls[0]).toMatchObject({
Expand All @@ -319,7 +323,6 @@ describe("Tier AC — agent components", () => {
yield* installStub(stub);
const { output, result } = yield* runDoc(
'<Agent name="probe-me" />\n<Session name="warm" />\nplain text\n',
new InMemoryStream(),
);
expect(result.ok).toBe(true);
expect(stub.agentProbes).toContain("probe-me");
Expand All @@ -331,7 +334,11 @@ describe("Tier AC — agent components", () => {
it("AC7: failed prompts render partial text, later content runs, completion aggregates in order", function* () {
const stub = createStubProvider((content) => {
if (content.includes("first-fail")) {
return { status: "failed", stopReason: "max_tokens", deltas: ["partial-one "] };
return {
status: "failed",
stopReason: "max_tokens",
deltas: ["partial-one "],
};
}
if (content.includes("second-fail")) {
return { status: "failed", stopReason: "refusal", deltas: [] };
Expand All @@ -349,7 +356,7 @@ describe("Tier AC — agent components", () => {
"after all prompts",
"",
].join("\n");
const { output, result } = yield* runDoc(doc, new InMemoryStream());
const { output, result } = yield* runDoc(doc);
expect(output).toContain("partial-one");
expect(output).toContain("after all prompts");
expect(result.ok).toBe(false);
Expand All @@ -371,11 +378,13 @@ describe("Tier AC — agent components", () => {
});

it("AC8: throwOnError aborts the document immediately", function* () {
const stub = createStubProvider(() => ({ status: "failed", stopReason: "refusal" }));
const stub = createStubProvider(() => ({
status: "failed",
stopReason: "refusal",
}));
yield* installStub(stub);
const { output, result } = yield* runDoc(
'<Prompt text="boom" throwOnError />\n\nnever reached\n',
new InMemoryStream(),
);
expect(result.ok).toBe(false);
if (!result.ok) {
Expand Down Expand Up @@ -505,7 +514,11 @@ describe("Tier AC — agent components", () => {
yield* stream.append({
type: "yield",
coroutineId: "root.0",
description: { type: "agent_prompt", name: "prompt:doc.md:1:1#0", input: "a" },
description: {
type: "agent_prompt",
name: "prompt:doc.md:1:1#0",
input: "a",
},
result: {
status: "ok",
value: {
Expand All @@ -523,7 +536,11 @@ describe("Tier AC — agent components", () => {
yield* stream.append({
type: "yield",
coroutineId: "root.1",
description: { type: "agent_prompt", name: "prompt:doc.md:2:1#0", input: "b" },
description: {
type: "agent_prompt",
name: "prompt:doc.md:2:1#0",
input: "b",
},
result: {
status: "ok",
value: {
Expand Down
Loading
Loading