From ea5201389503be8b5d6b87ccd133502b26924762 Mon Sep 17 00:00:00 2001 From: Kate Lovett Date: Mon, 15 Nov 2021 14:40:32 -0600 Subject: [PATCH] Close tree if unapproved golden images get in (#93516) --- .../test/flutter_goldens_test.dart | 39 +++++++++++++++++++ .../lib/skia_client.dart | 23 ++++++++--- 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/packages/flutter_goldens/test/flutter_goldens_test.dart b/packages/flutter_goldens/test/flutter_goldens_test.dart index a58f6694e1..45b2b4e2da 100644 --- a/packages/flutter_goldens/test/flutter_goldens_test.dart +++ b/packages/flutter_goldens/test/flutter_goldens_test.dart @@ -153,6 +153,45 @@ void main() { ); }); + test('throws for error state from imgtestAdd', () { + final File goldenFile = fs.file('/workDirectory/temp/golden_file_test.png') + ..createSync(recursive: true); + platform = FakePlatform( + environment: { + 'FLUTTER_ROOT': _kFlutterRoot, + 'GOLDCTL' : 'goldctl', + }, + operatingSystem: 'macos' + ); + + skiaClient = SkiaGoldClient( + workDirectory, + fs: fs, + process: process, + platform: platform, + httpClient: fakeHttpClient, + ); + + process.fallbackProcessResult = ProcessResult(123, 1, 'fail', 'fail'); + const RunInvocation goldctlInvocation = RunInvocation( + [ + 'goldctl', + 'imgtest', 'add', + '--work-dir', '/workDirectory/temp', + '--test-name', 'golden_file_test', + '--png-file', '/workDirectory/temp/golden_file_test.png', + '--passfail', + ], + null, + ); + process.processResults[goldctlInvocation] = ProcessResult(123, 1, 'fail', 'fail'); + + expect( + skiaClient.imgtestAdd('golden_file_test', goldenFile), + throwsException, + ); + }); + test('correctly inits tryjob for luci', () async { platform = FakePlatform( environment: { diff --git a/packages/flutter_goldens_client/lib/skia_client.dart b/packages/flutter_goldens_client/lib/skia_client.dart index 396d2e2f4a..69d1704e4b 100644 --- a/packages/flutter_goldens_client/lib/skia_client.dart +++ b/packages/flutter_goldens_client/lib/skia_client.dart @@ -177,17 +177,28 @@ class SkiaGoldClient { .path, '--test-name', cleanTestName(testName), '--png-file', goldenFile.path, + '--passfail', ]; final io.ProcessResult result = await process.run(imgtestCommand); if (result.exitCode != 0) { - // We do not want to throw for non-zero exit codes here, as an intentional - // change or new golden file test expect non-zero exit codes. Logging here - // is meant to help debugging in CI when an unexpected result occurs. - // See also: https://github.com/flutter/flutter/issues/91285 - print('goldctl imgtest add stdout: ${result.stdout}'); // ignore: avoid_print - print('goldctl imgtest add stderr: ${result.stderr}'); // ignore: avoid_print + // If an unapproved image has made it to post-submit, throw to close the + // tree. + final StringBuffer buf = StringBuffer() + ..writeln('Skia Gold received an unapproved image in post-submit ') + ..writeln('testing. Golden file images in flutter/flutter are triaged ') + ..writeln('in pre-submit during code review for the given PR.') + ..writeln() + ..writeln('Visit https://flutter-gold.skia.org/ to view and approve ') + ..writeln('the image(s), or revert the associated change. For more ') + ..writeln('information, visit the wiki: ') + ..writeln('https://github.com/flutter/flutter/wiki/Writing-a-golden-file-test-for-package:flutter') + ..writeln() + ..writeln('Debug information for Gold:') + ..writeln('stdout: ${result.stdout}') + ..writeln('stderr: ${result.stderr}'); + throw Exception(buf.toString()); } return true;