Skip to content

Commit 23e637e

Browse files
jorda0megaclaude
andcommitted
fix(mobile): page the release index when the feed lacks the host's channel
The release feed lists only the ten newest releases, so a preview that later nightlies pushed out of it was no longer found. When the feed has no release on the host's channel, page the API release index as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 5195897 commit 23e637e

2 files changed

Lines changed: 63 additions & 14 deletions

File tree

‎apps/mobile/src/features/settings/environment-maintenance.test.ts‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,33 @@ describe("environment release checks", () => {
199199
expect(fetchMock.mock.calls[0]?.[0]).toBe("https://github.com/pingdotgg/t3code/releases.atom");
200200
});
201201

202+
it("pages the release index for a preview that later nightlies pushed out of the feed", async () => {
203+
const nightlies = Array.from({ length: 10 }, (_, i) => `v1.0.0-nightly.20260930.${i}`);
204+
const fetchMock = vi
205+
.fn()
206+
.mockResolvedValueOnce(feed(...nightlies))
207+
.mockResolvedValueOnce(
208+
Response.json(nightlies.concat(Array(90).fill("v1.0.0")).map((tag_name) => ({ tag_name }))),
209+
)
210+
.mockResolvedValueOnce(Response.json([{ tag_name: "v1.0.0-preview.20260924.3" }]));
211+
vi.stubGlobal("fetch", fetchMock);
212+
expect(await findEnvironmentUpdate("1.0.0-preview.20260923.1", signal)).toBe(
213+
"1.0.0-preview.20260924.3",
214+
);
215+
expect(fetchMock.mock.calls[2]?.[0]).toContain("api.github.com");
216+
expect(fetchMock.mock.calls[2]?.[0]).toContain("page=2");
217+
});
218+
202219
it("reports failed checks instead of claiming the server is current", async () => {
203220
vi.stubGlobal("fetch", vi.fn().mockResolvedValue(new Response(null, { status: 429 })));
204221
await expect(findEnvironmentUpdate("1.0.0", signal)).rejects.toThrow("429");
205-
vi.stubGlobal("fetch", vi.fn().mockResolvedValue(feed("v1.0.0")));
222+
vi.stubGlobal(
223+
"fetch",
224+
vi
225+
.fn()
226+
.mockResolvedValueOnce(feed("v1.0.0"))
227+
.mockResolvedValueOnce(Response.json([{ tag_name: "v1.0.0" }])),
228+
);
206229
await expect(findEnvironmentUpdate("1.0.0-nightly.20260923.1", signal)).rejects.toThrow(
207230
"No nightly release",
208231
);

‎apps/mobile/src/features/settings/environment-maintenance.ts‎

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
CLI_RELEASES_PAGE_URL,
1010
type CliReleaseChannel,
1111
cliReleaseChannelOf,
12+
cliReleaseIndexPageUrl,
1213
newestCliReleaseVersion,
1314
} from "@t3tools/shared/cliRelease";
1415
import { compareSemverVersions } from "@t3tools/shared/semver";
@@ -47,38 +48,63 @@ export function canUpdateEnvironmentProvider(provider: ServerProvider) {
4748
}
4849

4950
const decodeLatestRelease = Schema.decodeUnknownSync(Schema.Struct({ tag_name: Schema.String }));
51+
const decodeReleaseIndex = Schema.decodeUnknownSync(
52+
Schema.Array(
53+
Schema.Struct({ tag_name: Schema.String, draft: Schema.optionalKey(Schema.Boolean) }),
54+
),
55+
);
5056
const FEED_TAG = /<id>tag:github\.com,2008:Repository\/\d+\/([^<]+)<\/id>/g;
5157

52-
// Reads github.com rather than api.github.com, whose 60 anonymous requests an
53-
// hour per IP are shared with every other device on the phone's network.
54-
async function fetchReleases(path: "/latest" | ".atom", accept: string, signal: AbortSignal) {
55-
const response = await fetch(`${CLI_RELEASES_PAGE_URL}${path}`, {
56-
signal,
57-
headers: { Accept: accept },
58-
});
58+
async function fetchReleases(url: string, accept: string, signal: AbortSignal) {
59+
const response = await fetch(url, { signal, headers: { Accept: accept } });
5960
if (!response.ok) throw new Error(`Could not check releases (${response.status}). Try again.`);
6061
return response;
6162
}
6263

6364
/**
64-
* Stable hosts read the latest release. Nightly and preview are never marked
65-
* latest, so they read the feed of the ten newest releases, which nightly's
66-
* several-a-day cadence keeps current.
65+
* Reads github.com release pages, which unlike api.github.com do not share 60 anonymous
66+
* requests an hour with every other device on the phone's network. Stable hosts read the
67+
* latest release. Nightly and preview are never marked latest, so they read the feed of
68+
* the ten newest releases.
6769
*/
6870
async function channelReleases(channel: CliReleaseChannel, signal: AbortSignal) {
6971
if (channel === "stable") {
70-
const response = await fetchReleases("/latest", "application/json", signal);
72+
const response = await fetchReleases(
73+
`${CLI_RELEASES_PAGE_URL}/latest`,
74+
"application/json",
75+
signal,
76+
);
7177
return [decodeLatestRelease(await response.json())];
7278
}
73-
const response = await fetchReleases(".atom", "application/atom+xml", signal);
79+
const response = await fetchReleases(
80+
`${CLI_RELEASES_PAGE_URL}.atom`,
81+
"application/atom+xml",
82+
signal,
83+
);
7484
return Array.from((await response.text()).matchAll(FEED_TAG), ([, tag_name = ""]) => ({
7585
tag_name,
7686
}));
7787
}
7888

89+
/** Pages the API release index, for a preview that later nightlies pushed out of the feed. */
90+
async function newestInReleaseIndex(channel: CliReleaseChannel, signal: AbortSignal) {
91+
for (let page = 1; ; page++) {
92+
const response = await fetchReleases(
93+
cliReleaseIndexPageUrl(page),
94+
"application/vnd.github+json",
95+
signal,
96+
);
97+
const releases = decodeReleaseIndex(await response.json());
98+
const version = newestCliReleaseVersion(releases, channel);
99+
if (version !== undefined || releases.length < 100) return version;
100+
}
101+
}
102+
79103
export async function findEnvironmentUpdate(currentVersion: string, signal: AbortSignal) {
80104
const channel = cliReleaseChannelOf(currentVersion);
81-
const version = newestCliReleaseVersion(await channelReleases(channel, signal), channel);
105+
const version =
106+
newestCliReleaseVersion(await channelReleases(channel, signal), channel) ??
107+
(await newestInReleaseIndex(channel, signal));
82108
if (version === undefined) throw new Error(`No ${channel} release was found.`);
83109
return compareSemverVersions(version, currentVersion) > 0 ? version : null;
84110
}

0 commit comments

Comments
 (0)