Merge remote-tracking branch 'origin/master' into codex/tiaoyitiao

This commit is contained in:
kdletters
2026-06-05 23:45:17 +08:00
11 changed files with 605 additions and 43 deletions

View File

@@ -70,6 +70,7 @@ import type {
PuzzleAgentSessionSnapshot,
SendPuzzleAgentMessageRequest,
} from '../../../packages/shared/src/contracts/puzzleAgentSession';
import { isPuzzleCompileActionReady } from './puzzleDraftGenerationState';
import type { PuzzleCreativeTemplateSelection } from '../../../packages/shared/src/contracts/puzzleCreativeTemplate';
import type {
PuzzleRunSnapshot,
@@ -6279,7 +6280,7 @@ export function PlatformEntryFlowShellImpl({
sessionController.setCreationTypeError(errorMessage);
setPuzzleCreationError(errorMessage);
},
onActionComplete: async ({ payload, response, setSession }) => {
onActionComplete: async ({ payload, response, session, setSession }) => {
setPuzzleOperation(response.operation);
setSession(response.session);
const formPayload = buildPuzzleFormPayloadFromAction(payload);
@@ -6303,6 +6304,47 @@ export function PlatformEntryFlowShellImpl({
if (payload.action === 'compile_puzzle_draft') {
const openResult = selectionStageRef.current === 'puzzle-generating';
if (!isPuzzleCompileActionReady(response.session)) {
const nextPayload =
formPayload ?? buildPuzzleFormPayloadFromSession(response.session);
const fallbackGenerationState = createPuzzleDraftGenerationStateFromPayload(
nextPayload,
response.session,
);
const nextGenerationState = mergePuzzleSessionProgressIntoGenerationState(
puzzleGenerationState ?? fallbackGenerationState,
response.session,
);
activePuzzleGenerationSessionIdRef.current = response.session.sessionId;
setSelectionStage('puzzle-generating');
markDraftGenerating('puzzle', [
response.session.sessionId,
buildPuzzleResultWorkId(response.session.sessionId),
response.session.publishedProfileId,
buildPuzzleResultProfileId(response.session.sessionId),
]);
markPendingDraftGenerating(
'puzzle',
response.session.sessionId,
buildPendingPuzzleDraftMetadata(nextPayload),
);
setPuzzleGenerationState(nextGenerationState);
setPuzzleBackgroundCompileTasks((current) => {
const next = { ...current };
if (session.sessionId !== response.session.sessionId) {
delete next[session.sessionId];
}
next[response.session.sessionId] = {
session: response.session,
payload: nextPayload,
generationState: nextGenerationState,
error: null,
};
return next;
});
void refreshPuzzleShelf();
return { openResult: false };
}
setPuzzleGenerationState((current) =>
current
? resolveFinishedMiniGameDraftGenerationState(current, 'ready', {
@@ -7197,6 +7239,22 @@ export function PlatformEntryFlowShellImpl({
return;
}
if (hasRecoverableGeneratedPuzzleDraft(latestSession)) {
const payload =
puzzleGenerationViewPayload ??
buildPuzzleFormPayloadFromSession(latestSession);
const generationState =
puzzleGenerationViewState ??
createPuzzleDraftGenerationStateFromPayload(payload, latestSession);
await recoverCompletedPuzzleDraftGeneration({
sessionId: latestSession.sessionId,
payload,
generationState,
setSession: setPuzzleSession,
});
return;
}
setPuzzleSession(latestSession);
setPuzzleBackgroundCompileTasks((current) => {
const task = current[activePuzzleGenerationSessionId];
@@ -7240,6 +7298,9 @@ export function PlatformEntryFlowShellImpl({
};
}, [
activePuzzleGenerationSessionId,
puzzleGenerationViewPayload,
puzzleGenerationViewState,
recoverCompletedPuzzleDraftGeneration,
shouldPollPuzzleGenerationSession,
setPuzzleSession,
]);
@@ -9479,20 +9540,26 @@ export function PlatformEntryFlowShellImpl({
const executeSquareHoleAction = squareHoleFlow.executeAction;
const retryMatch3DDraftGeneration = useCallback(() => {
if (match3dFormDraftPayload && !match3dSession?.draft?.profileId) {
void createMatch3DDraftFromForm(match3dFormDraftPayload);
if (match3dSession?.sessionId) {
const retryPayload =
match3dFormDraftPayload ??
buildMatch3DFormPayloadFromSession(match3dSession);
void executeMatch3DAction({
action: 'match3d_compile_draft',
generateClickSound: retryPayload.generateClickSound,
});
return;
}
void executeMatch3DAction({
action: 'match3d_compile_draft',
generateClickSound: match3dFormDraftPayload?.generateClickSound,
});
if (match3dFormDraftPayload) {
void createMatch3DDraftFromForm(match3dFormDraftPayload);
return;
}
}, [
createMatch3DDraftFromForm,
executeMatch3DAction,
match3dFormDraftPayload,
match3dSession?.draft?.profileId,
match3dSession,
]);
const retrySquareHoleAssetGeneration = useCallback(() => {
@@ -10405,15 +10472,25 @@ export function PlatformEntryFlowShellImpl({
);
const retryPuzzleDraftGeneration = useCallback(() => {
if (puzzleFormDraftPayload) {
void createPuzzleDraftFromForm(puzzleFormDraftPayload);
if (puzzleSession?.sessionId) {
const retryPayload =
puzzleFormDraftPayload ??
buildPuzzleFormPayloadFromSession(puzzleSession);
void executePuzzleAction(
buildPuzzleCompileActionFromFormPayload(retryPayload),
);
return;
}
void executePuzzleAction(
buildPuzzleCompileActionFromFormPayload(puzzleFormDraftPayload),
);
}, [createPuzzleDraftFromForm, executePuzzleAction, puzzleFormDraftPayload]);
if (puzzleFormDraftPayload) {
void createPuzzleDraftFromForm(puzzleFormDraftPayload);
}
}, [
createPuzzleDraftFromForm,
executePuzzleAction,
puzzleFormDraftPayload,
puzzleSession,
]);
const retryVisualNovelDraftGeneration = useCallback(() => {
if (!visualNovelFormDraftPayload) {

View File

@@ -0,0 +1,40 @@
import { describe, expect, it } from 'vitest';
import { isPuzzleCompileActionReady } from './puzzleDraftGenerationState';
import type { PuzzleAgentSessionSnapshot } from '../../../packages/shared/src/contracts/puzzleAgentSession';
describe('isPuzzleCompileActionReady', () => {
it('keeps compile action generating until the draft has a cover image', () => {
const session = {
sessionId: 'puzzle-session-1',
draft: {
coverImageSrc: null,
levels: [
{
generationStatus: 'generating',
coverImageSrc: null,
},
],
},
} as PuzzleAgentSessionSnapshot;
expect(isPuzzleCompileActionReady(session)).toBe(false);
});
it('treats compile action as ready after the selected cover exists', () => {
const session = {
sessionId: 'puzzle-session-1',
draft: {
coverImageSrc: '/generated-puzzle-assets/session/cover.png',
levels: [
{
generationStatus: 'ready',
coverImageSrc: '/generated-puzzle-assets/session/cover.png',
},
],
},
} as PuzzleAgentSessionSnapshot;
expect(isPuzzleCompileActionReady(session)).toBe(true);
});
});

View File

@@ -0,0 +1,20 @@
import type { PuzzleAgentSessionSnapshot } from '../../../packages/shared/src/contracts/puzzleAgentSession';
function hasText(value: string | null | undefined) {
return typeof value === 'string' && value.trim().length > 0;
}
export function isPuzzleCompileActionReady(
session: PuzzleAgentSessionSnapshot,
) {
const draft = session.draft;
if (!draft) {
return false;
}
if (hasText(draft.coverImageSrc)) {
return true;
}
return (
draft.levels?.some((level) => hasText(level.coverImageSrc)) === true
);
}

View File

@@ -4223,6 +4223,115 @@ test('background match3d draft failure notifies and reopens failed retry page',
expect(match3dCreationClient.executeAction).toHaveBeenCalledTimes(1);
});
test('failed match3d draft retry reuses current session instead of creating another draft', async () => {
const user = userEvent.setup();
const failedSession = buildMockMatch3DAgentSession({
sessionId: 'match3d-retry-failed-session',
draft: null,
stage: 'collecting_config',
updatedAt: '2026-05-18T12:05:00.000Z',
});
const persistedFailedWork: Match3DWorkSummary = {
workId: 'match3d-retry-failed-work',
profileId: 'match3d-retry-failed-profile',
ownerUserId: 'user-1',
sourceSessionId: failedSession.sessionId,
gameName: '重试抓鹅',
themeText: '霓虹水果摊',
summary: '抓大鹅素材生成失败,可重新打开处理。',
tags: ['水果', '抓大鹅'],
coverImageSrc: null,
referenceImageSrc: null,
clearCount: 12,
difficulty: 4,
publicationStatus: 'draft',
playCount: 0,
updatedAt: '2026-05-18T12:05:00.000Z',
publishedAt: null,
publishReady: false,
generationStatus: 'generating',
generatedItemAssets: [],
};
let rejectCompile!: (reason?: unknown) => void;
vi.mocked(match3dCreationClient.createSession).mockResolvedValue({
session: failedSession,
});
vi.mocked(match3dCreationClient.executeAction).mockReturnValueOnce(
new Promise((_, reject) => {
rejectCompile = reject;
}),
);
vi.mocked(match3dCreationClient.getSession).mockResolvedValue({
session: failedSession,
});
render(<TestWrapper withAuth />);
await openCreateTemplateHub(user);
await user.click(await findCreationTypeButton('抓大鹅'));
await user.click(
await screen.findByRole('button', { name: '生成抓大鹅草稿' }),
);
await screen.findByRole('progressbar', { name: '抓大鹅草稿生成进度' });
await user.click(screen.getByRole('button', { name: '返回创作中心' }));
await openDraftHub(user);
vi.mocked(listMatch3DWorks).mockResolvedValue({
items: [persistedFailedWork],
});
await act(async () => {
rejectCompile(new Error('抓大鹅素材服务失败'));
await Promise.resolve();
});
const failureDialog = await screen.findByRole('dialog', {
name: '发生错误',
});
await user.click(within(failureDialog).getByRole('button', { name: '关闭' }));
const draftPanel = getPlatformTabPanel('saves');
await user.click(
await within(draftPanel).findByRole('button', {
name: /继续创作《(?:重试抓鹅|抓大鹅草稿)》/u,
}),
);
const reopenedFailureDialog = await screen.findByRole('dialog', {
name: '发生错误',
});
await user.click(
within(reopenedFailureDialog).getByRole('button', { name: '关闭' }),
);
vi.mocked(match3dCreationClient.executeAction).mockResolvedValueOnce({
session: buildMockMatch3DAgentSession({
sessionId: failedSession.sessionId,
stage: 'draft_ready',
draft: {
profileId: persistedFailedWork.profileId,
gameName: persistedFailedWork.gameName,
themeText: persistedFailedWork.themeText,
summary: persistedFailedWork.summary,
tags: persistedFailedWork.tags,
coverImageSrc: null,
referenceImageSrc: null,
clearCount: persistedFailedWork.clearCount,
difficulty: persistedFailedWork.difficulty,
generatedItemAssets: [],
},
}),
});
await user.click(await screen.findByRole('button', { name: '重新生成草稿' }));
await waitFor(() => {
expect(match3dCreationClient.executeAction).toHaveBeenCalledTimes(2);
});
expect(match3dCreationClient.createSession).toHaveBeenCalledTimes(1);
expect(match3dCreationClient.executeAction).toHaveBeenNthCalledWith(
2,
failedSession.sessionId,
expect.objectContaining({ action: 'match3d_compile_draft' }),
);
});
test('running match3d persisted draft reopens progress instead of unfinished result', async () => {
const user = userEvent.setup();
const runningSession = buildMockMatch3DAgentSession({
@@ -4916,6 +5025,113 @@ test('failed parallel puzzle generations stay as separate non-generating drafts'
.toBeTruthy();
});
test('failed puzzle draft retry reuses current session instead of creating another draft', async () => {
const user = userEvent.setup();
const failedSession = buildMockPuzzleAgentSession({
sessionId: 'puzzle-retry-failed-session',
draft: null,
stage: 'collecting_anchors',
updatedAt: '2026-05-18T12:00:00.000Z',
});
const persistedFailedWork: PuzzleWorkSummary = {
workId: `puzzle-work-${failedSession.sessionId}`,
profileId: `puzzle-profile-${failedSession.sessionId}`,
ownerUserId: 'user-1',
sourceSessionId: failedSession.sessionId,
authorDisplayName: '测试玩家',
workTitle: '',
workDescription: '一套雨夜猫街主题拼图。',
levelName: '第1关',
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: 'failed',
levels: [],
};
let rejectCompile!: (reason?: unknown) => void;
vi.mocked(createPuzzleAgentSession).mockResolvedValue({
session: failedSession,
});
vi.mocked(getPuzzleAgentSession).mockResolvedValue({
session: failedSession,
});
vi.mocked(executePuzzleAgentAction).mockReturnValueOnce(
new Promise((_, reject) => {
rejectCompile = reject;
}),
);
render(<TestWrapper withAuth />);
await openCreateTemplateHub(user);
await user.click(await findCreationTypeButton('拼图'));
await user.click(await screen.findByRole('button', { name: '生成草稿' }));
await screen.findByRole('progressbar', { name: '拼图图片生成进度' });
await user.click(screen.getByRole('button', { name: '返回创作中心' }));
await openDraftHub(user);
vi.mocked(listPuzzleWorks).mockResolvedValue({
items: [persistedFailedWork],
});
await act(async () => {
rejectCompile(new Error('拼图图片生成失败'));
await Promise.resolve();
});
const failureDialog = await screen.findByRole('dialog', {
name: '发生错误',
});
await user.click(within(failureDialog).getByRole('button', { name: '关闭' }));
const draftPanel = getPlatformTabPanel('saves');
await user.click(
await within(draftPanel).findByRole('button', {
name: /继续创作《[^》]+》/u,
}),
);
const reopenedFailureDialog = await screen.findByRole('dialog', {
name: '发生错误',
});
await user.click(
within(reopenedFailureDialog).getByRole('button', { name: '关闭' }),
);
vi.mocked(executePuzzleAgentAction).mockResolvedValueOnce({
operation: {
operationId: 'compile-puzzle-retry',
type: 'compile_puzzle_draft',
status: 'completed',
phaseLabel: '已完成',
phaseDetail: '草稿已生成',
progress: 1,
},
session: buildMockPuzzleAgentSession({
sessionId: failedSession.sessionId,
stage: 'ready_to_publish',
progressPercent: 100,
draft: buildReadyPuzzleDraft(),
}),
});
await user.click(await screen.findByRole('button', { name: '重新生成图片' }));
await waitFor(() => {
expect(executePuzzleAgentAction).toHaveBeenCalledTimes(2);
});
expect(createPuzzleAgentSession).toHaveBeenCalledTimes(1);
expect(executePuzzleAgentAction).toHaveBeenNthCalledWith(
2,
failedSession.sessionId,
expect.objectContaining({ action: 'compile_puzzle_draft' }),
);
});
test('running puzzle draft opens generation progress from draft tab', async () => {
const user = userEvent.setup();
const runningSession = buildMockPuzzleAgentSession({