Open History to see the last commit
1import * as NodeModule from "node:module";
2
3import { GitHubProvider } from "electron-updater/out/providers/GitHubProvider.js";
4import { describe, expect, it } from "vite-plus/test";
5
6type ProviderArgs = ConstructorParameters<typeof GitHubProvider>;
7
8// electron-updater's own dependency, which apps/desktop does not declare.
9const semver = NodeModule.createRequire(
10 NodeModule.createRequire(import.meta.url).resolve("electron-updater"),
11)("semver") as { parse: (version: string) => ProviderArgs[1]["currentVersion"] };
12
13const REPO = "/pingdotgg/t3code";
14const nightly = (build: number) => `v0.1.10-nightly.20261112.${build}`;
15
16const atomFeed = (tags: ReadonlyArray<string>) =>
17 `<feed xmlns="http://www.w3.org/2005/Atom">${tags
18 .map(
19 (tag) =>
20 `<entry><link rel="alternate" type="text/html" href="https://github.com${REPO}/releases/tag/${tag}"/><title>${tag}</title><content type="html">${tag} feed notes</content></entry>`,
21 )
22 .join("")}</feed>`;
23
24/**
25 * The release a nightly install on 4580 is offered when GitHub serves this feed, this `update-feed`
26 * pointer, and this newest nightly from the REST API scan.
27 */
28const offeredRelease = async (
29 feedTags: ReadonlyArray<string>,
30 pointerTag: string | undefined,
31 listedTag?: string | Error,
32) => {
33 let apiScans = 0;
34 const request = async ({ path = "" }: { readonly path?: string | null }) => {
35 if (path === `${REPO}/releases.atom`) return atomFeed(feedTags);
36 if (path === `${REPO}/releases/download/update-feed/nightly.json`) {
37 if (pointerTag === undefined) throw new Error("404");
38 return JSON.stringify({ tag_name: pointerTag, name: pointerTag, body: "pointer notes" });
39 }
40 const manifest = /\/releases\/download\/v([^/]+)\/nightly\.yml$/.exec(path ?? "");
41 if (manifest) return `version: ${manifest[1]}\npath: T3-Code.exe\nsha512: abc\n`;
42 apiScans += 1;
43 if (listedTag instanceof Error) throw listedTag;
44 return JSON.stringify(listedTag ? [{ tag_name: listedTag, body: "API notes" }] : []);
45 };
46 const provider = new GitHubProvider(
47 { provider: "github", owner: "pingdotgg", repo: "t3code" },
48 // Only the four fields the provider reads; a real AppUpdater needs Electron.
49 {
50 allowPrerelease: true,
51 channel: "nightly",
52 currentVersion: semver.parse("0.1.10-nightly.20261112.4580"),
53 fullChangelog: true,
54 } as ProviderArgs[1],
55 {
56 isUseMultipleRangeRequest: false,
57 platform: "win32",
58 executor: { request },
59 } as ProviderArgs[2],
60 );
61 const { tag, releaseNotes } = await provider.getLatestVersion();
62 return { tag, releaseNotes, apiScans };
63};
64
65// What filled releases.atom on 2026-11-12: ten tags, none of them a nightly.
66const crowdedFeed = Array.from({ length: 10 }, (_, i) => `v0.1.10-preview.20261112.${4550 + i}`);
67
68describe("GitHubProvider nightly lookup", () => {
69 it.each([
70 ["other tags fill the feed", crowdedFeed],
71 ["the feed's first nightly is an older one", [nightly(4603)]],
72 ])("finds the newest nightly at the fixed pointer when %s", async (_case, feedTags) => {
73 expect(await offeredRelease(feedTags, nightly(4606))).toEqual({
74 tag: nightly(4606),
75 releaseNotes: "pointer notes",
76 apiScans: 0,
77 });
78 });
79
80 it("still scans the API when the feed has no nightly and the pointer offers nothing new", async () => {
81 expect(await offeredRelease(crowdedFeed, nightly(4580), nightly(4606))).toEqual({
82 tag: nightly(4606),
83 releaseNotes: "API notes",
84 apiScans: 1,
85 });
86 });
87
88 it("keeps the pointer's answer when the API scan fails", async () => {
89 const rateLimited = new Error("403");
90 expect(await offeredRelease(crowdedFeed, nightly(4580), rateLimited)).toMatchObject({
91 tag: nightly(4580),
92 apiScans: 1,
93 });
94 });
95
96 it.each([
97 ["the feed is newer than the pointer", nightly(4603)],
98 ["there is no pointer", undefined],
99 ["the pointer names another channel", "v0.1.10-preview.20261112.4700"],
100 ])("keeps the feed's nightly when %s", async (_case, pointerTag) => {
101 expect(await offeredRelease([nightly(4606)], pointerTag)).toEqual({
102 tag: nightly(4606),
103 releaseNotes: [{ version: nightly(4606).slice(1), note: `${nightly(4606)} feed notes` }],
104 apiScans: 0,
105 });
106 });
107});