全量回归抓到的两处:裁判那本账留回 judge._today 这个日历名字;冻结表结构快照时 ctx 不一定带目录视图

- engine/judge.py:裁判的测试(test_judge_settings、test_verify_spend)换 judge._today 来模拟裁判这边跨天。上一版把它去掉、让三本账都只认 spend._today,等于改了这些测试的前提。改成裁判那本 Ledger 实例放在 judge.py(judge_spend,键不变,日历是 judge._today,它缺省就是 spend._today);spend.py 只放核查、评测两本。test_evidence_judge 恢复原样,test_spend_ledger 跟着改:换 spend._today 三本一起滚,换 judge._today 只动裁判那本
- tools/datasource._store_schema:按 getattr 取 ctx.catalog_view——几处测试(和以后的调用方)直接拿一个只有 run_id / node_id 的对象调它,没有这个属性就是缺省视图
This commit is contained in:
ThearchyHelios
2026-10-16 11:04:41 +08:00
parent ee6e07959b
commit 96af448fc5
5 changed files with 21 additions and 14 deletions
+2 -4
View File
@@ -30,7 +30,6 @@ from app.core.events import EventType
from app.db.base import SessionLocal
from app.db.models import Setting
from app.engine import judge as judge_mod
from app.engine import spend
from app.engine.evidence import build_catalog, compose_doc, iter_units
from app.engine.judge import (
BATCH_SIZE,
@@ -504,7 +503,7 @@ async def test_unlimited_never_truncates(monkeypatch, stored):
raw = "".join(f"第 {i} 个区域的销售额增长来自新客。[[see:m:gmv]]" for i in range(BATCH_SIZE + 5))
doc = compose_doc(raw, catalog)
async with SessionLocal() as session: # 今天已经花掉很多:不限就是不限
session.add(Setting(key=SPEND_KEY, value={"date": spend._today(), "usd": 999.0, "calls": 9}))
session.add(Setting(key=SPEND_KEY, value={"date": judge_mod._today(), "usd": 999.0, "calls": 9}))
await session.commit()
outcome = await judge_doc(doc, catalog, spec=SPEC, budget=UNLIMITED)
assert [len(units) for units in judge.judged] == [BATCH_SIZE, 5]
@@ -518,8 +517,7 @@ async def test_the_daily_cap_resets_the_next_day(monkeypatch, stored):
cost = prepare(doc, catalog).cost(PRICED, prepare(doc, catalog).cands)
budget = Budget(max_claims=None, max_cost_usd=None, timeout_s=None, daily_max_usd=cost * 1.05)
day = {"today": "2026-09-28"}
# 裁判的账和核查、评测按同一个本地日期滚动(engine/spend.py 的 Ledger)
monkeypatch.setattr(spend, "_today", lambda: day["today"])
monkeypatch.setattr(judge_mod, "_today", lambda: day["today"])
judge = Judge(monkeypatch)
first = await judge_doc(doc, catalog, spec=SPEC, budget=budget)
+7 -3
View File
@@ -12,7 +12,8 @@ from sqlalchemy import delete
from app.db.base import SessionLocal
from app.db.models import Setting
from app.engine import judge, spend
from app.engine.spend import Ledger, eval_spend, judge_spend, verify_spend
from app.engine.judge import judge_spend
from app.engine.spend import Ledger, eval_spend, verify_spend
@pytest.fixture(autouse=True)
@@ -70,9 +71,12 @@ async def test_one_book_hitting_its_cap_does_not_squeeze_the_others():
assert (await eval_spend.daily())["usd"] == pytest.approx(1.5)
async def test_all_books_roll_over_on_the_same_clock(monkeypatch):
"""三本账按同一个本地日期滚动(spend._today):裁判不再自己另有一份时钟。"""
async def test_all_books_roll_over_on_the_local_date(monkeypatch):
"""三本账按同一个本地日期滚动(spend._today);裁判那本另留一个 judge._today,换它只动裁判这一本。"""
monkeypatch.setattr(spend, "_today", lambda: "2026-01-02")
assert await judge_spend.charge(0.1, limit=None, priced=True) == "2026-01-02"
assert (await judge.daily_spend())["date"] == "2026-01-02"
assert (await eval_spend.daily())["date"] == "2026-01-02"
monkeypatch.setattr(judge, "_today", lambda: "2026-01-03")
assert (await judge.daily_spend())["date"] == "2026-01-03"
assert (await verify_spend.daily())["date"] == "2026-01-02"