From 0a66c6c0d9536d12578cd8f2410e21005ef1c100 Mon Sep 17 00:00:00 2001 From: EugeniyKiyashko Date: Fri, 4 Dec 2026 13:37:12 +0400 Subject: [PATCH 1/5] Playwright(demos e2e): collect flaky test candidates and report them in the repository monitor --- .github/workflows/repository-check.yml | 68 ++++++++++++------- .github/workflows/visual-tests-demos.yml | 63 +++++++++++++++++ apps/demos/README.md | 2 +- apps/demos/playwright.config.ts | 5 ++ tools/flaky-test-reporter/src/main.test.ts | 8 +++ tools/flaky-test-reporter/src/main.ts | 16 ++++- .../flaky-test-reporter/src/markdown.test.ts | 6 ++ tools/flaky-test-reporter/src/markdown.ts | 6 +- tools/flaky-test-reporter/src/report.test.ts | 8 +++ tools/flaky-test-reporter/src/report.ts | 9 ++- 10 files changed, 159 insertions(+), 32 deletions(-) diff --git a/.github/workflows/repository-check.yml b/.github/workflows/repository-check.yml index 6ea1d2e9597b..ea618d236004 100644 --- a/.github/workflows/repository-check.yml +++ b/.github/workflows/repository-check.yml @@ -46,37 +46,55 @@ jobs: run: | # tee opens the log before the tool runs, so the directory must already exist. mkdir -p "$GITHUB_WORKSPACE/artifacts" - report="$GITHUB_WORKSPACE/artifacts/flaky-tests-report.json" - markdown="$GITHUB_WORKSPACE/artifacts/flaky-tests-report.md" - log="$GITHUB_WORKSPACE/artifacts/collect.log" - # --silent keeps pnpm's own banner out of the summary; 2>&1 keeps the tool's warnings in. - # tee stores the plain text for the summary, then sed turns the tool's warnings into - # GitHub annotations so they surface on the run page. - pnpm --silent --filter flaky-test-reporter run collect -- \ - --repo "${{ github.repository }}" \ - --workflow playwright_tests.yml \ - --artifact flaky-candidates \ - --branch "${{ github.ref_name }}" \ - --window-hours "$WINDOW_HOURS" \ - --out-json "$report" \ - --out-markdown "$markdown" 2>&1 \ - | tee "$log" \ - | sed -e 's/^warning: /::warning::/' -e 's/^Collection failed: /::error::/' + # One report per workflow. The suffix names its files, the label its summary section, and + # the rest of the arguments go to the tool. + collect_flaky() { + suffix="$1" + label="$2" + shift 2 + log="$GITHUB_WORKSPACE/artifacts/collect$suffix.log" - { - echo "## Flaky test candidates" - echo "" - echo '```' - cat "$log" - echo '```' - } >> "$GITHUB_STEP_SUMMARY" + # --silent keeps pnpm's own banner out of the summary; 2>&1 keeps the tool's warnings in. + # tee stores the plain text for the summary, then sed turns the tool's warnings into + # GitHub annotations so they surface on the run page. + pnpm --silent --filter flaky-test-reporter run collect -- \ + --repo "${{ github.repository }}" \ + --artifact flaky-candidates \ + --branch "${{ github.ref_name }}" \ + --window-hours "$WINDOW_HOURS" \ + --out-json "$GITHUB_WORKSPACE/artifacts/flaky-tests-report$suffix.json" \ + --out-markdown "$GITHUB_WORKSPACE/artifacts/flaky-tests-report$suffix.md" \ + "$@" 2>&1 \ + | tee "$log" \ + | sed -e 's/^warning: /::warning::/' -e 's/^Collection failed: /::error::/' + + { + echo "## Flaky test candidates: $label" + echo "" + echo '```' + cat "$log" + echo '```' + } >> "$GITHUB_STEP_SUMMARY" + } + + collect_flaky "" "component tests" --workflow playwright_tests.yml + # Both reports go into one issue body, which is capped at 65,536 characters: the demos list + # is shorter. + collect_flaky "-demos" "demos" --workflow visual-tests-demos.yml \ + --title "Flaky Test Candidates (Demos)" --max-tests 10 # Multiline output form, so the markdown crosses the job boundary as-is. The delimiter # must not occur in the content, which markdown headings and tables never produce. + # A report the tool did not write leaves out its section only. { echo 'details<> "$GITHUB_OUTPUT" @@ -88,6 +106,8 @@ jobs: path: | ${{ github.workspace }}/artifacts/flaky-tests-report.json ${{ github.workspace }}/artifacts/collect.log + ${{ github.workspace }}/artifacts/flaky-tests-report-demos.json + ${{ github.workspace }}/artifacts/collect-demos.log retention-days: 7 if-no-files-found: ignore diff --git a/.github/workflows/visual-tests-demos.yml b/.github/workflows/visual-tests-demos.yml index 1861d3044f07..3e3bcb5065c8 100644 --- a/.github/workflows/visual-tests-demos.yml +++ b/.github/workflows/visual-tests-demos.yml @@ -523,6 +523,9 @@ jobs: # The default blob name is built from the test paths only, so jobs that differ by theme or # shard alone would write the same zip and overwrite each other once merged. PLAYWRIGHT_BLOB_OUTPUT_NAME: report-${{ env.PLAYWRIGHT_JOB_NAME }}.zip + # tools/playwright/flakyReporter.ts stamps every flaky test it records with the job it ran in. + FLAKY_REPORT_JOB: ${{ matrix.CONSTEL }}-${{ matrix.STRATEGY }}-${{ matrix.THEME }} + FLAKY_REPORT_BASE_BRANCH: ${{ github.base_ref || github.event.merge_group.base_ref || github.ref_name }} run: pnpm run test-playwright - name: Run Playwright accessibility tests (jQuery) @@ -566,6 +569,15 @@ jobs: path: ${{ github.workspace }}/apps/demos/testing/artifacts/playwright/test-results if-no-files-found: ignore + - name: Upload flaky test report + if: always() && matrix.STRATEGY == 'screenshots' + uses: actions/upload-artifact@v7 + with: + name: playwright-flaky-report-${{ env.PLAYWRIGHT_JOB_NAME }} + path: ${{ github.workspace }}/apps/demos/testing/artifacts/playwright/flaky-report.json + retention-days: 1 + if-no-files-found: ignore + # One folder at repository paths: the new etalons the tests wrote, and the etalons of the failed # shots that tools/playwright/etalonCollector.ts collected. - name: Collect etalons @@ -743,6 +755,9 @@ jobs: # The default blob name is built from the test paths only, so jobs that differ by theme or # shard alone would write the same zip and overwrite each other once merged. PLAYWRIGHT_BLOB_OUTPUT_NAME: report-${{ env.PLAYWRIGHT_JOB_NAME }}.zip + # tools/playwright/flakyReporter.ts stamps every flaky test it records with the job it ran in. + FLAKY_REPORT_JOB: ${{ matrix.CONSTEL }}-screenshots-${{ matrix.THEME }} + FLAKY_REPORT_BASE_BRANCH: ${{ github.base_ref || github.event.merge_group.base_ref || github.ref_name }} run: pnpm run test-playwright # A test that writes a missing etalon passes (updateSnapshots: 'missing'), so this step fails the job @@ -775,6 +790,15 @@ jobs: path: ${{ github.workspace }}/apps/demos/testing/artifacts/playwright/test-results if-no-files-found: ignore + - name: Upload flaky test report + if: always() + uses: actions/upload-artifact@v7 + with: + name: playwright-flaky-report-${{ env.PLAYWRIGHT_JOB_NAME }} + path: ${{ github.workspace }}/apps/demos/testing/artifacts/playwright/flaky-report.json + retention-days: 1 + if-no-files-found: ignore + # One folder at repository paths: the new etalons the tests wrote, and the etalons of the failed # shots that tools/playwright/etalonCollector.ts collected. - name: Collect etalons @@ -820,6 +844,7 @@ jobs: etalons_react: /^playwright-etalons-react\(/, etalons_vue: /^playwright-etalons-vue\(/, etalons_angular: /^playwright-etalons-angular\(/, + flaky: /^playwright-flaky-report-/, }; for (const [outputName, pattern] of Object.entries(artifactGroups)) { @@ -921,6 +946,44 @@ jobs: pattern: playwright-etalons-angular(* delete-merged: true + - name: Download flaky test reports + if: steps.playwright-artifacts.outputs.flaky == 'true' + uses: actions/download-artifact@v8 + with: + pattern: playwright-flaky-report-* + path: ${{ github.workspace }}/flaky-reports + + # The file tools/flaky-test-reporter collects from every run of this workflow (repository-check.yml). + - name: Build flaky candidates report + if: steps.playwright-artifacts.outputs.flaky == 'true' + run: | + mkdir -p artifacts + report=artifacts/flaky-candidates.json + find flaky-reports -type f -name flaky-report.json -print0 \ + | xargs -0 jq -s '{ schemaVersion: 1, candidates: (map(.candidates) | add) }' \ + > "$report" + + { + echo "## Flaky tests" + echo "" + if [ "$(jq '.candidates | length' "$report")" -eq 0 ]; then + echo "_none_" + else + echo "| Test | Job |" + echo "|---|---|" + jq -r '.candidates[] | "| \(.test | gsub("\\|"; "\\|")) | \(.sourceJob) |"' "$report" + fi + } >> "$GITHUB_STEP_SUMMARY" + + - name: Upload flaky candidates report + if: steps.playwright-artifacts.outputs.flaky == 'true' + uses: actions/upload-artifact@v7 + with: + name: flaky-candidates + path: ${{ github.workspace }}/artifacts/flaky-candidates.json + retention-days: 7 + if-no-files-found: ignore + - name: Merge jQuery accessibility reports if: needs.playwright-jquery.result == 'failure' uses: actions/upload-artifact/merge@v7 diff --git a/apps/demos/README.md b/apps/demos/README.md index 3b8692987543..9d2ddf77ff8c 100644 --- a/apps/demos/README.md +++ b/apps/demos/README.md @@ -195,7 +195,7 @@ gh run download -n playwright-traces -D ci-traces pnpm exec playwright show-report ci-report ``` -A failed comparison uploads its `-expected`, `-actual` and `-diff` images with the trace. On CI a failed test runs once more; a test that passes then is listed under "flaky" and does not fail the job. +A failed comparison uploads its `-expected`, `-actual` and `-diff` images with the trace. On CI a failed test runs once more; a test that passes then is listed under "flaky" and does not fail the job. It is not forgotten either: the job marks it with a "Flaky test" warning, the run lists the flaky tests of every job in its summary and keeps them in its `flaky-candidates` artifact, and `repository-check.yml` adds those up over 72 hours in the repository monitor issue, in a section of its own ("Flaky tests" in `e2e/playwright/README.md` describes the same for the component tests). ## Accessibility Tests diff --git a/apps/demos/playwright.config.ts b/apps/demos/playwright.config.ts index 28f2cee5e900..3e97b38ed9cb 100644 --- a/apps/demos/playwright.config.ts +++ b/apps/demos/playwright.config.ts @@ -59,10 +59,15 @@ export default defineConfig({ ? [ ['list'], ['blob', { outputDir: './testing/artifacts/playwright/blob-report' }], + // Before the flaky reporter: its annotations share the step's limit of 10 warnings. ['../../tools/playwright/etalonCollector.ts', { outputDir: './testing/artifacts/playwright/collected-etalons', repositoryRoot: '../..', }], + ['../../tools/playwright/flakyReporter.ts', { + outputFile: './testing/artifacts/playwright/flaky-report.json', + defaultTheme: THEME, + }], ] : [['list']], timeout: 60000, diff --git a/tools/flaky-test-reporter/src/main.test.ts b/tools/flaky-test-reporter/src/main.test.ts index 55b38066c365..c1750e8398fd 100644 --- a/tools/flaky-test-reporter/src/main.test.ts +++ b/tools/flaky-test-reporter/src/main.test.ts @@ -30,6 +30,14 @@ describe('parseArgs', () => { }); }); + it('keeps the default heading and test cap unless given', () => { + expect(parseArgs(flags)).toMatchObject({ title: 'Flaky Test Candidates', maxTests: 20 }); + expect(parseArgs([...flags, '--title', 'Demos', '--max-tests', '10'])).toMatchObject({ + title: 'Demos', + maxTests: 10, + }); + }); + it('parses identically when invoked through `pnpm run