agentdatabase 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
agentdb/testing.py ADDED
@@ -0,0 +1,68 @@
1
+ """
2
+ Test doubles for AgentDB adapters, maintained alongside the real classes so
3
+ downstream integrations don't need to hand-roll and manually keep a fake in
4
+ sync with real constructor signatures. tests/unit/test_testing_fakes.py
5
+ asserts the fakes' curated params still exist on the real adapter — any
6
+ drift is caught here, in this repo's own suite, not downstream in
7
+ production (see docs/integrations/claude-agent-sdk-gateway-guide.md for the
8
+ incident that motivated this module).
9
+ """
10
+ from __future__ import annotations
11
+
12
+ from typing import Any, Optional
13
+
14
+
15
+ class FakeAgentDBClaudeMiddleware:
16
+ """
17
+ Minimal in-memory stand-in for AgentDBClaudeMiddleware, for downstream
18
+ apps testing their OWN wiring code (e.g. "did we pass the right
19
+ constructor args?") without needing a real AgentDB/SQLite instance or
20
+ re-testing AgentDB's own retrieval/persistence logic.
21
+
22
+ Deliberately does not implement prepare_turn/finalize_turn/run_turn —
23
+ those exercise real retrieval and persistence behavior already covered
24
+ by AgentDB's own test suite; faking them here would just be
25
+ re-implementing (and risking diverging from) that logic. Use a real
26
+ AgentDBClaudeMiddleware backed by a tmp-path SQLite AgentDB instance if
27
+ you need to test turn behavior itself.
28
+ """
29
+
30
+ def __init__(
31
+ self,
32
+ db: Any,
33
+ agent_id: str,
34
+ ) -> None:
35
+ self.db = db
36
+ self.agent_id = agent_id
37
+ self._conflicts: list = []
38
+ self._proposals: dict[str, dict] = {}
39
+
40
+ def pending_conflicts(self, resolved: bool = False) -> list:
41
+ return self._conflicts
42
+
43
+ def propose_skill(
44
+ self,
45
+ name: str,
46
+ content: str,
47
+ scope: list[str],
48
+ entities: Optional[list[str]] = None,
49
+ session_id: Optional[str] = None,
50
+ ) -> str:
51
+ proposal_id = f"fake-proposal-{len(self._proposals) + 1}"
52
+ self._proposals[proposal_id] = {
53
+ "proposal_id": proposal_id,
54
+ "name": name,
55
+ "content": content,
56
+ "scope": scope,
57
+ "status": "pending",
58
+ }
59
+ return proposal_id
60
+
61
+ def approve_proposal(self, proposal_id: str, resolution: Optional[str] = None) -> None:
62
+ self._proposals[proposal_id]["status"] = "approved"
63
+
64
+ def reject_proposal(self, proposal_id: str, reason: Optional[str] = None) -> None:
65
+ self._proposals[proposal_id]["status"] = "rejected"
66
+
67
+ def list_proposals(self, status: str = "pending") -> list[dict]:
68
+ return [p for p in self._proposals.values() if p["status"] == status]