Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

test(eve): reproduce a press on an inactive session's approval card doing nothing (#4838)

roboeve[bot]566601bb2f01
diff --git a/packages/eve/src/internal/testing/channel-conformance/harness.ts b/packages/eve/src/internal/testing/channel-conformance/harness.ts
index d366166d0..fe0c205e4 100644
--- a/packages/eve/src/internal/testing/channel-conformance/harness.ts
+++ b/packages/eve/src/internal/testing/channel-conformance/harness.ts
@@ -20,7 +20,7 @@ import {
askDayAndTimeWorkflow,
askRetroDayWorkflow,
} from "#internal/testing/channel-conformance/question-workflows.js";
-import { getWorld } from "#internal/workflow/runtime.js";
+import { getRun, getWorld } from "#internal/workflow/runtime.js";
import type { MessageStreamEvent } from "#protocol/message.js";
import {
type ConnectionAuthorizationChallenge,
@@ -246,6 +246,11 @@ export interface ChannelConversation {
waitForToolOutcome(tool: string): Promise<ToolOutcome>;
/** Waits until every session has stopped working and waits only on a person. */
waitForRest(): Promise<void>;
+ /**
+ * Cancels every session's workflow run through the workflow world, as an
+ * operator would, so no eve code runs for those sessions again.
+ */
+ cancelRunsInWorld(): Promise<void>;
/** How many times a gated tool actually executed, as its side effect would show. */
runsOf(tool: GatedTool): number;
/**
@@ -792,6 +797,8 @@ async function converse(
});
const sessions = new Map<string, Session>();
const background: Promise<unknown>[] = [];
+ // A cancelled run's hooks are gone, so its address is never claimed again.
+ let runsCancelledInWorld = false;
function track(session: Session): Session {
sessions.set(session.id, session);
@@ -810,7 +817,7 @@ async function converse(
...source,
send: async (...sendArgs) => track(await source.send(...sendArgs)),
respond: async (...respondArgs) => {
- await waitForAddress(address);
+ if (!runsCancelledInWorld) await waitForAddress(address);
return track(await source.respond(...respondArgs));
},
};
@@ -964,6 +971,13 @@ async function converse(
runsOf: (tool) => runs[tool],
callersOf: () => callers,
waitForRest: () => waitForRest([...sessions.values()], wait),
+ async cancelRunsInWorld() {
+ await waitForStepsToFinish([...sessions.values()], wait);
+ await Promise.all([...sessions.keys()].map((runId) => getRun(runId).cancel()));
+ runsCancelledInWorld = true;
+ // A cancelled run never rests, so there is nothing left to settle.
+ sessions.clear();
+ },
async shownPrompt(prompt) {
if (view.shownPrompt === undefined) throw new Error(`${label} cannot read shown messages.`);
return await view.shownPrompt(prompt);
diff --git a/packages/eve/src/internal/testing/channel-conformance/telegram-driver.ts b/packages/eve/src/internal/testing/channel-conformance/telegram-driver.ts
index 4acb27a3f..5aac1623e 100644
--- a/packages/eve/src/internal/testing/channel-conformance/telegram-driver.ts
+++ b/packages/eve/src/internal/testing/channel-conformance/telegram-driver.ts
@@ -194,6 +194,16 @@ export function telegramDriver(surface: Exclude<Surface, "public"> = "shared"):
return inlineOptions(call);
},
shownMessage(call) {
+ // A callback answer is a notice only the presser sees.
+ if (call.method === "answerCallbackQuery") {
+ const { callback_query_id: id, text } = call.body as {
+ readonly callback_query_id: string;
+ readonly text?: string;
+ };
+ return text === undefined
+ ? undefined
+ : { id: `callback:${id}`, onlyPerson: true, options: [], text };
+ }
if (!MESSAGE_WRITES.has(call.method)) return undefined;
return {
id: String(messageIdOf(call)),
diff --git a/packages/eve/src/public/channels/inactive-session-press.integration.test.ts b/packages/eve/src/public/channels/inactive-session-press.integration.test.ts
new file mode 100644
index 000000000..0018deb98
--- /dev/null
+++ b/packages/eve/src/public/channels/inactive-session-press.integration.test.ts
@@ -0,0 +1,32 @@
+import { expect, it } from "vitest";
+
+import {
+ deployPrompt,
+ GATED_TOOL,
+ withChannelConversation,
+} from "#internal/testing/channel-conformance/harness.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";
+
+// #4835: an operator cancels a session's run through the workflow world, so
+// eve never withdraws its pending approval. A later press reaches no session.
+for (const driver of [slackDriver(), teamsDriver(), telegramDriver()]) {
+ it.fails(
+ `${driver.name}: pressing Approve after the session's run was cancelled outside eve clears the approval's buttons and says it is no longer active`,
+ () =>
+ withChannelConversation(driver, async (conversation) => {
+ const prompt = deployPrompt("v2.4");
+ await conversation.say(`Use ${GATED_TOOL} to ship release "v2.4".`);
+ const options = await conversation.waitForQuestion(prompt);
+ await conversation.cancelRunsInWorld();
+
+ await conversation.press(options.find(({ label }) => label === "Approve")!);
+
+ expect(conversation.runsOf(GATED_TOOL)).toBe(0);
+ expect((await conversation.shownPrompt(prompt)).options).toEqual([]);
+ await conversation.waitForShown(/no longer active/);
+ }),
+ 60_000,
+ );
+}