Skip to content

test: file — File.status() git changed file detection#689

Open
anandgupta42 wants to merge 1 commit intomainfrom
test/hourly-20260410-1928
Open

test: file — File.status() git changed file detection#689
anandgupta42 wants to merge 1 commit intomainfrom
test/hourly-20260410-1928

Conversation

@anandgupta42
Copy link
Copy Markdown
Contributor

@anandgupta42 anandgupta42 commented Apr 10, 2026

Summary

File.status()src/file/index.ts:421-502 (6 new tests)

File.status() powers the TUI changed-file indicator that shows users which files have been modified, added, or deleted in their working tree. It parses git diff --numstat HEAD output, detects untracked files via git ls-files --others, and identifies deleted files via git diff --diff-filter=D. Despite being a core user-facing function, it had zero direct test coverage — only a single indirect call buried in fsmonitor.test.ts.

New coverage includes:

  • Modified file detection: verifies correct added/removed line count parsing from git diff --numstat output
  • Untracked (new) file detection: verifies status is "added" and line count matches content.split("\n").length
  • Deleted file detection: verifies the --diff-filter=D code path correctly identifies removed files
  • Clean working tree: verifies empty array is returned when no changes exist
  • Binary file handling: verifies that "-" in numstat output (binary diffs) is correctly parsed as 0 for both added and removed — this is a real edge case where parseInt("-", 10) would return NaN without the explicit check
  • Path normalization: verifies all returned paths are relative to the project directory, not absolute

Why this matters

If File.status() breaks, the TUI shows incorrect changed-file data — users see wrong file counts, miss deleted files, or get NaN for binary modifications. The binary-dash parsing and deleted-file detection paths are especially fragile since they rely on specific git output formatting.

Type of change

  • New feature (non-breaking change which adds functionality)

Issue for this PR

N/A — proactive test coverage via test-discovery

How did you verify your code works?

bun test test/file/status.test.ts       # 6 pass, 0 fail (746ms)

Marker guard check also passes:

bun run script/upstream/analyze.ts --markers --base main --strict
# ok — All custom code in upstream-shared files is properly marked

Checklist

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

https://claude.ai/code/session_01P7m7yBWTz8L7Qz17mK9GPP


Summary by cubic

Add 6 tests for File.status() to ensure reliable git changed-file detection and accurate TUI indicators. Covers modified numstat parsing, untracked additions, deletions, binary “-” counts parsed as 0, clean tree returning an empty list, and project-relative paths.

Written for commit dab9700. Summary will update on new commits.

Summary by CodeRabbit

  • Tests
    • Added comprehensive test suite for file status detection, including validation of modified, untracked, deleted, and binary files within git repositories, ensuring accurate line counts and normalized file path handling.

File.status() powers the TUI changed-file indicator and had zero direct test
coverage. New tests cover modified/untracked/deleted file detection, binary
diff parsing (dash line counts), and path normalization.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

https://claude.ai/code/session_01P7m7yBWTz8L7Qz17mK9GPP
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 repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 10, 2026

📝 Walkthrough

Walkthrough

A new test suite is added for File.status() that validates detection of modified, untracked, and deleted files in git working trees. The tests also verify handling of binary files and path normalization using temporary git repositories and git --numstat output.

Changes

Cohort / File(s) Summary
File Status Tests
packages/opencode/test/file/status.test.ts
New test suite with multiple scenarios validating File.status() behavior: detection of modified files with accurate line counts, untracked files reported as added, deleted files marked as deleted, clean working trees returning empty results, binary file handling with line counts as -, and relative path normalization.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Files have status, now we test with care,
Git states and changes floating everywhere!
Modified, deleted, untracked—all aligned,
Binary mysteries gracefully designed. ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is comprehensive but fails to include the required 'PINEAPPLE' marker specified in the template for AI-generated contributions, though it does include other required sections and detailed explanations. Add 'PINEAPPLE' at the very top of the PR description as required by the repository template for AI-generated contributions.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding tests for File.status() git changed file detection, which is the primary focus of this PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/hourly-20260410-1928

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.

Copy link
Copy Markdown

@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.

🧹 Nitpick comments (1)
packages/opencode/test/file/status.test.ts (1)

106-119: Tighten the path-normalization assertion to avoid false positives.

!path.isAbsolute(file.path) is good, but values like ../outside.ts would still pass. Consider asserting the expected relative path (or at least rejecting .. prefixes) for stronger safety.

Suggested assertion tightening
   test("normalizes paths to be relative", async () => {
@@
       fn: async () => {
         const changed = await File.status()
+        expect(changed.some((f) => f.path === "src/app.ts")).toBe(true)
         for (const file of changed) {
           // All paths should be relative, not absolute
           expect(path.isAbsolute(file.path)).toBe(false)
+          expect(file.path.startsWith("..")).toBe(false)
         }
       },
     })
   })
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/opencode/test/file/status.test.ts` around lines 106 - 119, The test
"normalizes paths to be relative" currently only asserts
!path.isAbsolute(file.path), which still allows paths like "../outside.ts";
update the assertion inside the Instance.provide callback for File.status so
each file.path is not absolute and does not contain or start with parent-dir
segments—e.g., assert !path.isAbsolute(file.path) AND that file.path does not
start with ".." (or contain ".." + path.sep) or, even better, compare to the
expected relative path "src/app.ts" for the created file to ensure strict
normalization; modify the check near File.status() handling in the test to
reject any ".." prefixes or mismatched expected relative path.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/opencode/test/file/status.test.ts`:
- Around line 106-119: The test "normalizes paths to be relative" currently only
asserts !path.isAbsolute(file.path), which still allows paths like
"../outside.ts"; update the assertion inside the Instance.provide callback for
File.status so each file.path is not absolute and does not contain or start with
parent-dir segments—e.g., assert !path.isAbsolute(file.path) AND that file.path
does not start with ".." (or contain ".." + path.sep) or, even better, compare
to the expected relative path "src/app.ts" for the created file to ensure strict
normalization; modify the check near File.status() handling in the test to
reject any ".." prefixes or mismatched expected relative path.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3b07b692-a8b7-48d3-a4f2-440ead98e0b9

📥 Commits

Reviewing files that changed from the base of the PR and between f030bf8 and dab9700.

📒 Files selected for processing (1)
  • packages/opencode/test/file/status.test.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants