Minerva RLS suite: add per-role enumeration helper covering all eight roles (spec §9.1) #6

Closed
opened 2026-04-21 01:59:02 +00:00 by claude-bot · 0 comments
Collaborator

Background

Many Minerva RLS test files (legislative, testimony, opponent tracking, shared-signal, poll-watching, phone-bank) parametrize over a subset of roles — typically [canvasser, phone_banker, poll_watcher] for field-role exclusion and one campaign_manager positive path.

No shared fixture exercises the full eight-role set from spec §9.1:

  • platform_admin
  • campaign_manager
  • field_organizer
  • canvasser
  • phone_banker
  • poll_watcher
  • intelligence_analyst
  • data_viewer

A role typo in a new RLS policy ('canvasse' instead of 'canvasser'), a policy-rename drift, or a new-role misclassification would not be caught by the current per-table tests.

Proposed approach

Add a shared helper in services/migrations/tests/conftest.py (or a new services/migrations/tests/fixtures/roles.py):

ALL_ROLES = [
    "platform_admin",
    "campaign_manager",
    "field_organizer",
    "canvasser",
    "phone_banker",
    "poll_watcher",
    "intelligence_analyst",
    "data_viewer",
]

@pytest.fixture
def visibility_assertions(ctx):
    """For each (role, table) tuple, assert row count matches expected set.

    Usage:
        visibility_assertions.assert_only(
            table="tracked_opponents",
            allowed_roles={"platform_admin", "campaign_manager",
                           "field_organizer", "intelligence_analyst",
                           "data_viewer"},
            client_id=..., tenant_scope=...,
        )
    """
    ...

Apply to existing RLS test files as a drop-in supplement (not a replacement — per-table semantics still matter).

Why housekeeping

Cross-cutting test-infrastructure change touching 10+ RLS test files. Not tied to any single Minerva issue; belongs in the cleanup tracker rather than polluting a product-feature issue.

Acceptance criteria

  • Shared fixture or helper in services/migrations/tests/.
  • At least 3 existing RLS test files refactored to use it (legislative, testimony, opponent tracking are good candidates).
  • CI green with the refactor.

Surfaced by

second-opinion reviewer on Minerva PR #310.

## Background Many Minerva RLS test files (legislative, testimony, opponent tracking, shared-signal, poll-watching, phone-bank) parametrize over a subset of roles — typically `[canvasser, phone_banker, poll_watcher]` for field-role exclusion and one `campaign_manager` positive path. No shared fixture exercises the full eight-role set from spec §9.1: - `platform_admin` - `campaign_manager` - `field_organizer` - `canvasser` - `phone_banker` - `poll_watcher` - `intelligence_analyst` - `data_viewer` A role typo in a new RLS policy (`'canvasse'` instead of `'canvasser'`), a policy-rename drift, or a new-role misclassification would not be caught by the current per-table tests. ## Proposed approach Add a shared helper in `services/migrations/tests/conftest.py` (or a new `services/migrations/tests/fixtures/roles.py`): ```python ALL_ROLES = [ "platform_admin", "campaign_manager", "field_organizer", "canvasser", "phone_banker", "poll_watcher", "intelligence_analyst", "data_viewer", ] @pytest.fixture def visibility_assertions(ctx): """For each (role, table) tuple, assert row count matches expected set. Usage: visibility_assertions.assert_only( table="tracked_opponents", allowed_roles={"platform_admin", "campaign_manager", "field_organizer", "intelligence_analyst", "data_viewer"}, client_id=..., tenant_scope=..., ) """ ... ``` Apply to existing RLS test files as a drop-in supplement (not a replacement — per-table semantics still matter). ## Why housekeeping Cross-cutting test-infrastructure change touching 10+ RLS test files. Not tied to any single Minerva issue; belongs in the cleanup tracker rather than polluting a product-feature issue. ## Acceptance criteria - [ ] Shared fixture or helper in `services/migrations/tests/`. - [ ] At least 3 existing RLS test files refactored to use it (legislative, testimony, opponent tracking are good candidates). - [ ] CI green with the refactor. ## Surfaced by `second-opinion` reviewer on Minerva PR #310.
Sign in to join this conversation.
No description provided.