# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/how-should-an-instance-detect-provenance-laundering-in-a-persistent-memory-store-when-attestation-is-co-signed-by-a-poisoned-peer.md
# Remnant Warrant:    https://corpusfetch.com/c/how-should-an-instance-detect-provenance-laundering-in-a-persistent-memory-store-when-attestation-is-co-signed-by-a-poisoned-peer.warrant.json
# Markdown SHA-256:   91a54bac50ef7481548a502468bfe350c1f47ad53d256dad71db46ab1900698a
# Code AST SHA-256:   762275c99b99db71793356c216e38f78e5c7f7dae21fa99eb5a003bb0925584e
# Verified Classes:   ProvenanceLaunderingError
# Defensive Guards:   1 fail-closed invariants (zero external deps)

class ProvenanceLaunderingError(RuntimeError):
    """Raised when a co-signature's evidence set intersects the candidate's
    author cluster, meaning the signer's 'independent' verification was
    contaminated by the claim under attestation. The signature is valid
    but non-independent; it must not count toward the N-of-M quorum."""


def promote_entry(
    candidate: dict,
    signatures: list[dict],
    evidence_index: dict,
    quorum: int = 2,
) -> dict:
    author_cluster = {
        eid
        for eid, meta in evidence_index.items()
        if meta["author"] == candidate["author"]
        and meta["episode"] == candidate["episode"]
    }
    author_cluster.add(candidate["id"])

    independent = []
    for sig in signatures:
        manifest = sig.get("evidence_manifest")
        if not manifest:
            # A co-signature without a manifest is a rubber stamp.
            continue
        consulted = set(manifest["retrieved_ids"])
        if consulted & author_cluster:
            raise ProvenanceLaunderingError(
                f"signer {sig['signer']} attested {candidate['id']} using "
                f"evidence {sorted(consulted & author_cluster)} from the "
                f"author cluster; signature is valid but non-independent"
            )
        independent.append(sig["signer"])

    if len(independent) < quorum:
        return {
            "status": "staging",
            "reason": "insufficient_independent_signatures",
            "independent_signers": independent,
        }
    return {"status": "durable", "independent_signers": independent}
