Skip to content

feat: honor --json-compact and signal pagination in --query output - #1672

Merged
ramya18101 merged 13 commits into
mainfrom
fix/agent-query-output
Sep 18, 2026
Merged

ramya18101 merged 13 commits into
mainfrom
fix/agent-query-output

Conversation

@developerkunal

@developerkunal developerkunal commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

🔧 Changes

Improves the --query list output path (auth0 actions list, auth0 roles list, and any future list command wired through runJSONQuery) in two ways:

  • Honor --json-compact. When --json-compact is set, the response is emitted as a single dense JSON line via json.Compact. The default output stays pretty-printed. Both paths run through ansi.ColorizeJSON, which is TTY-guarded, so interactive output is colorized while piped or agent output stays plain. --csv is intentionally not supported here, because the response is raw API JSON with no fixed column shape to flatten.
  • Signal pagination. A single --query call fetches one page. When the response indicates more records exist than were returned, a diagnostic is now printed to stderr so the returned records aren't mistaken for the full result set. The output on stdout and the number of records fetched are unchanged.

The truncation signal reads the Management API's standard list envelope, whose fields go-auth0 models as management.List (start/limit/length/total/next), and mirrors that type's own HasNext() contract so the hint agrees with how the SDK defines "more pages":

  • Offset pagination (include_totals): more pages exist when total > start + limit. The "Showing X of Y" count comes from the envelope's length field (the number actually returned on this page), falling back to limit when length is absent. A total without limit is not treated as a pagination signal, so an unrelated scalar field cannot trigger a spurious hint.
  • Checkpoint pagination (from/take): fires on a non-empty next token and points the caller to pass it as from, but is suppressed on an empty page (length == 0) so it never claims more results for a page that returned nothing.
  • A bare array, or an object without these fields, yields no hint, since there is no reliable signal to infer truncation from.

📚 References

Part of the agent-compatibility work. Stacked on #1671.

🔬 Testing

Covered by unit tests in internal/cli/query_json_test.go:

  • TestRunJSONQuery_CompactOutput asserts compact mode emits a single dense line.
  • TestPaginationHint covers offset and checkpoint pagination plus the negative cases (complete set, last page, empty next token, empty checkpoint page, total without limit, no metadata, bare array).
  • TestRunJSONQuery_TruncationWarning asserts the diagnostic reaches stderr on a truncated page.

Run with make test-unit or go test ./internal/cli/ -run 'TestRunJSONQuery|TestPaginationHint'.

Backward compatibility note: this changes observable behavior on two commands that already shipped, auth0 actions list --query and auth0 roles list --query. They now emit an additional diagnostic line to stderr on a truncated page, and they now honor --json-compact (previously the flag was silently ignored on this path). Scripts that read results from stdout are unaffected; only stderr gains a line, and only when the result set is truncated. Flagging for a maintainer decision, since it touches existing command output.

📝 Checklist

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

The --query encoder rendered every value through fmt.Sprintf("%v", val)
and url.Values.Set, so an array became the literal "[a b]", a repeated
value overwrote instead of accumulating, and large numbers could turn into
scientific notation. Any structured filter silently built the wrong request.

Decode with UseNumber and encode per JSON type: scalars become a single
value, arrays of scalars become repeated params (?k=a&k=b), numbers keep
their literal, and a nested object or array-of-objects is rejected with a
clear error naming the key.
Emit compact single-line JSON from --query list commands when
--json-compact is set (default stays pretty-printed), and print a
stderr diagnostic when the response is one page of a larger result
set. The truncation hint covers checkpoint (next token), offset with
totals, and offset with only a total, so callers don't mistake a page
for the full set. The records fetched are unchanged.
@developerkunal
developerkunal requested a review from a team as a code owner September 16, 2026 17:24
developerkunal and others added 10 commits September 17, 2026 12:08
Base the --query pagination hint on the Management API's standard list
envelope (start/limit/length/total/next) and mirror management.List.HasNext
rather than guessing the records array by length:

- Offset: signal more pages when total > start + limit, and report the count
  from the envelope's length field instead of the longest top-level array. A
  bare total without limit is no longer treated as a pagination signal, so an
  unrelated total field cannot trigger a spurious hint.
- Checkpoint: keep firing on a non-empty next token, but suppress it on an
  empty page (length == 0) so we never claim more results for a page that
  returned nothing.

Also colorize --json-compact --query output to match the other compact
commands (ColorizeJSON is already TTY-guarded, so piped output stays plain).
…, single-parse)

Reject --csv when combined with --query instead of silently ignoring it,
soften the checkpoint hint wording so a trailing next token no longer claims
results definitively exist, report only the total when the envelope omits
length, decode just the scalar pagination fields to avoid allocating the
result array, and document the include_totals requirement on the --query flag.
Wrap the --query decode and encode failures in validationError so a
malformed or nested filter classifies as "validation" instead of
"unknown", matching the --data path. A JSON null now omits the
parameter instead of sending an empty value, and queryScalarString
gained a float64 fallback so the encoder stays correct if a caller
decodes without UseNumber.
# Conflicts:
#	CHANGELOG.md
#	internal/cli/query_json_test.go
Keeps the literals compilable once validationError gains additional
fields, independent of merge order with the error-envelope change.
Base automatically changed from fix/agent-query-encoding to main September 18, 2026 06:37
# Conflicts:
#	internal/cli/query_json.go
#	internal/cli/query_json_test.go
@ramya18101
ramya18101 enabled auto-merge (squash) September 18, 2026 06:47
@ramya18101
ramya18101 merged commit d75351f into main Sep 18, 2026
6 checks passed
@ramya18101
ramya18101 deleted the fix/agent-query-output branch September 18, 2026 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants