Waiver
waiver
Acknowledged-cluster waiver mechanism, factored and key-schema agnostic.
This is the single implementation of the cluster-acknowledgement contract used by the AXM duplicate-detection tools. It is intentionally parametrizable by the key schema that identifies a cluster member, so the same hash and the same mark/stale/validate logic serve different callers:
echo_codehashes a cluster on its members'(package, qualname);duplicate_tests(audit) hashes on(file, name).
The algorithm is ported byte-for-byte (modulo the key parameter) from
axm_audit.core.rules.test_quality.duplicate_tests so the two tools agree
on what a cluster hash is -- the anti-duplication tool must not duplicate its
own waiver mechanism. A later ticket may have duplicate_tests import this
module to drop its private copy; that migration is out of scope here.
The contract:
- :func:
cluster_hash-- order-independent 12-hex digest of a cluster's member key set (members sorted before serialization, so the hash is robust to ordering and to line drift, sensitive only to membership). - :func:
validate_acknowledged_entry-- graceful schema validation: returns an error message for a malformed waiver,Nonewhen valid; never raises. - :func:
mark_acknowledged-- stampsacknowledged=Trueon every live cluster whosecluster_hashis waived. - :func:
stale_acknowledged-- the virtuous half: waivers whose hash matches no live cluster ("this waiver no longer serves a purpose, retire it"). - :func:
extract_acknowledged_section-- pull the[[tool.<tool>.<rule>]]acknowledged table out of a parsed pyproject mapping.
cluster_hash(cluster, *, key_fields)
Compute a stable 12-hex-char hash of a cluster's member key set.
The hash is order-independent (members are sorted before serialization) and
depends only on key_fields -- the chosen identity of a member. For
echo_code pass key_fields=("package", "qualname"); for the audit
duplicate-tests rule pass ("file", "name"). Two clusters with the same
membership under the same key schema hash identically; the same membership
under a different key schema hashes differently.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cluster
|
Mapping[str, object]
|
A mapping carrying a |
required |
key_fields
|
Sequence[str]
|
The member fields, in order, that define member identity. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The first :data: |
str
|
canonically-serialized member key tuples. |
Source code in packages/axm-echo/src/axm_echo/waiver.py
extract_acknowledged_section(data, *, tool, rule)
Pull the [[tool.<tool>.<rule>]] acknowledged table from a pyproject.
Walks data["tool"][tool][rule] defensively: any missing or non-mapping
level yields {} so a malformed or absent section degrades gracefully.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
object
|
The parsed pyproject mapping (or anything, defensively). |
required |
tool
|
str
|
The tool table name (e.g. |
required |
rule
|
str
|
The rule/section name (e.g. |
required |
Returns:
| Type | Description |
|---|---|
object
|
The nested section value, or |
Source code in packages/axm-echo/src/axm_echo/waiver.py
mark_acknowledged(clusters, acknowledged)
Stamp acknowledged=True on every live cluster that is waived.
A cluster is waived when its "cluster_hash" appears among the waiver
hashes. Mutates the cluster mappings in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
clusters
|
list[dict[str, object]]
|
Live clusters, each carrying a |
required |
acknowledged
|
list[dict[str, str]]
|
Validated waiver entries (each with a |
required |
Source code in packages/axm-echo/src/axm_echo/waiver.py
stale_acknowledged(clusters, acknowledged)
Return the waivers whose hash matches no live cluster (stale, retirable).
This is the virtuous half of the mechanism: a waiver that no longer covers any live cluster is dead weight and should be removed from the pyproject. Informative only -- it never blocks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
clusters
|
list[dict[str, object]]
|
Live clusters, each carrying a |
required |
acknowledged
|
list[dict[str, str]]
|
Validated waiver entries (each with a |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, str]]
|
The subset of |
Source code in packages/axm-echo/src/axm_echo/waiver.py
validate_acknowledged_entry(entry)
Validate one acknowledged-waiver entry; return an error or None.
A valid entry is a table with a 12-char hex hash and a non-empty
reason. On any violation an explanatory message is returned (never an
exception) so the caller can surface it gracefully instead of crashing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entry
|
object
|
The raw waiver entry parsed from the pyproject. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
An error message string if the entry is malformed, else |