Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(release): the update notification downloads the installer, instead of a 404

yhhd1d5dfc20959
diff --git a/.github/workflows/mirror-release.yml b/.github/workflows/mirror-release.yml
index b968c4192..db909af94 100644
--- a/.github/workflows/mirror-release.yml
+++ b/.github/workflows/mirror-release.yml
@@ -95,6 +95,9 @@ jobs:
ENDPOINT: https://${{ secrets.R2_ACCOUNT_ID }}.r2.cloudflarestorage.com
BUCKET: ${{ secrets.R2_BUCKET }}
PUBLIC_BASE: ${{ secrets.R2_PUBLIC_BASE }}
+ # The site's download section — a real page, unlike the bucket, which
+ # serves objects and has no index to land on.
+ SITE_DOWNLOAD: https://estellaengine.com/#download
TAG: ${{ inputs.tag || github.event.release.tag_name }}
IS_LATEST: ${{ steps.latest.outputs.is_latest }}
run: |
@@ -147,8 +150,13 @@ jobs:
# latest.json must never be pointed at a version whose assets are still
# uploading, nor at an older one somebody re-mirrored. `version` and
# `url` are the editor's update check; `downloads` is what the website
- # labels its buttons with, and adding to it cannot break the editor.
- jq -n --arg version "$version" --arg url "$base/v$version/" --argjson downloads "$downloads" \
+ # labels its buttons with, and what a current editor downloads from.
+ #
+ # `url` is the fallback for an editor that finds no installer for its own
+ # platform, so it has to be a PAGE. It used to be "$base/v$version/" —
+ # a bucket directory, which 404s: object storage has no directory index,
+ # so every update notification led to a Cloudflare error page.
+ jq -n --arg version "$version" --arg url "$SITE_DOWNLOAD" --argjson downloads "$downloads" \
'{version: $version, url: $url, downloads: $downloads}' > latest.json
cat latest.json
aws s3 cp latest.json "s3://$BUCKET/latest.json" \
diff --git a/desktop/electron/updateCheck.ts b/desktop/electron/updateCheck.ts
index 52db4c0fc..fab1a603b 100644
--- a/desktop/electron/updateCheck.ts
+++ b/desktop/electron/updateCheck.ts
@@ -21,12 +21,29 @@ const RELEASES_LATEST = 'https://api.github.com/repos/esengine/estella/releases/
/**
* What a mirror publishes at its root so an editor can ask "what is current?"
- * without the origin's API: the version, and where its download page or installer
- * is. Written by the release workflow's mirror step beside the version folders.
+ * without the origin's API. Written by the release workflow's mirror step beside
+ * the version folders.
*/
interface MirrorLatest {
version?: string;
+ /** Generic landing place — a page a human can download from. */
url?: string;
+ /** Per-platform installers at stable, version-less aliases. Keyed as below. */
+ downloads?: Record<string, { url?: string; name?: string; size?: number }>;
+}
+
+/**
+ * The `downloads` key for a build, or null where no installer is published for it.
+ *
+ * The notification's button says "Download", so it should land on the installer for
+ * the machine reading it rather than on a page listing every platform — and the
+ * mirror already publishes exactly that, at an alias that survives releases.
+ */
+export function downloadKeyFor(platform: string, arch: string): string | null {
+ if (platform === 'win32') return 'win';
+ if (platform === 'darwin') return arch === 'arm64' ? 'mac-arm64' : 'mac-x64';
+ if (platform === 'linux') return arch === 'arm64' ? 'linux-arm64' : 'linux';
+ return null;
}
export interface LatestRelease {
@@ -66,9 +83,11 @@ export async function checkForUpdate(
currentVersion: string,
fetchImpl: typeof fetch = fetch,
env: NodeJS.ProcessEnv = process.env,
+ platform: string = process.platform,
+ arch: string = process.arch,
): Promise<LatestRelease | null> {
for (const mirror of releaseMirrors(env)) {
- const found = await checkMirror(mirror, currentVersion, fetchImpl);
+ const found = await checkMirror(mirror, currentVersion, fetchImpl, platform, arch);
if (found) return found;
}
return checkOrigin(currentVersion, fetchImpl);
@@ -79,6 +98,8 @@ async function checkMirror(
mirror: string,
currentVersion: string,
fetchImpl: typeof fetch,
+ platform: string,
+ arch: string,
): Promise<LatestRelease | null> {
try {
const res = await fetchImpl(`${mirror}/latest.json`, { headers: { accept: 'application/json' } });
@@ -88,9 +109,16 @@ async function checkMirror(
const parsed = parseVersion(body.version);
if (!parsed || !isNewerVersion(body.version, currentVersion)) return null;
const version = parsed.parts.join('.') + (parsed.pre ? `-${parsed.pre}` : '');
- // The mirror's own copy of that version's assets, so the download is as fast as
- // the check was. A mirror that names no url still gets the user to the release.
- return { version, url: body.url ?? `${mirror}/v${version}/` };
+
+ // This machine's installer if the mirror publishes one, else whatever page it
+ // named. NOTHING is composed from the version here: a bare `<mirror>/v<x>/` was
+ // composed once as a "sensible" fallback, and it 404s on every static host —
+ // object storage has no directory index. A url we did not get from the mirror
+ // is a url nobody has ever loaded, so when the mirror names none, this reports
+ // no answer and the origin (whose release page is real) gets asked instead.
+ const key = downloadKeyFor(platform, arch);
+ const url = (key ? body.downloads?.[key]?.url : undefined) ?? body.url;
+ return url ? { version, url } : null;
} catch {
return null;
}
diff --git a/desktop/tests/release-mirror.test.ts b/desktop/tests/release-mirror.test.ts
index e81f8115d..9a00e29a0 100644
--- a/desktop/tests/release-mirror.test.ts
+++ b/desktop/tests/release-mirror.test.ts
@@ -156,16 +156,26 @@ describe('downloading a template with a mirror configured', () => {
describe('checking for an editor update with a mirror configured', () => {
const env = { [RELEASE_MIRROR_ENV]: MIRROR };
- it('asks the mirror first and points the download at it', async () => {
+ it('asks the mirror first and points the download at the installer it publishes', async () => {
const asked: string[] = [];
const fetchImpl = (async (url: string) => {
asked.push(url);
- return { ok: true, status: 200, json: async () => ({ version: '1.2.0' }) } as unknown as Response;
+ return {
+ ok: true, status: 200,
+ json: async () => ({
+ version: '1.2.0',
+ url: 'https://estellaengine.com/#download',
+ downloads: { win: { url: `${MIRROR}/latest/Estella-Editor-Setup.exe` } },
+ }),
+ } as unknown as Response;
}) as unknown as typeof fetch;
- const res = await checkForUpdate('1.1.0', fetchImpl, env);
+ const res = await checkForUpdate('1.1.0', fetchImpl, env, 'win32', 'x64');
- expect(res).toEqual({ version: '1.2.0', url: `${MIRROR}/v1.2.0/` });
+ // This test used to assert `${MIRROR}/v1.2.0/` — a url composed here rather
+ // than published by the mirror, and a 404 on every static host, since object
+ // storage has no directory index. It pinned the bug as the contract.
+ expect(res).toEqual({ version: '1.2.0', url: `${MIRROR}/latest/Estella-Editor-Setup.exe` });
expect(asked).toEqual([`${MIRROR}/latest.json`]);
});
diff --git a/desktop/tests/update-check.test.ts b/desktop/tests/update-check.test.ts
index a9cc15a60..413577289 100644
--- a/desktop/tests/update-check.test.ts
+++ b/desktop/tests/update-check.test.ts
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
import { describe, it, expect } from 'vitest';
-import { parseVersion, isNewerVersion, checkForUpdate } from '../electron/updateCheck';
+import { parseVersion, isNewerVersion, checkForUpdate, downloadKeyFor } from '../electron/updateCheck';
describe('parseVersion', () => {
it('parses plain and v-prefixed versions', () => {
@@ -65,3 +65,87 @@ describe('checkForUpdate', () => {
expect(await checkForUpdate('0.17.0', f)).toBeNull();
});
});
+
+// — The mirror path —————————————————————————————————————————————————————————————
+//
+// The notification's button says "Download", so where it lands is the whole point.
+// It used to land on `<mirror>/v<version>/`, composed here rather than published by
+// the mirror — a bucket directory, which 404s on any static host because object
+// storage has no directory index. Every update notification led to an error page.
+
+const MIRROR = 'https://m.test';
+const env = { ESTELLA_RELEASE_MIRROR: MIRROR } as NodeJS.ProcessEnv;
+
+/** Routes by URL, so one stub can answer both the mirror and the GitHub origin. */
+const fetchRouting = (routes: Record<string, unknown>): typeof fetch =>
+ (async (url: string) => {
+ const hit = Object.entries(routes).find(([prefix]) => String(url).startsWith(prefix));
+ if (!hit) return { ok: false, status: 404, json: async () => ({}) };
+ return { ok: true, status: 200, json: async () => hit[1] };
+ }) as unknown as typeof fetch;
+
+const LATEST = {
+ version: '0.35.0',
+ url: 'https://estellaengine.com/#download',
+ downloads: {
+ win: { url: 'https://m.test/latest/Estella-Editor-Setup.exe', name: 'Estella-Editor-Setup-0.35.0.exe', size: 1 },
+ 'mac-arm64': { url: 'https://m.test/latest/Estella-Editor-arm64.dmg', name: 'Estella-Editor-0.35.0-arm64.dmg', size: 1 },
+ },
+};
+
+describe('downloadKeyFor', () => {
+ it('maps a build to the key the mirror publishes it under', () => {
+ expect(downloadKeyFor('win32', 'x64')).toBe('win');
+ expect(downloadKeyFor('darwin', 'arm64')).toBe('mac-arm64');
+ expect(downloadKeyFor('darwin', 'x64')).toBe('mac-x64');
+ expect(downloadKeyFor('linux', 'x64')).toBe('linux');
+ expect(downloadKeyFor('freebsd', 'x64')).toBeNull();
+ });
+});
+
+describe('checkForUpdate — mirror', () => {
+ const f = fetchRouting({ [MIRROR]: LATEST });
+
+ it('downloads THIS machine`s installer, not a page listing every platform', async () => {
+ expect(await checkForUpdate('0.34.1', f, env, 'win32', 'x64')).toEqual({
+ version: '0.35.0',
+ url: 'https://m.test/latest/Estella-Editor-Setup.exe',
+ });
+ expect((await checkForUpdate('0.34.1', f, env, 'darwin', 'arm64'))?.url)
+ .toBe('https://m.test/latest/Estella-Editor-arm64.dmg');
+ });
+
+ it('falls back to the published page when this platform has no installer', async () => {
+ // An Intel Mac, or Linux: the mirror ships neither, and a page a human can
+ // choose from is the honest answer — not a guess at a filename.
+ expect((await checkForUpdate('0.34.1', f, env, 'darwin', 'x64'))?.url)
+ .toBe('https://estellaengine.com/#download');
+ expect((await checkForUpdate('0.34.1', f, env, 'linux', 'x64'))?.url)
+ .toBe('https://estellaengine.com/#download');
+ });
+
+ it('never composes a url the mirror did not publish', async () => {
+ // The regression. A mirror naming neither an installer nor a page is "no
+ // answer" — the origin's release page is real, and a fabricated directory
+ // url is one nobody has ever loaded.
+ const bare = fetchRouting({
+ [MIRROR]: { version: '0.35.0' },
+ 'https://api.github.com': { tag_name: 'v0.35.0', html_url: 'https://github.com/x/releases/v0.35.0' },
+ });
+ const found = await checkForUpdate('0.34.1', bare, env, 'win32', 'x64');
+ expect(found?.url).toBe('https://github.com/x/releases/v0.35.0');
+ expect(found?.url).not.toMatch(/\/v0\.35\.0\/$/);
+ });
+
+ it('still reports nothing when the mirror is not newer', async () => {
+ expect(await checkForUpdate('0.35.0', f, env, 'win32', 'x64')).toBeNull();
+ });
+
+ it('lets the origin answer when the mirror is unreachable', async () => {
+ const originOnly = fetchRouting({
+ 'https://api.github.com': { tag_name: 'v0.35.0', html_url: 'https://github.com/x/releases/v0.35.0' },
+ });
+ expect((await checkForUpdate('0.34.1', originOnly, env, 'win32', 'x64'))?.url)
+ .toBe('https://github.com/x/releases/v0.35.0');
+ });
+});