From 7ecffb3b4829994190ba08c318c000ec7590e31b Mon Sep 17 00:00:00 2001 From: bolbol Date: Thu, 30 Jul 2026 08:41:00 +0000 Subject: [PATCH] test: regression table agents + onboarding nouvel agent sans redeploiement --- app/test_phase5_agents_table.py | 47 +++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 app/test_phase5_agents_table.py diff --git a/app/test_phase5_agents_table.py b/app/test_phase5_agents_table.py new file mode 100644 index 0000000..5781f2e --- /dev/null +++ b/app/test_phase5_agents_table.py @@ -0,0 +1,47 @@ +import asyncio, sqlite3, json +from mcp.client.sse import sse_client +from mcp import ClientSession + +def get_key(agent): + con = sqlite3.connect("data/context_hub.db") + cur = con.cursor() + cur.execute("SELECT api_key FROM api_keys WHERE agent_name=?", (agent,)) + row = cur.fetchone() + return row[0] if row else None + +async def call_as(api_key, tool, args): + async with sse_client("http://localhost:8000/mcp", headers={"X-API-Key": api_key}) as (read, write): + async with ClientSession(read, write) as session: + await session.initialize() + return await session.call_tool(tool, args) + +async def main(): + print("=== TEST 1 : non-regression -- CLAUDE toujours OK sur tt (via table agents) ===") + r = await call_as(get_key("CLAUDE"), "get_rules", {"scope": "tt"}) + print("OK" if "error" not in r.content[0].text else r.content[0].text) + + print("=== TEST 2 : non-regression -- GEMINI toujours refuse sur tt ===") + r2 = await call_as(get_key("GEMINI"), "get_rules", {"scope": "tt"}) + print(r2.content[0].text) + + print("=== TEST 3 : nouvel agent ajoute SANS redeploiement (insertion directe table agents) ===") + con = sqlite3.connect("data/context_hub.db") + cur = con.cursor() + cur.execute("INSERT OR REPLACE INTO agents (agent_name, agent_type, scopes) VALUES (?, ?, ?)", + ("TEST_AGENT_PHASE5", "test", json.dumps(["coding"]))) + cur.execute("INSERT OR REPLACE INTO api_keys (agent_name, api_key) VALUES (?, ?)", + ("TEST_AGENT_PHASE5", "test-phase5-key-temporaire")) + con.commit() + + r3 = await call_as("test-phase5-key-temporaire", "get_rules", {"scope": "coding"}) + print("acces coding:", r3.content[0].text[:100]) + r4 = await call_as("test-phase5-key-temporaire", "get_rules", {"scope": "tt"}) + print("acces tt (doit etre refuse):", r4.content[0].text) + + print("=== nettoyage ===") + cur.execute("DELETE FROM api_keys WHERE agent_name='TEST_AGENT_PHASE5'") + cur.execute("DELETE FROM agents WHERE agent_name='TEST_AGENT_PHASE5'") + con.commit() + print("nettoye") + +asyncio.run(main())