fix(whatsapp,roles): self-heal legacy whatsapp_log schema; map underscore role aliases #13

Merged
abiba-bot merged 2 commits from fm/fix-denya-mocklog-roles-20260909 into main 2026-09-09 13:16:35 +00:00
Owner

Captain-approved fix batch (relay #747 follow-up), no-mistakes validated (run 01M233QWPSRVJEQDPC9ENDEDTX, 0 findings, 90 tests green).

1. mock-log 500 (HIGH) — schema drift: the live demo DB's whatsapp_log table predates the columns the app queries (message_text, wa_message_id, ticket_number). ensure_legacy_schema (startup legacy shim) now self-heals legacy whatsapp_log tables idempotently: adds the missing columns, backfills message_text from legacy content where possible, drops the obsolete command column. New producer/consumer test proves a legacy-shaped table gains columns at startup and mock-log returns 200.

2. Role alias gap (MED) — cs_rep / cs_manager / fm_dispatcher (underscore forms) were unmapped in ROLE_ALIASES (only space forms mapped), so startup role normalization could never converge them and frontend exact-match routing sent those users to /tickets. Added the underscore aliases → canonical roles.

Both fixes apply through the app's own startup path so every legacy DB self-heals on deploy — no manual DB surgery. Test user 18 (test@denya.com) itself was deleted from the live DB by firstmate (deployer-owned cleanup, verified gone; all 17 remaining users carry canonical roles).

Captain-approved fix batch (relay #747 follow-up), no-mistakes validated (run 01M233QWPSRVJEQDPC9ENDEDTX, 0 findings, 90 tests green). **1. mock-log 500 (HIGH)** — schema drift: the live demo DB's `whatsapp_log` table predates the columns the app queries (`message_text`, `wa_message_id`, `ticket_number`). `ensure_legacy_schema` (startup legacy shim) now self-heals legacy whatsapp_log tables idempotently: adds the missing columns, backfills `message_text` from legacy content where possible, drops the obsolete `command` column. New producer/consumer test proves a legacy-shaped table gains columns at startup and mock-log returns 200. **2. Role alias gap (MED)** — `cs_rep` / `cs_manager` / `fm_dispatcher` (underscore forms) were unmapped in `ROLE_ALIASES` (only space forms mapped), so startup role normalization could never converge them and frontend exact-match routing sent those users to /tickets. Added the underscore aliases → canonical roles. Both fixes apply through the app's own startup path so every legacy DB self-heals on deploy — no manual DB surgery. Test user 18 (test@denya.com) itself was deleted from the live DB by firstmate (deployer-owned cleanup, verified gone; all 17 remaining users carry canonical roles).
abiba-bot added 2 commits 2026-09-09 13:16:27 +00:00
CT115 (Mumuni relay #747) — two live-instance defects after PR #12:

1. GET /api/whatsapp/mock-log 500'd with a valid admin token:
   'no such column: whatsapp_log.message_text'. The model gained
   message_text/wa_message_id/ticket_number (and dropped command) in
   4afdc36 with no migration, so legacy DBs keep the (command, ...) shape.
   ensure_legacy_schema (startup, app/main.py) now adds the three missing
   columns idempotently and backfills legacy command bodies into
   message_text before dropping the obsolete NOT NULL command column, so
   both the mock-log read path and the ORM write path work on healed DBs.
   New producer/consumer regression (tests/test_whatsapp_log_legacy_heal.py)
   reproduces the exact OperationalError, then asserts 200 + data.

2. ROLE_ALIASES gap: underscore legacy roles (cs_rep, cs_manager,
   fm_dispatcher) were not mapped, so normalize_legacy_user_roles could not
   converge rows like user 18 (test@denya.com, role 'cs_rep') and the
   frontend stranded them on /tickets. Added the underscore aliases; tests
   assert normalize_role('cs_rep') == 'CS Rep' and a cs_rep row converges
   and authenticates.
abiba-bot merged commit 7ca2924191 into main 2026-09-09 13:16:35 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: SyslogSolution/denya-onecare#13