|
|
@@ -192,3 +192,28 @@ def test_page_index_search_chinese_query(fresh_db, tmp_path):
|
|
|
# 英文 query 不受影响
|
|
|
hits_en = _page_index_search(kb["root_dir"], "ADT stack push pop", 3)
|
|
|
assert hits_en and hits_en[0]["score"] > 0
|
|
|
+
|
|
|
+
|
|
|
+def test_resolve_tenant_prefers_busiest(fresh_db, tmp_path):
|
|
|
+ """多租户老库:示例库应归属活跃智能体最多的租户(浏览器会话所在地),
|
|
|
+ 而非最老租户或 config.json 租户。"""
|
|
|
+ from agentpaas.db.models import gen_id, now_utc
|
|
|
+ from agentpaas.engine.sample_kb import ensure_sample_kb, SAMPLE_KB_NAME
|
|
|
+
|
|
|
+ db, tid_old = fresh_db
|
|
|
+ # 第二个租户,拥有 2 个活跃智能体(模拟日常使用租户)
|
|
|
+ tid_busy = gen_id("tn_")
|
|
|
+ now = now_utc()
|
|
|
+ db.execute("INSERT INTO tenants (id, name, plan, status, created_at) "
|
|
|
+ "VALUES (?, 'busy', 'free', 'active', ?)", (tid_busy, now))
|
|
|
+ for i in range(2):
|
|
|
+ db.execute(
|
|
|
+ "INSERT INTO agents (id, tenant_id, name, current_version, status, "
|
|
|
+ "created_at, updated_at) VALUES (?, ?, ?, 1, 'active', ?, ?)",
|
|
|
+ (gen_id("ag_"), tid_busy, f"a{i}", now, now))
|
|
|
+ db.commit()
|
|
|
+
|
|
|
+ ensure_sample_kb(str(tmp_path))
|
|
|
+ kb = db.fetchone("SELECT tenant_id FROM knowledge_bases WHERE name = ?",
|
|
|
+ (SAMPLE_KB_NAME,))
|
|
|
+ assert kb["tenant_id"] == tid_busy, "应归属智能体最多的租户"
|