Skip to content

Comments

fix(schema): use v1.Model instead of v1.ModelConfig in validateConfig#170

Open
pradhyum6144 wants to merge 1 commit intomodelpack:mainfrom
pradhyum6144:fix-validateconfig-wrong-unmarshal-type
Open

fix(schema): use v1.Model instead of v1.ModelConfig in validateConfig#170
pradhyum6144 wants to merge 1 commit intomodelpack:mainfrom
pradhyum6144:fix-validateconfig-wrong-unmarshal-type

Conversation

@pradhyum6144
Copy link

Summary

validateConfig was unmarshaling input into v1.ModelConfig (the inner config block) instead of v1.Model (the full document). Since json.Unmarshal silently ignores unknown fields, the pre-schema type check always succeeded — making it a no-op.

Details

  • Problem: validateConfig used v1.ModelConfig{} as the unmarshal target. A full Model JSON (with descriptor, config, modelfs) would unmarshal into the tiny ModelConfig struct without error, so structural mismatches were never caught at this stage.
  • Fix: Changed the unmarshal target to v1.Model{} so the pre-validation actually checks the correct document shape.
  • Tests: Added 3 positive test cases to TestConfig — previously all 17 cases asserted failure, so a validator that always errored would still pass the entire suite.

Testing

```
go test ./schema/ -run TestConfig -v ✓ PASS
go test ./schema/ -run TestValidateConfigExample -v ✓ PASS
go test ./... ✓ PASS
```

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @pradhyum6144, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug in the schema validation logic where the validateConfig function was incorrectly unmarshaling input into a partial configuration struct (v1.ModelConfig) instead of the complete model document (v1.Model). This oversight meant that structural mismatches in the full model JSON were silently ignored during pre-validation. The fix ensures that the entire model document is correctly validated against its schema, significantly improving the robustness of configuration parsing. Additionally, new positive test cases have been introduced to thoroughly verify the corrected validation behavior.

Highlights

  • Schema Validation Fix: Corrected validateConfig to unmarshal into v1.Model instead of v1.ModelConfig, ensuring proper validation of the full model document.
  • Improved Test Coverage: Added three new positive test cases to TestConfig to verify the v1.Model validation logic, addressing a previous gap where only failure cases were asserted.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • schema/config_test.go
    • Added three new test cases to TestConfig to validate successful unmarshaling of minimal, full, and multimodal model configurations.
  • schema/validator.go
    • Modified the validateConfig function to unmarshal JSON into v1.Model instead of v1.ModelConfig.
Activity
  • No human activity has occurred on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly fixes a bug in validateConfig where it was unmarshaling into v1.ModelConfig instead of the full v1.Model, which made the pre-schema validation a no-op. The change to unmarshal into v1.Model is correct. Additionally, the pull request significantly improves test coverage by adding positive test cases, addressing a situation where the test suite would pass even with a validator that always failed. The changes are solid, and I have one minor suggestion for improving code clarity.


func validateConfig(buf []byte) error {
mc := v1.ModelConfig{}
mc := v1.Model{}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For better readability and to reflect the type change, consider renaming the mc variable. It likely stood for ModelConfig, but now it holds a v1.Model. Renaming it to m or model would make the code clearer. You would need to update its usage on line 119 as well.

Fixes pre validation always succeeding due to wrong unmarshal target.
Also adds positive test cases to TestConfig.

Signed-off-by: pradhyum6144 <pradhyum314@gmail.com>
@pradhyum6144 pradhyum6144 force-pushed the fix-validateconfig-wrong-unmarshal-type branch from 863b290 to c9e0ca8 Compare February 23, 2026 21:22
@pradhyum6144
Copy link
Author

pradhyum6144 commented Feb 23, 2026

Could a maintainer please add the bug label to this PR? The Classify PR check requires exactly one of: bug, enhancement, documentation, dependencies and this is a bug fix.

@aftersnow aftersnow added the bug Something isn't working label Feb 24, 2026
Copy link
Contributor

@aftersnow aftersnow left a comment

Choose a reason for hiding this comment

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

lgtm, thank you!

Copy link

@sabre1041 sabre1041 left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants