[COVAL-4475] Treat a null metadata_key as absent in reports validation - #107
Draft
callumreid wants to merge 1 commit into
Draft
[COVAL-4475] Treat a null metadata_key as absent in reports validation#107callumreid wants to merge 1 commit into
callumreid wants to merge 1 commit into
Conversation
contains_key returns true for an explicit JSON null, but the field deserializes into an Option as None, so the guard disagreed with what was actually sent. Use the same predicate as validate_custom_dimensions.
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository YAML (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Problem
validate_metadata_keyinsrc/commands/reports.rsdecided whether a metadata key was supplied withinput.contains_key("metadata_key").contains_keyreturns true for an explicit JSONnull, but the field deserializes into anOptionasNone— so a null is effectively absent, and the guard disagreed with what actually got sent.Two wrong outcomes, both reachable through
--input-jsononreports createandreports update:--input-json '{"compare_by": "metadata", "metadata_key": null}'passed the client-side check, then sent a metadata comparison with no key for the API to reject. Catching that before the request is the entire point of the guard.--input-json '{"compare_by": "run", "metadata_key": null}'bailed with--metadata-key can only be set when --compare-by is metadata, blocking a valid command over a field that is effectively absent.Change
The same predicate Greptile's review produced for the sibling
validate_custom_dimensionsin #102 (commitf55c51e):metadata_keywas left out of that PR deliberately —validate_metadata_keypredates it onmain, and the standing rule is to scope review-bot fixes to new code. This is that fix, on its own.Note that #102 is still open, so
validate_custom_dimensionsis not onmainyet; these two functions will want to converge on a shared helper once it lands. Left alone here to keep this diff to the defect.Tests
Two regression tests in
tests/cli_tests.rs, mirroringtest_reports_create_custom_rejects_null_custom_dimensionsandtest_reports_create_allows_null_custom_dimensions_without_custom_compare_byfrom #102:test_reports_create_metadata_rejects_null_metadata_keytest_reports_create_allows_null_metadata_key_without_metadata_compare_byVerified they fail without the source change (stashed
src/commands/reports.rs, re-ran). The failure output is the defect verbatim:Error: Authentication failed: Missing API Key— i.e. validation let it through and the CLI really did reach the API.Error: --metadata-key can only be set when --compare-by is metadata.Observed locally on the branch head:
cargo fmt --check— cleancargo clippy --all-targets -- -D warnings— cleancargo test --test cli_tests reports— 10 passed, 0 failedCloses COVAL-4475.