feat(gateway): enhance gateway readiness handling and batch sync configuration (#851)

Co-authored-by: paisley <8197966+su8su@users.noreply.github.com>
This commit is contained in:
Haze
2026-04-14 15:42:37 +08:00
committed by GitHub
Unverified
parent 758a8f8c94
commit 30bd8c08f9
14 changed files with 626 additions and 69 deletions

View File

@@ -38,4 +38,42 @@ describe('gateway store event wiring', () => {
handlers.get('gateway:status')?.({ state: 'stopped', port: 18789 });
expect(useGatewayStore.getState().status.state).toBe('stopped');
});
it('propagates gatewayReady field from status events', async () => {
hostApiFetchMock.mockResolvedValueOnce({ state: 'running', port: 18789, gatewayReady: false });
const handlers = new Map<string, (payload: unknown) => void>();
subscribeHostEventMock.mockImplementation((eventName: string, handler: (payload: unknown) => void) => {
handlers.set(eventName, handler);
return () => {};
});
const { useGatewayStore } = await import('@/stores/gateway');
await useGatewayStore.getState().init();
// Initially gatewayReady=false from the status fetch
expect(useGatewayStore.getState().status.gatewayReady).toBe(false);
// Simulate gateway.ready event setting gatewayReady=true
handlers.get('gateway:status')?.({ state: 'running', port: 18789, gatewayReady: true });
expect(useGatewayStore.getState().status.gatewayReady).toBe(true);
});
it('treats undefined gatewayReady as ready for backwards compatibility', async () => {
hostApiFetchMock.mockResolvedValueOnce({ state: 'running', port: 18789 });
const handlers = new Map<string, (payload: unknown) => void>();
subscribeHostEventMock.mockImplementation((eventName: string, handler: (payload: unknown) => void) => {
handlers.set(eventName, handler);
return () => {};
});
const { useGatewayStore } = await import('@/stores/gateway');
await useGatewayStore.getState().init();
const status = useGatewayStore.getState().status;
// gatewayReady is undefined (old gateway version) — should be treated as ready
expect(status.gatewayReady).toBeUndefined();
expect(status.state === 'running' && status.gatewayReady !== false).toBe(true);
});
});