|
| 1 | +import { expect } from "e2e"; |
| 2 | +import * as Effect from "effect/Effect"; |
| 3 | +import * as FileSystem from "effect/FileSystem"; |
| 4 | +import * as Path from "effect/Path"; |
| 5 | +import * as Schema from "effect/Schema"; |
| 6 | + |
| 7 | +import { T3_HOME } from "../e2e.config.ts"; |
| 8 | +import { SECOND_HOME, startSecondServer } from "./second-server.ts"; |
| 9 | +import { run } from "./shell.ts"; |
| 10 | +import { makeState, runPromise, test, WEB } from "./t3.ts"; |
| 11 | + |
| 12 | +const SettingsJson = Schema.fromJsonString(Schema.Record(Schema.String, Schema.Unknown)); |
| 13 | +const decodeSettings = Schema.decodeEffect(SettingsJson); |
| 14 | +const encodeSettings = Schema.encodeEffect(SettingsJson); |
| 15 | + |
| 16 | +// The second machine starts new threads on the replay agent's "Plan and reads" recording. |
| 17 | +const secondMachineDefaultsToPlanAndReads = Effect.gen(function* () { |
| 18 | + const fs = yield* FileSystem.FileSystem; |
| 19 | + const settingsPath = (yield* Path.Path).join(SECOND_HOME, "userdata/settings.json"); |
| 20 | + const settings = yield* decodeSettings(yield* fs.readFileString(settingsPath)); |
| 21 | + yield* fs.writeFileString( |
| 22 | + settingsPath, |
| 23 | + yield* encodeSettings({ |
| 24 | + ...settings, |
| 25 | + defaultModelSelection: { instanceId: "devReplay", model: "todo-list" }, |
| 26 | + }), |
| 27 | + ); |
| 28 | +}); |
| 29 | + |
| 30 | +test( |
| 31 | + "A new draft takes the other machine's default model when it moves there", |
| 32 | + WEB, |
| 33 | + async ({ t3, app, screen, browser }) => { |
| 34 | + const primary = makeState(T3_HOME); |
| 35 | + const second = makeState(SECOND_HOME); |
| 36 | + // Machines share a project through its repository, which needs a remote to be named by. |
| 37 | + const workspace = await runPromise( |
| 38 | + Effect.gen(function* () { |
| 39 | + const fs = yield* FileSystem.FileSystem; |
| 40 | + const path = yield* Path.Path; |
| 41 | + yield* fs.makeDirectory(path.join(T3_HOME, "workspaces"), { recursive: true }); |
| 42 | + const directory = yield* fs.makeTempDirectory({ |
| 43 | + directory: path.join(T3_HOME, "workspaces"), |
| 44 | + prefix: "demo-", |
| 45 | + }); |
| 46 | + yield* fs.writeFileString(path.join(directory, "README.md"), ""); |
| 47 | + return directory; |
| 48 | + }), |
| 49 | + ); |
| 50 | + const git = (args: ReadonlyArray<string>) => runPromise(run("git", args, { cwd: workspace })); |
| 51 | + await git(["init", "--quiet", "--initial-branch=main"]); |
| 52 | + await git(["remote", "add", "origin", "https://github.com/scenario/demo.git"]); |
| 53 | + await git(["add", "--all"]); |
| 54 | + await git([ |
| 55 | + "-c", |
| 56 | + "user.name=Scenario", |
| 57 | + "-c", |
| 58 | + |
| 59 | + "commit", |
| 60 | + "--quiet", |
| 61 | + "--message", |
| 62 | + "Initial commit", |
| 63 | + ]); |
| 64 | + await runPromise(primary.cli(["project", "add", workspace, "--title", "demo"])); |
| 65 | + const server = startSecondServer(app.baseUrl ?? ""); |
| 66 | + try { |
| 67 | + const { host, token } = await server.ready; |
| 68 | + await runPromise(secondMachineDefaultsToPlanAndReads); |
| 69 | + await runPromise(second.cli(["project", "add", workspace, "--title", "demo"])); |
| 70 | + |
| 71 | + await t3.open("/settings/connections"); |
| 72 | + await screen.getByRole("button", "Add environment").tap(); |
| 73 | + const dialog = screen.getByRole("dialog"); |
| 74 | + await dialog.getByPlaceholder("backend.example.com").fill(host); |
| 75 | + await dialog.getByPlaceholder("PAIRCODE").fill(token); |
| 76 | + await dialog.getByRole("button", "Add environment").tap(); |
| 77 | + await expect(screen.getByRole("button", "More actions for Scenario")).toBeVisible({ |
| 78 | + timeout: 60_000, |
| 79 | + }); |
| 80 | + await app.open("/"); |
| 81 | + // The draft may open on either machine; it starts on that machine's default. |
| 82 | + const showcase = screen.getByRole("button", "Showcase", { exact: false }).first(); |
| 83 | + const planAndReads = screen.getByRole("button", "Plan and reads", { exact: false }).first(); |
| 84 | + await expect(showcase.or(planAndReads)).toBeVisible(); |
| 85 | + const otherDefault = (await planAndReads.isVisible()) ? showcase : planAndReads; |
| 86 | + await app.screenshot("before-machine-switch"); |
| 87 | + |
| 88 | + // Both machines are named Scenario; the draft runs on the checked one. |
| 89 | + const runOn = () => screen.getByText("Scenario").last().tap(); |
| 90 | + const machine = (index: number) => browser.locator('[role="menuitemradio"]').nth(index); |
| 91 | + await runOn(); |
| 92 | + const target = (await machine(0).getAttribute("aria-checked")) === "true" ? 1 : 0; |
| 93 | + await machine(target).click(); |
| 94 | + await runOn(); |
| 95 | + await expect(machine(target)).toHaveAttribute("aria-checked", "true"); |
| 96 | + await browser.keyboard.press("Escape"); |
| 97 | + |
| 98 | + await app.screenshot("after-machine-switch"); |
| 99 | + await expect(otherDefault).toBeVisible(); |
| 100 | + } finally { |
| 101 | + await server.stop(); |
| 102 | + await runPromise(primary.cli(["project", "remove", workspace, "--force"])); |
| 103 | + } |
| 104 | + }, |
| 105 | +); |
0 commit comments