Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions pm-stack/provider-usage/reconcile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"),
Expand Down
29 changes: 28 additions & 1 deletion pm-stack/provider-usage/test_reconcile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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")