Skip to main content

Module contracts_lock

Module contracts_lock 

Source
Expand description

#2554: bynk.contracts.lock, the older service contracts a callee still accepts, as a document.

A callee compares the X-Bynk-Contract hash a caller stamps with its own (ADR 0200). Once the classifier (bynk_check::contract_compat, #2485) can say a change is compatible, a callee can be deployed ahead of its callers if it also accepts the hash they were compiled against. That hash cannot be derived from the callee’s source, which only knows the contract it has now, so the older contracts are recorded here, committed, and visible in review.

The document holds the older contracts as the shape text (bynk_check::contract_compat::ServiceShape::to_text), not hashes: the build re-checks each against the contract the callee has now, and a hash cannot be classified. This module is pure, like schema_registry: it reads and writes no disk. bynk-driver’s contracts_lock module owns the file, and bynk-check owns what the shapes mean.

version = 1

[accepts."shop.payment"]
charge = ['Svc("charge",P("order",B("Int")),Ret(B("Bool")))']

Structs§

ContractsLock
The older shapes each context’s services accept: qualified context name (shop.payment) to service to shape texts, oldest first.

Constants§

ACCEPTED_CAP
How many older contracts one service may accept before the build warns. A callee that accepts a long tail has not been pruned: callers have moved on.
LOCK_FILE
The file at the project root.

Functions§

corrupt_error
bynk.project.contracts_lock_corrupt: the lock cannot be read. Like the schema lock, it fails the build rather than reading as empty.
oversized_warning
bynk.project.contracts_lock_oversized (warning): a service accepts more than ACCEPTED_CAP older contracts.
parse
Read the lock’s pre-read content. None is a project that has none, which accepts nothing. Some(text) that is empty, unparseable or of another version is corruption and fails: a callee silently forgetting the callers it accepts would answer them 409 in production.
serialize
The lock’s TOML form. Cannot fail for this data shape (string keys and string lists).
stale_warning
bynk.project.contracts_lock_stale (warning): an entry the callee does not accept, because it is unreadable or no longer compatible with the contract the service has now. The build leaves it out; the lock is not rewritten.