Skip to content

fix(contract): strict-decode scenarios.yaml so a typo'd key is a decode error - #910

Merged
jiashuoz merged 1 commit into
tokencanopy:mainfrom
AmirF194:fix/823-contract-yaml-strict-decode
Aug 21, 2026
Merged

fix(contract): strict-decode scenarios.yaml so a typo'd key is a decode error#910
jiashuoz merged 1 commit into
tokencanopy:mainfrom
AmirF194:fix/823-contract-yaml-strict-decode

Conversation

@AmirF194

Copy link
Copy Markdown
Contributor

Summary

loadScenarios (tests/contract/contract_test.go) parses scenarios.yaml with plain yaml.Unmarshal, which silently drops any key with no matching struct field. A scenario author who misspells the assertion block key (body_matchs: instead of body_match:) gets a scenario that still runs and still reports PASS, having asserted nothing about the response body.

decodeScenarios now decodes with yaml.NewDecoder(...).KnownFields(true), so an unknown key fails the decode with the field name in the error instead of vanishing. loadScenarios calls 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 step dispatch in the TS/Python runners), which is a different code path than the assertion-key decode this PR fixes.

Test plan

  • New TestDecodeScenariosRejectsUnknownFields exercises decodeScenarios directly with a body_matchs typo and asserts the decode error names the field. It cannot compile against origin/main (decodeScenarios does not exist there); it passes on this branch.
  • Full TestScenarios suite (32 scenarios) against a real Postgres 16 container: all pass, so the strict decode does not flag any pre-existing key in the real scenarios.yaml.
  • go vet -tags integration ./tests/contract/... and gofmt -l clean on the changed file.
  • Not verified: the TypeScript and Python contract runners' own setup-key handling (out of scope for this PR, see above).

@AmirF194
AmirF194 requested a review from jiashuoz as a code owner August 19, 2026 12:51
…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
jiashuoz force-pushed the fix/823-contract-yaml-strict-decode branch from 5c51b2e to 0e9739b Compare August 21, 2026 05:36

@jiashuoz jiashuoz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed the strict YAML decode path and regression coverage. The refreshed branch is clean and all CI checks pass.

@jiashuoz
jiashuoz merged commit 619f991 into tokencanopy:main Aug 21, 2026
24 checks passed
@AmirF194

Copy link
Copy Markdown
Contributor Author

Thanks for reviewing and merging.

@AmirF194
AmirF194 deleted the fix/823-contract-yaml-strict-decode branch August 21, 2026 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants