Skip to content

Commit 3033393

Browse files
matanlureypull[bot]
authored andcommitted
Add documentation about updating .ci.yaml and flutter-gold. (flutter#154184)
Closes flutter#143863. /cc @christopherfujino
1 parent 622707c commit 3033393

File tree

1 file changed

+99
-12
lines changed

1 file changed

+99
-12
lines changed

docs/contributing/testing/Writing-a-golden-file-test-for-package-flutter.md

Lines changed: 99 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@ _(This page is referenced by comments in the Flutter codebase.)_
77
Golden file tests for `package:flutter` use [Flutter Gold](https://flutter-gold.skia.org/?query=source_type%3Dflutter) for baseline and version management of golden files. This allows for golden file testing on Linux, Windows, MacOS and Web, which accounts for the occasional subtle rendering differences between these platforms.
88

99
## Index
10+
1011
- [Known Issues](#known-issues)
1112
- [Build Breakage](#build-breakage)
1213
- [Creating a New Golden File Test](#creating-a-new-golden-file-test)
13-
- [Adding a new key in the Skia Client](#Adding-a-new-key-in-the-Skia-Client)
14+
- [Add or configure a `.ci.yaml` task](#add-or-configure-a-ciyaml-task)
15+
- [Adding a known task name to the `flutter-gold` check](#adding-a-known-task-name-to-the-flutter-gold-check)
16+
- [Writing and submitting the test](#writing-and-submitting-the-test)
17+
- [Adding a new key in the Skia Client](#adding-a-new-key-in-the-skia-client)
1418
- [Updating a Golden File Test](#updating-a-golden-file-test)
1519
- [Flutter Gold Login](#flutter-gold-login)
1620
- [`flutter-gold` Check](#flutter-gold-check)
1721
- [`reduced-test-set` tag](#reduced-test-set-tag)
1822
- [Troubleshooting](#troubleshooting)
1923

20-
2124
## Known Issues
2225

2326
### Negative Images
@@ -31,9 +34,7 @@ If you would like to instantly invalidate all prior renderings, changing the nam
3134

3235
If the Flutter build is broken due to a golden file test failure, this typically means an image change has landed without being triaged. Golden file images should be triaged in pre-submit before a change lands (as described in the steps below). If this process is not followed, a test with an unapproved golden file image will fail in post-submit testing. This will present in the following error message:
3336

34-
<!-- TODO(Piinks): Update this error message in the framework. -->
35-
36-
```
37+
```txt
3738
Skia Gold received an unapproved image in post-submit
3839
testing. Golden file images in flutter/flutter are triaged
3940
in pre-submit during code review for the given PR.
@@ -50,6 +51,92 @@ Notice, Gold may wrongly attribute blame for image changes on the dashboard. Pos
5051

5152
## Creating a New Golden File Test
5253

54+
<!--
55+
Note: These instructions are also referred to in the flutter/engine repository
56+
ensure that when updating them, the workflow is either consistent or the
57+
differences are clearly called out.
58+
-->
59+
60+
Writing a _new_ golden file test if the _test suite_ (sometimes called "task"
61+
or "shard") is not already configured for golden file testing is an involved
62+
process, and missing a step can result in a broken build or a failing test.
63+
64+
The process involves:
65+
66+
1. [Adding or configuring a `.ci.yaml` task](#add-or-configure-a-ciyaml-task).
67+
1. [Writing and submitting the test](#writing-and-submitting-the-test).
68+
1. [Adding a known task name to the `flutter-gold` check](#adding-a-known-task-name-to-the-flutter-gold-check).
69+
70+
### Add or configure a `.ci.yaml` task
71+
72+
_If you are editing an existing test or test suite that already includes the
73+
`goldctl` dependency (as seen below), you can skip this step._
74+
75+
Every test suite that runs tests (golden file tests included) needs to be
76+
configured in the top-level [`.ci.yaml` file](../../../.ci.yaml), which contains
77+
the configuration for all the CI tasks that run on the Flutter repository. For
78+
example, the task `Linux framework_tests_widgets` (as of 2024-08-27) looks like
79+
this:
80+
81+
```yaml
82+
# Some parts omitted for brevity
83+
84+
- name: Linux framework_tests_widgets
85+
properties:
86+
dependencies: >-
87+
[
88+
{"dependency": "goldctl", "version": "git_revision:2387d6fff449587eecbb7e45b2692ca0710b63b9"}
89+
]
90+
```
91+
92+
What this means is that the task, `Linux framework_tests_widgets`, will install
93+
the `goldctl` tool (which is used to interface with Skia Gold) at the specified
94+
revision. If you are adding a new test suite, or adding golden testing to a
95+
test suite that didn't have it before, you will need to add or modify a task in
96+
the `.ci.yaml` file:
97+
98+
```diff
99+
+ properties:
100+
+ dependencies: >-
101+
+ [
102+
+ {"dependency": "goldctl", "version": "git_revision:2387d6fff449587eecbb7e45b2692ca0710b63b9"}
103+
+ ]
104+
```
105+
106+
> [!TIP]
107+
> The exact git revision of `goldctl` should be copied from an existing task.
108+
109+
If a new dependency was added, see [adding a known task name to the `flutter-gold` check](#adding-a-known-task-name-to-the-flutter-gold-check).
110+
111+
### Adding a known task name to the `flutter-gold` check
112+
113+
The `flutter-gold` check is a cron job that is scheduled to run (every 5
114+
minutes) through every open (non-draft) PR across `flutter/flutter` and
115+
`flutter/engine` is checked for tasks that are _known_ to run golden file tests,
116+
and if they are present, the check asks (via a Skia Gold API) if there were any
117+
untriaged images generated, showing a :question: if so, or a :white_check_mark:
118+
if not.
119+
120+
This list is manually curated in the [`flutter/cocoon` codebase](https://github.com/flutter/cocoon/blob/65e89508cad5b6f9622ee072a1178913fed5001e/app_dart/lib/src/request_handlers/push_gold_status_to_github.dart#L123-L144)
121+
and needs to be updated when new tasks are added or removed.
122+
123+
See [#149544](https://github.com/flutter/flutter/pull/149544) for an example of adding a new task to the list
124+
and [#143863](https://github.com/flutter/flutter/issues/143863#issuecomment-2310898513) for a discussion on the topic.
125+
126+
Failure to add a new task to this list will result in the `flutter-gold` check
127+
not running on some PRs (and build breakages as a result).
128+
129+
### Writing and submitting the test
130+
131+
> [!NOTE]
132+
> These instructions are specific to writing golden file tests for
133+
> `package:flutter`. If you are writing integration tests, or tests in another
134+
> repository (such as `flutter/engine`) the specifics will be different; consult
135+
> relevant documentation and/or team members about the process. Examples:
136+
>
137+
> - [`engine > testing > skia_gold_client > README.md`](https://github.com/flutter/engine/blob/main/testing/skia_gold_client/README.md)
138+
> - [`engine > impeller > golden_tests > README.md`](https://github.com/flutter/engine/blob/main/impeller/golden_tests/README.md)
139+
53140
Write your test as a normal test, using `testWidgets` and `await tester.pumpWidget` and so on.
54141

55142
Put a `RepaintBoundary` widget around the part of the subtree that you want to verify. If you don't, the output will be a 2400x1800 image, since the tests by default use an 800x600 viewport with a device pixel ratio of 3.0. If you would like to further control the image size, put a `SizedBox` around your `RepaintBoundary` to set constraints.
@@ -108,10 +195,9 @@ The updated tests can be triaged from these tryjobs, which will cause the pendin
108195

109196
And that’s it! Your new golden file(s) will be checked in as the baseline(s) for your new test(s), and your PR will be ready to merge. :tada:
110197

111-
112198
## Flutter Gold Login
113199

114-
Triage permission is currently restricted to members of *flutter-hackers*. For more information, see [Contributor Access](../Contributor-access.md).
200+
Triage permission is currently restricted to members of _flutter-hackers_. For more information, see [Contributor Access](../Contributor-access.md).
115201
Once you have been added as an authorized user for Flutter Gold, you can log in through the [homepage of the Flutter Gold dashboard](https://flutter-gold.skia.org/) and proceed to triage your image results under [Changelists](https://flutter-gold.skia.org/changelists).
116202

117203
## `flutter gold` Check
@@ -134,10 +220,11 @@ For more context, see [flutter.dev/go/reduce-ci-tests](https://flutter.dev/go/re
134220

135221
## Troubleshooting
136222

137-
* Trouble: the `flutter-gold` is stuck at pending status while all other checks are successful (if they are not, see [flutter-gold check](#flutter-gold-check)).
138-
* Solution: this may be a side-effect of force-pushed commits (`git push -f`) and a known Skia Gold issue (https://issues.skia.org/issues/40044676), typically after a rebase. If this happens, try rebasing or pushing an empty commit without force pushing. This side-effect is flaky.
139-
* Trouble: the `flutter-gold` check posted a message saying "Golden file changes have been found..." but the triage page is empty.
140-
* Solution: this may be another side-effect of force-pushed commits (see above), but may also be a side-effect of untriaged goldens from already submitted PRs. Try rebasing again, or reach out in #hackers-infra on the Discord.
223+
- Trouble: the `flutter-gold` is stuck at pending status while all other checks are successful (if they are not, see [flutter-gold check](#flutter-gold-check)).
224+
- Solution: this may be a side-effect of force-pushed commits (`git push -f`) and a known Skia Gold issue (https://issues.skia.org/issues/40044676), typically after a rebase. If this happens, try rebasing or pushing an empty commit without force pushing. This side-effect is flaky.
225+
- Trouble: the `flutter-gold` check posted a message saying "Golden file changes have been found..." but the triage page is empty.
226+
- Solution: this may be another side-effect of force-pushed commits (see above), but may also be a side-effect of untriaged goldens from already submitted PRs. Try rebasing again, or reach out in #hackers-infra on the Discord.
141227

142228
## Additional Resources
143-
- [Gold APIs used by the Flutter Framework](https://docs.google.com/document/d/1H3CDqT7zBUt4Je2HPQpleYA-drwj2oy0mdPlSdf2d4A/edit?usp=sharing)
229+
230+
- [Gold APIs used by the Flutter Framework](https://docs.google.com/document/d/1H3CDqT7zBUt4Je2HPQpleYA-drwj2oy0mdPlSdf2d4A/edit?usp=sharing)

0 commit comments

Comments
 (0)