Repository navigation
fix(cli): render paginated API results in text mode - #3984
Merged
Merged
Conversation
dvd233
marked this pull request as ready for review
October 6, 2026 08:13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
weknora api --paginate --format textfetches and merges the pages, then fails withFormatOptions.Emit: cannot emit text mode as JSON; caller must render human-readable separately. The same failure occurs when text is selected throughWEKNORA_FORMAT=text.This change adds the missing text dispatch after aggregation. Text emits one bare
{data,total}JSON object followed by a newline. JSON and NDJSON keep their existing emitter paths, and the mergedjson.RawMessagevalues retain their precision. Output errors use the existinglocal.file_ioclassification.The paginated GET path also rejects resolved text mode with
--jqbefore making HTTP requests. This covers text selected through the environment; an explicit JSON or NDJSON flag still takes precedence and applies its filter. API help and agent-help now identify JSON as the default and describe text aggregation.Only
cli/cmd/api/api.goand the newcli/cmd/api/paginate_text_test.gochange. The shared FormatOptions.Emit text guard, pagination loop, raw fallback, and non-GET/non-paginated behavior stay unchanged.Type of Change
Related Issue
This is independent of #3983. That PR propagates response-body read errors; this PR handles successfully read and aggregated text results. Both patches apply cleanly in either order, and the combined tree passes the full CLI tests, race checks, vet, and build. Neither patch depends on the other.
Testing
Validated locally on Linux/amd64 using Go 1.26.8 from the separate
cli/module:go test -count=1 ./...go test -race -count=1 ./...go vet ./...go build ./...go test ./cmd/api -run TestAPI_Paginate -count=20golangci-lint run --new-from-rev=bccb4b151bae403508da77fbb174efc79dc47c1a ./...(v2.14.0, zero issues)go mod verify, gofmt/gofumpt checks, andgit diff --cached --checkThe identical regression file has 10 expected failing cases and 16 passing compatibility cases on baseline
bccb4b151bae403508da77fbb174efc79dc47c1a; all 26 pass with the fix. It exercises the real root command and SDK against local HTTP fixtures, including single/multiple/empty pages, format precedence, jq, raw fallback, non-GET behavior, large numeric values, and body/newline writer errors.Separately built baseline and fixed binaries were exercised in 22 cases each, including a real PTY. Previously successful machine/raw outputs remain byte-identical. Environment-selected text with either a valid or malformed jq expression now exits 2 with empty stdout and no HTTP calls. The same 22 cases pass with both patches applied.
Two independent coding-agent reviews approved this exact patch after rerunning their own CLI, transport, writer-error, and compatibility probes. Hosted source-bound validation passed on this exact feature commit, including the strict 10-fail/16-pass baseline and 26-pass fixed checks, full CLI tests/race/vet/build, and repository scripts.
Upstream validation also passed: CLI build, race tests and vet on Linux, macOS and Windows, plus the Go Lint workflow.
Scope: the full default CLI suite includes acceptance contracts. Root backend/frontend tests, standalone SDK tests, and live-server
acceptance_e2etests were not run. Fixtures use synthetic local data and no real service credentials. Environment scrubbing and disabled module downloads do not imply kernel-level network isolation.Checklist
AI assistance: coding agents prepared the patch, tests, and reviews. No personal human review is claimed.