Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions tests/integration/test_code_result_lessons.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,20 @@

pytestmark = pytest.mark.asyncio

ORG = unique_org("code-result-lessons")
PATH = "server/code/app/search/handler.py"
DECISION = "Decided: the search memo never stores a caller's memories, " * 6


def _set(base: str, token: str, key: str, value: str, files: list[str], **kw: Any) -> None:
body = {"org": ORG, "namespace": "dev", "agent": "claude-code", "memory_key": key}
def _set(
org: str,
base: str,
token: str,
key: str,
value: str,
files: list[str],
**kw: Any,
) -> None:
body = {"org": org, "namespace": "dev", "agent": "claude-code", "memory_key": key}
body |= {"value": value, "files": files, **kw}
r = httpx.post(
f"{base}/v1/memory.set", json=body, headers={"Authorization": f"Bearer {token}"}, timeout=10
Expand All @@ -34,22 +41,32 @@ async def test_lessons_match_the_result_file_by_path(
from server.core.ch import get_client
from server.memory.app import path_lessons

org = unique_org("code-result-lessons")
await get_client().connect()
token = mint_test_token(org=ORG, namespaces=["*"], roles=["writer"])
_set(control_plane_url, token, "notes/exact", "Pages are cut by tokens.", [PATH])
_set(control_plane_url, token, "notes/bare", "Every handler logs its route.", ["handler.py"])
token = mint_test_token(org=org, namespaces=["*"], roles=["writer"])
_set(org, control_plane_url, token, "notes/exact", "Pages are cut by tokens.", [PATH])
_set(
org,
control_plane_url,
token,
"notes/bare",
"Every handler logs its route.",
["handler.py"],
)
_set(
org,
control_plane_url,
token,
"notes/other",
"The memory handler drops weak hits.",
["server/memory/app/loom_search/handler.py"],
)
_set(control_plane_url, token, "design/memo", DECISION, [PATH], memory_type="decision")
_set(org, control_plane_url, token, "design/memo", DECISION, [PATH], memory_type="decision")
# More rows about other directories' handler.py than a small read would keep: the
# exact path's rows still come back.
for i in range(12):
_set(
org,
control_plane_url,
token,
f"notes/elsewhere-{i}",
Expand All @@ -61,7 +78,7 @@ async def test_lessons_match_the_result_file_by_path(
rows: list[dict[str, Any]] = []
for _ in range(50):
rows = (
await path_lessons.lessons_for_paths(ORG, ["dev"], "", [PATH], token_budget=2000)
await path_lessons.lessons_for_paths(org, ["dev"], "", [PATH], token_budget=2000)
).rows
if len(rows) >= 3:
break
Expand All @@ -78,7 +95,7 @@ async def test_lessons_match_the_result_file_by_path(
}
assert by_key["design/memo"]["excerpt"] == " ".join(DECISION.split())
# a cap below the decision's size leaves it out, never cut
small = (await path_lessons.lessons_for_paths(ORG, ["dev"], "", [PATH], token_budget=60)).rows
small = (await path_lessons.lessons_for_paths(org, ["dev"], "", [PATH], token_budget=60)).rows
assert "design/memo" not in {r["memory_key"] for r in small}


Expand All @@ -93,9 +110,10 @@ async def test_a_search_keeps_a_stored_lesson_when_another_file_read_times_out(
from server.memory.app import path_lessons
from server.settings import settings

org = unique_org("code-result-lessons")
await get_client().connect()
token = mint_test_token(org=ORG, namespaces=["*"], roles=["writer"])
_set(control_plane_url, token, "notes/ready", "Keep the ready file's lesson.", [PATH])
token = mint_test_token(org=org, namespaces=["*"], roles=["writer"])
_set(org, control_plane_url, token, "notes/ready", "Keep the ready file's lesson.", [PATH])
listing_rows = path_lessons.listing_rows
stopped = asyncio.Event()

Expand All @@ -117,7 +135,7 @@ async def _search(inp: CodeSearchInput) -> CodeSearchOutput:
wrapped = result_lessons.WithLessons(_search, result_lessons.search_paths)
out = await wrapped(
CodeSearchInput(
org=ORG, namespace="code-repo", query="ready file", lesson_namespaces=["dev"]
org=org, namespace="code-repo", query="ready file", lesson_namespaces=["dev"]
)
)
assert any(row["memory_key"] == "notes/ready" for row in out.lessons), out.model_dump()
Expand Down