Repository navigation
fix(tests): the four red unit tests, and the constraint one of them found - #676
Merged
Merged
Conversation
…ound
`pnpm test:unit` was red on scf-core. Working through the four failures found
one stale test, one test asserting a contract I had already changed, and a
schema defect that had been there since the table was created.
**useApplicationStatusChange** — the test built its own query client,
`{ invalidateQueries }` and nothing else. #648 taught the hook to patch the
cached list optimistically, so it started calling `getQueriesData`, which the
stand-in did not have. Swapped for a real QueryClient: the cache API is real,
`invalidateQueries` is spied on the real method, and the optimistic patch and
its rollback can be asserted against actual cache contents. Two tests added for
exactly that, since neither was covered.
The same test was also named "executes valid non-critical transitions
immediately" and asserted the mutation had fired by the time `changeStatus`
resolved. #648 deliberately stopped that — a non-critical move is held for
UNDO_WINDOW_MS so Undo has something to cancel. I changed the behaviour and did
not update the test; it kept "passing" only because it died earlier, on the
stub. Now it pins both halves: nothing sent during the window, sent after.
**ApplicationsFilters** — asserted a "Clear Filters" button. #624 moved
clear-all out of the filter body and onto the chip strip, so no such button
exists here any more. The assertion is still worth having, so it moves to
filters.test.ts next to the module the screen's `onClearAll` actually calls,
covering EMPTY_FILTERS and the `activeFilterCount > 0` gate.
**office-role-access** — this one was not a stale test. It failed with
PGRST116 on a `.single()`, because the local database held 26 duplicated
(user, role, scope) pairs. The cause:
UNIQUE (role_id, user_id, scope_org_id, scope_team_id)
has never prevented a duplicate. Two NULLs are not equal in a default UNIQUE
constraint, and the table's own CHECK guarantees every legal row has at least
one NULL scope column — so no two rows ever compare as equal. Every seed's
`ON CONFLICT ... DO NOTHING` on this table silently no-opped and appended
another copy instead, and revoking a role by deleting "the" assignment would
leave a duplicate behind and the user still holding it.
Migration 348 collapses the duplicates (oldest wins, deterministic) and
recreates the constraint as UNIQUE NULLS NOT DISTINCT, which is what it always
meant. Verified locally: a duplicate insert is now rejected, and re-running the
002 seed insert reports INSERT 0 0 rather than appending.
Filed as #675, whose acceptance list is deliberately unfinished — the migration
deletes rows, and production has not had it applied.
scf-core 1148/1148. Typecheck 12/12. Lint 10/10.
Closed
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pnpm test:unitwas red onscf-core, which blocks cutting a release. Four failures: one stale test, one test asserting a contract I had already changed and not updated, and — behind the last two — a schema defect that has been there since the table was created.useApplicationStatusChange— a stub that could not notice realityThe test built its own query client:
{ invalidateQueries }and nothing else. #648 taught the hook to patch the cached list optimistically, so it started callinggetQueriesData, which the stand-in did not have.TypeError: queryClient.getQueriesData is not a function.Swapped for a real
QueryClient. The cache API is real,invalidateQueriesis spied on the real method, and the optimistic patch and its rollback can now be asserted against actual cache contents. Two tests added for exactly that, because neither was covered:Same class of problem as the retry stub in #650.
…and a test asserting the contract I changed
That test was called "executes valid non-critical transitions immediately" and asserted the mutation had fired by the time
changeStatusresolved. #648 deliberately stopped that — a non-critical move is held forUNDO_WINDOW_MSso Undo has something to cancel.I changed the behaviour and did not update the test. It kept "passing" in the suite only because it died earlier, on the stub. It now pins both halves of the real contract: nothing sent during the window, sent after.
ApplicationsFilters— the button movedAsserted a
Clear Filtersbutton. #624 moved clear-all out of the filter body and onto the chip strip (onClearAll, gated onactiveFilterCount > 0), so no such button exists in this component any more.The assertion is still worth having, so it moves to
filters.test.ts, next to the module the screen'sonClearAllactually calls — coveringEMPTY_FILTERS, that it leaves the chip strip empty, and the gate. A breadcrumb is left where it used to live.office-role-access— not a stale testThis one was real, and it is the interesting finding. It failed
expected { code: 'PGRST116', … } to be nullon a.single(), because the local database held 26 duplicated(user, role, scope)pairs.core.role_assignmentshas carried this since it was created:It has never prevented a duplicate. Two NULLs are not equal in a default
UNIQUEconstraint, and the table's own CHECK guarantees every legal row has at least one NULL scope column:So no two rows ever compare as equal and the index waves all of them through. Consequences:
ON CONFLICT … DO NOTHINGon this table silently no-opped.002_seed-users.sql:200says-- Skip if role assignment already exists. It could never match; each seed run appended another copy..single()read 500s once a duplicate exists.Migration
348collapses the duplicates (oldest wins, orderedcreated_at, idso it is deterministic) and recreates the constraint asUNIQUE NULLS NOT DISTINCT— PG 15+, and the database is on 17.6. That is the semantics it always meant.Verified locally:
Filed separately as #675. Its acceptance list is deliberately unfinished: the migration deletes rows, and production has not had it applied. Production very likely holds duplicates too and the counts should be inspected before it is run there — that is a call for a human, not something to slip into a merge.
Verification
scf-core--skip-nx-cachetest:unit--skip-nx-cachetypechecklintThe cache mattered: the first full run read 6 of 7 projects from Nx cache, which is exactly how a red suite stays invisible.
🤖 Generated with Claude Code