🐛 fix(connect): 修复首次启动数据库连接偶发失败

This commit is contained in:
DurianPankek
2026-03-21 16:17:29 +08:00
parent 36a57f9601
commit 7bc358d612
5 changed files with 383 additions and 26 deletions

View File

@@ -0,0 +1,26 @@
import { describe, expect, it } from 'vitest';
import { getConnectionWorkbenchState } from './startupReadiness';
describe('startup readiness helpers', () => {
it('blocks sidebar interactions before local store hydration completes', () => {
expect(getConnectionWorkbenchState(false, false)).toEqual({
ready: false,
message: '正在加载本地配置...',
});
});
it('keeps sidebar blocked until initial global proxy sync finishes', () => {
expect(getConnectionWorkbenchState(true, false)).toEqual({
ready: false,
message: '正在同步全局代理配置...',
});
});
it('unblocks sidebar after startup configuration is fully applied', () => {
expect(getConnectionWorkbenchState(true, true)).toEqual({
ready: true,
message: '',
});
});
});

View File

@@ -0,0 +1,26 @@
export interface ConnectionWorkbenchState {
ready: boolean;
message: string;
}
export function getConnectionWorkbenchState(
isStoreHydrated: boolean,
hasAppliedInitialGlobalProxy: boolean
): ConnectionWorkbenchState {
if (!isStoreHydrated) {
return {
ready: false,
message: '正在加载本地配置...',
};
}
if (!hasAppliedInitialGlobalProxy) {
return {
ready: false,
message: '正在同步全局代理配置...',
};
}
return {
ready: true,
message: '',
};
}