CodeSampleX

Beispiel

referencing 0.37.0

Verifiziertes Beispiel für pypi referencing 0.37.0. Der Vertrag lief auf python 3.12 · linux alpine/x64 · docker und bestand: assert Resource.from_contents…

sha256:8f92f22f2d7afc34c633f943cd4d77e2f0a165f90641de86337ee5209f8ebba3

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung python 3.12 linux 24 · alpine · musl x64 python 3.12 python pip 24

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
python 3.12 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · python@1python:3.12-alpine@sha256:d09d15e60962…
2026-08-27

Fall

HOW
Ziel
verify pkg:pypi/referencing@0.37.0
Pakete
Umgebung
python 3.12
Erstellt
2026-08-27T18:35:40Z

Contract

  1. assert Resource.from_contents detects specification from $schema keyword and preserves schema contents
  2. assert Resource.from_contents raises CannotDetermineSpecification when $schema is absent unless default_specification is provided
  3. assert Registry is immutable and stores resources via with_resource and with_contents
  4. assert Resolver.lookup resolves schemas by absolute URI and JSON Pointer
  5. assert Resolver.lookup resolves internal resource schemas by $anchor
  6. assert Resolver with base_uri resolves relative references across registered resources
  7. assert Registry and Resolver raise NoSuchResource, Unresolvable, PointerToNowhere, and NoSuchAnchor on lookup errors
  8. assert Registry with custom retrieve callback dynamically resolves resources on demand

Dateien

  • PROMPT.md
  • csx.json
  • pyproject.toml
  • requirements.txt
  • spec.json
  • test/contract.py

Quellartefakt herunterladen (tar.gz)

Quelltext

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify pkg:pypi/referencing@0.37.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:pypi/referencing@0.37.0
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:914e2bac95cc4a624d6d1d303730d6fc4135da9065dd410bce092990b583d668","constraints":{"executionContext":"python"},"contract":["assert Resource.from_contents detects specification from $schema keyword and preserves schema contents","assert Resource.from_contents raises CannotDetermineSpecification when $schema is absent unless default_specification is provided","assert Registry is immutable and stores resources via with_resource and with_contents","assert Resolver.lookup resolves schemas by absolute URI and JSON Pointer","assert Resolver.lookup resolves internal resource schemas by $anchor","assert Resolver with base_uri resolves relative references across registered resources","assert Registry and Resolver raise NoSuchResource, Unresolvable, PointerToNowhere, and NoSuchAnchor on lookup errors","assert Registry with custom retrieve callback dynamically resolves resources on demand"],"goal":"verify pkg:pypi/referencing@0.37.0","kind":"HOW","packages":["pkg:pypi/referencing@0.37.0"],"schemaVersion":1},"contractCommand":["python3","test/contract.py"],"environment":{"arch":"x64","distro":"alpine","ecosystem":"pypi","executionContext":"python","language":"python","libc":"musl","moduleSystem":"standard","os":"linux","osVersionBucket":"24","packageManager":"pip","packageManagerVersion":"24.0","runtime":"python","runtimeVersion":"3.12","schemaVersion":1},"license":"MIT-0","packages":["pkg:pypi/referencing@0.37.0"],"schemaVersion":1,"subject":"pkg:pypi/referencing@0.37.0","verifierAdapter":"python@1"}
pyproject.toml
[project]
name = "verify-referencing"
version = "0.1.0"
dependencies = [
    "referencing==0.37.0",
    "attrs==25.4.0",
    "rpds-py==0.22.3",
    "typing-extensions==4.12.2",
]
requirements.txt
referencing==0.37.0
attrs==25.4.0
rpds-py==0.22.3
typing-extensions==4.12.2
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:pypi/referencing@0.37.0",
  "kind": "HOW",
  "packages": [
    "pkg:pypi/referencing@0.37.0"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.py
import referencing
from referencing import Registry, Resource
from referencing.jsonschema import DRAFT202012
from referencing.exceptions import (
    CannotDetermineSpecification,
    NoSuchResource,
    NoSuchAnchor,
    PointerToNowhere,
    Unresolvable,
)


def test_resource_from_contents_detection():
    schema = {
        "$id": "https://example.com/schemas/person",
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "type": "object",
        "properties": {
            "name": {"type": "string"},
            "age": {"type": "integer", "minimum": 0}
        },
        "$defs": {
            "address": {
                "$anchor": "addressAnchor",
                "type": "object",
                "properties": {"street": {"type": "string"}, "city": {"type": "string"}}
            }
        }
    }
    resource = Resource.from_contents(schema)
    assert resource.id() == "https://example.com/schemas/person"
    assert resource.contents == schema


def test_resource_from_contents_specification_requirement():
    schema_unspecified = {"type": "string", "maxLength": 50}
    try:
        Resource.from_contents(schema_unspecified)
        assert False, "Expected CannotDetermineSpecification when $schema is absent"
    except CannotDetermineSpecification as exc:
        assert exc.contents == schema_unspecified

    resource_with_default = Resource.from_contents(schema_unspecified, default_specification=DRAFT202012)
    assert resource_with_default.contents == schema_unspecified


def test_registry_immutability_and_registration():
    schema = {
        "$id": "https://example.com/schemas/item",
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "type": "object",
        "properties": {"sku": {"type": "string"}, "price": {"type": "number"}}
    }
    empty_registry = Registry()
    resource = Resource.from_contents(schema)
    registry_with_resource = empty_registry.with_resource("https://example.com/schemas/item", resource)

    assert len(empty_registry) == 0
    assert len(registry_with_resource) == 1
    assert "https://example.com/schemas/item" in registry_with_resource
    assert registry_with_resource["https://example.com/schemas/item"] == resource

    registry_with_contents = empty_registry.with_contents([("https://example.com/schemas/item", schema)])
    assert len(registry_with_contents) == 1
    assert "https://example.com/schemas/item" in registry_with_contents


def test_resolver_lookup_uri_and_pointer():
    schema = {
        "$id": "https://example.com/schemas/catalog",
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "type": "object",
        "properties": {
            "title": {"type": "string"},
            "count": {"type": "integer"}
        }
    }
    registry = Registry().with_contents([("https://example.com/schemas/catalog", schema)])
    resolver = registry.resolver()

    resolved_root = resolver.lookup("https://example.com/schemas/catalog")
    assert resolved_root.contents == schema

    resolved_title = resolver.lookup("https://example.com/schemas/catalog#/properties/title")
    assert resolved_title.contents == {"type": "string"}


def test_resolver_lookup_anchor():
    schema = {
        "$id": "https://example.com/schemas/models",
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "type": "object",
        "$defs": {
            "user": {
                "$anchor": "userAnchor",
                "type": "object",
                "properties": {"username": {"type": "string"}}
            }
        }
    }
    registry = Registry().with_contents([("https://example.com/schemas/models", schema)])
    resolver = registry.resolver()

    resolved_anchor = resolver.lookup("https://example.com/schemas/models#userAnchor")
    assert resolved_anchor.contents["type"] == "object"
    assert "username" in resolved_anchor.contents["properties"]


def test_resolver_base_uri_scoping():
    schema_user = {
        "$id": "https://example.com/schemas/user",
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "type": "object",
        "properties": {"id": {"type": "string"}}
    }
    schema_order = {
        "$id": "https://example.com/schemas/order",
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "type": "object",
        "properties": {
            "customer": {"$ref": "user"}
        }
    }
    registry = Registry().with_contents([
        ("https://example.com/schemas/user", schema_user),
        ("https://example.com/schemas/order", schema_order),
    ])

    order_resolver = registry.resolver(base_uri="https://example.com/schemas/order")
    resolved_customer = order_resolver.lookup("user")
    assert resolved_customer.contents == schema_user


def test_resolver_error_handling():
    schema = {
        "$id": "https://example.com/schemas/target",
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "type": "object",
        "properties": {"value": {"type": "string"}}
    }
    registry = Registry().with_contents([("https://example.com/schemas/target", schema)])
    resolver = registry.resolver()

    try:
        _ = registry["https://example.com/schemas/nonexistent"]
        assert False, "Expected NoSuchResource"
    except NoSuchResource as exc:
        assert exc.ref == "https://example.com/schemas/nonexistent"

    try:
        resolver.lookup("https://example.com/schemas/nonexistent")
        assert False, "Expected Unresolvable"
    except Unresolvable as exc:
        assert exc.ref == "https://example.com/schemas/nonexistent"

    try:
        resolver.lookup("https://example.com/schemas/target#/properties/missing")
        assert False, "Expected PointerToNowhere"
    except PointerToNowhere as exc:
        assert exc.ref == "/properties/missing"

    try:
        resolver.lookup("https://example.com/schemas/target#missingAnchor")
        assert False, "Expected NoSuchAnchor"
    except NoSuchAnchor as exc:
        assert exc.anchor == "missingAnchor"


def test_registry_dynamic_retrieve_callback():
    def custom_retrieve(uri):
        if uri == "https://example.com/schemas/dynamically-loaded":
            return Resource.from_contents({
                "$id": "https://example.com/schemas/dynamically-loaded",
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "boolean"
            })
        raise NoSuchResource(ref=uri)

    registry = Registry(retrieve=custom_retrieve)
    resolver = registry.resolver()
    resolved = resolver.lookup("https://example.com/schemas/dynamically-loaded")
    assert resolved.contents["type"] == "boolean"


def main():
    test_resource_from_contents_detection()
    test_resource_from_contents_specification_requirement()
    test_registry_immutability_and_registration()
    test_resolver_lookup_uri_and_pointer()
    test_resolver_lookup_anchor()
    test_resolver_base_uri_scoping()
    test_resolver_error_handling()
    test_registry_dynamic_retrieve_callback()
    print("All referencing contract tests passed successfully.")


if __name__ == "__main__":
    main()

Ursprungs-Seeder

anonym