Repository navigation
test(scenario): refuse explicit null on every optional object field - #146
Merged
Merged
Conversation
Walk scenario.schema.json for optional object and array properties, including nested ones, and check that an explicit null on each fails to load with a scenario error. A new optional object field is covered without editing the test. Fixes #141
Contributor
Author
|
Verdict: LGTM (head 67c8c7d) Independent check, test-only PR.
|
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.
Fixes #141
What
One test,
explicit_null_on_an_optional_structured_field_is_refusedincrates/athena-sim/tests/scenario_schema.rs. It walksdocs/scenario.schema.json(following$refand the versionif/then/else) for every optional property typedobjectorarray, including nested ones. For each, it sets an explicitnullin an otherwise valid scenario and requiresrun_scenarioto returnRunError::Scenario(_). A new optional object field in the schema is covered without editing the test. The base isvalid/practice-range.json; for version 2 it is rewritten toscenarioVersion2 withstaterenamed tovars. The schema marks these fields as plainobject/arraywith nonullintype, so the contract is "null is rejected". No new dependency (jsonschemawas already a dev-dependency but is not needed here).Fields enumerated
Version 1:
events,events[0].values,expect,objectives,players[0].buttons,players[0].facing,players[0].position,players[0].state,random,serverLoad.Version 2: the same, plus
players[0].vars,players[0].state.velocity,players[0].state.eyePosition.Loader bug
None. Every field already fails with
ScenarioError::Format.state.velocityandstate.eyePositionare refused by the vector check instate_value, not byobject_or_absent.Mutation evidence
Reverting
object_or_absentto plain#[serde(default)]on a field makes the test fail (file restored afterwards):random(ScenarioDoc.random):version 1: ["random"] set to null: Ok(Trace { outcome: Complete, ... })vars(PlayerDoc.vars):version 2: ["players",0,"vars"] set to null: Ok(Trace { outcome: Complete, ... })Verification run
cargo fmt --check: cleancargo clippy --all-targets -- -D warnings: cleancargo test: all suites pass