mirror of
https://github.com/garrytan/gbrain.git
synced 2026-07-28 14:59:47 +00:00
`gbrain search <q> --json` silently printed human text: the search/query ops declare no json param, parseOpArgs dropped the undeclared trailing flag, and formatResult only emitted human text or --explain output. Treat --json as a CLI-local boolean formatter flag in parseOpArgs (never added to the operation contract; MCP validateParams ignores the extra key on the routed path) and have formatResult's search/query case emit the raw result array as parseable JSON when set. Takeover of #2531, rebased onto master (keeps bigintToStringReplacer at the local-path formatResult call site). Co-authored-by: javieraldape <javieraldape@users.noreply.github.com> Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
29 lines
752 B
TypeScript
29 lines
752 B
TypeScript
import { describe, expect, test } from 'bun:test';
|
|
import { formatResult } from '../src/cli.ts';
|
|
|
|
describe('formatResult - search/query --json', () => {
|
|
test('search --json renders the raw result array as parseable JSON', () => {
|
|
const out = formatResult('search', [
|
|
{
|
|
slug: 'docs/example',
|
|
score: 0.42,
|
|
chunk_text: 'Example result text',
|
|
},
|
|
], { json: true });
|
|
|
|
expect(JSON.parse(out)).toEqual([
|
|
{
|
|
slug: 'docs/example',
|
|
score: 0.42,
|
|
chunk_text: 'Example result text',
|
|
},
|
|
]);
|
|
});
|
|
|
|
test('query --json keeps empty results machine-readable', () => {
|
|
const out = formatResult('query', [], { json: true });
|
|
|
|
expect(JSON.parse(out)).toEqual([]);
|
|
});
|
|
});
|