Skip to content

codegen: add golden tests and test data (PRINFRA-121) - #16

Merged
somanshreddy merged 1 commit into
mainfrom
04-01-codegen_add_golden_tests_and_test_data
Apr 1, 2026
Merged

somanshreddy merged 1 commit into
mainfrom
04-01-codegen_add_golden_tests_and_test_data

Conversation

@somanshreddy

@somanshreddy somanshreddy commented Apr 1, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Proves the codegen pipeline produces correct output.

Golden file tests — a mini OpenAPI spec with 9 endpoints (CRUD, multipart, action with x-cli-action, hidden with x-cli-visible) runs through the full pipeline. Output is compared byte-for-byte against checked-in golden files.

To refresh golden files after intentional changes: go test ./codegen/ -update

Test coverage:

  • Full pipeline: spec → grouper → renderer → golden file comparison
  • Example validation: missing examples produce an error

Mini test spec covers:

  • Standard CRUD (videos: list, create, get, delete)
  • Sub-group with terminal verb (videos/caption → caption get)
  • Multipart upload (assets: Source:"file" flag)
  • Action endpoint with x-cli-action (avatars/consent)
  • Hidden endpoint with x-cli-visible: false
  • Query params with enum, min/max
  • Body fields with complex field skipping

Testing

Golden file comparison (3 output files: video.go, asset.go, registry.go) + example validation test.

Files

  • codegen/generate_test.go — golden file test + example validation test
  • codegen/testdata/mini_spec.json — minimal 9-endpoint OpenAPI spec
  • codegen/testdata/golden/widget.go — expected video group output
  • codegen/testdata/golden/upload.go — expected asset group output
  • codegen/testdata/golden/registry.go — expected registry output

@somanshreddy somanshreddy changed the title codegen: add golden tests and test data codegen: add golden tests and test data (PRINFRA-121) Apr 1, 2026
@linear

linear Bot commented Apr 1, 2026

Copy link
Copy Markdown
PRINFRA-121 CLI M1: OpenAPI codegen pipeline

Build the code generation pipeline that reads openapi/external-api.json and produces CommandSpec structs.

Scope

  • Go program in codegen/ using text/template
  • Parse OpenAPI spec, filter to v3 endpoints only
  • Generate CommandSpec data structs in gen/ (zero logic)
  • overrides.yaml for:
    • Positional arg promotion (prompt, text, file)
    • Command group naming (video-translations → translate, webhooks/endpoints → webhook)
    • Help examples per command
  • make generate SPEC=... target
  • Nested path collapsing (e.g., /webhooks/endpoints/{id}/rotate-secret → webhook rotate-secret)
  • Golden file tests for codegen output stability
  • Generate all ~30 commands, wire into Cobra at startup

Mapping Rules

  • OpenAPI tag → command group
  • POST → create, GET (list) → list, GET (by id) → get, DELETE → delete, PATCH → update
  • Path params → positional args, query params → flags, body fields → flags
  • overrides.yaml exceptions for positional promotion and group naming

Acceptance Criteria

  • make generate produces compilable CommandSpec files for all v3 endpoints
  • Adding a new endpoint to spec + re-running codegen produces new command
  • Generated help text includes descriptions and examples
  • Golden file tests pass
  • Override validation: make generate fails if overrides reference non-existent endpoints

@somanshreddy
somanshreddy force-pushed the 04-01-codegen_add_golden_tests_and_test_data branch from 97aaada to e10a625 Compare April 1, 2026 16:38
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_renderer_templates_and_cli_entry_point branch from cb080cf to c0cc301 Compare April 1, 2026 16:38
@somanshreddy
somanshreddy force-pushed the 04-01-codegen_add_golden_tests_and_test_data branch from e10a625 to e2df6d6 Compare April 1, 2026 17:01
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_renderer_templates_and_cli_entry_point branch from c0cc301 to bc62a76 Compare April 1, 2026 17:01
@somanshreddy
somanshreddy marked this pull request as ready for review April 1, 2026 17:29
@somanshreddy
somanshreddy requested a review from jrusso1020 April 1, 2026 17:57

somanshreddy commented Apr 1, 2026 •

Copy link
Copy Markdown
Collaborator Author

Merge activity

  • Apr 1, 7:16 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Apr 1, 7:23 PM UTC: Graphite rebased this pull request as part of a merge.
  • Apr 1, 7:25 PM UTC: @somanshreddy merged this pull request with Graphite.

@somanshreddy
somanshreddy changed the base branch from 03-31-codegen_add_renderer_templates_and_cli_entry_point to graphite-base/16 April 1, 2026 19:20
@somanshreddy
somanshreddy changed the base branch from graphite-base/16 to main April 1, 2026 19:22
Golden file tests run the full pipeline on a mini OpenAPI spec and
compare output against checked-in expected files. Run with -update
to refresh golden files after intentional changes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@somanshreddy
somanshreddy force-pushed the 04-01-codegen_add_golden_tests_and_test_data branch from e2df6d6 to 935528a Compare April 1, 2026 19:23
@somanshreddy
somanshreddy merged commit 8cd2433 into main Apr 1, 2026
9 checks passed
@somanshreddy
somanshreddy deleted the 04-01-codegen_add_golden_tests_and_test_data branch April 1, 2026 19:25
@somanshreddy somanshreddy added this to the M1: Codegen Pipeline milestone Apr 3, 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