Knowledge bases, and a file input that lines up
**Bases.** Documents now live in named collections rather than one flat pile, and a chat can be pointed at particular ones — "answer from the contracts folder" is a different question from "answer from everything I have ever uploaded". A chat with none attached still searches everything its owner can see, because empty means unscoped, not empty. The harness names the attached bases. Without that the model cannot tell "there is nothing about this" from "I am only allowed to see one folder", and it phrases a miss as the former. **Sharing moves to the base.** A document is visible to whoever can see the base it lives in, so `Document` is gone from the shareable types and `documents.visible()` filters through `base_id`. "This folder is the team's" is the granularity people think in; per-document grants meant answering "who can see this?" by checking every file. Moving a document between bases changes who can see it, so the destination has to be one you own. `Document.base_id` is nullable only because the column had to be added to a table that already had rows. `sweep_unfiled()` runs at startup beside the orphaned-upload sweep and files anything predating bases into its owner's default, which is what makes "always set" true everywhere else. **The file input.** `.input` gave it a fixed height and horizontal padding, so the browser's own button sat hard against the left edge while the filename floated off the centre line. A file input is two controls in one box and neither inherits anything useful, so it gets its own rule: no horizontal padding, the button sized to `--control-h` with the divider that separates it, and the text centred with line-height rather than flexbox, which file inputs do not lay out reliably. 437 tests, ruff clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -166,6 +166,48 @@ def _context(**kwargs):
|
||||
return tools_service.ToolContext(owner_id="someone", **kwargs)
|
||||
|
||||
|
||||
# --- Knowledge is scoped to the chat's bases ---------------------------------
|
||||
async def test_knowledge_search_is_limited_to_the_attached_bases(db, user_id):
|
||||
""""Answer from the contracts folder" is a different question from "answer
|
||||
from everything I have ever uploaded"."""
|
||||
from lembas.db.models import User
|
||||
from lembas.services.library import documents as documents_service
|
||||
|
||||
owner = db.get(User, user_id)
|
||||
trees = documents_service.create_base(db, owner=owner, name="Trees")
|
||||
contracts = documents_service.create_base(db, owner=owner, name="Contracts")
|
||||
documents_service.store_upload(
|
||||
db, owner=owner, payload=b"The mallorn is golden.", filename="a.txt",
|
||||
title="Mallorn", base=trees,
|
||||
)
|
||||
documents_service.store_upload(
|
||||
db, owner=owner, payload=b"The mallorn clause is void.", filename="b.txt",
|
||||
title="Clause", base=contracts,
|
||||
)
|
||||
|
||||
everywhere = await tools_service.run_tool(
|
||||
tools_service.ToolContext(owner_id=user_id), "knowledge_search",
|
||||
'{"query": "mallorn"}',
|
||||
)
|
||||
assert {r["title"] for r in everywhere.event["results"]} == {"Mallorn", "Clause"}
|
||||
|
||||
scoped = await tools_service.run_tool(
|
||||
tools_service.ToolContext(owner_id=user_id, base_ids=[contracts.id]),
|
||||
"knowledge_search",
|
||||
'{"query": "mallorn"}',
|
||||
)
|
||||
assert [r["title"] for r in scoped.event["results"]] == ["Clause"]
|
||||
|
||||
|
||||
def test_a_chat_with_no_bases_searches_everything(db, user_id):
|
||||
"""Empty means "everything the owner can see", not "nothing"."""
|
||||
from lembas.db.models import User
|
||||
|
||||
chat = _chat_with(db, user_id, capabilities={"tools": True})
|
||||
context = tools_service.context_for(db, db.get(User, user_id), chat)
|
||||
assert context.base_ids == []
|
||||
|
||||
|
||||
# --- Running one -------------------------------------------------------------
|
||||
async def test_running_web_search_formats_results_for_the_model(monkeypatch):
|
||||
async def fake_run(_config, query, *, limit=None):
|
||||
|
||||
Reference in New Issue
Block a user