Skip to content

Normalize relative working directories in glob searches - #1725

Open
VIOLETee0 wants to merge 3 commits into
CodebuffAI:mainfrom
VIOLETee0:fix/glob-relative-cwd
Open

VIOLETee0 wants to merge 3 commits into
CodebuffAI:mainfrom
VIOLETee0:fix/glob-relative-cwd

Conversation

@VIOLETee0

@VIOLETee0 VIOLETee0 commented Nov 25, 2026 •

Copy link
Copy Markdown

Problem / Why

Relative cwd spellings such as "." or "./src" do not match the project's normalized file paths, so glob can silently return no files that actually exist.

Changes

Normalize cwd once, convert native separators to "/", and treat "." as the project root. Apply this filter to the current listProjectFiles selection path, preserving upstream ripgrep enumeration, cancellation, result limits and partial-scan diagnostics. The branch incorporates main through fef9b86.

Verification

  • The existing real-filesystem cwd regression fails on current main and passes after the fix.
  • Related glob tests: 4 pass / 5 existing failures, compared with 3 pass / 6 failures on unmodified main with the same regression. The same five injected-filesystem fixtures fail on both; no new failing case.
  • The five cwd spellings also pass through real ripgrep (10 assertions).
  • SDK typecheck passes with native TypeScript 7.0.2. ESLint: 0 errors / 4 resolver warnings.
  • Production glob.ts passes Prettier. The existing regression has a checkout line-ending discrepancy; normalized source/test comparison has no formatting differences.
  • SDK build remains blocked by the unchanged declaration-generator ts.sys dependency; no binary/smoke or cross-platform CI pass is claimed.

Scope / Tradeoffs

Existing regression unchanged; no new cases or dependencies added. This keeps cwd project-relative and does not define new absolute-cwd behavior. Local validation is Windows/Bun 1.3.14.

@codebuff-team

Copy link
Copy Markdown
Contributor

Good catch and a clean fix. The root bug is real: the old prefix-matching logic in glob.ts never special-cased cwd === '.' (so it filtered against './' and dropped every file), and it never normalized the cwd string, so ./src and src/../src didn't match the project-relative /-separated paths produced by flattenTree. Using path.normalize + converting path.sep to / + special-casing '.' as "no filter" is the right, small fix for this.

The new test in glob-cwd.test.ts is appropriately scoped — it builds a real temp project, writes nested files, and checks several equivalent relative cwd spellings including the native separator case (path.join('src','nested','..')). That's exactly the kind of regression coverage this fix needs, and the PR description is honest about pre-existing unrelated SDK fixture failures on your Windows environment (good diligence, not hiding anything).

Two things worth double-checking before this lands:

  1. Behavior for an absolute cwd (outside the project root) isn't addressed — probably fine since that's out of scope for this bug, but worth a one-line comment confirming it's an explicit non-goal.
  2. path.normalize uses the OS-native separator semantics; on Windows this correctly produces backslash-normalized paths before you convert to /, but it'd be good to confirm this behaves identically if cwd is ever constructed with mixed separators from a config file rather than a CLI arg.

Overall this is a focused, well-tested fix in the right file. Worth porting as-is, pending a maintainer glance at the absolute-path edge case.

@codebuff-team codebuff-team added bot:triaged Classified by the community triage bot pr:port-candidate Worth porting into the private source tree labels Nov 26, 2026

This branch has not been deployed

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

Labels

bot:triaged Classified by the community triage bot pr:port-candidate Worth porting into the private source tree

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants