Skip to content

7.4 billion tokens per month. 34 free LLM providers. 635 free model endpoints. All behind one /v1 endpoint, plus any custom OpenAI-compatible endpoint. Smart routing, automatic failover, encrypted keys. Personal experimentation only.

TypeScript

fix(update): compare desktop installs against the latest release tag (#1279)

Tashfeen6c812a645eb5
diff --git a/server/src/__tests__/routes/update.test.ts b/server/src/__tests__/routes/update.test.ts
index 259bd369..e1b6eb9e 100644
--- a/server/src/__tests__/routes/update.test.ts
+++ b/server/src/__tests__/routes/update.test.ts
@@ -161,6 +161,92 @@ describe('Update API', () => {
expect(request?.headers).not.toHaveProperty('Authorization');
});
+ it('compares desktop installs against the latest release tag, not main', async () => {
+ const fetchMock = vi.fn(async (url: string | URL | RequestInfo) => {
+ if (String(url).includes('/releases/latest')) {
+ return response({
+ tag_name: 'v0.11.0',
+ html_url: 'https://github.com/tashfeenahmed/freellmapi/releases/tag/v0.11.0',
+ });
+ }
+ return response(compareBody('identical'));
+ });
+ const { app } = createTestApp({
+ env: { FREELLMAPI_INSTALL_METHOD: 'desktop', FREELLMAPI_COMMIT_SHA: LOCAL_SHA },
+ fetch: fetchMock,
+ });
+
+ const result = await httpGet(app, '/api/update/check');
+
+ expect(result.body).toMatchObject({ status: 'current', installation: 'desktop' });
+ expect(fetchMock).toHaveBeenCalledWith(
+ `https://api.github.com/repos/tashfeenahmed/freellmapi/compare/${LOCAL_SHA}...v0.11.0`,
+ expect.any(Object),
+ );
+ // 'identical' against the tag: no update offered for untagged main commits.
+ expect(result.body.remoteSha).toBe(LOCAL_SHA.slice(0, 7));
+ });
+
+ it('reports an update when a desktop install trails the latest tag', async () => {
+ const fetchMock = vi.fn(async (url: string | URL | RequestInfo) => {
+ if (String(url).includes('/releases/latest')) {
+ return response({
+ tag_name: 'v0.12.0',
+ html_url: 'https://github.com/tashfeenahmed/freellmapi/releases/tag/v0.12.0',
+ });
+ }
+ return response(compareBody('ahead'));
+ });
+ const { app } = createTestApp({
+ env: { FREELLMAPI_INSTALL_METHOD: 'desktop', FREELLMAPI_COMMIT_SHA: LOCAL_SHA },
+ fetch: fetchMock,
+ });
+
+ const result = await httpGet(app, '/api/update/check');
+
+ expect(result.body).toMatchObject({ status: 'available', installation: 'desktop' });
+ });
+
+ it('reports unknown for a desktop install when no release tag can be resolved', async () => {
+ const fetchMock = vi.fn(async (url: string | URL | RequestInfo) => {
+ if (String(url).includes('/releases/latest')) return response({ message: 'no releases' }, 404);
+ return response(compareBody('ahead'));
+ });
+ const { app } = createTestApp({
+ env: { FREELLMAPI_INSTALL_METHOD: 'desktop', FREELLMAPI_COMMIT_SHA: LOCAL_SHA },
+ fetch: fetchMock,
+ });
+
+ const result = await httpGet(app, '/api/update/check');
+
+ expect(result.body).toMatchObject({ status: 'unknown', installation: 'desktop' });
+ // Without a tag to compare against, main must not be dialed at all.
+ expect(fetchMock).toHaveBeenCalledTimes(1);
+ });
+
+ it('never falls back to the main-branch Atom feed for a desktop install', async () => {
+ const fetchMock = vi.fn(async (url: string | URL | RequestInfo) => {
+ if (String(url).includes('/releases/latest')) {
+ return response({
+ tag_name: 'v0.11.0',
+ html_url: 'https://github.com/tashfeenahmed/freellmapi/releases/tag/v0.11.0',
+ });
+ }
+ return response({ message: 'rate limited' }, 403);
+ });
+ const { app } = createTestApp({
+ env: { FREELLMAPI_INSTALL_METHOD: 'desktop', FREELLMAPI_COMMIT_SHA: LOCAL_SHA },
+ fetch: fetchMock,
+ });
+
+ const result = await httpGet(app, '/api/update/check');
+
+ // The Atom feed only tracks main; falling back to it would re-offer
+ // untagged commits, so the request must surface as an upstream error.
+ expect(result.status).toBe(502);
+ expect(fetchMock).toHaveBeenCalledTimes(2);
+ });
+
it('reports disabled without resolving Git identity or making a network request', async () => {
const fetchMock = vi.fn();
const execMock = vi.fn(async () => ({ stdout: `${LOCAL_SHA}\n` }));
diff --git a/server/src/routes/update.ts b/server/src/routes/update.ts
index a668d557..ab276022 100644
--- a/server/src/routes/update.ts
+++ b/server/src/routes/update.ts
@@ -402,7 +402,20 @@ export function createUpdateRouter(options: UpdateRouterOptions = {}): Router {
checkedAt: new Date(checkedAtMs).toISOString(),
version: appVersion(),
};
- const url = `https://api.github.com/repos/${REPOSITORY}/compare/${currentIdentity.sha}...main`;
+ // A desktop build can only be replaced by installing a published release,
+ // so it must compare against the latest tag rather than `main` (#1270):
+ // untagged commits on main have no installer, and offering them produced
+ // an "Update available" that did nothing when clicked.
+ let compareTarget = 'main';
+ if (currentIdentity.installation === 'desktop') {
+ try {
+ compareTarget = (await latestRelease()).tagName;
+ } catch {
+ return { status: 'unknown', ...baseResult };
+ }
+ }
+
+ const url = `https://api.github.com/repos/${REPOSITORY}/compare/${currentIdentity.sha}...${compareTarget}`;
const response = await fetchImpl(url, {
headers: githubHeaders('application/vnd.github+json'),
signal: AbortSignal.timeout(10_000),
@@ -412,6 +425,11 @@ export function createUpdateRouter(options: UpdateRouterOptions = {}): Router {
return { status: 'unknown', ...baseResult };
}
if (response.status === 401 || response.status === 403 || response.status === 429) {
+ // The Atom feed tracks `main` only; for a desktop install it would
+ // reintroduce the bug this branch fixes, so let the rate limit surface.
+ if (currentIdentity.installation === 'desktop') {
+ throw new Error(`GitHub compare request returned HTTP ${response.status}`);
+ }
const atomResponse = await fetchImpl(`https://github.com/${REPOSITORY}/commits/main.atom`, {
headers: {
Accept: 'application/atom+xml',