Skip to main content

No project description provided

Project description

keble-referral

keble-referral owns referral-code, referrer, wallet, policy, commission, and withdrawal-history schemas plus the Mongo/Redis-backed ReferralClient.

Exact Money Contract

keble-referral 1.1.6 interprets payment captures, commissions, wallet balances, locked balances, and withdrawal request integers as the wallet currency's ISO minor units. Percentage commissions use exact Decimal basis-point math with one explicit round-down to prevent over-credit. All stored and response Money values use the shared exponent (JPY 0, USD 2, BHD 3); no wallet path divides by 100 or rebuilds a float.

The package consumes keble-payment>=3.0.0,<4.0.0. Payment 3 keeps the commission callback contract while making typed order kind and fulfillment state canonical, so the referral callback remains idempotent against the same persisted order identity.

Withdrawal amounts must be strictly positive canonical minor units; invalid zero or negative requests fail schema validation before any wallet mutation or provider call.

Referral policy threshold and fixed-commission currencies must match the policy marketplace currency. Invalid policies fail at schema admission rather than later during a paid callback or wallet tier comparison.

Mongo Startup Index Contract

ReferralClient.ainit(amongo=...) creates idempotent Mongo indexes for the backend-used referral reads: owner/referrer lookups, referral code lookups, wallet by marketplace, withdrawal history by wallet/status/transaction, paid history by referrer/referee/wallet/order, and marketplace policy reads.

Side effect if changes: keble.backend.app.main.init_db() calls this hook before APIs/workers serve traffic; do not create these indexes inside request handlers or CRUD hot paths.

Paid-order commission application is ACID and retry-safe: history insertion and wallet credit occur in one Mongo transaction, and new rows carry partial-unique application/identity keys. The partial indexes deliberately exclude historical rows that predate those keys, so legacy duplicate wallets or histories cannot block startup; every new order can still credit at most once under concurrent callback delivery.

Testing

This repo follows the root TESTING_GUIDELINE.md. Detailed test structure notes live in docs/testing.md.

Local-full development command:

RUN_INTEGRATION=1 RUN_REAL_DB=1 RUN_LOCAL_STACK=1 RUN_DB_STACK=1 \
  uv run pytest -q -m "not live and not container"

Portable-offline command:

uv run pytest -q -m "not live and not slow and not eval and not local_stack and not db_stack and not container"

Run schema-only unit tests:

uv run pytest -m unit

Run real Mongo/Redis integration tests:

RUN_INTEGRATION=1 RUN_REAL_DB=1 RUN_LOCAL_STACK=1 uv run pytest -q -m integration

Eval selector:

uv run pytest -q -m eval

Integration tests require:

MONGO_DB_URI or MONGO_TEST_URI
REDIS_URI or REDIS_TEST_URI

The test settings resolve those aliases through keble_db.testing.resolve_test_env, so clean worktrees can reuse credentials from the umbrella keble.backend/.env without committing package-local secrets.

Run the Python syntax/type gate:

npx --yes pyright .

Latest 2026-07-22 release proof: payment 3 dependency resolution, local-full pytest, Pyright, Ruff, and wheel/sdist gates passed.

Previous 2026-07-18 proof: exact Money edge slice 11 passed; portable 70 passed, 284 deselected; isolated local-full 355 passed; isolated integration 284 passed, 71 deselected; Pyright 0 errors; Ruff, lock, and wheel/sdist build gates passed.

Layer mapping:

  • tests/unit/schemas/ is the fast unit layer when tests do not request DB fixtures.
  • tests/integration/crud/, tests/integration/main/, and tests/integration/workflows/ are guarded integration, db, mongo, redis, and local_stack tests.
  • Future referral quality or policy-regression datasets belong under tests/evals with eval; selecting -m eval is enough, so do not add a generic RUN_EVALS gate.
  • Mongo databases, collection names, and Redis namespaces are generated per test with keble_db.testing.create_test_namespace; do not reintroduce broad shared DB cleanup.
  • External withdrawal execution remains mocked by default; do not add real payment-provider calls to default tests.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

keble_referral-1.1.6.tar.gz (595.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

keble_referral-1.1.6-py3-none-any.whl (37.2 kB view details)

Uploaded Python 3

File details

Details for the file keble_referral-1.1.6.tar.gz.

File metadata

  • Download URL: keble_referral-1.1.6.tar.gz
  • Upload date:
  • Size: 595.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for keble_referral-1.1.6.tar.gz
Algorithm Hash digest
SHA256 2ea8e9c8d4b869f800b1b8e091866ba615555fb4525427d285bc14fafdba066c
MD5 38039d84ec80b99d3729befc3f83ae2c
BLAKE2b-256 83f5c56e28ad44b55d6dedfbde2bb32b82f21dc7e49430e3b1ac7a9b38256119

See more details on using hashes here.

File details

Details for the file keble_referral-1.1.6-py3-none-any.whl.

File metadata

  • Download URL: keble_referral-1.1.6-py3-none-any.whl
  • Upload date:
  • Size: 37.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for keble_referral-1.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 5b600d3b37feff02c2cd73f6f2cd11a7b45b26bc6a4ad8c4594723553fe268b3
MD5 fe55eeb8bb05cf7cff7110a6c69c19c4
BLAKE2b-256 a7be96e71beeb457ea0d0f0d2d25f8271fb2b272f75b2632fa5ff799307fe585

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page