fix(toolkit-lib): user-supplied glob include patterns silently ignored#1652
Open
iliapolo wants to merge 4 commits into
Open
fix(toolkit-lib): user-supplied glob include patterns silently ignored#1652iliapolo wants to merge 4 commits into
iliapolo wants to merge 4 commits into
Conversation
Contributor
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1652 +/- ##
=======================================
Coverage 88.80% 88.80%
=======================================
Files 77 77
Lines 11354 11354
Branches 1584 1584
=======================================
Hits 10083 10083
Misses 1241 1241
Partials 30 30
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Regression test for #1647. The existing glob watch integ tests use a '**/*.ts' include with a file at the watch-dir root - the one glob shape that cannot reproduce the bug, since a '**'-leading pattern prunes nothing and a root-level file needs no directory descent. This test uses a directory-scoped glob ('src/**/*.ts') with the watched file nested inside 'src', exercising the path that actually regressed: chokidar v4's ignored callback gates directory traversal, and the bug pruned the 'src' directory before any nested file could be discovered. Verified the test fails (poll timeout waiting for 'Detected change to') when the matcher fix is reverted, and passes with it in place.
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.
Fixes #1647
Summary
User-specified glob patterns in
cdk.json'swatch.include(e.g.src/**/*.ts) were silently ignored:cdk watchstarted, observed nothing, and never triggered on file changes. Only literal directory paths worked, and no error was shown — so watch appeared to be running but was effectively dead.Root cause
This is remaining fallout from the chokidar v3→v4 migration (#1146 fixed only the default
include: ['**']case). In chokidar v4 theignoredcallback also controls directory traversal: if a directory is ignored, its entire subtree is pruned and no nested file is ever discovered.The matcher ignored any path that didn't match an include pattern. But a directory like
srcnever matches a file glob likesrc/**/*.ts, sosrcwas pruned before any.tsfile inside it could be found — leaving watch observing nothing.Fix
The matcher now uses the
Statschokidar provides to distinguish files from directories:/-delimited prefixes of each include pattern, e.g.src/**/*.ts→src,src/**,src/**/*.ts), so we descend and discover the nested files we actually want. It is never pruned merely for failing the file-level include filter.This restores chokidar v3 glob semantics: globs like
src/**/*.tswatch exactly the matching files, while excludes still prune entire subtrees (e.g.node_modules/**) efficiently. Literal directory paths and the default['**']config continue to work unchanged.Testing
glob-matcher.test.tscovering directory traversal: ancestor directories of a file glob are descended into, directories that cannot contain a match are pruned, directories are only pruned by excludes, multiple globs across separate trees, and the no-stats traversal path.watch.test.tsasserting theignoredcallback descends into ancestor directories of a user-supplied file glob (src/**/*.ts).ignoredcallback the way chokidar v4 actually does — with file systemStats.Q. Why did every test need to be updated to pass a stats argument?
The fix changes the matcher's contract. It used to be a pure path filter — one string in, ignore/keep out — so tests called shouldIgnore('some/path') and asserted the result directly. Now the correct answer depends on whether the path is a file or a directory: src must be kept (so chokidar descends and finds src/a.ts) even though it doesn't match a file glob like src/**/*.ts, while src/a.js under that same glob must be ignored. Since 'src' looks just like a file path, the only way to tell them apart is the Stats argument chokidar v4 actually passes. The old single-argument calls now hit the stats-absent fallback — which is intentionally permissive and defers real filtering to the later with-stats call — so they no longer reflect how chokidar invokes the callback. Passing FILE/DIR stats updates the tests to exercise it the way production does.
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license