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 | // @effect-diagnostics nodeBuiltinImport:off - the scenario writes a fake Pi CLI and its settings. |
| 2 | import * as NodeFSP from "node:fs/promises"; |
| 3 | import * as NodePath from "node:path"; |
| 4 | |
| 5 | import { expect } from "e2e"; |
| 6 | |
| 7 | import { T3_HOME } from "../e2e.config.ts"; |
| 8 | import { makeState, runPromise, test, WEB } from "./t3.ts"; |
| 9 | |
| 10 | const CHOSEN_MODEL = "anthropic/claude-sonnet-4"; |
| 11 | // A supported Pi whose RPC discovery fails, so its catalog falls back to the "default" alias. |
| 12 | const FAKE_PI = `#!/bin/sh |
| 13 | if [ "$1" = "--version" ]; then echo "0.84.3"; exit 0; fi |
| 14 | echo "scenario Pi cannot list models" >&2 |
| 15 | exit 1 |
| 16 | `; |
| 17 | |
| 18 | test( |
| 19 | "A Pi model chosen in Settings is still the one sent while Pi cannot list its models", |
| 20 | WEB, |
| 21 | async ({ t3, app, screen, browser }) => { |
| 22 | const project = await t3.project("demo"); |
| 23 | const fakePi = NodePath.join(T3_HOME, "bin/fake-pi"); |
| 24 | const settingsPath = NodePath.join(T3_HOME, "userdata/settings.json"); |
| 25 | const originalSettings = await NodeFSP.readFile(settingsPath, "utf8"); |
| 26 | const settings = JSON.parse(originalSettings); |
| 27 | try { |
| 28 | await NodeFSP.writeFile(fakePi, FAKE_PI, { mode: 0o755 }); |
| 29 | settings.providerInstances.pi = { |
| 30 | driver: "pi", |
| 31 | enabled: true, |
| 32 | config: { binaryPath: fakePi }, |
| 33 | }; |
| 34 | settings.defaultModelSelection = { instanceId: "pi", model: CHOSEN_MODEL }; |
| 35 | await NodeFSP.writeFile(settingsPath, JSON.stringify(settings)); |
| 36 | |
| 37 | await t3.open(); |
| 38 | // The composer shows a Pi model once the settings watcher has enabled Pi. |
| 39 | await expect(browser.locator("[data-chat-provider-model-picker-label]").first()).toHaveText( |
| 40 | /sonnet|default/i, |
| 41 | { timeout: 60_000 }, |
| 42 | ); |
| 43 | await app.screenshot("composer"); |
| 44 | |
| 45 | await screen.getByRole("textbox").fill("Which model is this?"); |
| 46 | await screen.getByRole("textbox").press("Enter"); |
| 47 | const { cli } = makeState(T3_HOME); |
| 48 | await expect |
| 49 | .poll( |
| 50 | async () => { |
| 51 | const listed = await runPromise( |
| 52 | cli(["thread", "list", "--project", project, "--json"]), |
| 53 | ); |
| 54 | const threads = JSON.parse(listed.stdout) as Array<{ model: string }>; |
| 55 | return threads[0]?.model ?? null; |
| 56 | }, |
| 57 | { timeout: 30_000 }, |
| 58 | ) |
| 59 | .toBe(CHOSEN_MODEL); |
| 60 | } finally { |
| 61 | await NodeFSP.writeFile(settingsPath, originalSettings); |
| 62 | await NodeFSP.rm(fakePi, { force: true }); |
| 63 | } |
| 64 | }, |
| 65 | ); |