fix(orbit): add QueryRaw for streaming llm/GOON response body verbatim

Note

This MR was authored by an agent

What does this MR do and why?

Adds QueryRaw as a new, backwards-compatible method on OrbitService that streams the Orbit query response body verbatim to an io.Writer, bypassing json.NewDecoder.

The problem

OrbitService.Query decodes the response body via json.NewDecoder into *OrbitQueryResult. This works for response_format=raw (JSON envelope) but fails for response_format=llm: the Orbit API returns GOON/TOON plain text (Content-Type: text/plain) whose first byte is @ (the GOON header marker). The decoder rejects it with:

invalid character '@' looking for beginning of value

This affects any Go consumer of the SDK that calls Query with response_format=llm — not just glab. The workaround in gitlab-org/cli!3269 was to bypass Query entirely and call client.NewRequest + client.Do(req, &bytes.Buffer{}) directly (which triggers the io.Writer copy-path in Do instead of the JSON decoder). That's the right tactical move for glab, but it's a workaround that every future SDK consumer would need to rediscover.

The fix

New method with signature:

func (s *OrbitService) QueryRaw(opt *OrbitQueryRequest, w io.Writer, options ...RequestOptionFunc) (*Response, error)

QueryRaw calls NewRequest + Do(req, w) internally, streaming bytes from the wire directly into w without any JSON decode. Non-2xx responses still go through CheckResponse and are returned as errors; w is only written on success.

Query is completely unchanged — its signature, behaviour, and generated mock are unmodified. This is a purely additive change.

When to use which method

Method Works for Notes
Query response_format=raw Returns typed *OrbitQueryResult; fails on llm
QueryRaw llm, raw, or any future format Streams bytes verbatim; caller owns the io.Writer

Tests

Three new tests in orbit_test.go:

  • TestOrbitService_QueryRaw_LLMFormat — sends a multi-line GOON body beginning with @header and asserts byte-exact equality with the writer. Confirms no JSON decode is attempted.
  • TestOrbitService_QueryRaw_RawFormat — sends compact JSON and asserts byte-exact forwarding. Guards against any future client-side re-marshaling that would change whitespace or key order.
  • TestOrbitService_QueryRaw_NonTwoXXReturnsError — 403 response returns an error; the writer is not touched.
Edited by Dmitry Gruzd

Merge request reports

Loading