Skip to content

Commit ea52013

Browse files
authored
Close tree if unapproved golden images get in (flutter#93516)
1 parent 0a2227c commit ea52013

File tree

2 files changed

+56
-6
lines changed

2 files changed

+56
-6
lines changed

packages/flutter_goldens/test/flutter_goldens_test.dart

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,45 @@ void main() {
153153
);
154154
});
155155

156+
test('throws for error state from imgtestAdd', () {
157+
final File goldenFile = fs.file('/workDirectory/temp/golden_file_test.png')
158+
..createSync(recursive: true);
159+
platform = FakePlatform(
160+
environment: <String, String>{
161+
'FLUTTER_ROOT': _kFlutterRoot,
162+
'GOLDCTL' : 'goldctl',
163+
},
164+
operatingSystem: 'macos'
165+
);
166+
167+
skiaClient = SkiaGoldClient(
168+
workDirectory,
169+
fs: fs,
170+
process: process,
171+
platform: platform,
172+
httpClient: fakeHttpClient,
173+
);
174+
175+
process.fallbackProcessResult = ProcessResult(123, 1, 'fail', 'fail');
176+
const RunInvocation goldctlInvocation = RunInvocation(
177+
<String>[
178+
'goldctl',
179+
'imgtest', 'add',
180+
'--work-dir', '/workDirectory/temp',
181+
'--test-name', 'golden_file_test',
182+
'--png-file', '/workDirectory/temp/golden_file_test.png',
183+
'--passfail',
184+
],
185+
null,
186+
);
187+
process.processResults[goldctlInvocation] = ProcessResult(123, 1, 'fail', 'fail');
188+
189+
expect(
190+
skiaClient.imgtestAdd('golden_file_test', goldenFile),
191+
throwsException,
192+
);
193+
});
194+
156195
test('correctly inits tryjob for luci', () async {
157196
platform = FakePlatform(
158197
environment: <String, String>{

packages/flutter_goldens_client/lib/skia_client.dart

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,28 @@ class SkiaGoldClient {
177177
.path,
178178
'--test-name', cleanTestName(testName),
179179
'--png-file', goldenFile.path,
180+
'--passfail',
180181
];
181182

182183
final io.ProcessResult result = await process.run(imgtestCommand);
183184

184185
if (result.exitCode != 0) {
185-
// We do not want to throw for non-zero exit codes here, as an intentional
186-
// change or new golden file test expect non-zero exit codes. Logging here
187-
// is meant to help debugging in CI when an unexpected result occurs.
188-
// See also: https://github.com/flutter/flutter/issues/91285
189-
print('goldctl imgtest add stdout: ${result.stdout}'); // ignore: avoid_print
190-
print('goldctl imgtest add stderr: ${result.stderr}'); // ignore: avoid_print
186+
// If an unapproved image has made it to post-submit, throw to close the
187+
// tree.
188+
final StringBuffer buf = StringBuffer()
189+
..writeln('Skia Gold received an unapproved image in post-submit ')
190+
..writeln('testing. Golden file images in flutter/flutter are triaged ')
191+
..writeln('in pre-submit during code review for the given PR.')
192+
..writeln()
193+
..writeln('Visit https://flutter-gold.skia.org/ to view and approve ')
194+
..writeln('the image(s), or revert the associated change. For more ')
195+
..writeln('information, visit the wiki: ')
196+
..writeln('https://github.com/flutter/flutter/wiki/Writing-a-golden-file-test-for-package:flutter')
197+
..writeln()
198+
..writeln('Debug information for Gold:')
199+
..writeln('stdout: ${result.stdout}')
200+
..writeln('stderr: ${result.stderr}');
201+
throw Exception(buf.toString());
191202
}
192203

193204
return true;

0 commit comments

Comments
 (0)