Skip to content

test: util — findUp, globUp traversal and overlaps boundary#414

Closed
anandgupta42 wants to merge 1 commit intomainfrom
test/hourly-20260323-2208
Closed

test: util — findUp, globUp traversal and overlaps boundary#414
anandgupta42 wants to merge 1 commit intomainfrom
test/hourly-20260323-2208

Conversation

@anandgupta42
Copy link
Contributor

@anandgupta42 anandgupta42 commented Mar 23, 2026

What does this PR do?

1. Filesystem.findUp() and Filesystem.globUp()src/util/filesystem.ts (9 new tests)

These functions power instruction file discovery (AGENTS.md, CLAUDE.md, CONTEXT.md) by walking directories upward from a starting point. Zero direct tests existed — they were only indirectly exercised through mocked filesystem calls in instruction.test.ts. If these functions fail silently or stop early, users in nested project directories lose all project-level context from the agent.

New coverage includes:

  • File found at start directory
  • Files found at multiple levels walking upward (ordering correctness)
  • Stop directory is inclusive (file at stop level IS found — verifies the break placement)
  • Returns empty when no matches exist anywhere in the traversal
  • Does not traverse past the stop directory (prevents loading instructions from parent projects)
  • globUp with wildcard patterns matching multiple files at one level
  • globUp with no matches
  • globUp respects stop boundary

2. Filesystem.overlaps()src/util/filesystem.ts (7 new tests)

This function determines whether two directory paths share files (one contains the other). It's used in project detection to determine project boundaries. The implementation uses a non-obvious || chain on path.relative() results that could easily regress. Zero direct tests existed.

New coverage includes:

  • Same path overlaps with itself
  • Parent/child paths overlap (both directions)
  • Sibling directories do NOT overlap
  • Unrelated paths do NOT overlap
  • String-prefix-but-not-ancestor edge case (/foo/bar vs /foo/barbaz — the classic path containment bug)
  • Trailing slash does not affect result
  • Root path overlaps with everything

Type of change

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

Issue for this PR

N/A — proactive test coverage from test-discovery skill

How did you verify your code works?

bun test test/util/filesystem.test.ts    # 71 pass (55 existing + 16 new)

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_01Hfr4bad38JKSQzQejhHzjC

Summary by CodeRabbit

  • Tests
    • Enhanced test coverage for internal filesystem utility functions, including upward directory traversal, glob pattern matching, and path overlap validation.

Note: This release includes internal testing improvements with no user-facing changes.

…ndary

findUp/globUp power instruction file discovery (AGENTS.md, CLAUDE.md).
If they fail silently or stop early, users in nested project dirs lose
all project context. overlaps() governs project boundary detection;
incorrect results could cause cross-project context bleeding.

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

https://claude.ai/code/session_01Hfr4bad38JKSQzQejhHzjC
Copy link

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

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

@coderabbitai
Copy link

coderabbitai bot commented Mar 23, 2026

📝 Walkthrough

Walkthrough

Test coverage expanded for filesystem utilities with comprehensive validation blocks for findUp() and globUp() methods testing upward directory traversal with stop boundaries, pattern matching, and edge cases. Additional overlap detection test cases added covering self-overlap, ancestor/descendant relationships, and slash normalization.

Changes

Cohort / File(s) Summary
Filesystem Utility Tests
packages/opencode/test/util/filesystem.test.ts
Added comprehensive test coverage for findUp() validating upward traversal with stop directory bounds, globUp() testing glob pattern matching during traversal, and expanded overlaps() tests covering edge cases like self-overlap, ancestor/descendant relationships, sibling paths, and slash normalization.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 With tests so thorough, bound and free,
Our filesystem climbs each family tree,
From globUp to findUp, we cover the way,
Traversing upward, come what may!
Happy hops for this test display!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: adding test coverage for three utility functions (findUp, globUp, overlaps) with focus on traversal and boundary behavior.
Description check ✅ Passed The description includes all required template sections with comprehensive detail: What changed and why (detailed explanation of each test block), Test Plan (verification command showing 71 pass), and Checklist (both items checked).
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-20260323-2208

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

@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/util/filesystem.test.ts (1)

632-637: Assert explicit ordering in the multi-level globUp() test.

The test comment states child-level results should come first, but current assertions only check membership. Since this fixture has one match per level, asserting exact order will better lock traversal-order behavior.

Suggested test tightening
       const results = await Filesystem.globUp("*.md", child, tmp.path)
-      // Child level first, then root level
-      expect(results.length).toBe(2)
-      expect(results).toContain(path.join(child, "readme.md"))
-      expect(results).toContain(path.join(tmp.path, "notes.md"))
+      // Child level first, then root level
+      expect(results).toEqual([
+        path.join(child, "readme.md"),
+        path.join(tmp.path, "notes.md"),
+      ])
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/opencode/test/util/filesystem.test.ts` around lines 632 - 637, The
test for Filesystem.globUp currently only checks membership but claims
child-level results should come first; update the assertions to assert exact
ordering by replacing the two .toContain checks and length check with a single
equality assertion that results strictly equals [path.join(child, "readme.md"),
path.join(tmp.path, "notes.md")] (or the reverse if traversal differs) so the
test locks the expected traversal order from Filesystem.globUp.
🤖 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/util/filesystem.test.ts`:
- Around line 632-637: The test for Filesystem.globUp currently only checks
membership but claims child-level results should come first; update the
assertions to assert exact ordering by replacing the two .toContain checks and
length check with a single equality assertion that results strictly equals
[path.join(child, "readme.md"), path.join(tmp.path, "notes.md")] (or the reverse
if traversal differs) so the test locks the expected traversal order from
Filesystem.globUp.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5e64bcf3-e63d-4ef9-ae8f-dab2f72c295c

📥 Commits

Reviewing files that changed from the base of the PR and between 4c01aac and b2b51eb.

📒 Files selected for processing (1)
  • packages/opencode/test/util/filesystem.test.ts

@anandgupta42
Copy link
Contributor Author

Superseded by #439 which consolidates all 12 test PRs into one, deduplicates overlapping tests, and fixes bugs found during review.

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