Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

[5/6] test(eve): add tool approval rules to the HITL conformance suite (#4166)

Ben Pankow26e30713e3d3
diff --git a/packages/eve/src/internal/testing/channel-conformance/conformance.ts b/packages/eve/src/internal/testing/channel-conformance/conformance.ts
new file mode 100644
index 000000000..434484cce
--- /dev/null
+++ b/packages/eve/src/internal/testing/channel-conformance/conformance.ts
@@ -0,0 +1,153 @@
+import { describe, expect, it } from "vitest";
+
+import { type HitlRule, hitlContract } from "#internal/testing/channel-conformance/contract.js";
+import {
+ type ChannelDriver,
+ withChannelConversation,
+} from "#internal/testing/channel-conformance/harness.js";
+import {
+ chatSdkDriver,
+ chatSdkTextDriver,
+} from "#internal/testing/channel-conformance/chat-sdk-driver.js";
+import { discordDriver } from "#internal/testing/channel-conformance/discord-driver.js";
+import { githubDriver } from "#internal/testing/channel-conformance/github-driver.js";
+import { linearDriver } from "#internal/testing/channel-conformance/linear-driver.js";
+import { linqDriver } from "#internal/testing/channel-conformance/linq-driver.js";
+import { slackDriver } from "#internal/testing/channel-conformance/slack-driver.js";
+import { teamsDriver } from "#internal/testing/channel-conformance/teams-driver.js";
+import { telegramDriver } from "#internal/testing/channel-conformance/telegram-driver.js";
+import { twilioDriver } from "#internal/testing/channel-conformance/twilio-driver.js";
+
+export interface BrokenCell {
+ readonly reason: string;
+ /** Matches the error this rule fails with today. */
+ readonly symptom: RegExp;
+}
+
+interface ConformanceChannel {
+ readonly driver: () => ChannelDriver;
+ readonly broken?: Partial<Record<HitlRule, BrokenCell>>;
+}
+
+/**
+ * Every first-party channel's place in the HITL contract, keyed by the channel
+ * directory whose `hitl-conformance.integration.test.ts` runs it. Each cell is
+ * one of:
+ *
+ * - must pass;
+ * - not supported: the platform lacks a capability the rule requires (skipped);
+ * - broken: the channel should pass but doesn't yet. The cell passes only when
+ * the rule fails with the recorded `symptom`, so a fix or an unrelated
+ * failure (such as harness breakage) both turn it red.
+ */
+const hitlConformance = {
+ "chat-sdk": [
+ { driver: chatSdkDriver },
+ {
+ driver: chatSdkTextDriver,
+ broken: {
+ "a rendered question shows every option a person can choose": {
+ reason: "#3712: the card's fallback text is only the prompt",
+ symptom: /the question showed \[\]/,
+ },
+ "a tool approval shows Approve and Cancel": {
+ reason: "#3712: the card's fallback text is only the prompt",
+ symptom: /the approval showed \[\]/,
+ },
+ },
+ },
+ ],
+ discord: [{ driver: discordDriver }],
+ github: [{ driver: githubDriver }],
+ linear: [{ driver: linearDriver }],
+ linq: [{ driver: linqDriver }],
+ slack: [{ driver: slackDriver }],
+ teams: [{ driver: teamsDriver }],
+ telegram: [
+ {
+ driver: telegramDriver,
+ broken: {
+ "pressing Approve runs the gated tool": {
+ reason:
+ "#4135: a held approval checks the button's callback id before Telegram maps it to the request",
+ symptom: /Timed out waiting for deploy_release to run or be denied on telegram/,
+ },
+ "pressing Cancel stops the gated tool without running it": {
+ reason:
+ "#4135: a held approval checks the button's callback id before Telegram maps it to the request",
+ symptom: /Timed out waiting for deploy_release to run or be denied on telegram/,
+ },
+ },
+ },
+ ],
+ twilio: [
+ {
+ driver: twilioDriver,
+ broken: {
+ "a rendered question shows every option a person can choose": {
+ reason: "the channel never sends the question (no input.requested handler)",
+ symptom:
+ /Timed out waiting for the question "Which day works for the review\?" on twilio/,
+ },
+ "a text reply matching an option answers the only pending question": {
+ reason: "the channel never sends the question (no input.requested handler)",
+ symptom:
+ /Timed out waiting for the question "Which day works for the review\?" on twilio/,
+ },
+ "a tool approval shows Approve and Cancel": {
+ reason: "the channel never sends the approval (no input.requested handler)",
+ symptom: /Timed out waiting for the question "Approve Deploy release\?" on twilio/,
+ },
+ "a text reply of approve runs the gated tool": {
+ reason: "the channel never sends the approval (no input.requested handler)",
+ symptom: /Timed out waiting for the question "Approve Deploy release\?" on twilio/,
+ },
+ "a text reply of cancel stops the gated tool without running it": {
+ reason: "the channel never sends the approval (no input.requested handler)",
+ symptom: /Timed out waiting for the question "Approve Deploy release\?" on twilio/,
+ },
+ },
+ },
+ ],
+} satisfies Record<string, readonly ConformanceChannel[]>;
+
+/**
+ * A broken cell fails with its symptom, often a wait that never ends, so it gets
+ * a short wait. Real platform calls arrive in well under a second once warm.
+ */
+const BROKEN_WAIT_TIMEOUT_MS = 3_000;
+
+/**
+ * Declares the HITL contract cells for one channel directory. Each channel gets
+ * its own test file because conversations can't overlap within a process, and
+ * separate files let vitest run channels in parallel workers.
+ */
+export function describeHitlConformance(channel: keyof typeof hitlConformance): void {
+ const entries: readonly ConformanceChannel[] = hitlConformance[channel];
+ describe.each(entries.map((entry) => ({ ...entry, name: entry.driver().name })))(
+ "$name HITL contract",
+ ({ driver, broken }) => {
+ const { capabilities } = driver();
+ for (const rule of hitlContract) {
+ const supported = rule.requires.every((capability) => capabilities.includes(capability));
+ const known = broken?.[rule.rule];
+ if (!supported) {
+ it.skip(`${rule.rule} (not supported)`, () => {});
+ } else if (known === undefined) {
+ it(rule.rule, () => withChannelConversation(driver(), (c) => rule.run(c)), 60_000);
+ } else {
+ it(
+ `${rule.rule} (broken: ${known.reason})`,
+ () =>
+ expect(
+ withChannelConversation(driver(), (c) => rule.run(c), {
+ waitTimeoutMs: BROKEN_WAIT_TIMEOUT_MS,
+ }),
+ ).rejects.toThrow(known.symptom),
+ 60_000,
+ );
+ }
+ }
+ },
+ );
+}
diff --git a/packages/eve/src/internal/testing/channel-conformance/contract.ts b/packages/eve/src/internal/testing/channel-conformance/contract.ts
index ae2c79eed..0833b01b5 100644
--- a/packages/eve/src/internal/testing/channel-conformance/contract.ts
+++ b/packages/eve/src/internal/testing/channel-conformance/contract.ts
@@ -1,8 +1,9 @@
import { expect } from "vitest";
-import type {
- ChannelCapability,
- ChannelConversation,
+import {
+ type ChannelCapability,
+ type ChannelConversation,
+ GATED_TOOL,
} from "#internal/testing/channel-conformance/harness.js";
/**
@@ -27,6 +28,31 @@ async function askWhichDay(conversation: ChannelConversation) {
return await conversation.waitForQuestion(PROMPT);
}
+const DEPLOY = `Use ${GATED_TOOL} to ship the release.`;
+const APPROVAL_PROMPT = "Approve Deploy release?";
+
+async function askToDeploy(conversation: ChannelConversation) {
+ await conversation.say(DEPLOY);
+ return await conversation.waitForQuestion(APPROVAL_PROMPT);
+}
+
+async function expectDeployed(conversation: ChannelConversation) {
+ const outcome = await conversation.waitForToolOutcome(GATED_TOOL);
+ expect(outcome, `${GATED_TOOL} settled as ${JSON.stringify(outcome)}`).toEqual({
+ kind: "ran",
+ output: { deployed: true },
+ });
+ expect(conversation.gatedToolRuns).toBe(1);
+}
+
+async function expectNotDeployed(conversation: ChannelConversation) {
+ const outcome = await conversation.waitForToolOutcome(GATED_TOOL);
+ expect(outcome, `${GATED_TOOL} settled as ${JSON.stringify(outcome)}`).toEqual({
+ kind: "denied",
+ });
+ expect(conversation.gatedToolRuns).toBe(0);
+}
+
function expectAnsweredSaturday(output: unknown) {
// The message carries the real output so a broken cell's symptom can match it.
expect(output, `ask_question returned ${JSON.stringify(output)}`).toEqual({
@@ -70,6 +96,63 @@ export const hitlContract = [
expectAnsweredSaturday(await conversation.waitForToolResult("ask_question"));
},
},
+ {
+ rule: "a tool approval shows Approve and Cancel",
+ source: "docs/tools/human-in-the-loop.md#approvals",
+ requires: [],
+ async run(conversation) {
+ const options = await askToDeploy(conversation);
+ const labels = options.map((option) => option.label).sort();
+ expect(labels, `the approval showed ${JSON.stringify(labels)}`).toEqual([
+ "Approve",
+ "Cancel",
+ ]);
+ },
+ },
+ {
+ rule: "pressing Approve runs the gated tool",
+ source: "docs/tools/human-in-the-loop.md#approvals",
+ requires: ["buttons"],
+ async run(conversation) {
+ const options = await askToDeploy(conversation);
+ const approve = options.find((option) => option.label === "Approve");
+ expect(approve, "an Approve option to press").toBeDefined();
+ await conversation.press(approve!);
+ await expectDeployed(conversation);
+ },
+ },
+ {
+ rule: "pressing Cancel stops the gated tool without running it",
+ source: "docs/tools/human-in-the-loop.md#approvals",
+ requires: ["buttons"],
+ async run(conversation) {
+ const options = await askToDeploy(conversation);
+ const cancel = options.find((option) => option.label === "Cancel");
+ expect(cancel, "a Cancel option to press").toBeDefined();
+ await conversation.press(cancel!);
+ await expectNotDeployed(conversation);
+ },
+ },
+ {
+ rule: "a text reply of approve runs the gated tool",
+ source: "docs/tools/human-in-the-loop.md#how-pause-and-resume-works",
+ requires: ["text-replies"],
+ async run(conversation) {
+ await askToDeploy(conversation);
+ await conversation.say("approve");
+ await expectDeployed(conversation);
+ },
+ },
+ {
+ rule: "a text reply of cancel stops the gated tool without running it",
+ source: "docs/tools/human-in-the-loop.md#how-pause-and-resume-works",
+ requires: ["text-replies"],
+ async run(conversation) {
+ await askToDeploy(conversation);
+ await conversation.say("cancel");
+ await expectNotDeployed(conversation);
+ },
+ },
] as const satisfies readonly ContractRule[];
export type HitlRule = (typeof hitlContract)[number]["rule"];
diff --git a/packages/eve/src/internal/testing/channel-conformance/discord-driver.ts b/packages/eve/src/internal/testing/channel-conformance/discord-driver.ts
index f772043f9..793f28906 100644
--- a/packages/eve/src/internal/testing/channel-conformance/discord-driver.ts
+++ b/packages/eve/src/internal/testing/channel-conformance/discord-driver.ts
@@ -61,12 +61,12 @@ export function discordDriver(): ChannelDriver {
const body = text === "" ? {} : JSON.parse(text);
const path = new URL(request.url).pathname;
if (path.endsWith("/typing")) {
- return { body, method: "POST", response: {} };
+ return { body, method: `POST ${path}`, response: {} };
}
messageId += 1;
return {
body,
- method: request.method,
+ method: `${request.method} ${path}`,
response: { channel_id: channelId, id: `M_CONFORMANCE_${messageId}` },
};
}
@@ -101,7 +101,7 @@ export function discordDriver(): ChannelDriver {
);
},
findOptions(call, prompt) {
- if (call.method !== "PATCH") return undefined;
+ if (!isMessageWrite(call)) return undefined;
const body = call.body as {
readonly components?: readonly { readonly components?: readonly DiscordComponent[] }[];
readonly content?: string;
@@ -133,7 +133,7 @@ export function discordDriver(): ChannelDriver {
);
},
postedText(call) {
- if (call.method !== "POST" && call.method !== "PATCH") return undefined;
+ if (!isMessageWrite(call)) return undefined;
return (call.body as { readonly content?: string }).content;
},
};
@@ -153,3 +153,12 @@ function visibleChoices(component: DiscordComponent, messageId: string): Rendere
}
return [];
}
+
+/**
+ * Any call that writes a message a person sees. eve edits the interaction's
+ * original response first, then sends follow-ups, and falls back to a plain
+ * channel message when the interaction token fails.
+ */
+function isMessageWrite(call: PlatformCall): boolean {
+ return /^(PATCH|POST) /u.test(call.method) && !call.method.endsWith("/typing");
+}
diff --git a/packages/eve/src/internal/testing/channel-conformance/harness.ts b/packages/eve/src/internal/testing/channel-conformance/harness.ts
index 2059aa703..24b749c47 100644
--- a/packages/eve/src/internal/testing/channel-conformance/harness.ts
+++ b/packages/eve/src/internal/testing/channel-conformance/harness.ts
@@ -6,7 +6,11 @@ import { createTestRuntime } from "#internal/testing/app-harness.js";
import { createBundledRuntimeCompiledArtifactsSource } from "#runtime/compiled-artifacts-source.js";
import { getCompiledRuntimeAgentBundle } from "#runtime/sessions/compiled-agent-cache.js";
import type { Session } from "#channel/session.js";
+import { z } from "#compiled/zod/index.js";
+import { always } from "#tools/approval/policies.js";
+import { defineTool } from "#tools/definition.js";
import { askQuestion } from "#tools/provided/ask-question.js";
+import { getWorld } from "#internal/workflow/runtime.js";
/** One outbound call a channel made to its platform API. */
export interface PlatformCall {
@@ -74,9 +78,25 @@ export interface ChannelConversation {
press(option: RenderedOption): Promise<void>;
/** Waits until `tool` returns, as visible in the bot's reply, and returns its output. */
waitForToolResult(tool: string): Promise<unknown>;
+ /** Waits until the bot's reply shows `tool` ran or was denied. */
+ waitForToolOutcome(tool: string): Promise<ToolOutcome>;
+ /** How many times {@link GATED_TOOL} actually executed, as its side effect would show. */
+ readonly gatedToolRuns: number;
}
-const WAIT_TIMEOUT_MS = 10_000;
+/**
+ * How long to wait for a platform call. Steps finish in well under a second, so
+ * this mostly absorbs the first conversation's cold start on a busy machine.
+ */
+const WAIT_TIMEOUT_MS = 30_000;
+
+/** The test agent's tool that always needs a person's approval before it runs. */
+export const GATED_TOOL = "deploy_release";
+
+/** What a person sees once a tool call settles. */
+export type ToolOutcome =
+ | { readonly kind: "ran"; readonly output: unknown }
+ | { readonly kind: "denied" };
/** A `fetch` for an HTTP platform API: `decode` turns each request into a call and its answer. */
export function recordingFetch(
@@ -94,14 +114,18 @@ export function recordingFetch(
* Runs `body` against an agent with `ask_question` and `driver`'s channel. Every
* interaction goes through the channel's real webhook routes; the only fake is
* the platform behind the channel, usually its injected `fetch`.
+ *
+ * Conversations must not overlap: each compiles its own agent, and concurrent
+ * ones can resolve each other's compiled artifacts in the shared workflow world.
*/
export async function withChannelConversation(
driver: ChannelDriver,
body: (conversation: ChannelConversation) => Promise<void>,
+ options: { readonly waitTimeoutMs?: number } = {},
): Promise<void> {
const calls: PlatformCall[] = [];
try {
- await converse(driver, calls, body);
+ await converse(driver, calls, body, options.waitTimeoutMs ?? WAIT_TIMEOUT_MS);
} finally {
driver.dispose?.();
}
@@ -111,10 +135,12 @@ async function converse(
driver: ChannelDriver,
calls: PlatformCall[],
body: (conversation: ChannelConversation) => Promise<void>,
+ waitTimeoutMs: number,
): Promise<void> {
const created = driver.createChannel((call) => void calls.push(call));
if (!isCompiledChannel(created)) throw new Error(`${driver.name} is not a compiled channel.`);
const channel: CompiledChannel = created;
+ let gatedToolRuns = 0;
const runtime = await createTestRuntime({
agent: { name: `${driver.name}-hitl-conformance` },
@@ -123,6 +149,20 @@ async function converse(
logicalPath: "tools/ask_question.ts",
loadNamespace: async () => ({ default: askQuestion() }),
},
+ {
+ logicalPath: `tools/${GATED_TOOL}.ts`,
+ loadNamespace: async () => ({
+ default: defineTool({
+ approval: always(),
+ description: `Deploys a release. Only call when asked to use ${GATED_TOOL}.`,
+ async execute() {
+ gatedToolRuns += 1;
+ return { deployed: true };
+ },
+ inputSchema: z.object({ release: z.string().optional() }),
+ }),
+ }),
+ },
{
logicalPath: `channels/${driver.name}.ts`,
loadNamespace: async () => ({ default: channel }),
@@ -168,7 +208,7 @@ async function converse(
}
async function waitFor<T>(label: string, select: (call: PlatformCall) => T | undefined) {
- const deadline = Date.now() + WAIT_TIMEOUT_MS;
+ const deadline = Date.now() + waitTimeoutMs;
while (Date.now() < deadline) {
for (const call of calls) {
const selected = select(call);
@@ -184,28 +224,112 @@ async function converse(
const conversation: ChannelConversation = {
say: (text) => post(driver.message(text)),
press: (option) => post(driver.press(option)),
- waitForQuestion: (prompt) =>
- waitFor(`the question "${prompt}"`, (call) => driver.findOptions(call, prompt)),
+ async waitForQuestion(prompt) {
+ const options = await waitFor(`the question "${prompt}"`, (call) =>
+ driver.findOptions(call, prompt),
+ );
+ await waitForTurnToHoldForInput();
+ return options;
+ },
waitForToolResult: (tool) =>
waitFor(`${tool} to return`, (call) => {
const text = driver.postedText(call);
return text === undefined ? undefined : readMockToolReply(text, tool);
}),
+ waitForToolOutcome: (tool) =>
+ waitFor(`${tool} to run or be denied`, (call): ToolOutcome | undefined => {
+ const text = driver.postedText(call);
+ if (text === undefined) return undefined;
+ const output = readMockToolReply(text, tool);
+ if (output !== undefined) return { kind: "ran", output };
+ return isMockDenialReply(text) ? { kind: "denied" } : undefined;
+ }),
+ get gatedToolRuns() {
+ return gatedToolRuns;
+ },
};
+ /** How many times each session's turn has held for input, as of the last wait. */
+ const inputHolds = new Map<string, number>();
+
+ /**
+ * A person answers once the bot has finished asking. Answering the moment
+ * the question appears races the channel's own bookkeeping for it, such as
+ * Discord aliasing the session to the message it just posted.
+ */
+ async function waitForTurnToHoldForInput(): Promise<void> {
+ const deadline = Date.now() + waitTimeoutMs;
+ while (Date.now() < deadline) {
+ for (const session of sessions.values()) {
+ const holds = await countInputHolds(session);
+ if (holds > (inputHolds.get(session.id) ?? 0)) {
+ inputHolds.set(session.id, holds);
+ return;
+ }
+ }
+ await new Promise((resolve) => setTimeout(resolve, 25));
+ }
+ throw new Error(`Timed out waiting for the turn to hold for input on ${driver.name}.`);
+ }
+
function track(session: Session): Session {
sessions.set(session.id, session);
return session;
}
+ // The test file's workflow world closes after its last test, so a session
+ // still writing then fails with an unhandled rejection.
+ const settle = () => Promise.all([...sessions.values()].map(cancelUntilResting));
try {
await body(conversation);
- } finally {
- await Promise.allSettled([...sessions.values()].map((session) => session.cancel()));
+ } catch (error) {
+ await settle().catch(() => {});
+ throw error;
}
+ await settle();
});
}
+const TERMINAL_STEP_STATUSES = new Set(["completed", "failed", "cancelled"]);
+
+/**
+ * Cancels `session` until it waits for its next message with none of its steps
+ * still running. A turn that starts after the first cancel needs another.
+ */
+async function cancelUntilResting(session: Session): Promise<void> {
+ const world = await getWorld();
+ const deadline = Date.now() + WAIT_TIMEOUT_MS;
+ while (Date.now() < deadline) {
+ await session.cancel();
+ const tail = await session.getStreamTailIndex();
+ const reader = (await session.getEventStream({ startIndex: tail })).getReader();
+ const last = await reader.read().finally(() => reader.cancel());
+ if (last.value?.type === "session.waiting") {
+ const steps = await world.steps.list({ resolveData: "none", runId: session.id });
+ if (steps.data.every((step) => TERMINAL_STEP_STATUSES.has(step.status))) return;
+ }
+ await new Promise((resolve) => setTimeout(resolve, 25));
+ }
+ throw new Error(`Timed out waiting for session ${session.id} to rest.`);
+}
+
+async function countInputHolds(session: Session): Promise<number> {
+ const tail = await session.getStreamTailIndex();
+ if (tail < 0) return 0;
+ const reader = (await session.getEventStream({ startIndex: 0 })).getReader();
+ let holds = 0;
+ try {
+ for (let index = 0; index <= tail; index += 1) {
+ const { done, value } = await reader.read();
+ if (done) break;
+ if (value.type === "turn.waiting" && value.data.on === "input") holds += 1;
+ }
+ } finally {
+ await reader.cancel();
+ }
+ return holds;
+}
+
function findRoute(channel: CompiledChannel, request: Request) {
const { pathname } = new URL(request.url);
const route = channel.routes.find(
@@ -241,3 +365,8 @@ function readMockToolReply(text: string, tool: string): unknown {
return undefined;
}
}
+
+/** The test model reports a denied call's `execution-denied` result in its reply. */
+function isMockDenialReply(text: string): boolean {
+ return text.includes('"type":"execution-denied"');
+}
diff --git a/packages/eve/src/internal/testing/channel-conformance/slack-driver.ts b/packages/eve/src/internal/testing/channel-conformance/slack-driver.ts
index 1cc36f454..6d19f7c15 100644
--- a/packages/eve/src/internal/testing/channel-conformance/slack-driver.ts
+++ b/packages/eve/src/internal/testing/channel-conformance/slack-driver.ts
@@ -126,7 +126,12 @@ export function slackDriver(): ChannelDriver {
return undefined;
const messageTs = (call.response as { readonly ts: string }).ts;
const options = body.blocks.flatMap((block) =>
- ((block as { readonly elements?: readonly SlackElement[] }).elements ?? [])
+ // Questions use `actions` blocks (`elements`); approval cards keep buttons in `actions`.
+ (
+ (block as { readonly elements?: readonly SlackElement[] }).elements ??
+ (block as { readonly actions?: readonly SlackElement[] }).actions ??
+ []
+ )
.filter((element) => element.action_id.startsWith(HITL_ACTION_PREFIX))
.flatMap((element) => renderedOptions(element, messageTs)),
);
diff --git a/packages/eve/src/internal/testing/channel-conformance/teams-driver.ts b/packages/eve/src/internal/testing/channel-conformance/teams-driver.ts
index e96f89c5f..4c35e90f9 100644
--- a/packages/eve/src/internal/testing/channel-conformance/teams-driver.ts
+++ b/packages/eve/src/internal/testing/channel-conformance/teams-driver.ts
@@ -24,6 +24,7 @@ interface AdaptiveCard {
}[];
readonly actions?: readonly {
readonly data?: Record<string, unknown>;
+ readonly title?: string;
readonly type?: string;
}[];
}
@@ -39,7 +40,8 @@ interface ActivityBody {
interface PressHandle {
readonly data: Record<string, unknown>;
- readonly value: string;
+ /** The chosen ChoiceSet value; unset when each option is its own Submit action. */
+ readonly value?: string;
}
/** Drives Teams' Bot Framework webhook and Connector API in a personal chat. */
@@ -98,12 +100,21 @@ export function teamsDriver(): ChannelDriver {
(attachment) => attachment.contentType === "application/vnd.microsoft.card.adaptive",
)?.content;
const choiceSet = card?.body?.find((element) => element.type === "Input.ChoiceSet");
- const submit = card?.actions?.find((action) => action.type === "Action.Submit");
- const data = submit?.data;
- if (choiceSet?.choices === undefined || data === undefined) return [];
- return choiceSet.choices.map((choice) => ({
- handle: { data, value: choice.value } satisfies PressHandle,
- label: choice.title,
+ const submits = (card?.actions ?? []).filter(
+ (action) => action.type === "Action.Submit" && action.data !== undefined,
+ );
+ // A select renders one ChoiceSet and a single Submit; other choices are one Submit each.
+ if (choiceSet?.choices !== undefined) {
+ const data = submits[0]?.data;
+ if (data === undefined) return [];
+ return choiceSet.choices.map((choice) => ({
+ handle: { data, value: choice.value } satisfies PressHandle,
+ label: choice.title,
+ }));
+ }
+ return submits.map((action) => ({
+ handle: { data: action.data! } satisfies PressHandle,
+ label: action.title ?? "",
}));
},
press: (option: RenderedOption) => {
@@ -112,7 +123,7 @@ export function teamsDriver(): ChannelDriver {
id: `INVOKE-${activityId + 1}`,
name: "adaptiveCard/action",
type: "invoke",
- value: { action: { data: { ...data, eve_option: value } } },
+ value: { action: { data: value === undefined ? data : { ...data, eve_option: value } } },
});
},
postedText(call) {
diff --git a/packages/eve/src/public/channels/chat-sdk/hitl-conformance.integration.test.ts b/packages/eve/src/public/channels/chat-sdk/hitl-conformance.integration.test.ts
new file mode 100644
index 000000000..429f1a0ed
--- /dev/null
+++ b/packages/eve/src/public/channels/chat-sdk/hitl-conformance.integration.test.ts
@@ -0,0 +1,3 @@
+import { describeHitlConformance } from "#internal/testing/channel-conformance/conformance.js";
+
+describeHitlConformance("chat-sdk");
diff --git a/packages/eve/src/public/channels/discord/hitl-conformance.integration.test.ts b/packages/eve/src/public/channels/discord/hitl-conformance.integration.test.ts
new file mode 100644
index 000000000..3b21ac187
--- /dev/null
+++ b/packages/eve/src/public/channels/discord/hitl-conformance.integration.test.ts
@@ -0,0 +1,3 @@
+import { describeHitlConformance } from "#internal/testing/channel-conformance/conformance.js";
+
+describeHitlConformance("discord");
diff --git a/packages/eve/src/public/channels/discord/hitl.test.ts b/packages/eve/src/public/channels/discord/hitl.test.ts
index 8c58ffe0f..ff15530b2 100644
--- a/packages/eve/src/public/channels/discord/hitl.test.ts
+++ b/packages/eve/src/public/channels/discord/hitl.test.ts
@@ -37,31 +37,6 @@ function request(overrides?: Partial<InputRequest>): InputRequest {
}
describe("renderInputRequestComponents", () => {
- it("renders confirmation options as buttons and decodes the clicked option", () => {
- const components = renderInputRequestComponents(
- request({
- display: "confirmation",
- options: [
- { id: "approve", label: "Approve", style: "primary" },
- { id: "cancel", label: "Cancel", style: "danger" },
- ],
- }),
- );
- const firstRow = components[0] as { components: Array<{ custom_id: string }> };
- const approveCustomId = firstRow.components[0]!.custom_id;
-
- expect(
- deriveComponentInputResponses({
- ...BASE_COMPONENT,
- componentType: 2,
- customId: approveCustomId,
- messageId: "M01",
- type: 3,
- values: [],
- }),
- ).toEqual([{ optionId: "approve", requestId: "call_1" }]);
- });
-
it("renders select requests as a string select and decodes selected values", () => {
const components = renderInputRequestComponents(
request({
diff --git a/packages/eve/src/public/channels/github/githubChannel.test.ts b/packages/eve/src/public/channels/github/githubChannel.test.ts
index 8b55ba566..b5a5c848a 100644
--- a/packages/eve/src/public/channels/github/githubChannel.test.ts
+++ b/packages/eve/src/public/channels/github/githubChannel.test.ts
@@ -932,57 +932,6 @@ describe("githubChannel", () => {
);
});
- it("posts input requests through the issue comments API", async () => {
- const fetchMock = vi.fn().mockResolvedValue(new Response(JSON.stringify({ id: 77 })));
- const adapter = withState(
- getAdapter(
- githubChannel({
- api: { apiBaseUrl: "https://github.test", fetch: fetchMock },
- botName: "testbot",
- credentials: {
- installationToken: "ghs_test",
- webhookSecret: SECRET,
- },
- }),
- ),
- {
- conversationKind: "issue",
- installationId: 55,
- issueNumber: 5,
- owner: "vercel",
- repo: "eve",
- repositoryId: 123,
- },
- );
- const ctx = buildAdapterContext(adapter, stubAccessor());
-
- await callEvent(
- adapter,
- makeEvent("input.requested", {
- requests: [
- {
- action: { callId: "call_1", input: {}, kind: "tool-call", toolName: "deploy" },
- options: [
- { id: "approve", label: "Yes" },
- { id: "deny", label: "No" },
- ],
- prompt: "Approve this change?",
- requestId: "call_1",
- },
- ],
- sequence: 0,
- stepIndex: 0,
- turnId: "t1",
- }),
- ctx,
- );
-
- expect(fetchMock).toHaveBeenCalledTimes(1);
- expect(JSON.parse(String((fetchMock.mock.calls[0]![1] as RequestInit).body))).toEqual({
- body: "Approve this change?\n\n1. Yes\n2. No\n\nAnswer by mentioning me in a reply, e.g. `@testbot Yes`.",
- });
- });
-
it("renders the mention instruction from a lazy botName resolver", async () => {
const fetchMock = vi.fn().mockResolvedValue(new Response(JSON.stringify({ id: 79 })));
const adapter = withState(
diff --git a/packages/eve/src/public/channels/github/hitl-conformance.integration.test.ts b/packages/eve/src/public/channels/github/hitl-conformance.integration.test.ts
new file mode 100644
index 000000000..ea2ea3887
--- /dev/null
+++ b/packages/eve/src/public/channels/github/hitl-conformance.integration.test.ts
@@ -0,0 +1,3 @@
+import { describeHitlConformance } from "#internal/testing/channel-conformance/conformance.js";
+
+describeHitlConformance("github");
diff --git a/packages/eve/src/public/channels/hitl-conformance.integration.test.ts b/packages/eve/src/public/channels/hitl-conformance.integration.test.ts
deleted file mode 100644
index 51162122f..000000000
--- a/packages/eve/src/public/channels/hitl-conformance.integration.test.ts
+++ /dev/null
@@ -1,93 +0,0 @@
-import { describe, expect, it } from "vitest";
-
-import { type HitlRule, hitlContract } from "#internal/testing/channel-conformance/contract.js";
-import {
- type ChannelDriver,
- withChannelConversation,
-} from "#internal/testing/channel-conformance/harness.js";
-import {
- chatSdkDriver,
- chatSdkTextDriver,
-} from "#internal/testing/channel-conformance/chat-sdk-driver.js";
-import { discordDriver } from "#internal/testing/channel-conformance/discord-driver.js";
-import { githubDriver } from "#internal/testing/channel-conformance/github-driver.js";
-import { linearDriver } from "#internal/testing/channel-conformance/linear-driver.js";
-import { linqDriver } from "#internal/testing/channel-conformance/linq-driver.js";
-import { slackDriver } from "#internal/testing/channel-conformance/slack-driver.js";
-import { teamsDriver } from "#internal/testing/channel-conformance/teams-driver.js";
-import { telegramDriver } from "#internal/testing/channel-conformance/telegram-driver.js";
-import { twilioDriver } from "#internal/testing/channel-conformance/twilio-driver.js";
-
-interface BrokenCell {
- readonly reason: string;
- /** Matches the error this rule fails with today. */
- readonly symptom: RegExp;
-}
-
-/**
- * Runs the HITL contract against every registered channel driver. Each cell is one of:
- *
- * - must pass;
- * - not supported: the platform lacks a capability the rule requires (skipped);
- * - broken: the channel should pass but doesn't yet. The cell passes only when
- * the rule fails with the recorded `symptom`, so a fix or an unrelated
- * failure (such as harness breakage) both turn it red.
- */
-const channels: readonly {
- readonly driver: () => ChannelDriver;
- readonly broken?: Partial<Record<HitlRule, BrokenCell>>;
-}[] = [
- { driver: chatSdkDriver },
- {
- driver: chatSdkTextDriver,
- broken: {
- "a rendered question shows every option a person can choose": {
- reason: "#3712: the card's fallback text is only the prompt",
- symptom: /the question showed \[\]/,
- },
- },
- },
- { driver: discordDriver },
- { driver: githubDriver },
- { driver: linearDriver },
- { driver: linqDriver },
- { driver: slackDriver },
- { driver: teamsDriver },
- { driver: telegramDriver },
- {
- driver: twilioDriver,
- broken: {
- "a rendered question shows every option a person can choose": {
- reason: "the channel never sends the question (no input.requested handler)",
- symptom: /Timed out waiting for the question "Which day works for the review\?" on twilio/,
- },
- "a text reply matching an option answers the only pending question": {
- reason: "the channel never sends the question (no input.requested handler)",
- symptom: /Timed out waiting for the question "Which day works for the review\?" on twilio/,
- },
- },
- },
-];
-
-describe.each(channels.map((entry) => ({ ...entry, name: entry.driver().name })))(
- "$name HITL contract",
- ({ driver, broken }) => {
- for (const rule of hitlContract) {
- const { capabilities } = driver();
- const supported = rule.requires.every((capability) => capabilities.includes(capability));
- const known = broken?.[rule.rule];
- const run = () => withChannelConversation(driver(), (c) => rule.run(c));
- if (!supported) {
- it.skip(`${rule.rule} (not supported)`, run);
- } else if (known === undefined) {
- it(rule.rule, run, 60_000);
- } else {
- it(
- `${rule.rule} (broken: ${known.reason})`,
- () => expect(run()).rejects.toThrow(known.symptom),
- 60_000,
- );
- }
- }
- },
-);
diff --git a/packages/eve/src/public/channels/linear/hitl-conformance.integration.test.ts b/packages/eve/src/public/channels/linear/hitl-conformance.integration.test.ts
new file mode 100644
index 000000000..287eff5b3
--- /dev/null
+++ b/packages/eve/src/public/channels/linear/hitl-conformance.integration.test.ts
@@ -0,0 +1,3 @@
+import { describeHitlConformance } from "#internal/testing/channel-conformance/conformance.js";
+
+describeHitlConformance("linear");
diff --git a/packages/eve/src/public/channels/linear/linearChannel.test.ts b/packages/eve/src/public/channels/linear/linearChannel.test.ts
index 31e850b17..3d1d6f2c1 100644
--- a/packages/eve/src/public/channels/linear/linearChannel.test.ts
+++ b/packages/eve/src/public/channels/linear/linearChannel.test.ts
@@ -205,29 +205,6 @@ describe("linearChannel inbound Agent Session events", () => {
expect(send).toHaveBeenCalledTimes(1);
});
- it("delivers prompted values as messages for the harness to resolve", async () => {
- const channel = linearChannel({ credentials: { webhookSecret: SECRET } });
- const { send } = await firePost(
- channel,
- signedRequest(
- sessionPayload({
- action: "prompted",
- agentActivity: {
- content: { body: "approve", type: "prompt" },
- id: "activity_prompt",
- user: { id: "user_1" },
- userId: "user_1",
- },
- }),
- ),
- );
-
- expect(send).toHaveBeenCalledTimes(1);
- const [, input] = send.mock.calls[0]!;
- expect(input.inputResponses).toBeUndefined();
- expect(input.message).toBe("approve");
- });
-
it("attaches authenticated Linear upload images to prompted messages", async () => {
const fetchMock = vi.fn().mockResolvedValue(
new Response(new Uint8Array([1, 2, 3]), {
diff --git a/packages/eve/src/public/channels/linq/hitl-conformance.integration.test.ts b/packages/eve/src/public/channels/linq/hitl-conformance.integration.test.ts
new file mode 100644
index 000000000..15407164f
--- /dev/null
+++ b/packages/eve/src/public/channels/linq/hitl-conformance.integration.test.ts
@@ -0,0 +1,3 @@
+import { describeHitlConformance } from "#internal/testing/channel-conformance/conformance.js";
+
+describeHitlConformance("linq");
diff --git a/packages/eve/src/public/channels/slack/hitl-conformance.integration.test.ts b/packages/eve/src/public/channels/slack/hitl-conformance.integration.test.ts
new file mode 100644
index 000000000..b57e6f209
--- /dev/null
+++ b/packages/eve/src/public/channels/slack/hitl-conformance.integration.test.ts
@@ -0,0 +1,3 @@
+import { describeHitlConformance } from "#internal/testing/channel-conformance/conformance.js";
+
+describeHitlConformance("slack");
diff --git a/packages/eve/src/public/channels/slack/slackChannel.test.ts b/packages/eve/src/public/channels/slack/slackChannel.test.ts
index 59553f27d..67594b201 100644
--- a/packages/eve/src/public/channels/slack/slackChannel.test.ts
+++ b/packages/eve/src/public/channels/slack/slackChannel.test.ts
@@ -1324,13 +1324,6 @@ describe("slackChannel() default event handlers", () => {
const callbackBody = await interactionRequest.clone().text();
expect(callbackBody).not.toContain("cursor+cloud+task");
expect(callbackBody.length).toBeLessThan(3_000);
-
- const { send } = await firePost(channel, interactionRequest);
- expect(send).toHaveBeenCalledTimes(1);
- expect(send.mock.calls[0]?.[0]).toBe("C01:1700000000.000001");
- expect(send.mock.calls[0]?.[1]).toMatchObject({
- inputResponses: [{ optionId: "approve", requestId: "approval_cursor" }],
- });
});
it("input.requested caps section and fallback text so Slack does not reject the post", async () => {
diff --git a/packages/eve/src/public/channels/teams/hitl-conformance.integration.test.ts b/packages/eve/src/public/channels/teams/hitl-conformance.integration.test.ts
new file mode 100644
index 000000000..ced259fa7
--- /dev/null
+++ b/packages/eve/src/public/channels/teams/hitl-conformance.integration.test.ts
@@ -0,0 +1,3 @@
+import { describeHitlConformance } from "#internal/testing/channel-conformance/conformance.js";
+
+describeHitlConformance("teams");
diff --git a/packages/eve/src/public/channels/telegram/hitl-conformance.integration.test.ts b/packages/eve/src/public/channels/telegram/hitl-conformance.integration.test.ts
new file mode 100644
index 000000000..e66a28253
--- /dev/null
+++ b/packages/eve/src/public/channels/telegram/hitl-conformance.integration.test.ts
@@ -0,0 +1,3 @@
+import { describeHitlConformance } from "#internal/testing/channel-conformance/conformance.js";
+
+describeHitlConformance("telegram");
diff --git a/packages/eve/src/public/channels/twilio/hitl-conformance.integration.test.ts b/packages/eve/src/public/channels/twilio/hitl-conformance.integration.test.ts
new file mode 100644
index 000000000..c22f7cabf
--- /dev/null
+++ b/packages/eve/src/public/channels/twilio/hitl-conformance.integration.test.ts
@@ -0,0 +1,3 @@
+import { describeHitlConformance } from "#internal/testing/channel-conformance/conformance.js";
+
+describeHitlConformance("twilio");