diff --git a/.github/workflows/test-order.yml b/.github/workflows/test-order.yml new file mode 100644 index 00000000000..63c3b29a096 --- /dev/null +++ b/.github/workflows/test-order.yml @@ -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" diff --git a/apps/app/src/components/dialogs/ProjectPathDialog.test.tsx b/apps/app/src/components/dialogs/ProjectPathDialog.test.tsx index 96a17ae80c2..66f2923aaf2 100644 --- a/apps/app/src/components/dialogs/ProjectPathDialog.test.tsx +++ b/apps/app/src/components/dialogs/ProjectPathDialog.test.tsx @@ -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( { 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" })); diff --git a/apps/app/src/lib/plugin-frontend-boot-catch-up.test.ts b/apps/app/src/lib/plugin-frontend-boot-catch-up.test.ts index b4eb440dffb..89f918b713c 100644 --- a/apps/app/src/lib/plugin-frontend-boot-catch-up.test.ts +++ b/apps/app/src/lib/plugin-frontend-boot-catch-up.test.ts @@ -8,6 +8,8 @@ import { schedulePluginFrontendReconcile, } from "./plugin-frontend-lazy"; +await import("./plugin-frontend"); + afterEach(() => { vi.unstubAllGlobals(); }); diff --git a/apps/app/src/lib/plugin-frontend-boot.test.ts b/apps/app/src/lib/plugin-frontend-boot.test.ts index 336060db6fa..747ef3ab758 100644 --- a/apps/app/src/lib/plugin-frontend-boot.test.ts +++ b/apps/app/src/lib/plugin-frontend-boot.test.ts @@ -8,6 +8,8 @@ import { schedulePluginFrontendReconcile, } from "./plugin-frontend-lazy"; +await import("./plugin-frontend"); + afterEach(() => { vi.unstubAllGlobals(); }); diff --git a/apps/server/test/perf/request-path-statements.test.ts b/apps/server/test/perf/request-path-statements.test.ts index d47396332cf..a80883c1b54 100644 --- a/apps/server/test/perf/request-path-statements.test.ts +++ b/apps/server/test/perf/request-path-statements.test.ts @@ -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(() => { diff --git a/docs/debugging-and-qa.md b/docs/debugging-and-qa.md index 7c8f31c47df..12b3ed5b088 100644 --- a/docs/debugging-and-qa.md +++ b/docs/debugging-and-qa.md @@ -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 diff --git a/plugins/browser-automation/app.test.tsx b/plugins/browser-automation/app.test.tsx index d0a72cf2fc4..7b19647829e 100644 --- a/plugins/browser-automation/app.test.tsx +++ b/plugins/browser-automation/app.test.tsx @@ -65,6 +65,10 @@ describe("inline browser preview", () => { const firstRequested = new Promise((resolve) => { deliverFirst = resolve; }); + let deliverSecond!: () => void; + const secondRequested = new Promise((resolve) => { + deliverSecond = resolve; + }); const slot = renderSlot(directive, props(), { rpc: { preview: async () => { @@ -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(); }, }, @@ -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( diff --git a/plugins/connect/app.test.tsx b/plugins/connect/app.test.tsx index b7796a6dbd3..eaebf39a551 100644 --- a/plugins/connect/app.test.tsx +++ b/plugins/connect/app.test.tsx @@ -93,6 +93,12 @@ const signedInAccount = { }, }; +async function clickSetUp(slot: ReturnType) { + const setUp = await slot.findByRole("button", { name: "Set up" }); + await waitFor(() => expect(setUp.hasAttribute("disabled")).toBe(false)); + fireEvent.click(setUp); +} + function pendingLogin(state = "pending", message: string | null = null) { return { id: "login-1", @@ -1046,7 +1052,7 @@ describe("connect setup guide section", () => { }, ); - fireEvent.click(await slot.findByRole("button", { name: "Set up" })); + await clickSetUp(slot); await slot.findByRole("link", { name: "getbb.app" }); expect(onSetupStarted).toHaveBeenCalledOnce(); expect(slot.navigateCalls).toContainEqual({ @@ -1090,7 +1096,7 @@ describe("connect setup guide section", () => { }, ); - fireEvent.click(await slot.findByRole("button", { name: "Set up" })); + await clickSetUp(slot); const showCode = await slot.findByRole("button", { name: "Show pairing code", }); @@ -1144,7 +1150,7 @@ describe("connect setup guide section", () => { }, ); - fireEvent.click(await slot.findByRole("button", { name: "Set up" })); + await clickSetUp(slot); const toggle = await slot.findByRole("button", { name: "Have a pairing code?", }); @@ -1203,7 +1209,7 @@ describe("connect setup guide section", () => { }, ); - fireEvent.click(await slot.findByRole("button", { name: "Set up" })); + await clickSetUp(slot); fireEvent.click( await slot.findByRole("button", { name: "Have a pairing code?" }), ); @@ -1254,7 +1260,7 @@ describe("connect setup guide section", () => { }, ); - fireEvent.click(await slot.findByRole("button", { name: "Set up" })); + await clickSetUp(slot); fireEvent.click( await slot.findByRole("button", { name: "Have a pairing code?" }), ); @@ -1309,10 +1315,7 @@ describe("connect setup guide section", () => { ); const setUp = await slot.findByRole("button", { name: "Set up" }); - await waitFor(() => - expect(slot.rpcCalls.map((call) => call.method)).toContain("status"), - ); - await act(async () => {}); + await waitFor(() => expect(setUp.hasAttribute("disabled")).toBe(false)); vi.useFakeTimers(); await act(async () => fireEvent.click(setUp)); await act(async () => vi.advanceTimersByTimeAsync(2_000)); @@ -1349,10 +1352,7 @@ describe("connect setup guide section", () => { ); const setUp = await slot.findByRole("button", { name: "Set up" }); - await waitFor(() => - expect(slot.rpcCalls.map((call) => call.method)).toContain("status"), - ); - await act(async () => {}); + await waitFor(() => expect(setUp.hasAttribute("disabled")).toBe(false)); vi.useFakeTimers(); await act(async () => fireEvent.click(setUp)); await act(async () => vi.advanceTimersByTimeAsync(2_000)); @@ -1425,10 +1425,7 @@ describe("connect setup guide section", () => { ); const setUp = await slot.findByRole("button", { name: "Set up" }); - await waitFor(() => - expect(slot.rpcCalls.map((call) => call.method)).toContain("status"), - ); - await act(async () => {}); + await waitFor(() => expect(setUp.hasAttribute("disabled")).toBe(false)); fireEvent.click(setUp); await slot.findByText("bb connect is on"); slot.getByText("https://workstation.getbb.app"); diff --git a/plugins/connect/app.tsx b/plugins/connect/app.tsx index ab600aaf6a5..a265be675e5 100644 --- a/plugins/connect/app.tsx +++ b/plugins/connect/app.tsx @@ -2433,7 +2433,9 @@ function ConnectSetupGuideSection({ type="button" size="sm" variant="outline" - disabled={starting || turningOn} + disabled={ + starting || turningOn || (status === null && loadError === null) + } onClick={setUp} > {starting || turningOn ? (