Skip to content
Closed
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
152 changes: 152 additions & 0 deletions .github/workflows/test-order.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
name: Shuffled test order

on:
schedule:
- cron: "41 8 * * *"
workflow_dispatch:
inputs:
seed:
description: Vitest shuffle seed; defaults to the run number
required: false
type: string

env:
PRIMARY_NODE_VERSION: "22.x"
PNPM_VERSION: "9.15.0"

permissions:
contents: read

concurrency:
group: test-order
cancel-in-progress: false

jobs:
plan:
name: Select shuffled shards
if: github.repository == 'get-bb/bb'
runs-on: blacksmith-4vcpu-ubuntu-2404
timeout-minutes: 5
outputs:
seed: ${{ steps.plan.outputs.seed }}
tests: ${{ steps.plan.outputs.tests }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
- name: Choose seed and shards
id: plan
env:
SEED_INPUT: ${{ inputs.seed }}
run: |
seed="${SEED_INPUT:-$GITHUB_RUN_NUMBER}"
if [[ ! "$seed" =~ ^[0-9]+$ ]]; then
echo "::error::Seed must be a non-negative integer, got '$seed'."
exit 1
fi
echo "seed=$seed" >> "$GITHUB_OUTPUT"
echo "tests=$(node scripts/plan-ci.mjs --full | node -e 'process.stdout.write(JSON.stringify(JSON.parse(require("node:fs").readFileSync(0, "utf8")).tests))')" >> "$GITHUB_OUTPUT"
echo "Shuffle seed: $seed (commit $GITHUB_SHA)" >> "$GITHUB_STEP_SUMMARY"

tests:
name: Shuffled tests (${{ matrix.shard }}, seed ${{ needs.plan.outputs.seed }})
needs: plan
runs-on: blacksmith-4vcpu-ubuntu-2404
timeout-minutes: 40
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.plan.outputs.tests) }}
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Setup workspace tools
uses: ./.github/actions/setup-workspace-tools
with:
node-version: ${{ env.PRIMARY_NODE_VERSION }}
pnpm-version: ${{ env.PNPM_VERSION }}

- name: Restore React Compiler cache
if: ${{ contains(matrix.filter, '--filter=@bb/demo-server') }}
timeout-minutes: 1
continue-on-error: true
uses: ./.github/actions/cache-react-compiler

- name: Restore CI Turbo cache
id: cache
timeout-minutes: 1
continue-on-error: true
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9
env:
SEGMENT_DOWNLOAD_TIMEOUT_MINS: "1"
with:
path: .turbo/cache
key: ${{ runner.os }}-node-${{ env.PRIMARY_NODE_VERSION }}-turbo-${{ hashFiles('pnpm-lock.yaml') }}-test-${{ matrix.shard }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-node-${{ env.PRIMARY_NODE_VERSION }}-turbo-${{ hashFiles('pnpm-lock.yaml') }}-test-${{ matrix.shard }}-
${{ runner.os }}-node-${{ env.PRIMARY_NODE_VERSION }}-turbo-${{ hashFiles('pnpm-lock.yaml') }}-

- name: Restore pnpm cache
id: pnpm-cache
timeout-minutes: 1
continue-on-error: true
uses: ./.github/actions/cache-pnpm

- name: Install dependencies
timeout-minutes: 5
env:
TURBO_CACHE_RESTORE_OUTCOME: ${{ steps.cache.outcome }}
PNPM_CACHE_RESTORE_OUTCOME: ${{ steps.pnpm-cache.outcome }}
APP_SHARD: ${{ startsWith(matrix.shard, 'app-') }}
DEMO_ONLY: ${{ matrix.filter == '--filter=@bb/demo-server' }}
MOBILE_TESTS: ${{ matrix.mobile }}
run: |
filters=()
if [[ "$APP_SHARD" == "true" ]]; then
filters=(--ignore-scripts --filter bb --filter '@bb/app...' --filter '@bb/db...')
elif [[ "$DEMO_ONLY" == "true" ]]; then
filters=(--ignore-scripts --filter bb --filter '@bb/demo-server...' --filter '@bb/db...')
elif [[ "$MOBILE_TESTS" != "true" ]]; then
filters=(--filter '!@bb/mobile')
fi
bash .github/actions/setup-workspace/install-dependencies.sh "${filters[@]}"

- name: Setup Bun
if: ${{ startsWith(matrix.shard, 'packages-') || startsWith(matrix.shard, 'plugins-') }}
timeout-minutes: 4
uses: ./.github/actions/setup-bun
with:
version: "1.3.14"

- name: Install Electron runtime libraries
if: ${{ contains(matrix.filter, '--filter=@bb/desktop') }}
run: |
bash .github/actions/setup-workspace/install-electron-libraries.sh
ELECTRON_RUN_AS_NODE=1 pnpm --filter @bb/desktop exec electron --version

- name: Test in shuffled order
env:
BB_CI_TEST_SHARD: ${{ matrix.vitestShard }}
VITEST_MAX_WORKERS: ${{ (startsWith(matrix.shard, 'server-') || matrix.shard == 'integration') && '4' || '2' }}
run: ${{ contains(matrix.filter, '--filter=@bb/desktop') && 'xvfb-run -a' || '' }} pnpm exec turbo run test ${{ matrix.filter }} --cache-dir="${TURBO_CACHE_DIR:-.turbo/cache}" --output-logs=new-only --summarize --continue --concurrency=4 -- --sequence.shuffle --sequence.seed=${{ needs.plan.outputs.seed }}

- name: Describe reproduction
if: ${{ failure() }}
env:
SEED: ${{ needs.plan.outputs.seed }}
FILTER: ${{ matrix.filter }}
SHARD: ${{ matrix.vitestShard }}
run: |
{
echo "### Order-dependent failure in ${{ matrix.shard }}"
echo
echo "Reproduce at $GITHUB_SHA:"
echo
echo '```bash'
if [[ -n "$SHARD" ]]; then
echo "BB_CI_TEST_SHARD=$SHARD pnpm exec turbo run test $FILTER -- --sequence.shuffle --sequence.seed=$SEED"
else
echo "pnpm exec turbo run test $FILTER -- --sequence.shuffle --sequence.seed=$SEED"
fi
echo '```'
echo
echo "Failing packages print their Vitest failures above; rerun one package with its own --filter to iterate."
} >> "$GITHUB_STEP_SUMMARY"
4 changes: 2 additions & 2 deletions apps/app/src/components/dialogs/ProjectPathDialog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe("ProjectPathDialog machine selection", () => {
);
});

it("preserves the direct single-machine folder flow", () => {
it("preserves the direct single-machine folder flow", async () => {
const onSubmit = vi.fn();
render(
<ProjectPathDialog
Expand All @@ -108,7 +108,7 @@ describe("ProjectPathDialog machine selection", () => {

expect(screen.queryByRole("button", { name: "Machine" })).toBeNull();
fireEvent.click(
screen.getByRole("button", { name: "Choose folder on host_atum" }),
await screen.findByRole("button", { name: "Choose folder on host_atum" }),
);
fireEvent.click(screen.getByRole("button", { name: "Add project" }));

Expand Down
2 changes: 2 additions & 0 deletions apps/app/src/lib/plugin-frontend-boot-catch-up.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
schedulePluginFrontendReconcile,
} from "./plugin-frontend-lazy";

await import("./plugin-frontend");

afterEach(() => {
vi.unstubAllGlobals();
});
Expand Down
2 changes: 2 additions & 0 deletions apps/app/src/lib/plugin-frontend-boot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
schedulePluginFrontendReconcile,
} from "./plugin-frontend-lazy";

await import("./plugin-frontend");

afterEach(() => {
vi.unstubAllGlobals();
});
Expand Down
82 changes: 44 additions & 38 deletions apps/server/test/perf/request-path-statements.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -648,47 +648,53 @@ const REQUEST_PATHS: readonly RequestPath[] = [
},
];

describe.each(GROWTH_AXES)("request path costs as $name grows", (axis) => {
let small: SizedServer;
let large: SizedServer;

beforeAll(async () => {
small = await startSizedServer(axis.small);
large = await startSizedServer(axis.large);
}, FIXTURE_BUILD_TIMEOUT_MS);

afterAll(async () => {
await small.harness.cleanup();
await large.harness.cleanup();
});
describe("request paths in fixture order", { shuffle: false }, () => {
describe.each(GROWTH_AXES)("request path costs as $name grows", (axis) => {
let small: SizedServer;
let large: SizedServer;

beforeAll(async () => {
small = await startSizedServer(axis.small);
large = await startSizedServer(axis.large);
}, FIXTURE_BUILD_TIMEOUT_MS);

afterAll(async () => {
await small.harness.cleanup();
await large.harness.cleanup();
});

it.each(REQUEST_PATHS)(
"$name runs a statement count and returns a response that do not grow",
async (path) => {
small.received.bytes = 0;
const smallStatements = await small.counter.record(() => path.run(small));
large.received.bytes = 0;
const largeStatements = await large.counter.record(() => path.run(large));
const summary = `${path.name}: ${smallStatements.length} statements and ${small.received.bytes} response bytes with ${describeWorld(axis.small)}, ${largeStatements.length} and ${large.received.bytes} with ${describeWorld(axis.large)}`;
expect(largeStatements.length).toBeGreaterThan(0);
if (path.linearResponse?.[axis.name] === undefined) {
expect(large.received.bytes, summary).toBeLessThanOrEqual(
small.received.bytes * RESPONSE_BYTES_GROWTH_LIMIT +
RESPONSE_BYTES_SLACK,
it.each(REQUEST_PATHS)(
"$name runs a statement count and returns a response that do not grow",
async (path) => {
small.received.bytes = 0;
const smallStatements = await small.counter.record(() =>
path.run(small),
);
}
if (path.linearStatements?.[axis.name] === undefined) {
expect(
grownStatements(smallStatements, largeStatements),
summary,
).toEqual([]);
} else {
expect(largeStatements.length, summary).toBeLessThanOrEqual(
smallStatements.length * LINEAR_GROWTH_LIMIT,
large.received.bytes = 0;
const largeStatements = await large.counter.record(() =>
path.run(large),
);
}
},
);
const summary = `${path.name}: ${smallStatements.length} statements and ${small.received.bytes} response bytes with ${describeWorld(axis.small)}, ${largeStatements.length} and ${large.received.bytes} with ${describeWorld(axis.large)}`;
expect(largeStatements.length).toBeGreaterThan(0);
if (path.linearResponse?.[axis.name] === undefined) {
expect(large.received.bytes, summary).toBeLessThanOrEqual(
small.received.bytes * RESPONSE_BYTES_GROWTH_LIMIT +
RESPONSE_BYTES_SLACK,
);
}
if (path.linearStatements?.[axis.name] === undefined) {
expect(
grownStatements(smallStatements, largeStatements),
summary,
).toEqual([]);
} else {
expect(largeStatements.length, summary).toBeLessThanOrEqual(
smallStatements.length * LINEAR_GROWTH_LIMIT,
);
}
},
);
});
});

afterAll(() => {
Expand Down
11 changes: 8 additions & 3 deletions docs/debugging-and-qa.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,14 @@ DESC`.

## Reproducing Test Order Failures

CI's test shards shuffle test files and tests within each file. Vitest prints the seed for
runs that execute; unchanged Turbo tasks can still reuse cached results.
Reproduce a failing package with its logged seed:
Blocking CI runs tests in a stable order. The nightly `Shuffled test order`
workflow (`.github/workflows/test-order.yml`) reruns every Linux test shard on
main with test files and the tests within each file shuffled, so an order
dependency fails that run instead of an unrelated PR. Its seed is the run number
unless a `seed` input is given to a manual run; the job title, the step summary,
and Vitest's `Running tests with seed` line all print it, and a failing shard's
summary gives the exact reproduction command. Batch the failures it finds into
fix PRs. Reproduce a failing package with its logged seed:

```bash
pnpm exec turbo run test --filter=@bb/app -- --sequence.shuffle --sequence.seed=4721 --maxWorkers=2
Expand Down
16 changes: 10 additions & 6 deletions plugins/browser-automation/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ describe("inline browser preview", () => {
const firstRequested = new Promise<void>((resolve) => {
deliverFirst = resolve;
});
let deliverSecond!: () => void;
const secondRequested = new Promise<void>((resolve) => {
deliverSecond = resolve;
});
const slot = renderSlot(directive, props(), {
rpc: {
preview: async () => {
Expand All @@ -73,7 +77,10 @@ describe("inline browser preview", () => {
await firstRequested;
return { session, frame: frame(4) };
}
if (polls === 2) return { session, frame: frame(5, "Checkout") };
if (polls === 2) {
await secondRequested;
return { session, frame: frame(5, "Checkout") };
}
return hang();
},
},
Expand All @@ -85,11 +92,8 @@ describe("inline browser preview", () => {
expect(first.getAttribute("src")).toBe("data:image/jpeg;base64,bytes4");
expect(slot.getByText("shop.test/cart")).toBeTruthy();
expect(slot.getByText("Live")).toBeTruthy();
const second = await slot.findByAltText(
"Live view of Checkout",
{},
{ timeout: 3_000 },
);
deliverSecond();
const second = await slot.findByAltText("Live view of Checkout");
expect(second.getAttribute("src")).toBe("data:image/jpeg;base64,bytes5");
await waitFor(() =>
expect(previewInputs(slot)).toEqual(
Expand Down
Loading
Loading