Files
gbrain/test/cli-format-search-json.test.ts
22022182f8 fix(cli): honor search --json output (#2042)
`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>
2026-07-21 14:20:25 -07:00

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([]);
});
});