@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

main
ts 79 lines 3.37 KB
Raw
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 { runPromise, test, WEB } from "./t3.ts";
9
10 // Windows Volta 2 writes `bin/<tool>` scripts that run `volta run`, not links to `volta-shim`.
11 // The fake `volta` only reports a version, so nothing installs or reaches a model. The latest
12 // version comes from npm's registry through the host's npm, which the server finds first on PATH.
13 const VOLTA_SCRIPT_SHIM = '#!/bin/bash\nvolta run "$(basename $0)" "$@"\n';
14 const FAKE_VOLTA = '#!/bin/sh\n[ "$1 $3" = "run --version" ] && echo 2.1.2 && exit 0\nexit 1\n';
15
16 const SettingsJson = Schema.fromJsonString(
17 Schema.StructWithRest(
18 Schema.Struct({ providerInstances: Schema.Record(Schema.String, Schema.Unknown) }),
19 [Schema.Record(Schema.String, Schema.Unknown)],
20 ),
21 );
22
23 const decodeSettings = Schema.decodeEffect(SettingsJson);
24 const encodeSettings = Schema.encodeEffect(SettingsJson);
25
26 const installVoltaOpenCode = Effect.gen(function* () {
27 const fs = yield* FileSystem.FileSystem;
28 const path = yield* Path.Path;
29 const voltaHome = path.join(T3_HOME, "Volta");
30 const shim = path.join(voltaHome, "bin", "opencode");
31 const executable = (file: string, text: string) =>
32 fs
33 .makeDirectory(path.dirname(file), { recursive: true })
34 .pipe(Effect.andThen(fs.writeFileString(file, text)), Effect.andThen(fs.chmod(file, 0o755)));
35 yield* executable(shim, VOLTA_SCRIPT_SHIM);
36 yield* fs.makeDirectory(path.join(voltaHome, "tools", "image", "packages", "@opencode", "cli"), {
37 recursive: true,
38 });
39 // The scenario home's `bin` is on the server's PATH.
40 yield* executable(path.join(T3_HOME, "bin", "volta"), FAKE_VOLTA);
41
42 const settingsPath = path.join(T3_HOME, "userdata", "settings.json");
43 const settings = yield* decodeSettings(yield* fs.readFileString(settingsPath));
44 const opencode = { driver: "opencode", enabled: true, config: { binaryPath: shim } };
45 yield* fs.writeFileString(
46 settingsPath,
47 yield* encodeSettings({
48 ...settings,
49 providerInstances: { ...settings.providerInstances, opencode },
50 }),
51 );
52 });
53
54 test(
55 "OpenCode installed through a Volta script shim offers a Volta update",
56 WEB,
57 async ({ t3, app, browser, screen }) => {
58 await browser.emulateMedia({ colorScheme: "dark" });
59 await t3.project("demo");
60 await runPromise(installVoltaOpenCode);
61 await t3.open("/settings/providers?instanceId=opencode");
62
63 // The list row and the detail header both carry the button; take the header's.
64 const details = screen.getByRole("button", /view details/).last();
65 await expect(details).toBeVisible({ timeout: 60_000 });
66 await details.tap();
67 await expect(screen.getByRole("dialog", "Update available")).toBeVisible();
68 // Capture the settled popover, not its fade-in.
69 await browser.evaluate(() => {
70 const popover = document.querySelector('[role="dialog"][aria-label="Update available"]');
71 for (const animation of popover?.getAnimations({ subtree: true }) ?? []) {
72 if (Number.isFinite(animation.effect?.getComputedTiming().endTime)) animation.finish();
73 }
74 return null;
75 });
76 await app.screenshot("update-details");
77 await expect(screen.getByText("volta install @opencode/cli@latest")).toBeVisible();
78 },
79 );