Skip to content

fix(server): reject a bounded context whose slug differs from its namespace - #208

Merged
yordis merged 1 commit into
TrogonStack:mainfrom
enilsen16:enilsen16/fix-context-slug-mismatch
Oct 20, 2026
Merged

yordis merged 1 commit into
TrogonStack:mainfrom
enilsen16:enilsen16/fix-context-slug-mismatch

Conversation

@enilsen16

@enilsen16 enilsen16 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Rule 11 and strategic.proto say that the slug of a BoundedContext must equal its namespace (CONTEXT_SLUG_MISMATCH, Error). The server did not enforce this rule. Only the BoundedContext branch of validate_scenarios emits the code. At put time, that function runs only for slice kinds. validate_model and validate_store do not emit the code. Thus apply accepted a second context in a namespace, and validation returned no finding.

Change

  • Add context_slug_mismatch in validation.rs. It makes the CONTEXT_SLUG_MISMATCH issue. validate_scenarios now uses it, so the message does not change.
  • PutEntity and BatchMutate reject a BoundedContext whose slug is not its namespace. They return INVALID_ARGUMENT with the code in the message. The check is next to check_project_namespace_conflict.
  • validate_store emits CONTEXT_SLUG_MISMATCH for each stored context that does not obey the rule. Thus ValidateProject and the merge gate show contexts that were stored before this change.
  • The client export test put a context with a slug that was not its namespace. It now uses slug == namespace.

Question for the maintainer

The other checks in the BoundedContext branch of validate_scenarios (REALIZES_*, RELATIONSHIP_* and the seam checks) also cannot run over RPC, for the same reason. This PR does not move them. Do you want them moved into validate_store? A put-time check is not correct for REALIZES_DANGLING, because it would reject a context that is put before its Subdomain.

Test

  • cargo test -p trogon-atlas-server: new handler tests for put and batch put (mismatch is rejected, a match is accepted), and a pure test that validate_store flags only the context that does not obey the rule.
  • cargo test -p trogon-atlas-client
  • cargo clippy -p trogon-atlas-server -p trogon-atlas-client --all-targets -- -D warnings

Closes #89


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

…espace

Signed-off-by: Erik Nilsen <enilsen16@live.com>
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 473e5178-3ccb-4d46-889e-ebff33a54111
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@enilsen16
enilsen16 marked this pull request as ready for review October 20, 2026 15:19
@cursor

cursor Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes entity write validation and store hygiene for bounded contexts; incorrect enforcement could block legitimate puts or miss invalid data, but scope is narrow and well-tested.

Overview
Enforces CONTEXT_SLUG_MISMATCH on writes and in store validation, so a BoundedContext cannot be persisted when its slug differs from its namespace (one context per namespace).

Shared logic lives in context_slug_mismatch in validation.rs; validate_scenarios delegates to it unchanged in behavior. PutEntity and BatchMutate now call check_context_slug and return INVALID_ARGUMENT with the validation code. validate_store scans stored contexts so ValidateProject / merge gates can surface legacy bad data.

Tests cover handler reject/accept paths, validate_store flagging only offending contexts, and the client export integration test now seeds a context with slug == namespace.

Reviewed by Cursor Bugbot for commit 0e1adf1. Bugbot is set up for automated code reviews on this repo. Configure here.

@yordis
yordis merged commit 692ad01 into TrogonStack:main Oct 20, 2026
28 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.

Several bounded contexts in one namespace are neither supported nor rejected

2 participants