test: cover tools error mapping and unify timeout fallback check
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import type { QueryResult } from './query/utils.js';
|
import type { QueryResult } from './query/utils.js';
|
||||||
import type { QueryRegistry } from './query/registry.js';
|
import type { QueryRegistry } from './query/registry.js';
|
||||||
import type { TransportMode } from './gsd-transport-policy.js';
|
import type { TransportMode } from './gsd-transport-policy.js';
|
||||||
import { isTimeoutLikeError } from './query-failure-classification.js';
|
import { toFailureSignal } from './query-failure-classification.js';
|
||||||
|
|
||||||
export interface TransportRequest {
|
export interface TransportRequest {
|
||||||
legacyCommand: string;
|
legacyCommand: string;
|
||||||
@@ -49,7 +49,7 @@ export class GSDTransport {
|
|||||||
// Do not subprocess-fallback after a timed-out native dispatch:
|
// Do not subprocess-fallback after a timed-out native dispatch:
|
||||||
// the timeout does not cancel the native handler, so falling through
|
// the timeout does not cancel the native handler, so falling through
|
||||||
// would run the same command twice (double-execution race).
|
// would run the same command twice (double-execution race).
|
||||||
if (isTimeoutLikeError(error)) throw error;
|
if (toFailureSignal(error).kind === 'timeout') throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
21
sdk/src/query-tools-error-mapper.test.ts
Normal file
21
sdk/src/query-tools-error-mapper.test.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { describe, expect, it } from 'vitest';
|
||||||
|
import { ErrorClassification, GSDError } from './errors.js';
|
||||||
|
import { toGSDToolsError } from './query-tools-error-mapper.js';
|
||||||
|
|
||||||
|
describe('query tools error mapper', () => {
|
||||||
|
it('maps GSDError to GSDToolsError exit code', () => {
|
||||||
|
const err = toGSDToolsError('state', ['load'], new GSDError('bad input', ErrorClassification.Validation));
|
||||||
|
expect(err.exitCode).toBe(10);
|
||||||
|
expect(err.message).toBe('bad input');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('attaches timeout classification when message indicates timeout', () => {
|
||||||
|
const err = toGSDToolsError('state', ['load'], new Error('gsd-tools timed out after 1234ms: state load'));
|
||||||
|
expect(err.classification).toEqual({ kind: 'timeout', timeoutMs: 1234 });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not attach timeout classification for non-timeout failures', () => {
|
||||||
|
const err = toGSDToolsError('state', ['load'], new Error('boom'));
|
||||||
|
expect(err.classification).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user