Skip to content

fix: let union-variant flags whose field is an object take JSON - #40

Closed
Bradenream wants to merge 3 commits into
masterfrom
braden/union-variant-object-flags/COR-0
Closed

Bradenream wants to merge 3 commits into
masterfrom
braden/union-variant-object-flags/COR-0

Conversation

@Bradenream

@Bradenream Bradenream commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Some commands expand a union variant into one flag per field (--body-param.<variant>.<field>). The generated metadata declares some of those flags as plain strings although their fields are objects or nullable strings. setFieldByPath cannot store text in those fields, so each failed with cannot convert string to … whatever value it was given; only --body, or the variant's whole-JSON flag, could set them. A survey of all 38 expanded variant fields found 11:

  • test turn create --body-param.agent.payload (an object)
  • integration connect --body-param.<provider>.credentials, for twilio, ujet, genesys, kustomer, dixa, sunshine and custom-handoff (objects)
  • evaluation create --body-param.<type>.description, for boolean, number and string (nullable strings, so plain text failed too)

buildStringField now hands such a flag to buildJSONField, the builder that JSON flags use (internal/flagutil/stringflag.go). An object takes JSON, and a nullable string takes plain text or null. Flags whose field holds text are unchanged.

Before and after

master this PR
The 11 flags, run on the built binary 11 fail with cannot convert string to … 11 send their value
--body-param.agent.payload sequential (text for an object) cannot convert … invalid value … expected a JSON value, with an example

Test plan

The generated metadata declares some expanded union-variant flags as
plain strings although their fields are objects or nullable strings. A
survey of all 38 expanded variant fields found 11:
- test turn create --body-param.agent.payload (an object)
- integration connect --body-param.<provider>.credentials, for twilio,
  ujet, genesys, kustomer, dixa, sunshine and custom-handoff (objects)
- evaluation create --body-param.<type>.description, for boolean,
  number and string (nullable strings)
setFieldByPath cannot store text in those fields, so every one failed
with "cannot convert string to ..." whatever value it was given. Only
--body, or the variant's whole-JSON flag, could set them.

buildStringField now hands such a flag to buildJSONField, the builder
JSON flags use. An object takes JSON, and a nullable string takes plain
text or null. Flags whose field holds text are unchanged. All 11 were
checked on the built binary: each failed on master and now sends its
value.
Copilot AI balanced review requested due to automatic review settings October 1, 2026 22:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Explicitly supplied empty nullable strings are omitted instead of being sent as empty values.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Fixes expanded union-variant flags so object and nullable-string fields use the CLI’s existing JSON handling.

Changes:

  • Routes non-text targets through the JSON builder, preserving ordinary string behavior.
  • Adds unit and CLI regression tests for objects, nullable strings, and invalid input.
File Description
test/​union-variant-flags.test.ts Tests request bodies and invalid-value errors.
internal/​flagutil/​stringflag.go Detects fields that can hold plain text.
internal/​flagutil/​stringflag_test.go Tests detection and string-builder behavior.
internal/​flagutil/​metadata.go Delegates non-text string flags to JSON handling.
Files not reviewed (1)
  • internal/flagutil/metadata.go: Generated file

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread internal/flagutil/metadata.go
A string flag whose field cannot hold text is built by buildJSONField,
which reads an empty value as not given. So
--body-param.boolean.description '' left description out of the
request instead of sending "", though a string flag set to '' has
always meant empty text. Copilot raised this in review.

A nullable string given '' on purpose is now stored as "". A flag that
is not given stays out, and an object given '' is still left out, as it
would be from a JSON flag. Unit tests cover flags that are optional and
flags that are neither optional nor required, each given '' and not
given at all.

effervescentia commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Merge activity

  • Oct 2, 6:38 PM UTC: The merge label 'merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Oct 2, 6:39 PM UTC: effervescentia added this pull request to the Graphite merge queue.
  • Oct 2, 6:39 PM UTC: CI is running for this pull request on a draft pull request (#48) due to your merge queue CI optimization settings.
  • Oct 2, 6:40 PM UTC: Merged by the Graphite merge queue via draft PR: #48.

@graphite-app graphite-app Bot closed this Oct 2, 2026
@graphite-app
graphite-app Bot deleted the braden/union-variant-object-flags/COR-0 branch October 2, 2026 18:40
@graphite-app graphite-app Bot removed the merge label Oct 2, 2026
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.

3 participants