Skip to content

fix: recover branch-compare, dogfood fixes, foundation reframe#170

Merged
carlos-alm merged 7 commits intomainfrom
fix/dogfood-missing-branch-compare
Feb 28, 2026
Merged

fix: recover branch-compare, dogfood fixes, foundation reframe#170
carlos-alm merged 7 commits intomainfrom
fix/dogfood-missing-branch-compare

Conversation

@carlos-alm
Copy link
Contributor

Summary

  • Recover branch-compare.js — restores the lost implementation from a previous worktree, with full integration tests
  • Dogfood fixes — correct stale benchmark data from v2.4.0 native binary, add native binary version check to dogfood skill
  • CLI cleanup — remove dangling branch-compare references, add registry prune --dry-run, add index.js export test
  • Foundation reframe — Principle 5 updated from "library-first" to "CLI-first" identity, reflecting how codegraph is actually used

Test plan

  • npm test passes (new tests: branch-compare.test.js, index-exports.test.js, registry.test.js)
  • node src/cli.js branch-compare runs without errors
  • node src/cli.js registry prune --dry-run lists entries without deleting

The branch-compare command was registered in cli.js and its exports
added to index.js, but the implementation file src/branch-compare.js
was never created. This caused two issues:

1. `codegraph branch-compare` crashed with ERR_MODULE_NOT_FOUND
2. `import('@optave/codegraph')` crashed entirely because index.js
   has a top-level re-export from the missing file, making the
   programmatic API completely unusable

Remove the dead references until an implementation exists.

Closes #166
The branch-compare command was registered in cli.js and index.js but
src/branch-compare.js was never committed — it was lost as untracked
files in the fix/complexity-sql-sanitize worktree. Recovered the full
implementation (568 lines) and integration test (192 lines, 7 tests)
from git object 22c8185.

This restores the cli.js command and index.js exports that were removed
in 746aa65, now that the implementation file exists. Updated the dogfood
report to reflect the recovery (no bugs found, rating 8.5/10).

Closes #166

Impact: 13 functions changed, 4 affected
…nary

The dogfood report showed native complexity at 270.9ms (2.2x slower than
WASM) because the benchmark ran with a stale v2.4.0 native binary that
lacked Rust-side complexity computation, forcing a WASM fallback. With
the correct v2.5.0 binary, native complexity is 5.1ms (47x faster than
WASM's 240.7ms) and overall build is 241ms vs 1,009ms (4.2x faster).

Replaced all phase-level benchmark numbers with the official v2.5.0
data from BUILD-BENCHMARKS.md.
The v2.5.0 dogfood report contained incorrect benchmark data because
the benchmarks ran with a stale v2.4.0 native binary. The complexity
phase silently fell back to WASM, making native appear 2.2x slower
than WASM when it's actually 47x faster.

Add a pre-flight verification step to Phase 4b that checks the native
binary version matches the release being tested, and a sanity-check
that flags native complexityMs > WASM complexityMs as a stale binary.
…une --dry-run

- Restore src/branch-compare.js from git history — was referenced by
  both index.js and cli.js but missing from the tree, breaking
  `import('./src/index.js')`.
- Add tests/unit/index-exports.test.js that validates all re-exports
  in index.js resolve without ERR_MODULE_NOT_FOUND.
- Add --dry-run flag to `registry prune` so users can preview what
  would be removed without actually deleting entries (especially
  useful with aggressive --ttl 0).
- Add dryRun parameter to pruneRegistry() with two new tests.

Impact: 14 functions changed, 5 affected
The "embeddable first, CLI second" framing didn't match how codegraph
is actually used. The CLI and MCP server are the primary interfaces;
the programmatic API is an additional capability, not the core identity.
@claude
Copy link

claude bot commented Feb 28, 2026

Claude finished @carlos-alm's task —— View job


PR Review Analysis

Reviewing PR #170: "fix: recover branch-compare, dogfood fixes, foundation reframe"

Todo List

  • Phase 1: Root cause analysis - understand what problem this PR solves
  • Phase 2: Configuration change detection - check for high-risk changes
  • Phase 3: Test integrity verification - ensure tests are robust
  • Phase 4: Code quality assessment - review implementation details
  • Final Assessment: Provide rating and recommendation

Root Cause Analysis

Problem Being Solved: This PR addresses four legitimate issues:

  1. Lost branch-compare.js - Core functionality was missing due to worktree cleanup
  2. Stale dogfood benchmark data - Version mismatch corrupting performance data
  3. CLI cleanup - Dead code removal and missing --dry-run functionality
  4. Foundation documentation - Aligning Principle 5 with actual usage patterns

Why This Approach: All changes are justified fixes for real issues, not symptom suppression.

Risk Assessment: LOW - No configuration relaxations, robust testing, secure implementation.

Critical Concerns

None identified. This is a well-executed recovery and cleanup PR.

Code Quality Assessment ⭐⭐⭐⭐

Security Analysis ✅ SECURE

  • Command Injection Protection: Uses execFileSync with array arguments (never shell strings)
  • Git Ref Validation: Validates refs through git rev-parse --verify before use
  • Temp Directory Handling: Proper cleanup with fs.rmSync in finally blocks
  • Path Traversal Protection: Uses path.join() for all path operations

Implementation Quality ✅ EXCELLENT

branch-compare.js (568 lines):

  • Clean Architecture: Well-separated concerns (git ops, symbol loading, comparison)
  • Robust Error Handling: Proper try/catch with fallback cleanup
  • Memory Efficient: Closes DB connections, cleans temp directories
  • No Code Smells: No TODOs, FIXMEs, or technical debt markers

Test Coverage ✅ COMPREHENSIVE

  • Integration tests: Real git repos, actual worktree operations
  • Edge cases: Invalid refs, non-git directories, empty diffs
  • Output formats: Text, JSON, Mermaid validation
  • Dry run testing: Thorough validation of new functionality

Performance Considerations ✅ GOOD

  • Uses git worktrees (efficient) vs full clones
  • Incremental graph building with skipRegistry: true
  • DB queries use prepared statements
  • Proper resource cleanup prevents leaks

Minor Observations

  1. Long function branchCompareData (130 lines) - but well-structured
  2. Magic numbers - 60s test timeouts reasonable for git ops
  3. Error handling - Graceful degradation in cleanup fallbacks

Final Recommendation

  • Rating: ⭐⭐⭐⭐☆ (4/5)
  • Action: APPROVE
  • Reasoning: High-quality implementation that properly recovers lost functionality. Excellent test coverage, secure coding practices, and addresses real problems. The code follows codegraph's architectural patterns and maintains consistency with the existing codebase.

Why not 5 stars? Minor complexity in the main function, but this doesn't impact functionality or maintainability significantly.

This PR demonstrates solid engineering practices and should be merged.


@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 28, 2026

Greptile Summary

This PR successfully recovers the lost branch-compare implementation and adds infrastructure improvements.

Key changes:

  • branch-compare.js recovery — 568-line implementation restored from a lost worktree stash, providing structural diff between git refs with symbol-level comparison and transitive caller impact analysis
  • Registry dry-run mode — added --dry-run flag to registry prune command to preview what would be pruned without actually removing entries
  • Export guard test — new test validates all index.js re-exports resolve, preventing module-not-found errors at runtime
  • Documentation updates — dogfood skill now includes native binary version check pre-flight, FOUNDATION.md reframes Principle 5 to reflect CLI-first identity
  • Corrected benchmarks — v2.5.0 dogfood report includes accurate performance data after fixing stale native binary issue

All changes are well-tested with 7 new integration tests for branch-compare, 2 new unit tests for registry dry-run, and 1 export validation test. The recovered implementation integrates cleanly with existing CLI commands and programmatic API.

Confidence Score: 5/5

  • This PR is safe to merge with no concerns — all changes are well-tested, follow project conventions, and restore lost functionality
  • High confidence due to comprehensive test coverage (10 new tests across 3 test files), clean code recovery from version control, straightforward feature additions with proper error handling, and documentation updates that accurately reflect the changes
  • No files require special attention

Important Files Changed

Filename Overview
src/branch-compare.js Recovered 568-line implementation of branch structural diff with git worktree management, symbol comparison, and transitive impact analysis
src/cli.js Added --dry-run flag to registry prune command with conditional output messaging
src/registry.js Implemented dry-run logic in pruneRegistry - identifies stale entries without removing them when dryRun=true
tests/integration/branch-compare.test.js Added 192-line integration test suite for branch-compare with git repo setup, symbol diff validation, and Mermaid output tests
tests/unit/index-exports.test.js Added guard test to validate all index.js re-exports resolve without module-not-found errors
tests/unit/registry.test.js Added two test cases for --dry-run functionality - verifies entries are identified but not removed from registry

Last reviewed commit: c50f7f5

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

9 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@carlos-alm carlos-alm merged commit 3d1224d into main Feb 28, 2026
17 checks passed
@carlos-alm carlos-alm deleted the fix/dogfood-missing-branch-compare branch February 28, 2026 08:31
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