fix(13): emit raw string scalars for sdk --pick output (#239)

This commit is contained in:
Tom Boucher
2026-05-24 19:14:05 -04:00
committed by GitHub
parent 247596079f
commit e95fa8ad7d
3 changed files with 31 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
---
type: Fixed
pr: 13
---
**`gsd-sdk query --pick` now emits raw string scalars (CJS parity restored)** — the SDK dispatch formatter previously JSON-stringified picked values, which wrapped string outputs in literal quotes and broke shell capture/path composition. The pick formatter now returns raw string scalars with newline while preserving JSON output for non-string picks. (#13)

View File

@@ -178,6 +178,12 @@ describe('stage: formatting', () => {
expect(formatSuccess({ nested: { value: 3 } }, 'json', 'nested.value')).toBe('3\n');
});
it('formatSuccess emits raw scalar for picked string fields', () => {
expect(formatSuccess({ slug: 'cli-agent-transcript-persistence' }, 'json', 'slug')).toBe(
'cli-agent-transcript-persistence\n',
);
});
it('formatPick returns input unchanged when no pickField provided', () => {
const input = { ok: true };
expect(formatPick(input)).toBe(input);
@@ -362,6 +368,23 @@ describe('end-to-end IR contract', () => {
expect(out.exit_code).toBe(0);
});
it('applies --pick to native json string output without quote wrapping', async () => {
const registry = createRegistry();
const out = await runQueryDispatch({
registry,
projectDir: tmpDir,
cjsFallbackEnabled: true,
resolveGsdToolsPath: () => '',
dispatchNative: async () => ({ data: { slug: 'cli-agent-transcript-persistence' } }),
topology: createCommandTopology(registry),
}, ['generate-slug', 'CLI agent transcript persistence', '--pick', 'slug']);
expect(out.ok).toBe(true);
if (!out.ok) throw new Error('expected success');
expect(out.stdout).toBe('cli-agent-transcript-persistence\n');
expect(out.exit_code).toBe(0);
});
it('returns structured error for unknown command when fallback disabled', async () => {
const registry = createRegistry();
const out = await runQueryDispatch({

View File

@@ -86,6 +86,9 @@ export function formatSuccess(data: unknown, format: DispatchSuccessFormat, pick
return data.endsWith('\n') ? data : `${data}\n`;
}
const output = formatPick(data, pickField);
if (pickField && typeof output === 'string') {
return output.endsWith('\n') ? output : `${output}\n`;
}
return `${JSON.stringify(output === undefined ? null : output, null, 2)}\n`;
}