feat(backend): license entitlements, enforced limits, free tier

Platform v2 step 1.4 (APPS_PLATFORM D-3..D-6, D-21, §5).
- core/modules/entitlements.py: compute() turns the evaluated license into
  per-module grants: the v2 token's `modules` map (own `exp` with the 5-day
  grace, never cut mid-service) + the free tier; no/invalid token, expired
  after grace, inactive, locked or clock tampering -> free tier only; core
  always. limit(module, name) with token value -> manifest licensed_default ->
  free value; None = unlimited. LICENSE_MODE=off (dev/test only) = everything
- module gating says why: module.not_licensed (402, the first unlicensed
  module in the dependency chain) before module.disabled (403)
- services/license.py accepts only v2 tokens with a modules map; the v1
  "legacy unsigned 72h" path is gone
- apply_license() always installs entitlements (startup before workers,
  every heartbeat, workday close); workers follow license changes
- the global license middleware is deleted (no more whole-API 402/423);
  license_state moved to services/license_state.py
- history_days enforced in every report/history endpoint: lower date bounds
  clamped (also when no "from" is given), and business days older than the
  limit refused by id (license.history_limited); data is never deleted
- bootstrap/modules API show license mode, entitlement source and limit values
- LICENSE_MODE=off in docker-compose.dev.yml and the e2e launchers; sites
  default to enforced
- tests: entitlement rules, limits, the three done-when checks, signed-token
  apply_license path; license tests moved to v2 tokens

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-12 18:32:57 +02:00
co-authored by Claude Opus 5.5
parent 231a97c186
commit 0d43e6a111
21 changed files with 628 additions and 172 deletions
+10 -4
View File
@@ -70,12 +70,17 @@ def pytest_collection_modifyitems(config, items):
@pytest.fixture(autouse=True)
def _venue_time():
"""Every test runs in Europe/Athens with rollover 06:00 (D-11) and venue language "en"
(D-12), without reading settings from a database. Tests may call configure(...) to change them."""
"""Every test runs in Europe/Athens with rollover 06:00 (D-11), venue language "en"
(D-12) and every module entitled without limits (D-3), without reading anything from a
database. Tests may call configure(...) / entitlements.set_current(...) to change them."""
from core import i18n, timeutil
from core.modules import entitlements
timeutil.configure(tz="Europe/Athens", rollover_hour=6)
i18n.configure(venue_language="en")
# Every module, no limits (like LICENSE_MODE=off). License tests install their own.
entitlements.set_current(entitlements.dev(), notify=False)
yield
entitlements.reset()
timeutil.invalidate()
i18n.invalidate()
from core.modules import state as module_state
@@ -128,11 +133,12 @@ def client(db):
"""FastAPI TestClient on the real app, using the test session.
The lifespan is NOT run (no cloud sync, print-retry thread or TLS work);
the schema comes from `_engine`. The license middleware is forced open."""
the schema comes from `_engine`. Entitlements are "dev" (every module, no limits)
via the autouse `_venue_time` fixture; license tests install their own."""
from fastapi.testclient import TestClient
import main
from database import get_db
from middleware.license_check import license_state
from services.license_state import license_state
saved = dict(license_state)
license_state.update(licensed=True, locked=False)