Skip to content

test: add focused coverage for review metrics#133

Merged
benvinegar merged 1 commit intomainfrom
pi/todo-3f7f302b-tests
Mar 30, 2026
Merged

test: add focused coverage for review metrics#133
benvinegar merged 1 commit intomainfrom
pi/todo-3f7f302b-tests

Conversation

@benvinegar
Copy link
Copy Markdown
Member

Summary

  • add dedicated regression coverage for measureDiffSectionMetrics() including notes, wrapping, empty files, and header-only hunks
  • add focused computeHunkRevealScrollTop() tests for fitting, oversized, clamped, and zero-viewport cases
  • add loader ordering tests around agent narrative order, stable fallback order, and renamed files via previousPath

Testing

  • bun run typecheck
  • bun test

This PR description was generated by Pi using OpenAI GPT-5

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Mar 30, 2026

Greptile Summary

This PR adds focused regression coverage for three distinct subsystems — measureDiffSectionMetrics, computeHunkRevealScrollTop, and orderDiffFiles — alongside a new shared test/fixtures/diff-helpers.ts module and a single export keyword added to orderDiffFiles to make it importable from tests.

Key changes:

  • src/core/loaders.ts: orderDiffFiles is exported (no logic changes)
  • test/fixtures/diff-helpers.ts: New shared helpers createDiffFile, createHeaderOnlyDiffFile, and lines used across all three new test suites
  • test/hunk-scroll.test.ts: Five cases covering fitting, preferred-padding, oversized, clamped-negative, and zero-viewport behaviors of computeHunkRevealScrollTop
  • test/loaders-ordering.test.ts: Four cases covering agent-narrative ordering, stable fallback order for unranked files, null/empty context passthrough, and previousPath rename matching
  • test/section-heights.test.ts: Five cases covering split vs. stack layout sizing, inline-note height without moving hunk anchors, line-wrapping, empty-file placeholder, and header-only hunks

Findings:

  • The stats field in createDiffFile is hardcoded to { additions: 1, deletions: 1 } regardless of actual fixture content, which could mislead future authors writing stats-sensitive tests
  • In the "no visible hunks" test in section-heights.test.ts, the precondition assertion (file.metadata.hunks.toHaveLength(0)) is placed after the call under test rather than before it, making the test premise slightly harder to read at a glance

Confidence Score: 5/5

Safe to merge — test-only changes with a minimal, non-breaking export addition in production code.

All findings are P2 style suggestions. The single production-code change (adding export to orderDiffFiles) is trivially safe. Test logic was manually verified against the implementations of computeHunkRevealScrollTop, measureDiffSectionMetrics, and orderDiffFiles and all assertions are correct.

test/fixtures/diff-helpers.ts — hardcoded stats values may mislead future test authors

Important Files Changed

Filename Overview
src/core/loaders.ts Minimal change: adds export keyword to orderDiffFiles so the loader-ordering tests can import it directly. No logic changes.
test/fixtures/diff-helpers.ts New shared test fixture file. createDiffFile is well-structured and covers all DiffFile fields including optional previousPath. Minor issue: stats is hardcoded to { additions: 1, deletions: 1 } for every file regardless of actual content, which could mislead future callers.
test/hunk-scroll.test.ts New focused tests for computeHunkRevealScrollTop covering fitting, preferred-padding, oversized, negative-clamp, and zero-viewport cases. All assertions verified correct against the implementation.
test/loaders-ordering.test.ts New ordering tests covering agent narrative order, stable fallback order, null/empty context, and previousPath rename matching. Logic verified against orderDiffFiles implementation.
test/section-heights.test.ts New section-metrics tests covering split/stack layouts, inline notes, line-wrapping, empty files, and header-only hunks. Minor: precondition assertion in the "empty file" case appears after the call under test rather than before it.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[test/fixtures/diff-helpers.ts] -->|createDiffFile / createHeaderOnlyDiffFile| B[test/section-heights.test.ts]
    A -->|createDiffFile| C[test/loaders-ordering.test.ts]

    B -->|import| D[measureDiffSectionMetrics\nsrc/ui/lib/sectionHeights.ts]
    C -->|import| E[orderDiffFiles\nsrc/core/loaders.ts]
    F[test/hunk-scroll.test.ts] -->|import| G[computeHunkRevealScrollTop\nsrc/ui/lib/hunkScroll.ts]

    E -.->|export added| H[src/core/loaders.ts]
Loading

Reviews (1): Last reviewed commit: "test: add focused coverage for review me..." | Re-trigger Greptile

patch: "",
path,
previousPath,
stats: { additions: 1, deletions: 1 },
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Hardcoded stats don't reflect actual content

The default before/after pair changes two lines (alpha 1→10 and gamma 3→30), so the real stats are { additions: 2, deletions: 2 }. Hardcoding { additions: 1, deletions: 1 } for all fixture files regardless of content could mislead future test authors who reach for createDiffFile in a test that does assert on stats.

Consider computing stats from the diff metadata, or at least accepting them as an override parameter:

stats: { additions: metadata.hunks.reduce((s, h) => s + h.additionLines, 0), deletions: metadata.hunks.reduce((s, h) => s + h.deletionLines, 0) },

Comment on lines +88 to +93
test("returns a one-row placeholder for files with no visible hunks", () => {
const file = createDiffFile({
after: "const stable = true;\n",
before: "const stable = true;\n",
id: "empty",
path: "empty.ts",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Precondition assertion placed after the call under test

expect(file.metadata.hunks).toHaveLength(0) is a setup invariant that documents why the branch under test is taken — it reads more clearly before the measureDiffSectionMetrics call. As written, a reader has to work backwards to understand the test's premise.

Suggested change
test("returns a one-row placeholder for files with no visible hunks", () => {
const file = createDiffFile({
after: "const stable = true;\n",
before: "const stable = true;\n",
id: "empty",
path: "empty.ts",
expect(file.metadata.hunks).toHaveLength(0);
const metrics = measureDiffSectionMetrics(file, "split", true, theme);
expect(metrics.bodyHeight).toBe(1);
expect(metrics.hunkBounds.size).toBe(0);
expect(metrics.rowMetrics).toEqual([]);

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@benvinegar benvinegar merged commit 4cbfb83 into main Mar 30, 2026
3 checks passed
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