[feat] agent: per-company 카탈로그 — 회사 전용 카드도 action space 포함
카탈로그 스코프를 공용(user_id NULL) 전용에서 "공용 + 그 회사 유저가 만든 카드"로 확장. 공용 먼저(action_id 0..N-1 안정) → 회사 카드 뒤(append) 정렬로 공용 카드 학습을 보호. - get_nego_catalog(cdb, company_id): company_id 주면 공용 + company.users 소속 카드 함께 조회. - registry._apply_db_catalog: company_id(UUID)면 회사 카드 포함(데모/비-UUID는 공용만). - 효과: 견적이 회사 전용 카드를 선택해도 카탈로그에 있어 _selection_mask 가 매핑됨 (기존 스코프 불일치 갭 — 회사 카드 선택이 무시되던 문제 해소). 한계: 공용 카드 추가 시 회사 카드 action_id 밀림(공용은 안정) — 카드번호 기반 매핑 후속. agent 99/99. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
18020a9e07
commit
f4e59a2184
4 files changed
+88
-11
No files matched your search
@@ -105,7 +105,7 @@ async def test_action_space_from_db_catalog(db_engine):
|
||||
from negotiation.cards.ports.card_catalog_port import ICardCatalogRepository
|
||||
|
||||
class _FakeCatalog(ICardCatalogRepository):
|
||||
async def get_nego_catalog(self, cdb):
|
||||
async def get_nego_catalog(self, cdb, company_id=None):
|
||||
return ErrorType.SUCCESS, ["NGC-001", "NGC-002", "NGC-003"] # 3장짜리 카탈로그(파일은 11장)
|
||||
|
||||
reg = TenantEngineRegistry(
|
||||
@@ -126,7 +126,7 @@ async def test_action_space_falls_back_to_file_when_catalog_empty(db_engine):
|
||||
from negotiation.cards.ports.card_catalog_port import ICardCatalogRepository
|
||||
|
||||
class _EmptyCatalog(ICardCatalogRepository):
|
||||
async def get_nego_catalog(self, cdb):
|
||||
async def get_nego_catalog(self, cdb, company_id=None):
|
||||
return ErrorType.SUCCESS, []
|
||||
|
||||
reg = TenantEngineRegistry(
|
||||
@@ -175,6 +175,54 @@ async def test_demo_tenant_keeps_file_brand(db_engine):
|
||||
assert eng.config.resources.company_name == "데모상사 A"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_catalog_includes_company_cards(db_engine):
|
||||
"""per-company 카탈로그: 공용 카드(NGC-*) + 그 회사 유저가 만든 카드 — 공용 먼저 → 회사 뒤."""
|
||||
import uuid as _uuid
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from sqlalchemy import column, delete, insert, table
|
||||
|
||||
from common.database.db_session_manager import DB_SESSION_MNG
|
||||
from common.enums import DBType, ErrorType
|
||||
from negotiation.cards.adapters.card_catalog_db import CardCatalogDbRepository
|
||||
|
||||
cid, uid, card_id = _uuid.uuid4(), _uuid.uuid4(), _uuid.uuid4()
|
||||
_USERS = table("users", column("user_id"), column("company_id"), column("id"), column("password"),
|
||||
column("last_accessed_at"), column("status"), column("role"), schema="company")
|
||||
_NEGO = table("nego_cards", column("nego_card_id"), column("user_id"), column("name"),
|
||||
column("number"), column("usage_type"), schema="card")
|
||||
|
||||
async def _seed(s):
|
||||
await DB_SESSION_MNG.add(s, insert(_USERS).values(
|
||||
user_id=uid, company_id=cid, id="pytest_catalog_user", password="x",
|
||||
last_accessed_at=datetime.now(timezone.utc), status=1, role=1))
|
||||
return await DB_SESSION_MNG.add(s, insert(_NEGO).values(
|
||||
nego_card_id=card_id, user_id=uid, name="회사전용카드", number="COMP-01", usage_type=1))
|
||||
|
||||
err = await DB_SESSION_MNG.execute_lambda_run([DBType.MAIN.value], [_seed])
|
||||
assert err == ErrorType.SUCCESS
|
||||
try:
|
||||
repo = CardCatalogDbRepository()
|
||||
_, nums = await DB_SESSION_MNG.execute_lambda(
|
||||
DBType.MAIN.value, 1, lambda s: repo.get_nego_catalog(s, cid))
|
||||
assert "COMP-01" in nums # 회사 카드 포함
|
||||
assert nums[0] == "NGC-001" # 공용이 먼저(action_id 0 안정)
|
||||
assert nums[-1] == "COMP-01" # 회사 카드는 뒤에 append
|
||||
assert nums.index("NGC-011") < nums.index("COMP-01") # 공용 전부 → 회사
|
||||
|
||||
# company_id 없으면 공용만 (회사 카드 제외)
|
||||
_, shared_only = await DB_SESSION_MNG.execute_lambda(
|
||||
DBType.MAIN.value, 1, lambda s: repo.get_nego_catalog(s, None))
|
||||
assert "COMP-01" not in shared_only
|
||||
finally:
|
||||
await DB_SESSION_MNG.execute_lambda_run(
|
||||
[DBType.MAIN.value],
|
||||
[lambda s: DB_SESSION_MNG.add(s, delete(_NEGO).where(_NEGO.c.nego_card_id == card_id)),
|
||||
lambda s: DB_SESSION_MNG.add(s, delete(_USERS).where(_USERS.c.user_id == uid))],
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_middleware_header_missing_unregistered_registered(client):
|
||||
# 헤더 누락 → 400
|
||||
|
||||
Reference in new issue
Block a user