Spaces:
Running
Running
Add honest source attestation contract
#4
by betterwithage - opened
- README.md +1 -0
- killinchu_public_contracts.py +95 -2
- tests/test_public_contracts.py +43 -0
README.md
CHANGED
|
@@ -472,6 +472,7 @@ One sovereign substrate, many organs — every decision carries a signed, checka
|
|
| 472 |
- `GET /health` - typed read-only health contract; reachability is not readiness.
|
| 473 |
- `GET /api/killinchu/v1/status` - runtime, doctrine, and contract discovery.
|
| 474 |
- `GET /api/killinchu/v1/melt/summary` - measured in-process MELT summary with explicit external-trace limits.
|
|
|
|
| 475 |
- `GET /openapi.json`, `/api/killinchu/openapi.json`, or `/api/killinchu/v1/openapi.json` - the same generated API description, with bad legacy annotations omitted rather than crashing discovery.
|
| 476 |
|
| 477 |
The MELT contract exposes aggregate metric family and sample counts, not private
|
|
|
|
| 472 |
- `GET /health` - typed read-only health contract; reachability is not readiness.
|
| 473 |
- `GET /api/killinchu/v1/status` - runtime, doctrine, and contract discovery.
|
| 474 |
- `GET /api/killinchu/v1/melt/summary` - measured in-process MELT summary with explicit external-trace limits.
|
| 475 |
+
- `GET /.well-known/szl-source.json` - honest source attestation that keeps the observed GitHub revision, Hugging Face overlay base, and running Space revision distinct. It currently reports `PENDING_GITHUB_SYNC` and does not claim repository parity.
|
| 476 |
- `GET /openapi.json`, `/api/killinchu/openapi.json`, or `/api/killinchu/v1/openapi.json` - the same generated API description, with bad legacy annotations omitted rather than crashing discovery.
|
| 477 |
|
| 478 |
The MELT contract exposes aggregate metric family and sample counts, not private
|
killinchu_public_contracts.py
CHANGED
|
@@ -11,6 +11,13 @@ from datetime import datetime, timezone
|
|
| 11 |
from typing import Any
|
| 12 |
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
def _now() -> str:
|
| 15 |
return datetime.now(timezone.utc).isoformat()
|
| 16 |
|
|
@@ -23,6 +30,73 @@ def _has_route(app: Any, path: str, method: str = "GET") -> bool:
|
|
| 23 |
return False
|
| 24 |
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
def _metrics_snapshot(app: Any) -> dict[str, Any]:
|
| 27 |
try:
|
| 28 |
import szl_metrics_prom
|
|
@@ -116,7 +190,13 @@ def runtime_status(app: Any, ns: str = "killinchu") -> dict[str, Any]:
|
|
| 116 |
},
|
| 117 |
"runtime": {
|
| 118 |
"route_count": route_count,
|
| 119 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
"build_time": os.getenv("SZL_BUILD_TIME", "unknown"),
|
| 121 |
},
|
| 122 |
"contracts": {
|
|
@@ -125,6 +205,7 @@ def runtime_status(app: Any, ns: str = "killinchu") -> dict[str, Any]:
|
|
| 125 |
"melt": f"/api/{ns}/v1/melt/summary",
|
| 126 |
"metrics": "/metrics",
|
| 127 |
"readiness": f"/api/{ns}/readyz",
|
|
|
|
| 128 |
},
|
| 129 |
"limits": [
|
| 130 |
"Reachability and registered routes do not establish data freshness, model quality, or mission readiness.",
|
|
@@ -148,6 +229,12 @@ def register(app: Any, ns: str = "killinchu") -> dict[str, Any]:
|
|
| 148 |
async def _melt(_request):
|
| 149 |
return JSONResponse(melt_summary(app, ns), headers={"Cache-Control": "no-store"})
|
| 150 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
routes = [
|
| 152 |
Route("/health", _health, methods=["GET"], name="killinchu_public_health"),
|
| 153 |
Route(
|
|
@@ -162,6 +249,12 @@ def register(app: Any, ns: str = "killinchu") -> dict[str, Any]:
|
|
| 162 |
methods=["GET"],
|
| 163 |
name="killinchu_melt_summary",
|
| 164 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
]
|
| 166 |
existing = {getattr(route, "name", None) for route in app.router.routes}
|
| 167 |
new = [route for route in routes if route.name not in existing]
|
|
@@ -181,6 +274,6 @@ if __name__ == "__main__":
|
|
| 181 |
"/api/killinchu/v1/mesh/state", lambda: {}, methods=["GET"]
|
| 182 |
)
|
| 183 |
result = register(candidate)
|
| 184 |
-
assert len(result["routes"]) ==
|
| 185 |
assert runtime_status(candidate)["transport_state"] == "REACHABLE"
|
| 186 |
print("SELFTEST OK")
|
|
|
|
| 11 |
from typing import Any
|
| 12 |
|
| 13 |
|
| 14 |
+
GITHUB_REPOSITORY = "https://github.com/szl-holdings/killinchu"
|
| 15 |
+
GITHUB_OBSERVED_REVISION = "dbb7ef1b20b941b299235d13dbd8404eb96cc0a4"
|
| 16 |
+
HF_SPACE_REPOSITORY = "https://huggingface.co/spaces/SZLHOLDINGS/killinchu"
|
| 17 |
+
HF_OVERLAY_BASE_REVISION = "2dd8aaae39bf0ec22959b26cc3c24328f980447c"
|
| 18 |
+
REVISION_OBSERVED_AT = "2026-07-11T16:16:12.897595+00:00"
|
| 19 |
+
|
| 20 |
+
|
| 21 |
def _now() -> str:
|
| 22 |
return datetime.now(timezone.utc).isoformat()
|
| 23 |
|
|
|
|
| 30 |
return False
|
| 31 |
|
| 32 |
|
| 33 |
+
def _source_git_build_variable() -> dict[str, Any]:
|
| 34 |
+
value = os.getenv("SZL_GIT_SHA", "unknown")
|
| 35 |
+
return {
|
| 36 |
+
"name": "SZL_GIT_SHA",
|
| 37 |
+
"value": value,
|
| 38 |
+
"state": "PRESENT_UNVERIFIED" if value != "unknown" else "UNAVAILABLE",
|
| 39 |
+
"meaning": "operator-supplied source revision build metadata",
|
| 40 |
+
"verification_state": "UNVERIFIED",
|
| 41 |
+
"is_huggingface_deployment_revision": False,
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def source_attestation() -> dict[str, Any]:
|
| 46 |
+
"""Describe source/deployment revision evidence without claiming parity."""
|
| 47 |
+
return {
|
| 48 |
+
"schema": "szl.source-attestation/v1",
|
| 49 |
+
"observed_at": _now(),
|
| 50 |
+
"service": "killinchu",
|
| 51 |
+
"attestation_state": "PENDING_GITHUB_SYNC",
|
| 52 |
+
"alignment_state": "NOT_VERIFIED",
|
| 53 |
+
"github_source_observation": {
|
| 54 |
+
"repository": GITHUB_REPOSITORY,
|
| 55 |
+
"branch": "main",
|
| 56 |
+
"revision": GITHUB_OBSERVED_REVISION,
|
| 57 |
+
"observed_at": REVISION_OBSERVED_AT,
|
| 58 |
+
"evidence": (
|
| 59 |
+
"https://api.github.com/repos/szl-holdings/killinchu/commits/"
|
| 60 |
+
+ GITHUB_OBSERVED_REVISION
|
| 61 |
+
),
|
| 62 |
+
"live_branch_head_resolver": (
|
| 63 |
+
"https://api.github.com/repos/szl-holdings/killinchu/commits/main"
|
| 64 |
+
),
|
| 65 |
+
"semantics": "GitHub main revision observed when this overlay was prepared",
|
| 66 |
+
},
|
| 67 |
+
"huggingface_overlay": {
|
| 68 |
+
"repository": HF_SPACE_REPOSITORY,
|
| 69 |
+
"base_revision": HF_OVERLAY_BASE_REVISION,
|
| 70 |
+
"base_revision_semantics": (
|
| 71 |
+
"Hugging Face Space revision on which this source-attestation overlay was based"
|
| 72 |
+
),
|
| 73 |
+
"repository_head_state": "RESOLVE_EXTERNALLY",
|
| 74 |
+
"repository_head_resolver": (
|
| 75 |
+
"https://huggingface.co/api/spaces/SZLHOLDINGS/killinchu"
|
| 76 |
+
),
|
| 77 |
+
"repository_head_json_field": "sha",
|
| 78 |
+
"running_process_revision_state": "NOT_EXPOSED_IN_PROCESS",
|
| 79 |
+
},
|
| 80 |
+
"build_metadata": {
|
| 81 |
+
"source_git_revision_variable": _source_git_build_variable(),
|
| 82 |
+
},
|
| 83 |
+
"relationship": {
|
| 84 |
+
"state": "PENDING_GITHUB_SYNC",
|
| 85 |
+
"basis": (
|
| 86 |
+
"The Hugging Face Space includes overlay commits not yet represented by a "
|
| 87 |
+
"verified GitHub commit. Repository equality is not claimed."
|
| 88 |
+
),
|
| 89 |
+
},
|
| 90 |
+
"limits": [
|
| 91 |
+
"The observed GitHub revision is point-in-time evidence, not a live branch-head claim.",
|
| 92 |
+
"The overlay base revision is not the currently running Hugging Face revision.",
|
| 93 |
+
"The Hub repository head may lead or lag the process during a rolling deployment, so it is not labeled as the running process revision.",
|
| 94 |
+
"SZL_GIT_SHA is source build metadata and must not be interpreted as a Hugging Face deployment revision.",
|
| 95 |
+
"This document is unsigned and does not establish SLSA provenance or binary reproducibility.",
|
| 96 |
+
],
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
|
| 100 |
def _metrics_snapshot(app: Any) -> dict[str, Any]:
|
| 101 |
try:
|
| 102 |
import szl_metrics_prom
|
|
|
|
| 190 |
},
|
| 191 |
"runtime": {
|
| 192 |
"route_count": route_count,
|
| 193 |
+
"source_git_revision_variable": _source_git_build_variable(),
|
| 194 |
+
"huggingface_revision_evidence": {
|
| 195 |
+
"running_process_revision_state": "NOT_EXPOSED_IN_PROCESS",
|
| 196 |
+
"repository_head_state": "RESOLVE_EXTERNALLY",
|
| 197 |
+
"repository_head_resolver": "https://huggingface.co/api/spaces/SZLHOLDINGS/killinchu",
|
| 198 |
+
"repository_head_json_field": "sha",
|
| 199 |
+
},
|
| 200 |
"build_time": os.getenv("SZL_BUILD_TIME", "unknown"),
|
| 201 |
},
|
| 202 |
"contracts": {
|
|
|
|
| 205 |
"melt": f"/api/{ns}/v1/melt/summary",
|
| 206 |
"metrics": "/metrics",
|
| 207 |
"readiness": f"/api/{ns}/readyz",
|
| 208 |
+
"source_attestation": "/.well-known/szl-source.json",
|
| 209 |
},
|
| 210 |
"limits": [
|
| 211 |
"Reachability and registered routes do not establish data freshness, model quality, or mission readiness.",
|
|
|
|
| 229 |
async def _melt(_request):
|
| 230 |
return JSONResponse(melt_summary(app, ns), headers={"Cache-Control": "no-store"})
|
| 231 |
|
| 232 |
+
async def _source_attestation(_request):
|
| 233 |
+
return JSONResponse(
|
| 234 |
+
source_attestation(),
|
| 235 |
+
headers={"Cache-Control": "no-store", "X-Content-Type-Options": "nosniff"},
|
| 236 |
+
)
|
| 237 |
+
|
| 238 |
routes = [
|
| 239 |
Route("/health", _health, methods=["GET"], name="killinchu_public_health"),
|
| 240 |
Route(
|
|
|
|
| 249 |
methods=["GET"],
|
| 250 |
name="killinchu_melt_summary",
|
| 251 |
),
|
| 252 |
+
Route(
|
| 253 |
+
"/.well-known/szl-source.json",
|
| 254 |
+
_source_attestation,
|
| 255 |
+
methods=["GET"],
|
| 256 |
+
name="killinchu_source_attestation",
|
| 257 |
+
),
|
| 258 |
]
|
| 259 |
existing = {getattr(route, "name", None) for route in app.router.routes}
|
| 260 |
new = [route for route in routes if route.name not in existing]
|
|
|
|
| 274 |
"/api/killinchu/v1/mesh/state", lambda: {}, methods=["GET"]
|
| 275 |
)
|
| 276 |
result = register(candidate)
|
| 277 |
+
assert len(result["routes"]) == 4
|
| 278 |
assert runtime_status(candidate)["transport_state"] == "REACHABLE"
|
| 279 |
print("SELFTEST OK")
|
tests/test_public_contracts.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import unittest
|
|
|
|
| 2 |
|
| 3 |
from fastapi import FastAPI
|
| 4 |
from fastapi.testclient import TestClient
|
|
@@ -27,6 +28,17 @@ class PublicContractTests(unittest.TestCase):
|
|
| 27 |
self.assertEqual(health.status_code, 200)
|
| 28 |
self.assertEqual(health.json()["transport_state"], "REACHABLE")
|
| 29 |
self.assertEqual(health.json()["authority_state"], "READ_ONLY")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
status = client.get("/api/killinchu/v1/status")
|
| 32 |
self.assertEqual(status.status_code, 200)
|
|
@@ -39,6 +51,37 @@ class PublicContractTests(unittest.TestCase):
|
|
| 39 |
self.assertTrue(melt.json()["contracts"]["mesh_state_route_registered"])
|
| 40 |
self.assertEqual(melt.json()["signals"]["traces"]["state"], "EXPORT_UNAVAILABLE")
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
def test_all_openapi_discovery_paths_avoid_legacy_500(self):
|
| 43 |
client = TestClient(self.build_app())
|
| 44 |
for path in (
|
|
|
|
| 1 |
import unittest
|
| 2 |
+
from unittest.mock import patch
|
| 3 |
|
| 4 |
from fastapi import FastAPI
|
| 5 |
from fastapi.testclient import TestClient
|
|
|
|
| 28 |
self.assertEqual(health.status_code, 200)
|
| 29 |
self.assertEqual(health.json()["transport_state"], "REACHABLE")
|
| 30 |
self.assertEqual(health.json()["authority_state"], "READ_ONLY")
|
| 31 |
+
runtime = health.json()["runtime"]
|
| 32 |
+
self.assertNotIn("git_sha", runtime)
|
| 33 |
+
self.assertEqual(
|
| 34 |
+
runtime["source_git_revision_variable"]["meaning"],
|
| 35 |
+
"operator-supplied source revision build metadata",
|
| 36 |
+
)
|
| 37 |
+
self.assertFalse(
|
| 38 |
+
runtime["source_git_revision_variable"][
|
| 39 |
+
"is_huggingface_deployment_revision"
|
| 40 |
+
]
|
| 41 |
+
)
|
| 42 |
|
| 43 |
status = client.get("/api/killinchu/v1/status")
|
| 44 |
self.assertEqual(status.status_code, 200)
|
|
|
|
| 51 |
self.assertTrue(melt.json()["contracts"]["mesh_state_route_registered"])
|
| 52 |
self.assertEqual(melt.json()["signals"]["traces"]["state"], "EXPORT_UNAVAILABLE")
|
| 53 |
|
| 54 |
+
def test_source_attestation_keeps_source_and_deployment_distinct(self):
|
| 55 |
+
client = TestClient(self.build_app())
|
| 56 |
+
with patch.dict("os.environ", {"SZL_GIT_SHA": "source-build-sha"}):
|
| 57 |
+
response = client.get("/.well-known/szl-source.json")
|
| 58 |
+
self.assertEqual(response.status_code, 200)
|
| 59 |
+
self.assertEqual(response.headers["cache-control"], "no-store")
|
| 60 |
+
payload = response.json()
|
| 61 |
+
self.assertEqual(payload["schema"], "szl.source-attestation/v1")
|
| 62 |
+
self.assertEqual(payload["attestation_state"], "PENDING_GITHUB_SYNC")
|
| 63 |
+
self.assertEqual(payload["alignment_state"], "NOT_VERIFIED")
|
| 64 |
+
self.assertEqual(
|
| 65 |
+
payload["github_source_observation"]["revision"],
|
| 66 |
+
killinchu_public_contracts.GITHUB_OBSERVED_REVISION,
|
| 67 |
+
)
|
| 68 |
+
self.assertEqual(
|
| 69 |
+
payload["huggingface_overlay"]["base_revision"],
|
| 70 |
+
killinchu_public_contracts.HF_OVERLAY_BASE_REVISION,
|
| 71 |
+
)
|
| 72 |
+
self.assertEqual(
|
| 73 |
+
payload["huggingface_overlay"]["repository_head_state"],
|
| 74 |
+
"RESOLVE_EXTERNALLY",
|
| 75 |
+
)
|
| 76 |
+
self.assertEqual(
|
| 77 |
+
payload["huggingface_overlay"]["running_process_revision_state"],
|
| 78 |
+
"NOT_EXPOSED_IN_PROCESS",
|
| 79 |
+
)
|
| 80 |
+
build_variable = payload["build_metadata"]["source_git_revision_variable"]
|
| 81 |
+
self.assertEqual(build_variable["value"], "source-build-sha")
|
| 82 |
+
self.assertFalse(build_variable["is_huggingface_deployment_revision"])
|
| 83 |
+
self.assertEqual(payload["relationship"]["state"], "PENDING_GITHUB_SYNC")
|
| 84 |
+
|
| 85 |
def test_all_openapi_discovery_paths_avoid_legacy_500(self):
|
| 86 |
client = TestClient(self.build_app())
|
| 87 |
for path in (
|