Skip to content

fix(web): add 3 missing audit actions + FarmLogo entityType to filter/labels (#247) - #255

Merged
mforce merged 1 commit into
mainfrom
f247-audit-action-drift
Jul 28, 2026
Merged

mforce merged 1 commit into
mainfrom
f247-audit-action-drift

Conversation

@mforce

@mforce mforce commented Jul 28, 2026

Copy link
Copy Markdown
Owner

Fixes #247 — the audit-log action filter + entityType labels drifted from the server.

Gap (pre-existing, surfaced by the #182 B5 review — not a regression)

The server emits 31 distinct audit.WriteAsync action codes; the client's typed AUDIT_ACTION_VALUES listed 28, silently dropping three real writes from the /audit action filter (rows showed only under All actions):

Action Handler entityType
Account.SetLogo SetFarmLogoHandler FarmLogo
Account.RemoveLogo RemoveFarmLogoHandler FarmLogo
Account.UpdateSettings UpdateFarmSettingsHandler Account

And logo rows carried entityType = "FarmLogo", which was not in ENTITY_TYPE_VALUES, so entityTypeLabel degraded it to the raw FarmLogo string.

Fix (client-side only, exactly per the issue)

  • enums.ts — add the 3 codes to AUDIT_ACTION_VALUES + AUDIT_ACTION_KEYS, and FarmLogo to ENTITY_TYPE_VALUES + ENTITY_TYPE_KEYS. The as const satisfies Record<Union, EnumsKey> maps keep values↔keys exhaustive at compile time; the ENUMS registry auto-covers the new values in enums.test.
  • en/es/tl — friendly labels, machine-drafted es/tl matching the existing audit-label style:
    key en es tl
    auditAction.Account.SetLogo Farm logo set Logotipo de la granja establecido Na-set ang logo ng bukid
    auditAction.Account.RemoveLogo Farm logo removed Logotipo de la granja eliminado Naalis ang logo ng bukid
    auditAction.Account.UpdateSettings Farm settings updated Configuración de la granja actualizada Na-update ang mga setting ng bukid
    entityType.FarmLogo Farm logo Logotipo de la granja Logo ng bukid

Tests

  • AuditPage.test: the 3 actions are now offered as filterable options (labelled + value-preserved); a FarmLogo row renders the friendly label, not the raw code. Mutation-probed (removing the enums entries fails both).
  • npm run test 1177 green · typecheck clean · build ok · i18n:scan 3 (false positives) · catalogParity + enums registry green.

Out of scope / still tracked on #247

The root cause — a hand-maintained client action list (#84 magic-strings debt) that can silently drift from the server — remains. #247's longer-term prevention (derive/validate AUDIT_ACTION_VALUES against a server-emitted enum or /audit/actions metadata) is a separate, larger change, left for that issue.

Not included

Unrelated local working-tree edits (deploy/docker-compose.yml, web/vite.config.ts) deliberately not in this branch.

…e filter/labels (#247)

The server emits 31 distinct audit action codes; the client's typed
AUDIT_ACTION_VALUES listed 28, silently dropping three real writes from the
/audit action filter (rows showed only under 'All actions'):
- Account.SetLogo      (SetFarmLogoHandler,    entityType FarmLogo)
- Account.RemoveLogo   (RemoveFarmLogoHandler, entityType FarmLogo)
- Account.UpdateSettings (UpdateFarmSettingsHandler, entityType Account)

And logo rows carried entityType 'FarmLogo', absent from ENTITY_TYPE_VALUES,
so entityTypeLabel degraded it to the raw 'FarmLogo' string.

- enums.ts: add the 3 codes to AUDIT_ACTION_VALUES + AUDIT_ACTION_KEYS, and
  FarmLogo to ENTITY_TYPE_VALUES + ENTITY_TYPE_KEYS (the satisfies maps keep
  values/keys exhaustive at compile time; the ENUMS registry auto-covers them
  in enums.test).
- en/es/tl: friendly enums:auditAction.* + enums:entityType.FarmLogo labels
  ('Farm logo set' / 'Farm logo removed' / 'Farm settings updated' / 'Farm
  logo'), machine-drafted es/tl matching the existing audit-label style.
- AuditPage.test: the 3 actions are now offered as filterable options
  (labelled + value-preserved), and a FarmLogo row renders the friendly label
  not the raw code. Mutation-probed.

Pre-existing drift surfaced by the #182 B5 review, not a regression. The
root cause (hand-maintained client action list, #84 magic-strings debt) and
its longer-term server-derived-enum prevention remain tracked on #247.
@mforce

mforce commented Jul 28, 2026

Copy link
Copy Markdown
Owner Author

Review — unanimous approve (codex + 2 Claude agents + pi)

Reviewer Verdict
codex ✅ approve — no findings (ran its own repo-aware standards+spec pass; typecheck + focused tests green)
pi ✅ approve — no blocking defects
Claude (spec/server-match) ✅ approve
Claude (adversarial, full server enumeration) ✅ approve — no findings ≥80 confidence

Independently verified by reviewers (against server source, not just the diff):

  • Drift fully closed: server emits 31 distinct action codes / 14 entity types; client's post-PR AUDIT_ACTION_VALUES/ENTITY_TYPE_VALUES = 31 / 14 — complete 1:1 match, no remaining drift, no phantom client values.
  • Action strings match the handlers exactly: Account.SetLogo + Account.RemoveLogo → nameof(FarmLogo); Account.UpdateSettings → nameof(Account) (correctly not FarmLogo). AuditWriter stores the strings verbatim.
  • es/tl correct: Spanish gender agreement holds (Logotipo→establecido/eliminado, Configuración→actualizada); Configuración de la granja (singular) matches the app's existing settings-screen term; tl follows the established Na-[loanword] ang … pattern and Naalis ang logo matches a pre-existing catalog string.
  • Type-safety: satisfies Record<Union, EnumsKey> keeps values↔keys exhaustive; the 4 new en.enums keys exist so a missing one is a compile error; enums.test registry auto-covers them.
  • Parity: all 4 keys present in en AND es AND tl (catalogParity enforced).
  • Tests non-vacuous: both fail pre-fix (option absent / raw-code fallback); negative assertions guard against raw-code leakage.

Root cause still open (tracked on #247): the hand-maintained client list can drift again — the longer-term server-derived-enum prevention is a separate, larger change.

Verified: npm run test 1177 green · typecheck clean · build ok · scan 3 (false positives).

@mforce
mforce merged commit 5a1e85f into main Jul 28, 2026
7 checks passed
@mforce
mforce deleted the f247-audit-action-drift branch July 28, 2026 15:49
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.

1 participant