Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 5ec9d0b

Browse files
[flutter_plugin_tools] Fix federated safety check (#4368)
The new safety check doesn't allow simple platform-interface-only changes because it doesn't actually check that a non-interface package is actually modified before failing it for a modified platform interface. This fixes that, and adds a test case covering it.
1 parent c05887f commit 5ec9d0b

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

script/tool/lib/src/federation_safety_check_command.dart

+7
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@ class FederationSafetyCheckCommand extends PackageLoopingCommand {
135135
return PackageResult.success();
136136
}
137137

138+
final List<String> changedPackageFiles =
139+
_changedDartFiles[package.directory.basename] ?? <String>[];
140+
if (changedPackageFiles.isEmpty) {
141+
print('No Dart changes.');
142+
return PackageResult.success();
143+
}
144+
138145
// If the change would be flagged, but it appears to be a mass change
139146
// rather than a plugin-specific change, allow it with a warning.
140147
//

script/tool/test/federation_safety_check_command_test.dart

+41
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,47 @@ void main() {
125125
);
126126
});
127127

128+
test('allows changes to just an interface package', () async {
129+
final Directory pluginGroupDir = packagesDir.childDirectory('foo');
130+
final Directory platformInterface =
131+
createFakePlugin('foo_platform_interface', pluginGroupDir);
132+
createFakePlugin('foo', pluginGroupDir);
133+
createFakePlugin('foo_ios', pluginGroupDir);
134+
createFakePlugin('foo_android', pluginGroupDir);
135+
136+
final String changedFileOutput = <File>[
137+
platformInterface.childDirectory('lib').childFile('foo.dart'),
138+
platformInterface.childFile('pubspec.yaml'),
139+
].map((File file) => file.path).join('\n');
140+
processRunner.mockProcessesForExecutable['git-diff'] = <io.Process>[
141+
MockProcess(stdout: changedFileOutput),
142+
];
143+
144+
final List<String> output =
145+
await runCapturingPrint(runner, <String>['federation-safety-check']);
146+
147+
expect(
148+
output,
149+
containsAllInOrder(<Matcher>[
150+
contains('Running for foo/foo...'),
151+
contains('No Dart changes.'),
152+
contains('Running for foo_android...'),
153+
contains('No Dart changes.'),
154+
contains('Running for foo_ios...'),
155+
contains('No Dart changes.'),
156+
contains('Running for foo_platform_interface...'),
157+
contains('Ran for 3 package(s)'),
158+
contains('Skipped 1 package(s)'),
159+
]),
160+
);
161+
expect(
162+
output,
163+
isNot(contains(<Matcher>[
164+
contains('No published changes for foo_platform_interface'),
165+
])),
166+
);
167+
});
168+
128169
test('allows changes to multiple non-interface packages', () async {
129170
final Directory pluginGroupDir = packagesDir.childDirectory('foo');
130171
final Directory appFacing = createFakePlugin('foo', pluginGroupDir);

0 commit comments

Comments
 (0)