Skip to content

test(harness): Tier 2 Claude Code hook end-to-end bench (#29) - #70

Merged
thehoff merged 2 commits into
developfrom
test/harness-tier2-claude-29
May 18, 2026
Merged

thehoff merged 2 commits into
developfrom
test/harness-tier2-claude-29

Conversation

@thehoff

@thehoff thehoff commented May 18, 2026

Copy link
Copy Markdown
Owner

Summary

Adds Tier 2 of the three-tier bench harness (#29) — Tier 1 (standalone, tests/harness_standalone.rs) shipped in PR #30; this PR adds the Claude Code hook end-to-end tier.

What it does

  • Stands up a synthetic ~/.claude tempdir with a fixture settings.json pointing at the contextcrawler hook
  • For each fixture command (8 representative shapes: git status, git log -5, ls -la src/, head -50 src/main.rs, grep -r ..., find . -name '*.rs', etc.):
    • Calls contextcrawler hook claude with a synthetic Claude Code tool_use envelope on stdin
    • Captures the rewritten command from the hook
    • Executes BOTH raw + rewritten and measures realised token savings
  • Aggregates into bench/claude-code-<git-sha>.{json,md} (matches Tier 1's report shape)

Measured savings on develop tip

case_count: 8
cases_rewritten: 7
total_raw_output_tokens: 1828
total_saved_tokens: 190
weighted_savings_pct: 10.4

Standouts: ls -la src/ 87.5% savings, git status 21–38% (varies with tree state).

Design notes

  • Uses RTK_DB_PATH to point tracking at a tempfile — user's real history.db stays untouched
  • resolve_rtk_prefix() substitutes the test-binary path for rtk so the harness exercises THIS binary, not a globally-installed shim — closes the measurement-validity question
  • Exit-127 cases (binary missing) are skipped to avoid phantom savings poisoning the aggregate
  • Test runtime: ~1.5s
  • Sanity-floor assertions only (cases_rewritten > 0, weighted_savings_pct >= 0.0) — catches dead-registry / aggregate regression, not subtle drift

.gitignore addition

Tier 2 reports excluded via bench/claude-code-*.{json,md} mirroring the existing Tier 1 exclusion. Otherwise every cargo-test run leaves untracked files.

Flagged for follow-up (NOT in this PR)

The harness shows 3 fixture commands (git log -5 --oneline, git diff HEAD~1 --stat, grep -rn) get the rtk prefix but produce identical output — those filters are either no-ops or already bypassed for short outputs. Real registry-optimisation opportunity, not a harness defect. Same root cause as #62 (rewrite_command outputs rtk X but it's a no-op when bypassed).

Closes #29 (Tier 2 only — Tier 3 = Codex still open).

thehoff added 2 commits May 19, 2026 00:00
Adds tests/harness_claude_code.rs, the second tier of the three-tier
bench harness from issue #29. Where Tier 1 (harness_standalone.rs)
drives the contextcrawler binary directly against fixture files, Tier
2 exercises the full Claude Code PreToolUse pipeline:

  1. Stand up a synthetic ~/.claude in a tempdir with a settings.json
     that wires `contextcrawler hook claude` as the PreToolUse handler.
     We do NOT touch the user's real ~/.claude.
  2. For each fixture command (tests/fixtures/bench_commands.txt),
     synthesize a Claude Code Bash tool_use envelope, pipe it through
     `contextcrawler hook claude`, and parse the rewritten command
     out of hookSpecificOutput.updatedInput.command.
  3. Execute BOTH the raw and rewritten commands against the working
     tree, count output tokens, record the realised end-to-end savings
     a Claude Code user would have seen.
  4. Write a per-git-sha report to bench/claude-code-<sha>.{json,md}
     in the same shape as Tier 1's results-<sha>.{json,md}.

Isolation matches Tier 1: RTK_DB_PATH points the tracking DB at a
tempfile so the real history.db is never touched, and
RTK_TELEMETRY_DISABLED=1 suppresses any telemetry pings.

Skip semantics: commands that exit 127 (binary not on this host) are
flagged skipped and excluded from the aggregate so a missing `htop`
can't poison the headline number. Binary-missing also skips the whole
test rather than panicking.

Sanity floors (not regression gates):
  - At least one fixture must be rewritten (catches a dead registry).
  - Aggregate savings must be >= 0% (catches the hook making things
    worse on average).

Per-case regression gates belong in a follow-up that diffs against a
checked-in bench/baseline-tier2.json.

Runtime measured at ~1.3s on M-series macOS dev box (well under the
60s budget). Idempotent in structure; raw token counts drift slightly
because the harness runs real `git status` against the live tree
(same pattern as Tier 1).

Report files: bench/claude-code-<sha>.{json,md} are NOT yet in
.gitignore. The strict file contract on this dispatch round forbids
modifying .gitignore, so a follow-up should extend the existing
`bench/results-*` pattern to cover `bench/claude-code-*`. Until then,
the files will appear as untracked after each test run.

Refs #29.

Generated with Claude Code (https://claude.com/claude-code)
…ss output)

Mirrors the existing bench/results-* exclusion. Per Agent C's report
for #29 — the harness runs every cargo test invocation and writes
git-sha-keyed reports under bench/, which would otherwise show as
untracked on every diff.
@thehoff
thehoff merged commit 942e5ef into develop May 18, 2026
@thehoff
thehoff deleted the test/harness-tier2-claude-29 branch May 18, 2026 14:01
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.

test(harness): three-tier bench harness — standalone binary + Claude Code + Codex (with isolated DBs/logs)

1 participant