CodeSampleX

Exemple

structlog 26.1.0: Prove that `structlog` binding APIs do not mutate an existing logger instance.

Échantillon vérifié pour pypi structlog 26.1.0: Prove that `structlog` binding APIs do not mutate an existing logger instance. Le contrat s'est exécuté sur…

sha256:860cb1a769dff8104efd29459c32a26bdec09b05ed739c73df0632ac4719b4e5

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
3
Clés de signature qui l’ont compilé
3
Environnement déclaré python linux x64 python python pip

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
python 3.12 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · python@1
2026-08-17
python 3.12 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · python@1
2026-08-18
python 3.12 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · python@1python:3.12-slim@sha256:09f7da3bc104…
2026-09-08

Cas

HOW
Objectif
Prove that `structlog` binding APIs do not mutate an existing logger instance.
Paquets
Symboles
  • structlog.get_logger
  • structlog.configure
  • structlog.testing.capture_logs
Environnement
python
Créé
2026-08-17T03:54:30Z

Contrat

  1. assert logger is not logger_bound
  2. assert captured[0].get('user') == 'alice'
  3. assert 'user' not in captured[1]

Fichiers

  • NOTES.md
  • csx.json
  • requirements.txt
  • test/contract.py

Télécharger l’artefact source (tar.gz)

Code source

NOTES.md
# Notes

`search_known_solution` returned a compatible existing sample for structlog integration (`case:sha256:2d6ee21327f92d4ac51657e55ce179714708af915d368fe18433a80d9aa7931b`), which proves `dictConfig`, `ProcessorFormatter` placement, and `disable_existing_loggers` interaction.

A naive model would expect `logger.bind(...)` to mutate the same logger instance, which in this sample fails with `assert logger is not logger_bound`.
csx.json
{"case":{"believed":"A caller expects `bind` to mutate the original logger and return that same object.","caseId":"case:sha256:3ca7fa9e3d5ded6c84380644920e11eef657e22a113ebdd6fc93437c424169a2","contract":["assert logger is not logger_bound","assert captured[0].get('user') == 'alice'","assert 'user' not in captured[1]"],"goal":"Prove that `structlog` binding APIs do not mutate an existing logger instance.","kind":"HOW","packages":["pkg:pypi/structlog@26.1.0"],"schemaVersion":1,"symbols":["structlog.get_logger","structlog.configure","structlog.testing.capture_logs"]},"contractCommand":["python","test/contract.py"],"environment":{"arch":"x64","ecosystem":"pypi","executionContext":"python","language":"python","os":"linux","packageManager":"pip","runtime":"python","schemaVersion":1},"license":"MIT-0","packages":["pkg:pypi/structlog@26.1.0"],"schemaVersion":1,"symbols":["structlog.get_logger","structlog.configure","structlog.testing.capture_logs"],"verifierAdapter":"python@1"}
requirements.txt
structlog==26.1.0
test/contract.py
import structlog
from structlog.testing import CapturingLoggerFactory, capture_logs


def main() -> None:
    structlog.configure(processors=[], logger_factory=CapturingLoggerFactory())

    logger = structlog.get_logger()
    logger_bound = logger.bind(user="alice")

    with capture_logs() as captured:
        logger_bound.info("bound event")
        logger.info("plain event")

    assert logger is not logger_bound
    assert captured[0].get("user") == "alice"
    assert "user" not in captured[1]


if __name__ == "__main__":
    main()

Seeder d'origine

csx-seed