固定客户端dev服务并支持官网多平台下载
Project CI / AI game creator shell Rust shard 4/4 (push) Successful in 7m31s
Project CI / AI game creator shell Rust shard 1/4 (push) Successful in 7m32s
Project CI / AI game creator shell Rust shard 3/4 (push) Successful in 7m33s
Project CI / AI game creator shell Rust shard 2/4 (push) Successful in 7m40s
Project CI / AI game creator shell Rust smoke (push) Successful in 2m21s
Project CI / AI game creator shell Rust crates (push) Successful in 3m11s
Project CI / Native shell tests (push) Successful in 16m15s
Project CI / Frontend tests (push) Successful in 14m57s
Project CI / Repository checks (push) Successful in 14m48s
Project CI / Backend tests (push) Successful in 20m7s
Project CI / AI game creator shell web tests (push) Successful in 6m20s

移除服务器选择并按来源隔离登录凭据
新增官网客户端下载入口和匿名平台聚合接口
根据发布清单自动展示Windows与macOS首装包
补齐Mac首装元数据和上传顺序校验
同步定向测试与下载发布规范
This commit is contained in:
kdletters
2026-09-19 16:18:05 +08:00
parent 33f5ad68bf
commit e3682fd06f
34 changed files with 2245 additions and 653 deletions
@@ -0,0 +1,223 @@
/* @vitest-environment jsdom */
import {
act,
cleanup,
fireEvent,
render,
screen,
waitFor,
within,
} from '@testing-library/react';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { ClientDownloadEntry } from './ClientDownloadEntry';
const fetchMock = vi.fn();
const installerUrl = (version: string) =>
`https://agc-dev.oss-rg-china-mainland.aliyuncs.com/agc/dev-win/${version}/setup.exe`;
const releaseResponse = (version: string) =>
new Response(
JSON.stringify({
downloads: [
{
platform: 'windows',
architecture: 'x86_64',
version,
downloadUrl: installerUrl(version),
},
],
unavailablePlatforms: [],
}),
);
const macDownload = (architecture: 'aarch64' | 'x86_64') => ({
platform: 'macos',
architecture,
version: '0.2.0',
downloadUrl: `https://agc-dev.oss-rg-china-mainland.aliyuncs.com/agc/dev-mac/0.2.0/app_${architecture}.dmg`,
});
describe('官网下载入口', () => {
beforeEach(() => {
fetchMock.mockReset();
vi.stubGlobal('fetch', fetchMock);
});
afterEach(() => {
cleanup();
vi.unstubAllGlobals();
vi.useRealTimers();
});
it('无需登录,每次打开重新获取最新版本和安装包链接', async () => {
fetchMock.mockImplementationOnce(() =>
Promise.resolve(releaseResponse('0.1.73')),
);
render(<ClientDownloadEntry />);
expect(fetchMock).not.toHaveBeenCalled();
fireEvent.click(screen.getByRole('button', { name: '下载客户端' }));
expect(
(
await screen.findByRole('link', { name: '下载 Windows 版' })
).getAttribute('href'),
).toBe(installerUrl('0.1.73'));
expect(screen.getByText('最新版本 v0.1.73')).toBeTruthy();
expect(fetchMock).toHaveBeenCalledWith(
'/api/client-downloads',
expect.objectContaining({ cache: 'no-store', credentials: 'omit' }),
);
fireEvent.keyDown(document, { key: 'Escape' });
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
fetchMock.mockImplementationOnce(() =>
Promise.resolve(releaseResponse('0.1.74')),
);
fireEvent.click(screen.getByRole('button', { name: '下载客户端' }));
expect(
(
await screen.findByRole('link', { name: '下载 Windows 版' })
).getAttribute('href'),
).toBe(installerUrl('0.1.74'));
});
it('服务不可用时不显示下载链接,重试后使用成功响应', async () => {
fetchMock.mockResolvedValueOnce(new Response('', { status: 502 }));
render(<ClientDownloadEntry />);
fireEvent.click(screen.getByRole('button', { name: '下载客户端' }));
expect(await screen.findByRole('alert')).toBeTruthy();
expect(screen.queryByRole('link')).toBeNull();
fetchMock.mockImplementationOnce(() =>
Promise.resolve(releaseResponse('0.1.75')),
);
fireEvent.click(screen.getByRole('button', { name: '重试' }));
expect(
(
await screen.findByRole('link', { name: '下载 Windows 版' })
).getAttribute('href'),
).toBe(installerUrl('0.1.75'));
});
it('Mac 发布后重新打开即显示各架构和独立版本,未发布时不显示', async () => {
fetchMock.mockImplementationOnce(() =>
Promise.resolve(releaseResponse('0.1.73')),
);
render(<ClientDownloadEntry />);
fireEvent.click(screen.getByRole('button', { name: '下载客户端' }));
await screen.findByRole('link', { name: '下载 Windows 版' });
expect(screen.queryByText(/macOS/u)).toBeNull();
fireEvent.keyDown(document, { key: 'Escape' });
fetchMock.mockImplementationOnce(async () => {
const windows = await releaseResponse('0.1.74').json();
return new Response(
JSON.stringify({
...windows,
downloads: [
...windows.downloads,
macDownload('aarch64'),
macDownload('x86_64'),
],
}),
);
});
fireEvent.click(screen.getByRole('button', { name: '下载客户端' }));
const arm = await screen.findByRole('region', {
name: 'macOS(Apple Silicon)',
});
const intel = screen.getByRole('region', { name: 'macOS(Intel)' });
expect(within(arm).getByText('最新版本 v0.2.0')).toBeTruthy();
expect(within(arm).getByRole('link').getAttribute('href')).toBe(
macDownload('aarch64').downloadUrl,
);
expect(within(intel).getByRole('link').getAttribute('href')).toBe(
macDownload('x86_64').downloadUrl,
);
expect(screen.getByText('最新版本 v0.1.74')).toBeTruthy();
expect(screen.getAllByRole('link')).toHaveLength(3);
});
it('部分平台失败仍可下载其他平台,重试成功后补齐列表', async () => {
fetchMock.mockImplementationOnce(async () => {
const windows = await releaseResponse('0.1.74').json();
return new Response(
JSON.stringify({ ...windows, unavailablePlatforms: ['macos'] }),
);
});
render(<ClientDownloadEntry />);
fireEvent.click(screen.getByRole('button', { name: '下载客户端' }));
expect(
(
await screen.findByRole('link', { name: '下载 Windows 版' })
).getAttribute('href'),
).toBe(installerUrl('0.1.74'));
expect(screen.getByRole('alert').textContent).toContain('macOS');
fetchMock.mockResolvedValueOnce(
new Response(
JSON.stringify({
downloads: [macDownload('aarch64')],
unavailablePlatforms: [],
}),
),
);
fireEvent.click(screen.getByRole('button', { name: '重试' }));
await screen.findByRole('region', { name: 'macOS(Apple Silicon)' });
expect(screen.queryByRole('alert')).toBeNull();
expect(screen.queryByRole('link', { name: '下载 Windows 版' })).toBeNull();
});
it('所有平台尚未发布时显示空状态而不伪造链接', async () => {
fetchMock.mockResolvedValueOnce(
new Response(JSON.stringify({ downloads: [], unavailablePlatforms: [] })),
);
render(<ClientDownloadEntry />);
fireEvent.click(screen.getByRole('button', { name: '下载客户端' }));
expect(await screen.findByText('暂无可下载版本')).toBeTruthy();
expect(screen.queryByRole('link')).toBeNull();
expect(screen.getByRole('button', { name: '重试' })).toBeTruthy();
});
it('响应缺少平台列表时显示可重试错误', async () => {
fetchMock.mockResolvedValueOnce(new Response('{}'));
render(<ClientDownloadEntry />);
fireEvent.click(screen.getByRole('button', { name: '下载客户端' }));
expect(await screen.findByRole('alert')).toBeTruthy();
expect(screen.queryByRole('link')).toBeNull();
});
it('关闭取消请求,迟到响应不覆盖重开后版本', async () => {
let resolveFirst!: (response: Response) => void;
fetchMock.mockImplementationOnce(
() =>
new Promise<Response>((resolve) => {
resolveFirst = resolve;
}),
);
render(<ClientDownloadEntry />);
fireEvent.click(screen.getByRole('button', { name: '下载客户端' }));
const signal = fetchMock.mock.calls[0][1].signal as AbortSignal;
fireEvent.keyDown(document, { key: 'Escape' });
expect(signal.aborted).toBe(true);
fetchMock.mockImplementationOnce(() =>
Promise.resolve(releaseResponse('0.1.76')),
);
fireEvent.click(screen.getByRole('button', { name: '下载客户端' }));
await screen.findByText('最新版本 v0.1.76');
await act(async () => {
resolveFirst(releaseResponse('0.1.73'));
});
expect(screen.getByText('最新版本 v0.1.76')).toBeTruthy();
});
it('请求超时后退出加载并允许重试', async () => {
vi.useFakeTimers();
fetchMock.mockImplementationOnce(() => new Promise(() => {}));
render(<ClientDownloadEntry />);
fireEvent.click(screen.getByRole('button', { name: '下载客户端' }));
const signal = fetchMock.mock.calls[0][1].signal as AbortSignal;
await act(async () => {
vi.advanceTimersByTime(15_000);
});
expect(signal.aborted).toBe(true);
expect(screen.getByRole('alert')).toBeTruthy();
expect(screen.getByRole('button', { name: '重试' })).toBeTruthy();
});
});
@@ -0,0 +1,174 @@
import { getPlatformActionButtonClassName } from '@genarrative/shared/components';
import { Download, Monitor } from 'lucide-react';
import { useEffect, useState } from 'react';
import type { ClientDownloadResponse } from '../../../packages/shared/src/contracts/clientDownload';
import { PlatformActionButton } from '../common/PlatformActionButton';
import { PlatformStatusMessage } from '../common/PlatformStatusMessage';
import { PlatformSubpanel } from '../common/PlatformSubpanel';
import { UnifiedModal } from '../common/UnifiedModal';
const DOWNLOAD_ERROR = '暂时无法获取最新版本,请稍后重试';
type DownloadState =
| { status: 'loading' }
| { status: 'ready'; release: ClientDownloadResponse }
| { status: 'error' };
const platformNames = { windows: 'Windows', macos: 'macOS' } as const;
function downloadLabel(download: ClientDownloadResponse['downloads'][number]) {
if (download.platform === 'windows') return 'Windows 64 位';
return `macOS(${download.architecture === 'aarch64' ? 'Apple Silicon' : 'Intel'})`;
}
export function ClientDownloadEntry() {
const [open, setOpen] = useState(false);
const [attempt, setAttempt] = useState(0);
const [state, setState] = useState<DownloadState>({ status: 'loading' });
useEffect(() => {
if (!open) return;
const controller = new AbortController();
let disposed = false;
const timeout = window.setTimeout(() => {
if (disposed) return;
disposed = true;
controller.abort();
setState({ status: 'error' });
}, 15_000);
setState({ status: 'loading' });
void (async () => {
try {
const response = await fetch('/api/client-downloads', {
signal: controller.signal,
cache: 'no-store',
credentials: 'omit',
});
if (!response.ok) throw new Error(DOWNLOAD_ERROR);
const release = (await response.json()) as ClientDownloadResponse;
if (
!Array.isArray(release.downloads) ||
!Array.isArray(release.unavailablePlatforms)
) {
throw new Error(DOWNLOAD_ERROR);
}
if (!disposed) setState({ status: 'ready', release });
} catch {
if (!disposed) setState({ status: 'error' });
} finally {
window.clearTimeout(timeout);
}
})();
return () => {
disposed = true;
window.clearTimeout(timeout);
controller.abort();
};
}, [open, attempt]);
return (
<>
<PlatformActionButton
tone="secondary"
size="sm"
shape="pill"
className="min-h-11 shrink-0 whitespace-nowrap"
onClick={() => {
setState({ status: 'loading' });
setOpen(true);
}}
>
<Download className="h-4 w-4" aria-hidden="true" />
下载客户端
</PlatformActionButton>
<UnifiedModal
open={open}
onClose={() => setOpen(false)}
title="下载陶泥儿客户端"
size="sm"
>
{state.status === 'loading' ? (
<PlatformStatusMessage tone="info" role="status">
正在获取最新版本…
</PlatformStatusMessage>
) : state.status === 'error' ? (
<div className="flex flex-col gap-4">
<PlatformStatusMessage tone="error" role="alert">
{DOWNLOAD_ERROR}
</PlatformStatusMessage>
<PlatformActionButton
onClick={() => setAttempt((value) => value + 1)}
>
重试
</PlatformActionButton>
</div>
) : (
<div className="flex flex-col gap-4">
{state.release.downloads.map((download) => (
<PlatformSubpanel
key={`${download.platform}-${download.architecture}`}
as="section"
aria-label={downloadLabel(download)}
padding="md"
radius="md"
>
<div className="mb-4 flex items-center gap-3">
<Monitor
className="h-7 w-7 shrink-0 text-[var(--platform-accent-strong)]"
aria-hidden="true"
/>
<div>
<p className="font-semibold text-[var(--platform-text-strong)]">
{downloadLabel(download)}
</p>
<p className="text-sm text-[var(--platform-text-soft)]">
最新版本 v{download.version}
</p>
</div>
</div>
<a
href={download.downloadUrl}
className={getPlatformActionButtonClassName({
size: 'md',
fullWidth: true,
})}
referrerPolicy="no-referrer"
>
<Download className="h-4 w-4 shrink-0" aria-hidden="true" />
{download.platform === 'windows'
? '下载 Windows 版'
: `下载 ${downloadLabel(download)}`}
</a>
</PlatformSubpanel>
))}
{state.release.downloads.length === 0 ? (
<PlatformStatusMessage tone="info" role="status">
暂无可下载版本
</PlatformStatusMessage>
) : null}
{state.release.unavailablePlatforms.length > 0 ? (
<PlatformStatusMessage tone="warning" role="alert">
{state.release.unavailablePlatforms
.map((platform) => platformNames[platform])
.join('、')}{' '}
版本暂时无法获取
</PlatformStatusMessage>
) : null}
{state.release.downloads.length === 0 ||
state.release.unavailablePlatforms.length > 0 ? (
<PlatformActionButton
tone="secondary"
onClick={() => setAttempt((value) => value + 1)}
>
重试
</PlatformActionButton>
) : null}
</div>
)}
</UnifiedModal>
</>
);
}
@@ -230,6 +230,7 @@ describe('PlatformEntryActiveFlowShell', () => {
);
expect(await screen.findByLabelText('泥点 207')).toBeTruthy();
expect(screen.getByRole('button', { name: '下载客户端' })).toBeTruthy();
rerender(
<PlatformEntryFlowShellImpl
@@ -484,6 +485,7 @@ describe('PlatformEntryActiveFlowShell', () => {
.map((button) => button.getAttribute('aria-label')),
).toEqual(['我的']);
expect(await screen.findByRole('main', { name: '我的' })).toBeTruthy();
expect(screen.getByRole('button', { name: '下载客户端' })).toBeTruthy();
expect(
within(navigation)
.getByRole('button', { name: '我的' })
@@ -30,6 +30,7 @@ import { useAuthUi } from '../auth/AuthUiContext';
import { FLOATING_FEEDBACK_FORM_URL } from '../common/floatingFeedbackEntryModel';
import { PlatformActionButton } from '../common/PlatformActionButton';
import { PlatformSubpanel } from '../common/PlatformSubpanel';
import { ClientDownloadEntry } from '../creation-home/ClientDownloadEntry';
import {
PlatformActiveMobileWelcomeDialog,
shouldOpenActiveMobileWelcomeDialog,
@@ -494,7 +495,7 @@ export function PlatformEntryFlowShellImpl({
</aside>
<div className="platform-desktop-main flex min-w-0 flex-1 flex-col">
<header className="platform-desktop-topbar flex min-h-16 shrink-0 items-center justify-between gap-1 px-4 sm:gap-3 sm:px-6">
<header className="platform-desktop-topbar flex min-h-16 shrink-0 flex-wrap items-center justify-between gap-1 gap-y-2 px-4 py-2 sm:flex-nowrap sm:gap-3 sm:px-6 sm:py-0">
<div className="min-w-0 shrink-0 lg:hidden">
<ActivePlatformBrand />
</div>
@@ -534,7 +535,8 @@ export function PlatformEntryFlowShellImpl({
</form>
</div>
<div className="platform-desktop-topbar__actions flex shrink-0 items-center gap-1 sm:gap-2 lg:gap-3">
<div className="platform-desktop-topbar__actions flex max-w-full shrink-0 flex-wrap items-center gap-1 sm:flex-nowrap sm:gap-2 lg:gap-3">
<ClientDownloadEntry />
{isAuthenticated ? (
<PlatformMudPointWalletEntry
variant={isDesktopLayout ? 'desktop' : 'mobile'}