Skip to content

Add compare install validity gate - #343

Merged
mohanagy merged 2 commits into
nextfrom
issue-341-compare-install-gate
May 26, 2026
Merged

mohanagy merged 2 commits into
nextfrom
issue-341-compare-install-gate

Conversation

@mohanagy

@mohanagy mohanagy commented May 26, 2026 •

Copy link
Copy Markdown
Owner

Closes #341

Summary

  • add native-agent compare install detection, --allow-no-install, and persisted validity/install reporting
  • skip bench:suite cells when the target repo is missing a verified Madar install and count them in suite summaries
  • add unit coverage plus a stored regression fixture for no-install vs with-install validity states

Test Plan

  • npm run typecheck
  • npm run build
  • CI=1 npm run test:run

Summary by CodeRabbit

  • New Features

    • New CLI flag: --allow-no-install to permit compares when native install isn't present.
    • Reports now include install verification, measurement validity (valid/degraded/invalid), and Madar MCP call counts.
  • Improvements

    • Benchmark suite skips cells when installs are missing and reports skipped counts.
    • Summaries and console output include install/validity details.
  • Tests

    • Added unit tests and fixtures covering install detection and report variations.

Review Change Stack

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented May 26, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 89388d02-3c93-4bc5-8815-c1408543413e

📥 Commits

Reviewing files that changed from the base of the PR and between 39f8ba8 and 918f38f.

📒 Files selected for processing (6)
  • src/cli/main.ts
  • src/cli/parser.ts
  • src/infrastructure/benchmark/suite.ts
  • tests/unit/benchmark-suite.test.ts
  • tests/unit/cli.test.ts
  • tests/unit/compare-install-regression-fixture.test.ts
🚧 Files skipped from review as they are similar to previous changes (6)
  • src/cli/main.ts
  • tests/unit/compare-install-regression-fixture.test.ts
  • tests/unit/benchmark-suite.test.ts
  • tests/unit/cli.test.ts
  • src/infrastructure/benchmark/suite.ts
  • src/cli/parser.ts

📝 Walkthrough

Walkthrough

This PR implements comprehensive install detection and measurement validity reporting for madar compare and madar bench:suite. It adds a pre-flight install verification gate, extends reports with install status and measurement validity fields, counts Madar MCP calls in trace analysis, and skips benchmark cells that lack proper Madar installation, with full test coverage and regression fixtures.

Changes

Madar install detection and measurement validity gates

Layer / File(s) Summary
CLI flag and error handling
src/cli/parser.ts, src/cli/main.ts
CompareCliOptions adds allowNoInstall: boolean. parseCompareArgs recognizes --allow-no-install and uses COMPARE_USAGE. CLI main wraps runCompareCommand to convert NativeAgentInstallRequiredError into UsageError.
Trace schema and MCP counting
src/infrastructure/compare.ts
CompareMadarTrace adds madar_mcp_call_count. analyzeMadarTraceExploration extended to compute and return madar_mcp_call_count across exploration branches.
Report schema and types
src/infrastructure/compare.ts
Adds NativeAgentMeasurementValidity type and augments GenerateCompareArtifactsInput with allowNoInstall. NativeAgentCompareReport adds install_verified, measurement_validity, and madar_mcp_call_count fields.
Install inspection helpers
src/infrastructure/compare.ts
Exports inspectClaudeNativeAgentInstall() to check .mcp.json, CLAUDE.md, and .claude/settings.json, and defines NativeAgentInstallRequiredError.
Native agent execution and finalization
src/infrastructure/compare.ts
executeNativeAgentCompare enforces the install gate (throws unless allowNoInstall), initializes install-derived report fields, updates from madar_trace, and finalizes measurement_validity as valid/degraded/invalid based on install and MCP call count.
Summary formatting
src/infrastructure/compare.ts
Adds helpers to render measurement_validity, install_verified, and madar_mcp_call_count lines and integrates them into runner-error, answer-only, and succeeded summary outputs.
Benchmark suite install gating and skipping
src/infrastructure/benchmark/suite.ts
Adds skipped status to BenchmarkSuiteSummaryCell, records per-repo skipped reasons during preparation via install inspection, emits skipped cells with reason during processing, and includes cells_skipped_for_install in the final JSON and markdown summary.
Test fixture configuration and regression fixtures
tests/unit/compare.test.ts, tests/unit/benchmark-suite.test.ts, tests/unit/compare-native-agent.test.ts, docs/benchmarks/regression/install-ab-govalidate-explain/*
Fixture writers now emit .mcp.json, CLAUDE.md, .claude/settings.json, and out/graph.json. Adds regression report fixtures for no-install and with-install arms capturing install/validity/MCP counts.
Unit tests and assertions
tests/unit/cli.test.ts, tests/unit/compare-native-agent.test.ts, tests/unit/benchmark-suite.test.ts, tests/unit/compare-install-regression-fixture.test.ts
Updates CLI tests for allowNoInstall, extends native-agent compare tests for abort/invalid/degraded/valid flows, adds benchmark-suite test for skipped cells, and adds regression fixture test asserting install_verified/measurement_validity/madar_mcp_call_count across arms.

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related issues

Possibly related PRs

  • mohanagy/madar#333 — Overlaps in native-agent trace parsing and report aggregation logic.
  • mohanagy/madar#321 — Related changes to CompareMadarTrace and exploration outcome classification.
  • mohanagy/madar#239 — Related updates to native-agent compare pipeline and summary formatting.

Poem

🐰 I hopped in code to check the land,

"Is Madar here?" I asked the sand.
If missing, I cry, "Please install!"
Or pass the flag to run through all.
Honest reports now bloom, not bland.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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 'Add compare install validity gate' clearly and concisely summarizes the main objective of the PR: adding install detection and validity gating to the compare command.
Description check ✅ Passed The PR description follows the template with a Summary section, Test Plan with checkmarks, and references the related issue #341. All key changes are explained and testing was performed.
Linked Issues check ✅ Passed The PR fully implements all acceptance criteria from issue #341: install detection with abort gate, --allow-no-install flag, measurement_validity reporting (valid/degraded/invalid), terminal output updates, bench:suite cell skipping, and comprehensive unit/regression test coverage.
Out of Scope Changes check ✅ Passed All changes are tightly scoped to the install validity gate objectives: CLI parsing updates, compare logic enhancements, benchmark suite modifications, fixture additions, and test coverage—no unrelated functionality or refactoring introduced.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 issue-341-compare-install-gate

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


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

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
src/cli/parser.ts (1)

1093-1100: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Update compare usage text to include --allow-no-install.

The parser accepts --allow-no-install, but the Usage: madar compare ... error text still omits it. That makes the new escape hatch hard to discover when users hit validation errors.

Also applies to: 1202-1202

🤖 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 `@src/cli/parser.ts` around lines 1093 - 1100, The compare command's usage
string in the error thrown by UsageError omits the new --allow-no-install flag;
update the two usage message literals surrounding the normalizedQuestion
validation (the UsageError thrown where normalizedQuestion.trim() is checked)
and the other occurrence near line ~1202 to include --allow-no-install so the
help text reflects the accepted flag.
src/cli/main.ts (1)

408-417: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Document --allow-no-install in compare help output.

formatHelp() lists compare flags but omits --allow-no-install, so users won’t see the intended override path from --help.

🤖 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 `@src/cli/main.ts` around lines 408 - 417, The compare command's help output
(built in formatHelp for the 'compare' command strings in src/cli/main.ts) is
missing the `--allow-no-install` flag; add an entry for `--allow-no-install` to
the same help lines array/strings where the other compare options are defined so
it appears in `--help` (match style/placement and a short description like
"allow running compare without installing dependencies"). Locate the block that
defines the compare usage/help lines (the strings including 'compare [question] 
run a real baseline vs madar prompt comparison' and its option lines) and insert
the new `--allow-no-install` flag line there so it shows up in the CLI help.
src/infrastructure/benchmark/suite.ts (1)

431-461: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

summary.md does not mark skipped cells per-row.

You’re collecting skipped state/reason, but the markdown table only prints metrics, so skipped cells are not explicitly labeled skipped (no install) in row output. This misses the stated per-cell reporting requirement.

Suggested direction
-      lines.push('| Repo | Baseline input tokens | Madar input tokens | SPI Madar input tokens | Baseline tool calls | Madar tool calls | SPI Madar tool calls | Baseline Read | Madar Read | SPI Madar Read | Baseline Glob/Grep | Madar Glob/Grep | SPI Madar Glob/Grep | Baseline wall-clock (ms) | Madar wall-clock (ms) | SPI Madar wall-clock (ms) | Baseline cost (USD) | Madar cost (USD) | SPI Madar cost (USD) |')
-      lines.push('| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |')
+      lines.push('| Repo | Status | Reason | Baseline input tokens | Madar input tokens | SPI Madar input tokens | Baseline tool calls | Madar tool calls | SPI Madar tool calls | Baseline Read | Madar Read | SPI Madar Read | Baseline Glob/Grep | Madar Glob/Grep | SPI Madar Glob/Grep | Baseline wall-clock (ms) | Madar wall-clock (ms) | SPI Madar wall-clock (ms) | Baseline cost (USD) | Madar cost (USD) | SPI Madar cost (USD) |')
+      lines.push('| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |')
 function formatCellRow(cell: BenchmarkSuiteSummaryCell): string {
+  const statusLabel = cell.status === 'skipped' ? 'skipped (no install)' : cell.status
+  const reason = cell.reason ?? '—'
   return [
     cell.repoId,
+    statusLabel,
+    reason,
     formatMetric(cell.baseline.input_tokens),
     ...
   ].join(' | ')
 }
🤖 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 `@src/infrastructure/benchmark/suite.ts` around lines 431 - 461, The markdown
table never marks per-row skipped cells; update
formatBenchmarkSuiteSummaryMarkdown (or its helper formatCellRow) to detect the
cell's skipped state/reason (e.g., cell.skipped, cell.skipped_for_install, or
cell.skippedReason) and emit a clear row indicating "skipped (no install)" (or
the captured reason) instead of metrics; implement this by short-circuiting when
a cell is skipped and returning a table row with the repo and a single explicit
"skipped (no install)" message (and empty/dash placeholders for the other metric
columns) so every skipped cell is labeled in the generated summary.
🧹 Nitpick comments (1)
tests/unit/compare-install-regression-fixture.test.ts (1)

21-29: 💤 Low value

Consider validating madar_mcp_call_count in assertions.

The test verifies install_verified and measurement_validity but not madar_mcp_call_count, which is part of the new report schema. Validating that the no-install fixture has madar_mcp_call_count: 0 and the with-install fixture has madar_mcp_call_count: 2 would strengthen the test.

🤖 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/unit/compare-install-regression-fixture.test.ts` around lines 21 - 29,
Add assertions to validate the new madar_mcp_call_count field on the report
fixtures: for noInstallReport and noInstallShareSafeReport assert
madar_mcp_call_count === 0, and for withInstallReport and
withInstallShareSafeReport assert madar_mcp_call_count === 2; update the test
block that currently checks install_verified and measurement_validity to include
these madar_mcp_call_count expects for all four report variables
(noInstallReport, withInstallReport, noInstallShareSafeReport,
withInstallShareSafeReport).
🤖 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.

Inline comments:
In `@tests/unit/benchmark-suite.test.ts`:
- Around line 500-596: The test "skips runnable cells when the repo has no
verified Madar install" is currently nested inside the mock callback
(executeNativeAgentCompare) and thus unreachable; move that entire it(...) block
out of the mock callback body so it lives at the top-level within the test suite
(same scope as other it blocks). Locate the mock function
executeNativeAgentCompare in this file and remove the nested it(...) from inside
it, then place the it(...) after the surrounding describe/it setup (so it calls
runBenchmarkSuite with the same mock overrides and assertions), keeping the same
variables names (generateCalls, compareCalls, runBenchmarkSuite, result, etc.)
so the assertions and mocks still reference the correct symbols. Ensure the mock
executeNativeAgentCompare only contains mock behavior/throws and does not
include any test registration code.

In `@tests/unit/compare-install-regression-fixture.test.ts`:
- Around line 14-31: The test compare install regression fixture currently only
asserts 'invalid' and 'valid' states; add coverage for the 'degraded' state by
reading the degraded fixture reports (use the same helper readFixtureReport) and
asserting install_verified is true and measurement_validity is 'degraded' for
both the normal and share-safe reports; update the test 'stores invalid vs valid
measurement validity across the no-install and with-install arms' or add a
separate it block that calls readFixtureReport('degraded' or a new fixture name
you create) for both 'report.json' and 'report.share-safe.json' and adds
expect(...install_verified).toBe(true) and
expect(...measurement_validity).toBe('degraded').

---

Outside diff comments:
In `@src/cli/main.ts`:
- Around line 408-417: The compare command's help output (built in formatHelp
for the 'compare' command strings in src/cli/main.ts) is missing the
`--allow-no-install` flag; add an entry for `--allow-no-install` to the same
help lines array/strings where the other compare options are defined so it
appears in `--help` (match style/placement and a short description like "allow
running compare without installing dependencies"). Locate the block that defines
the compare usage/help lines (the strings including 'compare [question]    run a
real baseline vs madar prompt comparison' and its option lines) and insert the
new `--allow-no-install` flag line there so it shows up in the CLI help.

In `@src/cli/parser.ts`:
- Around line 1093-1100: The compare command's usage string in the error thrown
by UsageError omits the new --allow-no-install flag; update the two usage
message literals surrounding the normalizedQuestion validation (the UsageError
thrown where normalizedQuestion.trim() is checked) and the other occurrence near
line ~1202 to include --allow-no-install so the help text reflects the accepted
flag.

In `@src/infrastructure/benchmark/suite.ts`:
- Around line 431-461: The markdown table never marks per-row skipped cells;
update formatBenchmarkSuiteSummaryMarkdown (or its helper formatCellRow) to
detect the cell's skipped state/reason (e.g., cell.skipped,
cell.skipped_for_install, or cell.skippedReason) and emit a clear row indicating
"skipped (no install)" (or the captured reason) instead of metrics; implement
this by short-circuiting when a cell is skipped and returning a table row with
the repo and a single explicit "skipped (no install)" message (and empty/dash
placeholders for the other metric columns) so every skipped cell is labeled in
the generated summary.

---

Nitpick comments:
In `@tests/unit/compare-install-regression-fixture.test.ts`:
- Around line 21-29: Add assertions to validate the new madar_mcp_call_count
field on the report fixtures: for noInstallReport and noInstallShareSafeReport
assert madar_mcp_call_count === 0, and for withInstallReport and
withInstallShareSafeReport assert madar_mcp_call_count === 2; update the test
block that currently checks install_verified and measurement_validity to include
these madar_mcp_call_count expects for all four report variables
(noInstallReport, withInstallReport, noInstallShareSafeReport,
withInstallShareSafeReport).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 2c655fa4-0dc6-417d-bef9-764f0856b87d

📥 Commits

Reviewing files that changed from the base of the PR and between 7e5f770 and 39f8ba8.

📒 Files selected for processing (13)
  • docs/benchmarks/regression/install-ab-govalidate-explain/no-install/report.json
  • docs/benchmarks/regression/install-ab-govalidate-explain/no-install/report.share-safe.json
  • docs/benchmarks/regression/install-ab-govalidate-explain/with-install/report.json
  • docs/benchmarks/regression/install-ab-govalidate-explain/with-install/report.share-safe.json
  • src/cli/main.ts
  • src/cli/parser.ts
  • src/infrastructure/benchmark/suite.ts
  • src/infrastructure/compare.ts
  • tests/unit/benchmark-suite.test.ts
  • tests/unit/cli.test.ts
  • tests/unit/compare-install-regression-fixture.test.ts
  • tests/unit/compare-native-agent.test.ts
  • tests/unit/compare.test.ts

Comment thread tests/unit/benchmark-suite.test.ts Resolved
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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