Skip to content

fix(shared): count Vitest type-test files as tests in diffs - #46808

Merged
juliusmarminge merged 1 commit into
pingdotgg:mainfrom
saphid:hunter/c-8baad25c87
Dec 1, 2026
Merged

juliusmarminge merged 1 commit into
pingdotgg:mainfrom
saphid:hunter/c-8baad25c87

Conversation

@saphid

@saphid saphid commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Problem

Vitest type-test files (*.test-d.ts, *.spec-d.ts) are classified as product code, so they stay visible under Hide Tests in the web working-tree/PR diff panels and the mobile PR diff, and their additions and deletions are counted as code in PR change breakdowns. TEST_NAME in packages/shared/src/changedFileKind.ts matches .test./.spec. but not Vitest's -d type-test suffix.

Deterministic repro on origin/main (3763606d20cd834ebfb419ef1525695b397af793): from packages/shared, import src/changedFileKind.ts and call isTestChangedFile on src/format.test-d.ts, src/format.spec-d.ts and src/format.d.ts, then summarizeChangedFiles([{ path: "src/format.test-d.ts", additions: 8, deletions: 2 }]). In the app, DiffPanel and the mobile PR diff filter call isTestChangedFile for every unselected file when Hide Tests is on, and the server PR change breakdown calls summarizeChangedFiles.

  • Observed: all three paths return false, and the breakdown puts +8/-2 in code with 0/0 in tests.
  • Expected: both type-test files are tests (+8/-2 in tests). The plain declaration file src/format.d.ts stays code.

Change

Recognize Vitest's *.test-d.* and *.spec-d.* names in the shared classifier, limited to the script extensions Vitest type-checks (.ts, .tsx, .js, .jsx, and their c/m variants). A plain .d.ts stays code and a document such as docs/api.spec-d.md stays docs. Every surface (web working-tree and PR diff filters, mobile PR diff filter, PR change breakdowns) uses this classifier, so this one change covers all of them.

Scope

Small fix for an obvious bug; no issue needed under CONTRIBUTING.md.

Verification

  • Added four cases to packages/shared/src/changedFileKind.test.ts: src/format.test-d.ts and src/format.spec-d.ts are tests, src/format.d.ts is code, and the Markdown control docs/api.spec-d.md is docs.
  • I ran the same final 36-case test file against both revisions. With the base implementation, 2 fail (src/format.test-d.ts and src/format.spec-d.ts: expected "tests", received "code") and 34 pass. On head 072dce92778, all 36 pass.
  • The before/after runtime transcript, both test runs, and the passing vp run check:changed summary for head 072dce92778 (format, lint, knip, typecheck, tests) are here: https://gist.github.com/saphid/4a5d75c3e9a16580c8f31ce65649c489

Not shown: I did not run an app scenario or capture before/after screenshots of the rendered Hide Tests toggle in web or mobile. The evidence covers the shared classifier those filters call, not the rendered interaction.

Authored by Claude Opus 5.5 (Model Hub); reviewed by GPT-6.2 Sol (Codex).

Not shown

  • apps/web/src/components/DiffPanel.tsx:795 — The classifier transcript does not show the rendered Hide Tests interaction. Capture before/after web working-tree and PR diffs and the mobile PR diff with an unselected type-test file.
  • apps/web/src/components/pullRequest/ChangeBreakdownGrid.tsx:27 — The transcript verifies bucket values, not their rendered presentation. If adding screenshots, show the same PR's line counts moving from Code to Tests.
  • docs/internals/15_testing.md:52 — The classifier probe is deterministic but not a scenarios:prove case. For automated app proof, seed a small diff containing a regular source file and a type-test file, turn on Hide Tests, and assert that only the source file remains visible.

@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:XS 0-9 changed lines (additions + deletions). labels Dec 1, 2026
@macroscopeapp

macroscopeapp Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at 23ad307

Macroscope's review found this PR approvable — Recognizes Vitest type-test filenames as tests in diff summaries and existing test-file filtering and folding. The change is limited to presentation and classification, with no change to product defaults or diagnostic suppression.

You can add or adjust custom eligibility rules. Learn more.

@coderabbitai

coderabbitai Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The test filename pattern now recognizes .test-d and .spec-d names with supported JavaScript and TypeScript extensions. New cases check how declaration test files and related declaration or documentation files are classified.

Changes: Changed file classification

Layer / File(s) Summary
Recognize declaration test filenames
packages/shared/src/changedFileKind.ts, packages/shared/src/changedFileKind.test.ts
TEST_NAME now matches .test-d and .spec-d filenames with supported extensions. Tests expect .test-d.ts and .spec-d.ts files to classify as tests, .d.ts files as code, and .spec-d.md files as docs.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested reviewers: iamshadmantaqi

Merge Risk: Minimal · up to 23ad3

Vitest type-test files such as *.test-d.ts are now classified as tests in diff filters and change breakdowns. Declaration files and docs keep their existing classification. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: Vitest type-test files (such as *.test-d.ts) are now counted as tests in diffs. The changeset matches this. The title uses a conventional commit prefix and a plain-lan…
Description check Passed The description follows the template's main sections: Problem, Change, Scope, and Verification. It gives a clear problem statement, a fix explanation, a scope note that no issue is needed for a small …
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.
Full details: Title check

Explanation

The title names the main change: Vitest type-test files (such as *.test-d.ts) are now counted as tests in diffs. The changeset matches this. The title uses a conventional commit prefix and a plain-language summary, so it passes.

Full details: Description check

Explanation

The description follows the template's main sections: Problem, Change, Scope, and Verification. It gives a clear problem statement, a fix explanation, a scope note that no issue is needed for a small obvious bug, and specific test evidence with before and after results. The Verification section notes what was not checked (app scenario and screenshots). The template asks for before/after screenshots for UI changes, and the author did not provide them. The Verification section also links to an external gist, which the template allows. The missing UI evidence is a gap, but the description is mostly complete, so the check passes.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 89ba000 and 23ad307.

Files selected for processing: 2

  • packages/shared/src/changedFileKind.test.ts
  • packages/shared/src/changedFileKind.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

@juliusmarminge juliusmarminge added the takeover:in-progress A takeover lead is working on this PR label Dec 1, 2026
@juliusmarminge

Copy link
Copy Markdown
Member

Evidence

Environment: real web dev app, Chromium, 1280×800, light theme, fresh isolated databases and identical synthetic repository on each side; Replay (dev), default model.

On both commits, created a fresh synthetic git project with committed format.ts, format.d.ts and README.md; modified the code (+1), declaration (+1/-1), and Markdown (+1), and added format.test-d.ts (+5), format.spec-d.ts (+6), and format.test.ts (+3), all under src outside test directories. Seeded a Replay thread, opened it, opened the right-panel working-tree Diff, verified all six files were listed with none selected, and enabled Hide test files. The ordinary test disappeared on both sides; both type tests stayed visible on base and disappeared on head. Code, declaration and Markdown controls remained visible.

Scenario: Hide Tests hides Vitest type tests outside test directories

Proven: the scenario fails on base 89ba000739 and passes on head 23ad3077a6.

Base 89ba000739 Head 23ad3077a6
Result ❌ failed
ASSERTION_FAILED: expect.not.toBeVisible failed
locator: getByRole("button", name: "Expand src/format.test-d.ts")
expected: not visible
observed: default states (match count 1)
✅ passed
all files Base 89ba000739: all files Head 23ad3077a6: all files
hide tests Base 89ba000739: hide tests Head 23ad3077a6: hide tests
failure Base 89ba000739: failure
Interaction recording Before After
Hide Tests Base recording Head recording

Scenario and seed script

Not shown:

  • PR change-breakdown Code/Tests/Docs additions and deletions were not exercised; this scenario uses a local working-tree diff rather than a real GitHub PR.
  • Mobile PR diff filtering and other Vitest type-test extension variants were not exercised; the real-app proof covers the reported .test-d.ts and .spec-d.ts web reproduction.

@juliusmarminge juliusmarminge added takeover:ready Takeover done; auto-lands when gates pass and removed takeover:in-progress A takeover lead is working on this PR labels Dec 1, 2026
@juliusmarminge
juliusmarminge merged commit 41a1079 into pingdotgg:main Dec 1, 2026
74 checks passed
@juliusmarminge juliusmarminge removed the takeover:ready Takeover done; auto-lands when gates pass label Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS 0-9 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants