Skip to content

test(scf-core): merge duplicate vi.mock registrations; ci: drift audit on migration PRs - #571

Merged
thinkclay merged 2 commits into
mainfrom
claude/autonomous
Aug 11, 2026
Merged

thinkclay merged 2 commits into
mainfrom
claude/autonomous

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

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, 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:

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, byte-identical every time.

Each file merged into a single factory that spreads ...actual and 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 returns null. But TestQueryWrapper renders a SafeAreaProvider, 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.ts blamed 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 via UniversalThemeProvider). The exclusion comment now says that instead of the thing that is no longer true.

Guard

The guard test moves from features/office/__tests__/ to packages/scf-core/__tests__/ and covers the whole package. Mutation-checked: appending a second vi.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 lint clean on every file touched (the 7 warnings in discover/profile are pre-existing and in files this PR does not touch).

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.
@thinkclay thinkclay changed the title test(scf-core): merge the last duplicate vi.mock registrations test(scf-core): merge duplicate vi.mock registrations; ci: drift audit on migration PRs Aug 11, 2026
@thinkclay

Copy link
Copy Markdown
Contributor Author

Added a second, unrelated commit to this branch: ci(supabase): run the migration drift audit on migration PRs — partly addressing #559. Happy to split it out if you would rather review it separately.

The finding is more interesting than the change

A migration drift audit already existed: supabase-drift-audit.yml, nightly, against dev, preview and prod. So #559's premise was narrower and worse than stated — the check was there, it was correct, and it had been failing every night with nobody acting on it.

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:

env result
preview clean
prod clean
dev fails — 337 genuinely unapplied (#564, blocked on vault secrets)

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 change

A pull_request trigger scoped to packages/supabase/migrations/**, so a migration-only PR is no longer invisible to database CI.

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 pull_request the job 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 of that issue. Four migrations from this epic reached main and sat unapplied; a check that notices is necessary but not sufficient.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(scf-core): eight more test files register vi.mock twice for the same module

1 participant