fix(acl): make the visibility predicates pure builders; repair CI
CI & Build / Python lint (push) Successful in 3s
CI & Build / integration (push) Successful in 21s
CI & Build / TypeScript typecheck (push) Successful in 49s
CI & Build / Python tests (push) Successful in 57s
CI & Build / Build & push image (push) Successful in 1m5s
CI & Build / Python lint (push) Successful in 3s
CI & Build / integration (push) Successful in 21s
CI & Build / TypeScript typecheck (push) Successful in 49s
CI & Build / Python tests (push) Successful in 57s
CI & Build / Build & push image (push) Successful in 1m5s
Run 2888 failed with 7 tests down, both causes mine. The real problem was a design flaw, not the tests: readable_notes_clause and browsable_notes_clause each opened their own DB session to fetch the caller's group ids. That made them unmockable at the call site, so every unrelated service test suddenly had to know they existed and stub them — four modules broke the moment a service started calling one, and one of my own stubs patched the wrong name (readable_* where the code had moved to browsable_*). Fixed at the root: group membership is now a SUBQUERY rather than a fetched list, so both clauses are synchronous pure functions with no session. One fewer round-trip per query, membership folded into the statement the caller was already running, and nothing for callers' tests to mock. The "no groups means no group arm" special case disappears too — an empty subquery simply matches nothing. Also: _fake_note in the process tool tests had no real user_id, so its auto-MagicMock attribute reached session.get(User, ...) through the new provenance check and SQLAlchemy rejected it. The fixture now takes a real user_id defaulting to the bound caller, which makes "is this shared?" meaningful, and gains a case asserting another user's process comes back flagged. Test assertions on compiled SQL are deliberately loose about formatting: the local env has no SQLAlchemy (rule #10), so they check that the arms exist rather than guessing at exact rendering. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RLwAaV4DQEmVyn496HnEvt
This commit is contained in:
@@ -94,7 +94,7 @@ async def query_knowledge(
|
||||
|
||||
# No query = browsing. Narrower scope: a record shared directly with the
|
||||
# caller is search-only and must not appear in an ambient list.
|
||||
visible = await browsable_notes_clause(user_id)
|
||||
visible = browsable_notes_clause(user_id)
|
||||
async with async_session() as session:
|
||||
base = select(Note).where(visible)
|
||||
|
||||
@@ -152,7 +152,7 @@ async def _semantic_knowledge_search(
|
||||
try:
|
||||
# A typed query is an explicit act, so it reaches the caller's full read
|
||||
# scope — including records shared directly with them.
|
||||
visible = await readable_notes_clause(user_id)
|
||||
visible = readable_notes_clause(user_id)
|
||||
async with async_session() as session:
|
||||
pattern = f"%{q}%"
|
||||
base = (
|
||||
@@ -231,7 +231,7 @@ async def get_knowledge_tags(user_id: int, note_type: str | None = None) -> list
|
||||
Follows the browse list rather than the read scope: a facet is itself a
|
||||
passive surface, and offering a tag that only a search-only record carries
|
||||
would filter the visible list down to nothing."""
|
||||
visible = await browsable_notes_clause(user_id)
|
||||
visible = browsable_notes_clause(user_id)
|
||||
async with async_session() as session:
|
||||
base = (
|
||||
select(func.unnest(Note.tags).label("tag"))
|
||||
@@ -247,7 +247,7 @@ async def get_knowledge_counts(user_id: int, tags: list[str] | None = None) -> d
|
||||
"""Per-type counts for the sidebar, over what this user can BROWSE — so the
|
||||
numbers match the list they sit beside rather than promising rows that only a
|
||||
search would surface."""
|
||||
visible = await browsable_notes_clause(user_id)
|
||||
visible = browsable_notes_clause(user_id)
|
||||
async with async_session() as session:
|
||||
# Count non-task types
|
||||
stmt = (
|
||||
@@ -316,7 +316,7 @@ async def query_knowledge_ids(
|
||||
return [item["id"] for item in items], total
|
||||
|
||||
# Browsing (see query_knowledge) — narrower scope.
|
||||
visible = await browsable_notes_clause(user_id)
|
||||
visible = browsable_notes_clause(user_id)
|
||||
async with async_session() as session:
|
||||
base = select(Note.id).where(visible)
|
||||
|
||||
@@ -347,7 +347,7 @@ async def get_knowledge_by_ids(user_id: int, ids: list[int]) -> list[dict]:
|
||||
return []
|
||||
# Fetching specific ids is explicit, so this takes the full read scope — the
|
||||
# ids came from either a browse or a search, and both must resolve.
|
||||
visible = await readable_notes_clause(user_id)
|
||||
visible = readable_notes_clause(user_id)
|
||||
async with async_session() as session:
|
||||
stmt = (
|
||||
select(Note)
|
||||
|
||||
Reference in New Issue
Block a user