Skip to content

test(admin-cli): enumerate health-report template behavior#3966

Open
chet wants to merge 1 commit into
NVIDIA:mainfrom
chet:gh-issue-3964
Open

test(admin-cli): enumerate health-report template behavior#3966
chet wants to merge 1 commit into
NVIDIA:mainfrom
chet:gh-issue-3964

Conversation

@chet

@chet chet commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Health-report template tests covered only five of the eleven constructor variants and repeated partial message and classification assertions across nine standalone tests. The six remaining match arms and the separate empty-template constructor had no direct coverage.

This replaces those overlapping tests with one labeled check_values table that projects every stable report field. The table owns all eleven HealthReportTemplates variants, while one focused structural test owns get_empty_template.

Related issues

Supports #3964.

Type of Change

  • Add - New feature or capability
  • Change - Changes in existing functionality
  • Fix - Bug fixes
  • Remove - Removed features or deprecated functionality
  • Internal - Internal changes (refactoring, tests, docs, etc.)

Breaking Changes

  • This PR contains breaking changes

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • No testing required (docs, internal refactor, etc.)

Additional Notes

Coverage was measured from the same base at original, conversion-only, and expanded checkpoints:

  • Constructor production coverage stayed at 66/121 lines and 73/135 regions through conversion, then reached 121/121 lines and 135/135 regions.
  • The target file moved from 213/305 lines to 205/300 after the inline tests were consolidated, then to 376/413. Its uncovered count fell from 92 to 37.
  • Package coverage moved from 2,707/27,495 lines (9.85%) to 2,870/27,603 (10.40%), with 55 fewer uncovered lines.

The raw test count moved from 400 to 392 at the conversion checkpoint because nine overlapping tests became one table, then to 393 when the empty-template contract was added.

Validation:

  • cargo +1.96.0 test --locked -p nico-admin-cli --bin nico-admin-cli machine::health_report::cmd::tests
  • Full nico-admin-cli coverage run: 393 tests passed
  • cargo make format-nightly
  • cargo make clippy
  • cargo make carbide-lints
  • Local CodeRabbit review: no findings
  • Local Claude review: no required changes

@chet
chet requested a review from a team as a code owner July 23, 2026 09:01
@chet

chet commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full_review, thanks!

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

@chet, I’ll perform a complete re-review of #3966, including the updated test structure and its coverage of all health-report template variants.

🐇🔍

✅ Action performed

Full review finished.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 749eedb1-a133-4110-a482-7a5da8087703

📥 Commits

Reviewing files that changed from the base of the PR and between 2de970b and e622bbe.

📒 Files selected for processing (1)
  • crates/admin-cli/src/machine/health_report/cmd.rs

Summary by CodeRabbit

  • Tests
    • Refactored health report test coverage into a table-driven suite spanning multiple report template variants.
    • Added consistent output normalization/projection so comparisons remain stable across templates.
    • Updated the empty-template test to validate the normalized default success/alert and classification expectations.
    • Added an assertion that all template variants are covered by the test table.

Walkthrough

Health report template tests were consolidated into deterministic projected assertions. A table-driven test now covers every HealthReportTemplates variant, while empty-template validation uses the same projection model.

Changes

Health report test refactor

Layer / File(s) Summary
Reusable report projection helpers
crates/admin-cli/src/machine/health_report/cmd.rs
Adds test-only projection and expected-value helpers for comparing report sources, alerts, success fields, timestamps, and classifications.
Table-driven template validation
crates/admin-cli/src/machine/health_report/cmd.rs
Consolidates template tests into coverage-checked check_values scenarios and updates empty-template assertions to use the projection representation.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related issues

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% 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 accurately reflects the test-focused change and the new exhaustive health-report template coverage.
Description check ✅ Passed The description is directly about the test consolidation and coverage expansion in the health-report template code.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
crates/admin-cli/src/machine/health_report/cmd.rs (1)

282-306: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Positional string parameters in expected_report are a misuse footgun.

source, alert_id, target, and message are all string-shaped positional parameters with no type distinction, so a future accidental swap (e.g., of target and message) at one of the 10 call sites in the next test will compile silently and only surface as a same-shaped assertion mismatch. As per coding guidelines, designs should be "hard to misuse," and struct literals are preferred for plain data. Consider a small named-field struct or builder for the expected values instead of five positional args.

♻️ Example refactor using a named-field struct
-    fn expected_report(
-        source: &str,
-        alert_id: &str,
-        target: Option<&str>,
-        message: &str,
-        classifications: &[&str],
-    ) -> ReportProjection {
+    struct ExpectedAlert<'a> {
+        source: &'a str,
+        alert_id: &'a str,
+        target: Option<&'a str>,
+        message: &'a str,
+        classifications: &'a [&'a str],
+    }
+
+    fn expected_report(expected: ExpectedAlert) -> ReportProjection {
         ReportProjection {
-            source: source.to_string(),
+            source: expected.source.to_string(),
             triggered_by: None,
             observed_at_present: true,
             successes: vec![],
             alerts: vec![AlertProjection {
-                id: alert_id.to_string(),
-                target: target.map(str::to_string),
+                id: expected.alert_id.to_string(),
+                target: expected.target.map(str::to_string),
                 in_alert_since_present: false,
-                message: message.to_string(),
+                message: expected.message.to_string(),
                 tenant_message: None,
-                classifications: classifications
+                classifications: expected
+                    .classifications
                     .iter()
                     .map(|classification| (*classification).to_string())
                     .collect(),
             }],
         }
     }
🤖 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 `@crates/admin-cli/src/machine/health_report/cmd.rs` around lines 282 - 306,
Refactor the test helper expected_report to accept a named-field input struct or
equivalent builder instead of positional source, alert_id, target, message, and
classifications arguments. Update all expected_report call sites to use the
named fields, preserving the resulting ReportProjection values and existing
assertion behavior.

Source: Coding guidelines

🤖 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 `@crates/admin-cli/src/machine/health_report/cmd.rs`:
- Around line 282-306: Refactor the test helper expected_report to accept a
named-field input struct or equivalent builder instead of positional source,
alert_id, target, message, and classifications arguments. Update all
expected_report call sites to use the named fields, preserving the resulting
ReportProjection values and existing assertion behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 67ce0a06-6e08-4a47-a649-aebb9a0d8a3c

📥 Commits

Reviewing files that changed from the base of the PR and between 2de970b and af69b50.

📒 Files selected for processing (1)
  • crates/admin-cli/src/machine/health_report/cmd.rs

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
crates/admin-cli/src/machine/health_report/cmd.rs (1)

318-490: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider deriving the cases from the enum. This test hand-lists every HealthReportTemplates variant; if the enum is expected to grow, drive the scenarios from a single source of truth (for example EnumIter or a small exhaustive helper match) so new variants cannot be added without updating coverage.

🤖 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 `@crates/admin-cli/src/machine/health_report/cmd.rs` around lines 318 - 490,
The health_report_templates test manually duplicates every HealthReportTemplates
variant, allowing new variants to miss coverage. Replace the hand-built cases
with enum-derived iteration or an exhaustive helper match, while retaining each
variant’s existing expected report data and ensuring adding a new enum variant
requires updating the test’s single source of truth.
🤖 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 `@crates/admin-cli/src/machine/health_report/cmd.rs`:
- Around line 318-490: The health_report_templates test manually duplicates
every HealthReportTemplates variant, allowing new variants to miss coverage.
Replace the hand-built cases with enum-derived iteration or an exhaustive helper
match, while retaining each variant’s existing expected report data and ensuring
adding a new enum variant requires updating the test’s single source of truth.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 9b5a6a8f-de6c-4700-9a1b-cd69b9ca6794

📥 Commits

Reviewing files that changed from the base of the PR and between 2de970b and af69b50.

📒 Files selected for processing (1)
  • crates/admin-cli/src/machine/health_report/cmd.rs

Replace nine overlapping template tests with one labeled table that compares every stable report field.

Cover all eleven template variants and keep the empty report constructor as a separate structural contract.

Record conversion parity before taking both constructors to full line and region coverage.

This supports NVIDIA#3964

Signed-off-by: Chet Nichols III <chetn@nvidia.com>
@chet

chet commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the review feedback in e622bbe: expected report fields are named, the table is checked against every derived ValueEnum variant with readable failures, and the projections destructure each source struct so new fields cannot be skipped silently. @coderabbitai full_review, thanks!

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

@chet, acknowledged. I’ll perform a complete re-review of #3966, with particular attention to the exhaustive variant coverage and projection safeguards introduced in e622bbe03.

🐇🔍

✅ Action performed

Full review finished.

@chet
chet enabled auto-merge (squash) July 23, 2026 14:28
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