Преглед изворни кода

test: 同步游走预算新值(30/20/20)到用例 + deep_frontier 钉死小预算解耦

walk_policy 放宽后修配置快照断言:max_total 30、tag/author 各 20(real_knobs/walk_graph_config/flow_ledger run_walk 预算总览);
test_deep_frontier 改用 monkeypatch 深拷贝钉死 10/5/5 验撞顶留痕,与生产数值解耦(生产再改不影响该用例)。504 passed。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sam Lee пре 3 недеља
родитељ
комит
131d2d60c7

+ 1 - 1
tests/test_flow_ledger_api.py

@@ -590,7 +590,7 @@ def test_flow_ledger_api_returns_business_v4_ledger(tmp_path, monkeypatch):
     run_walk = client.get(f"/runs/{run_id}/flow-ledger/walk").json()
     assert run_walk["summary"]["total_actions"] >= 1
     assert run_walk["summary"]["tag_used"] == 1  # walk_001 hashtag success
-    assert run_walk["summary"]["tag_cap"] == 5
+    assert run_walk["summary"]["tag_cap"] == 20
     assert run_walk["summary"]["author_used"] == 0
     assert run_walk["summary"]["max_depth_reached"] == 1
     assert run_walk["summary"]["max_depth_cap"] == 5

+ 16 - 3
tests/test_walk_engine_deep_frontier.py

@@ -95,7 +95,20 @@ def _expansion_successes(walk_actions):
     ]
 
 
-def test_deep_frontier_alternates_edges_within_caps(tmp_path):
+def test_deep_frontier_alternates_edges_within_caps(tmp_path, monkeypatch):
+    # 本测试钉死小预算(10/5/5)验"撞顶留痕"机制,与生产 walk_policy 数值解耦(生产改大不影响本测试)。
+    from content_agent.integrations import walk_graph_json as _wgj
+    _orig_load = _wgj.WalkGraphStore.load_policy
+
+    def _capped(self):
+        import copy
+        policy = copy.deepcopy(_orig_load(self))  # 深拷贝,别污染共享缓存的 policy
+        policy["global"]["max_total_actions_per_run"] = 10
+        policy["edge_budgets_by_id"]["hashtag_to_query"]["max_total_actions"] = 5
+        policy["edge_budgets_by_id"]["author_to_works"]["max_total_actions"] = 5
+        return policy
+
+    monkeypatch.setattr(_wgj.WalkGraphStore, "load_policy", _capped)
     context = _seed(tmp_path)
     client = _BranchingClient()
 
@@ -109,7 +122,7 @@ def test_deep_frontier_alternates_edges_within_caps(tmp_path):
     depths = {a["depth"] for a in successes}
     assert {1, 2, 3} <= depths
 
-    # 三道闸 + 总闸:depth≤5、标签≤5、作者≤5、总向外跳≤10。
+    # 三道闸 + 总闸(本测试钉死的小预算):depth≤5、标签≤5、作者≤5、总向外跳≤10。
     assert max(depths) <= 5
     tag_jumps = [a for a in successes if a["edge_id"] == "hashtag_to_query"]
     author_jumps = [a for a in successes if a["edge_id"] == "author_to_works"]
@@ -155,7 +168,7 @@ def test_deep_frontier_dedups_repeated_content_author_tag(tmp_path):
     content_ids = [i["platform_content_id"] for i in result["discovered_content_items"]]
     assert len(content_ids) == len(set(content_ids))  # 无重复内容
     successes = _expansion_successes(result["walk_actions"])
-    assert len(successes) <= 10
+    assert len(successes) <= 30
 
 
 def test_global_action_cap_emits_skip(tmp_path):

+ 3 - 3
tests/test_walk_graph_config.py

@@ -25,7 +25,7 @@ def test_graph_has_8_nodes_and_9_edges():
 def test_policy_unwraps_pinned_values():
     policy = WalkGraphStore().load_policy()
     # M8 拍板:总闸 60→10、删 max_reseed_rounds;deny / halve_min_1(max(1, budget//2))。
-    assert policy["global"]["max_total_actions_per_run"] == 10
+    assert policy["global"]["max_total_actions_per_run"] == 30
     assert policy["global"]["max_depth"] == 5
     assert "max_reseed_rounds" not in policy["global"]
     assert policy["edge_permissions"]["KEEP_CONTENT_FOR_REVIEW"]["video_to_hashtag"] == "deny"
@@ -66,9 +66,9 @@ def test_policy_edge_budgets_match_decided_values():
     # M8 拍板 2026-06-17:标签 5、作者 5、每作者作品 5;query_next_page 已删。
     budgets = WalkGraphStore().load_policy()["edge_budgets_by_id"]
     assert "query_next_page" not in budgets
-    assert budgets["author_to_works"]["max_total_actions"] == 5
+    assert budgets["author_to_works"]["max_total_actions"] == 20
     assert budgets["author_to_works"]["max_works_per_author"] == 5
-    assert budgets["hashtag_to_query"]["max_total_actions"] == 5
+    assert budgets["hashtag_to_query"]["max_total_actions"] == 20
 
 
 def test_shipinhao_author_edges_blocked_and_terminal_edges_supported():

+ 3 - 3
tests/test_walk_policy_real_knobs.py

@@ -11,7 +11,7 @@ def test_global_knobs_unwrap_to_plain_int():
     glob = _policy()["global"]
     assert glob["max_depth"] == 5
     assert isinstance(glob["max_depth"], int)
-    assert glob["max_total_actions_per_run"] == 10
+    assert glob["max_total_actions_per_run"] == 30
     assert isinstance(glob["max_total_actions_per_run"], int)
 
 
@@ -23,8 +23,8 @@ def test_max_reseed_rounds_removed_and_loader_ok():
 
 def test_edge_budgets_are_m8_values():
     budgets = _policy()["edge_budgets_by_id"]
-    assert budgets["hashtag_to_query"]["max_total_actions"] == 5
-    assert budgets["author_to_works"]["max_total_actions"] == 5
+    assert budgets["hashtag_to_query"]["max_total_actions"] == 20
+    assert budgets["author_to_works"]["max_total_actions"] == 20
     assert budgets["author_to_works"]["max_works_per_author"] == 5