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:
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user