Skip to content

feat(cohorts): add validation endpoint and enforce references at startup#267

Merged
taigrr merged 1 commit intomasterfrom
cd/nested-cohort-validation
Mar 30, 2026
Merged

feat(cohorts): add validation endpoint and enforce references at startup#267
taigrr merged 1 commit intomasterfrom
cd/nested-cohort-validation

Conversation

@taigrr
Copy link
Copy Markdown
Member

@taigrr taigrr commented Mar 30, 2026

Summary

Closes the gap where nested/compound cohort reference validation was implemented in the rbac package but never wired into farmer startup or exposed as an API.

Changes

Farmer startup validation

  • loadCohortRegistry() now calls ValidateReferences() after loading cohorts from config, logging errors for broken compound references (missing operands, circular refs, exceeded depth)

New ValidateReferencesAll() method

  • Unlike ValidateReferences() which returns on first error, this collects all validation errors — useful for config debugging

New cohorts.validate API endpoint

  • NATS handler returns {valid, errors[], cohorts} response
  • Mapped to ActionView in RBAC middleware (any viewer can check config validity)

New grlx cohorts validate CLI command

  • Human-readable output with colored pass/fail
  • JSON output mode supported (-o json)
  • Non-zero exit code on validation failure (CI-friendly)

Client library

  • client.ValidateCohorts() for programmatic access

Tests

  • TestValidateReferencesAll* — multiple errors, no errors, mixed circular+missing
  • TestHandleCohortsValidate* — empty registry, valid compound, missing ref, nil registry
  • TestValidateCohorts_* — client success, failure, NATS error

All existing tests pass. staticcheck clean.

- Call ValidateReferences() during farmer startup to catch broken
  compound cohort configs (missing operands, circular refs, depth)
- Add ValidateReferencesAll() to collect all errors instead of just first
- Add cohorts.validate NATS handler and CLI command (grlx cohorts validate)
- Add client.ValidateCohorts() for programmatic access
- Map cohorts.validate to ActionView in RBAC middleware
- Full test coverage across rbac, natsapi handlers, and client
@taigrr taigrr merged commit 291a792 into master Mar 30, 2026
6 of 7 checks passed
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