generated from coulomb/repo-seed
Implement Stripe publication layer and close WP-0007
This commit is contained in:
@@ -30,6 +30,9 @@ def test_dashboard_payload_contains_live_ledger_totals() -> None:
|
||||
assert payload["pricing_simulations"]["reference_model_id"] is not None
|
||||
assert payload["customer_tuning"]["request_count"] == 2
|
||||
assert payload["customer_tuning"]["accepted_request_ids"] == ["small-team-lower-usage-price"]
|
||||
assert payload["provider_publication"]["provider"] == "stripe"
|
||||
assert payload["provider_publication"]["model_id"] == "flat-899-eur-monthly"
|
||||
assert payload["provider_publication"]["plan"]["summary"].startswith("stripe:")
|
||||
assert len(payload["boundary_validation"]["model_results"]) == 3
|
||||
assert payload["boundary_validation"]["policy"]["target_margin_pct"] == "15"
|
||||
assert any(
|
||||
|
||||
124
projects/coulomb-pricing/tests/test_publication.py
Normal file
124
projects/coulomb-pricing/tests/test_publication.py
Normal file
@@ -0,0 +1,124 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from observatory.load import load_pricing_models, load_product
|
||||
from observatory.publication import (
|
||||
build_stripe_publication_preview,
|
||||
publish_to_stripe_shadow,
|
||||
rollback_stripe_shadow,
|
||||
)
|
||||
|
||||
DATA_DIR = Path(__file__).resolve().parent.parent / "data"
|
||||
|
||||
|
||||
def _catalog():
|
||||
return load_product(DATA_DIR), load_pricing_models(DATA_DIR)
|
||||
|
||||
|
||||
def test_overage_preview_includes_meter_and_approximate_mapping(tmp_path: Path) -> None:
|
||||
product, models = _catalog()
|
||||
preview = build_stripe_publication_preview(
|
||||
product,
|
||||
models,
|
||||
DATA_DIR,
|
||||
model_id="membership-plus-overage",
|
||||
state_path=tmp_path / "stripe-state.json",
|
||||
)
|
||||
|
||||
assert preview["artifact_counts"]["exact"] >= 3
|
||||
assert preview["artifact_counts"]["approximate"] >= 1
|
||||
assert preview["artifact_counts"]["unsupported"] == 0
|
||||
assert any(
|
||||
operation["provider_object_type"] == "billing_meter"
|
||||
for operation in preview["plan"]["operations"]
|
||||
)
|
||||
|
||||
|
||||
def test_credit_allowance_preview_marks_unsupported_usage_mapping(tmp_path: Path) -> None:
|
||||
product, models = _catalog()
|
||||
preview = build_stripe_publication_preview(
|
||||
product,
|
||||
models,
|
||||
DATA_DIR,
|
||||
model_id="membership-plus-credits",
|
||||
state_path=tmp_path / "stripe-state.json",
|
||||
)
|
||||
|
||||
unsupported = {
|
||||
artifact["source_key"]
|
||||
for artifact in preview["plan"]["unsupported_artifacts"]
|
||||
}
|
||||
assert "price:membership-plus-credits:ai-credit-allowance" in unsupported
|
||||
assert preview["artifact_counts"]["unsupported"] >= 1
|
||||
|
||||
|
||||
def test_publication_is_idempotent_and_detects_drift(tmp_path: Path) -> None:
|
||||
product, models = _catalog()
|
||||
state_path = tmp_path / "stripe-state.json"
|
||||
|
||||
publish_to_stripe_shadow(
|
||||
product,
|
||||
models,
|
||||
DATA_DIR,
|
||||
model_id="flat-899-eur-monthly",
|
||||
state_path=state_path,
|
||||
)
|
||||
preview = build_stripe_publication_preview(
|
||||
product,
|
||||
models,
|
||||
DATA_DIR,
|
||||
model_id="flat-899-eur-monthly",
|
||||
state_path=state_path,
|
||||
)
|
||||
|
||||
assert {operation["kind"] for operation in preview["plan"]["operations"]} == {"noop"}
|
||||
|
||||
raw_state = json.loads(state_path.read_text(encoding="utf-8"))
|
||||
price_artifact = next(
|
||||
artifact
|
||||
for artifact in raw_state["artifacts"]
|
||||
if artifact["provider_id"] == "price--flat-899-eur-monthly--membership-access"
|
||||
)
|
||||
price_artifact["payload"]["unit_amount_decimal"] = "9.49"
|
||||
state_path.write_text(json.dumps(raw_state, indent=2), encoding="utf-8")
|
||||
|
||||
drifted = build_stripe_publication_preview(
|
||||
product,
|
||||
models,
|
||||
DATA_DIR,
|
||||
model_id="flat-899-eur-monthly",
|
||||
state_path=state_path,
|
||||
)
|
||||
|
||||
assert drifted["plan"]["drift"]
|
||||
assert any(operation["kind"] == "update" for operation in drifted["plan"]["operations"])
|
||||
|
||||
|
||||
def test_publication_rollback_restores_prior_revision(tmp_path: Path) -> None:
|
||||
product, models = _catalog()
|
||||
state_path = tmp_path / "stripe-state.json"
|
||||
|
||||
first = publish_to_stripe_shadow(
|
||||
product,
|
||||
models,
|
||||
DATA_DIR,
|
||||
model_id="flat-899-eur-monthly",
|
||||
state_path=state_path,
|
||||
)
|
||||
publish_to_stripe_shadow(
|
||||
product,
|
||||
models,
|
||||
DATA_DIR,
|
||||
model_id="membership-plus-overage",
|
||||
state_path=state_path,
|
||||
)
|
||||
rollback = rollback_stripe_shadow(
|
||||
DATA_DIR,
|
||||
first["result"]["revision"]["revision_id"],
|
||||
state_path=state_path,
|
||||
)
|
||||
|
||||
assert rollback["result"]["state"]["active_model_id"] == "flat-899-eur-monthly"
|
||||
assert rollback["result"]["revision"]["summary"].startswith("Rolled back")
|
||||
Reference in New Issue
Block a user