Extract reusable cancellable file search utility
Context
PR #538 introduced an efficient cancellable fast-glob traversal for recipe-local discovery.
The implementation currently keeps recipe-specific discovery policy and generic filesystem traversal together in client/src/documentLinkProvider.ts.
Following maintainer feedback, the most useful reusable boundary is the filesystem search itself rather than a larger module split.
Proposed work
Extract a small CancellableFileSearch utility responsible for the reusable traversal mechanics:
- run efficient file/folder searches from supplied glob patterns;
- preserve bounded concurrency and the current traversal options;
- observe pre-existing cancellation;
- destroy an active stream when cancellation is requested;
- dispose the cancellation subscription;
- clean up the stream when traversal finishes or another error occurs;
- return the discovered files and directories without introducing recipe-specific policy.
Keep recipe-local responsibilities close to BitbakeDocumentLinkProvider for now:
- deciding whether recipe-local discovery applies;
- constructing recipe-local roots;
- producing glob patterns;
- associating discovered URIs with document links.
A separate RecipeLocalDiscovery class in the same TypeScript file is acceptable if it improves the distinction without adding unnecessary module structure, but it is not a goal by itself.
Testing approach
Reuse the functional and edge-case coverage added with #538.
Add or adjust tests only where the extraction introduces project-owned behavior that is not already covered. Do not add tests for fast-glob implementation details or duplicate traversal-library guarantees.
Non-goals
- adding a benchmark or performance harness;
- introducing timing or memory thresholds;
- broadly splitting document-link and recipe-local discovery into separate modules;
- adding exhaustive traversal tests;
- changing completion or document-link semantics;
- introducing a timeout or result truncation.
Acceptance criteria
- generic cancellable traversal is encapsulated in a reusable
CancellableFileSearchutility; - recipe-specific discovery delegates filesystem traversal to that utility;
- existing user-visible behavior remains unchanged;
- cancellation and cleanup behavior from #538 is preserved;
- no benchmark or redundant library-level test coverage is added;
- lint, TypeScript compilation, and relevant existing tests pass.
Relationship to existing work
This is a small maintainability follow-up to #537 and merged PR #538. It intentionally follows the narrower KISS direction discussed during review.
Splitting this implementation is something I also was thinking about when reviewing the PR:
- DocumentLinkProvider: Associates links with file URIs, leveraging the other components
- RecipeLocalDiscovery: Produces the patterns and calls the search engine
- CancellableFileSearch: Reusable utility performing efficient file/folder search, with cancelable policy I think the CancellableFileSearch is the most interesting refactoring since this is a utility we can imagine using for different purposes in the future. The DocumentLinkProvider/RecipeLocalDiscovery split seem less important, and could remain in the same file for now. I don't foresee a usage of RecipeLocalDiscovery outside of the DocumentLinkProvider. Maybe making the distinction at least through different classes in the .ts file could be a start for them. What is your opinion?
Add an opt-in benchmark -> This is too thorough a test for this small, isolated feature IMO.
Add deterministic traversal tests -> Likewise, we already have very thorough coverage for functionality and edge-case behavior with your PR. We should avoid bloating the test suites and make the code base too rigid. Unit tests are meant to test our own logic, not the underlying libraries we are using. KISS.
Thanks, I agree that the useful reusable boundary is CancellableFileSearch.
Keeping recipe-local policy close to BitbakeDocumentLinkProvider for now also makes sense to me. A separate class in the same TypeScript file can be considered if it makes the responsibilities clearer without introducing unnecessary structure.
I have narrowed the issue accordingly: no benchmark, no exhaustive traversal tests, and only focused test adjustments if the extraction introduces project-owned behavior that is not already covered.
I will keep this as a small behavior-preserving refactor.