Repository navigation
test(harness): Tier 2 Claude Code hook end-to-end bench (#29) - #70
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
~/.claudetempdir with a fixturesettings.jsonpointing at the contextcrawler hookgit status,git log -5,ls -la src/,head -50 src/main.rs,grep -r ...,find . -name '*.rs', etc.):contextcrawler hook claudewith a synthetic Claude Codetool_useenvelope on stdinbench/claude-code-<git-sha>.{json,md}(matches Tier 1's report shape)Measured savings on develop tip
Standouts:
ls -la src/87.5% savings,git status21–38% (varies with tree state).Design notes
RTK_DB_PATHto point tracking at a tempfile — user's realhistory.dbstays untouchedresolve_rtk_prefix()substitutes the test-binary path forrtkso the harness exercises THIS binary, not a globally-installed shim — closes the measurement-validity questioncases_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 thertkprefix 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 outputsrtk Xbut it's a no-op when bypassed).Closes #29 (Tier 2 only — Tier 3 = Codex still open).