完善客户端模块与工作区能力
This commit is contained in:
@@ -38,11 +38,21 @@ describe('global Agent user profile', () => {
|
||||
expect(context).toContain('用户性别:男');
|
||||
});
|
||||
|
||||
it('does not persist temporary signed avatar URLs locally', () => {
|
||||
useUserProfileStore.getState().setAvatarUrl('user-a', 'https://oss.example/avatar.webp?signature=temporary');
|
||||
|
||||
const persisted = JSON.parse(localStorage.getItem('niancode-user-agent-profiles') ?? '{}') as {
|
||||
state?: { profilesByUserId?: Record<string, { avatarUrl?: string | null }> };
|
||||
};
|
||||
expect(persisted.state?.profilesByUserId?.['user-a']?.avatarUrl).toBeNull();
|
||||
});
|
||||
|
||||
it('uses the server profile as the source of truth when it already has a version', async () => {
|
||||
getAgentProfileMock.mockResolvedValue({
|
||||
display_name: '云端名字',
|
||||
age: null,
|
||||
gender: null,
|
||||
avatar_url: 'https://cdn.example/avatar.webp',
|
||||
share_age_with_agents: false,
|
||||
share_gender_with_agents: false,
|
||||
analysis_enabled: true,
|
||||
@@ -60,6 +70,7 @@ describe('global Agent user profile', () => {
|
||||
displayName: '云端名字',
|
||||
age: null,
|
||||
gender: 'undisclosed',
|
||||
avatarUrl: 'https://cdn.example/avatar.webp',
|
||||
version: 3,
|
||||
pendingSync: false,
|
||||
});
|
||||
@@ -156,6 +167,55 @@ describe('global Agent user profile', () => {
|
||||
expect(useUserProfileStore.getState().profilesByUserId['user-a']?.version).toBe(4);
|
||||
});
|
||||
|
||||
it('uploads session data without replacing local profile fields with cloud values', async () => {
|
||||
putAgentProfileMock.mockResolvedValue({
|
||||
display_name: '云端其他名字',
|
||||
age: 20,
|
||||
gender: 'female',
|
||||
share_age_with_agents: true,
|
||||
share_gender_with_agents: true,
|
||||
analysis_enabled: true,
|
||||
completed: true,
|
||||
version: 5,
|
||||
updated_at: '2026-07-12T00:00:00Z',
|
||||
});
|
||||
useUserProfileStore.getState().saveProfile('user-a', {
|
||||
displayName: '本地名字', age: 16, gender: 'male',
|
||||
});
|
||||
useUserProfileStore.setState((state) => ({
|
||||
profilesByUserId: {
|
||||
...state.profilesByUserId,
|
||||
'user-a': { ...state.profilesByUserId['user-a'], version: 4 },
|
||||
},
|
||||
}));
|
||||
const sessionData = {
|
||||
project_id: 'prj_1',
|
||||
session_id: 'ses_1',
|
||||
updated_at: '2026-08-13T10:00:00.000Z',
|
||||
messages: [{ role: 'assistant' as const, text: '这是自然语言回答。' }],
|
||||
};
|
||||
|
||||
await useUserProfileStore.getState().pushSessionData('user-a', 'access-token', sessionData);
|
||||
|
||||
expect(putAgentProfileMock).toHaveBeenCalledWith('access-token', {
|
||||
display_name: '本地名字',
|
||||
age: 16,
|
||||
gender: 'male',
|
||||
share_age_with_agents: true,
|
||||
share_gender_with_agents: true,
|
||||
analysis_enabled: true,
|
||||
version: 4,
|
||||
session_data: sessionData,
|
||||
});
|
||||
expect(useUserProfileStore.getState().profilesByUserId['user-a']).toMatchObject({
|
||||
displayName: '本地名字',
|
||||
age: 16,
|
||||
gender: 'male',
|
||||
version: 5,
|
||||
pendingSync: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('reloads the server profile after a version conflict instead of retrying the old edit', async () => {
|
||||
putAgentProfileMock.mockRejectedValue(new AgentProfileApiError(409, 'Profile version conflict'));
|
||||
getAgentProfileMock.mockResolvedValue({
|
||||
|
||||
Reference in New Issue
Block a user