refactor(filesystem): extract buildDirectoryTree to lib.ts#4055
Open
FazeelUsmani wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
refactor(filesystem): extract buildDirectoryTree to lib.ts#4055FazeelUsmani wants to merge 1 commit intomodelcontextprotocol:mainfrom
FazeelUsmani wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
Move the buildTree closure out of the directory_tree handler and export it as buildDirectoryTree. Replaces the duplicated buildTreeForTesting in the test suite so tests now exercise the production function directly. No behavior change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
closes ##3537
Move the
buildTreeclosure out of thedirectory_treehandler inindex.tsand export it asbuildDirectoryTreefromlib.ts. Replaces the duplicatedbuildTreeForTestingcopy in__tests__/directory-tree.test.tsso tests now exercise the production function directly.No behavior change.
Server Details
Motivation and Context
buildTreewas defined as a closure inside thedirectory_treerequest handler. The test suite kept a near-identical copy (buildTreeForTesting) to exercise the recursion logic. Any drift between the two would silently invalidate the tests - exactly the kind of duplication a future change is most likely to break.Hoisting
buildTreetolib.tsand importing it in the test removes the duplication and ensures regressions are caught against the production function.How Has This Been Tested?
npm testinsrc/filesystem- 146/146 tests pass.The
directory-tree.test.tssuite now drives the realbuildDirectoryTreethrough a real tmpdir tree, which exercisesvalidatePathend-to-end (the previous helper bypassed it; anfs.realpathcall was added to handle macOS's/var→/private/varsymlink).Breaking Changes
None. The
directory_treetool's input schema, output schema, and runtime behavior are unchanged.Types of changes
Checklist