Skip to content

📝 chore: Add mixed-input regression coverage to generate config tests#607

Merged
mckornfield merged 1 commit into
move-structured-gen-parameters/mckfrom
coderabbitai/chat/ae26998
Jun 25, 2026
Merged

📝 chore: Add mixed-input regression coverage to generate config tests#607
mckornfield merged 1 commit into
move-structured-gen-parameters/mckfrom
coderabbitai/chat/ae26998

Conversation

@coderabbitai

@coderabbitai coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Code changes was requested by @binaryaaron.

The following files were modified:

  • tests/config/test_generate.py

@coderabbitai
coderabbitai Bot requested a review from a team as a code owner June 24, 2026 15:15
@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

Important

Review skipped

This PR was authored by the user configured for CodeRabbit reviews. CodeRabbit does not review PRs authored by this user. It's recommended to use a dedicated user account to post CodeRabbit review feedback.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: d597ab47-6bee-4110-bd49-5f88b6018c72

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds TestMixedInputMigration, a new test class with 7 regression tests covering the scenario where legacy flat structured-generation keys (e.g. structured_generation_backend, use_structured_generation) coexist with a nested structured_generation dict during model validation or from_params calls.

  • Five tests correctly verify that legacy flat keys take precedence over their nested-dict counterparts and that un-overridden fields are preserved, covering both GenerateParameters.model_validate and SafeSynthesizerParameters.from_params call sites.
  • Two tests (test_nested_dict_with_no_legacy_keys_uses_dict_values and test_legacy_keys_with_no_nested_dict_are_migrated) cover the degenerate non-mixed cases and largely duplicate tests that already exist in TestStructuredGenerationParametersStructuralTagValidation; the only genuinely new assertion is use_single_sequence in the legacy-only test.
  • No test covers the case where a mixed-input combination resolves to an incompatible validated state (e.g. legacy backend="outlines" override on a nested dict with schema_method="structural_tag"), leaving the validator's rejection path untested for mixed inputs.

Confidence Score: 4/5

Test-only change; the assertions match the actual migration logic and will not regress production behavior.

All assertions are consistent with the _migrate_legacy_structured_generation_fields implementation. The two duplicate/misclassified tests are noise but not wrong. The only real gap is missing a pytest.raises test for a mixed-input pair that produces an invalid merged config, leaving one branch of the migration+validation interaction untested.

tests/config/test_generate.py — the two non-mixed-input tests and the absent validation-failure test are worth a second look.

Important Files Changed

Filename Overview
tests/config/test_generate.py Adds TestMixedInputMigration (7 tests) covering legacy-key-over-nested-dict precedence; assertions are logically correct against the migration implementation, but two tests are misclassified (non-mixed scenarios) and there is no coverage for a mixed-input combination that produces a validation failure.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["model_validate(data dict)"] --> B{"Any legacy flat keys?\ne.g. use_structured_generation,\nstructured_generation_backend"}
    B -- No --> C["Return data unchanged\n(nested dict used as-is)"]
    B -- Yes --> D["Pop legacy keys into legacy{}"]
    D --> E{"structured_generation\nvalue type?"}
    E -- "dict / BaseModel" --> F["structured_values = dict(nested)"]
    E -- None --> G["structured_values = {}"]
    F --> H["Merge: structured_values | legacy\n(legacy wins on collision)"]
    G --> H
    H --> I["Set values['structured_generation']"]
    I --> J["Pydantic validates StructuredGenerationParameters"]
    J --> K{"enabled AND schema_method == structural_tag?"}
    K -- No --> L["Valid params"]
    K -- Yes --> M{"backend in xgrammar / auto?"}
    M -- Yes --> L
    M -- No --> N["ParameterError raised"]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A["model_validate(data dict)"] --> B{"Any legacy flat keys?\ne.g. use_structured_generation,\nstructured_generation_backend"}
    B -- No --> C["Return data unchanged\n(nested dict used as-is)"]
    B -- Yes --> D["Pop legacy keys into legacy{}"]
    D --> E{"structured_generation\nvalue type?"}
    E -- "dict / BaseModel" --> F["structured_values = dict(nested)"]
    E -- None --> G["structured_values = {}"]
    F --> H["Merge: structured_values | legacy\n(legacy wins on collision)"]
    G --> H
    H --> I["Set values['structured_generation']"]
    I --> J["Pydantic validates StructuredGenerationParameters"]
    J --> K{"enabled AND schema_method == structural_tag?"}
    K -- No --> L["Valid params"]
    K -- Yes --> M{"backend in xgrammar / auto?"}
    M -- Yes --> L
    M -- No --> N["ParameterError raised"]
Loading

Comments Outside Diff (1)

  1. tests/config/test_generate.py, line 183-212 (link)

    P2 Two tests don't belong in TestMixedInputMigration

    test_nested_dict_with_no_legacy_keys_uses_dict_values and test_legacy_keys_with_no_nested_dict_are_migrated test the pure-nested and pure-legacy paths respectively — not the mixed-input scenario that the class docstring and name describe. They are also effectively duplicates of test_generate_parameters_accepts_nested_structured_generation and test_generate_parameters_migrates_legacy_flat_keys that already exist in TestStructuredGenerationParametersStructuralTagValidation. The only genuine addition in test_legacy_keys_with_no_nested_dict_are_migrated is the structured_generation_use_single_sequence key, which could be a one-liner addition to the existing test. Keeping them here is fine as baselines, but the class docstring should acknowledge they cover the degenerate (non-mixed) cases.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Reviews (1): Last reviewed commit: "📝 CodeRabbit Chat: Add mixed-input regr..." | Re-trigger Greptile

Comment on lines +124 to +181
@pytest.mark.unit
class TestMixedInputMigration:
"""Regression coverage for mixed-input: legacy flat keys coexist with nested structured_generation dict.

The migration contract: when both forms are present, legacy flat keys win as explicit overrides.
Un-overridden nested dict fields are preserved.
"""

def test_legacy_backend_overrides_nested_dict_backend(self) -> None:
"""A legacy flat backend key beats the nested dict backend when both are supplied."""
params = GenerateParameters.model_validate(
{
"structured_generation": {"enabled": True, "backend": "outlines"},
"structured_generation_backend": "xgrammar",
}
)
assert params.structured_generation.backend == "xgrammar"
assert params.structured_generation.enabled is True # nested value preserved

def test_legacy_enabled_overrides_nested_dict_enabled(self) -> None:
"""A legacy use_structured_generation key beats the nested dict enabled field."""
params = GenerateParameters.model_validate(
{
"use_structured_generation": True,
"structured_generation": {"enabled": False, "schema_method": "json_schema"},
}
)
assert params.structured_generation.enabled is True
assert params.structured_generation.schema_method == "json_schema" # preserved

def test_legacy_schema_method_overrides_nested_dict_schema_method(self) -> None:
"""A legacy schema_method key beats the nested dict schema_method field."""
params = GenerateParameters.model_validate(
{
"structured_generation_schema_method": "regex",
"structured_generation": {"enabled": True, "schema_method": "json_schema"},
}
)
assert params.structured_generation.schema_method == "regex"
assert params.structured_generation.enabled is True # preserved

def test_from_params_legacy_backend_overrides_generation_section_backend(self) -> None:
"""from_params: a top-level legacy backend key overrides the backend inside generation={}."""
params = SafeSynthesizerParameters.from_params(
generation={"structured_generation": {"enabled": True, "backend": "outlines"}},
structured_generation_backend="xgrammar",
)
assert params.generation.structured_generation.backend == "xgrammar"
assert params.generation.structured_generation.enabled is True # preserved

def test_from_params_legacy_enabled_overrides_structured_generation_kwarg(self) -> None:
"""from_params: a top-level legacy use_structured_generation overrides structured_generation kwarg."""
params = SafeSynthesizerParameters.from_params(
structured_generation={"enabled": False, "schema_method": "json_schema"},
use_structured_generation=True,
)
assert params.generation.structured_generation.enabled is True
assert params.generation.structured_generation.schema_method == "json_schema" # preserved

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 No test for a mixed-input combination that produces an invalid merged config

Every mixed-input test here asserts a valid final state. The migration contract is that legacy keys act as overrides, so a caller who passes structured_generation={"schema_method": "structural_tag", "backend": "xgrammar"} alongside a legacy structured_generation_backend="outlines" override would end up with schema_method="structural_tag" + backend="outlines" — an incompatible pair that the _validate_structural_tag_backend validator must reject. Without a pytest.raises test for this path there is no regression coverage for the case where the merged result is invalid, and a future change to the merge order or validator could silently break it.

@mckornfield mckornfield changed the title 📝 CodeRabbit Chat: Add mixed-input regression coverage to generate config tests 📝 chore: Add mixed-input regression coverage to generate config tests Jun 25, 2026
@mckornfield
mckornfield merged commit 2bd332c into move-structured-gen-parameters/mck Jun 25, 2026
3 of 7 checks passed
@mckornfield
mckornfield deleted the coderabbitai/chat/ae26998 branch June 25, 2026 15:48
mckornfield pushed a commit that referenced this pull request Jun 25, 2026
…607)

Code changes was requested by @binaryaaron.

*
#595 (comment)

The following files were modified:

* `tests/config/test_generate.py`

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: mkornfield <mkornfield@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants