Skip to content

test: fuzz schema generation for union inputs + docs fixup#3049

Merged
markphelps merged 3 commits into
mainfrom
union-inputs-fuzz
Jun 5, 2026
Merged

test: fuzz schema generation for union inputs + docs fixup#3049
markphelps merged 3 commits into
mainfrom
union-inputs-fuzz

Conversation

@markphelps
Copy link
Copy Markdown
Collaborator

@markphelps markphelps commented Jun 5, 2026

What

Two related follow-ups to the union inputs feature (#3048, now merged):

  1. Fuzz coverage for the schema-generation codepaths exercised by union inputs, which previously had no fuzzing and no validity oracle.
  2. A docs correction for stale union type limitations left behind after feat: support JSON-native union inputs #3048 merged.

Fuzz targets (pkg/schema/input_type_fuzz_test.go)

  • FuzzResolveInputType — feeds arbitrary TypeAnnotation trees through ResolveInputType, then (for any input type that resolves) runs GenerateOpenAPISchema and validates the output.
  • FuzzInputTypeJSONSchema — builds arbitrary InputType trees directly (reaching shapes the resolver never produces) and validates the generated OpenAPI document.

Both use an assertValidOpenAPI oracle — the same kin-openapi validator as writeAndValidateSchema at build time. The key improvement over the existing fuzz tests (which only assert "no panic"): a union shape that resolves cleanly but emits an invalid schema (e.g. an unsupported type: null branch — exactly the bug hit during union-inputs development) now fails the fuzzer instead of surfacing as a confusing user build error.

Auto-discovery for test:fuzz

Replaced the hardcoded target list with go test -list-based discovery, so new Fuzz* targets are picked up automatically and can't be silently missed. This also surfaced targets the old list already missed:

Targets run
Before (hardcoded) 4
After (auto-discovered) 11 — adds pkg/config's 3 targets, 2 parser helpers, and the 2 new union targets
  • jq (used for discovery) is now a managed mise tool (aqua:jqlang/jq), per the single-source-of-truth tooling convention.
  • The CI fuzz-go job now just runs mise run test:fuzz; timeout bumped 10→15 min for headroom as the target count grows.

Docs correction (docs/python.md)

After #3048 merged, the "Type limitations" section still claimed only Optional[T] unions were supported, directly contradicting the new Union section. Fixed:

  • Scoped the limitation correctly: output unions remain unsupported; input unions of JSON-native types (str | int, str | float | None, …) are supported.
  • Added a separate bullet for the genuinely-unsupported case (input unions of Path/File/Secret/custom coders/BaseModel, which fail at build).
  • Added the missing Union table-of-contents entry and regenerated docs/llms.txt.

Testing

  • FUZZTIME=2s mise run test:fuzz → "All 11 fuzz targets passed."
  • Extended fuzzing (45s each) of both new targets: no crashes, oracle active.
  • go test ./pkg/schema/..., lint:go (0 issues), fmt:docs + lint:docs clean, YAML validated.

Base automatically changed from union-inputs to main June 5, 2026 13:26
Add fuzz coverage for the schema-gen codepaths exercised by union
inputs, which previously had no fuzzing and no validity oracle:

- FuzzResolveInputType: feeds arbitrary TypeAnnotation trees through
  ResolveInputType, then validates that any successfully resolved input
  type generates an OpenAPI document the build-time validator accepts.
- FuzzInputTypeJSONSchema: builds arbitrary InputType trees directly
  (reaching shapes the resolver never produces) and validates the
  generated OpenAPI document.

Both use an assertValidOpenAPI oracle (the same kin-openapi validator
as writeAndValidateSchema), so a union shape that resolves cleanly but
emits an invalid schema (e.g. an unsupported `type: null` branch) fails
the fuzzer rather than surfacing as a confusing user build error.

Make the test:fuzz task auto-discover every Fuzz* target via
`go test -list` instead of hardcoding names, so new fuzz tests are
picked up automatically. This also surfaced targets the hardcoded list
missed (pkg/config's three targets and two parser helpers): 11 total
vs the 4 previously run. Manage jq (used for discovery) as a mise tool
and simplify the CI fuzz-go job to call the task.
@markphelps markphelps force-pushed the union-inputs-fuzz branch from 5b57aca to 6224d47 Compare June 5, 2026 13:28
@markphelps markphelps marked this pull request as ready for review June 5, 2026 13:28
@markphelps markphelps requested a review from a team as a code owner June 5, 2026 13:28
The union-inputs feature (#3048) added input union support, but the
"Type limitations" section still claimed only Optional[T] was supported,
contradicting the new Union section. Scope the limitation correctly:
output unions remain unsupported, JSON-native input unions are
supported, and input unions of Path/File/Secret/custom-coder/BaseModel
members fail at build. Also add the missing Union table-of-contents
entry and regenerate llms.txt.
Copy link
Copy Markdown
Contributor

@ask-bonk ask-bonk Bot left a comment

Choose a reason for hiding this comment

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

This PR adds fuzz coverage for union input schema generation with auto-discovery of fuzz targets.

Issue: assertValidOpenAPI uses raw t.Fatalf instead of testify assertions

The project convention requires testify (require/assert) instead of raw t.Fatal/t.Fatalf in tests.

Comment thread pkg/schema/input_type_fuzz_test.go
@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented Jun 5, 2026

Posted a review on PR #3049. Found one actionable issue: assertValidOpenAPI in the new fuzz test uses raw t.Fatalf instead of the required testify require.NoError assertions. Everything else looks solid — the auto-discovery approach for fuzz targets, the oracle validation with kin-openapi, and the CI timeout bump are all good improvements.

github run

@markphelps markphelps changed the title test: fuzz schema generation for union inputs test: fuzz schema generation for union inputs + docs fixup Jun 5, 2026
Replace raw t.Fatalf with require.NoError per the project testing
conventions (AGENTS.md).
Copy link
Copy Markdown
Contributor

@ask-bonk ask-bonk Bot left a comment

Choose a reason for hiding this comment

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

I'm Bonk, and I've done a quick review of your PR.

This PR adds fuzz coverage for union input schema generation, auto-discovers fuzz targets in mise run test:fuzz, and corrects stale union type limitations in the docs.

One issue to address:

  1. assertValidOpenAPI uses raw t.Fatalf instead of testify require.NoError, violating the project's testing conventions (all tests must use testify assertions).

require.NoError(t, err, "generated schema is invalid\n%s", string(schemaJSON))
}

// decodeInputType builds an InputType tree from bytes, mirroring the encoding
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use testify require instead of raw t.Fatalf, per project testing conventions:

Suggested change
// decodeInputType builds an InputType tree from bytes, mirroring the encoding
func assertValidOpenAPI(t *testing.T, schemaJSON []byte) {
t.Helper()
loader := openapi3.NewLoader()
loader.IsExternalRefsAllowed = true
doc, err := loader.LoadFromData(schemaJSON)
require.NoError(t, err, "generated schema failed to load\n%s", string(schemaJSON))
err = doc.Validate(context.Background())
require.NoError(t, err, "generated schema is invalid\n%s", string(schemaJSON))
}

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented Jun 5, 2026

I'm Bonk, and I've done a quick review of your PR.

This PR adds fuzz coverage for union input schema generation, auto-discovers fuzz targets in mise run test:fuzz, and corrects stale union type limitations in the docs.

One issue to address:

  1. assertValidOpenAPI uses raw t.Fatalf instead of testify require.NoError, violating the project's testing conventions (all tests must use testify assertions).

I've posted a review on PR #3049 with a suggestion to fix the testify usage in assertValidOpenAPI.

github run

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented Jun 5, 2026

LGTM

github run

@markphelps markphelps merged commit 2ab4cc4 into main Jun 5, 2026
45 checks passed
@markphelps markphelps deleted the union-inputs-fuzz branch June 5, 2026 14:18
@markphelps markphelps mentioned this pull request Jun 5, 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.

2 participants