The best way to control Claude Code, Codex and more from any computer or phone
| 1 | // @effect-diagnostics nodeBuiltinImport:off -- The scenario starts a local ACP fixture. |
| 2 | import * as NodePath from "node:path"; |
| 3 | |
| 4 | import { ProviderDriverKind, ProviderInstanceId } from "@t3tools/contracts"; |
| 5 | import { expect } from "e2e"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | |
| 8 | import { T3_HOME } from "../e2e.config.ts"; |
| 9 | import { |
| 10 | expectHeldImageCompressions, |
| 11 | finishImageCompression, |
| 12 | holdImageCompression, |
| 13 | pasteWideScreenshot, |
| 14 | } from "./image-compression-hold.ts"; |
| 15 | import { makeState, rpcClient, runPromise, test, WEB } from "./t3.ts"; |
| 16 | |
| 17 | const ACP = ` |
| 18 | import { createInterface } from "node:readline"; |
| 19 | |
| 20 | const sessionId = "image-question-session"; |
| 21 | const send = (message) => process.stdout.write(JSON.stringify({ jsonrpc: "2.0", ...message }) + "\\n"); |
| 22 | let promptId; |
| 23 | for await (const line of createInterface({ input: process.stdin })) { |
| 24 | const { id, method } = JSON.parse(line); |
| 25 | if (method === "session/cancel" && promptId !== undefined) { |
| 26 | send({ id: promptId, result: { stopReason: "cancelled" } }); |
| 27 | promptId = undefined; |
| 28 | } |
| 29 | if (id === undefined || method === undefined) continue; |
| 30 | if (method === "initialize") { |
| 31 | send({ id, result: { protocolVersion: 1, agentCapabilities: { promptCapabilities: { image: true } }, authMethods: [], |
| 32 | agentInfo: { name: "Question fixture", version: "1.0.0" } } }); |
| 33 | } else if (method === "session/new") { |
| 34 | send({ id, result: { sessionId } }); |
| 35 | } else if (method === "session/prompt") { |
| 36 | promptId = id; |
| 37 | send({ |
| 38 | id: "ask-image-question", |
| 39 | method: "elicitation/create", |
| 40 | params: { |
| 41 | sessionId, |
| 42 | mode: "form", |
| 43 | message: "What should we look at?", |
| 44 | requestedSchema: { |
| 45 | type: "object", |
| 46 | properties: { answer: { type: "string", title: "Screenshot question" } }, |
| 47 | required: ["answer"], |
| 48 | }, |
| 49 | }, |
| 50 | }); |
| 51 | } else { |
| 52 | send({ id, error: { code: -32601, message: "Method not found" } }); |
| 53 | } |
| 54 | } |
| 55 | `; |
| 56 | |
| 57 | test( |
| 58 | "Stopping an unanswered question keeps a screenshot that is still preparing", |
| 59 | WEB, |
| 60 | async ({ t3, app, browser }) => { |
| 61 | await holdImageCompression(browser); |
| 62 | const project = await t3.project("demo", { "question-agent.mjs": ACP }); |
| 63 | const instanceId = ProviderInstanceId.make("scenario-question-agent"); |
| 64 | await runPromise( |
| 65 | Effect.gen(function* () { |
| 66 | const client = yield* rpcClient(T3_HOME, app.baseUrl ?? ""); |
| 67 | yield* client["server.updateSettings"]({ |
| 68 | patch: {}, |
| 69 | providerInstanceMutation: { |
| 70 | operation: "upsert", |
| 71 | instanceId, |
| 72 | instance: { |
| 73 | driver: ProviderDriverKind.make("acpRegistry"), |
| 74 | displayName: "Question fixture", |
| 75 | enabled: true, |
| 76 | config: { |
| 77 | source: "local", |
| 78 | commandPath: process.execPath, |
| 79 | commandArgs: [NodePath.join(project, "question-agent.mjs")], |
| 80 | }, |
| 81 | }, |
| 82 | }, |
| 83 | }); |
| 84 | }).pipe(Effect.scoped), |
| 85 | ); |
| 86 | const { cli } = makeState(T3_HOME); |
| 87 | const started = await runPromise( |
| 88 | cli( |
| 89 | [ |
| 90 | "thread", |
| 91 | "start", |
| 92 | project, |
| 93 | "Ask for a screenshot.", |
| 94 | "--title", |
| 95 | "Screenshot question thread", |
| 96 | "--provider", |
| 97 | instanceId, |
| 98 | "--model", |
| 99 | "default", |
| 100 | "--wait", |
| 101 | "--json", |
| 102 | ], |
| 103 | [2], |
| 104 | ), |
| 105 | ); |
| 106 | const { threadId } = JSON.parse(started.stdout) as { threadId: string }; |
| 107 | await t3.open({ threadId }); |
| 108 | |
| 109 | const composer = browser.locator('[data-chat-composer-form="true"]'); |
| 110 | const question = browser.locator( |
| 111 | '[data-chat-composer-form="true"] [data-pending-user-input-toggle]', |
| 112 | ); |
| 113 | await question.waitFor({ timeout: 60_000 }); |
| 114 | await composer.getByRole("textbox").fill("Here is the screenshot."); |
| 115 | await pasteWideScreenshot(browser); |
| 116 | await expectHeldImageCompressions(browser, 1); |
| 117 | await composer.getByRole("button", "Stop generation").tap(); |
| 118 | await question.waitFor({ state: "hidden" }); |
| 119 | |
| 120 | await finishImageCompression(browser); |
| 121 | await app.screenshot("draft-after-stopping-question"); |
| 122 | await expect( |
| 123 | browser.locator( |
| 124 | '[data-chat-composer-form="true"] button[aria-label="Preview screenshot.png"]:enabled', |
| 125 | ), |
| 126 | ).toBeVisible(); |
| 127 | }, |
| 128 | ); |