fix: address coderabbit query seam findings

This commit is contained in:
Tom Boucher
2026-05-03 18:46:45 -04:00
parent 3e22c70fac
commit ac883f8150
3 changed files with 26 additions and 2 deletions

View File

@@ -1,8 +1,12 @@
import { describe, it, expect, vi } from 'vitest';
import { describe, it, expect, vi, afterEach } from 'vitest';
import { QueryExecutionPolicy } from './query-execution-policy.js';
import { setTransportPolicy, clearTransportPolicy } from './gsd-transport-policy.js';
describe('QueryExecutionPolicy', () => {
afterEach(() => {
clearTransportPolicy();
});
it('applies transport policy to transport.run', async () => {
const run = vi.fn().mockResolvedValue({ ok: true });
const policy = new QueryExecutionPolicy({ run } as never);
@@ -23,6 +27,5 @@ describe('QueryExecutionPolicy', () => {
const [, policyArg] = run.mock.calls[0];
expect(policyArg).toEqual({ preferNative: true, allowFallbackToSubprocess: false });
clearTransportPolicy();
});
});

View File

@@ -10,6 +10,9 @@ export function formatQueryRawOutput(registryCommand: string, data: unknown): st
}
if (registryCommand === 'commit') {
if (data == null || typeof data !== 'object' || Array.isArray(data)) {
return JSON.stringify(data, null, 2);
}
const d = data as Record<string, unknown>;
if (d.committed === true) {
return d.hash != null ? String(d.hash) : 'committed';
@@ -33,6 +36,9 @@ export function formatQueryRawOutput(registryCommand: string, data: unknown): st
}
if (registryCommand === 'config-set') {
if (data == null || typeof data !== 'object' || Array.isArray(data)) {
return JSON.stringify(data, null, 2);
}
const d = data as Record<string, unknown>;
if ((d.updated === true || d.set === true) && d.key !== undefined) {
const v = d.value;
@@ -48,6 +54,9 @@ export function formatQueryRawOutput(registryCommand: string, data: unknown): st
}
if (registryCommand === 'state.begin-phase' || registryCommand === 'state begin-phase') {
if (data == null || typeof data !== 'object' || Array.isArray(data)) {
return JSON.stringify(data, null, 2);
}
const d = data as Record<string, unknown>;
const u = d.updated as string[] | undefined;
return Array.isArray(u) && u.length > 0 ? 'true' : 'false';

View File

@@ -103,6 +103,18 @@ export class QuerySubprocessAdapter {
(error, stdout, stderr) => {
const stderrStr = stderr?.toString() ?? '';
if (error) {
if (error.killed || (error as NodeJS.ErrnoException).code === 'ETIMEDOUT') {
reject(
this.deps.createToolsError(
`gsd-tools timed out after ${this.deps.timeoutMs}ms: ${command} ${args.join(' ')}`,
command,
args,
null,
stderrStr,
),
);
return;
}
reject(
this.deps.createToolsError(
`gsd-tools exited with code ${error.code ?? 'unknown'}: ${command} ${args.join(' ')}${stderrStr ? `\n${stderrStr}` : ''}`,