Merge branch 'master' of https://git.genarrative.world/GenarrativeAI/Genarrative
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -300,6 +300,161 @@ function ActionCompleteHarness({
|
||||
);
|
||||
}
|
||||
|
||||
function SessionChangeHarness({
|
||||
onSessionChanged,
|
||||
}: {
|
||||
onSessionChanged: (session: TestSession | null) => void;
|
||||
}) {
|
||||
const flow = usePlatformCreationAgentFlowController<
|
||||
TestSession,
|
||||
Record<string, never>,
|
||||
{ session: TestSession },
|
||||
TestMessagePayload,
|
||||
{ action: string },
|
||||
{ session: TestSession }
|
||||
>({
|
||||
client: {
|
||||
createSession: async () => ({
|
||||
session: {
|
||||
sessionId: 'session-open',
|
||||
messages: [],
|
||||
},
|
||||
}),
|
||||
getSession: async () => ({
|
||||
session: {
|
||||
sessionId: 'session-restore',
|
||||
messages: [],
|
||||
},
|
||||
}),
|
||||
streamMessage: async () => ({
|
||||
sessionId: 'session-open',
|
||||
messages: [],
|
||||
}),
|
||||
executeAction: async () => ({
|
||||
session: {
|
||||
sessionId: 'session-compile',
|
||||
messages: [],
|
||||
},
|
||||
}),
|
||||
selectSession: (response) => response.session,
|
||||
},
|
||||
createPayload: {},
|
||||
workspaceStage: 'match3d-agent-workspace',
|
||||
resultStage: 'match3d-result',
|
||||
platformStage: 'platform',
|
||||
isCompileAction: (payload) => payload.action === 'match3d_compile_draft',
|
||||
resolveErrorMessage: (error, fallback) =>
|
||||
error instanceof Error ? error.message : fallback,
|
||||
errorMessages: {
|
||||
open: '打开失败',
|
||||
restoreMissingSession: '缺少会话',
|
||||
restore: '恢复失败',
|
||||
submit: '发送失败',
|
||||
execute: '执行失败',
|
||||
},
|
||||
enterCreateTab: () => {},
|
||||
setSelectionStage: () => {},
|
||||
onSessionChanged,
|
||||
onActionComplete: ({ response, setSession }) => {
|
||||
setSession(response.session);
|
||||
},
|
||||
});
|
||||
|
||||
return (
|
||||
<div>
|
||||
<button type="button" onClick={() => void flow.openWorkspace({})}>
|
||||
打开
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void flow.restoreDraft('session-restore')}
|
||||
>
|
||||
恢复
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() =>
|
||||
void flow.executeAction({ action: 'match3d_compile_draft' })
|
||||
}
|
||||
>
|
||||
编译
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function SessionSetterIdentityHarness({
|
||||
onSetterIdentity,
|
||||
}: {
|
||||
onSetterIdentity: (setter: unknown) => void;
|
||||
}) {
|
||||
const [renderCount, setRenderCount] = useState(0);
|
||||
const flow = usePlatformCreationAgentFlowController<
|
||||
TestSession,
|
||||
Record<string, never>,
|
||||
{ session: TestSession },
|
||||
TestMessagePayload,
|
||||
{ action: string },
|
||||
{ session: TestSession }
|
||||
>({
|
||||
client: {
|
||||
createSession: async () => ({
|
||||
session: {
|
||||
sessionId: 'session-open',
|
||||
messages: [],
|
||||
},
|
||||
}),
|
||||
getSession: async () => ({
|
||||
session: {
|
||||
sessionId: 'session-restore',
|
||||
messages: [],
|
||||
},
|
||||
}),
|
||||
streamMessage: async () => ({
|
||||
sessionId: 'session-open',
|
||||
messages: [],
|
||||
}),
|
||||
executeAction: async () => ({
|
||||
session: {
|
||||
sessionId: 'session-compile',
|
||||
messages: [],
|
||||
},
|
||||
}),
|
||||
selectSession: (response) => response.session,
|
||||
},
|
||||
createPayload: {},
|
||||
workspaceStage: 'match3d-agent-workspace',
|
||||
resultStage: 'match3d-result',
|
||||
platformStage: 'platform',
|
||||
isCompileAction: () => false,
|
||||
resolveErrorMessage: (error, fallback) =>
|
||||
error instanceof Error ? error.message : fallback,
|
||||
errorMessages: {
|
||||
open: '打开失败',
|
||||
restoreMissingSession: '缺少会话',
|
||||
restore: '恢复失败',
|
||||
submit: '发送失败',
|
||||
execute: '执行失败',
|
||||
},
|
||||
enterCreateTab: () => {},
|
||||
setSelectionStage: () => {},
|
||||
onSessionChanged: () => {},
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
onSetterIdentity(flow.setSession);
|
||||
});
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setRenderCount((current) => current + 1)}
|
||||
>
|
||||
重渲染 {renderCount}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
test('creation agent flow preserves streamed assistant text when stream fails', async () => {
|
||||
const streamMessage = vi.fn(async (_sessionId, _payload, options) => {
|
||||
options?.onUpdate?.('先把方洞万能的反差定住。');
|
||||
@@ -391,3 +546,48 @@ test('creation agent flow suppresses compile result stage for background complet
|
||||
'match3d-agent-workspace',
|
||||
);
|
||||
});
|
||||
|
||||
test('creation agent flow notifies session changes after open restore and compile', async () => {
|
||||
const onSessionChanged = vi.fn();
|
||||
|
||||
render(<SessionChangeHarness onSessionChanged={onSessionChanged} />);
|
||||
|
||||
await act(async () => {
|
||||
screen.getByRole('button', { name: '打开' }).click();
|
||||
});
|
||||
await act(async () => {
|
||||
screen.getByRole('button', { name: '恢复' }).click();
|
||||
});
|
||||
await act(async () => {
|
||||
screen.getByRole('button', { name: '编译' }).click();
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(onSessionChanged).toHaveBeenCalledTimes(3);
|
||||
});
|
||||
|
||||
expect(
|
||||
onSessionChanged.mock.calls.map(([session]) => session?.sessionId),
|
||||
).toEqual(['session-open', 'session-restore', 'session-compile']);
|
||||
});
|
||||
|
||||
test('creation agent flow keeps session setter stable across parent rerenders', async () => {
|
||||
const onSetterIdentity = vi.fn();
|
||||
|
||||
render(<SessionSetterIdentityHarness onSetterIdentity={onSetterIdentity} />);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(onSetterIdentity).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
const initialSetter = onSetterIdentity.mock.calls[0]?.[0];
|
||||
|
||||
await act(async () => {
|
||||
screen.getByRole('button', { name: /重渲染/u }).click();
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(onSetterIdentity).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
expect(onSetterIdentity.mock.calls[1]?.[0]).toBe(initialSetter);
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useCallback, useRef, useState } from 'react';
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import type { Dispatch, SetStateAction } from 'react';
|
||||
|
||||
import type { TextStreamOptions } from '../../services/aiTypes';
|
||||
import type { SelectionStage } from './platformEntryTypes';
|
||||
@@ -75,12 +76,13 @@ type PlatformCreationAgentFlowControllerOptions<
|
||||
enterCreateTab: () => void;
|
||||
setSelectionStage: (stage: SelectionStage) => void;
|
||||
onSessionOpened?: () => void;
|
||||
onSessionChanged?: (session: TSession | null) => void;
|
||||
onOpenError?: (params: { error: unknown; errorMessage: string }) => void;
|
||||
onActionComplete?: (params: {
|
||||
payload: TActionPayload;
|
||||
response: TActionResponse;
|
||||
session: TSession;
|
||||
setSession: (session: TSession) => void;
|
||||
setSession: Dispatch<SetStateAction<TSession | null>>;
|
||||
}) =>
|
||||
| Promise<{ openResult?: boolean } | void>
|
||||
| { openResult?: boolean }
|
||||
@@ -94,7 +96,7 @@ type PlatformCreationAgentFlowControllerOptions<
|
||||
error: unknown;
|
||||
errorMessage: string;
|
||||
session: TSession;
|
||||
setSession: (session: TSession) => void;
|
||||
setSession: Dispatch<SetStateAction<TSession | null>>;
|
||||
}) => void | Promise<void>;
|
||||
};
|
||||
|
||||
@@ -141,12 +143,27 @@ export function usePlatformCreationAgentFlowController<
|
||||
TActionResponse
|
||||
>,
|
||||
) {
|
||||
const [session, setSession] = useState<TSession | null>(null);
|
||||
const [session, rawSetSession] = useState<TSession | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [isBusy, setIsBusy] = useState(false);
|
||||
const [streamingReplyText, setStreamingReplyText] = useState('');
|
||||
const [isStreamingReply, setIsStreamingReply] = useState(false);
|
||||
const latestStreamingReplyTextRef = useRef('');
|
||||
const onSessionChangedRef = useRef(options.onSessionChanged);
|
||||
|
||||
useEffect(() => {
|
||||
onSessionChangedRef.current = options.onSessionChanged;
|
||||
}, [options.onSessionChanged]);
|
||||
|
||||
const setSession = useCallback(
|
||||
(nextSessionOrUpdater: SetStateAction<TSession | null>) => {
|
||||
rawSetSession(nextSessionOrUpdater);
|
||||
if (typeof nextSessionOrUpdater !== 'function') {
|
||||
onSessionChangedRef.current?.(nextSessionOrUpdater);
|
||||
}
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
const updateStreamingReplyText = useCallback((text: string) => {
|
||||
latestStreamingReplyTextRef.current = text;
|
||||
@@ -174,10 +191,10 @@ export function usePlatformCreationAgentFlowController<
|
||||
createPayload ?? options.createPayload,
|
||||
);
|
||||
const nextSession = options.client.selectSession(response);
|
||||
setSession(nextSession);
|
||||
options.enterCreateTab();
|
||||
options.onSessionOpened?.();
|
||||
options.setSelectionStage(options.workspaceStage);
|
||||
setSession(nextSession);
|
||||
return nextSession;
|
||||
} catch (caughtError) {
|
||||
const errorMessage = options.resolveErrorMessage(
|
||||
@@ -212,11 +229,11 @@ export function usePlatformCreationAgentFlowController<
|
||||
try {
|
||||
const response = await options.client.getSession(normalizedSessionId);
|
||||
const nextSession = options.client.selectSession(response);
|
||||
setSession(nextSession);
|
||||
options.enterCreateTab();
|
||||
options.setSelectionStage(
|
||||
nextSession.draft ? options.resultStage : options.workspaceStage,
|
||||
);
|
||||
setSession(nextSession);
|
||||
return nextSession;
|
||||
} catch (caughtError) {
|
||||
setError(
|
||||
|
||||
@@ -120,10 +120,7 @@ import {
|
||||
startLocalPuzzleRun,
|
||||
swapLocalPuzzlePieces,
|
||||
} from '../../services/puzzle-runtime/puzzleLocalRuntime';
|
||||
import {
|
||||
listPuzzleWorks,
|
||||
updatePuzzleWork,
|
||||
} from '../../services/puzzle-works';
|
||||
import { listPuzzleWorks, updatePuzzleWork } from '../../services/puzzle-works';
|
||||
import {
|
||||
createRpgCreationSession,
|
||||
executeRpgCreationAction,
|
||||
@@ -242,14 +239,22 @@ async function openCreateTemplateHub(user: ReturnType<typeof userEvent.setup>) {
|
||||
|
||||
async function findCreationTypeButton(name: string | RegExp) {
|
||||
const matcher =
|
||||
typeof name === 'string' ? new RegExp(name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'u') : name;
|
||||
return within(getPlatformTabPanel('create')).findByRole('button', { name: matcher });
|
||||
typeof name === 'string'
|
||||
? new RegExp(name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'u')
|
||||
: name;
|
||||
return within(getPlatformTabPanel('create')).findByRole('button', {
|
||||
name: matcher,
|
||||
});
|
||||
}
|
||||
|
||||
function queryCreationTypeButton(name: string | RegExp) {
|
||||
const matcher =
|
||||
typeof name === 'string' ? new RegExp(name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'u') : name;
|
||||
return within(getPlatformTabPanel('create')).queryByRole('button', { name: matcher });
|
||||
typeof name === 'string'
|
||||
? new RegExp(name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'u')
|
||||
: name;
|
||||
return within(getPlatformTabPanel('create')).queryByRole('button', {
|
||||
name: matcher,
|
||||
});
|
||||
}
|
||||
|
||||
async function openDraftHub(user: ReturnType<typeof userEvent.setup>) {
|
||||
@@ -258,9 +263,7 @@ async function openDraftHub(user: ReturnType<typeof userEvent.setup>) {
|
||||
await waitFor(() => {
|
||||
expect(panel.getAttribute('aria-hidden')).toBe('false');
|
||||
});
|
||||
expect(
|
||||
await within(panel).findByRole('tab', { name: /全部/u }),
|
||||
).toBeTruthy();
|
||||
expect(await within(panel).findByRole('tab', { name: /全部/u })).toBeTruthy();
|
||||
}
|
||||
|
||||
async function expectDraftHubGeneratingBadgeCountAtLeast(count: number) {
|
||||
@@ -641,7 +644,12 @@ vi.mock('../../services/match3dGeneratedModelCache', () => ({
|
||||
(
|
||||
primaryAssets: Match3DWorkSummary['generatedItemAssets'],
|
||||
fallbackAssets: Match3DWorkSummary['generatedItemAssets'],
|
||||
) => (primaryAssets ? [...primaryAssets] : fallbackAssets ? [...fallbackAssets] : []),
|
||||
) =>
|
||||
primaryAssets
|
||||
? [...primaryAssets]
|
||||
: fallbackAssets
|
||||
? [...fallbackAssets]
|
||||
: [],
|
||||
),
|
||||
preloadMatch3DGeneratedRuntimeAssets: vi.fn(() => Promise.resolve()),
|
||||
}));
|
||||
@@ -1075,20 +1083,16 @@ vi.mock('../match3d-runtime/Match3DRuntimeShell', () => ({
|
||||
}
|
||||
</div>
|
||||
<div data-testid="match3d-runtime-top-level-background-count">
|
||||
{
|
||||
generatedBackgroundAsset?.imageSrc?.trim() ||
|
||||
generatedBackgroundAsset?.imageObjectKey?.trim()
|
||||
? 1
|
||||
: 0
|
||||
}
|
||||
{generatedBackgroundAsset?.imageSrc?.trim() ||
|
||||
generatedBackgroundAsset?.imageObjectKey?.trim()
|
||||
? 1
|
||||
: 0}
|
||||
</div>
|
||||
<div data-testid="match3d-runtime-top-level-container-ui-count">
|
||||
{
|
||||
generatedBackgroundAsset?.containerImageSrc?.trim() ||
|
||||
generatedBackgroundAsset?.containerImageObjectKey?.trim()
|
||||
? 1
|
||||
: 0
|
||||
}
|
||||
{generatedBackgroundAsset?.containerImageSrc?.trim() ||
|
||||
generatedBackgroundAsset?.containerImageObjectKey?.trim()
|
||||
? 1
|
||||
: 0}
|
||||
</div>
|
||||
<button type="button" onClick={onBack}>
|
||||
返回
|
||||
@@ -1243,11 +1247,16 @@ vi.mock('../../games/bark-battle/ui/BarkBattleRuntimeShell', () => ({
|
||||
title?: string;
|
||||
workId?: string;
|
||||
runtimeMode?: string;
|
||||
publishedConfig?: { workId?: string; playerCharacterImageSrc?: string | null } | null;
|
||||
publishedConfig?: {
|
||||
workId?: string;
|
||||
playerCharacterImageSrc?: string | null;
|
||||
} | null;
|
||||
onExit?: () => void;
|
||||
}) => (
|
||||
<div className="bark-battle-runtime-shell-mock">
|
||||
<div>汪汪声浪运行态:{title ?? '未命名'} / {workId ?? 'missing-work'}</div>
|
||||
<div>
|
||||
汪汪声浪运行态:{title ?? '未命名'} / {workId ?? 'missing-work'}
|
||||
</div>
|
||||
<div data-testid="bark-battle-runtime-mode">
|
||||
{runtimeMode ?? 'missing-mode'}
|
||||
</div>
|
||||
@@ -1842,7 +1851,8 @@ function buildMockMatch3DRun(profileId: string): Match3DRunSnapshot {
|
||||
|
||||
const match3DGeneratedUiAsset = {
|
||||
prompt: '果园竖屏纯背景',
|
||||
imageSrc: '/generated-match3d-assets/session/profile/background/background.png',
|
||||
imageSrc:
|
||||
'/generated-match3d-assets/session/profile/background/background.png',
|
||||
imageObjectKey:
|
||||
'generated-match3d-assets/session/profile/background/background.png',
|
||||
containerPrompt: '果园浅盘容器',
|
||||
@@ -2308,7 +2318,8 @@ beforeEach(() => {
|
||||
index === 0
|
||||
? {
|
||||
...asset,
|
||||
backgroundMusic: asset.backgroundMusic ?? musicCarrier.backgroundMusic,
|
||||
backgroundMusic:
|
||||
asset.backgroundMusic ?? musicCarrier.backgroundMusic,
|
||||
}
|
||||
: {
|
||||
...asset,
|
||||
@@ -2316,7 +2327,7 @@ beforeEach(() => {
|
||||
backgroundMusicTitle: null,
|
||||
backgroundMusicStyle: null,
|
||||
backgroundMusicPrompt: null,
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
vi.mocked(
|
||||
@@ -2334,7 +2345,9 @@ beforeEach(() => {
|
||||
primary,
|
||||
);
|
||||
}
|
||||
const fallbackById = new Map(fallback.map((asset) => [asset.itemId, asset]));
|
||||
const fallbackById = new Map(
|
||||
fallback.map((asset) => [asset.itemId, asset]),
|
||||
);
|
||||
return match3dGeneratedModelCache.normalizeMatch3DGeneratedItemAssetsForRuntime(
|
||||
primary.map((asset) => {
|
||||
const fallbackAsset = fallbackById.get(asset.itemId);
|
||||
@@ -3015,48 +3028,50 @@ beforeEach(() => {
|
||||
vi.mocked(generateAllBarkBattleImageAssets).mockResolvedValue({
|
||||
assets: {
|
||||
'player-character': {
|
||||
imageSrc: '/generated-bark-battle/player.png',
|
||||
assetId: 'asset-player',
|
||||
model: 'gpt-image-2-all',
|
||||
size: '1024*1024',
|
||||
taskId: 'task-player',
|
||||
prompt: 'player',
|
||||
},
|
||||
imageSrc: '/generated-bark-battle/player.png',
|
||||
assetId: 'asset-player',
|
||||
model: 'gpt-image-2-all',
|
||||
size: '1024*1024',
|
||||
taskId: 'task-player',
|
||||
prompt: 'player',
|
||||
},
|
||||
'opponent-character': {
|
||||
imageSrc: '/generated-bark-battle/opponent.png',
|
||||
assetId: 'asset-opponent',
|
||||
model: 'gpt-image-2-all',
|
||||
size: '1024*1024',
|
||||
taskId: 'task-opponent',
|
||||
prompt: 'opponent',
|
||||
},
|
||||
imageSrc: '/generated-bark-battle/opponent.png',
|
||||
assetId: 'asset-opponent',
|
||||
model: 'gpt-image-2-all',
|
||||
size: '1024*1024',
|
||||
taskId: 'task-opponent',
|
||||
prompt: 'opponent',
|
||||
},
|
||||
'ui-background': {
|
||||
imageSrc: '/generated-bark-battle/background.png',
|
||||
assetId: 'asset-background',
|
||||
model: 'gpt-image-2-all',
|
||||
size: '1024*1792',
|
||||
taskId: 'task-background',
|
||||
prompt: 'background',
|
||||
imageSrc: '/generated-bark-battle/background.png',
|
||||
assetId: 'asset-background',
|
||||
model: 'gpt-image-2-all',
|
||||
size: '1024*1792',
|
||||
taskId: 'task-background',
|
||||
prompt: 'background',
|
||||
},
|
||||
},
|
||||
failures: {},
|
||||
});
|
||||
vi.mocked(updateBarkBattleDraftConfig).mockImplementation(async (payload) => ({
|
||||
draftId: payload.draftId,
|
||||
workId: payload.workId ?? 'bark-battle-work-1',
|
||||
title: payload.title,
|
||||
description: payload.description,
|
||||
themeDescription: payload.themeDescription,
|
||||
playerImageDescription: payload.playerImageDescription,
|
||||
opponentImageDescription: payload.opponentImageDescription,
|
||||
playerCharacterImageSrc: payload.playerCharacterImageSrc,
|
||||
opponentCharacterImageSrc: payload.opponentCharacterImageSrc,
|
||||
uiBackgroundImageSrc: payload.uiBackgroundImageSrc,
|
||||
difficultyPreset: payload.difficultyPreset,
|
||||
configVersion: (payload.configVersion ?? 1) + 1,
|
||||
rulesetVersion: payload.rulesetVersion ?? 'bark-battle-ruleset-v1',
|
||||
updatedAt: '2026-05-14T10:01:00.000Z',
|
||||
}));
|
||||
vi.mocked(updateBarkBattleDraftConfig).mockImplementation(
|
||||
async (payload) => ({
|
||||
draftId: payload.draftId,
|
||||
workId: payload.workId ?? 'bark-battle-work-1',
|
||||
title: payload.title,
|
||||
description: payload.description,
|
||||
themeDescription: payload.themeDescription,
|
||||
playerImageDescription: payload.playerImageDescription,
|
||||
opponentImageDescription: payload.opponentImageDescription,
|
||||
playerCharacterImageSrc: payload.playerCharacterImageSrc,
|
||||
opponentCharacterImageSrc: payload.opponentCharacterImageSrc,
|
||||
uiBackgroundImageSrc: payload.uiBackgroundImageSrc,
|
||||
difficultyPreset: payload.difficultyPreset,
|
||||
configVersion: (payload.configVersion ?? 1) + 1,
|
||||
rulesetVersion: payload.rulesetVersion ?? 'bark-battle-ruleset-v1',
|
||||
updatedAt: '2026-05-14T10:01:00.000Z',
|
||||
}),
|
||||
);
|
||||
vi.mocked(listBarkBattleWorks).mockResolvedValue({ items: [] });
|
||||
vi.mocked(listBarkBattleGallery).mockResolvedValue({ items: [] });
|
||||
vi.mocked(publishBarkBattleWork).mockResolvedValue({
|
||||
@@ -3145,31 +3160,33 @@ beforeEach(() => {
|
||||
vi.mocked(listPuzzleWorks).mockResolvedValue({
|
||||
items: [],
|
||||
});
|
||||
vi.mocked(updatePuzzleWork).mockImplementation(async (profileId, payload) => ({
|
||||
item: {
|
||||
workId: `puzzle-work-${profileId}`,
|
||||
profileId,
|
||||
ownerUserId: mockAuthUser.id,
|
||||
sourceSessionId: null,
|
||||
authorDisplayName: mockAuthUser.displayName,
|
||||
workTitle: payload.workTitle ?? payload.levelName,
|
||||
workDescription: payload.workDescription ?? payload.summary,
|
||||
levelName: payload.levelName,
|
||||
summary: payload.summary,
|
||||
themeTags: payload.themeTags,
|
||||
coverImageSrc: payload.coverImageSrc ?? null,
|
||||
coverAssetId: payload.coverAssetId ?? null,
|
||||
publicationStatus: 'draft',
|
||||
updatedAt: '2026-05-12T10:00:00.000Z',
|
||||
publishedAt: null,
|
||||
playCount: 0,
|
||||
remixCount: 0,
|
||||
likeCount: 0,
|
||||
publishReady: false,
|
||||
levels: payload.levels,
|
||||
anchorPack: buildPuzzleAnchorPack(),
|
||||
},
|
||||
}));
|
||||
vi.mocked(updatePuzzleWork).mockImplementation(
|
||||
async (profileId, payload) => ({
|
||||
item: {
|
||||
workId: `puzzle-work-${profileId}`,
|
||||
profileId,
|
||||
ownerUserId: mockAuthUser.id,
|
||||
sourceSessionId: null,
|
||||
authorDisplayName: mockAuthUser.displayName,
|
||||
workTitle: payload.workTitle ?? payload.levelName,
|
||||
workDescription: payload.workDescription ?? payload.summary,
|
||||
levelName: payload.levelName,
|
||||
summary: payload.summary,
|
||||
themeTags: payload.themeTags,
|
||||
coverImageSrc: payload.coverImageSrc ?? null,
|
||||
coverAssetId: payload.coverAssetId ?? null,
|
||||
publicationStatus: 'draft',
|
||||
updatedAt: '2026-05-12T10:00:00.000Z',
|
||||
publishedAt: null,
|
||||
playCount: 0,
|
||||
remixCount: 0,
|
||||
likeCount: 0,
|
||||
publishReady: false,
|
||||
levels: payload.levels,
|
||||
anchorPack: buildPuzzleAnchorPack(),
|
||||
},
|
||||
}),
|
||||
);
|
||||
vi.mocked(listPuzzleGallery).mockResolvedValue({
|
||||
items: [],
|
||||
});
|
||||
@@ -3308,12 +3325,17 @@ beforeEach(() => {
|
||||
const runId = `local-puzzle-run-${item.profileId}`;
|
||||
const firstLevel = item.levels?.[0] ?? null;
|
||||
return {
|
||||
...buildMockPuzzleRun(item.profileId, firstLevel?.levelName ?? item.levelName),
|
||||
...buildMockPuzzleRun(
|
||||
item.profileId,
|
||||
firstLevel?.levelName ?? item.levelName,
|
||||
),
|
||||
runId,
|
||||
entryProfileId: item.profileId,
|
||||
currentLevel: {
|
||||
...buildMockPuzzleRun(item.profileId, firstLevel?.levelName ?? item.levelName)
|
||||
.currentLevel!,
|
||||
...buildMockPuzzleRun(
|
||||
item.profileId,
|
||||
firstLevel?.levelName ?? item.levelName,
|
||||
).currentLevel!,
|
||||
runId,
|
||||
levelId: levelId ?? firstLevel?.levelId ?? null,
|
||||
coverImageSrc: firstLevel?.coverImageSrc ?? item.coverImageSrc,
|
||||
@@ -3447,30 +3469,16 @@ test('create tab shows template tabs and embeds puzzle form by default', async (
|
||||
expect(screen.getByRole('tablist', { name: '玩法模板分类' })).toBeTruthy();
|
||||
expect(
|
||||
screen.getByRole('tablist', { name: '玩法模板分类' }).className,
|
||||
).toContain(
|
||||
'scroll-px-3',
|
||||
);
|
||||
).toContain('scroll-px-3');
|
||||
expect(
|
||||
screen.getByRole('tab', { name: '最近创作' }).getAttribute('aria-selected'),
|
||||
).toBe('true');
|
||||
expect(
|
||||
await findCreationTypeButton('拼图'),
|
||||
).toBeTruthy();
|
||||
expect(
|
||||
await findCreationTypeButton('文字冒险'),
|
||||
).toBeTruthy();
|
||||
expect(
|
||||
await findCreationTypeButton('抓大鹅'),
|
||||
).toBeTruthy();
|
||||
expect(
|
||||
await findCreationTypeButton('汪汪声浪'),
|
||||
).toBeTruthy();
|
||||
expect(
|
||||
await findCreationTypeButton('宝贝识物'),
|
||||
).toBeTruthy();
|
||||
expect(
|
||||
queryCreationTypeButton('智能创作'),
|
||||
).toBeNull();
|
||||
expect(await findCreationTypeButton('拼图')).toBeTruthy();
|
||||
expect(await findCreationTypeButton('文字冒险')).toBeTruthy();
|
||||
expect(await findCreationTypeButton('抓大鹅')).toBeTruthy();
|
||||
expect(await findCreationTypeButton('汪汪声浪')).toBeTruthy();
|
||||
expect(await findCreationTypeButton('宝贝识物')).toBeTruthy();
|
||||
expect(queryCreationTypeButton('智能创作')).toBeNull();
|
||||
expect(
|
||||
screen
|
||||
.getByRole('tab', { name: '最近创作' })
|
||||
@@ -3609,8 +3617,6 @@ test('direct bark battle runtime public code opens published runtime', async ()
|
||||
expect(screen.queryByText('分享给朋友')).toBeNull();
|
||||
});
|
||||
|
||||
|
||||
|
||||
test('bark battle form checks mud points before creating image assets', async () => {
|
||||
const user = userEvent.setup();
|
||||
vi.mocked(getProfileDashboard).mockResolvedValue({
|
||||
@@ -3725,7 +3731,9 @@ test('published bark battle stays visible when refresh temporarily returns only
|
||||
await user.click(within(panel).getByRole('button', { name: /已发布/u }));
|
||||
|
||||
expect(await within(panel).findByText('汪汪测试杯')).toBeTruthy();
|
||||
expect(within(panel).getByRole('button', { name: /查看详情《汪汪测试杯》/u })).toBeTruthy();
|
||||
expect(
|
||||
within(panel).getByRole('button', { name: /查看详情《汪汪测试杯》/u }),
|
||||
).toBeTruthy();
|
||||
});
|
||||
|
||||
test('running match3d form generation can return to draft tab and reopen progress', async () => {
|
||||
@@ -3838,9 +3846,9 @@ test('running match3d persisted draft reopens progress instead of unfinished res
|
||||
await screen.findByRole('button', { name: '生成抓大鹅草稿' }),
|
||||
);
|
||||
expect(await screen.findByText('抓大鹅草稿生成进度')).toBeTruthy();
|
||||
expect(
|
||||
await screen.findAllByText('素材生成仍在后台处理'),
|
||||
).not.toHaveLength(0);
|
||||
expect(await screen.findAllByText('素材生成仍在后台处理')).not.toHaveLength(
|
||||
0,
|
||||
);
|
||||
vi.mocked(match3dCreationClient.getSession).mockClear();
|
||||
|
||||
await user.click(screen.getByRole('button', { name: '返回创作中心' }));
|
||||
@@ -4496,8 +4504,7 @@ test('match3d result trial passes generated 2D image views into first runtime mo
|
||||
imageViews: [1, 2, 3, 4, 5].map((viewIndex) => ({
|
||||
viewId: `view-${String(viewIndex).padStart(2, '0')}`,
|
||||
viewIndex,
|
||||
imageSrc:
|
||||
`/generated-match3d-assets/session/profile/items/match3d-item-1-item/views/view-${String(viewIndex).padStart(2, '0')}.png`,
|
||||
imageSrc: `/generated-match3d-assets/session/profile/items/match3d-item-1-item/views/view-${String(viewIndex).padStart(2, '0')}.png`,
|
||||
imageObjectKey: null,
|
||||
})),
|
||||
modelSrc: null,
|
||||
@@ -5012,9 +5019,9 @@ test('completed baby object match draft viewed immediately does not keep unread
|
||||
await user.click(screen.getByRole('tab', { name: '宝贝识物' }));
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
screen.getByRole('tab', { name: '宝贝识物' }).getAttribute(
|
||||
'aria-selected',
|
||||
),
|
||||
screen
|
||||
.getByRole('tab', { name: '宝贝识物' })
|
||||
.getAttribute('aria-selected'),
|
||||
).toBe('true');
|
||||
});
|
||||
await user.type(await screen.findByLabelText('物品 A'), '苹果');
|
||||
@@ -5165,7 +5172,8 @@ test('puzzle draft generation auto starts trial and runtime back opens draft res
|
||||
render(<TestWrapper withAuth />);
|
||||
|
||||
await openCreateTemplateHub(user);
|
||||
await user.click(screen.getByRole('button', { name: '生成草稿' }));
|
||||
await user.click(await findCreationTypeButton('拼图'));
|
||||
await user.click(await screen.findByRole('button', { name: '生成草稿' }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(updatePuzzleWork).toHaveBeenCalledWith(
|
||||
@@ -5203,10 +5211,14 @@ test('puzzle draft generation auto starts trial and runtime back opens draft res
|
||||
'/generated-puzzle-assets/puzzle-session-auto-1/ui/background.png',
|
||||
);
|
||||
expect(screen.queryByText('拼图结果页')).toBeNull();
|
||||
await waitFor(() => {
|
||||
expect(window.location.pathname).toBe('/runtime/puzzle');
|
||||
expect(window.location.search).toBe(
|
||||
'?runtimeProfileId=puzzle-profile-auto-1&runtimeSessionId=puzzle-session-auto-1&mode=draft',
|
||||
);
|
||||
});
|
||||
|
||||
await user.click(
|
||||
await screen.findByRole('button', { name: '返回上一页' }),
|
||||
);
|
||||
await user.click(await screen.findByRole('button', { name: '返回上一页' }));
|
||||
|
||||
expect(await screen.findByText('拼图结果页')).toBeTruthy();
|
||||
expect(screen.getByDisplayValue('雨夜猫街')).toBeTruthy();
|
||||
@@ -6384,10 +6396,9 @@ test('home recommendation Match3D runtime keeps image, music and UI assets witho
|
||||
expect(
|
||||
screen.getByTestId('match3d-runtime-background-music-count'),
|
||||
).toHaveProperty('textContent', '1');
|
||||
expect(screen.getByTestId('match3d-runtime-container-ui-count')).toHaveProperty(
|
||||
'textContent',
|
||||
'1',
|
||||
);
|
||||
expect(
|
||||
screen.getByTestId('match3d-runtime-container-ui-count'),
|
||||
).toHaveProperty('textContent', '1');
|
||||
expect(
|
||||
screen.getByTestId('match3d-runtime-top-level-background-count'),
|
||||
).toHaveProperty('textContent', '1');
|
||||
@@ -7044,6 +7055,68 @@ test('persisted generating puzzle draft opens generation progress after refresh'
|
||||
expect(screen.queryByText('拼图结果页')).toBeNull();
|
||||
});
|
||||
|
||||
test('persisted generating puzzle draft keeps session polling on the same session', async () => {
|
||||
const user = userEvent.setup();
|
||||
|
||||
vi.mocked(listPuzzleWorks).mockResolvedValue({
|
||||
items: [
|
||||
{
|
||||
workId: 'puzzle-work-session-generating',
|
||||
profileId: 'puzzle-profile-session-generating',
|
||||
ownerUserId: 'user-1',
|
||||
sourceSessionId: 'puzzle-session-generating',
|
||||
authorDisplayName: '测试玩家',
|
||||
workTitle: '生成中拼图',
|
||||
workDescription: '刷新后仍应回到生成面板。',
|
||||
levelName: '生成中拼图',
|
||||
summary: '刷新后仍应回到生成面板。',
|
||||
themeTags: ['雨夜'],
|
||||
coverImageSrc: null,
|
||||
coverAssetId: null,
|
||||
publicationStatus: 'draft',
|
||||
updatedAt: '2026-05-18T12:00:00.000Z',
|
||||
publishedAt: null,
|
||||
playCount: 0,
|
||||
remixCount: 0,
|
||||
likeCount: 0,
|
||||
publishReady: false,
|
||||
generationStatus: 'generating',
|
||||
},
|
||||
],
|
||||
});
|
||||
const persistedGeneratingPuzzleSession = buildMockPuzzleAgentSession({
|
||||
sessionId: 'puzzle-session-generating',
|
||||
stage: 'collecting_anchors',
|
||||
progressPercent: 88,
|
||||
lastAssistantReply: '正在生成拼图草稿。',
|
||||
updatedAt: '2026-05-18T12:00:00.000Z',
|
||||
});
|
||||
vi.mocked(getPuzzleAgentSession).mockResolvedValue({
|
||||
session: persistedGeneratingPuzzleSession,
|
||||
});
|
||||
|
||||
render(<TestWrapper withAuth />);
|
||||
|
||||
await openDraftHub(user);
|
||||
await user.click(await screen.findByRole('button', { name: /继续创作/u }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(getPuzzleAgentSession).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
expect(
|
||||
await screen.findByRole('progressbar', {
|
||||
name: '拼图草稿生成进度',
|
||||
}),
|
||||
).toBeTruthy();
|
||||
|
||||
await act(async () => {
|
||||
await new Promise((resolve) => window.setTimeout(resolve, 120));
|
||||
});
|
||||
|
||||
expect(getPuzzleAgentSession).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
test('published puzzle work card restores its source session for editing', async () => {
|
||||
const user = userEvent.setup();
|
||||
|
||||
@@ -7739,11 +7812,7 @@ test('missing puzzle public detail returns to platform home', async () => {
|
||||
test('direct missing public work detail alert returns to platform home', async () => {
|
||||
const alertSpy = vi.spyOn(window, 'alert').mockImplementation(() => {});
|
||||
|
||||
window.history.replaceState(
|
||||
null,
|
||||
'',
|
||||
'/works/detail?work=PZ-7A7B18D9',
|
||||
);
|
||||
window.history.replaceState(null, '', '/works/detail?work=PZ-7A7B18D9');
|
||||
vi.mocked(listPuzzleGallery).mockResolvedValue({
|
||||
items: [],
|
||||
});
|
||||
@@ -8629,7 +8698,9 @@ test('agent draft result test button enters the opened draft profile instead of
|
||||
name: /继续完善《星砂废都》/u,
|
||||
}),
|
||||
);
|
||||
expect(await screen.findByText('世界档案', {}, { timeout: 5000 })).toBeTruthy();
|
||||
expect(
|
||||
await screen.findByText('世界档案', {}, { timeout: 5000 }),
|
||||
).toBeTruthy();
|
||||
expect(screen.getByText('星砂废都')).toBeTruthy();
|
||||
|
||||
await user.click(
|
||||
@@ -8764,7 +8835,9 @@ test('agent draft result start button enters the opened published draft profile
|
||||
name: /继续完善《星砂废都》/u,
|
||||
}),
|
||||
);
|
||||
expect(await screen.findByText('世界档案', {}, { timeout: 5000 })).toBeTruthy();
|
||||
expect(
|
||||
await screen.findByText('世界档案', {}, { timeout: 5000 }),
|
||||
).toBeTruthy();
|
||||
expect(screen.getByText('星砂废都')).toBeTruthy();
|
||||
|
||||
await user.click(
|
||||
@@ -9084,9 +9157,7 @@ test('agent draft result back button returns to creation hub without syncing res
|
||||
await user.click(screen.getByRole('button', { name: /返回创作/u }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
screen.getByRole('tablist', { name: '玩法模板分类' }),
|
||||
).toBeTruthy();
|
||||
expect(screen.getByRole('tablist', { name: '玩法模板分类' })).toBeTruthy();
|
||||
});
|
||||
|
||||
expect(
|
||||
@@ -9524,8 +9595,12 @@ test('profile page exposes save archive picker as a direct entry', async () => {
|
||||
render(<TestWrapper withAuth onContinueGame={handleContinueGame} />);
|
||||
|
||||
await clickFirstButtonByName(user, '我的');
|
||||
const shortcutRegion = await screen.findByRole('region', { name: '常用功能' });
|
||||
await user.click(within(shortcutRegion).getByRole('button', { name: /存档/u }));
|
||||
const shortcutRegion = await screen.findByRole('region', {
|
||||
name: '常用功能',
|
||||
});
|
||||
await user.click(
|
||||
within(shortcutRegion).getByRole('button', { name: /存档/u }),
|
||||
);
|
||||
|
||||
const closeButton = await screen.findByLabelText('关闭存档');
|
||||
const modal = closeButton.closest('.fixed') as HTMLElement;
|
||||
@@ -10085,7 +10160,9 @@ test('creation hub published work edit keeps loaded detail profile assets instea
|
||||
});
|
||||
await user.click(await screen.findByRole('button', { name: '作品编辑' }));
|
||||
|
||||
expect(await screen.findByText('世界档案', {}, { timeout: 5000 })).toBeTruthy();
|
||||
expect(
|
||||
await screen.findByText('世界档案', {}, { timeout: 5000 }),
|
||||
).toBeTruthy();
|
||||
expect(
|
||||
document.querySelector('video[src="/assets/custom-world/opening.mp4"]'),
|
||||
).toBeTruthy();
|
||||
|
||||
Reference in New Issue
Block a user