From bbde91c943d20ec9c986d70c552bafc8b3d1ddaf Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 23 Nov 2026 15:16:37 +0000 Subject: [PATCH] fix(quota-plane): normalise fee_period vocabulary in reconcile.py (#13375) The diff compared fee_period as a raw string, but the legs use different vocabularies for the same fact: the plan-store Effect schema only admits monthly/yearly/once, while the tracker says month/year. Since #1270 slice 2 seeded the store, every daily diff reported 9 fee_period findings that were pure vocabulary noise. Normalise the store leg to the tracker vocabulary in load_store (monthly->month, yearly->year); values outside the map (e.g. once) pass through untouched, so a genuinely new period still reports drift. The fixture masked this: its hand-written store row used month, a value the real store schema rejects. The fixture now carries monthly (the real store value), so the agreeing-legs case proves no drift, and a new case proves a genuine mismatch (monthly vs year) is still caught with the plan-store named as winner. Failing-first: the agreeing-legs case failed pre-fix with a fee_period finding {plan-store: monthly, tracker: month}. --- pm-stack/provider-usage/reconcile.py | 13 ++++++++-- pm-stack/provider-usage/test_reconcile.py | 29 ++++++++++++++++++++++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/pm-stack/provider-usage/reconcile.py b/pm-stack/provider-usage/reconcile.py index 78163d07ff..f84cdbdb06 100644 --- a/pm-stack/provider-usage/reconcile.py +++ b/pm-stack/provider-usage/reconcile.py @@ -28,6 +28,14 @@ FIELDS = ("fee_amount", "fee_period", "window", "limit", "reset", "status") +# The plan-store Effect schema only admits monthly/yearly/once, while +# the tracker vocabulary is month/year (#13375). Normalise the store +# leg to the tracker vocabulary at load, so the diff compares the same +# fact instead of reporting the spelling as permanent drift. Values +# outside the map (e.g. "once", or anything new) pass through +# untouched, so a genuinely new period still reports drift. +STORE_PERIOD_TO_TRACKER = {"monthly": "month", "yearly": "year"} + def load_store(path): p = Path(path) @@ -38,11 +46,12 @@ def load_store(path): for plan in d.get("plans", []): quotas = plan.get("quotas") or [{}] q = quotas[0] + fee = plan.get("fee") or {} rows[plan["id"]] = { "plan": plan.get("plan") or plan["id"], "provider": plan.get("providerID"), - "fee_amount": (plan.get("fee") or {}).get("amount"), - "fee_period": (plan.get("fee") or {}).get("period"), + "fee_amount": fee.get("amount"), + "fee_period": STORE_PERIOD_TO_TRACKER.get(fee.get("period"), fee.get("period")), "window": q.get("windowHours"), "limit": q.get("limit"), "reset": q.get("resetRule"), diff --git a/pm-stack/provider-usage/test_reconcile.py b/pm-stack/provider-usage/test_reconcile.py index 8ebafbc877..18c4d78be2 100644 --- a/pm-stack/provider-usage/test_reconcile.py +++ b/pm-stack/provider-usage/test_reconcile.py @@ -39,12 +39,17 @@ def tracker(rows): STORE = { + # NB (#13375): the store fixture carries "monthly" — the value the + # real store schema admits (monthly/yearly/once). The old "month" + # masked the vocabulary mismatch: the tracker says month/year while + # the store says monthly/yearly, and the diff must not report that + # as drift. Test 1 below is the no-drift proof. "plans": [ { "id": "go-personal", "providerID": "opencode-go", "plan": "go", - "fee": {"amount": 10, "period": "month"}, + "fee": {"amount": 10, "period": "monthly"}, "quotas": [ { "name": "monthly", @@ -108,4 +113,26 @@ def tracker(rows): out = json.loads(r.stdout) assert any(x["field"] == "presence" for x in out["findings"]), out +# 5. GENUINE PERIOD MISMATCH (#13375): store monthly vs tracker year is +# real drift, not vocabulary noise -> caught, store wins +mismatch = tracker( + [ + { + "plan": "go-personal", + "provider": "opencode-go", + "fee_amount": 10, + "fee_period": "year", + "window": 720, + "limit": 100, + "reset": "calendar", + "status": "active", + } + ] +) +r = run(STORE, mismatch, {"providers": {}}) +out = json.loads(r.stdout) +assert out["result"] == "findings" and len(out["findings"]) == 1, out +f = out["findings"][0] +assert f["field"] == "fee_period" and f["winner"] == "plan-store", f + print("all reconcile fixture tests pass")