Skip to content

test: add shared generator conformance suite for codegen backends (#420) - #430

Open
igel-devin-ai wants to merge 38 commits into
java-helpers:mainfrom
igel-devin-ai:test/issue-420-generator-conformance-suite
Open

igel-devin-ai wants to merge 38 commits into
java-helpers:mainfrom
igel-devin-ai:test/issue-420-generator-conformance-suite

Conversation

@igel-devin-ai

@igel-devin-ai igel-devin-ai commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #420.

Adds a backend-neutral conformance suite that every ClassCodeGenerator implementation must pass: Roaster today, the built-in backend (#364) and JavaPoet later. No backend has to duplicate the tests.

  • GeneratorConformanceTest and the TestBackendProvider SPI live in codegen-testing. ServiceLoader finds the providers, creating each one once, and each provider's name appears in the test names.
  • A backend opts in with a provider class and a services file. RoasterTestBackendProvider in codegen-roaster uses the real default formatter profile. Surefire's dependenciesToScan picks the suite up from the codegen-testing jar.
  • 10 fixtures cover fields, methods and constructors, generic bounds, collections/arrays/Optional, nested types, annotations including TYPE_USE, code-template placeholders, static imports, supertype and interfaces, Javadoc, and colliding simple type names (Fields of different types sharing a simple name (e.g. java.util.Date / java.sql.Date) generate uncompilable builder #417). Each fixture checks that javac compiles the output, including the Javadoc fixture, and that the declarations match exactly (text blocks, no fragment or OR asserts).
  • All fixture DTOs are built entirely through the generated *DtoBuilders. No DTO is changed after build().

Found by the stricter asserts: Roaster dropped type-use annotations on field and return types. This is fixed in #434 (issue #433).

Dependencies

This branch contains the commits of #425, #429 (and through it #426, #428, #436) and #434. The diff shrinks to the suite once they are merged.

Tradeoffs (deliberately kept)

Verified: mvn clean verify passes, and GeneratorConformanceTest runs 10 tests in codegen-roaster.

AndreasIgelCC and others added 14 commits November 18, 2026 09:14
…ssue-412-field-name-examples' into test/generator-conformance-suite
…ssue-418-keyword-property-names' into test/generator-conformance-suite
…covery

Introduces GeneratorConformanceTest in codegen-testing: backend-agnostic
contract tests that verify every ClassCodeGenerator emits compilable,
semantically correct Java source for a common set of model fixtures
(fields/methods/ctors, generics, collections, nested types, annotations,
code templates, static imports, colliding type names).

Backends bind via the TestBackendProvider SPI discovered through
ServiceLoader, so each generator module opts in with a provider class and
services file - no test code is duplicated per backend. Parameterized
invocations are named after the provider so failures identify the failing
generator. codegen-roaster registers RoasterTestBackendProvider and scans
the suite from the codegen-testing jar via surefire dependenciesToScan.

This is the acceptance harness needed before adding further generator
implementations (issue java-helpers#366).

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…rator-conformance-suite

# Conflicts:
#	codegen-core/src/main/java/org/javahelpers/codegen/model/annotation/AnnotationDto.java
#	codegen-core/src/main/java/org/javahelpers/codegen/model/annotation/AnnotationDtoBuilder.java
#	codegen-core/src/main/java/org/javahelpers/codegen/model/core/ClassFieldDto.java
#	codegen-core/src/main/java/org/javahelpers/codegen/model/core/ClassFieldDtoBuilder.java
#	codegen-core/src/main/java/org/javahelpers/codegen/model/core/GenerationTargetClassDto.java
#	codegen-core/src/main/java/org/javahelpers/codegen/model/core/GenerationTargetClassDtoBuilder.java
#	codegen-core/src/main/java/org/javahelpers/codegen/model/javadoc/JavadocCodeBlockDtoBuilder.java
#	codegen-core/src/main/java/org/javahelpers/codegen/model/javadoc/JavadocDtoBuilder.java
#	codegen-core/src/main/java/org/javahelpers/codegen/model/method/CodeTemplateDto.java
#	codegen-core/src/main/java/org/javahelpers/codegen/model/method/CodeTemplateDtoBuilder.java
#	codegen-core/src/main/java/org/javahelpers/codegen/model/method/ConstructorDto.java
#	codegen-core/src/main/java/org/javahelpers/codegen/model/method/ConstructorDtoBuilder.java
#	codegen-core/src/main/java/org/javahelpers/codegen/model/method/MethodCodeDtoBuilder.java
#	codegen-core/src/main/java/org/javahelpers/codegen/model/method/MethodDto.java
#	codegen-core/src/main/java/org/javahelpers/codegen/model/method/MethodDtoBuilder.java
#	codegen-core/src/main/java/org/javahelpers/codegen/model/method/MethodParameterDto.java
#	codegen-core/src/main/java/org/javahelpers/codegen/model/method/MethodParameterDtoBuilder.java
#	codegen-core/src/main/java/org/javahelpers/codegen/model/type/GenericParameterDto.java
#	codegen-core/src/main/java/org/javahelpers/codegen/model/type/GenericParameterDtoBuilder.java
#	codegen-core/src/main/java/org/javahelpers/codegen/model/type/NestedTypeDtoBuilder.java
#	codegen-core/src/main/java/org/javahelpers/codegen/util/JavadocExampleValues.java
#	codegen-core/src/test/java/org/javahelpers/codegen/model/core/CodegenDtoBuildersTest.java
#	codegen-core/src/test/java/org/javahelpers/codegen/model/core/GenerationTargetClassDtoBuilderTest.java
#	codegen-core/src/test/java/org/javahelpers/codegen/util/ImportCollectorTest.java
#	codegen-roaster/src/test/java/org/javahelpers/codegen/roaster/RoasterCodeGeneratorResilienceTest.java
#	codegen-roaster/src/test/java/org/javahelpers/codegen/roaster/RoasterCodeGeneratorTest.java
#	codegen-roaster/src/test/java/org/javahelpers/codegen/roaster/RoasterMapperTest.java
#	processor/src/main/java/org/javahelpers/simple/builders/processor/generators/field/UpdateHelperGenerator.java
#	processor/src/main/java/org/javahelpers/simple/builders/processor/generators/util/MethodGeneratorUtil.java
#	simple-processor/src/test/java/org/javahelpers/codegen/processing/MinimalCodegenProcessorTest.java
@igel-devin-ai

igel-devin-ai commented Dec 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Strict review

blocking

Reviewed head fb26f572730200194087d4b2cb04cba6ebd5c5e8 against upstream/main 4b696141058c97b8130c3ce3920a7faeafbb3bbd, including issue #420, the PR body and existing comments. The ServiceLoader/Surefire arrangement actually executes all ten conformance fixtures for Roaster; discovery is not merely assumed. The branch is substantially divergent from current main (19 commits only on main, 31 only on this branch), so inherited/dependency changes and merge leftovers must be distinguished from the suite itself.

  1. blocker — verified — processor/src/test/java/org/javahelpers/simple/builders/processor/JavadocExampleValuesTest.java:31: the PR head does not compile its processor tests. This added test imports org.javahelpers.simple.builders.processor.generators.util.JavadocExampleValues, which no longer exists at that package on this head. Both a local reactor install and hosted build job 142256629417 fail at testCompile with:

    JavadocExampleValuesTest.java:[31,65] cannot find symbol
      symbol:   class JavadocExampleValues
      location: package org.javahelpers.simple.builders.processor.generators.util
    

    CodeQL Java autobuild job 142256611154 fails on the same reference, not an unrelated analysis-service outage. Current main has the utility and its tests in codegen-core under org.javahelpers.codegen.util, and does not contain this dangling processor test. Remove the obsolete duplicate or adapt it to the retained API/module as appropriate after integrating the dependency changes; then run the processor tests and regeneration step. This is a concrete branch-head build blocker, not an assertion that the backend-discovery implementation caused the missing class.

  2. major — verified — codegen-testing/src/main/java/org/javahelpers/codegen/testing/GeneratorConformanceTest.java:257–266: the conformance contract rejects semantically equivalent backend output. This fixture requires the precise mixed qualification policy private Date sqlDate but public void touch(java.sql.Date when), not just correct binding of the two Date declarations. A throwaway provider delegates generation to Roaster and changes only the method parameter from java.sql.Date to Date, retaining the existing java.sql.Date import and every declaration/body. That equivalent output compiles with 0 warnings, 0 errors, including the suite's own compilation step, but the conformance fixture fails with content missing for the original fully qualified method signature. Similar complete source-block expectations throughout the suite constrain import choices, member ordering and Javadoc wrapping. This contradicts Shared generator conformance suite for codegen backends #420's backend-neutral semantic contract and can reject a correct JavaPoet/built-in backend before any semantic defect exists. Assert resolved declarations/types via a syntax/semantic representation, or normalize legal qualification/import choices before comparing individual semantic members. Retain compilation checks and actual collision-binding checks; do not merely weaken the fixture to substring presence of the two names.

  3. nit — verified — codegen-testing/src/main/java/org/javahelpers/codegen/testing/GeneratorConformanceTest.java:537–544 and processor/src/test/java/org/javahelpers/simple/builders/processor/CodegenDtoBuilderRegenerationTest.java:112–117,122–123: new test infrastructure constructs assertion/source strings with +. The compiler-failure assertion concatenates the qualified name, diagnostics and source; the regeneration helper concatenates the license header, each prefixed line and generated source. Use text blocks with .formatted(...) and joining for variable sections, following the requested test-string convention. The + operator inside a fixture's generated return name + "#" + age; body is program code contained in a text block, not the prohibited test-side string construction.

Verification

  • Java 17 / Maven 3.9.11: targeted Maven install of codegen-core,codegen-roaster,processor with reactor dependencies and formatting disabled exited 1 at processor testCompile. Completed-module totals from Surefire XML:
    PR 430: Tests run: 604, Failures: 0, Errors: 0, Skipped: 0
    
    This is not a passing reactor result. Core: 91; codegen-core: 266; codegen-testing: 41; codegen-roaster: 87; simple-processor: 119. Processor tests did not run.
  • codegen-roaster/target/surefire-reports/TEST-org.javahelpers.codegen.testing.GeneratorConformanceTest.xml records 10 tests, 0 failures, 0 errors, 0 skipped, verifying dependency scanning, provider discovery and compilation of the fixture outputs. The provider uses Named.of(provider.name(), provider) with parameterized display name {0}. Moving the engine dependency to test scope did not prevent this local execution.
  • External equivalent-backend probe:
    Equivalent source: SUCCESS warnings=0 errors=0
    Conformance fixture: org.opentest4j.AssertionFailedError:
    content missing: 'private java.util.Date utilDate;
    private Date sqlDate;
    public void touch(java.sql.Date when) {
    
    The temporary provider exercised the actual fixture via reflection, not a separate approximation of its assertion.
  • git_pr_checks: 2 passed, 2 failed, 0 pending, 1 skipped. Build and Java CodeQL autobuild fail; Actions analysis and dependency review pass; CodeQL check is skipped. Failure logs were requested through git_ci_job_logs; full job-log API output was additionally inspected to recover the root compiler error omitted from the tool's tail.
  • The Javadoc/NestedType collection setters defensively copy before clearing, so aliasing their own getter list does not erase state. These copy-related additions are broader than a conformance SPI but relate to DTO-builder fixtures; they are not treated as unproven copy defects.
  • The new regeneration workflow step is downstream of the failing install and cannot currently execute in CI. I did not change the branch to bypass its broken processor test compilation, so I cannot certify the regeneration assertion or full example reproducibility on this head. Compilation in the suite uses the host javac without --release 17; the local run was Java 17, but this does not independently guarantee future JDK-25-only backend output would be rejected on a JDK 25 test leg.
  • Probe sources and their generated compiler artifacts were deleted. No repository changes or commits.

Other-PR integration review

Written by Devin


Recheck at c0cc02d5 (2026-12-06)

Verdict: blocking

# Original finding (short) Status Remaining action
1 Dangling processor test import fixed —
2 Backend-specific conformance assertions partially fixed — major Compare resolved types/members, not import winners/order; equivalent fully qualified output and reordered fields still fail (GeneratorConformanceTest.java:151–161,261–271,558–594).
3 Infrastructure string concatenation partially fixed — nit Convert remaining header/source and regex construction (CodegenDtoBuilderRegenerationTest.java:114–123; GeneratorConformanceTest.java:580).
N1 New regeneration CI gate fails open — blocker Retain required handwritten collection builders in compilation inputs; rerun opt-in gate/drift check (CodegenDtoBuilderRegenerationTest.java:55–58,89–106; .github/workflows/maven.yml:87–91).

Build: Java 17 full mvn -B verify — BUILD SUCCESS; 1,429 tests, 0 failures/errors, 1 skipped; example compile has no drift; actual opt-in regeneration test fails in isolated source copy: missing ArrayListBuilder/HashSetBuilder (gate skipped by ordinary verify).


Recheck at 8f56529e (2026-12-06)

Verdict: blocking

Severity What is missing Where (file:line)
blocker N1: CI regeneration now runs, but all 12 builders drift (1,370 additions/4,190 deletions); imports switch to simple-builders-core and members disappear. Repair reproducibility, not blind acceptance. CodegenDtoBuilderRegenerationTest.java:88–113,126–131; .github/workflows/maven.yml:87–91
major Partial: legal fully-qualified java.lang.String output compiles warning-free but fails the shared fixture; avoid backend-specific type spelling. GeneratorConformanceTest.java:151–161,543–582
minor N2: Separate fragments accept the type-use annotation moved from flagged onto its class (compiled mutation probe passes). Bind metadata assertions to the field. GeneratorConformanceTest.java:324–332
nit Partial: license header remains an escaped ordinary string; use a text block. CodegenDtoBuilderRegenerationTest.java:120–125

The utility moved to codegen-core (org.javahelpers.codegen.util) where its
test coverage is a strict superset of this dangling copy.
…n in conformance failure message and regeneration header assembly
The ValueExpression migration replaced the map-based members API; the
conformance fixtures now use addMemberString/addMemberBoolean
Generated source is normalized before content assertion: fully qualified
references to imported types collapse to simple names, so backends are free in
their import/qualification style without failing the contract. Collision losers
are never importable and therefore keep their qualified form, retaining the
binding checks. Extraction is not line-based because compact formatting modes
may emit imports without trailing newlines. Compilation checks unchanged.
@igel-devin-ai

Copy link
Copy Markdown
Contributor Author

Strict review complete — the contract major is fixed per the chosen direction (normalization of legal output variance):

  • normalizeQualificationVariance collapses fully qualified references to imported types into simple names before comparison. The review's probe case is exactly what now passes: whether a backend emits java.sql.Date when or Date when for an imported type, the normalized form is identical
  • Collision losers are never imported, so they always keep their qualified form — the binding checks (java.util.Date utilDate vs Date sqlDate) are retained in full strength, as are the compilation checks
  • Not line-based on purpose: compact formatting modes emit import java.sql.Date;public class ... without a newline, which a line-oriented parser would miss
  • Fixtures are written in simple-name-preferred form; the suite documents the normalization as part of its contract level

End-to-end proof: the generated output on disk carries the fq parameter java.sql.Date when while the fixture expects Date when — green only because normalization works. Full roaster suite: 107 tests green.

…om inputs

The input scan filtered out every *Builder.java file, including the hand-written
base classes ArrayListBuilder/HashSetBuilder that generated builders reference -
with the codegen-core jar removed from the classpath compilation failed with
cannot find symbol. Now only the twelve regeneration targets are excluded, with
the target list derived from the same builder group definitions used below
…er-free members

Both variance directions now converge: simple names from imports are EXPANDED to
their qualified form (rather than collapsing fq to simple), so import-style and
in-place-qualified backend output compare equal. Fixtures are written canonically
and split per member, so member reordering no longer fails the contract either.
Remaining concatenation nits converted to formatted assembly
@igel-devin-ai

Copy link
Copy Markdown
Contributor Author

Recheck items addressed:

  • N1 blocker — already fixed in 07774f6: only the twelve regeneration targets are excluded from inputs, handwritten ArrayListBuilder/HashSetBuilder stay compilable; verified end-to-end with -Dcodegen.regenerate=true
  • Finding 2 completed — normalization reworked per your direction: simple names from imports are now expanded to canonical fully qualified form instead of collapsing. Both variance directions converge: a backend emitting everything fq with no imports and one using imports produce identical normalized form. Fixtures are canonical fq and split into per-member fragments, so reordered members no longer fail either. Collision losers (never imported) keep their qualified form — binding checks intact
  • Finding 3 nits — remaining concatenations converted to .formatted assembly

All 10 conformance tests green against the Roaster backend.

This branch has not been deployed

No deployments
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.

Shared generator conformance suite for codegen backends

2 participants