feat(makelore): add platform oidc login

This commit is contained in:
brother7 committed 2026-10-10 17:29:33 +08:00
1 parent 87d3f03d75
commit 7236def07d
12 files changed
+528 -10

No files matched your search

+34 -1
View File
@@ -8,11 +8,16 @@ import { useProviderStore } from '@/stores/providers';
import { codingRecoveryAccount } from '@/lib/coding-login-recovery';
const hostApiFetchMock = vi.hoisted(() => vi.fn());
const invokeIpcMock = vi.hoisted(() => vi.fn());
vi.mock('@/lib/host-api', () => ({
hostApiFetch: (...args: unknown[]) => hostApiFetchMock(...args),
}));
vi.mock('@/lib/api-client', () => ({
invokeIpc: (...args: unknown[]) => invokeIpcMock(...args),
}));
const loginWithPassword = vi.fn();
const loginWithMobile = vi.fn();
const logout = vi.fn();
@@ -128,6 +133,7 @@ describe('Login page', () => {
useProviderStore.setState({ importUserModelConfig });
importUserModelConfig.mockResolvedValue(undefined);
logout.mockResolvedValue(undefined);
invokeIpcMock.mockResolvedValue(undefined);
hostApiFetchMock.mockImplementation(async (path: string) => {
if (path === '/api/auth/public-config') {
return {
@@ -153,7 +159,7 @@ describe('Login page', () => {
vi.useRealTimers();
});
it('shows native Chinese tabs with password login as the default and no browser authorization surface', async () => {
it('shows native Chinese tabs with password login as the default and a platform login action', async () => {
renderLogin();
await screen.findByRole('link', { name: '用户协议' });
@@ -168,9 +174,36 @@ describe('Login page', () => {
loginButton.compareDocumentPosition(rememberPasswordCheckbox)
& Node.DOCUMENT_POSITION_FOLLOWING,
).toBe(Node.DOCUMENT_POSITION_FOLLOWING);
expect(screen.getByRole('button', { name: '平台账号登录' })).toBeDisabled();
expect(screen.queryByText(/浏览器|微信|注册/)).not.toBeInTheDocument();
});
it('opens the platform authorization URL through Main after agreement', async () => {
hostApiFetchMock.mockImplementation(async (path: string) => {
if (path === '/api/auth/public-config') return { success: true, links: {} };
if (path === '/api/auth/remembered-password') return { success: true, available: false };
if (path === '/api/auth/platform/start') {
return { success: true, authorizationUrl: 'https://square.example.test/authorize?state=state-1' };
}
return { success: true };
});
renderLogin();
const agreement = await screen.findByRole('checkbox', { name: /我已阅读并同意/ });
fireEvent.click(agreement);
fireEvent.click(screen.getByRole('button', { name: '平台账号登录' }));
await waitFor(() => expect(invokeIpcMock).toHaveBeenCalledWith(
'shell:openExternal',
'https://square.example.test/authorize?state=state-1',
));
expect(hostApiFetchMock).toHaveBeenCalledWith('/api/auth/platform/start', {
method: 'POST',
cache: 'no-store',
body: JSON.stringify({}),
});
});
it('restores OS-protected password credentials and keeps remember password selected', async () => {
hostApiFetchMock.mockImplementation(async (path: string) => {
if (path === '/api/auth/public-config') return { success: true, links: {} };