dms_company_check.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. """Explicit read-only DMS integration check; output contains no company values."""
  2. import json
  3. from pathlib import Path
  4. from .dms_company import BASIC_ID, HONOR_ID, create_dms_company_client
  5. from .company import CompanyClient
  6. from .graph import build_graph
  7. from src.step5_session_analysis.dms import encode
  8. def main():
  9. path = Path(__file__).resolve().parents[2] / '.env'
  10. client = create_dms_company_client(path)
  11. client.connect()
  12. def seed(identity):
  13. return client.call('/content/selectContentList', {
  14. 'columnId': identity, 'page': 0, 'pageSize': 1, 'states': 0,
  15. 'search': '[]', 'orderBy': encode([{'field': 'id', 'orderByType': 1}])})['data'][0]
  16. row = seed(BASIC_ID)
  17. result = client.search(row['c_name'])
  18. assert result['exact_unique'] and HONOR_ID not in client.columns
  19. company = result['candidates'][0]
  20. profile = client.basic(company)
  21. assert HONOR_ID not in client.columns
  22. assert profile['data']['CreditCode'] == row['c_credit_code']
  23. assert profile['source']['provider'] == 'DMS'
  24. assert client.search(row['c_credit_code'])['exact_unique']
  25. honors = client.honors(company)
  26. assert honors['complete']
  27. fuzzy = client.search(row['c_name'][:4])
  28. assert 1 <= len(fuzzy['candidates']) <= 3 and fuzzy['can_search_more']
  29. empty = client.search('不存在的合成校验企业XYZ123')
  30. assert not empty['candidates'] and empty['complete']
  31. # Test fixture discovery only: locate a populated honor owner in memory.
  32. # The production graph below still resolves its basic identity first.
  33. honor_seed = seed(HONOR_ID)
  34. populated = client.search(honor_seed['c_credit_code'])
  35. assert populated['exact_unique']
  36. selected = populated['candidates'][0]
  37. client.basic(selected)
  38. multi = client.honors(selected)
  39. assert multi['complete'] and len(multi['records']) > 1
  40. assert all(r['data']['Name'] != selected['Name'] for r in multi['records'])
  41. def no_qcc():
  42. raise AssertionError('unexpected_qcc_call')
  43. combined = CompanyClient(path, dms_factory=lambda: create_dms_company_client(path), qcc_factory=no_qcc)
  44. graph = build_graph(combined, lambda q: {'conversation_kind': 'specific_need',
  45. 'needs_company': True, 'company_hint': q})
  46. answer = graph.invoke({'question': selected['Name']}, {'configurable': {'thread_id': 'read-only-dms-check'}})
  47. assert '__interrupt__' not in answer and answer['profile']['source']['provider'] == 'DMS'
  48. assert answer['honors']['complete'] and len(answer['honors']['records']) > 1
  49. print(json.dumps({'exact_name': True, 'exact_credit_code': True, 'basic_before_honors': True,
  50. 'fuzzy_candidates': len(fuzzy['candidates']), 'fuzzy_complete': fuzzy['complete'],
  51. 'empty_search': True, 'seed_honor_count': len(honors['records']),
  52. 'multiple_honor_count': len(multi['records']), 'graph_without_qcc': True,
  53. 'business_records_written': False}, ensure_ascii=False))
  54. if __name__ == '__main__':
  55. try:
  56. main()
  57. except Exception:
  58. print(json.dumps({'status': 'dms_company_check_failed'}))
  59. raise SystemExit(1) from None