Skip to content

Add discovery guard for flock-scoped EF query filters #613

Closed

Description

@mforce

Context

Follow-up from #388 / PR #611 review. #388 adds combined tenant+flock EF query filters to the 8 current flock-keyed entities. The tests prove every current filter and mutate each conjunct, but the set itself is hand-listed.

A future entity with a FlockId property can receive the mandatory tenant filter while silently omitting flock scoping. Existing tests stay green because they enumerate today's known 8.

This is the flock-axis counterpart to TenantBypassDiscoveryTests: walk the model/source surface, exclude deliberately, never trust a recalled list (AGENTS.md “Writing a guard”).

Required guard

  • Discover every mapped entity carrying a scalar FlockId (nullable or non-nullable) and Flock itself.
  • Assert it has the flock-scope query-filter conjunct in addition to AccountId tenancy.
  • Declare exclusions explicitly with reasons:
    • UserRoleAssignment is the scope source and must not filter itself (circular resolution).
    • Any future exclusion requires a reviewed allow-list entry, not an implicit omission.
  • Fail when a new discovered entity is absent from the declared scoped/excluded set.
  • Pin a literal floor/count only as a secondary alarm; discovery is authoritative.
  • Mutation proof: add a temporary mapped FlockId entity (or remove one filter conjunct) and prove the guard reds; restore and prove green.
  • Avoid brittle expression ToString() matching if a structural expression-tree walk is feasible.

Acceptance criteria

  • Current 8 scoped entities are discovered automatically.
  • UserRoleAssignment is a named, justified exclusion.
  • A newly mapped FlockId entity without flock scoping fails the guard.
  • A tenant-only filter on an existing flock entity fails the guard.
  • Guard does not weaken the existing tenant discovery/bypass guards.

Activity

  1. mforce commented on Aug 28, 2026

    @mforce
    OwnerAuthor

    Additional review note from PR #611 clean round (Claude Opus): two mapped child tables carry flock-derived data but no scalar FlockId, so a discovery guard limited to FlockId properties will not see them:

    • DailyEntryGrades — current production-report query is safe because it correlates through filtered DailyEntries; direct export is AdminOnly.
    • EggInventoryMovements — direct export is AdminOnly; flock ownership derives through EggLot.

    #613 should explicitly declare these policy/parent-join scoped surfaces and pin the current protection (AdminOnly export; filtered-parent correlation), or extend discovery to mapped relationships where practical. A future policy relaxation or query refactor must fail a guard rather than silently exposing all flocks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions