test(api): strict-decode config/samples to catch hallucinated CRD fields#1023
Merged
Defilan merged 1 commit intoJul 9, 2026
Merged
Conversation
The Foreman gate runs Go-only checks (fmt/vet/lint/test), so a config/samples change with invalid CRD fields passes: nothing validates the YAML against the schema. On defilantech#699 a coder rewrote a sample with spec.url (the field is source), a spec.parameters block, modelRef as an object (it is a string), runtime as an object, and spec.service (it is endpoint); the manifest would fail kubectl apply, yet it GATE-PASSed. Add a test that strict-decodes every Model/InferenceService/ModelRouter doc in config/samples into its typed struct via sigs.k8s.io/yaml.UnmarshalStrict, so an unknown or mistyped field fails in `make test` (gate-covered), not at kubectl apply time. Foreign kinds (HTTPScaledObject, Secret, Service) are skipped. A companion negative test proves the guard rejects the exact defilantech#699 field errors. Fixes defilantech#1021 Signed-off-by: Christopher Maher <chris@mahercode.io>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A Go test that strict-decodes every
Model/InferenceService/ModelRouterdocument inconfig/samples/**into its typed struct, failing on unknown or mistyped fields.Why
The Foreman gate runs Go-only checks, so a
config/sampleschange with invalid CRD fields GATE-PASSes — nothing validates the YAML against the schema. Dogfooding #699 exposed this: a coder rewrote a sample withspec.url(the field issource), aspec.parametersblock,modelRefas an object (it is a string),runtimeas an object, andspec.service(it isendpoint). The manifest would failkubectl apply, yet it GATE-PASSed and looked mergeable.How
sigs.k8s.io/yaml.UnmarshalStrict(YAML → JSON →json.DecoderwithDisallowUnknownFields) rejects unknown fields and type mismatches. The test iterates the sample docs, decodes the LLMKube CRD kinds into their structs, and skips foreign kinds (KEDAHTTPScaledObject, coreSecret/Service).Chosen over kubeconform + CRD-schema extraction (the approach floated in #1021): this needs no external tooling or CRD-to-JSON-Schema step, uses the types as the single source of truth, and — crucially — runs in
make test, so it is gate-covered. A future #699 would GATE-FAIL, not merely fail a CI-only step.Testing
TestConfigSamplesDecodeStrictpasses on all 22 current samples (no false positives).TestConfigSamplesDecodeStrict_CatchesBadFieldsproves the guard rejects the exact [FEATURE] Validated AMD (Vulkan) example InferenceService + benchmark #699 errors (url,parameters,modelRef-as-object).Checklist
Fixes #1021make testAssisted-by: Claude Code (identified the gate gap while reviewing Foreman output, wrote the guard; human-reviewed and DCO-signed by the maintainer).