Skip to content

fix(contract): validate role names for stable machine output - #42

Merged
saraeloop merged 1 commit into
mainfrom
fix/role-name-contract-hardening
Apr 15, 2026
Merged

fix(contract): validate role names for stable machine output#42
saraeloop merged 1 commit into
mainfrom
fix/role-name-contract-hardening

Conversation

@saraeloop

Copy link
Copy Markdown
Member

Summary

Harden the role-name contract so gitrole’s machine-readable output remains stable and predictable.

Changed

  • centralize role-name validation in src/domain/role.ts
  • require role names to match ^[a-z0-9_-]+$
  • add InvalidRoleNameError with clear error messages
  • enforce validation for:
    • gitrole add
    • gitrole import current --name <role>
    • direct role-referencing commands such as pin and remote set
  • validate names during role normalization so invalid persisted data fails clearly instead of leaking broken tokens into status --short
  • add focused tests for:
    • valid names like work, client-acme, and agent_bot
    • invalid names
    • consistent CLI errors
    • exact status --short output for valid role names
    • bad persisted role-name handling

Verification

  • npm run build
  • npm test
  • npm run test:e2e
  • npm run test:release

Notes

  • no docs changes in this pass
  • this is contract hardening to keep machine-readable output honest and stable

Harden the role-name contract so machine-readable surfaces like
`status --short` stay predictable.

Also:
- centralize role-name validation in `src/domain/role.ts`
- require role names to match `^[a-z0-9_-]+$`
- add `InvalidRoleNameError` with clear user-facing messages
- enforce validation in role creation and import
- enforce validation on direct role-referencing commands
- make invalid persisted role data fail clearly during normalization
- add focused CLI and use-case coverage for valid/invalid names
- keep `status --short` exact and safe for valid names

Verified with:
- npm run build
- npm test
- npm run test:e2e
- npm run test:release
@saraeloop saraeloop self-assigned this Apr 15, 2026
@saraeloop
saraeloop merged commit 4f503b7 into main Apr 15, 2026
4 checks passed
@saraeloop
saraeloop deleted the fix/role-name-contract-hardening branch April 15, 2026 16:57
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