refactor: deepen GSDTools query execution seams (#3085)
* refactor: deepen gsdtools query execution seams * docs: add changeset for query seam deepening * docs: fix changeset summary text * fix: address coderabbit query seam findings * test: address remaining coderabbit findings and notes * refactor: use internal gsdtools error type import
This commit is contained in:
43
sdk/src/query-native-hotpath-adapter.test.ts
Normal file
43
sdk/src/query-native-hotpath-adapter.test.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { QueryNativeHotpathAdapter } from './query-native-hotpath-adapter.js';
|
||||
|
||||
describe('QueryNativeHotpathAdapter', () => {
|
||||
it('uses native Adapter when native query enabled', async () => {
|
||||
const native = {
|
||||
dispatchJson: vi.fn().mockResolvedValue({ ok: true }),
|
||||
dispatchRaw: vi.fn().mockResolvedValue('ok'),
|
||||
} as never;
|
||||
|
||||
const adapter = new QueryNativeHotpathAdapter(
|
||||
() => true,
|
||||
native,
|
||||
vi.fn(),
|
||||
vi.fn(),
|
||||
);
|
||||
|
||||
await expect(adapter.dispatch('state', ['load'], 'state.load', [], 'json')).resolves.toEqual({ ok: true });
|
||||
await expect(adapter.dispatch('commit', ['m'], 'commit', ['m'], 'raw')).resolves.toEqual('ok');
|
||||
expect((native as { dispatchJson: ReturnType<typeof vi.fn> }).dispatchJson).toHaveBeenCalledWith('state', ['load'], 'state.load', []);
|
||||
expect((native as { dispatchRaw: ReturnType<typeof vi.fn> }).dispatchRaw).toHaveBeenCalledWith('commit', ['m'], 'commit', ['m']);
|
||||
});
|
||||
|
||||
it('uses fallback when native query disabled', async () => {
|
||||
const execJsonFallback = vi.fn().mockResolvedValue({ from: 'fallback-json' });
|
||||
const execRawFallback = vi.fn().mockResolvedValue('fallback-raw');
|
||||
|
||||
const adapter = new QueryNativeHotpathAdapter(
|
||||
() => false,
|
||||
{
|
||||
dispatchJson: vi.fn(),
|
||||
dispatchRaw: vi.fn(),
|
||||
} as never,
|
||||
execJsonFallback,
|
||||
execRawFallback,
|
||||
);
|
||||
|
||||
await expect(adapter.dispatch('state', ['load'], 'state.load', [], 'json')).resolves.toEqual({ from: 'fallback-json' });
|
||||
await expect(adapter.dispatch('commit', ['m'], 'commit', ['m'], 'raw')).resolves.toEqual('fallback-raw');
|
||||
expect(execJsonFallback).toHaveBeenCalledWith('state', ['load']);
|
||||
expect(execRawFallback).toHaveBeenCalledWith('commit', ['m']);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user