@@ -125,6 +125,55 @@ void main() {
125125 },
126126 );
127127
128+ FileSystem createFsWithPubspecInParentDir () {
129+ final FileSystem fs = MemoryFileSystem .test ();
130+ // Create pubspec.yaml in the root directory
131+ fs.currentDirectory.childFile ('pubspec.yaml' ).writeAsStringSync ('''
132+ flutter:
133+ config:
134+ enable-foo: true
135+ enable-bar: false
136+ ''' );
137+ // Create a subdirectory and set it as the current directory
138+ final Directory subdir = fs.currentDirectory.childDirectory ('lib' ).childDirectory ('src' );
139+ subdir.createSync (recursive: true );
140+ fs.currentDirectory = subdir;
141+ return fs;
142+ }
143+
144+ testUsingContext (
145+ 'FeatureFlags finds pubspec.yaml in parent directory when CWD is a subdirectory' ,
146+ () {
147+ // This test verifies that findProjectRoot is used to locate pubspec.yaml
148+ // even when the current directory is a subdirectory of the project.
149+ final FeatureFlags featureFlagsFromContext = featureFlags;
150+
151+ expect (
152+ featureFlagsFromContext.isEnabled (
153+ const Feature (
154+ name: 'foo' ,
155+ configSetting: 'enable-foo' ,
156+ master: FeatureChannelSetting (available: true ),
157+ ),
158+ ),
159+ isTrue,
160+ reason: 'enable-foo: true should be found in pubspec.yaml in parent directory' ,
161+ );
162+
163+ expect (
164+ featureFlagsFromContext.isEnabled (
165+ const Feature .fullyEnabled (name: 'bar' , configSetting: 'enable-bar' ),
166+ ),
167+ isFalse,
168+ reason: 'enable-bar: false should be found in pubspec.yaml in parent directory' ,
169+ );
170+ },
171+ overrides: < Type , Generator > {
172+ ProcessManager : FakeProcessManager .empty,
173+ FileSystem : createFsWithPubspecInParentDir,
174+ },
175+ );
176+
128177 testUsingContext ('Test feature flags match feature flags' , () {
129178 final FeatureFlags testFeatureFlags = TestFeatureFlags ();
130179
0 commit comments