Skip to content

Add 'metrics test' subcommand for testing metrics against simulation outputs#89

Merged
callumreid merged 3 commits into
mainfrom
feat/metrics-test-command
Jul 1, 2026
Merged

Add 'metrics test' subcommand for testing metrics against simulation outputs#89
callumreid merged 3 commits into
mainfrom
feat/metrics-test-command

Conversation

@callumreid

@callumreid callumreid commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Exposes the existing POST /v1/metrics/{metric_id}/test API endpoint in the CLI, allowing users to test metrics against simulation outputs from the command line.

Changes

  • src/commands/metrics.rs — Added Test(TestArgs) subcommand with --simulation-output-id (required) and --dev-id (optional) flags
  • src/client/mod.rs — Added test() method to MetricsClient that POSTs to /v1/metrics/{id}/test
  • src/client/models/metric.rs — Added TestMetricRequest and TestMetricResponse structs
  • src/agent_discovery.rs — Added "test" to the metrics command list for agent discovery
  • tests/cli_tests.rs — Added test_metrics_test_subcommand test

Usage

coval metrics test <metric_id> --simulation-output-id <sim_output_id>

Testing

All 91 tests pass, clippy is clean.

Summary by CodeRabbit

  • New Features

    • Added a new metrics test command in the CLI for testing metrics.
    • Introduced a new API action to trigger a metric test and return the resulting output ID.
    • Added support for an optional developer ID when running a metric test.
  • Bug Fixes

    • Updated metric discovery so the test command is recognized as a supported action.
  • Tests

    • Added CLI coverage for metric testing with and without the optional developer ID.

Greptile Summary

This PR exposes the POST /v1/metrics/{metric_id}/test API endpoint through a new metrics test subcommand, wiring up request/response models, client method, CLI command, and tests in a style consistent with the rest of the codebase.

  • New Test(TestArgs) subcommand added to MetricCommands with required --simulation-output-id and optional --dev-id flags; the handler builds a TestMetricRequest, calls the new MetricsClient::test method, and emits the response.
  • New TestMetricRequest / TestMetricResponse models added with correct Serialize/Deserialize derives; dev_id is conditionally omitted via skip_serializing_if = "Option::is_none".
  • Two integration tests cover both the without-dev_id and with-dev_id paths against a mock server returning a 202 response, confirming end-to-end serialization of both fields.

Confidence Score: 5/5

Safe to merge — the change is an additive, well-scoped feature that follows established patterns throughout the codebase without modifying any existing behaviour.

All five touched files make straightforward, additive changes: a new subcommand with three small fields, a single new client method, two new model structs with correct derive attributes, and two integration tests that verify both the happy path and the optional --dev-id flag end-to-end. The 202 Accepted response from the API is handled correctly by the shared is_success() check. No existing logic is altered.

No files require special attention.

Important Files Changed

Filename Overview
src/commands/metrics.rs Adds Test(TestArgs) subcommand and execute handler; consistent with existing patterns. TestArgs is correctly not boxed (small struct with 3 fields).
src/client/mod.rs Adds MetricsClient::test() method; uses the shared post() helper which correctly accepts any 2xx status (including 202 Accepted) via is_success().
src/client/models/metric.rs Adds TestMetricRequest (Serialize) and TestMetricResponse (Deserialize + Serialize); derives are correct — emit_one_with_actions only needs Serialize.
tests/cli_tests.rs Two new integration tests cover the without-dev_id and with-dev_id paths; body_partial_json assertions verify correct field serialization end-to-end.
src/agent_discovery.rs Adds 'test' to the metrics command list for agent discovery; straightforward one-line addition.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant User
    participant CLI as coval CLI
    participant Client as MetricsClient
    participant API as POST /v1/metrics/{id}/test

    User->>CLI: coval metrics test metric_id --simulation-output-id sim_output_id [--dev-id id]
    CLI->>CLI: Parse TestArgs, build TestMetricRequest
    CLI->>Client: "test(&metric_id, TestMetricRequest)"
    Client->>API: "POST /v1/metrics/{id}/test {simulation_output_id, dev_id?}"
    API-->>Client: "202 Accepted {metric_output_ulid}"
    Client-->>CLI: TestMetricResponse
    CLI->>User: emit_one_with_actions (metric_output_ulid + next actions)
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant User
    participant CLI as coval CLI
    participant Client as MetricsClient
    participant API as POST /v1/metrics/{id}/test

    User->>CLI: coval metrics test metric_id --simulation-output-id sim_output_id [--dev-id id]
    CLI->>CLI: Parse TestArgs, build TestMetricRequest
    CLI->>Client: "test(&metric_id, TestMetricRequest)"
    Client->>API: "POST /v1/metrics/{id}/test {simulation_output_id, dev_id?}"
    API-->>Client: "202 Accepted {metric_output_ulid}"
    Client-->>CLI: TestMetricResponse
    CLI->>User: emit_one_with_actions (metric_output_ulid + next actions)
Loading

Reviews (3): Last reviewed commit: "Fix review: next_actions point at metric..." | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a metrics test CLI subcommand that POSTs to /v1/metrics/{id}/test. New TestMetricRequest/TestMetricResponse models, a MetricsClient::test HTTP method, a MetricCommands::Test variant with TestArgs, agent discovery registration, and integration tests are included.

Changes

metrics test subcommand

Layer / File(s) Summary
Request/response models and HTTP client method
src/client/models/metric.rs, src/client/mod.rs
Adds TestMetricRequest (with simulation_output_id and optional dev_id) and TestMetricResponse (with metric_output_ulid), plus MetricsClient::test that POSTs to /v1/metrics/{id}/test.
CLI command definition and execution
src/commands/metrics.rs, src/agent_discovery.rs
Adds TestArgs struct, MetricCommands::Test variant, "test" operation mapping, and the execute() branch that constructs the request, calls the client, and emits results. Registers "test" in the metrics resource spec.
Integration tests
tests/cli_tests.rs
Two tests mock POST /v1/metrics/met_abc/test and assert CLI success and correct metric_output_ulid output, with and without --dev-id.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 A hop and a skip to /test we go,
Posting metrics with a JSON bow,
simulation_output_id in paw,
dev_id optional by law,
The rabbit tests metrics—hip hip hooray! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding a new metrics test subcommand for simulation-output testing.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/metrics-test-command

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

Comment thread src/commands/metrics.rs
Comment thread tests/cli_tests.rs

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tests/cli_tests.rs (1)

3048-3111: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add an agent-mode assertion for the new follow-up actions.

These tests only cover plain stdout. Because emit_one_with_actions() drops next_actions unless agent mode is enabled, a regression in the new next_actions::get("metrics", &args.metric_id) path would still pass here. Please add one --agent case that asserts the primary action targets metrics get met_abc.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/cli_tests.rs` around lines 3048 - 3111, Add an agent-mode coverage case
for metrics test so the new next_actions path is exercised. In
test_metrics_test_subcommand (and/or the dev-id variant), add a run with --agent
enabled and assert the emitted primary action points to metrics get met_abc,
since emit_one_with_actions() only preserves next_actions in agent mode. Use the
existing coval() CLI harness and the metrics::test flow to locate the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/cli_tests.rs`:
- Around line 3048-3111: Add an agent-mode coverage case for metrics test so the
new next_actions path is exercised. In test_metrics_test_subcommand (and/or the
dev-id variant), add a run with --agent enabled and assert the emitted primary
action points to metrics get met_abc, since emit_one_with_actions() only
preserves next_actions in agent mode. Use the existing coval() CLI harness and
the metrics::test flow to locate the change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 59bb52f4-2415-4098-bfc2-9f44a944b322

📥 Commits

Reviewing files that changed from the base of the PR and between 61d1d1d and ef48a93.

📒 Files selected for processing (5)
  • src/agent_discovery.rs
  • src/client/mod.rs
  • src/client/models/metric.rs
  • src/commands/metrics.rs
  • tests/cli_tests.rs

@callumreid callumreid merged commit 025e5c7 into main Jul 1, 2026
7 checks passed
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