Skip to content

Filter cosmetic orphan changes from semantic diff#294

Closed
Iron-Ham wants to merge 1 commit into
Ataraxy-Labs:mainfrom
Iron-Ham:Iron-Ham/fix-no-cosmetics-comments
Closed

Filter cosmetic orphan changes from semantic diff#294
Iron-Ham wants to merge 1 commit into
Ataraxy-Labs:mainfrom
Iron-Ham:Iron-Ham/fix-no-cosmetics-comments

Conversation

@Iron-Ham
Copy link
Copy Markdown
Contributor

@Iron-Ham Iron-Ham commented Jun 1, 2026

Summary

  • classify orphan changes with parser structural hashes so comment-only orphan edits are cosmetic
  • keep real orphan code changes visible under --no-cosmetics and preserve their summary buckets
  • treat shebang edits as structural executable metadata

Fixes #272

Test plan

  • cargo test --workspace
  • dummy Git repos covering comment-only edits, added comments, added imports, modified imports, and shebang edits
  • independent subagent review completed; actionable findings fixed
  • claude -p reviewer launched twice; final embedded-diff run exited successfully but produced no review text

Copy link
Copy Markdown

@inspect-review inspect-review Bot left a comment

Choose a reason for hiding this comment

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

inspect review

Triage: 38 entities analyzed | 0 critical, 0 high, 17 medium, 21 low
Verdict: standard_review

Findings (6)

  1. [low] In recalculate_diff_summary, orphan changes are now double-counted in change-type buckets. When entity_type == "orphan", the code increments orphan_count but no longer returns early, so it falls through to the match statement and increments the change-type bucket again (e.g., added_count). This means orphans contribute to both orphan_count AND their respective change-type count, which breaks the invariant that orphan_count should be a subset cross-cutting metric.
  2. [low] In recalculate_diff_summary, the logic for Moved/Renamed/Reordered changes double-counts modifications. When a change is Moved/Renamed/Reordered AND has content changes, it increments both the move/rename/reorder count AND modified_count. However, if the change is also an orphan, it will be triple-counted (orphan_count + move/rename/reorder count + modified_count), leading to incorrect summary totals.
  3. [low] In retain_non_cosmetic_changes, the filter logic is inverted for compound changes. The code retains changes where structural_change != Some(false) OR the change is Moved/Renamed/Reordered. This means a cosmetic (structural_change == Some(false)) Moved/Renamed/Reordered change will be retained, which contradicts the intent to drop purely cosmetic changes.
  4. [low] In test no_cosmetics_filter_recomputes_summary_from_remaining_changes, the expected modified_count changed from 1 to 2, but the test setup only has one Modified change (the structural one). The orphan has ChangeType::Modified but should not be counted separately in modified_count if the old behavior was correct, suggesting the new counting logic is wrong or the test expectation is incorrect.
  5. [low] In recalculate_diff_summary, the test orphan_changes_count_toward_change_type_buckets expects orphans to count toward change-type buckets (asserts added_count == 1 and deleted_count == 2 with 1 orphan added and 2 entities deleted). However, the comment in the AFTER code says 'orphan_count is cross-cutting metadata, while retained orphans still contribute to change-type buckets', which contradicts the BEFORE comment that said 'Orphans only skip the entity change-type buckets'. The removal of the continue statement changes the behavior to make orphans count in both places, but this appears to be inconsistent with the original design where orphans were separate.
  6. [low] In retain_non_cosmetic_changes, the filter logic now allows cosmetic changes (where structural_change == Some(false)) to be retained if they are Moved, Renamed, or Reordered. However, in recalculate_diff_summary, these cosmetic compound changes will increment both their primary bucket (moved_count, renamed_count, reordered_count) AND modified_count if has_content_change() returns true. This creates a logical inconsistency: a cosmetic change (structural_change=false) should not have a content change, but the code will still check and potentially double-count it.

Reviewed by inspect | Entity-level triage found 0 high-risk changes

@Iron-Ham Iron-Ham marked this pull request as ready for review June 1, 2026 23:59
@Iron-Ham
Copy link
Copy Markdown
Contributor Author

Iron-Ham commented Jun 2, 2026

Superseded by #311.

@Iron-Ham Iron-Ham closed this Jun 2, 2026
rs545837 pushed a commit that referenced this pull request Jun 4, 2026
## Summary
- consolidate binary file diff reporting, diff output escaping, and
cosmetic orphan filtering into one branch
- keep diff formatter, JSON, CLI, and MCP reporting behavior aligned
across the related changes

Supersedes #237, #290, #294.
Closes #181.
Closes #273.
Fixes #272.

## Test plan
- cargo test --manifest-path crates/Cargo.toml -p sem-cli --test
diff_file_compare
- cargo test --manifest-path crates/Cargo.toml -p sem-cli --test
diff_patch
- cargo test --manifest-path crates/Cargo.toml -p sem-cli --test
diff_output_hardening
- cargo test --manifest-path crates/Cargo.toml -p sem-cli --test
diff_no_cosmetics
- cargo test --manifest-path crates/Cargo.toml -p sem-cli
commands::diff::tests
- cargo test --manifest-path crates/Cargo.toml -p sem-core
parser::differ::tests
- cargo check --manifest-path crates/Cargo.toml -p sem-core -p sem-cli
-p sem-mcp
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.

sem diff --no-cosmetics does not hide comment-only changes, despite its help text

1 participant