实现网站游戏评分与评价 (#561)
Project CI / AI game creator shell Rust crates (push) Successful in 1m43s
Project CI / AI game creator shell Rust lane 2/2 (push) Failing after 2m7s
Project CI / AI game creator shell Rust smoke (push) Successful in 2m55s
Project CI / AI game creator shell Rust lane 1/2 (push) Failing after 3m23s
Project CI / Frontend tests (push) Successful in 3m3s
Project CI / Repository checks (push) Successful in 3m42s
Project CI / AI game creator shell web tests (push) Successful in 2m3s
Project CI / Backend tests (push) Successful in 6m19s
Project CI / Native shell tests (push) Successful in 8m7s

公开游戏详情页新增评分与评价:登录用户可提交并修改自己对每款游戏的唯一一条 1–10 分评价,评论可空且最多 4000 个 Unicode 码点;游客可分页浏览评价并查看平均分与评分人数。

- 新增私有评价表及共享 DTO/API,事务内校验游戏公开可见性、保证唯一性,并计算分页与全量评分统计;下架或封禁后关闭读写,重新公开及更新版本保留评价。
- 详情页支持编辑预填、取消、提交期间冻结输入、失败保留草稿,以及保存、翻页和账号/游戏切换时的旧响应隔离;复用现有认证与公共组件。
- 同步主规范、里程碑、实施计划、生成绑定、表目录和验收脚本。不扩展 AGC、外部 API、评论审核或评分缓存。

验证:
- 本轮审查复跑前端定向测试 40 项、评价领域测试 2 项,均通过。
- 网站 typecheck、Rust/TypeScript DTO 对齐、SpacetimeDB schema、文档索引、编码与 diff 检查通过。
- 实施文档另记录本地隔离数据库/API 49 项及桌面/移动视口浏览器 smoke 通过;本轮审查未重跑这些运行时验收,也未运行完整测试套件。

发布说明:新增 SpacetimeDB 表,部署时需同步 module 与 API。尚未部署 dev/production,待用户验收。

Reviewed-on: https://git.genarrative.world/git/GenarrativeAI/Genarrative/pulls/561
Co-authored-by: Linghong <ink29535@proton.me>
Co-committed-by: Linghong <ink29535@proton.me>
This commit was merged in pull request #561.
This commit is contained in:
2026-10-01 19:19:58 +08:00
committed by 孔令弘
parent 44f415d057
commit b60aea4e71
81 changed files with 8594 additions and 60 deletions
@@ -1,3 +1,4 @@
/* @vitest-environment jsdom */
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { clearStoredAccessToken, setStoredAccessToken } from './apiClient';
@@ -6,8 +7,11 @@ import {
createGameVersion,
getGame,
getGameVersion,
getMyGameReview,
listGameReviews,
listGames,
listMyGames,
saveMyGameReview,
unpublishGame,
uploadGamePackage,
} from './gameDistributionClient';
@@ -17,6 +21,40 @@ describe('gameDistributionClient', () => {
clearStoredAccessToken({ emit: false });
});
it('评价读取公开分页和私有鉴权、PUT 使用 envelope 且不缓存', async () => {
setStoredAccessToken('reviewer-token', { emit: false });
const fetchMock = vi.fn().mockImplementation(() =>
Promise.resolve(
new Response(
JSON.stringify({
ok: true,
data: { review: null },
error: null,
meta: { apiVersion: 'v1' },
}),
{ status: 200 },
),
),
);
vi.stubGlobal('fetch', fetchMock);
await listGameReviews('game-1', 2);
expect(fetchMock.mock.calls[0][0]).toBe(
'/api/game-distribution/games/game-1/reviews?page=2&pageSize=20',
);
expect(fetchMock.mock.calls[0][1].headers.Authorization).toBeUndefined();
expect(fetchMock.mock.calls[0][1].cache).toBe('no-store');
expect(await getMyGameReview('game-1')).toEqual({ review: null });
expect(fetchMock.mock.calls[1][1].headers.Authorization).toBe(
'Bearer reviewer-token',
);
await saveMyGameReview('game-1', { score: 10, comment: '' });
expect(fetchMock.mock.calls[2][1]).toMatchObject({
method: 'PUT',
cache: 'no-store',
body: JSON.stringify({ score: 10, comment: '' }),
});
});
it('按关键词和分类读取后端目录', async () => {
vi.stubGlobal(
'fetch',
+35
View File
@@ -6,6 +6,10 @@ import type {
GameDistributionCreateVersionRequest,
GameDistributionDeviceSupport,
GameDistributionGame,
GameDistributionMyReviewResponse,
GameDistributionReviewsResponse,
GameDistributionSaveReviewRequest,
GameDistributionSaveReviewResponse,
GameDistributionVersionDetail,
GameDistributionVersionStatus as GameDistributionVersionStatusValue,
GameDistributionVersionSummary,
@@ -20,7 +24,10 @@ export type {
GameDistributionDeviceSupport,
GameDistributionGame,
GameDistributionInputMode,
GameDistributionRatingSummary,
GameDistributionRecoveryAction,
GameDistributionReview,
GameDistributionReviewsResponse,
GameDistributionVersionDetail,
GameDistributionVersionSummary,
} from '../../packages/shared/src/contracts/gameDistribution';
@@ -164,6 +171,34 @@ export async function getGame(gameId: string) {
);
}
export function listGameReviews(gameId: string, page = 1) {
return requestJson<GameDistributionReviewsResponse>(
`/games/${encodeURIComponent(gameId)}/reviews?page=${page}&pageSize=20`,
{ method: 'GET', cache: 'no-store' },
'读取游戏评价失败',
PUBLIC_GAME_REQUEST_OPTIONS,
);
}
export function getMyGameReview(gameId: string) {
return requestJson<GameDistributionMyReviewResponse>(
`/games/${encodeURIComponent(gameId)}/my-review`,
{ method: 'GET', cache: 'no-store' },
'读取我的评价失败',
);
}
export function saveMyGameReview(
gameId: string,
payload: GameDistributionSaveReviewRequest,
) {
return requestJson<GameDistributionSaveReviewResponse>(
`/games/${encodeURIComponent(gameId)}/my-review`,
{ method: 'PUT', cache: 'no-store', body: JSON.stringify(payload) },
'保存评价失败',
);
}
export async function createGame(
payload: GameDistributionCreateGameRequest,
idempotencyKey: string,