dragon-py-core 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dragon_py_core-0.1.0/PKG-INFO +13 -0
- dragon_py_core-0.1.0/README.md +4 -0
- dragon_py_core-0.1.0/pyproject.toml +15 -0
- dragon_py_core-0.1.0/setup.cfg +4 -0
- dragon_py_core-0.1.0/src/dragon_py_core/__init__.py +27 -0
- dragon_py_core-0.1.0/src/dragon_py_core/contracts.py +59 -0
- dragon_py_core-0.1.0/src/dragon_py_core/fixtures.py +25 -0
- dragon_py_core-0.1.0/src/dragon_py_core.egg-info/PKG-INFO +13 -0
- dragon_py_core-0.1.0/src/dragon_py_core.egg-info/SOURCES.txt +11 -0
- dragon_py_core-0.1.0/src/dragon_py_core.egg-info/dependency_links.txt +1 -0
- dragon_py_core-0.1.0/src/dragon_py_core.egg-info/requires.txt +1 -0
- dragon_py_core-0.1.0/src/dragon_py_core.egg-info/top_level.txt +1 -0
- dragon_py_core-0.1.0/tests/test_conformance.py +40 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dragon-py-core
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: DRAGON 领域框架契约面(Python SDK):与 TS zod 正本逐值对齐的 pydantic 模型 + seam fixture 装载
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: pydantic>=1.10
|
|
9
|
+
|
|
10
|
+
# dragon-py-core
|
|
11
|
+
|
|
12
|
+
DRAGON 领域框架 Python SDK 组件(core 面)。用法与多语言一致性门禁见
|
|
13
|
+
[python/README.md](../README.md);框架主仓:DRAGON 领域框架(Apache-2.0)。
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "dragon-py-core"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "DRAGON 领域框架契约面(Python SDK):与 TS zod 正本逐值对齐的 pydantic 模型 + seam fixture 装载"
|
|
9
|
+
requires-python = ">=3.10"
|
|
10
|
+
license = {text = "Apache-2.0"}
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
dependencies = ["pydantic>=1.10"]
|
|
13
|
+
|
|
14
|
+
[tool.setuptools.packages.find]
|
|
15
|
+
where = ["src"]
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""dragon_py_core — DRAGON 领域框架契约面(Python SDK)。
|
|
2
|
+
|
|
3
|
+
与 TS 契约正本(`packages/is-contracts`,zod schema)逐值对齐;对齐门禁 = 与 TS 侧
|
|
4
|
+
消费同一套 seam fixture(`fixtures/seams/`)——多语言合规锚(Paper 2 §4/§6 证据面)。
|
|
5
|
+
|
|
6
|
+
兼容 pydantic v1 惯用法(在 v2 下带弃用告警运行)。
|
|
7
|
+
"""
|
|
8
|
+
from dragon_py_core.contracts import (
|
|
9
|
+
AutonomyLevel,
|
|
10
|
+
Envelope,
|
|
11
|
+
IsDescriptor,
|
|
12
|
+
LOW_CONFIDENCE_THRESHOLD,
|
|
13
|
+
Sla,
|
|
14
|
+
UNLABELED_AUTONOMY_FALLBACK,
|
|
15
|
+
)
|
|
16
|
+
from dragon_py_core.fixtures import load_seam_fixture, seams_root
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"AutonomyLevel",
|
|
20
|
+
"Envelope",
|
|
21
|
+
"IsDescriptor",
|
|
22
|
+
"LOW_CONFIDENCE_THRESHOLD",
|
|
23
|
+
"Sla",
|
|
24
|
+
"UNLABELED_AUTONOMY_FALLBACK",
|
|
25
|
+
"load_seam_fixture",
|
|
26
|
+
"seams_root",
|
|
27
|
+
]
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""L3 契约面(Python 侧)——与 TS 正本 `packages/is-contracts` 逐值对齐。
|
|
2
|
+
|
|
3
|
+
对齐纪律(同 contract-fuzz 的双语言纪律):值域/缺省/阈值任何一侧漂移,
|
|
4
|
+
`tests/test_conformance.py` 对 seam fixture 的断言即失败。
|
|
5
|
+
"""
|
|
6
|
+
from enum import Enum
|
|
7
|
+
from typing import List, Optional
|
|
8
|
+
|
|
9
|
+
from pydantic import BaseModel, Field, confloat
|
|
10
|
+
|
|
11
|
+
# 与 TS `meta/contract/src/autonomy.ts` 同值域;未标注缺省 L3(fail-closed,GADR-028)
|
|
12
|
+
UNLABELED_AUTONOMY_FALLBACK = "L3"
|
|
13
|
+
|
|
14
|
+
# 与 TS `is-contracts` LOW_CONFIDENCE_THRESHOLD 同值(编排决策分界)
|
|
15
|
+
LOW_CONFIDENCE_THRESHOLD = 0.6
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class AutonomyLevel(str, Enum):
|
|
19
|
+
L0 = "L0"
|
|
20
|
+
L1 = "L1"
|
|
21
|
+
L2 = "L2"
|
|
22
|
+
L3 = "L3"
|
|
23
|
+
L4 = "L4"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class Sla(BaseModel):
|
|
27
|
+
target_latency_ms: Optional[int] = Field(default=None, alias="targetLatencyMs")
|
|
28
|
+
availability: Optional[confloat(ge=0, le=1)] = None
|
|
29
|
+
|
|
30
|
+
class Config:
|
|
31
|
+
allow_population_by_field_name = True
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class Envelope(BaseModel):
|
|
35
|
+
"""概率契约(C1):置信度 + SLA + 前提 + 可降级。"""
|
|
36
|
+
|
|
37
|
+
confidence: confloat(ge=0, le=1)
|
|
38
|
+
sla: Optional[Sla] = None
|
|
39
|
+
preconditions: List[str] = Field(default_factory=list)
|
|
40
|
+
degradable: Optional[dict] = None
|
|
41
|
+
|
|
42
|
+
def is_low_confidence(self) -> bool:
|
|
43
|
+
return self.confidence < LOW_CONFIDENCE_THRESHOLD
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class IsDescriptor(BaseModel):
|
|
47
|
+
"""IS 契约描述符(Python 侧最小面——完整字段以 TS zod schema 为准)。"""
|
|
48
|
+
|
|
49
|
+
is_id: str = Field(alias="isId")
|
|
50
|
+
name: str
|
|
51
|
+
role: str # L1..L5
|
|
52
|
+
scope: str # IS | IIS
|
|
53
|
+
networkable: bool = False
|
|
54
|
+
envelope: Envelope
|
|
55
|
+
autonomy: AutonomyLevel = AutonomyLevel(UNLABELED_AUTONOMY_FALLBACK)
|
|
56
|
+
contract_version: str = Field(alias="contractVersion")
|
|
57
|
+
|
|
58
|
+
class Config:
|
|
59
|
+
allow_population_by_field_name = True
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""seam fixture 装载——多语言合规锚(OSR-15 的 Python 消费面)。
|
|
2
|
+
|
|
3
|
+
Python SDK 与 TS 内核消费**同一份** `fixtures/seams/*.json`:fixture 是契约锁,
|
|
4
|
+
任何一侧漂移在两侧测试同时失败。
|
|
5
|
+
"""
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Any, Dict
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def seams_root() -> Path:
|
|
13
|
+
"""定位 fixtures/seams 根(env 可覆盖:DRAGON_REPO_ROOT)。"""
|
|
14
|
+
override = os.environ.get("DRAGON_REPO_ROOT")
|
|
15
|
+
if override:
|
|
16
|
+
return Path(override) / "fixtures" / "seams"
|
|
17
|
+
# 本文件 <repo>/python/dragon_py_core/src/dragon_py_core/fixtures.py → 上溯 4 级到仓根
|
|
18
|
+
return Path(__file__).resolve().parents[4] / "fixtures" / "seams"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def load_seam_fixture(name: str) -> Dict[str, Any]:
|
|
22
|
+
"""按文件名装载 seam fixture(如 "s7-value-domains.json")。"""
|
|
23
|
+
path = seams_root() / name
|
|
24
|
+
with path.open(encoding="utf-8") as fh:
|
|
25
|
+
return json.load(fh)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dragon-py-core
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: DRAGON 领域框架契约面(Python SDK):与 TS zod 正本逐值对齐的 pydantic 模型 + seam fixture 装载
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: pydantic>=1.10
|
|
9
|
+
|
|
10
|
+
# dragon-py-core
|
|
11
|
+
|
|
12
|
+
DRAGON 领域框架 Python SDK 组件(core 面)。用法与多语言一致性门禁见
|
|
13
|
+
[python/README.md](../README.md);框架主仓:DRAGON 领域框架(Apache-2.0)。
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
src/dragon_py_core/__init__.py
|
|
4
|
+
src/dragon_py_core/contracts.py
|
|
5
|
+
src/dragon_py_core/fixtures.py
|
|
6
|
+
src/dragon_py_core.egg-info/PKG-INFO
|
|
7
|
+
src/dragon_py_core.egg-info/SOURCES.txt
|
|
8
|
+
src/dragon_py_core.egg-info/dependency_links.txt
|
|
9
|
+
src/dragon_py_core.egg-info/requires.txt
|
|
10
|
+
src/dragon_py_core.egg-info/top_level.txt
|
|
11
|
+
tests/test_conformance.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pydantic>=1.10
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
dragon_py_core
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""多语言合规一致性门禁(Python 侧):SDK 契约面 ↔ seam fixture 逐值对齐。
|
|
2
|
+
|
|
3
|
+
与 TS 侧 `packages/ara-tests/tests/seam-compliance.spec.ts` 消费同一套 fixture——
|
|
4
|
+
两语言测试互为镜像,任一语言漂移即该侧失败(Paper 2 §4「同一 fixture 集自检」的多语言实例)。
|
|
5
|
+
"""
|
|
6
|
+
from dragon_py_core import (
|
|
7
|
+
AutonomyLevel,
|
|
8
|
+
Envelope,
|
|
9
|
+
LOW_CONFIDENCE_THRESHOLD,
|
|
10
|
+
UNLABELED_AUTONOMY_FALLBACK,
|
|
11
|
+
load_seam_fixture,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def test_autonomy_domain_matches_seam_fixture():
|
|
16
|
+
s7 = load_seam_fixture("s7-value-domains.json")
|
|
17
|
+
assert s7["autonomy"]["domain"] == [lvl.value for lvl in AutonomyLevel]
|
|
18
|
+
# 未标注缺省 fail-closed:两侧同为 L3(GADR-028)
|
|
19
|
+
assert s7["autonomy"]["unlabeledDefault"].startswith(UNLABELED_AUTONOMY_FALLBACK)
|
|
20
|
+
assert UNLABELED_AUTONOMY_FALLBACK == "L3"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def test_envelope_confidence_bounds_match_contract():
|
|
24
|
+
env = Envelope(confidence=0.9)
|
|
25
|
+
assert env.confidence == 0.9
|
|
26
|
+
assert env.is_low_confidence() is False
|
|
27
|
+
assert Envelope(confidence=0.42).is_low_confidence() is True
|
|
28
|
+
# 阈值是编排分界——低于即触发重试/兜底/人审
|
|
29
|
+
assert LOW_CONFIDENCE_THRESHOLD == 0.6
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_approval_verbs_match_seam_fixture():
|
|
33
|
+
s1 = load_seam_fixture("s1-approval.json")
|
|
34
|
+
assert s1["valueDomain"]["decisionVerbs"] == ["approve", "reject"]
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def test_identity_rule_matches_seam_fixture():
|
|
38
|
+
s9 = load_seam_fixture("s9-token-claims.json")
|
|
39
|
+
# SDK 不做自有认证——与 TS 侧同一纪律(S-9)
|
|
40
|
+
assert "never issues, stores, or verifies credentials" in s9["rule"]
|