Skip to content

Flaky unit test: compute-ledger migration-trigger check depends on readdir order #2170

Open

Description

@neuromechanist

backend/test/compute-ledger.test.ts has a test whose result depends on the order in which the operating system lists a directory, so it fails intermittently on Linux runners.

The test: "migration 0114 creates the triggers on compute_pools, and migration 0130 only replaces the identity one with its anonymizing exception".
It collects the files that create a trigger on compute_pools through the helper sources(), which walks backend/src, backend/scripts, src, shared and scripts with readdirSync(dir, { withFileTypes: true }) and appends entries in the order returned.
readdirSync does not sort: the order is whatever the filesystem returns (sorted on macOS APFS, not guaranteed on Linux).
The assertion then expects the two migrations in a fixed order: expect(files.map((f) => f.path)).toEqual([0114_compute_ledger.sql, 0130_compute_anonymise.sql]).

Observed: one failure on a pull request run in the unit-pure shard 1/6 (run 43618622350 on nemarOrg/nemar-cli, 2026-11-14), where the files arrived with 0130 first; the rerun of the same job passed, the same test passed in five other recent runs, and it passes locally on macOS.

Suggested fix: sort the entries inside walk (for example readdirSync(...).sort((a, b) => a.name.localeCompare(b.name))), or sort files by path before comparing, so the assertion tests the migrations and not the filesystem.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions