Skip to content

codegen: add golden tests and production overrides (PRINFRA-121) - #15

Closed
somanshreddy wants to merge 1 commit into
graphite-base/15from
03-31-codegen_add_golden_tests_and_production_overrides
Closed

somanshreddy wants to merge 1 commit into
graphite-base/15from
03-31-codegen_add_golden_tests_and_production_overrides

Conversation

@somanshreddy

@somanshreddy somanshreddy commented Mar 31, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Proves the codegen pipeline works and configures it for all 40 v3 endpoints.

Golden file tests — a mini OpenAPI spec with 6 endpoints (list with pagination, get by ID, create with body including complex fields, delete, nested action, multipart upload) runs through the full pipeline. Output is compared against checked-in golden files. Run `go test ./codegen/ -update` to refresh golden files after intentional changes.

Test coverage — golden file comparison, v1 endpoint skipping, pagination detection, complex field omission, multipart detection, nested action naming, skip pattern matching, missing examples validation.

Production overrides — overrides.yaml configures all 40 v3 endpoints with:

  • Group renames ("Video Translate" → translate, "Video Agent" → video-agent)
  • v1/v2 skip patterns
  • Positional promotions (prompt, text, file)
  • Usage examples for every command (mandatory — codegen fails without them)

After this PR, running `make generate SPEC=path/to/external-api.json` produces all 40 command definitions. Wiring them into the CLI is Stack 2.

Testing

8 golden file tests covering all codegen patterns. All tests are mocked — no external dependencies.

Files

  • codegen/generate_test.go — 8 tests: golden files, v1 filtering, pagination, complex fields, multipart, naming, x-cli-visible, missing examples
  • codegen/overrides.yaml — production overrides for all 40 v3 endpoints
  • codegen/testdata/mini_spec.json — minimal 6-endpoint test spec
  • codegen/testdata/golden/ — expected codegen output (widget.go, upload.go, registry.go)

somanshreddy commented Mar 31, 2026 •

Copy link
Copy Markdown
Collaborator Author

@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_renderer_templates_and_cli_entry_point branch from 5a6a098 to a8b1753 Compare March 31, 2026 18:29
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_golden_tests_and_production_overrides branch from c25cc32 to 781d382 Compare March 31, 2026 18:29
@somanshreddy somanshreddy changed the title codegen: add golden tests and production overrides codegen: add golden tests and production overrides (PRINFRA-121) Mar 31, 2026
@linear

linear Bot commented Mar 31, 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 03-31-codegen_add_golden_tests_and_production_overrides branch 2 times, most recently from b165a9b to c2675cb Compare March 31, 2026 20:08
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_renderer_templates_and_cli_entry_point branch from 0b9e0be to 2f5c57f Compare March 31, 2026 20:08
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_golden_tests_and_production_overrides branch from c2675cb to e68dee9 Compare March 31, 2026 20:59
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_renderer_templates_and_cli_entry_point branch from 2f5c57f to b3208f9 Compare March 31, 2026 20:59
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_golden_tests_and_production_overrides branch from e68dee9 to 869f6f8 Compare March 31, 2026 21:06
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_renderer_templates_and_cli_entry_point branch 2 times, most recently from 16055f5 to 7f8ff00 Compare March 31, 2026 21:25
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_golden_tests_and_production_overrides branch from 869f6f8 to 6745dc1 Compare March 31, 2026 21:25
Golden file tests verify codegen output stability against a mini spec.
Production overrides.yaml configures all 40 v3 endpoints: group names,
skip patterns, positional promotions, and usage examples.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_golden_tests_and_production_overrides branch from 6745dc1 to e26cccf Compare March 31, 2026 21:31
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_renderer_templates_and_cli_entry_point branch from 7f8ff00 to 8b6e2ae Compare March 31, 2026 21:31
@somanshreddy
somanshreddy changed the base branch from 03-31-codegen_add_renderer_templates_and_cli_entry_point to graphite-base/15 March 31, 2026 21:41
@somanshreddy

Copy link
Copy Markdown
Collaborator Author

Merged into PR #14 (renderer + templates) during stack restructuring.

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.

1 participant