feat: simplify code project creation

This commit is contained in:
inman
2026-09-07 10:06:37 +08:00
parent f8eee430f4
commit af13aca003
15 changed files with 351 additions and 486 deletions

View File

@@ -6,6 +6,9 @@ import { useAuthStore } from '@/stores/auth';
import { useProviderStore } from '@/stores/providers';
import { useSettingsStore } from '@/stores/settings';
import { useUserSyncStore } from '@/stores/user-sync';
import { codingWorkspaceStore } from '@/stores/coding-workspace';
import { useProjectConfigStore } from '@/stores/project-config';
import { createCodingProjectConfigV2 } from '@electron/coding-projects/project-config';
vi.mock('@/components/layout/MainLayout', () => ({
MainLayout: () => (
@@ -41,6 +44,13 @@ vi.mock('@/pages/Settings', () => ({
describe('App programming provider initialization gate', () => {
const initProviders = vi.fn();
const project = {
id: 'local-project',
name: 'Local project',
createdAt: '2026-09-06T00:00:00.000Z',
updatedAt: '2026-09-06T00:00:00.000Z',
lastOpenedAt: '2026-09-06T00:00:00.000Z',
};
beforeEach(() => {
vi.clearAllMocks();
@@ -49,6 +59,18 @@ describe('App programming provider initialization gate', () => {
init: vi.fn(),
});
useProviderStore.setState({ init: initProviders });
codingWorkspaceStore.setState({
activeProjectId: project.id,
activeProject: project,
load: vi.fn().mockResolvedValue(undefined),
});
useProjectConfigStore.setState({
load: vi.fn().mockResolvedValue({
status: 'valid',
config: { ...createCodingProjectConfigV2(), initialized: false },
knowledgeFiles: [],
}),
});
useAuthStore.setState({
initialized: true,
accessToken: 'access-token',
@@ -94,6 +116,13 @@ describe('App programming provider initialization gate', () => {
await waitFor(() => expect(initProviders).toHaveBeenCalledTimes(1));
});
it('opens a valid project without requiring the legacy initialized flag', async () => {
await renderAt('/chat');
expect(await screen.findByText('Programming workspace')).toBeInTheDocument();
expect(screen.queryByText('项目尚未初始化')).not.toBeInTheDocument();
});
it('redirects an orphaned token without a user identity away from a direct workspace route', async () => {
useAuthStore.setState({
initialized: true,