Merge branch 'master' of http://82.157.175.59:3000/GenarrativeAI/Genarrative
Some checks failed
CI / verify (push) Has been cancelled

This commit is contained in:
2026-04-21 09:44:25 +08:00
5 changed files with 103 additions and 13 deletions

View File

@@ -387,7 +387,7 @@ beforeEach(() => {
test('create tab opens game type modal, keeps AIRP and visual novel locked, and enters agent workspace for RPG', async () => {
const user = userEvent.setup();
render(<TestWrapper />);
render(<TestWrapper withAuth />);
await openCreationHub(user);
const createButtons = await screen.findAllByRole('button', {
@@ -522,10 +522,37 @@ test('selecting RPG creation while logged out routes through requireAuth', async
expect(createCustomWorldAgentSession).not.toHaveBeenCalled();
});
test('restoring an agent workspace while logged out opens login modal before loading the protected session', async () => {
const openLoginModal = vi.fn();
window.history.replaceState(
null,
'',
'/?customWorldSessionId=custom-world-agent-session-1',
);
render(
<TestWrapper
authValue={createAuthValue({
user: null,
openLoginModal,
requireAuth: vi.fn(),
})}
/>,
);
await waitFor(() => {
expect(openLoginModal).toHaveBeenCalledTimes(1);
});
expect(openLoginModal).toHaveBeenCalledWith(expect.any(Function));
expect(getCustomWorldAgentSession).not.toHaveBeenCalled();
});
test('starting draft generation leaves the agent workspace and shows the generation progress view', async () => {
const user = userEvent.setup();
render(<TestWrapper />);
render(<TestWrapper withAuth />);
await openNewRpgCreation(user);
@@ -657,7 +684,7 @@ test('existing draft sessions enter the agent preview layout without opening leg
],
});
render(<TestWrapper />);
render(<TestWrapper withAuth />);
await openNewRpgCreation(user);

View File

@@ -228,6 +228,7 @@ export function PreGameSelectionFlow({
const authUi = useAuthUi();
const initialAgentUiStateRef = useRef(readCustomWorldAgentUiState());
const hasAppliedInitialAgentWorkspaceRef = useRef(false);
const hasRequestedInitialAgentWorkspaceAuthRef = useRef(false);
const [generatedCustomWorldProfile, setGeneratedCustomWorldProfile] =
useState<CustomWorldProfile | null>(null);
const [savedCustomWorldEntries, setSavedCustomWorldEntries] = useState<
@@ -400,16 +401,29 @@ export function PreGameSelectionFlow({
);
useEffect(() => {
if (hasAppliedInitialAgentWorkspaceRef.current) {
const initialAgentSessionId = initialAgentUiStateRef.current.activeSessionId;
if (!initialAgentSessionId || hasAppliedInitialAgentWorkspaceRef.current) {
return;
}
setPlatformTab('create');
// URL 或 sessionStorage 中残留的共创工作区属于受保护入口,
// 未登录时只允许先唤起登录弹窗,不能直接恢复会话请求。
if (!authUi?.user) {
if (!hasRequestedInitialAgentWorkspaceAuthRef.current) {
hasRequestedInitialAgentWorkspaceAuthRef.current = true;
authUi?.openLoginModal?.(() => {
setSelectionStage('agent-workspace');
});
}
return;
}
hasAppliedInitialAgentWorkspaceRef.current = true;
if (initialAgentUiStateRef.current.activeSessionId) {
setPlatformTab('create');
setSelectionStage('agent-workspace');
}
}, [setSelectionStage]);
setSelectionStage('agent-workspace');
}, [authUi?.openLoginModal, authUi?.user, setSelectionStage]);
useEffect(() => {
if (!selectedDetailEntry) {
@@ -602,6 +616,16 @@ export function PreGameSelectionFlow({
useEffect(() => {
if (!activeAgentSessionId) {
setAgentSession(null);
setAgentOperation(null);
setIsLoadingAgentSession(false);
setStreamingAgentReplyText('');
setIsStreamingAgentReply(false);
return;
}
if (!authUi?.user) {
setAgentSession(null);
setAgentOperation(null);
setIsLoadingAgentSession(false);
setStreamingAgentReplyText('');
setIsStreamingAgentReply(false);
@@ -644,13 +668,14 @@ export function PreGameSelectionFlow({
};
}, [
activeAgentSessionId,
authUi?.user,
persistAgentUiState,
setSelectionStage,
syncAgentSessionSnapshot,
]);
useEffect(() => {
if (!activeAgentSessionId || !activeAgentOperationId) {
if (!activeAgentSessionId || !activeAgentOperationId || !authUi?.user) {
return;
}
@@ -710,6 +735,7 @@ export function PreGameSelectionFlow({
}, [
activeAgentOperationId,
activeAgentSessionId,
authUi?.user,
persistAgentUiState,
syncAgentSessionSnapshot,
]);