Skip to content

test: generated tests check each union's null, and that nothing is dropped - #82

Merged
MarkRosemaker merged 2 commits into
mainfrom
test/round-trip-more
Nov 15, 2026
Merged

MarkRosemaker merged 2 commits into
mainfrom
test/round-trip-more

Conversation

@MarkRosemaker

@MarkRosemaker MarkRosemaker commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

This extends the generated round-trip tests, part of fixing go-api-libs/notion#21. It builds on go-api-libs/api#8, now merged; this branch pins go-api-libs/api at its master.

  • TestUnions_Null, generated for every union (tagged structs and unimplemented unions excluded): checks that a union holding no alternative encodes as null, and that null decodes as a union holding none (apitest.Null). This is the "cover": null case.
  • apitest.RoundTrip, from the api bump: each round-tripped alternative must now refuse a member no type declares, or keep it. It must never drop it silently. That makes the generated tests check what debug mode depends on.

Why: in notion, about 1,260 uncovered statements were each union decoder's null branch and its per-alternative return err, which no test reached. Measured with Go 1.27.4, devtool's version: notion goes from 77.8% to 83.6%. I checked against notion and pixellab with local replace directives: no generated type drops a member or mishandles null.

The golden and debug test packages gain the null checks, and TestDocument_NullUnions covers which types qualify.

Separately: with codegen#81, pixellab's replay test now fails. Its recorded last_response.detail holds error messages, but pixellab's generator types it as the style Detail enum. That's a pixellab fix, not part of this PR.

🤖 Generated with Claude Code

https://claude.ai/code/session_019QCb1AfnATvpBQCH3PrX7Y

…opped

Every union gets a generated Null check: holding no alternative, it encodes
as null, and null decodes as it, as an API sends a member it leaves unset.
apitest.RoundTrip, bumped, now also checks each round-tripped variant
refuses or keeps a member no type declares, never drops it. In notion, these
reach the null and error paths of every union's decoder, which no test did:
coverage, as devtool measures it, goes from 77.8% to 83.6%.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019QCb1AfnATvpBQCH3PrX7Y
@MarkRosemaker
MarkRosemaker merged commit 7c778c5 into main Nov 15, 2026
1 check passed
@MarkRosemaker
MarkRosemaker deleted the test/round-trip-more branch November 15, 2026 17:26
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