Skip to content

fix(test): stop the RBAC integration suite from sharing the seeded admin - #144

Merged
WhiteMuush merged 1 commit into
chore/deps-august-bumpsfrom
fix/itest-shared-admin-race
Aug 11, 2026
Merged

fix(test): stop the RBAC integration suite from sharing the seeded admin#144
WhiteMuush merged 1 commit into
chore/deps-august-bumpsfrom
fix/itest-shared-admin-race

Conversation

@WhiteMuush

Copy link
Copy Markdown
Owner

Fixes the flaky Integration (DB) job. Surfaced on #142, but the race predates it and has nothing to do with dependencies.

The race

src/lib/rbac/require-permission.itest.ts reassigned the shared seeded admin (admin@datashield.local) to the Viewer preset, then restored Administrator at the end of the test. Its own comment said "Restore Administrator so other suites keep working", which only holds if suites run one at a time.

Vitest runs test files in parallel against the same database. Any suite reading admin.roleId inside that window sees the read-only Viewer set.

How we know that is what happened

On #142, src/app/api/roles/route.itest.ts failed with the admin missing these ten permissions:

alerts:assign, alerts:status, alerts:comment, alerts:close, alerts:remediate, employees:scan, register:manage, register:evidence, reports:export, dashboard:customize

That is exactly the SOC Analyst preset minus its :read entries, in other words precisely what is left over when the actor holds only READ_ONLY, the Viewer definition.

Forcing the admin to Viewer and running that one suite reproduces the CI assertion character for character, same ten strings in the same order. The narrow window does not reproduce by chance on a fast machine: 8 consecutive local runs of the unmodified suite came out green.

The fix

The suite now creates its own company, seeds the presets there, and asserts on that company's Viewer role. It never used the admin user for its assertions in the first place, so the reassignment was dead weight that only created the race.

Verified locally

  • npm run test:integration against a postgres:16 container: 11 files, 19 tests, pass, three consecutive runs
  • npx tsc --noEmit: pass
  • npm run lint: pass

Merge order

Merge this first, then rebase #142 so its Integration (DB) job goes green.

require-permission.itest.ts reassigned the shared admin account to Viewer,
then restored Administrator at the end. That only holds if suites run one at
a time. Vitest runs test files in parallel against the same database, so any
suite reading the admin's role inside that window sees the read-only Viewer
set instead.

This is what broke Integration (DB) on the deps branch: roles/route.itest.ts
reported the admin missing exactly the ten non-read permissions of the SOC
Analyst preset, which is the Viewer set. Forcing the admin to Viewer and
running that suite reproduces the CI output character for character.

The suite now seeds its own company and asserts on that company's Viewer
role. It never touched the admin user for its assertions anyway, the
reassignment was dead weight that only created the race.
@WhiteMuush
WhiteMuush force-pushed the fix/itest-shared-admin-race branch from fcbece6 to 0710499 Compare August 11, 2026 12:59
@WhiteMuush
WhiteMuush changed the base branch from develop to chore/deps-august-bumps August 11, 2026 12:59
@WhiteMuush

Copy link
Copy Markdown
Owner Author

Retargeted onto chore/deps-august-bumps (#142) instead of develop, and rebased.

Reason: the two pull requests each tripped a gate the other one fixes. #142 was red on Integration (DB) because of the race fixed here, and this branch was red on Dependency audit because the js-yaml and nanoid overrides live in #142. That red audit here is worth noting on its own, it independently confirms the audit gate was already broken on develop before any Dependabot pull request touched it.

Stacking them breaks the cycle: this merges into #142, then #142 merges into develop with both fixes and every gate green.

@WhiteMuush
WhiteMuush merged commit 6c69c08 into chore/deps-august-bumps Aug 11, 2026
13 checks passed
@WhiteMuush
WhiteMuush deleted the fix/itest-shared-admin-race branch August 11, 2026 13:05
@github-project-automation github-project-automation Bot moved this from Todo to Done in DataShield Roadmap Aug 11, 2026
WhiteMuush added a commit that referenced this pull request Aug 11, 2026
…142)

* chore(deps): port the august bumps to develop and fix the audit gate

Dependabot opened #139, #140 and #141 against main, which is 64 commits
behind develop. Their lockfiles conflict with develop (next-auth removed,
better-auth added), so the bumps are redone here against the develop tree.

Ported:
- github/codeql-action 4.37.4 to 4.37.6
- @aws-sdk/client-identitystore, @base-ui/react, lucide-react, next 16.3.0
- @types/node, @types/pg, eslint-config-next, tsx

Left out: @tanstack/react-table 8 to 9. It is a breaking major that renames
the row model factories (getCoreRowModel to createCoreRowModel) and needs a
migration of EmployeeTable.tsx. Tracked separately.

The Dependency audit job was already failing on develop before these PRs,
on two high advisories reaching us through transitives:
- js-yaml 4.3.0 via @eslint/eslintrc (GHSA-5p4m-2wfm-xmqj)
- nanoid 3.3.16 via postcss (GHSA-2v37-7h3g-55p8)
Both are pinned through overrides, so npm audit --audit-level=high is clean.

* chore(next): opt out of the AGENTS.md rewrite added in next 16.3

Next 16.3 ships an `agentRules` option, on by default, that makes `next dev`
append a Next-authored block to AGENTS.md on every run. Two problems here:
the block contains a non-ASCII character, which the pre-push ASCII gate
rejects, and the working tree goes dirty on each dev start.

AGENTS.md is ours, so the option is turned off.

* fix(test): stop the RBAC integration suite from sharing the seeded admin (#144)

require-permission.itest.ts reassigned the shared admin account to Viewer,
then restored Administrator at the end. That only holds if suites run one at
a time. Vitest runs test files in parallel against the same database, so any
suite reading the admin's role inside that window sees the read-only Viewer
set instead.

This is what broke Integration (DB) on the deps branch: roles/route.itest.ts
reported the admin missing exactly the ten non-read permissions of the SOC
Analyst preset, which is the Viewer set. Forcing the admin to Viewer and
running that suite reproduces the CI output character for character.

The suite now seeds its own company and asserts on that company's Viewer
role. It never touched the admin user for its assertions anyway, the
reassignment was dead weight that only created the race.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant