From c9e0ca873e2ee37fceafa1f98ec41c1bf4686d09 Mon Sep 17 00:00:00 2001 From: pradhyum6144 Date: Tue, 24 Feb 2026 02:47:28 +0530 Subject: [PATCH] fix(schema): use v1.Model instead of v1.ModelConfig in validateConfig Fixes pre validation always succeeding due to wrong unmarshal target. Also adds positive test cases to TestConfig. Signed-off-by: pradhyum6144 --- schema/config_test.go | 89 +++++++++++++++++++++++++++++++++++++++++++ schema/validator.go | 4 +- 2 files changed, 91 insertions(+), 2 deletions(-) diff --git a/schema/config_test.go b/schema/config_test.go index fd6b644..72fd943 100644 --- a/schema/config_test.go +++ b/schema/config_test.go @@ -477,6 +477,95 @@ func TestConfig(t *testing.T) { `, fail: true, }, + // valid: minimal config with required fields only + { + config: ` +{ + "descriptor": { + "name": "xyz-3-8B-Instruct" + }, + "config": { + "paramSize": "8b" + }, + "modelfs": { + "type": "layers", + "diffIds": [ + "sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef" + ] + } +} +`, + fail: false, + }, + // valid: full config with all optional fields populated + { + config: ` +{ + "descriptor": { + "createdAt": "2025-01-01T00:00:00Z", + "authors": ["xyz@xyz.com"], + "vendor": "XYZ Corp.", + "family": "xyz3", + "name": "xyz-3-8B-Instruct", + "version": "3.1", + "title": "XYZ 3 8B Instruct", + "description": "xyz is a large language model.", + "docURL": "https://www.xyz.com/get-started/", + "sourceURL": "https://github.com/xyz/xyz3", + "datasetsURL": ["https://www.xyz.com/datasets/"], + "revision": "1234567890", + "licenses": ["Apache-2.0"] + }, + "config": { + "architecture": "transformer", + "format": "safetensors", + "paramSize": "8b", + "precision": "float16", + "quantization": "gptq", + "capabilities": { + "inputTypes": ["text"], + "outputTypes": ["text"], + "knowledgeCutoff": "2024-05-21T00:00:00Z", + "reasoning": true, + "toolUsage": false + } + }, + "modelfs": { + "type": "layers", + "diffIds": [ + "sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef", + "sha256:abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890" + ] + } +} +`, + fail: false, + }, + // valid: multimodal model with image input and output + { + config: ` +{ + "descriptor": { + "name": "xyz-vl-7B" + }, + "config": { + "architecture": "transformer", + "paramSize": "7b", + "capabilities": { + "inputTypes": ["text", "image"], + "outputTypes": ["text", "image", "embedding"] + } + }, + "modelfs": { + "type": "layers", + "diffIds": [ + "sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef" + ] + } +} +`, + fail: false, + }, } { r := strings.NewReader(tt.config) err := schema.ValidatorMediaTypeModelConfig.Validate(r) diff --git a/schema/validator.go b/schema/validator.go index d526ec8..bbd0a1a 100644 --- a/schema/validator.go +++ b/schema/validator.go @@ -114,9 +114,9 @@ var validateByMediaType = map[Validator]validateFunc{ } func validateConfig(buf []byte) error { - mc := v1.ModelConfig{} + model := v1.Model{} - err := json.Unmarshal(buf, &mc) + err := json.Unmarshal(buf, &model) if err != nil { return fmt.Errorf("config format mismatch: %w", err) }