Skip to content

Add constructive Rapid OpenAPI request-body test generation#1

Merged
djosh34 merged 81 commits into
masterfrom
overhaul-test_generator
Jul 11, 2026
Merged

Add constructive Rapid OpenAPI request-body test generation#1
djosh34 merged 81 commits into
masterfrom
overhaul-test_generator

Conversation

@djosh34

@djosh34 djosh34 commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Overview

Replaces the legacy request-body test generator with constructive, schema-driven Rapid generation. The new pipeline resolves OpenAPI references, compiles canonical multi-kind domains, plans valid and isolated-invalid cases, and generates exact semantic JSON values with independent validator coverage.

This includes optional type with type-specific keyword applicability and lazy Schema Object Reference Object resolution that ignores $ref siblings as required by OpenAPI 3.0.3.

Closes #2
Closes #3

Summary by CodeRabbit

  • New Features

    • Added comprehensive OpenAPI request-body test generation covering schemas, references, compositions, constraints, enums, and nested data.
    • Added constructive generation of valid and invalid JSON examples, including precise numeric handling and trusted string examples.
    • Added clearer validation errors and support for deterministic, semantically equivalent JSON values.
  • Bug Fixes

    • Improved detection of validator issues across common schema keyword families.
    • Added independent integration coverage against OpenAPI validation behavior.
  • Documentation

    • Added guidance for OpenAPI validation and architectural design practices.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pkg/test_generator/domain/allof_allof_merge_test.go (1)

379-397: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Test doesn't exercise its stated "injected child parse fails" scenario.

{"allOf":[{},{}]} uses two empty object items. validateAllOfItem rejects an empty allOf item schema before dc.Parse/the injected mock is ever called, so the returned error comes from schema validation, not from the injected "boom" failure on the second call. calls never reaches 2, but the test doesn't assert on calls, so it passes for the wrong reason and leaves the intended rollback-on-child-parse-error path (distinct from the preceding subtest, which already covers a real parser type error) effectively untested.

🧪 Proposed fix to actually exercise the injected failure
-		raw := json.RawMessage(`{"allOf":[{},{}]}`)
+		raw := json.RawMessage(`{"allOf":[{"type":"string"},{"type":"string"}]}`)
 		dc := &Context{}
 		calls := 0
 		dc.parse = func(_ *json.RawMessage) (types.Domain, error) {
 			calls++
 			if calls == 2 {
 				return nil, errors.New("boom")
 			}
 
 			return &StringDomain{}, nil
 		}
 		got, err := dc.Parse(&raw)
 		require.Error(t, err)
 		require.Nil(t, got)
 		require.Empty(t, dc.domainStore)
+		require.Equal(t, 2, calls)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/test_generator/domain/allof_allof_merge_test.go` around lines 379 - 397,
The subtest in Context.Parse is not reaching the injected child parse failure
because the allOf payload uses empty object items that fail validateAllOfItem
before the mocked parse is called. Change the test setup so the allOf items are
valid enough to pass schema validation, then keep the injected dc.parse failure
on the second call and assert the expected rollback behavior via dc.domainStore
plus the call count if needed. This ensures the “injected child parse fails no
partial store commit” case actually exercises the intended path in Context.Parse
and validateAllOfItem.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@pkg/test_generator/domain/allof_allof_merge_test.go`:
- Around line 379-397: The subtest in Context.Parse is not reaching the injected
child parse failure because the allOf payload uses empty object items that fail
validateAllOfItem before the mocked parse is called. Change the test setup so
the allOf items are valid enough to pass schema validation, then keep the
injected dc.parse failure on the second call and assert the expected rollback
behavior via dc.domainStore plus the call count if needed. This ensures the
“injected child parse fails no partial store commit” case actually exercises the
intended path in Context.Parse and validateAllOfItem.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 59fba323-d5ed-4bcd-b0f1-d2d9c06e90c6

📥 Commits

Reviewing files that changed from the base of the PR and between d26dd02 and 9df5ad0.

📒 Files selected for processing (42)
  • pkg/test_generator/domain/allOf_domain.go
  • pkg/test_generator/domain/allOf_parse_test.go
  • pkg/test_generator/domain/allof_allof_merge_test.go
  • pkg/test_generator/domain/allof_merge_additional_plan_test.go
  • pkg/test_generator/domain/array_allof_merge_test.go
  • pkg/test_generator/domain/array_domain.go
  • pkg/test_generator/domain/array_domain_test.go
  • pkg/test_generator/domain/array_parse_test.go
  • pkg/test_generator/domain/bool_allof_merge_test.go
  • pkg/test_generator/domain/bool_domain.go
  • pkg/test_generator/domain/bool_parse_test.go
  • pkg/test_generator/domain/coverage_gap_test.go
  • pkg/test_generator/domain/domain.go
  • pkg/test_generator/domain/domain_hash_test.go
  • pkg/test_generator/domain/domain_test.go
  • pkg/test_generator/domain/domain_types_test.go
  • pkg/test_generator/domain/enum.go
  • pkg/test_generator/domain/enum_test.go
  • pkg/test_generator/domain/enum_value_validation_test.go
  • pkg/test_generator/domain/hash.go
  • pkg/test_generator/domain/hash_test.go
  • pkg/test_generator/domain/number_allof_merge_test.go
  • pkg/test_generator/domain/number_domain.go
  • pkg/test_generator/domain/number_parse_test.go
  • pkg/test_generator/domain/object_allof_merge_test.go
  • pkg/test_generator/domain/object_domain.go
  • pkg/test_generator/domain/object_domain_test.go
  • pkg/test_generator/domain/string_allof_merge_test.go
  • pkg/test_generator/domain/string_domain.go
  • pkg/test_generator/domain/string_domain_test.go
  • pkg/test_generator/domain/string_parse_test.go
  • pkg/test_generator/jsonrefs/jsonrefs.go
  • pkg/test_generator/jsonrefs/jsonrefs_test.go
  • pkg/test_generator/openapi.go
  • pkg/test_generator/openapi_test.go
  • pkg/test_generator/test_generator.go
  • pkg/test_generator/types/enum.go
  • pkg/test_generator/types/enum_test.go
  • pkg/test_generator/types/string_constraints.go
  • pkg/test_generator/types/string_constraints_test.go
  • pkg/test_generator/types/types.go
  • pkg/test_generator/utils.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.pi/skills/codebase-design/DEEPENING.md:
- Around line 34-37: Revise the testing guidance around “interface is the test
surface” to prohibit deleting existing shallow-module tests until equivalent
behavioral coverage, including edge cases and invariants, exists at the deepened
module’s interface. Preserve the recommendation that interface tests are primary
and assert observable outcomes rather than internal state.

In @.pi/skills/codebase-design/SKILL.md:
- Around line 34-41: Add the text language identifier to both fenced ASCII
diagram blocks in SKILL.md, including the blocks around the “Small Interface”
and corresponding later diagram, by changing each opening fence to specify text
while preserving their contents.

In @.pi/skills/improve-codebase-architecture/HTML-REPORT.md:
- Line 16: Update the Mermaid initialization configuration to use securityLevel
"strict" instead of "loose" in mermaid.initialize; retain the existing
startOnLoad and theme settings, and only choose "sandbox" if the generated
report requires interactivity.

In @.pi/skills/improve-codebase-architecture/SKILL.md:
- Around line 34-36: Resolve the contradiction in the report-generation
instructions: either embed Tailwind and Mermaid assets directly in the generated
HTML, or explicitly state that the output requires network access and document
the trust and privacy implications of loading third-party CDN scripts. Update
the self-contained HTML guidance accordingly while preserving the existing
visualisation requirements.
- Around line 20-22: Update the initial workflow in the skill instructions to
handle a missing CONTEXT.md before requiring it to be read: either create the
file before Step 1 or explicitly continue using repository terminology when it
is absent. Ensure the subsequent exploration with the Explore agent remains
reachable in repositories without CONTEXT.md, while preserving the existing
ADR-reading guidance.

In `@AGENTS.md`:
- Line 17: Update the OpenAPI 3.0.3 description in AGENTS.md to identify it as
an extended subset of JSON Schema rather than a superset, avoiding wording that
suggests unsupported JSON Schema features are valid.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: de46111c-bffc-44d6-b444-38950a06e20e

📥 Commits

Reviewing files that changed from the base of the PR and between 9df5ad0 and f7f8e02.

📒 Files selected for processing (6)
  • .pi/skills/codebase-design/DEEPENING.md
  • .pi/skills/codebase-design/DESIGN-IT-TWICE.md
  • .pi/skills/codebase-design/SKILL.md
  • .pi/skills/improve-codebase-architecture/HTML-REPORT.md
  • .pi/skills/improve-codebase-architecture/SKILL.md
  • AGENTS.md

Comment thread .pi/skills/codebase-design/DEEPENING.md Outdated
Comment thread .pi/skills/codebase-design/SKILL.md Outdated
Comment thread .pi/skills/improve-codebase-architecture/HTML-REPORT.md Outdated
Comment thread .pi/skills/improve-codebase-architecture/SKILL.md Outdated
Comment thread .pi/skills/improve-codebase-architecture/SKILL.md Outdated
Comment thread AGENTS.md Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pkg/test_generator/internal/jsonvalue/value.go (1)

1-717: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Restore the missing testgenerator.GenerateValid API

pkg/test_generator/test_generator.go exports CheckJSONRequestBody, but pkg/generate/templates/models_test.go.tmpl still emits testgenerator.GenerateValid and testgenerator.GenerateInvalid. Update the template or add compatibility wrappers so generated downstream tests compile.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/test_generator/internal/jsonvalue/value.go` around lines 1 - 717, Restore
the exported testgenerator.GenerateValid API expected by generated tests,
alongside GenerateInvalid. Update the relevant generation template or add
compatibility wrappers around the existing JSON generation behavior so
pkg/generate/templates/models_test.go.tmpl output compiles without changing its
calls.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/test_generator/internal/jsonvalue/value.go`:
- Around line 128-138: In ParseNumber, simplify the magnitude calculation by
calling Abs directly with exponent instead of creating an intermediate copy,
reducing the expression to a single big.Int allocation while preserving the
existing comparison and parsing behavior.

In `@pkg/test_generator/test_generator.go`:
- Around line 39-57: The new CheckJSONRequestBody API is incompatible with
existing GenerateValid and GenerateInvalid callers. Either retain compatibility
wrappers for both public methods, or update
pkg/generate/templates/models_test.go.tmpl and regenerate the consumer tests to
use CheckJSONRequestBody, ensuring pkg/decode/example/models_test.go and
pkg/decode/example_gen/models_test.go compile.

---

Outside diff comments:
In `@pkg/test_generator/internal/jsonvalue/value.go`:
- Around line 1-717: Restore the exported testgenerator.GenerateValid API
expected by generated tests, alongside GenerateInvalid. Update the relevant
generation template or add compatibility wrappers around the existing JSON
generation behavior so pkg/generate/templates/models_test.go.tmpl output
compiles without changing its calls.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: f5df0725-d543-4042-8e1e-a6eb73cac895

📥 Commits

Reviewing files that changed from the base of the PR and between f7f8e02 and cb51cb3.

📒 Files selected for processing (12)
  • pkg/test_generator/check_test.go
  • pkg/test_generator/internal/jsonvalue/value.go
  • pkg/test_generator/internal/jsonvalue/value_test.go
  • pkg/test_generator/internal/oas/source.go
  • pkg/test_generator/internal/oas/source_test.go
  • pkg/test_generator/internal/suite/compile.go
  • pkg/test_generator/internal/suite/compile_test.go
  • pkg/test_generator/internal/suite/domain.go
  • pkg/test_generator/internal/suite/domain_registry.go
  • pkg/test_generator/openapi_test.go
  • pkg/test_generator/test_generator.go
  • pkg/test_generator/types/enum.go
💤 Files with no reviewable changes (1)
  • pkg/test_generator/openapi_test.go

Comment thread pkg/test_generator/internal/jsonvalue/value.go
Comment thread pkg/test_generator/test_generator.go Outdated
@djosh34

djosh34 commented Jul 11, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai resume\n\n@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown

@djosh34 Sure thing — resuming automatic reviews and kicking off a review now.

✅ Action performed

Reviews resumed.


Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@djosh34 djosh34 changed the title Overhaul test generator Add constructive Rapid OpenAPI request-body test generation Jul 11, 2026
@djosh34

djosh34 commented Jul 11, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai resume\n\n@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown

@djosh34 Got it — resuming automatic reviews and starting a new review now.

✅ Action performed

Reviews resumed.


Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@djosh34

djosh34 commented Jul 11, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai resume\n\n@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown

@djosh34: Resuming automatic reviews and starting a new review now.

✅ Action performed

Reviews resumed.


Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/test_generator/internal/suite/case_partitions.go`:
- Around line 165-176: Define one shared named type, such as labeledBound, for
the label-and-integer boundary entries, then update addStringLengthPartitions,
addArrayCountPartitions, and addObjectCountPartitions to use it for both slice
initialization and conditional appends. Preserve each helper’s existing labels
and constraint values while removing the repeated anonymous struct declarations.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: e2567279-5c30-496c-8b69-ab2aec168860

📥 Commits

Reviewing files that changed from the base of the PR and between f7f8e02 and e15616f.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (22)
  • go.mod
  • pkg/test_generator/check_test.go
  • pkg/test_generator/internal/jsonvalue/value.go
  • pkg/test_generator/internal/jsonvalue/value_test.go
  • pkg/test_generator/internal/oas/source.go
  • pkg/test_generator/internal/oas/source_test.go
  • pkg/test_generator/internal/suite/case_partitions.go
  • pkg/test_generator/internal/suite/case_planner.go
  • pkg/test_generator/internal/suite/case_planner_test.go
  • pkg/test_generator/internal/suite/case_witnesses.go
  • pkg/test_generator/internal/suite/compile.go
  • pkg/test_generator/internal/suite/compile_allof.go
  • pkg/test_generator/internal/suite/compile_test.go
  • pkg/test_generator/internal/suite/compile_values.go
  • pkg/test_generator/internal/suite/domain.go
  • pkg/test_generator/internal/suite/domain_registry.go
  • pkg/test_generator/internal/suite/intersect.go
  • pkg/test_generator/internal/suite/intersect_test.go
  • pkg/test_generator/internal/suite/rapid_generator.go
  • pkg/test_generator/internal/suite/rapid_generator_test.go
  • pkg/test_generator/libopenapi_validator_integration_test.go
  • pkg/test_generator/test_generator.go

Comment thread pkg/test_generator/internal/suite/case_partitions.go Outdated
@djosh34

djosh34 commented Jul 11, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai resume\n\n@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown

@djosh34 Resuming automatic reviews and starting a new review now.

✅ Action performed

Reviews resumed.


Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@djosh34 djosh34 merged commit a0df8f4 into master Jul 11, 2026
1 check passed
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.

Resolve Schema Object $ref before domain parsing and ignore siblings Support schemas without type and type-specific keyword applicability

1 participant