Skip to content

test: add comprehensive ListFilesTool test suite (40 tests)#213

Open
proyectoauraorg wants to merge 2 commits into
Zoo-Code-Org:mainfrom
proyectoauraorg:test/add-list-files-tool-tests
Open

test: add comprehensive ListFilesTool test suite (40 tests)#213
proyectoauraorg wants to merge 2 commits into
Zoo-Code-Org:mainfrom
proyectoauraorg:test/add-list-files-tool-tests

Conversation

@proyectoauraorg
Copy link
Copy Markdown
Contributor

@proyectoauraorg proyectoauraorg commented May 20, 2026

Description

This PR adds a comprehensive test suite for ListFilesTool with 40 test cases covering all critical code paths of the tool.

Closes #206

Test Coverage

Parameter Validation (5 tests)

  • Missing/empty path parameter detection
  • Consecutive mistake tracking (track_missing_file_errors vs track_consecutive_mistakes)
  • Proper error message format with <hint> tags

Happy Path - Non-Recursive (7 tests)

  • Basic file listing in a directory
  • Files with proper indentation markers (├── / └──)
  • Sorted output
  • Skips list_files tool-specific approval files
  • No approval flow for regular listings

Happy Path - Recursive (4 tests)

  • Recursive listing with nested directories
  • Deep nesting indentation
  • Default recursive behavior (recursive defaults to true)
  • Skips files matching rooIgnoreController patterns

Provider State (3 tests)

  • showRooIgnoredFiles flag shows normally ignored files
  • rooIgnoreController respected when not overridden
  • rooProtectedController removes protected files from output

Approval Flow (6 tests)

  • RequestApproval called with proper tool_name
  • User approval returns tool results
  • User rejection returns appropriate message
  • Approval triggers for large file counts
  • No approval for small file listings
  • No approval when approval_setting is "always"

Path Handling (6 tests)

  • Relative path resolution
  • Paths outside workspace detection
  • Root path display as "."
  • Readable path formatting (removes trailing slashes)
  • readDirectory mock called with correct arguments

handlePartial (4 tests)

  • Returns partial messages correctly
  • Recursive=true adds directory/* suffix
  • Recursive=false adds / suffix
  • Errors throw without affecting state

Edge Cases (5 tests)

  • Empty directories return no-file marker
  • Large file lists generate approval message
  • Singleton export validation
  • Tool description and schema validation
  • Combined recursive + rooIgnoreController

Tests Results

✓ ListFilesTool > 40 tests ✓
Test Suites: 1 passed
Tests:       40 passed
Duration:    ~3s

Checklist

  • Tests follow existing test patterns (same as AskFollowupQuestionTool, SwitchModeTool)
  • All mocks properly configured with type safety
  • No changes to source code, only test file added
  • check-types passes successfully
  • Tests execute and pass locally
  • Cross-platform path handling (no hardcoded paths)

Summary by CodeRabbit

  • Tests

    • Added comprehensive test coverage for the file-listing tool: parameter validation, recursive vs non-recursive behavior, path resolution (including outside-workspace detection), approval gating, error handling, streamed/partial message handling, and export sanity.
  • Note

    • No user-facing changes in this release.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 20, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5706d502-1457-4900-82ce-ffbc7663886a

📥 Commits

Reviewing files that changed from the base of the PR and between 90d2ad37da811718ae72abb935b1be73c5680494 and c7c5888.

📒 Files selected for processing (1)
  • src/core/tools/__tests__/listFilesTool.spec.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/core/tools/tests/listFilesTool.spec.ts

📝 Walkthrough

Walkthrough

Adds a comprehensive Vitest test suite for ListFilesTool that mocks dependencies and validates execution, approval gating, path resolution, partial/stream handling, error cases, edge cases, and the module's singleton export.

Changes

ListFilesTool Test Suite

Layer / File(s) Summary
Setup, param validation, and core listing
src/core/tools/__tests__/listFilesTool.spec.ts
Sets up Vitest mocks (glob, path, formatter), shared fixtures, and helper builders; validates missing-parameter errors, non-recursive/recursive listing, default recursive=false, formatter invocation, didHitLimit propagation, and provider showRooIgnoredFiles handling.
Approval gating, path resolution, and message structure
src/core/tools/__tests__/listFilesTool.spec.ts
Tests askApproval gating (push only on approval), relative path resolution against task.cwd, isOutsideWorkspace propagation, ignore/protected controller forwarding, getReadablePath usage, and exact JSON payload structure for top-level vs recursive requests.
handlePartial (streamed/partial usage)
src/core/tools/__tests__/listFilesTool.spec.ts
Validates handlePartial: parsing recursive from strings, defaulting/undefined paths to task.cwd, propagating isOutsideWorkspace and readable path, ensuring partial content is empty, and different error propagation for pre-ask vs ask rejections.
Error handling, edge cases, and exports
src/core/tools/__tests__/listFilesTool.spec.ts
Asserts handleError on listFiles or formatFilesList failures and consecutive-mistake-count behavior; covers empty file lists, truncation/limit behavior, root and dot-path handling; verifies exported singleton listFilesTool instance and name.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • taltas
  • navedmerchant
  • hannesrudolph
  • edelauna
  • JamesRobert20

Poem

🐰 Tests hop in with mock and cheer,
Paths resolved both far and near,
Partials whisper, approvals wait,
Errors handled, edge cases slate,
A bunny checks the list — all clear! 🥕

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR adds tests for ListFilesTool but does not implement the actual integration-test Turbo lane split or move existing tests, which are the core objectives of issue #206. Either implement the integration-test lane separation and test reorganization outlined in #206, or clarify that this PR is preparatory work for a separate task.
Out of Scope Changes check ⚠️ Warning The PR adds a new test file for ListFilesTool, which is not mentioned in issue #206's scope (worktree/Git and custom-tools/esbuild tests). Ensure the added test aligns with the integration-test lane objectives or confirm it should be part of the fast unit-test lane instead.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: adding a comprehensive test suite with 40 tests for ListFilesTool.
Description check ✅ Passed The description is comprehensive, covering test organization, coverage areas, results, and checklist completion following the template structure.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

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

Warning

Review ran into problems

🔥 Problems

Stopped waiting for pipeline failures after 30000ms. One of your pipelines takes longer than our 30000ms fetch window to run, so review may not consider pipeline-failure results for inline comments if any failures occurred after the fetch window. Increase the timeout if you want to wait longer or run a @coderabbit review after the pipeline has finished.


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
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: 1

🤖 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 `@src/core/tools/__tests__/listFilesTool.spec.ts`:
- Around line 385-395: The test claims "should not reset consecutive mistake
count on error" but never asserts the counter; update the test for the
tool.execute error path to explicitly assert that
mockTask.consecutiveMistakeCount remains unchanged (e.g., still 2) after the
mocked listFiles rejection; locate the test using
mockTask.consecutiveMistakeCount, vi.mocked(listFiles).mockRejectedValue,
tool.execute(params, mockTask, mockCallbacks) and mockCallbacks.handleError and
add an assertion that mockTask.consecutiveMistakeCount equals the original
value.
🪄 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 Plus

Run ID: 49e701af-160b-4450-bdaf-2d7ad74ba50e

📥 Commits

Reviewing files that changed from the base of the PR and between f25b102 and 90d2ad3.

📒 Files selected for processing (1)
  • src/core/tools/__tests__/listFilesTool.spec.ts

Comment on lines +385 to +395
it("should not reset consecutive mistake count on error", async () => {
mockTask.consecutiveMistakeCount = 2
vi.mocked(listFiles).mockRejectedValue(new Error("fail"))
const params = { path: "src", recursive: false }

await tool.execute(params, mockTask, mockCallbacks)

// The mistake count should NOT be reset since the error path doesn't reset it
// Note: it may be reset before the error occurs since the validation passed
expect(mockCallbacks.handleError).toHaveBeenCalled()
})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Assert the stated behavior for consecutiveMistakeCount

Line 385 says this test verifies no reset on error, but Lines 392-395 never assert the counter value. This test currently passes even if reset behavior regresses.

✅ Proposed fix
 	it("should not reset consecutive mistake count on error", async () => {
 		mockTask.consecutiveMistakeCount = 2
 		vi.mocked(listFiles).mockRejectedValue(new Error("fail"))
 		const params = { path: "src", recursive: false }

 		await tool.execute(params, mockTask, mockCallbacks)

-		// The mistake count should NOT be reset since the error path doesn't reset it
-		// Note: it may be reset before the error occurs since the validation passed
 		expect(mockCallbacks.handleError).toHaveBeenCalled()
+		expect(mockTask.consecutiveMistakeCount).toBe(2)
 	})
🤖 Prompt for 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.

In `@src/core/tools/__tests__/listFilesTool.spec.ts` around lines 385 - 395, The
test claims "should not reset consecutive mistake count on error" but never
asserts the counter; update the test for the tool.execute error path to
explicitly assert that mockTask.consecutiveMistakeCount remains unchanged (e.g.,
still 2) after the mocked listFiles rejection; locate the test using
mockTask.consecutiveMistakeCount, vi.mocked(listFiles).mockRejectedValue,
tool.execute(params, mockTask, mockCallbacks) and mockCallbacks.handleError and
add an assertion that mockTask.consecutiveMistakeCount equals the original
value.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@proyectoauraorg proyectoauraorg force-pushed the test/add-list-files-tool-tests branch from 90d2ad3 to 2ccef1b Compare May 20, 2026 17:29
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.

♻️ Duplicate comments (1)
src/core/tools/__tests__/listFilesTool.spec.ts (1)

397-407: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Assert the stated behavior for consecutiveMistakeCount

The test name claims to verify that the consecutive mistake count is NOT reset on error, but the test never asserts the counter value. Compare with Line 179, which explicitly asserts consecutiveMistakeCount equals 0 on success. This test should similarly assert that the count remains 2 after the error.

✅ Proposed fix
 	it("should not reset consecutive mistake count on error", async () => {
 		mockTask.consecutiveMistakeCount = 2
 		vi.mocked(listFiles).mockRejectedValue(new Error("fail"))
 		const params = { path: "src", recursive: false }

 		await tool.execute(params, mockTask, mockCallbacks)

-		// The mistake count should NOT be reset since the error path doesn't reset it
-		// Note: it may be reset before the error occurs since the validation passed
 		expect(mockCallbacks.handleError).toHaveBeenCalled()
+		expect(mockTask.consecutiveMistakeCount).toBe(2)
 	})
🤖 Prompt for 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.

In `@src/core/tools/__tests__/listFilesTool.spec.ts` around lines 397 - 407, The
test titled "should not reset consecutive mistake count on error" never asserts
the counter value; update the test for mockTask.consecutiveMistakeCount (set to
2 before calling tool.execute which mocks listFiles to reject) to assert it
remains 2 after execution (and after expecting mockCallbacks.handleError).
Specifically, in the test that calls tool.execute(params, mockTask,
mockCallbacks) with vi.mocked(listFiles).mockRejectedValue(new Error("fail")),
add an assertion like expect(mockTask.consecutiveMistakeCount).toBe(2) after the
existing expect(mockCallbacks.handleError).toHaveBeenCalled() so the test
verifies the counter was not reset on error.
🤖 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.

Duplicate comments:
In `@src/core/tools/__tests__/listFilesTool.spec.ts`:
- Around line 397-407: The test titled "should not reset consecutive mistake
count on error" never asserts the counter value; update the test for
mockTask.consecutiveMistakeCount (set to 2 before calling tool.execute which
mocks listFiles to reject) to assert it remains 2 after execution (and after
expecting mockCallbacks.handleError). Specifically, in the test that calls
tool.execute(params, mockTask, mockCallbacks) with
vi.mocked(listFiles).mockRejectedValue(new Error("fail")), add an assertion like
expect(mockTask.consecutiveMistakeCount).toBe(2) after the existing
expect(mockCallbacks.handleError).toHaveBeenCalled() so the test verifies the
counter was not reset on error.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6ebc2dc4-39e8-42dd-869b-1aefc30a70b3

📥 Commits

Reviewing files that changed from the base of the PR and between 90d2ad3 and 2ccef1b.

📒 Files selected for processing (1)
  • src/core/tools/__tests__/listFilesTool.spec.ts

Add full test coverage for ListFilesTool including:
- Parameter validation (missing path)
- Basic and recursive file listing
- Approval flow and user cancellation
- Relative and absolute path resolution
- Error handling (nonexistent dirs, permission denied)
- Partial message streaming (handlePartial)
- Edge cases (empty dirs, large file sets, root/dot paths)
- Singleton instance verification
- RooIgnore/RooProtected controller passthrough

Fixes cross-platform compatibility for Windows CI by using
path.resolve() instead of hardcoded Unix paths, and removing
the unnecessary path module mock that caused failures on Windows.

Closes Zoo-Code-Org#209
@proyectoauraorg proyectoauraorg force-pushed the test/add-list-files-tool-tests branch from 2ccef1b to 833b22f Compare May 20, 2026 18:52
…rror path

Addresses CodeRabbit review: the 'no reset on error' test never asserted the
counter, so it would pass even if the reset behavior regressed. Renamed to
reflect actual behavior (validation success resets to 0 before listFiles
throws) and added the missing assertion. 40 tests pass.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@proyectoauraorg
Copy link
Copy Markdown
Contributor Author

Good catch @coderabbitai — the test asserted nothing about the counter. Fixed: it now asserts `consecutiveMistakeCount === 0` and the name/comment reflect the real behavior (validation success resets the count to 0 before `listFiles` throws; the catch path leaves it untouched).

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 21, 2026

Tip

For best results, initiate chat on the files or code changes.

@proyectoauraorg: Thanks for the update! The fix sounds spot-on — asserting consecutiveMistakeCount === 0 correctly captures that the validation-success path resets the counter before listFiles throws, while the catch path leaves it unchanged. The updated test name and comment make the intent much clearer. 🎉

(´。• ᵕ •。`) ♡


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

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.

[ENHANCEMENT] Add packages/core integration-test Turbo lane for process-boundary suites

1 participant