Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/actions/flaky-tests-quarantine/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Flaky tests set aside
description: >-
Reads the tests set aside (the open flaky-test issues scripts/flaky-tests-watch.ts marked) once,
with the job's token, and writes them to flaky-tests-quarantine.json in the runner's temporary
folder, where the job's test steps read them (scripts/flaky-tests.ts). The test steps hold no
token and never ask GitHub themselves, so neither does a test they run. A read that fails writes
why, sets nothing aside, and fails nothing.

# The caller checks the repository out and sets up Bun first, and grants `issues: read`.

runs:
using: composite
steps:
- name: The tests set aside
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: bun scripts/flaky-tests.ts quarantine "$RUNNER_TEMP/flaky-tests-quarantine.json"
42 changes: 36 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,8 @@ jobs:
contents: read
# To cancel this run at its first failure (.github/actions/stop-on-failure).
actions: write
# To read the tests set aside (open flaky-test issues, scripts/flaky-tests.ts).
issues: read
env:
PLAYWRIGHT_IMAGE: mcr.microsoft.com/playwright:v1.62.1-noble@sha256:dcc5531e97840b9b5e794f2814476b21571c5124a3fca2267d73041f56e7580e
steps:
Expand All @@ -457,6 +459,9 @@ jobs:
with:
bun-version: 1.4.3
- run: bun install --frozen-lockfile
# The tests set aside, read once with the job's token; the test steps hold none
# (.github/actions/flaky-tests-quarantine). As in every job that runs tests.
- uses: $/.github/actions/flaky-tests-quarantine
# The app's real-browser tests: a running step's words
# under reduced motion, where onboarding's Back lands beside the Mac window's buttons, the name
# step's orb drawn whole under the step dashes, onboarding's reels playing each scene on their
Expand Down Expand Up @@ -500,6 +505,9 @@ jobs:
# onboarding frame reads the generated app config, which `bun test` alone doesn't write (the
# test script's pretest does).
- run: bun run generate:app-config
# Under scripts/flaky-tests.ts, like every real-browser list and the suite's shards: a test
# that fails runs once more, one that then passes is flaky and named in the run's notes, and a
# test set aside (an open flaky-test issue) still runs but does not fail the job.
- run: |
# One file per line, sorted: pull requests that each add a file then merge cleanly.
files=(
Expand Down Expand Up @@ -549,12 +557,13 @@ jobs:
extension/tests/idle-worker.browser.test.ts
extension/tests/recording-mark.browser.test.ts
)
bun scripts/flaky-tests.ts run -- \
docker run --rm --ipc=host \
--volume "$GITHUB_WORKSPACE:$GITHUB_WORKSPACE" --workdir "$GITHUB_WORKSPACE" \
--volume "$(command -v bun):/usr/local/bin/bun:ro" \
--env OPENBOT_APP_BROWSER=1 \
"$PLAYWRIGHT_IMAGE" \
bun test --parallel "${files[@]}"
bun test --parallel --retry=1 "${files[@]}"
# On a failure, cancels the run at once (.github/actions/stop-on-failure).
- if: failure()
uses: $/.github/actions/stop-on-failure
Expand Down Expand Up @@ -708,6 +717,8 @@ jobs:
contents: read
# To cancel this run at its first failure (.github/actions/stop-on-failure).
actions: write
# To read the tests set aside (open flaky-test issues, scripts/flaky-tests.ts).
issues: read
env:
PLAYWRIGHT_IMAGE: mcr.microsoft.com/playwright:v1.62.1-noble@sha256:dcc5531e97840b9b5e794f2814476b21571c5124a3fca2267d73041f56e7580e
TEST_WORKERS: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository && '2' || '8' }}
Expand All @@ -724,6 +735,7 @@ jobs:
bun-version: 1.4.3
- run: bun install --frozen-lockfile
- run: bun run generate:app-config
- uses: $/.github/actions/flaky-tests-quarantine
- run: |
# One file per line, sorted: pull requests that each add a file then merge cleanly.
files=(
Expand Down Expand Up @@ -870,12 +882,13 @@ jobs:
app/tests/work-folded-layout.test.tsx
app/tests/workspace-snapshots-layout.test.tsx
)
bun scripts/flaky-tests.ts run -- \
docker run --rm --ipc=host \
--volume "$GITHUB_WORKSPACE:$GITHUB_WORKSPACE" --workdir "$GITHUB_WORKSPACE" \
--volume "$(command -v bun):/usr/local/bin/bun:ro" \
--env OPENBOT_APP_BROWSER=1 --env OPENBOT_APP_ENGINES="$BROWSER_ENGINE" \
"$PLAYWRIGHT_IMAGE" \
bun test --parallel="$TEST_WORKERS" --timeout="$TEST_TIMEOUT_MS" --shard="$TEST_SHARD" --timings="scripts/browser-timings/$BROWSER_ENGINE.json" --update-timings "${files[@]}"
bun test --parallel="$TEST_WORKERS" --timeout="$TEST_TIMEOUT_MS" --retry=1 --shard="$TEST_SHARD" --timings="scripts/browser-timings/$BROWSER_ENGINE.json" --update-timings "${files[@]}"
# This shard's own durations, which the run wrote over the engine's record: download every
# shard's and merge them to refresh it (scripts/browser-timings.ts).
- if: ${{ !cancelled() }}
Expand All @@ -889,12 +902,13 @@ jobs:
# Only that test: the rest of the file runs in Chromium in the job above. Once, on the first shard.
- if: matrix.engine == 'WebKit' && matrix.shard == 1
run: |
bun scripts/flaky-tests.ts run -- \
docker run --rm --ipc=host \
--volume "$GITHUB_WORKSPACE:$GITHUB_WORKSPACE" --workdir "$GITHUB_WORKSPACE" \
--volume "$(command -v bun):/usr/local/bin/bun:ro" \
--env OPENBOT_APP_BROWSER=1 --env OPENBOT_APP_ENGINES=webkit \
"$PLAYWRIGHT_IMAGE" \
bun test app/tests/connect-your-ai.test.tsx -t "copies with one press"
bun test --retry=1 app/tests/connect-your-ai.test.tsx -t "copies with one press"
# On a failure, cancels the run at once (.github/actions/stop-on-failure).
- if: failure()
uses: $/.github/actions/stop-on-failure
Expand All @@ -914,6 +928,8 @@ jobs:
contents: read
# To cancel this run at its first failure (.github/actions/stop-on-failure).
actions: write
# To read the tests set aside (open flaky-test issues, scripts/flaky-tests.ts).
issues: read
env:
PLAYWRIGHT_IMAGE: mcr.microsoft.com/playwright:v1.62.1-noble@sha256:dcc5531e97840b9b5e794f2814476b21571c5124a3fca2267d73041f56e7580e
steps:
Expand All @@ -926,29 +942,33 @@ jobs:
- run: bun install --frozen-lockfile
- run: bun install --frozen-lockfile
working-directory: desktop
- uses: $/.github/actions/flaky-tests-quarantine
# A list, as in the jobs above, so scripts/ci-changes.ts can tell this job covers the file and a
# change to it does not run it a second time in `tests (changed files)`. Paths from desktop/.
# Under scripts/flaky-tests.ts, as the lists above.
- run: |
files=(
src/setupLayout.approved.browser.test.ts
src/setupLayout.browser.test.ts
src/setupLayout.moveToCloud.browser.test.ts
)
bun scripts/flaky-tests.ts run --root desktop -- \
docker run --rm --ipc=host \
--volume "$GITHUB_WORKSPACE:$GITHUB_WORKSPACE" --workdir "$GITHUB_WORKSPACE/desktop" \
--volume "$(command -v bun):/usr/local/bin/bun:ro" \
--env OPENBOT_APP_BROWSER=1 \
"$PLAYWRIGHT_IMAGE" \
bun test --parallel "${files[@]}"
bun test --parallel --retry=1 "${files[@]}"
# Connect your AI's key field and tab row, in WebKit, the engine the Mac window draws with.
# Only those tests: the rest of the file runs in Chromium in the step above.
- run: |
bun scripts/flaky-tests.ts run --root desktop -- \
docker run --rm --ipc=host \
--volume "$GITHUB_WORKSPACE:$GITHUB_WORKSPACE" --workdir "$GITHUB_WORKSPACE/desktop" \
--volume "$(command -v bun):/usr/local/bin/bun:ro" \
--env OPENBOT_APP_BROWSER=1 --env OPENBOT_APP_ENGINE=webkit \
"$PLAYWRIGHT_IMAGE" \
bun test src/setupLayout.browser.test.ts -t "the key field and the tab row"
bun test --retry=1 src/setupLayout.browser.test.ts -t "the key field and the tab row"
# On a failure, cancels the run at once (.github/actions/stop-on-failure).
- if: failure()
uses: $/.github/actions/stop-on-failure
Expand All @@ -972,6 +992,8 @@ jobs:
contents: read
# To cancel this run at its first failure (.github/actions/stop-on-failure).
actions: write
# To read the tests set aside (open flaky-test issues, scripts/flaky-tests.ts).
issues: read
strategy:
# Every shard runs to the end, so one red run names every failing test, not just the first
# shard's. On a pull request the first failure anywhere stops the whole run instead
Expand Down Expand Up @@ -999,8 +1021,13 @@ jobs:
# pinned by the desktop lockfile rather than the root one.
- run: bun install --frozen-lockfile
working-directory: desktop
# The tests set aside, read once with the job's token (.github/actions/flaky-tests-quarantine).
# A `uses` step: the upstream upgrade runs this job's `run` steps without it, and the suite
# below, which they run, holds no token.
- uses: $/.github/actions/flaky-tests-quarantine
# This shard's tests, failing on a failed test or on a count it cannot read. The floor under the
# count is the suite's, so the `tests` job checks it on the sum of the shards.
# count is the suite's, so the `tests` job checks it on the sum of the shards. A failed test
# runs once more, and a test set aside does not fail the shard (scripts/flaky-tests.ts).
- run: bun run test:ci
# The shard's count, and how long each of its files took.
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
Expand Down Expand Up @@ -1075,6 +1102,8 @@ jobs:
contents: read
# To cancel this run at its first failure (.github/actions/stop-on-failure).
actions: write
# To read the tests set aside (open flaky-test issues, scripts/flaky-tests.ts).
issues: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
Expand All @@ -1088,6 +1117,7 @@ jobs:
working-directory: agent-mastra
- run: bun install --frozen-lockfile
working-directory: desktop
- uses: $/.github/actions/flaky-tests-quarantine
- name: Install Chromium
if: needs.changes.outputs.browser_tests != '[]' || needs.changes.outputs.desktop_browser_tests != '[]'
run: bunx playwright-core install --with-deps --no-shell chromium
Expand Down
61 changes: 61 additions & 0 deletions .github/workflows/flaky-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Flaky tests

# Every 20 minutes: reads the "Flaky tests" notes CI's test steps left on the runs that finished since
# it last looked (scripts/flaky-tests.ts), and keeps one `flaky-test` issue per flaky test
# (scripts/flaky-tests-watch.ts). A test that failed and then passed on its retry opens its issue,
# with an owner and a review date, and is set aside while the issue is open: it still runs, and its
# failures do not fail CI. A test set aside that passes 60 runs in a row first time is released, and
# its issue closed. On a timer rather than after every run, and within a set number of requests: the
# repository's token is shared by every workflow. It reads runs and their notes through the API only;
# nothing here checks out or runs a pull request's code, and runs from forks are left alone.
on:
schedule:
- cron: "*/20 * * * *"
workflow_dispatch:
inputs:
dry_run:
description: Say what would change, and change nothing.
type: boolean
default: true

permissions:
contents: read

# One at a time, so two never write one issue at once.
concurrency:
group: flaky-tests
cancel-in-progress: false

jobs:
watch:
name: flaky tests
runs-on: ubuntu-24.04
timeout-minutes: 10
permissions:
contents: read
# To list the runs that finished, and where this workflow last left off.
actions: read
# To read the notes the test steps left on their jobs.
checks: read
# To open, update, reopen and close the flaky-test issues.
issues: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
with:
bun-version: 1.4.3
no-cache: true
- name: Flaky tests
env:
GH_TOKEN: ${{ github.token }}
WATCHED: CI
# The jobs that run tests: only their notes are read.
JOBS: ^(tests \(|app \(real browser)
DRY_RUN: ${{ github.event_name == 'workflow_dispatch' && inputs.dry_run }}
run: |
set -euo pipefail
args=()
if [ "$DRY_RUN" = true ]; then args+=(--dry-run); fi
bun scripts/flaky-tests-watch.ts "${args[@]}"
3 changes: 3 additions & 0 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,9 @@ jobs:
# CI's `release note` asks for it, to read a pull request's description. It runs on a pull
# request only, so on this push it is skipped and reads nothing.
pull-requests: read
# CI's test jobs ask for it, to read the tests set aside (open flaky-test issues,
# scripts/flaky-tests.ts).
issues: read

# The images, built once from the commit that passed the checks above, and tagged with this
# release's version and `latest`, with the server, computer and supervisor pinned at the tag this
Expand Down
12 changes: 12 additions & 0 deletions api/client-boundary.allow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,18 @@ export const ALLOWED: Allowed[] = [
rule: "third-party",
why: "GitHub's API, for a CI job's log, never OpenBot's server",
},
{
file: "scripts/flaky-tests.ts",
what: "fetch()",
rule: "third-party",
why: "GitHub's API, for the open flaky-test issues that set a test aside, never OpenBot's server",
},
{
file: "scripts/flaky-tests-watch.ts",
what: "fetch()",
rule: "third-party",
why: "GitHub's API, for the notes CI's test jobs left on a run, never OpenBot's server",
},
{
file: "scripts/model-compat.ts",
what: /^(fetch\(\)|\/health|\/api\/agents\/openbot\/generate)$/,
Expand Down
2 changes: 2 additions & 0 deletions scripts/ci-changes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,8 @@ function fullBrowserFiles(
flag,
) ||
/^--timeout=(?:[1-9]\d*|"\$[A-Z_][A-Z0-9_]*")$/.test(flag) ||
// A failed test run once more still runs every file (scripts/flaky-tests.ts).
/^--retry=[1-9]\d*$/.test(flag) ||
(completeShards && flag === '--shard="$TEST_SHARD"') ||
// Recorded durations move a file between shards, never out of them, as long
// as every shard of an engine reads the same record: a fixed path, or one named
Expand Down
3 changes: 3 additions & 0 deletions scripts/ci-run-tests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,12 @@ describe("changed desktop browser tests", () => {
"desktop/src/other.browser.test.ts",
]);
expect(result.status).toBe(0);
// Each run retries a failed test once (scripts/flaky-tests.ts).
expect(result.calls).toEqual([
{
args: [
"test",
"--retry=1",
"./src/setupLayout.browser.test.ts",
"./src/other.browser.test.ts",
],
Expand All @@ -143,6 +145,7 @@ describe("changed desktop browser tests", () => {
"test",
"-t",
"the key field and the tab row",
"--retry=1",
"./src/setupLayout.browser.test.ts",
],
cwd: result.cwd,
Expand Down
28 changes: 24 additions & 4 deletions scripts/ci-run-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
*/
import { existsSync, lstatSync } from "node:fs";
import { isBunTest, unusualPath } from "./ci-changes";
import {
judge,
parseBunOutput,
type Quarantine,
readableBunEnv,
readQuarantine,
report,
} from "./flaky-tests";
import { testsRan } from "./test-floor";

/** A path from the changes job, held to being a test file inside this checkout. */
Expand Down Expand Up @@ -39,6 +47,9 @@ export function testPaths(json: string | undefined, name: string): string[] {
});
}

/** The tests set aside, from the job's list (FLAKY_TESTS_QUARANTINE), read once for every group. */
let quarantine: Quarantine | undefined;

async function runGroup(
label: string,
command: string[],
Expand All @@ -47,16 +58,25 @@ async function runGroup(
): Promise<boolean> {
if (files.length === 0) return true;
console.log(`\n${label}: ${files.join(" ")}`);
const proc = Bun.spawn([...command, ...files], {
quarantine ??= readQuarantine();
// A failed test runs once more; one that then passes is flaky, and named in the run's notes, and
// a test set aside does not fail the group (scripts/flaky-tests.ts).
const proc = Bun.spawn([...command, "--retry=1", ...files], {
cwd: options.cwd,
env: { ...process.env, ...options.env },
env: readableBunEnv({ ...process.env, ...options.env }),
stdout: "inherit",
stderr: "pipe",
});
const stderr = await new Response(proc.stderr).text();
process.stderr.write(stderr);
const status = await proc.exited;
if (status !== 0) return false;
const setAside = quarantine;
const verdict = judge(
parseBunOutput(stderr, options.cwd ?? ""),
await proc.exited,
setAside.tests,
);
process.stdout.write(report(verdict, setAside));
if (verdict.blocking) return false;
const count = testsRan(stderr);
if (!count) {
console.error(
Expand Down
8 changes: 8 additions & 0 deletions scripts/ci-watch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ describe("the tests a failed job's log names", () => {
]);
});

test("leave out the go a retry adds, as the notes of a run name a test", () => {
expect(
failingTests(
"2026-12-04T10:00:00.0000000Z (fail) a group > a test (attempt 2) [12.00ms]\n",
),
).toEqual(["a group > a test"]);
});

test("are none in a log with no failed test", () => {
expect(
failingTests(
Expand Down
Loading
Loading