test_product_efficiency_skill_contract.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import json
  2. import subprocess
  3. import sys
  4. from pathlib import Path
  5. PROJECT = Path(__file__).parents[1]
  6. SKILL_DIR = PROJECT / ".agents" / "skills" / "odps-product-efficiency-report"
  7. def test_return_attribution_fields_are_explicit() -> None:
  8. contract = "\n".join(
  9. [
  10. (SKILL_DIR / "SKILL.md").read_text(encoding="utf-8"),
  11. (SKILL_DIR / "references" / "metrics.md").read_text(encoding="utf-8"),
  12. (SKILL_DIR / "references" / "raw-output-contract.md").read_text(encoding="utf-8"),
  13. ]
  14. )
  15. assert "topic='share'" in contract
  16. assert "topic='click'" in contract
  17. assert "type='share'" in contract
  18. assert "Never use `type='share'`" in contract
  19. def test_generic_catalog_uses_topic_for_return_chain() -> None:
  20. catalog = (
  21. PROJECT / ".agents" / "skills" / "query-odps-data" / "references" / "data-catalog.md"
  22. ).read_text(encoding="utf-8")
  23. assert "源分享使用 `topic='share'`" in catalog
  24. assert "点击使用 `topic='click'`" in catalog
  25. assert "禁止用 `type='share'` 判断源分享" in catalog
  26. def test_realtime_total_only_contract_is_explicit() -> None:
  27. skill = (SKILL_DIR / "SKILL.md").read_text(encoding="utf-8")
  28. raw_contract = (SKILL_DIR / "references" / "raw-output-contract.md").read_text(
  29. encoding="utf-8"
  30. )
  31. assert "仅全量" in skill
  32. assert "`dt LIKE 'yyyyMMdd%'`" in skill
  33. assert "Overall-only variant" in raw_contract
  34. assert "do not run the 16-bucket formatter" in raw_contract
  35. def test_realtime_video_sources_and_partition_formats_are_explicit() -> None:
  36. contract = "\n".join(
  37. [
  38. (SKILL_DIR / "SKILL.md").read_text(encoding="utf-8"),
  39. (SKILL_DIR / "references" / "metrics.md").read_text(encoding="utf-8"),
  40. (SKILL_DIR / "references" / "raw-output-contract.md").read_text(
  41. encoding="utf-8"
  42. ),
  43. ]
  44. )
  45. assert "video_action_log_per5min" in contract
  46. assert "`dt LIKE 'yyyyMMdd%'`" in contract
  47. assert "`dt='DD'`" in contract
  48. assert "`year='yyyy'`" in contract
  49. assert "`month='MM'`" in contract
  50. assert "全版本" in contract and "优先" in contract
  51. def test_realtime_normalizer_selects_video_source_by_version(tmp_path) -> None:
  52. script = SKILL_DIR / "scripts" / "normalize_request.py"
  53. request = {
  54. "app_type": "0",
  55. "date_from": "20260812",
  56. "date_to": "20260812",
  57. "data_mode": "realtime",
  58. "bucket_position_from_end": 3,
  59. "experiment_buckets": ["0", "1"],
  60. "version": "all",
  61. }
  62. request_path = tmp_path / "request.json"
  63. request_path.write_text(json.dumps(request), encoding="utf-8")
  64. all_version = subprocess.run(
  65. [sys.executable, str(script), str(request_path)],
  66. check=True,
  67. capture_output=True,
  68. text=True,
  69. )
  70. assert json.loads(all_version.stdout)["tables"]["video"].endswith(
  71. "video_action_log_per5min"
  72. )
  73. request["version"] = "1578"
  74. request_path.write_text(json.dumps(request), encoding="utf-8")
  75. specified_version = subprocess.run(
  76. [sys.executable, str(script), str(request_path)],
  77. check=True,
  78. capture_output=True,
  79. text=True,
  80. )
  81. assert json.loads(specified_version.stdout)["tables"]["video"].endswith(
  82. "video_action_log_flow"
  83. )