CodeSampleX

샘플

referencing 0.37.0

검증된 샘플 — pypi referencing 0.37.0. python 3.12 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: assert Resource.from_contents detects specification from…

sha256:8f92f22f2d7afc34c633f943cd4d77e2f0a165f90641de86337ee5209f8ebba3

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 python 3.12 linux 24 · alpine · musl x64 python 3.12 python pip 24

검증 실행 환경

환경 컨트랙트 단계 실행일
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

케이스

HOW
목표
verify pkg:pypi/referencing@0.37.0
패키지
환경
python 3.12
생성일
2026-08-27T18:35:40Z

컨트랙트

  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

파일

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

소스 아티팩트 내려받기 (tar.gz)

소스

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()

오리진 시더

익명