Repository navigation
test(scf-core): merge duplicate vi.mock registrations; ci: drift audit on migration PRs - #571
Conversation
Closes #566. Eight files outside features/office each registered vi.mock('@scaffald/ui') more than once — two of them three times. Two registrations for one module do not combine: one factory wins, and which one is not stable across runs, so whichever lost took its stubs with it. Baseline, three runs of the same seven files on an unchanged tree: run 1 -> 28 passed, 13 failed run 2 -> 39 passed, 2 failed run 3 -> 12 passed, 29 failed After: ten consecutive runs, 43 passed / 0 failed, identical every time. Each merged into one factory that spreads `...actual` and returns every stub — not by deleting a registration, since each usually provided something the others did not. Two findings while doing it. UserProfilePanel had two assertions that could only ever pass by accident: `expect(container.firstChild).toBeNull()` for a component that returns null. TestQueryWrapper renders a SafeAreaProvider, so the container always has a child div regardless — the assertion passed only when something upstream threw, which the mock race was making happen intermittently. They now assert the panel itself is absent. That is a test that was wrong before this change and would have kept passing at random. PortfolioManager stays excluded. vitest.config.ts blamed its exclusion on exactly these duplicate mocks, so re-enabling it was the obvious next step — but it still fails to transform, on an unrelated unresolvable import (`expo-router/react-navigation`, reached via UniversalThemeProvider). The exclusion comment now says that instead. The guard test moves from features/office/ to packages/scf-core/ and covers the whole package. Mutation-checked: reintroducing a duplicate registration turns it red. Office + utils suites: 263 passed / 0 failed. Typecheck clean.
Partly addresses #559. The audit already existed — supabase-drift-audit.yml runs nightly against dev, preview and prod — so the gap was narrower and worse than the issue described: the check was there, it was correct, and it had been failing every night without anyone acting on it. It was failing for real reasons. After applying 343 and 344 everywhere and 339/340/341 to dev, a dispatched run gives: preview clean prod clean dev fails — 337 is genuinely unapplied (#564, blocked on vault secrets) which is the first green preview/prod in at least five days of runs. This adds a `pull_request` trigger scoped to `packages/supabase/migrations/**`, so a migration-only PR is no longer invisible to database CI. What a PR can assert is narrower than what the nightly can, and the job now distinguishes them. A PR *adding* a migration is supposed to be unapplied everywhere, so failing on "Would push these migrations" would leave this check permanently red on exactly the PRs it exists to guard. On pull_request it therefore asserts only the two real drift signals — remote versions missing from the repo, and local migrations that would be inserted before the last applied one — and reports the unapplied set as a notice. The "not yet applied" failure stays nightly, where it means something. This does not close #559: nothing here makes a merged migration actually get applied, which is the larger half.
|
Added a second, unrelated commit to this branch: The finding is more interesting than the changeA migration drift audit already existed: It was failing for real reasons. After applying 343 and 344 to all three environments and 339/340/341 to dev, a dispatched run gives:
That is the first green preview/prod in at least five days of nightly runs, and dev's failure is the correct answer rather than noise. The changeA One nuance worth reviewing: a PR adding a migration is supposed to be unapplied everywhere. Failing on "Would push these migrations" would leave this check permanently red on exactly the PRs it exists to guard. So on This does not close #559Nothing here makes a merged migration actually get applied, which is the larger half of that issue. Four migrations from this epic reached |
Closes #566.
Eight files outside
features/officeeach registeredvi.mock('@scaffald/ui')more than once — two of them three times. Two registrations for one module do not combine: one factory wins, which one is not stable across runs, and whichever lost took its stubs with it.Before and after
Three runs of the same seven files, unchanged tree:
After: ten consecutive runs, 43 passed / 0 failed, byte-identical every time.
Each file merged into a single factory that spreads
...actualand returns every stub — not by deleting a registration, since each usually provided something the others did not.Two things worth reviewing
UserProfilePanel had two assertions that could only ever pass by accident.
expect(container.firstChild).toBeNull(), for a component that returnsnull. ButTestQueryWrapperrenders aSafeAreaProvider, so the container always has a child div regardless of what the component returns — the assertion could only pass when something upstream threw, which the mock race was making happen intermittently. They now assert the panel itself is absent. This was a wrong test before this PR, and it would have kept passing at random.PortfolioManager stays excluded.
vitest.config.tsblamed its exclusion on exactly these duplicate mocks, so re-enabling it was the obvious next step — I tried, and it still fails to transform on an unrelated unresolvable import (expo-router/react-navigation, reached viaUniversalThemeProvider). The exclusion comment now says that instead of the thing that is no longer true.Guard
The guard test moves from
features/office/__tests__/topackages/scf-core/__tests__/and covers the whole package. Mutation-checked: appending a secondvi.mock('@scaffald/ui')to any file turns it red.Note on method
My first pass scripted the merge across all eight files. It broke four of them — the script kept the first factory's local consts while appending later factories' return bodies, which reference their own consts. I reverted those four and merged them by hand. Worth mentioning because the four that scripted cleanly are only trustworthy because the other four failed loudly rather than subtly.
Verification
Office + utils suites 263 passed / 0 failed; scf-core typecheck clean;
biome lintclean on every file touched (the 7 warnings indiscover/profileare pre-existing and in files this PR does not touch).