fix(cli): stop compact list projection from mangling short fields - #145
Merged
Conversation
The default compact projection used by alert-event list, incident list, and incident similar (in json/toon mode, when --fields is omitted) computed a single per-field byte cap by dividing the total budget by the total count of string values across every row, then geometrically halved that cap whenever the aggregate output still overflowed 16 KiB. Each halving re-applied the shrinking cap to every string field on every row, including fields that were never responsible for the overflow (e.g. Mongo ObjectID-shaped ids, or short enum-like severity/ status strings), clipping them down toward a 1-byte cap even though a single long field (typically the title) was the actual cause. Once the cap dropped to 3 bytes or below, the truncation helper had no room left for its "..." marker and fell back to returning raw, unmarked bytes — making a shortened value indistinguishable from a genuinely short one. Piping such output to jq/grep for an exact id or status match then silently returns no hits, with no indication that the field was ever truncated. Replace the per-field cap computation with a search for the largest single cap that lets the whole page fit, then apply it once. A field already shorter than that cap is left completely untouched, so only the field(s) actually responsible for the overflow get shortened, and the cap is never allowed to drop low enough to lose the "..." marker. When no such cap exists, the command now fails with an actionable error instead of emitting values that look real but aren't. Add regression coverage: a fixture with long ids and a minority of oversized multi-word/CJK titles confirms the ids and short titles stay intact in both json and toon output while only the oversized titles are marked-truncated; a --fields path test confirms explicit field selection is unaffected; and a low-level test forces every string field to shrink and asserts the "..." marker is never dropped.
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.
Problem
The default compact projection used by `alert-event list`, `incident list`, and `incident similar` (in json/toon mode, when `--fields` is omitted) computed a single per-field byte cap by dividing the total budget by the total count of string values across every row, then geometrically halved that cap whenever the aggregate output still overflowed 16 KiB.
Each halving re-applied the shrinking cap to every string field on every row, including fields that were never responsible for the overflow (e.g. Mongo ObjectID-shaped ids, or short enum-like severity/status strings), clipping them down toward a 1-byte cap even though a single long field (typically the title) was the actual cause.
Once the cap dropped to 3 bytes or below, the truncation helper had no room left for its
"..."marker and fell back to returning raw, unmarked bytes — making a shortened value indistinguishable from a genuinely short one. Piping such output to jq/grep for an exact id or status match then silently returns no hits, with no indication the field was ever truncated.Fix
Replace the per-field cap computation with a search for the largest single cap that lets the whole page fit, then apply it once:
"..."marker.alert-event list,incident list, andincident similarall share this helper (boundProjectedListininternal/cli/fieldproject.go), so the fix applies to all three.alert listis unaffected — it doesn't run through this default compact-projection path.Tests
--fieldspath test confirms explicit field selection is unaffected."..."marker is never dropped.`go vet ./...`, `gofmt -s -l`, `make lint` (0 issues), and `go test ./...` all pass.