Skip to content

Conversation

@fredbi
Copy link
Member

@fredbi fredbi commented Dec 27, 2025

Inverts the generation model: internal/assertions is now the single source
of truth, with assert/ and require/ packages fully generated including all
variants (format, forward, tests, examples).

Architecture:

  • Scanner: AST/types analysis extracts functions, signatures, and test examples
  • Generator: Template-based generation of 76 functions × 8 variants = 608 functions
  • Model: Structured representation bridging scanner and generator

Key improvements:

  • Example-driven test generation from godoc "Examples:" sections
  • Achieves ~100% coverage in generated packages (99.5% - 0.5% gap from helpers)
  • Modern Go 1.23 iterator-based table-driven tests throughout
  • Domain-organized source (boolean, collection, compare, equal, error, etc.)
  • Function type detection for proper generation of type/var function signatures
  • Comprehensive documentation (MAINTAINERS.md, CLAUDE.md)
  • Codegen smoke tests (24.4% coverage)

Generated packages:

  • assert/require: assertions, format variants, forward methods
  • All with corresponding tests and runnable examples
  • Helper types and interfaces

This replaces the previous semi-hand-written/semi-generated approach where adding a single
assertion required manually updating 6+ files that already had thousands of lines.

Now: write once in internal/assertions/ in small focused source files, run go generate, done.

Trade-off: the existing code generator has been rewritten entirely.
The new one is more complex, but also more readable.
This added (mostly stable) complexity should be outweighted by the
simplification of the assertion development workflow.

Change type

Please select: 🆕 New feature or enhancement|🔧 Bug fix'|📃 Documentation update

Short description

Fixes

Full description

Checklist

  • I have signed all my commits with my name and email (see DCO. This does not require a PGP-signed commit
  • I have rebased and squashed my work, so only one commit remains
  • I have added tests to cover my changes.
  • I have properly enriched go doc comments in code.
  • I have properly documented any breaking change.

@fredbi fredbi requested a review from Copilot December 27, 2025 15:49
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements a comprehensive code generation architecture that inverts the previous model, making internal/assertions the single source of truth for generating both assert and require packages with all their variants. The system now generates 608 functions (76 base functions × 8 variants) with corresponding tests and examples, achieving ~100% test coverage in generated packages.

Key changes:

  • New scanner/generator architecture replaces previous semi-manual approach
  • Example-driven test generation from godoc "Examples:" sections
  • Modern Go 1.23 iterator-based table-driven tests throughout
  • Comprehensive documentation added (MAINTAINERS.md, CLAUDE.md)

Reviewed changes

Copilot reviewed 67 out of 161 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
doc.go Updated package documentation to reflect fork differences and code generation approach
codegen/main.go New entry point for code generator with configuration flags
codegen/main_test.go Smoke tests for code generation execution
codegen/internal/scanner/*.go AST/types analysis for extracting functions and metadata
codegen/internal/generator/*.go Template-based generation of assertion packages
codegen/internal/model/model.go Data structures bridging scanner and generator
codegen/internal/generator/templates/*.gotmpl Templates for generating assert/require variants
assert/*.go Generated assertion package files
.codecov.yml Updated to ignore new codegen directory

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link

codecov bot commented Dec 27, 2025

Codecov Report

❌ Patch coverage is 99.06542% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.78%. Comparing base (b5da3fc) to head (e378d7d).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
assert/assert_helpers.go 0.00% 10 Missing ⚠️
assert/enable/yaml/enable_yaml.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master       #8       +/-   ##
===========================================
+ Coverage   53.82%   95.78%   +41.96%     
===========================================
  Files          18       37       +19     
  Lines        4964     5627      +663     
===========================================
+ Hits         2672     5390     +2718     
+ Misses       2227      166     -2061     
- Partials       65       71        +6     
Flag Coverage Δ
oldstable-macos-latest 95.78% <99.06%> (+41.96%) ⬆️
oldstable-ubuntu-latest 95.78% <99.06%> (+41.96%) ⬆️
oldstable-windows-latest 95.78% <99.06%> (+41.96%) ⬆️
stable-macos-latest 95.78% <99.06%> (+41.96%) ⬆️
stable-ubuntu-latest 95.78% <99.06%> (+41.96%) ⬆️
stable-windows-latest 95.78% <99.06%> (+41.96%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@fredbi
Copy link
Member Author

fredbi commented Dec 27, 2025

fixes #6

@fredbi fredbi force-pushed the refact/more-generated-stuff branch from d4bc2d1 to d67df7a Compare December 27, 2025 16:18
  Inverts the generation model: internal/assertions is now the single source
  of truth, with assert/ and require/ packages fully generated including all
  variants (format, forward, tests, examples).

  Architecture:
  - Scanner: AST/types analysis extracts functions, signatures, and test examples
  - Generator: Template-based generation of 76 functions × 8 variants = 608 functions
  - Model: Structured representation bridging scanner and generator

  Key improvements:
  - Example-driven test generation from godoc "Examples:" sections
  - Achieves ~100% coverage in generated packages (99.5% - 0.5% gap from helpers)
  - Modern Go 1.23 iterator-based table-driven tests throughout
  - Domain-organized source (boolean, collection, compare, equal, error, etc.)
  - Function type detection for proper generation of type/var function signatures
  - Comprehensive documentation (MAINTAINERS.md, CLAUDE.md)
  - Codegen smoke tests (24.4% coverage)

  Generated packages:
  - assert/require: assertions, format variants, forward methods
  - All with corresponding tests and runnable examples
  - Helper types and interfaces

  This replaces the previous semi-hand-written/semi-generated approach where adding a single
  assertion required manually updating 6+ files that already had thousands of lines.

  Now: write once in internal/assertions/ in small focused source files, run go generate, done.

  Trade-off: the existing code generator has been rewritten entirely.
  The new one is more complex, but also more readable.
  This added (mostly stable) complexity should be outweighted by the
  simplification of the assertion development workflow.

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>

ci: enforced Windows TMP to reside on the same drive

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
@fredbi fredbi force-pushed the refact/more-generated-stuff branch from d67df7a to e378d7d Compare December 27, 2025 16:43
@fredbi fredbi merged commit 30ab924 into go-openapi:master Dec 27, 2025
13 of 14 checks passed
@fredbi fredbi deleted the refact/more-generated-stuff branch December 27, 2025 16:47
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