Skip to content

Tree diff tests#218

Draft
cravishe wants to merge 2 commits into
masc-ucsc:mainfrom
cravishe:tree-diff-tests
Draft

Tree diff tests#218
cravishe wants to merge 2 commits into
masc-ucsc:mainfrom
cravishe:tree-diff-tests

Conversation

@cravishe
Copy link
Copy Markdown
Contributor

@cravishe cravishe commented May 20, 2026

Summary

Adds a googletest-based test suite for hhds_tree_diff, verifying dump file loading, type table construction, and tree edit distance computation on LNAST-style dump files.

Files Added

  • hhds/tests/hhds_tree_diff_test.cpp — test suite with 8 test cases
  • hhds/BUILD.bazel — added cc_test target for hhds_tree_diff_test

Test Cases

Test What it verifies
IdenticalTrees Same dump file → distance 0
SwappedDeclarations Swapping const x/const y order → distance 6
SingleInsertion Adding one assign subtree → distance 3
SymmetricDistance dist(A,B) == dist(B,A)
SelfDistance dist(A,A) == 0
MissingFile Nonexistent file → null tree
TypeTableCorrectness Type names extracted in expected order
NodeCount add_trivial dump produces exactly 33 nodes

Test Output

bazel test //hhds:hhds_tree_diff_test
//hhds:hhds_tree_diff_test    PASSED in 0.1s

Summary by CodeRabbit

  • Tests

    • Added comprehensive test suite for tree edit distance validation, covering identical dumps, swapped declarations, tree insertions, distance symmetry, and type-table correctness.
  • Refactor

    • Consolidated dump-loading logic for improved data processing and extended tree printing to display node attributes alongside existing tree information.

Review Change Stack

Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 20, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 82563924-e7bd-412c-8c29-d9da70b24161

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR refactors the dump-loading pipeline in hhds_tree_diff.cpp, consolidates data structures, extends print_tree to handle node attributes, and introduces a comprehensive test suite validating tree edit distance computation with fixture-based dump files and custom cost functions.

Changes

Tree Edit Distance Testing and Dump Refactoring

Layer / File(s) Summary
DumpData structure and consolidated dump loading
hhds/hhds_tree_diff.cpp
Introduces DumpData struct with move-only semantics consolidating type tables, node text mappings, and label extraction; refactors load_dump to parse types from file, read tree via hhds::Tree::read_dump, extract node texts and full labels by re-reading the dump, and reset tree on label-count mismatch.
Extended print_tree with node attributes
hhds/hhds_tree_diff.cpp
Extends print_tree to discover attribute keys across nodes and wire PrintOptions::attributes with optional-return callbacks keyed by node debug id.
Tree edit distance test suite
hhds/tests/hhds_tree_diff_test.cpp
Adds test helpers to create temp dump files, parse type names and full labels from dump lines, load dumps with tree structures and label mappings, and compute edit distance via custom cost functions; includes fixtures and test cases validating identical trees (distance 0), swapped declarations (distance 6), subtree insertion (distance 3), symmetry, self-distance, missing file handling, type table order, and node count.
Build configuration
hhds/BUILD.bazel
Registers cc_test target hhds_tree_diff_test depending on :core, :tree_edit_distance, and @googletest//:gtest_main.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • masc-ucsc/hhds#214: Introduces the original hhds_tree_diff tool with dump-parsing and label-aware edit-distance behavior that this PR refactors and extends with comprehensive test coverage.

Suggested reviewers

  • renau

Poem

🐰 A rabbit's song on tests so fine,
Dump files dance in perfect line,
Attributes bloom, distances align,
Edit paths through trees—oh how they shine!
With fixtures firm and helpers true,
The diff is clear, the tests are new! 🌳✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Tree diff tests' clearly and concisely describes the main change: adding a comprehensive test suite for the tree diff functionality.
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.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@cravishe cravishe marked this pull request as draft May 20, 2026 04:16
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 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 `@hhds/tests/hhds_tree_diff_test.cpp`:
- Around line 313-316: The test TEST(TreeDiff, MissingFile) currently uses a
hardcoded path which can be flaky; change it to generate a unique non-existent
path at runtime (e.g., build a temp filename with a random/UUID suffix or use
mkstemp to create-and-unlink a file name) and pass that to load_test_dump so the
path is guaranteed absent; update the test to obtain the path before calling
load_test_dump and assert EXPECT_EQ(d.tree, nullptr) as before, referencing the
TEST(TreeDiff, MissingFile) block, the load_test_dump call and the d.tree check.
- Around line 13-18: The helper write_temp_dump currently creates a
deterministic /tmp filename and only EXPECTs that the ofstream opened, which can
collide in concurrent tests and return a path even on failure; change
write_temp_dump to create a unique temp file (use mkstemp or std::filesystem
temp_directory_path + a unique suffix/UUID) so concurrent runs don't collide,
open the file via the file descriptor/unique name, check success and fail fast
on error (use ASSERT_TRUE or throw std::runtime_error) instead of EXPECT_TRUE,
write the content, flush/close the stream, and then return the unique path;
refer to write_temp_dump to find where to replace the filename generation,
open/check logic, and return behavior.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: eccebae5-410a-496a-80e7-6202d1b3bb09

📥 Commits

Reviewing files that changed from the base of the PR and between 66198bc and f9c76d4.

📒 Files selected for processing (3)
  • hhds/BUILD.bazel
  • hhds/hhds_tree_diff.cpp
  • hhds/tests/hhds_tree_diff_test.cpp

Comment thread hhds/tests/hhds_tree_diff_test.cpp Outdated
Comment thread hhds/tests/hhds_tree_diff_test.cpp
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