fix(contract): strict-decode scenarios.yaml so a typo'd key is a decode error - #910
Merged
jiashuoz merged 1 commit intoAug 21, 2026
Conversation
…de error loadScenarios parsed scenarios.yaml with plain yaml.Unmarshal, which silently drops any key with no matching struct field. A misspelled assertion block (body_matchs instead of body_match) left the scenario running and reporting PASS with nothing actually asserted about the response body. decodeScenarios now uses yaml.NewDecoder(...).KnownFields(true), so an unknown key fails the decode with the field name in the error instead of vanishing. Refs tokencanopy#823
jiashuoz
force-pushed
the
fix/823-contract-yaml-strict-decode
branch
from
August 21, 2026 05:36
5c51b2e to
0e9739b
Compare
jiashuoz
approved these changes
Aug 21, 2026
jiashuoz
left a comment
Member
There was a problem hiding this comment.
Reviewed the strict YAML decode path and regression coverage. The refreshed branch is clean and all CI checks pass.
Contributor
Author
|
Thanks for reviewing and merging. |
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.
Summary
loadScenarios(tests/contract/contract_test.go) parsesscenarios.yamlwith plainyaml.Unmarshal, which silently drops any key with no matching struct field. A scenario author who misspells the assertion block key (body_matchs:instead ofbody_match:) gets a scenario that still runs and still reports PASS, having asserted nothing about the response body.decodeScenariosnow decodes withyaml.NewDecoder(...).KnownFields(true), so an unknown key fails the decode with the field name in the error instead of vanishing.loadScenarioscalls it and fails the test with that error, same as it already fails on a malformed YAML document.Refs #823. This covers the issue's proposed fix (the Go loader) and, since all three runners read the same
scenarios.yaml, the Go contract job now gates the file for TypeScript and Python too. It does not touch the runners' own unknown-setup-key handling that the issue separately flags in its last paragraph (if key in stepdispatch in the TS/Python runners), which is a different code path than the assertion-key decode this PR fixes.Test plan
TestDecodeScenariosRejectsUnknownFieldsexercisesdecodeScenariosdirectly with abody_matchstypo and asserts the decode error names the field. It cannot compile againstorigin/main(decodeScenariosdoes not exist there); it passes on this branch.TestScenariossuite (32 scenarios) against a real Postgres 16 container: all pass, so the strict decode does not flag any pre-existing key in the realscenarios.yaml.go vet -tags integration ./tests/contract/...andgofmt -lclean on the changed file.