[PR #5927] [CLOSED] fix(reference)!: honor nested .gitignore files #7105

Closed
opened 2026-11-01 21:45:26 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/5927
Author: @shoyann
Created: 10/21/2026
Status: ❌ Closed

Base: main ← Head: fix/nested-gitignore


📝 Commits (10+)

  • 739554c fix(reference): honor nested .gitignore files
  • 1129623 fix(reference): keep nested directory-only rules within their scope
  • 0f4ca95 fix(reference): skip sensitive nested ignore policies before reading
  • a0dfee7 fix(reference): normalize ignore file BOMs before matching rules
  • a184acb fix(reference)!: preserve ignore policy provenance
  • 16c9e9b fix(reference): skip sensitive policies with unreadable metadata
  • 869832c chore: merge main into nested ignore fix
  • 9e062c5 fix(reference): keep trailing globstars below their prefix
  • 6343bda fix(reference): preserve partial inventory on policy failures
  • 13c5565 fix(reference): preserve import exclusions and Git case rules

📊 Changes

28 files changed (+6430 additions, -334 deletions)

View changed files

📝 docs/cli.md (+52 -4)
📝 src/application/ReferenceSourceImport.ts (+113 -97)
📝 src/application/ReferenceSourceImportPolicy.ts (+639 -67)
📝 src/application/ReferenceSourceImportTypes.test.ts (+71 -1)
📝 src/application/ReferenceSourceImportTypes.ts (+22 -3)
📝 src/application/ReferenceSourceVcsAdapter.ts (+386 -59)
📝 src/domain/referenceSourceGraph.test.ts (+159 -0)
📝 src/domain/referenceSourceGraph.ts (+41 -18)
📝 src/reference/ReferenceSourceReader.ts (+1 -4)
📝 src/reference/ReferenceSourceReaderEntries.ts (+30 -5)
📝 src/reference/ReferenceSourceReaderTypes.ts (+11 -6)
📝 tests/boundary/cli/referenceSourceExclusions.test.ts (+71 -0)
📝 tests/boundary/cli/referenceSourceImportStatus.test.ts (+57 -0)
📝 tests/boundary/cli/referenceSourceSummary.test.ts (+14 -4)
➕ tests/boundary/filesystem/referenceSourceEscapedPatterns.test.ts (+890 -0)
➕ tests/boundary/filesystem/referenceSourceGitConfigParsing.test.ts (+459 -0)
➕ tests/boundary/filesystem/referenceSourceGitMetadataPaths.test.ts (+724 -0)
➕ tests/boundary/filesystem/referenceSourceIgnoreBom.test.ts (+120 -0)
➕ tests/boundary/filesystem/referenceSourceIgnoreLineEndings.test.ts (+111 -0)
📝 tests/boundary/filesystem/referenceSourceImport.test.ts (+4 -0)

...and 8 more files

📄 Description

Summary

Fixes #5891.

Reference imports previously read only the root .gitignore, so package-local generated files could be hashed and contribute unwanted dependencies. Nested policies now apply before a directory's children are read. The issue fixture keeps packages/widget/main.js and excludes packages/widget/generated/, including its unwanted import.

Approach

  • Each queued directory carries its inherited policy. Child rules stay within that subtree, excluded directories are pruned, and sibling rules stay independent.
  • Project rules preserve Git byte matching, escaping, directory scope and ASCII case folding. Caller/default/secret patterns retain their existing interpretation and precedence. Explicitly sensitive policy files are not read.
  • Git metadata identity is resolved once for HEAD and local configuration, including linked worktrees. Unsupported configuration or unrepresentable ref identities remain explicitly unknown.
  • Project exclusions record the supplying .gitignore as policy_path. That provenance participates in Evidence commitments. Traversal and cleanup failures retain partial observations and exclusions.

The latest follow-up fixes the escaped-leading-slash finding. A rule such as \/foo, including its negated form, remains nonmatching rather than becoming a root anchor. Existing root/nested traversal fixtures cover this alongside doubled/tripled backslashes, internal separators and ordinary anchors. The main sync preserves upstream raw-filename validation while passing the prepared directory policy to decoded entries.

Validation

Validated on WSL Ubuntu with Node 24.22.1, npm 11.16.0 and Git 2.53.0:

  • npm run test:focused -- <paths below>: 36 files passed; 583 tests passed, 2 Windows-only tests skipped. Includes the upstream filename-byte regression and CLI/MCP contract coverage.
  • npm run check: passed (typecheck, lint with existing warnings, formatting, unused-code checks, metadata and architecture guards).
  • npm run docs:check: passed, including 9 README consistency tests.
  • Leading-slash fixtures reproduced the missing/extra files before the fix. An independent 36-case real-import comparison against git ls-files --others --exclude-standard -z agreed in every case after the fix. This supplements, rather than replaces, the checked-in regressions.
Focused test paths
src/reference/ReferenceSourceReader.test.ts
src/reference/ReferenceSourceReaderFile.test.ts
tests/boundary/filesystem/referenceSourceImport.test.ts
tests/boundary/filesystem/referenceSourceNestedIgnore.test.ts
tests/boundary/filesystem/referenceSourceNestedIgnoreFailures.test.ts
tests/boundary/filesystem/referenceSourceMetadataCleanup.test.ts
tests/boundary/filesystem/referenceSourceCleanupOwnership.test.ts
tests/boundary/filesystem/referenceSourceFailureDetails.test.ts
tests/boundary/filesystem/referenceSourceQueuedDirectories.test.ts
tests/boundary/filesystem/referenceSourceUnreadableDirectories.test.ts
tests/boundary/cli/referenceSourceExclusions.test.ts
tests/boundary/cli/referenceSourceSummary.test.ts
tests/boundary/filesystem/referenceSourceSensitiveIgnore.test.ts
tests/boundary/filesystem/referenceSourceIgnoreBom.test.ts
src/domain/referenceSourceGraph.test.ts
src/domain/referenceSourceSummary.test.ts
src/domain/referenceSourcePathIdentity.test.ts
tests/boundary/cli/referenceSourceLegacyFacts.test.ts
tests/boundary/mcp/applicationEvidenceMcp.test.ts
tests/conformance/contracts/mcpInputSchemaProfile.test.ts
tests/boundary/mcp/contractPresentation.test.ts
tests/boundary/filesystem/referenceSourceTrailingGlobstar.test.ts
tests/boundary/cli/referenceSourceImportStatus.test.ts
src/application/ReferenceSourceImportTypes.test.ts
tests/boundary/filesystem/referenceSourceVcs.test.ts
tests/boundary/filesystem/referenceSourceIgnoreLineEndings.test.ts
tests/boundary/filesystem/referenceSourceGitConfigParsing.test.ts
tests/boundary/filesystem/referenceSourceEscapedPatterns.test.ts
tests/boundary/filesystem/referenceSourceGitMetadataPaths.test.ts
src/artifacts/RegularFileAdmission.test.ts
tests/boundary/filesystem/regularFileCancellation.test.ts
tests/process-global/regularFileNoFollowFallback.test.ts
tests/process-global/commandFinalizationCancellation.test.ts
src/application/analysisView/AnalysisViewService.test.ts
tests/boundary/filesystem/referenceSourcePosixClasses.test.ts
tests/boundary/filesystem/referenceSourceFilenameBytes.test.ts

Compatibility and limits

The title marks the optional policy_path addition as breaking: older strict readers reject new records containing it and need upgrading. Legacy graphs without it remain readable with unchanged graph/manifest commitments; their rule source stays unknown until re-import.

Config includes, worktree overrides, multiline continuations and version-dependent numeric forms remain explicitly unknown. Some Unicode-whitespace ref identities cannot be safely represented by the reference library and remain unknown. No complete Git config/ref/wildmatch parity is claimed. Existing pathname-race limitations remain, and partial-error byte serialization is still eager.

Native Windows/macOS, real providers and a real monorepo were not exercised locally. Full hosted CI must pass for the current head.

Author readiness

Human owner: @shoyann

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem and links the issue.
  • The scope is a focused correction within existing read-only import behavior.
  • Regression coverage and owning documentation are updated.
  • Human readiness is declared and required CI passes.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/5927 **Author:** [@shoyann](https://github.com/shoyann) **Created:** 10/21/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/nested-gitignore` --- ### 📝 Commits (10+) - [`739554c`](https://github.com/morluto/rea/commit/739554cda46dbe8725fec6460d9e6f730fe79942) fix(reference): honor nested .gitignore files - [`1129623`](https://github.com/morluto/rea/commit/112962311dd23785faf6a2901e5948d51360a44f) fix(reference): keep nested directory-only rules within their scope - [`0f4ca95`](https://github.com/morluto/rea/commit/0f4ca956d96f4eaf575c7bcb01eff447d293cbd2) fix(reference): skip sensitive nested ignore policies before reading - [`a0dfee7`](https://github.com/morluto/rea/commit/a0dfee7185092ab3290afa3001b7c6d5e526c908) fix(reference): normalize ignore file BOMs before matching rules - [`a184acb`](https://github.com/morluto/rea/commit/a184acb76f760b8475acb5c3149523ef1403bea2) fix(reference)!: preserve ignore policy provenance - [`16c9e9b`](https://github.com/morluto/rea/commit/16c9e9b0f295408b0ec3d67b8bd9679c60a1384c) fix(reference): skip sensitive policies with unreadable metadata - [`869832c`](https://github.com/morluto/rea/commit/869832c9fe11dd8abbd337639df9217989b8d705) chore: merge main into nested ignore fix - [`9e062c5`](https://github.com/morluto/rea/commit/9e062c5f2e5186ff0a3cd3de9c85d0d8757c1624) fix(reference): keep trailing globstars below their prefix - [`6343bda`](https://github.com/morluto/rea/commit/6343bda6f2888fcd4cdfefccd3ab33e1cf2a9150) fix(reference): preserve partial inventory on policy failures - [`13c5565`](https://github.com/morluto/rea/commit/13c55658125d8c504d7bfdde57d98796282a09a1) fix(reference): preserve import exclusions and Git case rules ### 📊 Changes **28 files changed** (+6430 additions, -334 deletions) <details> <summary>View changed files</summary> 📝 `docs/cli.md` (+52 -4) 📝 `src/application/ReferenceSourceImport.ts` (+113 -97) 📝 `src/application/ReferenceSourceImportPolicy.ts` (+639 -67) 📝 `src/application/ReferenceSourceImportTypes.test.ts` (+71 -1) 📝 `src/application/ReferenceSourceImportTypes.ts` (+22 -3) 📝 `src/application/ReferenceSourceVcsAdapter.ts` (+386 -59) 📝 `src/domain/referenceSourceGraph.test.ts` (+159 -0) 📝 `src/domain/referenceSourceGraph.ts` (+41 -18) 📝 `src/reference/ReferenceSourceReader.ts` (+1 -4) 📝 `src/reference/ReferenceSourceReaderEntries.ts` (+30 -5) 📝 `src/reference/ReferenceSourceReaderTypes.ts` (+11 -6) 📝 `tests/boundary/cli/referenceSourceExclusions.test.ts` (+71 -0) 📝 `tests/boundary/cli/referenceSourceImportStatus.test.ts` (+57 -0) 📝 `tests/boundary/cli/referenceSourceSummary.test.ts` (+14 -4) ➕ `tests/boundary/filesystem/referenceSourceEscapedPatterns.test.ts` (+890 -0) ➕ `tests/boundary/filesystem/referenceSourceGitConfigParsing.test.ts` (+459 -0) ➕ `tests/boundary/filesystem/referenceSourceGitMetadataPaths.test.ts` (+724 -0) ➕ `tests/boundary/filesystem/referenceSourceIgnoreBom.test.ts` (+120 -0) ➕ `tests/boundary/filesystem/referenceSourceIgnoreLineEndings.test.ts` (+111 -0) 📝 `tests/boundary/filesystem/referenceSourceImport.test.ts` (+4 -0) _...and 8 more files_ </details> ### 📄 Description ## Summary Fixes #5891. Reference imports previously read only the root `.gitignore`, so package-local generated files could be hashed and contribute unwanted dependencies. Nested policies now apply before a directory's children are read. The issue fixture keeps `packages/widget/main.js` and excludes `packages/widget/generated/`, including its unwanted import. ## Approach - Each queued directory carries its inherited policy. Child rules stay within that subtree, excluded directories are pruned, and sibling rules stay independent. - Project rules preserve Git byte matching, escaping, directory scope and ASCII case folding. Caller/default/secret patterns retain their existing interpretation and precedence. Explicitly sensitive policy files are not read. - Git metadata identity is resolved once for HEAD and local configuration, including linked worktrees. Unsupported configuration or unrepresentable ref identities remain explicitly unknown. - Project exclusions record the supplying `.gitignore` as `policy_path`. That provenance participates in Evidence commitments. Traversal and cleanup failures retain partial observations and exclusions. The latest follow-up fixes the [escaped-leading-slash finding](https://github.com/morluto/rea/pull/5927#discussion_r4357722987). A rule such as `\/foo`, including its negated form, remains nonmatching rather than becoming a root anchor. Existing root/nested traversal fixtures cover this alongside doubled/tripled backslashes, internal separators and ordinary anchors. The main sync preserves upstream raw-filename validation while passing the prepared directory policy to decoded entries. ## Validation Validated on WSL Ubuntu with Node 24.22.1, npm 11.16.0 and Git 2.53.0: - `npm run test:focused -- <paths below>`: **36 files passed; 583 tests passed, 2 Windows-only tests skipped**. Includes the upstream filename-byte regression and CLI/MCP contract coverage. - `npm run check`: passed (typecheck, lint with existing warnings, formatting, unused-code checks, metadata and architecture guards). - `npm run docs:check`: passed, including 9 README consistency tests. - Leading-slash fixtures reproduced the missing/extra files before the fix. An independent 36-case real-import comparison against `git ls-files --others --exclude-standard -z` agreed in every case after the fix. This supplements, rather than replaces, the checked-in regressions. <details> <summary>Focused test paths</summary> ```text src/reference/ReferenceSourceReader.test.ts src/reference/ReferenceSourceReaderFile.test.ts tests/boundary/filesystem/referenceSourceImport.test.ts tests/boundary/filesystem/referenceSourceNestedIgnore.test.ts tests/boundary/filesystem/referenceSourceNestedIgnoreFailures.test.ts tests/boundary/filesystem/referenceSourceMetadataCleanup.test.ts tests/boundary/filesystem/referenceSourceCleanupOwnership.test.ts tests/boundary/filesystem/referenceSourceFailureDetails.test.ts tests/boundary/filesystem/referenceSourceQueuedDirectories.test.ts tests/boundary/filesystem/referenceSourceUnreadableDirectories.test.ts tests/boundary/cli/referenceSourceExclusions.test.ts tests/boundary/cli/referenceSourceSummary.test.ts tests/boundary/filesystem/referenceSourceSensitiveIgnore.test.ts tests/boundary/filesystem/referenceSourceIgnoreBom.test.ts src/domain/referenceSourceGraph.test.ts src/domain/referenceSourceSummary.test.ts src/domain/referenceSourcePathIdentity.test.ts tests/boundary/cli/referenceSourceLegacyFacts.test.ts tests/boundary/mcp/applicationEvidenceMcp.test.ts tests/conformance/contracts/mcpInputSchemaProfile.test.ts tests/boundary/mcp/contractPresentation.test.ts tests/boundary/filesystem/referenceSourceTrailingGlobstar.test.ts tests/boundary/cli/referenceSourceImportStatus.test.ts src/application/ReferenceSourceImportTypes.test.ts tests/boundary/filesystem/referenceSourceVcs.test.ts tests/boundary/filesystem/referenceSourceIgnoreLineEndings.test.ts tests/boundary/filesystem/referenceSourceGitConfigParsing.test.ts tests/boundary/filesystem/referenceSourceEscapedPatterns.test.ts tests/boundary/filesystem/referenceSourceGitMetadataPaths.test.ts src/artifacts/RegularFileAdmission.test.ts tests/boundary/filesystem/regularFileCancellation.test.ts tests/process-global/regularFileNoFollowFallback.test.ts tests/process-global/commandFinalizationCancellation.test.ts src/application/analysisView/AnalysisViewService.test.ts tests/boundary/filesystem/referenceSourcePosixClasses.test.ts tests/boundary/filesystem/referenceSourceFilenameBytes.test.ts ``` </details> ## Compatibility and limits The title marks the optional `policy_path` addition as breaking: older strict readers reject new records containing it and need upgrading. Legacy graphs without it remain readable with unchanged graph/manifest commitments; their rule source stays unknown until re-import. Config includes, worktree overrides, multiline continuations and version-dependent numeric forms remain explicitly unknown. Some Unicode-whitespace ref identities cannot be safely represented by the reference library and remain unknown. No complete Git config/ref/wildmatch parity is claimed. Existing pathname-race limitations remain, and partial-error byte serialization is still eager. Native Windows/macOS, real providers and a real monorepo were not exercised locally. Full hosted CI must pass for the current head. ## Author readiness Human owner: @shoyann - [x] I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work. - [x] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [x] I declare this PR ready for initial maintainer review. ## Before merge - [x] This PR addresses a concrete problem and links the issue. - [x] The scope is a focused correction within existing read-only import behavior. - [x] Regression coverage and owning documentation are updated. - [ ] Human readiness is declared and required CI passes. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-01 21:45:26 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#7105
No description provided.