Skip to content

ref(cli): Check output.schema for commands with jsonTransform - #1869

Merged
BYK merged 1 commit into
mainfrom
byk/ref/cli-check-transformed-output-schema
Nov 3, 2026
Merged

BYK merged 1 commit into
mainfrom
byk/ref/cli-check-transformed-output-schema

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Fixes #1860, the follow-up from #1854.

#1854 checked output.schema against the yielded data, but only for commands without jsonTransform. With a transform, the schema describes the transform's item rather than T, and every transform returned unknown, so there was nothing to check against.

The builders now infer the transform's return type. The item is each element of a { data: [...] } envelope or an array, or else the result itself. Every field the schema documents must exist on that item with a matching type. Optionality isn't compared, since --fields makes items Partial. A transform that returns unknown no longer matches a schema. On a mismatch, the error lists only the mismatched fields under ~outputMismatch (e.g. { "~outputMismatch": { b: number } }), not the whole schema.

To make the results typed:

  • jsonTransformListResult returns ListJson<T> (ListEnvelope<T> | Partial<T>[]).
  • The hand-built list envelopes (agent-conversation, dashboard, dashboard revisions, events, replay, span, trace) are typed as ListEnvelope<Item>.
  • log list returns ListEnvelope<LogLike> | Partial<LogLike>.
  • The single-object views (event, issue, feedback, project, replay) drop their Record<string, unknown> annotations and let the spread's type through, using filterFieldsIfSet.
  • OrgListConfig takes the schema's type as a third parameter and checks the entity against it, so team, repo, monitor, and integration list are covered. buildOrgListCommand itself only sees a generic TWithOrg and can't check anything, so it erases the schema type there.
  • issue list and project list used OutputConfig<T> as an annotation or with satisfies. That erased the schema's type, so the check passed without comparing anything. Both are now inferred.

The check found these mismatches:

  • span list: the schema documented the API's field names (id, span.op, span.duration, timestamp, project, trace). The command emits the names spanListItemToFlatSpan gives them (span_id, op, duration_ms, start_timestamp, project_slug, trace_id). As a result, --help, --fields completion, and the skill reference listed fields that never appear in the output. A new FlatSpanSchema documents the emitted fields, and FlatSpan is now derived from it. A regression test checks that every key in the JSON output is a documented field. It fails against the old schema.
  • IssueEvent: the hand-written type said metadata could be null. The schema, built from @sentry/api, says it can't. IssueEvent is now the GroupEventsResponseDict item type.
  • ReplayListItem / ReplayDetails: these typed project_id as string | number, but lib/api/replays.ts normalizes it to a string. normalizeReplayProjectId now returns that type.

The regenerated span.md skill reference is included. packages/cli/AGENTS.md describes the check and how to type a transform.

Transforms without a schema (api, issue merge, trace view, span view, and others) are unchanged.

To confirm the check catches drift, I built throwaway commands that each break one way:

  • a transform's envelope item is missing a field;
  • an envelope item has a field of the wrong type;
  • a transform returns unknown;
  • a single-object transform is missing a field;
  • an array transform is missing a field;
  • an OrgListConfig entity is missing a field.

All six failed to compile. The matching versions, and a transform without a schema, compiled. These weren't kept as tests, because tsc only covers src/.

via @BYK.

--

View Session in Sentry

With a jsonTransform, output.schema describes the transform's item: each
item of a { data: [...] } envelope or an array, otherwise the result.
The builders now infer the transform's return type and require every
field the schema documents to exist on that item with a matching type.
Optionality isn't compared, since --fields makes items Partial. A
transform that returns unknown no longer matches a schema, and the error
lists the mismatched fields under ~outputMismatch.

Transforms now return typed JSON: ListJson<T> from
jsonTransformListResult, ListEnvelope<T> for hand-built envelopes, and
the spread object's own type for single-object views. OrgListConfig
takes the schema's type and checks the entity against it.

The check found these mismatches:

- span list documented the API's field names (id, span.op, trace, ...)
  but emits the renamed ones (span_id, op, trace_id, ...), so --help,
  --fields completion, and the skill reference listed fields that never
  appear. It now documents the emitted fields with FlatSpanSchema, which
  FlatSpan is derived from.
- IssueEvent typed metadata as nullable; it now is the @sentry/api
  GroupEventsResponseDict item, as the schema already was.
- ReplayListItem and ReplayDetails typed project_id as string | number,
  though the API layer normalizes it to a string.

issue list and project list annotated or checked their output config as
OutputConfig<T>, which erased the schema's type; both are now checked.

Fixes #1860

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
@vercel

vercel Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
sentry-local Ready Ready Preview Nov 3, 2026 6:29pm UTC

Request Review

@BYK
BYK merged commit 79b7224 into main Nov 3, 2026
27 checks passed
@BYK
BYK deleted the byk/ref/cli-check-transformed-output-schema branch November 3, 2026 21:28

This branch was successfully deployed

1 active deployment
Preview — d833d4bb Deployed Nov 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Check CLI output.schema for commands with jsonTransform

1 participant