Skip to content

[COVAL-4475] Treat a null metadata_key as absent in reports validation - #107

Draft
callumreid wants to merge 1 commit into
mainfrom
fix/coval-4475-metadata-key-null
Draft

[COVAL-4475] Treat a null metadata_key as absent in reports validation#107
callumreid wants to merge 1 commit into
mainfrom
fix/coval-4475-metadata-key-null

Conversation

@callumreid

Copy link
Copy Markdown
Contributor

Problem

validate_metadata_key in src/commands/reports.rs decided whether a metadata key was supplied with input.contains_key("metadata_key"). contains_key returns true for an explicit JSON null, but the field deserializes into an Option as None — so a null is effectively absent, and the guard disagreed with what actually got sent.

Two wrong outcomes, both reachable through --input-json on reports create and reports update:

  1. --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.
  2. --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_dimensions in #102 (commit f55c51e):

let has_metadata_key = input
    .get("metadata_key")
    .is_some_and(|value| !value.is_null());

metadata_key was left out of that PR deliberately — validate_metadata_key predates it on main, 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_dimensions is not on main yet; 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, mirroring test_reports_create_custom_rejects_null_custom_dimensions and test_reports_create_allows_null_custom_dimensions_without_custom_compare_by from #102:

  • test_reports_create_metadata_rejects_null_metadata_key
  • test_reports_create_allows_null_metadata_key_without_metadata_compare_by

Verified they fail without the source change (stashed src/commands/reports.rs, re-ran). The failure output is the defect verbatim:

  • Case 1 got Error: Authentication failed: Missing API Key — i.e. validation let it through and the CLI really did reach the API.
  • Case 2 got Error: --metadata-key can only be set when --compare-by is metadata.

Observed locally on the branch head:

  • cargo fmt --check — clean
  • cargo clippy --all-targets -- -D warnings — clean
  • cargo test --test cli_tests reports — 10 passed, 0 failed

Closes COVAL-4475.

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.
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: cbd365e5-b982-4309-a58b-317b9f6f873e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant