Merge remote-tracking branch 'origin/master' into fix/agc-composer-layout
Project CI / AI game creator shell Rust lane 1/2 (pull_request) Successful in 7m3s
Project CI / AI game creator shell Rust lane 2/2 (pull_request) Successful in 5m24s
Project CI / AI game creator shell Rust crates (pull_request) Successful in 4m14s
Project CI / Frontend tests (pull_request) Successful in 3m48s
Project CI / Backend tests (pull_request) Successful in 8m5s
Project CI / AI game creator shell web tests (pull_request) Successful in 3m0s
Project CI / Repository checks (pull_request) Successful in 7m30s
Project CI / Native shell tests (pull_request) Successful in 9m44s
Project CI / AI game creator shell Rust lane 1/2 (pull_request) Successful in 7m3s
Project CI / AI game creator shell Rust lane 2/2 (pull_request) Successful in 5m24s
Project CI / AI game creator shell Rust crates (pull_request) Successful in 4m14s
Project CI / Frontend tests (pull_request) Successful in 3m48s
Project CI / Backend tests (pull_request) Successful in 8m5s
Project CI / AI game creator shell web tests (pull_request) Successful in 3m0s
Project CI / Repository checks (pull_request) Successful in 7m30s
Project CI / Native shell tests (pull_request) Successful in 9m44s
合并 master be9f74f42(付费游玩泥点付费规范 #635 等):保留双方条目/内容 - 唯一冲突:`docs/project-memory/shared-memory/pitfalls.md` —— 本分支 2 条(2026-10-05「PR #607 复核修复」+「模型菜单的观感是组件自带的共享样式面」)在前,master 新增 2 条(「给 shared-contracts 请求 DTO 加字段」+「付费游戏播放会话前缀落在 /api/*」)紧随其后,**两侧 4 条都保留**(grep 逐条命中 1) - 其余 286 个文件自动合并(master 侧含 server-rs / admin-web / 主站 / vite.config.ts 等,与本分支不重叠;`styles.css` 也是自动合并、无冲突) - 门禁(本轮只合并、未改内容):`vitest run appSurface + chatDialogFrameLayout + conversationModelSelect` **258 passed / 9 skipped**;`npm run agc:typecheck` pass 3 / fail 0;`npm run check:encoding` 5418 files;`git diff --check` rc=0;prettier 已对合并后的 pitfalls 重新折行
This commit is contained in:
@@ -1183,6 +1183,8 @@ export interface AdminGameDistributionReviewEntry {
|
||||
packageBytes: number;
|
||||
status: string;
|
||||
publicationRevision: number;
|
||||
/** 买断制泥点价格;0 表示免费。后端始终下发,旧响应可能缺该字段,读取方按 0 兜底。 */
|
||||
priceMudPoints?: number;
|
||||
reviewReason: string | null;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
@@ -1211,6 +1213,8 @@ export interface AdminGameDistributionGameDetail {
|
||||
orientation: string;
|
||||
status: string;
|
||||
publicationRevision: number;
|
||||
/** 买断制泥点价格;0 表示免费。后端始终下发,旧响应可能缺该字段,读取方按 0 兜底。 */
|
||||
priceMudPoints?: number;
|
||||
playCount: number;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
reviewAdminGameDistributionVersion,
|
||||
} from '../api/adminApiClient';
|
||||
import type {
|
||||
AdminGameDistributionGameDetail,
|
||||
AdminGameDistributionGameListResponse,
|
||||
AdminGameDistributionReviewEntry,
|
||||
AdminGameDistributionVersionDetailResponse,
|
||||
@@ -50,6 +51,7 @@ const entry: AdminGameDistributionReviewEntry = {
|
||||
packageBytes: 2048,
|
||||
status: 'pending_review',
|
||||
publicationRevision: 4,
|
||||
priceMudPoints: 30,
|
||||
reviewReason: null,
|
||||
// 真实后台下发的是 `seconds.microsZ`(非 ISO 8601),见 shared-kernel `format_timestamp_micros`。
|
||||
createdAt: '1791008678.817257Z',
|
||||
@@ -94,6 +96,7 @@ const detailResponse: AdminGameDistributionVersionDetailResponse = {
|
||||
orientation: 'landscape',
|
||||
status: 'unpublished',
|
||||
publicationRevision: 7,
|
||||
priceMudPoints: 30,
|
||||
playCount: 0,
|
||||
createdAt: '2026-09-20T08:00:00Z',
|
||||
},
|
||||
@@ -230,7 +233,8 @@ test('提交时间列把后端的 seconds.microsZ 渲染成可读本地时间',
|
||||
|
||||
const row = screen.getByText(gameTitle).closest('tr');
|
||||
expect(row).not.toBeNull();
|
||||
const submittedCell = within(row as HTMLElement).getAllByRole('cell')[3];
|
||||
// 列序:游戏 / 版本 / 发行包 / 价格 / 提交时间 / 审核。
|
||||
const submittedCell = within(row as HTMLElement).getAllByRole('cell')[4];
|
||||
// 解析不出来时会回落到 `-`,这正是本次修复前的线上表现。
|
||||
expect(submittedCell?.textContent).not.toBe('-');
|
||||
expect(submittedCell?.textContent).toMatch(
|
||||
@@ -238,6 +242,56 @@ test('提交时间列把后端的 seconds.microsZ 渲染成可读本地时间',
|
||||
);
|
||||
});
|
||||
|
||||
test('价格列按买断制口径展示,免费与缺失价格都不显示 NaN', async () => {
|
||||
const freeEntry: AdminGameDistributionReviewEntry = {
|
||||
...entry,
|
||||
versionId: 'version-2',
|
||||
gameId: 'game_2',
|
||||
versionNumber: 1,
|
||||
priceMudPoints: 0,
|
||||
};
|
||||
// 旧响应可能完全没有该字段;列表必须回落到“免费”而不是 NaN。
|
||||
const legacyEntry = {
|
||||
...entry,
|
||||
versionId: 'version-3',
|
||||
gameId: 'game_3',
|
||||
versionNumber: 3,
|
||||
priceMudPoints: undefined,
|
||||
} as unknown as AdminGameDistributionReviewEntry;
|
||||
vi.mocked(listAdminGameDistributionReviews).mockResolvedValue({
|
||||
entries: [entry, freeEntry, legacyEntry],
|
||||
nextCursor: null,
|
||||
});
|
||||
|
||||
render(
|
||||
<AdminGameDistributionReviewPage
|
||||
token="admin-token"
|
||||
onUnauthorized={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
await screen.findByText(gameTitle);
|
||||
|
||||
const table = screen.getByText(gameTitle).closest('table');
|
||||
expect(table).not.toBeNull();
|
||||
// 按列名定位:绑「第 4 个格子」的话,任何插列或换序都会读到别的字段,断言随之失效。
|
||||
const priceColumnIndex = within(table as HTMLElement)
|
||||
.getAllByRole('columnheader')
|
||||
.findIndex((header) => header.textContent?.trim() === '价格');
|
||||
expect(priceColumnIndex).toBeGreaterThanOrEqual(0);
|
||||
|
||||
const cellAt = (text: string) => {
|
||||
const row = screen.getByText(text).closest('tr');
|
||||
expect(row).not.toBeNull();
|
||||
return within(row as HTMLElement).getAllByRole('cell')[priceColumnIndex]
|
||||
?.textContent;
|
||||
};
|
||||
|
||||
// 三行三态都按精确文案钉死:付费、免费与旧响应缺字段都不能渲染成 NaN。
|
||||
expect(cellAt(gameTitle)).toBe('30 泥点');
|
||||
expect(cellAt('game_2')).toBe('免费');
|
||||
expect(cellAt('game_3')).toBe('免费');
|
||||
});
|
||||
|
||||
test('取消理由输入时不做审核操作', async () => {
|
||||
render(
|
||||
<AdminGameDistributionReviewPage
|
||||
@@ -300,6 +354,9 @@ test('详情展示发布者和冻结资料,并试玩当前待审版本', async
|
||||
fireEvent.click(screen.getByRole('button', { name: '详情' }));
|
||||
expect((await screen.findAllByText(/测试作者/u)).length).toBeGreaterThan(0);
|
||||
expect(screen.getByText('测试详细介绍')).toBeTruthy();
|
||||
// 详情资料区展示买断制价格(0 或缺字段按“免费”)。
|
||||
expect(screen.getByText('价格')).toBeTruthy();
|
||||
expect(screen.getByText('30 泥点')).toBeTruthy();
|
||||
fireEvent.click(screen.getByRole('button', { name: '试玩当前待审版本' }));
|
||||
const frame = await screen.findByTitle('测试游戏 待审版本试玩');
|
||||
expect(frame.getAttribute('src')).toBe(
|
||||
@@ -372,7 +429,6 @@ test('试玩加载超过上限后给出超时说明与重建会话入口', async
|
||||
expiresAt: '2026-10-02T12:20:00Z',
|
||||
versionId: 'version-1',
|
||||
});
|
||||
|
||||
render(
|
||||
<AdminGameDistributionReviewPage
|
||||
token="admin-token"
|
||||
@@ -415,3 +471,60 @@ test('试玩加载超过上限后给出超时说明与重建会话入口', async
|
||||
vi.useRealTimers();
|
||||
}
|
||||
});
|
||||
|
||||
test('详情价格只渲染服务端下发的 priceMudPoints,不按冻结资料二次取价', async () => {
|
||||
vi.mocked(getAdminGameDistributionVersion).mockResolvedValue({
|
||||
// 服务端 `version_detail_payload` 已把「待审版本冻结价优先、缺字段按 0」归一写进
|
||||
// `game.priceMudPoints`,审核页只渲染这个字段。
|
||||
game: { ...detailResponse.game, priceMudPoints: 30 },
|
||||
version: {
|
||||
...detailResponse.version,
|
||||
// 对抗用例:冻结资料里的价格与服务端归一结果故意不同(999 ≠ 30)。客户端若自行
|
||||
// 复刻「冻结价优先」,就会显示 999 —— 这里必须仍然是服务端字段的 30。
|
||||
frozenMetadata: { title: '测试游戏', priceMudPoints: 999 },
|
||||
},
|
||||
});
|
||||
|
||||
render(
|
||||
<AdminGameDistributionReviewPage
|
||||
token="admin-token"
|
||||
onUnauthorized={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
await screen.findByText(gameTitle);
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: '详情' }));
|
||||
expect((await screen.findAllByText(/测试作者/u)).length).toBeGreaterThan(0);
|
||||
|
||||
expect(screen.getByText('价格')).toBeTruthy();
|
||||
expect(screen.getByText('30 泥点')).toBeTruthy();
|
||||
expect(screen.queryByText('999 泥点')).toBeNull();
|
||||
expect(screen.queryByText('免费')).toBeNull();
|
||||
});
|
||||
|
||||
test('旧版本冻结资料没有价格时按免费回落', async () => {
|
||||
vi.mocked(getAdminGameDistributionVersion).mockResolvedValue({
|
||||
game: {
|
||||
...detailResponse.game,
|
||||
priceMudPoints: undefined,
|
||||
} as unknown as AdminGameDistributionGameDetail,
|
||||
version: {
|
||||
...detailResponse.version,
|
||||
frozenMetadata: { title: '测试游戏' },
|
||||
},
|
||||
});
|
||||
|
||||
render(
|
||||
<AdminGameDistributionReviewPage
|
||||
token="admin-token"
|
||||
onUnauthorized={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
await screen.findByText(gameTitle);
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: '详情' }));
|
||||
expect((await screen.findAllByText(/测试作者/u)).length).toBeGreaterThan(0);
|
||||
|
||||
expect(screen.getByText('免费')).toBeTruthy();
|
||||
expect(screen.queryByText(/NaN/u)).toBeNull();
|
||||
});
|
||||
|
||||
@@ -100,6 +100,8 @@ function applyFrozenGameMetadata(
|
||||
typeof metadata.orientation === 'string'
|
||||
? metadata.orientation
|
||||
: game.orientation,
|
||||
// 价格不在这里二次叠加:服务端 `version_detail_payload` 已按「版本冻结价优先、
|
||||
// 缺字段按 0」把结果归一写进 `game.priceMudPoints`,客户端直接沿用该字段。
|
||||
};
|
||||
}
|
||||
|
||||
@@ -113,6 +115,11 @@ function formatBytes(value: number) {
|
||||
return `${value} B`;
|
||||
}
|
||||
|
||||
/** 买断制价格口径:0 或缺失(旧响应 / undefined)都按“免费”展示,避免出现 NaN。 */
|
||||
function formatPriceMudPoints(value: number | null | undefined) {
|
||||
return typeof value === 'number' && value > 0 ? `${value} 泥点` : '免费';
|
||||
}
|
||||
|
||||
function createReviewIdempotencyKey(versionId: string) {
|
||||
const random =
|
||||
typeof crypto !== 'undefined' && 'randomUUID' in crypto
|
||||
@@ -439,6 +446,7 @@ export function AdminGameDistributionReviewPage({
|
||||
{ key: 'gameId', label: '游戏' },
|
||||
{ key: 'versionNumber', label: '版本' },
|
||||
{ key: 'packageBytes', label: '发行包' },
|
||||
{ key: 'priceMudPoints', label: '价格' },
|
||||
{ key: 'createdAt', label: '提交时间' },
|
||||
{ key: 'actions', label: '审核' },
|
||||
]}
|
||||
@@ -484,6 +492,7 @@ export function AdminGameDistributionReviewPage({
|
||||
<code>{entry.packageSha256.slice(0, 12)}</code>
|
||||
</div>
|
||||
</td>
|
||||
<td>{formatPriceMudPoints(entry.priceMudPoints)}</td>
|
||||
<td>{formatAdminDateTime(entry.createdAt)}</td>
|
||||
<td className="admin-game-review-cell--actions">
|
||||
<AdminActionRow className="admin-review-actions">
|
||||
@@ -649,6 +658,10 @@ function AdminGameDistributionReviewDetailView({
|
||||
versionLabel={`v${detail.version.versionNumber}`}
|
||||
infoCards={[
|
||||
{ label: '状态', value: detail.version.status },
|
||||
{
|
||||
label: '价格',
|
||||
value: formatPriceMudPoints(detail.game.priceMudPoints),
|
||||
},
|
||||
{
|
||||
label: '提交时间',
|
||||
value: formatAdminDateTime(detail.version.createdAt),
|
||||
|
||||
@@ -27,14 +27,22 @@ table.admin-game-review-table td:nth-child(3) {
|
||||
width: 124px;
|
||||
}
|
||||
|
||||
/* 价格列:只展示「免费」或「N 泥点」,上限 1000000 泥点最长;给足宽度并允许换行,
|
||||
固定列宽 + overflow:hidden 下保持 nowrap 会把最大价硬裁掉。 */
|
||||
table.admin-game-review-table th:nth-child(4),
|
||||
table.admin-game-review-table td:nth-child(4) {
|
||||
width: 172px;
|
||||
white-space: nowrap;
|
||||
width: 120px;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
table.admin-game-review-table th:nth-child(5),
|
||||
table.admin-game-review-table td:nth-child(5) {
|
||||
width: 172px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
table.admin-game-review-table th:nth-child(6),
|
||||
table.admin-game-review-table td:nth-child(6) {
|
||||
width: 240px;
|
||||
}
|
||||
|
||||
@@ -100,7 +108,9 @@ table.admin-game-review-table td .admin-muted-text {
|
||||
table.admin-game-review-table th:nth-child(4),
|
||||
table.admin-game-review-table td:nth-child(4),
|
||||
table.admin-game-review-table th:nth-child(5),
|
||||
table.admin-game-review-table td:nth-child(5) {
|
||||
table.admin-game-review-table td:nth-child(5),
|
||||
table.admin-game-review-table th:nth-child(6),
|
||||
table.admin-game-review-table td:nth-child(6) {
|
||||
width: auto;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,9 @@ const PACKAGE_UPLOAD_PROGRESS_EVENT: &str = "game-package-upload-progress";
|
||||
/// JS `Number.MAX_SAFE_INTEGER`:版本号经 JSON number 传递,超过它就会丢精度。
|
||||
const MAX_SAFE_VERSION_NUMBER: u64 = 9_007_199_254_740_991;
|
||||
|
||||
/// 买断价上限(整数泥点),与服务端 `MAX_GAME_PRICE_MUD_POINTS` 及前端共享常量一致。
|
||||
const MAX_GAME_PRICE_MUD_POINTS: u64 = 1_000_000;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct GameDistributionPublishResult {
|
||||
@@ -101,6 +104,12 @@ pub(crate) struct GameDistributionPublicationDraft {
|
||||
pub(crate) input_modes: Vec<GameDistributionInputMode>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub(crate) orientation: Option<GameDistributionOrientation>,
|
||||
/// 更新面板预填的买断价(整数泥点,`0` 表示免费):取该作品**最近版本的冻结价**
|
||||
/// (该版本可能仍处于 `pending_review` / `rejected`,因此预填值未必已生效);该版本
|
||||
/// 冻结价缺失或为 `0` 时回落游戏行当前生效价,两条来源都取不到才按 `0`(免费),
|
||||
/// 避免把已上线的付费作品预填成免费。旧原生响应缺该字段时按免费兜底。
|
||||
#[serde(default)]
|
||||
pub(crate) price_mud_points: u64,
|
||||
}
|
||||
|
||||
/// 发布面板打开时的发布状态回读。
|
||||
@@ -121,6 +130,13 @@ pub(crate) struct GameDistributionPublicationReadResult {
|
||||
pub(crate) draft: Option<GameDistributionPublicationDraft>,
|
||||
#[serde(default)]
|
||||
pub(crate) visibility: Option<String>,
|
||||
/// 平台侧这次发布实际会用的版本号(作者视图已有版本的最大 `versionNumber + 1`)。
|
||||
///
|
||||
/// 首次发布会新建作品,服务端从 `1` 开始派发,所以这里也是 `1`。拿不到平台数据的路径
|
||||
/// (`unavailable`、以及「有本地绑定但没能刷新线上状态」)不下发:渲染层不得回落到本地工程
|
||||
/// 迭代计数,只能据此禁用提交。
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub(crate) next_version_number: Option<u64>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub(crate) message: Option<String>,
|
||||
}
|
||||
@@ -229,12 +245,22 @@ struct OwnerGameEntry {
|
||||
publication_revision: u64,
|
||||
#[serde(default)]
|
||||
latest_version: Option<OwnerGameVersion>,
|
||||
/// 该作者作品的版本列表(作者自有视图按最近更新倒序、单游戏最多 10 条)。
|
||||
///
|
||||
/// 平台只在客户端不传版本号时按 `max_existing + 1` 自动派发,所以「下一个版本号」必须取这里
|
||||
/// 已下发版本的最大 `versionNumber`;`latestVersion` 是最近**更新**的那条(可能是被改过状态的
|
||||
/// 历史版本),单靠它或本地工程迭代计数都会推出重复 / 回退的版本号。
|
||||
#[serde(default)]
|
||||
versions: Vec<OwnerGameVersion>,
|
||||
#[serde(default)]
|
||||
device_support: Option<GameDistributionDeviceSupport>,
|
||||
#[serde(default)]
|
||||
input_modes: Vec<String>,
|
||||
#[serde(default)]
|
||||
orientation: Option<String>,
|
||||
/// 游戏行当前生效的买断价(作者自有视图的 `priceMudPoints`)。
|
||||
#[serde(default)]
|
||||
price_mud_points: u64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Deserialize)]
|
||||
@@ -245,6 +271,9 @@ struct OwnerGameVersion {
|
||||
version_number: u64,
|
||||
#[serde(default)]
|
||||
status: String,
|
||||
/// 该版本审核通过后冻结的买断价;历史版本缺省为 `0`。
|
||||
#[serde(default)]
|
||||
price_mud_points: u64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
@@ -426,11 +455,19 @@ fn normalized_origin(value: &str) -> String {
|
||||
value.trim().trim_end_matches('/').to_string()
|
||||
}
|
||||
|
||||
fn metadata_digest(metadata: &GameDistributionCreateGameRequest) -> Result<String, String> {
|
||||
/// 发布资料摘要:随版本冻结的资料与买断价一起参与。
|
||||
///
|
||||
/// 价格必须进摘要:同一份包、同一版本标签只改价格时,幂等账本必须换键,否则会重放上一次
|
||||
/// 尝试的收据,把作者改后的价格静默丢掉。
|
||||
fn metadata_digest(
|
||||
metadata: &GameDistributionCreateGameRequest,
|
||||
price_mud_points: u64,
|
||||
) -> Result<String, String> {
|
||||
let bytes =
|
||||
serde_json::to_vec(metadata).map_err(|error| format!("计算发布资料摘要失败:{error}"))?;
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(&bytes);
|
||||
hasher.update(price_mud_points.to_le_bytes());
|
||||
Ok(format!("{:x}", hasher.finalize()))
|
||||
}
|
||||
|
||||
@@ -508,6 +545,8 @@ fn first_publish_state(message: Option<String>) -> GameDistributionPublicationRe
|
||||
refreshed: true,
|
||||
draft: None,
|
||||
visibility: None,
|
||||
// 首次发布会新建作品,平台自己也从 `1` 派发这一版的版本号。
|
||||
next_version_number: Some(1),
|
||||
message,
|
||||
}
|
||||
}
|
||||
@@ -519,15 +558,35 @@ fn unavailable_state(message: Option<String>) -> GameDistributionPublicationRead
|
||||
refreshed: false,
|
||||
draft: None,
|
||||
visibility: None,
|
||||
// 拿不到平台数据就不给版本号:渲染层据此禁用提交,不得回落到本地工程迭代计数。
|
||||
next_version_number: None,
|
||||
message,
|
||||
}
|
||||
}
|
||||
|
||||
/// 平台侧这次发布会用的版本号:作者视图里该作品已有版本的最大 `versionNumber + 1`。
|
||||
///
|
||||
/// 与平台自身的派发口径一致(`module-game-distribution::resolve_version_number` 的
|
||||
/// `max_existing + 1`)。`latestVersion` 只是最近更新的一条,必须与版本列表一起取最大值。
|
||||
/// 作者视图单游戏最多下发 10 条版本(`GAME_DISTRIBUTION_MAX_OWNER_VERSIONS_PER_GAME`):
|
||||
/// 号最大的那条被挤出列表时会低估一个已经存在的版本号,这是当前作者视图的取数边界。
|
||||
fn resolve_owner_next_version_number(entry: &OwnerGameEntry) -> u64 {
|
||||
entry
|
||||
.versions
|
||||
.iter()
|
||||
.chain(entry.latest_version.iter())
|
||||
.map(|version| version.version_number)
|
||||
.max()
|
||||
.unwrap_or(0)
|
||||
.saturating_add(1)
|
||||
}
|
||||
|
||||
/// 回写发布绑定;本地遗留的 `projectVersion` 一并清空。
|
||||
///
|
||||
/// 绑定本身已按当前会话(账号 + origin)与 gameId 隔离。项目版本标签不再从绑定推导(它由
|
||||
/// AGC 工程内部版本 `versions[]` 派生、只读),所以这里只落绑定,并把存量清单里可能残留的
|
||||
/// 遗留标签置空——`skip_serializing_if` 会让该键随下一次落盘消失。
|
||||
/// 绑定本身已按当前会话(账号 + origin)与 gameId 隔离。项目版本标签不从绑定推导,也不来自
|
||||
/// AGC 工程内部版本:它取平台作者视图里该作品的最大版本号 + 1(发布时显式提交同一个值),
|
||||
/// 所以这里只落绑定,并把存量清单里可能残留的遗留标签置空——`skip_serializing_if` 会让该键
|
||||
/// 随下一次落盘消失。
|
||||
fn write_publication_binding(
|
||||
root: &Path,
|
||||
binding: GameCreationAppPublicationBinding,
|
||||
@@ -781,9 +840,21 @@ async fn build_publication_draft(
|
||||
device_support,
|
||||
input_modes: parse_input_modes(input_modes),
|
||||
orientation: parse_orientation(orientation),
|
||||
price_mud_points: resolve_publication_prefill_price(entry),
|
||||
}
|
||||
}
|
||||
|
||||
/// 更新面板预填的买断价:优先取最近版本的冻结价(与网页更新模式同源),该版本历史无价格时
|
||||
/// 回退游戏行当前价。两条来源都拿不到才按 `0`(免费),避免把已上线的付费作品预填成免费。
|
||||
fn resolve_publication_prefill_price(entry: &OwnerGameEntry) -> u64 {
|
||||
entry
|
||||
.latest_version
|
||||
.as_ref()
|
||||
.map(|version| version.price_mud_points)
|
||||
.filter(|price| *price > 0)
|
||||
.unwrap_or(entry.price_mud_points)
|
||||
}
|
||||
|
||||
async fn bound_publication_result(
|
||||
client: &reqwest::Client,
|
||||
snapshot: &PlatformSessionSnapshot,
|
||||
@@ -820,6 +891,7 @@ async fn bound_publication_result(
|
||||
refreshed: true,
|
||||
draft: Some(draft),
|
||||
visibility: Some(entry.status.clone()).filter(|status| !status.is_empty()),
|
||||
next_version_number: Some(resolve_owner_next_version_number(&entry)),
|
||||
message: None,
|
||||
})
|
||||
}
|
||||
@@ -872,12 +944,14 @@ pub(crate) async fn read_game_distribution_publication(
|
||||
}
|
||||
Err(GameDistributionReadError::Unavailable(message)) => {
|
||||
// 结果未知:保留本地绑定,按更新模式返回但标注未刷新,由发布时的 CAS 兜底。
|
||||
// 这一路没有平台版本数据,所以不给版本号:渲染层禁用提交,等下一次刷新成功。
|
||||
Ok(GameDistributionPublicationReadResult {
|
||||
state: "update".to_string(),
|
||||
binding: Some(binding),
|
||||
refreshed: false,
|
||||
draft: None,
|
||||
visibility: None,
|
||||
next_version_number: None,
|
||||
message: Some(format!("无法刷新线上状态:{message}")),
|
||||
})
|
||||
}
|
||||
@@ -1237,6 +1311,8 @@ pub(crate) async fn publish_local_project_game(
|
||||
version_number: Option<u64>,
|
||||
expected_publication_revision: Option<u64>,
|
||||
idempotency_key: Option<String>,
|
||||
// 买断价(整数泥点,`0` 表示免费)。旧前端不传时为 `None`,按免费提交,保持向后兼容。
|
||||
price_mud_points: Option<u64>,
|
||||
) -> Result<GameDistributionPublishResult, String> {
|
||||
let snapshot = require_platform_session()?;
|
||||
let app_data_dir = app
|
||||
@@ -1283,7 +1359,12 @@ pub(crate) async fn publish_local_project_game(
|
||||
if target_game_id.is_some() && expected_publication_revision.is_none() {
|
||||
return Err("缺少公开修订号,请重新打开发布面板后再试".to_string());
|
||||
}
|
||||
let digest = metadata_digest(&metadata)?;
|
||||
// 买断价只允许 `0..=上限`;面板已按同一口径拦住非法输入,这里对命令边界再收一次口。
|
||||
let price_mud_points = price_mud_points.unwrap_or(0);
|
||||
if price_mud_points > MAX_GAME_PRICE_MUD_POINTS {
|
||||
return Err(format!("买断价不能超过 {MAX_GAME_PRICE_MUD_POINTS} 泥点"));
|
||||
}
|
||||
let digest = metadata_digest(&metadata, price_mud_points)?;
|
||||
// 根幂等键由账本按「账号 + origin + 本地项目 + 包摘要 + 目标游戏/版本 + 资料摘要」解析:
|
||||
// 同一份包重发、响应丢失后重试、进程重启后的分片续传都落在同一次服务端尝试上;
|
||||
// 包内容、目标版本标签或资料任一变化都换键,新标签的提交不会被幂等收据吞掉。
|
||||
@@ -1360,6 +1441,8 @@ pub(crate) async fn publish_local_project_game(
|
||||
package_file_count: staged.package_file_count,
|
||||
package_entry_path: "index.html".to_string(),
|
||||
version_number,
|
||||
// 买断价随版本冻结;面板已本地校验,这里透传服务端口径的整数泥点。
|
||||
price_mud_points,
|
||||
game_metadata: metadata,
|
||||
};
|
||||
let version_value = request_json(
|
||||
@@ -1482,7 +1565,8 @@ pub(crate) async fn publish_local_project_game(
|
||||
}
|
||||
});
|
||||
// 发布成功:把平台作品绑定和最近版本状态写回本地清单。项目版本标签不在这里对齐——它由
|
||||
// 工程内部版本派生,这次提交的平台版本号不回写本地(遗留 `projectVersion` 一并清空)。
|
||||
// 平台作者视图的最大版本号 + 1 推出、在提交前已经决定了下一次要用的值(遗留 `projectVersion`
|
||||
// 一并清空)。
|
||||
// 写回失败不回滚已经成功的发布,但会把错误交给作者——否则下次打开项目会退回首次发布,
|
||||
// 甚至可能重复建作品。
|
||||
let binding = GameCreationAppPublicationBinding {
|
||||
@@ -1495,7 +1579,7 @@ pub(crate) async fn publish_local_project_game(
|
||||
status: Some(status.clone()),
|
||||
};
|
||||
let manifest = crate::project::mutate_manifest_at(root, |manifest| {
|
||||
// 项目版本标签由工程内部版本派生,不由这次提交的平台版本号回写;遗留位一并清空。
|
||||
// 项目版本标签由平台作者视图派生并在提交前传下去,不由这次提交的平台版本号回写;遗留位一并清空。
|
||||
manifest.project_version = None;
|
||||
manifest.publication = Some(binding.clone());
|
||||
Ok(manifest.clone())
|
||||
@@ -1631,11 +1715,13 @@ mod tests {
|
||||
orientation:
|
||||
shared_contracts::game_distribution::GameDistributionOrientation::Responsive,
|
||||
};
|
||||
let first = metadata_digest(&metadata).expect("digest");
|
||||
let first = metadata_digest(&metadata, 0).expect("digest");
|
||||
assert_eq!(first.len(), 64);
|
||||
assert_eq!(metadata_digest(&metadata).expect("stable"), first);
|
||||
assert_eq!(metadata_digest(&metadata, 0).expect("stable"), first);
|
||||
// 只改价格的提交必须换幂等键:否则账本会重放上一次收据,静默丢掉改价。
|
||||
assert_ne!(metadata_digest(&metadata, 120).expect("priced"), first);
|
||||
metadata.title = "新标题".to_string();
|
||||
assert_ne!(metadata_digest(&metadata).expect("changed"), first);
|
||||
assert_ne!(metadata_digest(&metadata, 0).expect("changed"), first);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1647,20 +1733,115 @@ mod tests {
|
||||
"summary": "守住轨道城",
|
||||
"status": "published",
|
||||
"publicationRevision": 4,
|
||||
"priceMudPoints": 240,
|
||||
"latestVersion": {
|
||||
"versionId": "gamever-2",
|
||||
"versionNumber": 2,
|
||||
"status": "pending_review"
|
||||
}
|
||||
"status": "pending_review",
|
||||
"priceMudPoints": 300
|
||||
},
|
||||
"versions": [
|
||||
{
|
||||
"versionId": "gamever-2",
|
||||
"versionNumber": 2,
|
||||
"status": "pending_review",
|
||||
"priceMudPoints": 300
|
||||
},
|
||||
{
|
||||
"versionId": "gamever-5",
|
||||
"versionNumber": 5,
|
||||
"status": "published",
|
||||
"priceMudPoints": 0
|
||||
}
|
||||
]
|
||||
}))
|
||||
.expect("owner entry");
|
||||
assert_eq!(entry.id, "game-1");
|
||||
assert_eq!(entry.local_project_id.as_deref(), Some("proj-1"));
|
||||
assert_eq!(entry.publication_revision, 4);
|
||||
assert_eq!(entry.price_mud_points, 240);
|
||||
assert_eq!(entry.versions.len(), 2);
|
||||
let latest = entry.latest_version.expect("latest version");
|
||||
assert_eq!(latest.version_id, "gamever-2");
|
||||
assert_eq!(latest.version_number, 2);
|
||||
assert_eq!(latest.status, "pending_review");
|
||||
assert_eq!(latest.price_mud_points, 300);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn next_version_number_follows_platform_maximum_not_latest_or_local_count() {
|
||||
// 作者视图按最近更新倒序:`latestVersion` 是 v2(最近被改过状态),列表里号最大的是 v5。
|
||||
// 平台派发口径是 max_existing + 1,所以下一个版本号必须是 6,不能是 2 + 1。
|
||||
let entry = OwnerGameEntry {
|
||||
latest_version: Some(OwnerGameVersion {
|
||||
version_number: 2,
|
||||
..Default::default()
|
||||
}),
|
||||
versions: vec![
|
||||
OwnerGameVersion {
|
||||
version_number: 2,
|
||||
..Default::default()
|
||||
},
|
||||
OwnerGameVersion {
|
||||
version_number: 5,
|
||||
..Default::default()
|
||||
},
|
||||
],
|
||||
..Default::default()
|
||||
};
|
||||
assert_eq!(resolve_owner_next_version_number(&entry), 6);
|
||||
|
||||
// 没有任何版本记录的作品:平台会从 1 开始派发。
|
||||
assert_eq!(
|
||||
resolve_owner_next_version_number(&OwnerGameEntry::default()),
|
||||
1
|
||||
);
|
||||
|
||||
// 列表被条数上限截断、只带回旧版本时也只能按已下发的最大值推出(取数边界见函数注释)。
|
||||
let truncated = OwnerGameEntry {
|
||||
latest_version: None,
|
||||
versions: vec![OwnerGameVersion {
|
||||
version_number: 1,
|
||||
..Default::default()
|
||||
}],
|
||||
..Default::default()
|
||||
};
|
||||
assert_eq!(resolve_owner_next_version_number(&truncated), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn publication_prefill_price_prefers_latest_frozen_price_and_falls_back() {
|
||||
// 最新版本冻结价 > 0:与网页更新模式同源,直接用它。
|
||||
let paid = OwnerGameEntry {
|
||||
price_mud_points: 240,
|
||||
latest_version: Some(OwnerGameVersion {
|
||||
price_mud_points: 300,
|
||||
..Default::default()
|
||||
}),
|
||||
..Default::default()
|
||||
};
|
||||
assert_eq!(resolve_publication_prefill_price(&paid), 300);
|
||||
|
||||
// 历史版本没有冻结价(0):回退游戏行当前价,避免把已上线的付费作品预填成免费。
|
||||
let legacy = OwnerGameEntry {
|
||||
price_mud_points: 240,
|
||||
latest_version: Some(OwnerGameVersion::default()),
|
||||
..Default::default()
|
||||
};
|
||||
assert_eq!(resolve_publication_prefill_price(&legacy), 240);
|
||||
|
||||
// 免费作品、以及完全缺该字段的旧响应,都按 0(免费)。
|
||||
assert_eq!(
|
||||
resolve_publication_prefill_price(&OwnerGameEntry::default()),
|
||||
0
|
||||
);
|
||||
let legacy_entry = parse_owner_game_entry(json!({
|
||||
"id": "game-2",
|
||||
"title": "免费游戏",
|
||||
"latestVersion": { "versionId": "v1", "versionNumber": 1, "status": "published" }
|
||||
}))
|
||||
.expect("legacy owner entry");
|
||||
assert_eq!(resolve_publication_prefill_price(&legacy_entry), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -36,8 +36,8 @@ struct GamePublishAttemptRecord {
|
||||
/// 目标游戏身份:更新已有作品时非空;首次发布为空。
|
||||
#[serde(default)]
|
||||
target_game_id: Option<String>,
|
||||
/// 这次发布提交的项目版本标签(由清单 `versions[]` 的条数派生,不由 `projectVersion`
|
||||
/// 这种遗留兼容位提供):换了标签就是一次新尝试。
|
||||
/// 这次发布提交的平台版本号(作者视图里该作品的最大版本号 + 1,首次发布为 `1`;
|
||||
/// 不由清单 `versions[]` 的条数或遗留 `projectVersion` 位提供):换了版本号就是一次新尝试。
|
||||
#[serde(default)]
|
||||
target_version_number: Option<u64>,
|
||||
/// 随版本冻结的资料摘要:同一份包换了资料修订也必须换根键,不能只按 ZIP 摘要吞掉新发布。
|
||||
|
||||
@@ -207,9 +207,9 @@ fn validate_manifest_cocos_project_root(value: Option<&str>) -> Result<(), Strin
|
||||
|
||||
/// 遗留字段 `projectVersion` 的取值范围:缺省合法(旧清单),写了就必须是正整数。
|
||||
///
|
||||
/// 它**不参与**发布版本标签的推导(标签由 `versions[]` 的条数派生),只是为了让存量清单继续
|
||||
/// 可读。`0` 不是"未设置"的别名——未设置就是字段缺失;一旦落盘 0 会被当成非法值,所以在读
|
||||
/// 写两侧都失败关闭,避免坏值被静默传播。
|
||||
/// 它**不参与**发布版本号的推导(版本号取平台作者视图里该作品的最大版本号 + 1),只是为了让
|
||||
/// 存量清单继续可读。`0` 不是"未设置"的别名——未设置就是字段缺失;一旦落盘 0 会被当成非法值,
|
||||
/// 所以在读写两侧都失败关闭,避免坏值被静默传播。
|
||||
fn validate_manifest_project_version(value: Option<u64>) -> Result<(), String> {
|
||||
if value == Some(0) {
|
||||
return Err("manifest projectVersion 必须是大于 0 的整数".to_string());
|
||||
|
||||
+87
-22
@@ -1,10 +1,12 @@
|
||||
import { Eye, Trash2 } from 'lucide-react';
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
|
||||
import {
|
||||
type GameCreationAppManifest,
|
||||
resolveGameCreationAppProjectVersion,
|
||||
} from '../../../../../packages/shared/src/contracts/gameCreationApp';
|
||||
PlatformGamePricingField,
|
||||
type PlatformGamePricingMode,
|
||||
resolvePlatformGamePriceMudPoints,
|
||||
} from '@genarrative/shared/components';
|
||||
import { Eye, Trash2 } from 'lucide-react';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
|
||||
import { type GameCreationAppManifest } from '../../../../../packages/shared/src/contracts/gameCreationApp';
|
||||
import { GAME_DISTRIBUTION_CATEGORIES } from '../../../../../packages/shared/src/contracts/gameDistribution';
|
||||
import { IMAGE_MODEL_GPT_IMAGE_2 } from '../../../../../src/components/image-editor/ImageCanvasGenerationModel';
|
||||
import { resolveTauriInvoke } from '../../app/tauri';
|
||||
@@ -237,6 +239,10 @@ export function GameDistributionPublishPanel({
|
||||
const [summary, setSummary] = useState('');
|
||||
const [category, setCategory] =
|
||||
useState<GameDistributionPublishMetadata['category']>('其他');
|
||||
/** 付费方式与买断价输入;校验口径与网页、服务端一致。 */
|
||||
const [priceMode, setPriceMode] = useState<PlatformGamePricingMode>('free');
|
||||
const [priceInput, setPriceInput] = useState('');
|
||||
const [priceError, setPriceError] = useState('');
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const [result, setResult] = useState<GameDistributionPublishResult | null>(
|
||||
@@ -270,14 +276,15 @@ export function GameDistributionPublishPanel({
|
||||
/** 线上最近提交的版本号;首次发布为 0(没有线上版本)。 */
|
||||
const [latestVersionNumber, setLatestVersionNumber] = useState(0);
|
||||
/**
|
||||
* 面板展示并提交的「项目版本」:AGC 工程内部版本序数,唯一来源是清单的 `versions[]`。
|
||||
* 平台侧这次发布会用的版本号:作者视图里该作品已有版本的最大 `versionNumber + 1`
|
||||
* (首次发布为 `1`),由原生回读下发。
|
||||
*
|
||||
* 只读派生值,不是可编辑 state:用户不能改,平台版本号也改不了它。每次智能体修订追加一条
|
||||
* 内部版本,这个值随之推进。
|
||||
* `null` = 还没拿到平台数据(恢复失败、或更新模式没能刷新线上状态):这时不允许提交,
|
||||
* 也不回落到 AGC 工程内部版本 `versions[]` 的条数——那是本地迭代计数,会提交重复 /
|
||||
* 回退的平台版本号。面板展示的值与提交的值都只取这一个来源。
|
||||
*/
|
||||
const projectVersion = useMemo(
|
||||
() => resolveGameCreationAppProjectVersion(manifest),
|
||||
[manifest],
|
||||
const [nextVersionNumber, setNextVersionNumber] = useState<number | null>(
|
||||
null,
|
||||
);
|
||||
const metadataSuggestionRequestRef = useRef(0);
|
||||
const publicationRequestRef = useRef(0);
|
||||
@@ -304,6 +311,9 @@ export function GameDistributionPublishPanel({
|
||||
setTitle(manifest.name.trim());
|
||||
setSummary(fallbackSummary);
|
||||
setCategory('其他');
|
||||
setPriceMode('free');
|
||||
setPriceInput('');
|
||||
setPriceError('');
|
||||
setCover(null);
|
||||
setScreenshots([]);
|
||||
setBusy(false);
|
||||
@@ -320,6 +330,7 @@ export function GameDistributionPublishPanel({
|
||||
setPublicationRefreshed(false);
|
||||
setPublicationMessage('');
|
||||
setLatestVersionNumber(0);
|
||||
setNextVersionNumber(null);
|
||||
summaryTouchedRef.current = false;
|
||||
categoryTouchedRef.current = false;
|
||||
publicationDraftAppliedRef.current = false;
|
||||
@@ -359,7 +370,8 @@ export function GameDistributionPublishPanel({
|
||||
// 面板据此禁用提交而不是退化成首次发布。
|
||||
const invoke = resolveTauriInvoke();
|
||||
if (!invoke) {
|
||||
// 非 Tauri 宿主:没有可恢复的原生状态,交给提交时的失败提示兜底。
|
||||
// 非 Tauri 宿主:没有可恢复的原生状态,也就拿不到平台版本号——按首次发布展示表单,
|
||||
// 提交按钮因为版本号未知保持禁用(发布本身也需要原生宿主)。
|
||||
setPublicationState('first-publish');
|
||||
return;
|
||||
}
|
||||
@@ -375,8 +387,15 @@ export function GameDistributionPublishPanel({
|
||||
);
|
||||
return;
|
||||
}
|
||||
// 版本号只认原生按平台作者视图推出来的值;缺字段(旧原生端 / 没刷新成功)就保持未知。
|
||||
const platformNextVersion = recovery.nextVersionNumber;
|
||||
setNextVersionNumber(
|
||||
typeof platformNextVersion === 'number' && platformNextVersion > 0
|
||||
? platformNextVersion
|
||||
: null,
|
||||
);
|
||||
if (recovery.state === 'update') {
|
||||
// 线上最近提交的版本号只用于展示平台侧事实;面板的项目版本由内部版本派生,与它无关。
|
||||
// 线上最近提交的版本号只用于展示平台侧事实,与这次要用的版本号无关。
|
||||
const latestVersionNumber = recovery.binding.latestVersionNumber ?? 0;
|
||||
setPublicationState('update');
|
||||
setPublicationBinding(recovery.binding);
|
||||
@@ -422,6 +441,20 @@ export function GameDistributionPublishPanel({
|
||||
if (!categoryTouchedRef.current && draft.category) {
|
||||
setCategory(draft.category);
|
||||
}
|
||||
// 线上价格预填:付费作品进面板默认免费会在送审后把作品改成免费,这里按回读的
|
||||
// 当前价预填,作者不改就不变。历史响应缺该字段时按免费兜底。
|
||||
const existingPriceMudPoints = draft.priceMudPoints ?? 0;
|
||||
if (
|
||||
typeof existingPriceMudPoints === 'number' &&
|
||||
existingPriceMudPoints > 0
|
||||
) {
|
||||
setPriceMode('paid');
|
||||
setPriceInput(String(existingPriceMudPoints));
|
||||
} else {
|
||||
setPriceMode('free');
|
||||
setPriceInput('');
|
||||
}
|
||||
setPriceError('');
|
||||
if (draft.cover && (draft.cover.assetId || draft.cover.previewUrl)) {
|
||||
setCover(buildRestoredCover(draft.cover));
|
||||
}
|
||||
@@ -656,6 +689,11 @@ export function GameDistributionPublishPanel({
|
||||
setError('请先导出有效的试玩包');
|
||||
return;
|
||||
}
|
||||
// 版本号必须来自平台作者视图;拿不到就不发请求,也不猜本地工程迭代计数。
|
||||
if (nextVersionNumber === null) {
|
||||
setError('无法确认项目版本,请重新打开发布面板后再试');
|
||||
return;
|
||||
}
|
||||
const invoke = resolveTauriInvoke();
|
||||
if (!invoke) {
|
||||
setError('需要在 Tauri App 内发布');
|
||||
@@ -686,6 +724,12 @@ export function GameDistributionPublishPanel({
|
||||
setError('素材还在上传中,请稍候再发布');
|
||||
return;
|
||||
}
|
||||
const price = resolvePlatformGamePriceMudPoints(priceMode, priceInput);
|
||||
if (price.error) {
|
||||
setPriceError(price.error);
|
||||
return;
|
||||
}
|
||||
setPriceError('');
|
||||
setBusy(true);
|
||||
setError('');
|
||||
setPublishPhase({
|
||||
@@ -741,7 +785,9 @@ export function GameDistributionPublishPanel({
|
||||
publicationState === 'update'
|
||||
? (publicationBinding?.gameId ?? null)
|
||||
: null,
|
||||
versionNumber: projectVersion,
|
||||
// 展示与提交同一个平台版本号(作者视图最大版本号 + 1,首次发布为 1)。
|
||||
versionNumber: nextVersionNumber,
|
||||
priceMudPoints: price.priceMudPoints,
|
||||
expectedPublicationRevision:
|
||||
publicationState === 'update'
|
||||
? (publicationBinding?.revision ?? null)
|
||||
@@ -891,24 +937,42 @@ export function GameDistributionPublishPanel({
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
<div className="game-distribution-publish-panel__version-field">
|
||||
<span className="game-distribution-publish-panel__version-label">
|
||||
项目版本
|
||||
<span className="game-distribution-publish-panel__version-tag">
|
||||
{`v${projectVersion}`}
|
||||
{nextVersionNumber === null ? '—' : `v${nextVersionNumber}`}
|
||||
</span>
|
||||
</span>
|
||||
{/* 平台派发的版本号,作者不能填:只读 + 禁用观感,提交的也是同一个值。
|
||||
保留 readOnly 而不是 disabled:值仍可聚焦 / 可复制,读屏也能念出来。 */}
|
||||
<input
|
||||
type="number"
|
||||
min={1}
|
||||
step={1}
|
||||
className="game-distribution-publish-panel__version-value"
|
||||
type="text"
|
||||
inputMode="numeric"
|
||||
aria-label="项目版本"
|
||||
readOnly
|
||||
aria-readonly="true"
|
||||
value={projectVersion}
|
||||
value={
|
||||
nextVersionNumber === null ? '' : String(nextVersionNumber)
|
||||
}
|
||||
placeholder="—"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<PlatformGamePricingField
|
||||
mode={priceMode}
|
||||
priceInput={priceInput}
|
||||
disabled={busy}
|
||||
error={priceError}
|
||||
onModeChange={(nextMode) => {
|
||||
setPriceMode(nextMode);
|
||||
setPriceError('');
|
||||
}}
|
||||
onPriceInputChange={(nextValue) => {
|
||||
setPriceInput(nextValue);
|
||||
setPriceError('');
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
className="game-distribution-publish-panel__media"
|
||||
@@ -1125,6 +1189,7 @@ export function GameDistributionPublishPanel({
|
||||
Boolean(uploadingLabel) ||
|
||||
publicationState === 'checking' ||
|
||||
publicationState === 'unavailable' ||
|
||||
nextVersionNumber === null ||
|
||||
!title.trim() ||
|
||||
!summary.trim() ||
|
||||
!packageResult
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { PLATFORM_GAME_MAX_PRICE_MUD_POINTS } from '@genarrative/shared/components';
|
||||
|
||||
import {
|
||||
type GameCreationAppManifest,
|
||||
type GameCreationAppPublicationBinding,
|
||||
resolveGameCreationAppProjectVersion,
|
||||
} from '../../../../packages/shared/src/contracts/gameCreationApp';
|
||||
import type {
|
||||
GameDistributionCategory,
|
||||
@@ -74,6 +75,13 @@ export type GameDistributionPublicationDraft = {
|
||||
deviceSupport?: GameDistributionDeviceSupport | null;
|
||||
inputModes?: GameDistributionInputMode[];
|
||||
orientation?: GameDistributionOrientation | null;
|
||||
/**
|
||||
* 线上该作品当前的买断价(整数泥点,`0` 表示免费)。
|
||||
*
|
||||
* 更新面板据此预填价格与模式:作者不改就不会把已上线的付费作品静默改成免费。
|
||||
* 旧原生端不返回该字段,读取方按 `0`(免费)兜底。
|
||||
*/
|
||||
priceMudPoints?: number | null;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -81,6 +89,9 @@ export type GameDistributionPublicationDraft = {
|
||||
*
|
||||
* `state` 三态必须分开处理:`unavailable` 表示恢复被网络/401/5xx 挡住,绝不能当成首次发布;
|
||||
* `first-publish` 只在服务端给出确定答案(无绑定且作者名下没有匹配作品)时出现。
|
||||
*
|
||||
* `nextVersionNumber` 是平台侧这次发布会用的版本号(作者视图已有版本的最大 `versionNumber + 1`;
|
||||
* 首次发布为 `1`)。取不到平台数据时缺省,调用方不得回落到本地工程迭代计数,只能禁用提交。
|
||||
*/
|
||||
export type GameDistributionPublicationReadResult =
|
||||
| {
|
||||
@@ -89,6 +100,7 @@ export type GameDistributionPublicationReadResult =
|
||||
refreshed: boolean;
|
||||
draft: null;
|
||||
visibility: null;
|
||||
nextVersionNumber?: number | null;
|
||||
message?: string | null;
|
||||
}
|
||||
| {
|
||||
@@ -97,6 +109,7 @@ export type GameDistributionPublicationReadResult =
|
||||
refreshed: boolean;
|
||||
draft: GameDistributionPublicationDraft | null;
|
||||
visibility?: string | null;
|
||||
nextVersionNumber?: number | null;
|
||||
message?: string | null;
|
||||
}
|
||||
| {
|
||||
@@ -105,6 +118,7 @@ export type GameDistributionPublicationReadResult =
|
||||
refreshed: false;
|
||||
draft: null;
|
||||
visibility: null;
|
||||
nextVersionNumber?: number | null;
|
||||
message?: string | null;
|
||||
};
|
||||
|
||||
@@ -299,15 +313,23 @@ export async function publishLocalProjectGame(args: {
|
||||
*/
|
||||
gameId?: string | null;
|
||||
/**
|
||||
* 这次提交使用的项目版本标签。
|
||||
* 这次提交使用的平台版本号。
|
||||
*
|
||||
* 缺省时按 AGC 工程内部版本 `versions[]` 派生(见 `resolveGameCreationAppProjectVersion`):
|
||||
* 标签等于当前存活的内部版本条数,发布面板展示的只读值就是它,不存在第二份版本来源,也不
|
||||
* 读取平台绑定里的版本号。同一个版本标签可以反复提交,每次提交生成新的 `versionId`。
|
||||
* **必填**:只接受调用方从平台作者视图推出的值(该作品已有版本的最大 `versionNumber + 1`,
|
||||
* 首次发布为 `1`),也就是发布面板展示给作者的同一个数。这里刻意不回落到 AGC 工程内部版本
|
||||
* `versions[]` 的条数——那是本地迭代计数,与平台版本序列无关,会提交重复 / 回退的版本号。
|
||||
* 同一个版本号可以反复提交(每次提交生成新的 `versionId`)。
|
||||
*/
|
||||
versionNumber?: number | null;
|
||||
versionNumber: number;
|
||||
/** 更新送审所需的公开修订号 CAS;来自发布绑定。 */
|
||||
expectedPublicationRevision?: number | null;
|
||||
/**
|
||||
* 本版本的买断价(整数泥点,`0` 表示免费)。
|
||||
*
|
||||
* 缺省或为空按免费提交,兼容未接入定价的调用方;服务端仍会独立校验
|
||||
* `0..=1_000_000`。发布面板在提交前已按同一口径拦住非法输入。
|
||||
*/
|
||||
priceMudPoints?: number | null;
|
||||
/**
|
||||
* 发布根幂等键。渲染层默认**不**生成也不持久化它:原生发布链路按
|
||||
* 「账号身份 + 本地项目 + 发行包摘要 + 目标游戏/版本 + 资料摘要」在应用数据里维护发布
|
||||
@@ -327,13 +349,23 @@ export async function publishLocalProjectGame(args: {
|
||||
throw new Error('发布需要本地项目标识,请重新打开项目后再试');
|
||||
}
|
||||
const gameId = args.gameId?.trim() ?? '';
|
||||
// 版本标签只有一个来源:调用方显式传入的值优先(发布面板展示的派生值),否则回落到按 AGC
|
||||
// 工程内部版本派生的同一个值。服务端的自动递增路径只服务不传版本号的老客户端。
|
||||
const versionNumber =
|
||||
args.versionNumber ?? resolveGameCreationAppProjectVersion(args.manifest);
|
||||
// 版本号只有一个来源:调用方按平台作者视图推出的值(发布面板展示的同一个只读值)。
|
||||
// 不回落本地工程迭代计数:那是「本地有几条迭代」而不是「平台版本序列的下一个号」,
|
||||
// 提交重复 / 回退的版本号时平台不报错,版本序列会乱。
|
||||
const versionNumber = args.versionNumber;
|
||||
if (!Number.isSafeInteger(versionNumber) || versionNumber <= 0) {
|
||||
throw new Error('项目版本必须是大于 0 的安全整数');
|
||||
}
|
||||
const priceMudPoints = args.priceMudPoints ?? 0;
|
||||
if (
|
||||
!Number.isSafeInteger(priceMudPoints) ||
|
||||
priceMudPoints < 0 ||
|
||||
priceMudPoints > PLATFORM_GAME_MAX_PRICE_MUD_POINTS
|
||||
) {
|
||||
throw new Error(
|
||||
`买断价必须是 0 到 ${PLATFORM_GAME_MAX_PRICE_MUD_POINTS} 之间的整数泥点`,
|
||||
);
|
||||
}
|
||||
if (
|
||||
gameId &&
|
||||
(args.expectedPublicationRevision === null ||
|
||||
@@ -353,6 +385,7 @@ export async function publishLocalProjectGame(args: {
|
||||
metadata: gameMetadata,
|
||||
...(gameId ? { gameId } : {}),
|
||||
versionNumber,
|
||||
priceMudPoints,
|
||||
...(gameId
|
||||
? { expectedPublicationRevision: args.expectedPublicationRevision }
|
||||
: {}),
|
||||
|
||||
@@ -3761,7 +3761,32 @@ textarea {
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
/* 项目版本标签:值就是 AGC 工程内部版本序数(资源总览「项目版本」栏目里最新那张卡的「版本 N」)。 */
|
||||
/* 项目版本字段:值是平台按作者视图派发的下一个版本号,作者不能填。
|
||||
外壳与 `.game-distribution-publish-panel__fields label` 同形(grid + 6px 间距),
|
||||
值用禁用观感(灰底 + 弱化文字 + not-allowed),与同组其它可编辑输入一眼分得开。 */
|
||||
.game-distribution-publish-panel__version-field {
|
||||
display: grid;
|
||||
gap: 6px;
|
||||
color: var(--platform-text-strong);
|
||||
font-size: 12px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.game-distribution-publish-panel__fields
|
||||
.game-distribution-publish-panel__version-value {
|
||||
background: rgb(244 238 232 / 88%);
|
||||
color: var(--platform-text-muted);
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.game-distribution-publish-panel__fields
|
||||
.game-distribution-publish-panel__version-value:focus-visible {
|
||||
border-color: var(--platform-subpanel-border);
|
||||
outline: 2px solid rgb(168 102 61 / 20%);
|
||||
outline-offset: 1px;
|
||||
}
|
||||
|
||||
/* 项目版本标签:值是**平台**这次发布会用的版本号(作者视图最大版本号 + 1)。 */
|
||||
.game-distribution-publish-panel__version-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
@@ -34,10 +34,10 @@ export type ProjectVersionResourceSummary = GameIterationVersion & {
|
||||
childVersionIds: string[];
|
||||
/**
|
||||
* 只有**最新内部版本**(`manifest.versions` 最后一条)带它,值是内部版本序数
|
||||
* (= `versions.length`,也就是发布时会提交的那个标签,与发布面板的
|
||||
* `resolveGameCreationAppProjectVersion` 同源)。
|
||||
* (= `versions.length`)。
|
||||
*
|
||||
* 卡面据此只渲染**中性**的「最新」角标:发布固定取最新内部版本,卡面不把它写成
|
||||
* 它是 AGC 工程内部的迭代序数,**不是**发布时提交的平台版本号(后者取平台作者视图里
|
||||
* 该作品的最大版本号 + 1)。卡面据此只渲染**中性**的「最新」角标,不把它写成
|
||||
* 「发布标签」,免得诱导用户以为要挑一张卡才能发。
|
||||
*/
|
||||
publicationTag?: number;
|
||||
|
||||
@@ -69,6 +69,8 @@ describe('Rust 发布 facade', () => {
|
||||
coverAssetId: 'asset_cover',
|
||||
screenshots: ['asset_shot_1', 'asset_shot_2'],
|
||||
},
|
||||
// 平台版本号必填:调用方按作者视图推出的值,这里直接透传。
|
||||
versionNumber: 4,
|
||||
idempotencyKey: 'agc-publish-test',
|
||||
});
|
||||
|
||||
@@ -79,6 +81,8 @@ describe('Rust 发布 facade', () => {
|
||||
projectPath: '/tmp/project',
|
||||
packageRelativePath: 'exports/playtest-package-1.zip',
|
||||
idempotencyKey: 'agc-publish-test',
|
||||
// 未传价格时按免费提交,保持旧调用方向后兼容。
|
||||
priceMudPoints: 0,
|
||||
metadata: {
|
||||
localProjectId: 'local-proj-1',
|
||||
coverAssetId: 'asset_cover',
|
||||
@@ -102,6 +106,7 @@ describe('Rust 发布 facade', () => {
|
||||
packageRelativePath: 'exports/playtest-package-1.zip',
|
||||
manifest: MANIFEST,
|
||||
metadata: { coverAssetId: 'asset_cover' },
|
||||
versionNumber: 4,
|
||||
});
|
||||
|
||||
expect(calls).toHaveLength(1);
|
||||
@@ -124,6 +129,7 @@ describe('Rust 发布 facade', () => {
|
||||
packageRelativePath: 'exports/playtest-package-1.zip',
|
||||
manifest: { ...MANIFEST, projectId: ' ' } as GameCreationAppManifest,
|
||||
metadata: { coverAssetId: 'asset_cover' },
|
||||
versionNumber: 4,
|
||||
}),
|
||||
).rejects.toThrow('发布需要本地项目标识');
|
||||
expect(invoke).not.toHaveBeenCalled();
|
||||
@@ -138,6 +144,7 @@ describe('Rust 发布 facade', () => {
|
||||
packageRelativePath: 'exports/playtest-package-1.zip',
|
||||
manifest: MANIFEST,
|
||||
metadata: { coverAssetId: ' ' },
|
||||
versionNumber: 4,
|
||||
}),
|
||||
).rejects.toThrow('请先选择游戏封面');
|
||||
expect(invoke).not.toHaveBeenCalled();
|
||||
@@ -158,11 +165,51 @@ describe('Rust 发布 facade', () => {
|
||||
(_, index) => `asset_${index}`,
|
||||
),
|
||||
},
|
||||
versionNumber: 4,
|
||||
}),
|
||||
).rejects.toThrow('游戏截图最多 6 张');
|
||||
expect(invoke).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('买断价原样透传给 native 发布命令', async () => {
|
||||
const { invoke, calls } = installNativeInvoke((command) => {
|
||||
if (command === 'publish_local_project_game') return PUBLISH_RESULT;
|
||||
throw new Error(`未预期的命令:${command}`);
|
||||
});
|
||||
|
||||
await publishLocalProjectGame({
|
||||
invoke,
|
||||
projectPath: '/tmp/project',
|
||||
packageRelativePath: 'exports/playtest-package-1.zip',
|
||||
manifest: MANIFEST,
|
||||
metadata: { coverAssetId: 'asset_cover' },
|
||||
versionNumber: 4,
|
||||
priceMudPoints: 240,
|
||||
});
|
||||
|
||||
expect(calls).toHaveLength(1);
|
||||
expect(calls[0]?.args).toMatchObject({ priceMudPoints: 240 });
|
||||
});
|
||||
|
||||
test('买断价越界或非整数时在 native command 前失败关闭', async () => {
|
||||
const invoke = vi.fn() as unknown as TauriInvoke;
|
||||
const base = {
|
||||
invoke,
|
||||
projectPath: '/tmp/project',
|
||||
packageRelativePath: 'exports/playtest-package-1.zip',
|
||||
manifest: MANIFEST,
|
||||
metadata: { coverAssetId: 'asset_cover' },
|
||||
versionNumber: 4,
|
||||
};
|
||||
await expect(
|
||||
publishLocalProjectGame({ ...base, priceMudPoints: 1_000_001 }),
|
||||
).rejects.toThrow('买断价必须是 0 到 1000000 之间的整数泥点');
|
||||
await expect(
|
||||
publishLocalProjectGame({ ...base, priceMudPoints: 1.5 }),
|
||||
).rejects.toThrow('买断价必须是 0 到 1000000 之间的整数泥点');
|
||||
expect(invoke).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('资料建议和价格均通过 native command', async () => {
|
||||
const { invoke, calls } = installNativeInvoke((command) => {
|
||||
if (command === 'suggest_game_distribution_publish_metadata') {
|
||||
@@ -312,21 +359,23 @@ describe('Rust 发布 facade', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('未显式给出项目版本时按工程内部版本条数派生', async () => {
|
||||
const { invoke, calls } = installNativeInvoke(() => PUBLISH_RESULT);
|
||||
test('项目版本只认调用方传入的平台版本号:缺省失败关闭,本地迭代计数不参与', async () => {
|
||||
// 缺省:不回落本地工程迭代计数(那是「本地有几条迭代」,不是平台版本序列的下一个号),
|
||||
// 直接失败关闭,避免提交重复 / 回退的版本号。
|
||||
const missingInvoke = vi.fn() as unknown as TauriInvoke;
|
||||
await expect(
|
||||
publishLocalProjectGame({
|
||||
invoke: missingInvoke,
|
||||
projectPath: '/tmp/project',
|
||||
packageRelativePath: 'exports/playtest-package-1.zip',
|
||||
manifest: MANIFEST,
|
||||
metadata: { coverAssetId: 'asset_cover' },
|
||||
} as unknown as Parameters<typeof publishLocalProjectGame>[0]),
|
||||
).rejects.toThrow('项目版本必须是大于 0 的安全整数');
|
||||
expect(missingInvoke).not.toHaveBeenCalled();
|
||||
|
||||
// 没有任何内部版本记录:首版回落 1,不把「没写」变成服务端自动递增。
|
||||
await publishLocalProjectGame({
|
||||
invoke,
|
||||
projectPath: '/tmp/project',
|
||||
packageRelativePath: 'exports/playtest-package-1.zip',
|
||||
manifest: MANIFEST,
|
||||
metadata: { coverAssetId: 'asset_cover' },
|
||||
});
|
||||
expect(calls[0]?.args).toMatchObject({ versionNumber: 1 });
|
||||
|
||||
// 4 条内部版本 → 标签就是最新那张卡的序数 4;平台绑定里的版本号不参与派生。
|
||||
const withVersions = {
|
||||
// 本地有 4 条内部版本、还有遗留 projectVersion 与绑定里的版本号:都不能改写传下去的值。
|
||||
const withLocalHistory = {
|
||||
...MANIFEST,
|
||||
versions: [
|
||||
{ versionId: 'initial-13', parentVersionId: null, projectRevision: 13 },
|
||||
@@ -349,20 +398,17 @@ describe('Rust 发布 facade', () => {
|
||||
projectVersion: 6,
|
||||
publication: { latestVersionNumber: 6 },
|
||||
} as unknown as GameCreationAppManifest;
|
||||
const { invoke, calls } = installNativeInvoke(() => PUBLISH_RESULT);
|
||||
await publishLocalProjectGame({
|
||||
invoke,
|
||||
projectPath: '/tmp/project',
|
||||
packageRelativePath: 'exports/playtest-package-1.zip',
|
||||
manifest: withVersions,
|
||||
manifest: withLocalHistory,
|
||||
metadata: { coverAssetId: 'asset_cover' },
|
||||
gameId: 'game_9',
|
||||
expectedPublicationRevision: 7,
|
||||
});
|
||||
expect(calls[1]?.args).toMatchObject({
|
||||
gameId: 'game_9',
|
||||
versionNumber: 4,
|
||||
expectedPublicationRevision: 7,
|
||||
versionNumber: 7,
|
||||
});
|
||||
expect(calls[0]?.args).toMatchObject({ versionNumber: 7 });
|
||||
expect(calls[0]?.args).not.toMatchObject({ versionNumber: 4 });
|
||||
});
|
||||
|
||||
test('更新发布缺少公开修订号时在 native command 前失败关闭', async () => {
|
||||
|
||||
@@ -639,6 +639,8 @@ liveTest(
|
||||
packageRelativePath: 'dist/game.zip',
|
||||
manifest,
|
||||
metadata: { ...metadata, inputModes: [...metadata.inputModes] },
|
||||
// 平台侧接下来会用的版本号由作者视图推出:这个项目刚建,平台从 1 开始派发。
|
||||
versionNumber: 1,
|
||||
});
|
||||
expect(first.status).toBe('pending_review');
|
||||
expect(first.versionNumber).toBe(1);
|
||||
@@ -676,6 +678,8 @@ liveTest(
|
||||
packageRelativePath: 'dist/game.zip',
|
||||
manifest,
|
||||
metadata: { ...metadata, inputModes: [...metadata.inputModes] },
|
||||
// 同一作品第二次发布:作者视图已有 v1 → 这次用 2。
|
||||
versionNumber: 2,
|
||||
});
|
||||
expect(second.gameId).toBe(first.gameId);
|
||||
expect(second.versionNumber).toBe(first.versionNumber + 1);
|
||||
|
||||
@@ -129,12 +129,14 @@ beforeEach(() => {
|
||||
() => new Promise<never>(() => undefined),
|
||||
);
|
||||
// 默认按「首次发布」恢复,保持既有用例的提交路径不变;更新模式用例单独覆盖。
|
||||
// `nextVersionNumber` 是原生按平台作者视图推出来的值:首次发布没有线上作品,平台从 1 派发。
|
||||
vi.mocked(readGameDistributionPublication).mockResolvedValue({
|
||||
state: 'first-publish',
|
||||
binding: null,
|
||||
refreshed: true,
|
||||
draft: null,
|
||||
visibility: null,
|
||||
nextVersionNumber: 1,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -330,6 +332,8 @@ describe('GameDistributionPublishPanel', () => {
|
||||
// 根幂等键由原生发布链路按「账号 + 本地项目 + 包摘要」的账本解析并持久化,
|
||||
// 渲染层不再自己铸键,因此这里不带 idempotencyKey。
|
||||
expect(args?.idempotencyKey).toBeUndefined();
|
||||
// 默认免费:不改付费方式就按 0 泥点提交。
|
||||
expect(args?.priceMudPoints).toBe(0);
|
||||
expect(invoke).toBeDefined();
|
||||
|
||||
expect(await screen.findByText('已提交审核')).not.toBeNull();
|
||||
@@ -337,6 +341,47 @@ describe('GameDistributionPublishPanel', () => {
|
||||
expect(onPublished).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test('买断制先本地校验价格,合法时随版本提交', async () => {
|
||||
installTauriInvoke(async () => undefined);
|
||||
vi.mocked(publishLocalProjectGame).mockResolvedValue({
|
||||
gameId: 'game_1',
|
||||
versionId: 'gamever_1',
|
||||
versionNumber: 1,
|
||||
status: 'pending_review',
|
||||
packageSha256: 'a'.repeat(64),
|
||||
packageSizeBytes: 3,
|
||||
fileCount: 2,
|
||||
});
|
||||
renderPanel();
|
||||
await selectCover();
|
||||
const submit = await screen.findByRole('button', { name: '发布游戏' });
|
||||
|
||||
fireEvent.click(screen.getByLabelText('买断制'));
|
||||
// 空价格先被本地拦住,不发任何发布请求。
|
||||
fireEvent.click(submit);
|
||||
expect(await screen.findByText('买断价必须是整数泥点')).not.toBeNull();
|
||||
expect(publishLocalProjectGame).not.toHaveBeenCalled();
|
||||
|
||||
fireEvent.change(screen.getByLabelText(/买断价/u), {
|
||||
target: { value: '1000001' },
|
||||
});
|
||||
fireEvent.click(submit);
|
||||
expect(
|
||||
await screen.findByText('买断价必须是 1 到 1000000 之间的整数泥点'),
|
||||
).not.toBeNull();
|
||||
expect(publishLocalProjectGame).not.toHaveBeenCalled();
|
||||
|
||||
fireEvent.change(screen.getByLabelText(/买断价/u), {
|
||||
target: { value: '120' },
|
||||
});
|
||||
fireEvent.click(submit);
|
||||
await waitFor(() =>
|
||||
expect(publishLocalProjectGame).toHaveBeenCalledTimes(1),
|
||||
);
|
||||
const args = vi.mocked(publishLocalProjectGame).mock.calls[0]?.[0];
|
||||
expect(args?.priceMudPoints).toBe(120);
|
||||
});
|
||||
|
||||
test('连续点击只提交一次,上传中禁用动作按钮', async () => {
|
||||
installTauriInvoke(async () => undefined);
|
||||
let resolvePublish: (value: unknown) => void = () => undefined;
|
||||
@@ -670,8 +715,10 @@ describe('GameDistributionPublishPanel', () => {
|
||||
|
||||
test('不在 Tauri 宿主或缺少试玩包时失败关闭且不调用发布接口', async () => {
|
||||
renderPanel();
|
||||
fireEvent.click(screen.getByRole('button', { name: '发布游戏' }));
|
||||
expect(await screen.findByText('需要在 Tauri App 内发布')).not.toBeNull();
|
||||
// 没有原生宿主就没有平台版本号:不猜本地迭代计数,提交按钮保持禁用。
|
||||
expect(
|
||||
await screen.findByRole('button', { name: '发布游戏' }),
|
||||
).toHaveProperty('disabled', true);
|
||||
expect(publishLocalProjectGame).not.toHaveBeenCalled();
|
||||
|
||||
cleanup();
|
||||
@@ -683,7 +730,7 @@ describe('GameDistributionPublishPanel', () => {
|
||||
expect(screen.queryByLabelText('发行包摘要')).toBeNull();
|
||||
});
|
||||
|
||||
test('已有绑定时进入更新模式,回填线上资料并按派生项目版本提交原 gameId', async () => {
|
||||
test('已有绑定时进入更新模式,回填线上资料并提交平台下一个版本号', async () => {
|
||||
installTauriInvoke(async () => undefined);
|
||||
vi.mocked(readGameDistributionPublication).mockResolvedValue({
|
||||
state: 'update',
|
||||
@@ -697,6 +744,7 @@ describe('GameDistributionPublishPanel', () => {
|
||||
status: 'pending_review',
|
||||
},
|
||||
refreshed: true,
|
||||
nextVersionNumber: 3,
|
||||
draft: {
|
||||
title: '星轨防线(线上)',
|
||||
summary: '线上简介',
|
||||
@@ -730,8 +778,7 @@ describe('GameDistributionPublishPanel', () => {
|
||||
});
|
||||
const { onPublished } = renderPanel();
|
||||
|
||||
// 回填线上冻结资料;项目版本按工程内部版本派生(本 fixture 没有 versions → 首版 1),
|
||||
// 平台绑定的线上版本号只用于展示,不参与派生。
|
||||
// 回填线上冻结资料;项目版本取平台作者视图的下一个版本号(已有 v2 → 这次用 3)。
|
||||
await screen.findByRole('button', { name: '更新游戏' });
|
||||
expect(screen.getByLabelText('游戏名称')).toHaveProperty(
|
||||
'value',
|
||||
@@ -741,10 +788,11 @@ describe('GameDistributionPublishPanel', () => {
|
||||
'value',
|
||||
'线上简介',
|
||||
);
|
||||
const versionInput = screen.getByLabelText('项目版本');
|
||||
expect(versionInput).toHaveProperty('value', '1');
|
||||
expect(versionInput).toHaveProperty('readOnly', true);
|
||||
expect(screen.getByText('v1')).not.toBeNull();
|
||||
const versionInput = screen.getByLabelText('项目版本') as HTMLInputElement;
|
||||
expect(versionInput.value).toBe('3');
|
||||
expect(versionInput.readOnly).toBe(true);
|
||||
expect(versionInput.getAttribute('aria-readonly')).toBe('true');
|
||||
expect(screen.getByText('v3')).not.toBeNull();
|
||||
expect(screen.getByText(/线上最近提交 v2 · 审核中/u)).not.toBeNull();
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: '更新游戏' }));
|
||||
@@ -753,9 +801,11 @@ describe('GameDistributionPublishPanel', () => {
|
||||
);
|
||||
const args = vi.mocked(publishLocalProjectGame).mock.calls[0]?.[0];
|
||||
expect(args?.gameId).toBe('game_9');
|
||||
// 提交的就是派生出来的内部版本序数,与线上最近提交的 v2 无关。
|
||||
expect(args?.versionNumber).toBe(1);
|
||||
// 展示给作者的值与提交的值是同一个:平台已有 v2 → 提交 3,与本地迭代计数无关。
|
||||
expect(args?.versionNumber).toBe(3);
|
||||
expect(args?.expectedPublicationRevision).toBe(7);
|
||||
// 该草稿是历史响应,没有回读价格:按免费预填,不填就提交 0。
|
||||
expect(args?.priceMudPoints).toBe(0);
|
||||
// 冻结素材 ID 直接复用,不要求作者重新上传封面/截图。
|
||||
expect(args?.metadata?.coverAssetId).toBe('asset_cover_old');
|
||||
expect(args?.metadata?.screenshots).toEqual(['asset_shot_old']);
|
||||
@@ -771,7 +821,7 @@ describe('GameDistributionPublishPanel', () => {
|
||||
expect(onPublished).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test('项目版本由工程内部版本条数派生,线上版本号与遗留字段都不参与', async () => {
|
||||
test('更新模式预填线上买断价,作者不改就按原价提交', async () => {
|
||||
installTauriInvoke(async () => undefined);
|
||||
vi.mocked(readGameDistributionPublication).mockResolvedValue({
|
||||
state: 'update',
|
||||
@@ -780,17 +830,74 @@ describe('GameDistributionPublishPanel', () => {
|
||||
apiBaseUrl: 'https://dev.test',
|
||||
gameId: 'game_9',
|
||||
revision: 7,
|
||||
latestVersionId: 'gamever_5',
|
||||
latestVersionNumber: 5,
|
||||
latestVersionId: 'gamever_2',
|
||||
latestVersionNumber: 2,
|
||||
status: 'published',
|
||||
},
|
||||
refreshed: true,
|
||||
nextVersionNumber: 3,
|
||||
draft: {
|
||||
title: '星轨防线(线上)',
|
||||
summary: '线上简介',
|
||||
description: '线上详介',
|
||||
category: '策略',
|
||||
tags: ['塔防'],
|
||||
cover: {
|
||||
assetId: 'asset_cover_old',
|
||||
previewUrl: 'https://assets.test/cover.png',
|
||||
},
|
||||
screenshots: [],
|
||||
priceMudPoints: 240,
|
||||
},
|
||||
visibility: 'published',
|
||||
});
|
||||
vi.mocked(publishLocalProjectGame).mockResolvedValue({
|
||||
gameId: 'game_9',
|
||||
versionId: 'gamever_3',
|
||||
versionNumber: 1,
|
||||
status: 'pending_review',
|
||||
packageSha256: 'a'.repeat(64),
|
||||
packageSizeBytes: 3,
|
||||
fileCount: 2,
|
||||
});
|
||||
renderPanel();
|
||||
|
||||
const submit = await screen.findByRole('button', { name: '更新游戏' });
|
||||
// 预填线上价与模式:不改就按原价提交,避免审核通过后把付费作品静默改成免费。
|
||||
expect(screen.getByLabelText('买断制')).toHaveProperty('checked', true);
|
||||
expect(screen.getByLabelText(/买断价/u)).toHaveProperty('value', '240');
|
||||
|
||||
fireEvent.click(submit);
|
||||
await waitFor(() =>
|
||||
expect(publishLocalProjectGame).toHaveBeenCalledTimes(1),
|
||||
);
|
||||
expect(
|
||||
vi.mocked(publishLocalProjectGame).mock.calls[0]?.[0].priceMudPoints,
|
||||
).toBe(240);
|
||||
});
|
||||
|
||||
test('项目版本取平台作者视图的下一个版本号:本地迭代计数与遗留字段都不参与', async () => {
|
||||
installTauriInvoke(async () => undefined);
|
||||
vi.mocked(readGameDistributionPublication).mockResolvedValue({
|
||||
state: 'update',
|
||||
binding: {
|
||||
accountId: 'user-1',
|
||||
apiBaseUrl: 'https://dev.test',
|
||||
gameId: 'game_9',
|
||||
revision: 7,
|
||||
latestVersionId: 'gamever_3',
|
||||
latestVersionNumber: 3,
|
||||
status: 'published',
|
||||
},
|
||||
refreshed: true,
|
||||
draft: null,
|
||||
visibility: 'published',
|
||||
// 原生按作者视图算出「已有版本号 1..3 → 这次用 4」。
|
||||
nextVersionNumber: 4,
|
||||
});
|
||||
vi.mocked(publishLocalProjectGame).mockResolvedValue({
|
||||
gameId: 'game_9',
|
||||
versionId: 'gamever_6',
|
||||
versionId: 'gamever_4',
|
||||
versionNumber: 4,
|
||||
status: 'pending_review',
|
||||
packageSha256: 'a'.repeat(64),
|
||||
@@ -800,48 +907,96 @@ describe('GameDistributionPublishPanel', () => {
|
||||
renderPanel({
|
||||
manifest: {
|
||||
...MANIFEST,
|
||||
// 4 条内部版本 → 标签 4;遗留 projectVersion 6 与线上 v5 都不得影响它。
|
||||
// 本地只有 1 条内部版本、遗留 projectVersion 6:按旧口径会提交 1(或 2),
|
||||
// 这次必须采用平台推出的 4。
|
||||
versions: [
|
||||
{
|
||||
versionId: 'initial-13',
|
||||
parentVersionId: null,
|
||||
projectRevision: 13,
|
||||
},
|
||||
{
|
||||
versionId: 'agent-22',
|
||||
parentVersionId: 'initial-13',
|
||||
projectRevision: 22,
|
||||
},
|
||||
{
|
||||
versionId: 'agent-42',
|
||||
parentVersionId: 'agent-22',
|
||||
projectRevision: 42,
|
||||
},
|
||||
{
|
||||
versionId: 'agent-46',
|
||||
parentVersionId: 'agent-42',
|
||||
projectRevision: 46,
|
||||
},
|
||||
],
|
||||
projectVersion: 6,
|
||||
} as unknown as GameCreationAppManifest,
|
||||
});
|
||||
await screen.findByRole('button', { name: '更新游戏' });
|
||||
|
||||
const input = screen.getByLabelText('项目版本');
|
||||
expect(input).toHaveProperty('value', '4');
|
||||
expect(input).toHaveProperty('readOnly', true);
|
||||
const input = screen.getByLabelText('项目版本') as HTMLInputElement;
|
||||
expect(input.value).toBe('4');
|
||||
expect(input.readOnly).toBe(true);
|
||||
expect(screen.getByText('v4')).not.toBeNull();
|
||||
expect(screen.getByText(/线上最近提交 v5 · 已公开/u)).not.toBeNull();
|
||||
expect(screen.getByText(/线上最近提交 v3 · 已公开/u)).not.toBeNull();
|
||||
await selectCover();
|
||||
fireEvent.click(screen.getByRole('button', { name: '更新游戏' }));
|
||||
|
||||
await waitFor(() =>
|
||||
expect(publishLocalProjectGame).toHaveBeenCalledTimes(1),
|
||||
);
|
||||
const submittedVersion = vi.mocked(publishLocalProjectGame).mock
|
||||
.calls[0]?.[0].versionNumber;
|
||||
// 显示值 == 提交值 == 平台下一个版本号。
|
||||
expect(submittedVersion).toBe(4);
|
||||
// 本地迭代计数(1 条)与「本地计数 + 1」都不得成为提交值。
|
||||
expect(submittedVersion).not.toBe(1);
|
||||
expect(submittedVersion).not.toBe(2);
|
||||
});
|
||||
|
||||
test('平台版本号不可得时显示占位、提交禁用,且不回落本地迭代计数', async () => {
|
||||
installTauriInvoke(async () => undefined);
|
||||
vi.mocked(readGameDistributionPublication).mockResolvedValue({
|
||||
state: 'update',
|
||||
binding: {
|
||||
accountId: 'user-1',
|
||||
apiBaseUrl: 'https://dev.test',
|
||||
gameId: 'game_9',
|
||||
revision: 7,
|
||||
latestVersionId: 'gamever_2',
|
||||
latestVersionNumber: 2,
|
||||
status: 'pending_review',
|
||||
},
|
||||
// 有本地绑定但没能刷新线上状态:这一路没有平台版本数据。
|
||||
refreshed: false,
|
||||
draft: null,
|
||||
visibility: null,
|
||||
message: '无法刷新线上状态:无法连接登录服务',
|
||||
});
|
||||
renderPanel({
|
||||
manifest: {
|
||||
...MANIFEST,
|
||||
// 本地 3 条内部版本:不得被当成版本号提交。
|
||||
versions: [
|
||||
{ versionId: 'a', parentVersionId: null, projectRevision: 1 },
|
||||
{ versionId: 'b', parentVersionId: 'a', projectRevision: 2 },
|
||||
{ versionId: 'c', parentVersionId: 'b', projectRevision: 3 },
|
||||
],
|
||||
} as unknown as GameCreationAppManifest,
|
||||
});
|
||||
|
||||
const versionInput = (await screen.findByLabelText(
|
||||
'项目版本',
|
||||
)) as HTMLInputElement;
|
||||
expect(versionInput.value).toBe('');
|
||||
expect(versionInput.placeholder).toBe('—');
|
||||
expect(
|
||||
vi.mocked(publishLocalProjectGame).mock.calls[0]?.[0].versionNumber,
|
||||
).toBe(4);
|
||||
screen.getByText('—', {
|
||||
selector: '.game-distribution-publish-panel__version-tag',
|
||||
}),
|
||||
).not.toBeNull();
|
||||
expect(
|
||||
screen.getByText('无法刷新线上状态:无法连接登录服务'),
|
||||
).not.toBeNull();
|
||||
|
||||
// 其余必填项补齐后,提交仍因版本号未知保持禁用。
|
||||
fireEvent.change(screen.getByLabelText('游戏名称'), {
|
||||
target: { value: '星轨防线' },
|
||||
});
|
||||
fireEvent.change(screen.getByLabelText('一句话简介'), {
|
||||
target: { value: '守住轨道城' },
|
||||
});
|
||||
const submit = screen.getByRole('button', { name: '更新游戏' });
|
||||
expect(submit).toHaveProperty('disabled', true);
|
||||
fireEvent.click(submit);
|
||||
expect(publishLocalProjectGame).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('恢复失败(网络/5xx)时禁用提交,不按首次发布继续', async () => {
|
||||
|
||||
@@ -113,9 +113,19 @@ describe('运行页「刷新运行画面」', () => {
|
||||
const second = document.querySelector('iframe');
|
||||
|
||||
expect(second).not.toBe(first);
|
||||
expect(new URL(String(first?.getAttribute('src'))).searchParams.get('__agc_reload')).toBe('1');
|
||||
expect(new URL(String(second?.getAttribute('src'))).searchParams.get('__agc_reload')).toBe('2');
|
||||
expect(new URL(String(second?.getAttribute('src'))).origin).toBe('http://127.0.0.1:4173');
|
||||
expect(
|
||||
new URL(String(first?.getAttribute('src'))).searchParams.get(
|
||||
'__agc_reload',
|
||||
),
|
||||
).toBe('1');
|
||||
expect(
|
||||
new URL(String(second?.getAttribute('src'))).searchParams.get(
|
||||
'__agc_reload',
|
||||
),
|
||||
).toBe('2');
|
||||
expect(new URL(String(second?.getAttribute('src'))).origin).toBe(
|
||||
'http://127.0.0.1:4173',
|
||||
);
|
||||
});
|
||||
|
||||
it('没有活预览时不渲染刷新,而不是留一个点了没反应的入口', async () => {
|
||||
|
||||
Reference in New Issue
Block a user