The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
| 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 | |
| 6 | import { T3_HOME } from "../e2e.config.ts"; |
| 7 | import { SECOND_HOME, startSecondServer } from "./second-server.ts"; |
| 8 | import { run } from "./shell.ts"; |
| 9 | import { makeState, runPromise, test, WEB } from "./t3.ts"; |
| 10 | |
| 11 | test( |
| 12 | "A new draft keeps its selected models when it moves to another machine", |
| 13 | WEB, |
| 14 | async ({ t3, app, screen, browser }) => { |
| 15 | const primary = makeState(T3_HOME); |
| 16 | const second = makeState(SECOND_HOME); |
| 17 | // Machines share a project through its repository, which needs a remote to be named by. |
| 18 | const workspace = await runPromise( |
| 19 | Effect.gen(function* () { |
| 20 | const fs = yield* FileSystem.FileSystem; |
| 21 | const path = yield* Path.Path; |
| 22 | yield* fs.makeDirectory(path.join(T3_HOME, "workspaces"), { recursive: true }); |
| 23 | const directory = yield* fs.makeTempDirectory({ |
| 24 | directory: path.join(T3_HOME, "workspaces"), |
| 25 | prefix: "demo-", |
| 26 | }); |
| 27 | yield* fs.writeFileString(path.join(directory, "README.md"), ""); |
| 28 | return directory; |
| 29 | }), |
| 30 | ); |
| 31 | const git = (args: ReadonlyArray<string>) => runPromise(run("git", args, { cwd: workspace })); |
| 32 | await git(["init", "--quiet", "--initial-branch=main"]); |
| 33 | await git(["remote", "add", "origin", "https://github.com/scenario/demo.git"]); |
| 34 | await git(["add", "--all"]); |
| 35 | await git([ |
| 36 | "-c", |
| 37 | "user.name=Scenario", |
| 38 | "-c", |
| 39 | "user.email=scenario@example.invalid", |
| 40 | "commit", |
| 41 | "--quiet", |
| 42 | "--message", |
| 43 | "Initial commit", |
| 44 | ]); |
| 45 | await runPromise(primary.cli(["project", "add", workspace, "--title", "demo"])); |
| 46 | const server = startSecondServer(app.baseUrl ?? ""); |
| 47 | try { |
| 48 | const { host, token } = await server.ready; |
| 49 | await runPromise(second.cli(["project", "add", workspace, "--title", "demo"])); |
| 50 | |
| 51 | await t3.open("/settings/connections"); |
| 52 | await screen.getByRole("button", "Add environment").tap(); |
| 53 | const dialog = screen.getByRole("dialog"); |
| 54 | await dialog.getByPlaceholder("backend.example.com").fill(host); |
| 55 | await dialog.getByPlaceholder("PAIRCODE").fill(token); |
| 56 | await dialog.getByRole("button", "Add environment").tap(); |
| 57 | // The map is the default view; its rows carry no actions menu. |
| 58 | await screen.getByRole("button", "List", { exact: true }).tap(); |
| 59 | await expect(screen.getByRole("button", "More actions for Scenario")).toBeVisible({ |
| 60 | timeout: 60_000, |
| 61 | }); |
| 62 | await app.open("/"); |
| 63 | // Shift adds a model to the draft instead of replacing it. |
| 64 | await screen.getByRole("button", "Showcase", { exact: false }).first().tap(); |
| 65 | await browser.keyboard.type("Plan and reads"); |
| 66 | await browser.keyboard.press("Shift+Enter"); |
| 67 | await browser.keyboard.press("Escape"); |
| 68 | const models = screen.getByRole("button", "Showcase, Plan and reads", { exact: false }); |
| 69 | await expect(models.first()).toBeVisible(); |
| 70 | |
| 71 | // Both machines are named Scenario; the draft runs on the checked one. |
| 72 | const runOn = () => screen.getByText("Scenario").last().tap(); |
| 73 | const machine = (index: number) => browser.locator('[role="menuitemradio"]').nth(index); |
| 74 | await runOn(); |
| 75 | const target = (await machine(0).getAttribute("aria-checked")) === "true" ? 1 : 0; |
| 76 | await machine(target).click(); |
| 77 | await runOn(); |
| 78 | await expect(machine(target)).toHaveAttribute("aria-checked", "true"); |
| 79 | await browser.keyboard.press("Escape"); |
| 80 | |
| 81 | await app.screenshot("after-machine-switch"); |
| 82 | await expect(models.first()).toBeVisible(); |
| 83 | } finally { |
| 84 | await server.stop(); |
| 85 | await runPromise(primary.cli(["project", "remove", workspace, "--force"])); |
| 86 | } |
| 87 | }, |
| 88 | ); |