@devries-cameron20 / t3code Mirror · read-only / commits / 6ac70aa0c6
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 22, 23:15 UTC

fix(cli): use GitHub tokens when checking for updates (#19507)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

James C committed Oct 20, 2026 at 05:15 UTC 6ac70aa0c6dc8d176b61fbda9d007eefbaaf7b81
2 files changed +73 -18
apps/server/src/cli/update.test.ts
+54 -1
@@ -10,15 +10,68 @@ import * as Layer from "effect/Layer";
10 import * as Option from "effect/Option";
11 import * as Path from "effect/Path";
12 import { Command } from "effect/cli";
13 +import { HttpClient, HttpClientResponse } from "effect/http";
14 import { afterEach, vi } from "vite-plus/test";
15
16 import packageJson from "../../package.json" with { type: "json" };
17 import * as BootService from "../cloud/bootService.ts";
18 import { pinnedRuntimePaths } from "../cloud/pinnedRuntime.ts";
18 -import { repointLauncher, resolveLauncherPath, updateCommand } from "./update.ts";
19 +import {
20 + repointLauncher,
21 + resolveLauncherPath,
22 + resolveNewestVersion,
23 + updateCommand,
24 +} from "./update.ts";
25
26 afterEach(() => vi.restoreAllMocks());
27
28 +it.effect.each([
29 + { environment: { GH_TOKEN: " gh-token ", GITHUB_TOKEN: "github-token" }, token: "gh-token" },
30 + { environment: { GH_TOKEN: " ", GITHUB_TOKEN: " github-token " }, token: "github-token" },
31 + { environment: { GITHUB_TOKEN: "github-token" }, token: "github-token" },
32 + { environment: { GH_TOKEN: " ", GITHUB_TOKEN: " " }, token: undefined },
33 + { environment: {}, token: undefined },
34 +])("selects release authentication from $environment", ({ environment, token }) =>
35 + Effect.gen(function* () {
36 + const authorizations: Array<string | undefined> = [];
37 + const httpClient = HttpClient.make((request) => {
38 + authorizations.push(request.headers.authorization);
39 + return Effect.succeed(
40 + HttpClientResponse.fromWeb(request, Response.json([{ tag_name: "v1.2.3" }])),
41 + );
42 + });
43 + const version = yield* resolveNewestVersion("stable").pipe(
44 + Effect.provideService(HostProcess.Environment, environment),
45 + Effect.provideService(HttpClient.HttpClient, httpClient),
46 + );
47 + assert.equal(version, "1.2.3");
48 + assert.deepStrictEqual(authorizations, [token === undefined ? undefined : `Bearer ${token}`]);
49 + }),
50 +);
51 +
52 +it.effect("authenticates each release page until the requested channel is found", () =>
53 + Effect.gen(function* () {
54 + const pages: string[] = [];
55 + const httpClient = HttpClient.make((request) => {
56 + const url = new URL(request.url);
57 + assert.equal(url.origin, "https://api.github.com");
58 + assert.equal(url.pathname, "/repos/pingdotgg/t3code/releases");
59 + assert.equal(request.headers.accept, "application/vnd.github+json");
60 + assert.equal(request.headers.authorization, "Bearer gh-token");
61 + const page = url.searchParams.get("page") ?? "";
62 + pages.push(page);
63 + const tag_name = page === "1" ? "v1.2.4-preview.20260101.1" : "v1.2.3";
64 + return Effect.succeed(HttpClientResponse.fromWeb(request, Response.json([{ tag_name }])));
65 + });
66 + const version = yield* resolveNewestVersion("stable").pipe(
67 + Effect.provideService(HostProcess.Environment, { GH_TOKEN: "gh-token" }),
68 + Effect.provideService(HttpClient.HttpClient, httpClient),
69 + );
70 + assert.equal(version, "1.2.3");
71 + assert.deepStrictEqual(pages, ["1", "2"]);
72 + }),
73 +);
74 +
75 it.layer(NodeServices.layer)("t3 update launcher", (it) => {
76 it.effect("repoints a symlink that lives in a runtime versions tree", () =>
77 Effect.gen(function* () {
apps/server/src/cli/update.ts
+19 -17
@@ -52,27 +52,29 @@ const decodeReleaseIndex = Schema.decodeUnknownEffect(Schema.fromJsonString(Rele
52 const RELEASE_INDEX_TIMEOUT = Duration.seconds(30);
53 const RELEASE_INDEX_MAX_PAGES = 10;
54
55 -const resolveNewestVersion = Effect.fn("cli.update.resolve_newest")(function* (
55 +export const resolveNewestVersion = Effect.fn("cli.update.resolve_newest")(function* (
56 channel: CliReleaseChannel,
57 ) {
58 const httpClient = yield* HttpClient.HttpClient;
59 + const environment = yield* HostProcess.Environment;
60 + const githubToken = environment.GH_TOKEN?.trim() || environment.GITHUB_TOKEN?.trim() || undefined;
61 for (let page = 1; page <= RELEASE_INDEX_MAX_PAGES; page += 1) {
60 - const body = yield* httpClient
61 - .execute(
62 - HttpClientRequest.get(cliReleaseIndexPageUrl(page)).pipe(
63 - HttpClientRequest.setHeader("Accept", "application/vnd.github+json"),
64 - ),
65 - )
66 - .pipe(
67 - Effect.flatMap(HttpClientResponse.filterStatusOk),
68 - Effect.flatMap((response) => response.text),
69 - Effect.mapError(() => new CliUpdateError({ reason: "Could not list t3 releases." })),
70 - Effect.timeoutOrElse({
71 - duration: RELEASE_INDEX_TIMEOUT,
72 - orElse: () =>
73 - Effect.fail(new CliUpdateError({ reason: "Timed out listing t3 releases." })),
74 - }),
75 - );
62 + const request = HttpClientRequest.get(cliReleaseIndexPageUrl(page)).pipe(
63 + HttpClientRequest.setHeader("Accept", "application/vnd.github+json"),
64 + );
65 + const authenticatedRequest =
66 + githubToken === undefined
67 + ? request
68 + : HttpClientRequest.setHeader(request, "Authorization", `Bearer ${githubToken}`);
69 + const body = yield* httpClient.execute(authenticatedRequest).pipe(
70 + Effect.flatMap(HttpClientResponse.filterStatusOk),
71 + Effect.flatMap((response) => response.text),
72 + Effect.mapError(() => new CliUpdateError({ reason: "Could not list t3 releases." })),
73 + Effect.timeoutOrElse({
74 + duration: RELEASE_INDEX_TIMEOUT,
75 + orElse: () => Effect.fail(new CliUpdateError({ reason: "Timed out listing t3 releases." })),
76 + }),
77 + );
78 const releases = yield* decodeReleaseIndex(body).pipe(
79 Effect.mapError(
80 () => new CliUpdateError({ reason: "The t3 release index had an unexpected shape." }),