Skip to main content

Multi-language IR-Runtime common core (Python port). The COMMON 'thin core' primitives from dsl-contracts runtime-boundary.md — validate_envelope / evaluate_expression / render_template / run_plan / canonical_value / canonical_json / py_float_repr / assert_portable — with zero backend (DynamoDB/graphddb) dependencies.

Project description

behavior-contracts (Python)

The COMMON "thin core" runtime primitives from runtime-boundary.md, ported to Python from the TypeScript reference implementation (ts/src/*) with identical semantics.

This package contains only the DSL-agnostic primitives that WS1 classified as COMMON. It has zero backend (DynamoDB / graphddb) dependencies — no boto3, no key marshalling, no retry tuning, no hydrate, no bundle format. Those stay in the consumer (graphddb).

Public API

from behavior_contracts import (
    validate_envelope,     # spec-version fail-closed check
    evaluate_expression,   # expression-ir.md evaluator (i64-checked, truncated %, code-point cmp)
    render_template,        # {param} rendering (strict, Python str() parity)
    run_plan, final_tree,   # execution-plan skeleton (stage / Skip propagation / Policy Kind)
    canonical_value,        # key identity (top-level key sort)
    canonical_json,         # fingerprint (recursive key sort)
    py_float_repr,          # CPython repr(float) canonical decimal
    assert_portable,        # Portability Guard
    decode_value, deep_equals,  # conformance runner adapter (int/float type distinction)
    encode_value, resolve_partial, cmp_code_points,
    SPEC_VERSIONS, ENVELOPE_SPEC_VERSION,
)

Each COMMON primitive raises a typed *Failure exception carrying a .code string matching the conformance protocol's failure-code set.

§8 cross-language traps this port handles

  • % sign: normative mod is truncated (dividend sign). Python's native % returns the divisor sign, so evaluate_expression({"mod":[-7,2]}) == -1 (native -7 % 2 == 1). Implemented via truncated-quotient correction; float mod via math.fmod.
  • int is checked i64: Python int is arbitrary-precision, so i64 bounds are enforced manually; overflow → INT_OVERFLOW.
  • string comparison: code-point order. Python str compares by code point already (no UTF-16 surrogate hazard) — verified in tests.
  • NaN/Inf → Failure; div always float with |int| > 2^53 widening → PRECISION_LOSS; py_float_repr matches CPython repr(float) byte-for-byte (parametrized parity tests).
  • bool is not int: isinstance(x, bool) is checked before int everywhere (Python's bool <: int).

Conformance

Runs the 7 shared suites (147 vectors) from ../conformance/vectors/*.json through this package per ../conformance/PROTOCOL.md, including the pre-flight version fail-closed sweep.

python -m behavior_contracts.conformance      # → "147 passed, 0 failed / 147 vectors across 7 suites"
# or the console script:
behavior-contracts-conformance

Override the vectors location with DSL_CONTRACTS_VECTORS=/path/to/vectors.

Tests

pip install -e ".[test]"
python -m pytest        # unit tests over the public API + the conformance runner as a test

Docker integration: N/A

This package has no external service dependency (no database, no network) — it is pure in-process logic over JSON-shaped values. There is therefore nothing for a docker-compose integration harness to stand up; the conformance runner and pytest exercise the full surface in-process. (The graphddb adapter PoC in WS4 Part B is where docker-backed integration applies, because graphddb talks to DynamoDB Local.)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

behavior_contracts-0.2.0.tar.gz (45.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

behavior_contracts-0.2.0-py3-none-any.whl (40.1 kB view details)

Uploaded Python 3

File details

Details for the file behavior_contracts-0.2.0.tar.gz.

File metadata

  • Download URL: behavior_contracts-0.2.0.tar.gz
  • Upload date:
  • Size: 45.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for behavior_contracts-0.2.0.tar.gz
Algorithm Hash digest
SHA256 20d080b44573016051e63ab7a4014c74846d3b2cdfd3eab5cb2e01dcbf1c255c
MD5 f314f7f869bb1d6a9141da6eb6270fd1
BLAKE2b-256 864b8f54d2effe7fad54e0870175f9b01310afdb020cff6fbfe66ed793de6aa1

See more details on using hashes here.

File details

Details for the file behavior_contracts-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for behavior_contracts-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ce7a1716d57128ed6f6583e6bbe03377c080c722672e262cca4d3d5f37c485c8
MD5 7e826f4c274b18854b3dac0f60ba79d6
BLAKE2b-256 e0a8ccfda77f345c8c5e97943057c6e22ca2fc7b29ce4e271eaf8903aeb33e58

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page