66 lines
2.0 KiB
Python
Raw Normal View History

Converge every account onto every policy agreement it has not declined An instance kept production-identical for extended manual testing is otherwise taxed forever by its own safety controls: five consents, a versioned terms gate on every mutating request, and every account predating the trust and safety commit reading terms_version NULL because init_db deliberately never backfills it. AcceptanceService grants each agreement to each account that has not declined it, so the instance stays production byte for byte while nobody clicks the same dialog again. It is opt-in, dry run by default, and one switch per agreement type. The application is not allowed to know it exists. One registration line in main.py is the only import anywhere, there is no route, schema, template, Devii tool or environment flag, and a unit test greps the tree and fails the suite if a second importer appears. The decline register needs no storage: the ledger is append-only in effect, the service only ever grants, so any withdrawn row was written by a human and that pair is never touched again. No provenance column, nothing to observe. Satisfaction is the gate's own expression, never a proxy, which is why the ordering is created_at then id exactly as consent_state selects, and why the live-account clauses are built with has_column: init_db ensures terms_version and deletion_requested_at but not is_active, so a hardcoded reference raises no such column on an instance where nobody was ever suspended. Every write is one conditional statement decided on the real rowcount, proven with sixteen processes racing one account to exactly one ledger row and one audit row. The two existing audit keys carry it, with actor kind service, because a service that silently mutated consent state would be the worst possible exception to the append-only rule. lensfl.md is the source brief accept.md records the design against. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-10 00:17:47 +02:00
# retoor <retoor@molodetz.nl>
from devplacepy.database import CONSENT_KINDS
from devplacepy.services.acceptance.agreements import (
AGREEMENTS,
agreement_for,
label_for,
setting_key,
)
from devplacepy.services.acceptance.service import AcceptanceService
def test_every_consent_kind_is_classified_as_an_agreement():
assert {agreement.kind for agreement in AGREEMENTS} == set(CONSENT_KINDS)
def test_setting_keys_are_unique_and_namespaced():
keys = [setting_key(agreement.kind) for agreement in AGREEMENTS]
assert len(keys) == len(set(keys))
for key in keys:
assert key.startswith("acceptance_grant_")
def test_every_agreement_has_a_config_field_in_the_agreements_group():
service = AcceptanceService()
fields = {field.key: field for field in service.config_fields}
for agreement in AGREEMENTS:
field = fields[setting_key(agreement.kind)]
assert field.type == "bool"
assert field.default is False
assert field.group == "Agreements"
def test_labels_come_from_the_consent_registry():
for agreement in AGREEMENTS:
assert label_for(agreement.kind) == CONSENT_KINDS[agreement.kind]
def test_only_terms_declares_a_gate_column():
gated = [agreement.kind for agreement in AGREEMENTS if agreement.gate_column]
assert gated == ["terms"]
def test_versioned_agreements_match_the_application_version_keys():
from devplacepy.routers.profile.consent import VERSION_KEYS
versioned = {
agreement.kind: agreement.version_setting
for agreement in AGREEMENTS
if agreement.version_setting
}
assert versioned == VERSION_KEYS
def test_agreement_lookup_is_total_over_the_registry():
for agreement in AGREEMENTS:
assert agreement_for(agreement.kind) is agreement
assert agreement_for("not_a_consent") is None
def test_the_service_is_opt_in_and_runs_every_five_minutes():
service = AcceptanceService()
assert service.default_enabled is False
assert service.interval_seconds == 300
assert service.is_enabled() is False