|
| 1 | +// @effect-diagnostics nodeBuiltinImport:off -- Seed a local recording for the dev Replay agent. |
| 2 | +import * as NodeFSP from "node:fs/promises"; |
| 3 | +import * as NodePath from "node:path"; |
| 4 | + |
| 5 | +import { ProviderDriverKind, ProviderInstanceId } from "@t3tools/contracts"; |
| 6 | +import { expect } from "e2e"; |
| 7 | +import * as Effect from "effect/Effect"; |
| 8 | + |
| 9 | +import { T3_HOME } from "../e2e.config.ts"; |
| 10 | +import { makeState, rpcClient, runPromise, test, WEB } from "./t3.ts"; |
| 11 | + |
| 12 | +const recording = [ |
| 13 | + { type: "expect_outbound", frame: { kind: "request", method: "session/prompt" } }, |
| 14 | + { |
| 15 | + type: "emit_inbound", |
| 16 | + frame: { |
| 17 | + kind: "request", |
| 18 | + method: "elicitation/create", |
| 19 | + params: { |
| 20 | + sessionId: "demo-session", |
| 21 | + mode: "form", |
| 22 | + message: "Choose where to run the tests.", |
| 23 | + requestedSchema: { |
| 24 | + type: "object", |
| 25 | + properties: { |
| 26 | + targets: { |
| 27 | + type: "array", |
| 28 | + title: "Test targets", |
| 29 | + description: "Choose at least two targets.", |
| 30 | + items: { type: "string", enum: ["Web", "Desktop", "Mobile"] }, |
| 31 | + minItems: 2, |
| 32 | + }, |
| 33 | + }, |
| 34 | + required: ["targets"], |
| 35 | + }, |
| 36 | + }, |
| 37 | + }, |
| 38 | + }, |
| 39 | + { |
| 40 | + type: "emit_inbound", |
| 41 | + frame: { kind: "response", method: "session/prompt", result: { stopReason: "end_turn" } }, |
| 42 | + }, |
| 43 | +] |
| 44 | + .map((entry) => JSON.stringify(entry)) |
| 45 | + .join("\n"); |
| 46 | + |
| 47 | +test( |
| 48 | + "An ACP question requires the requested number of choices", |
| 49 | + WEB, |
| 50 | + async ({ t3, app, screen }) => { |
| 51 | + const replayAgent = await NodeFSP.readFile( |
| 52 | + new URL("../../apps/server/scripts/dev-replay-agent.ts", import.meta.url), |
| 53 | + "utf8", |
| 54 | + ); |
| 55 | + const project = await t3.project("Test targets demo", { |
| 56 | + "replay/dev-replay-agent.ts": replayAgent, |
| 57 | + "replay/dev-replay/showcase_transcript.ndjson": recording, |
| 58 | + }); |
| 59 | + const instanceId = ProviderInstanceId.make("scenario-choice-agent"); |
| 60 | + await runPromise( |
| 61 | + Effect.gen(function* () { |
| 62 | + const client = yield* rpcClient(T3_HOME, app.baseUrl ?? ""); |
| 63 | + yield* client["server.updateSettings"]({ |
| 64 | + patch: {}, |
| 65 | + providerInstanceMutation: { |
| 66 | + operation: "upsert", |
| 67 | + instanceId, |
| 68 | + instance: { |
| 69 | + driver: ProviderDriverKind.make("acpRegistry"), |
| 70 | + displayName: "Choice fixture", |
| 71 | + enabled: true, |
| 72 | + config: { |
| 73 | + source: "local", |
| 74 | + commandPath: process.execPath, |
| 75 | + commandArgs: [NodePath.join(project, "replay/dev-replay-agent.ts")], |
| 76 | + }, |
| 77 | + }, |
| 78 | + }, |
| 79 | + }); |
| 80 | + }).pipe(Effect.scoped), |
| 81 | + ); |
| 82 | + const { cli } = makeState(T3_HOME); |
| 83 | + const started = await runPromise( |
| 84 | + cli( |
| 85 | + [ |
| 86 | + "thread", |
| 87 | + "start", |
| 88 | + project, |
| 89 | + "Ask me where to run the tests.", |
| 90 | + "--title", |
| 91 | + "Choose test targets", |
| 92 | + "--provider", |
| 93 | + instanceId, |
| 94 | + "--model", |
| 95 | + "default", |
| 96 | + "--wait", |
| 97 | + "--json", |
| 98 | + ], |
| 99 | + [2], |
| 100 | + ), |
| 101 | + ); |
| 102 | + const { threadId } = JSON.parse(started.stdout) as { threadId: string }; |
| 103 | + await t3.open({ threadId }); |
| 104 | + |
| 105 | + const web = screen.getByRole("button", { name: /^Web\b/ }); |
| 106 | + const submit = screen.getByRole("button", { name: "Submit", exact: true }); |
| 107 | + await web.tap(); |
| 108 | + await expect(web).toHaveAttribute("aria-pressed", "true"); |
| 109 | + await app.screenshot("one-of-two-required-targets"); |
| 110 | + await expect(submit).toBeDisabled(); |
| 111 | + await screen.getByRole("button", { name: /^Mobile\b/ }).tap(); |
| 112 | + await expect(submit).toBeEnabled(); |
| 113 | + }, |
| 114 | +); |
0 commit comments