Spaces:
Running
Running
fix: activate fail-safe public contracts
#10
by betterwithage - opened
- README.md +3 -1
- killinchu_public_contracts.py +43 -6
- serve.py +14 -0
- tests/test_public_contracts.py +19 -0
README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
---
|
| 2 |
title: "killinchu — Andean Drone Intelligence"
|
| 3 |
emoji: "🦅"
|
| 4 |
-
thumbnail: "https://
|
| 5 |
colorFrom: gray
|
| 6 |
colorTo: indigo
|
| 7 |
sdk: docker
|
|
@@ -50,6 +50,8 @@ ecosystem-stage: "operational"
|
|
| 50 |
- **Primary face — the full application:** https://szlholdings-killinchu.hf.space/elite
|
| 51 |
- Space URL: https://szlholdings-killinchu.hf.space
|
| 52 |
- Health: `curl -s https://szlholdings-killinchu.hf.space/api/killinchu/v1/honest | jq .kernel_commit` → `"c7c0ba17"`
|
|
|
|
|
|
|
| 53 |
- Docs: https://szl-holdings.github.io/docs-site/flagships/killinchu
|
| 54 |
- Release: [v1.0.0](https://github.com/szl-holdings/killinchu/releases/tag/v1.0.0)
|
| 55 |
|
|
|
|
| 1 |
---
|
| 2 |
title: "killinchu — Andean Drone Intelligence"
|
| 3 |
emoji: "🦅"
|
| 4 |
+
thumbnail: "https://huggingface.co/spaces/SZLHOLDINGS/killinchu/resolve/main/static/og-card.png"
|
| 5 |
colorFrom: gray
|
| 6 |
colorTo: indigo
|
| 7 |
sdk: docker
|
|
|
|
| 50 |
- **Primary face — the full application:** https://szlholdings-killinchu.hf.space/elite
|
| 51 |
- Space URL: https://szlholdings-killinchu.hf.space
|
| 52 |
- Health: `curl -s https://szlholdings-killinchu.hf.space/api/killinchu/v1/honest | jq .kernel_commit` → `"c7c0ba17"`
|
| 53 |
+
- Source/deployment attestation: https://szlholdings-killinchu.hf.space/.well-known/szl-source.json
|
| 54 |
+
- OpenAPI: https://szlholdings-killinchu.hf.space/openapi.json
|
| 55 |
- Docs: https://szl-holdings.github.io/docs-site/flagships/killinchu
|
| 56 |
- Release: [v1.0.0](https://github.com/szl-holdings/killinchu/releases/tag/v1.0.0)
|
| 57 |
|
killinchu_public_contracts.py
CHANGED
|
@@ -6,6 +6,7 @@ or authority to actuate a defense system.
|
|
| 6 |
"""
|
| 7 |
from __future__ import annotations
|
| 8 |
|
|
|
|
| 9 |
import json
|
| 10 |
import os
|
| 11 |
import threading
|
|
@@ -17,11 +18,11 @@ from typing import Any
|
|
| 17 |
|
| 18 |
GITHUB_REPOSITORY = "https://github.com/szl-holdings/killinchu"
|
| 19 |
GITHUB_REPOSITORY_ID = "szl-holdings/killinchu"
|
| 20 |
-
GITHUB_OBSERVED_REVISION = "
|
| 21 |
HF_SPACE_REPOSITORY = "https://huggingface.co/spaces/SZLHOLDINGS/killinchu"
|
| 22 |
HF_SPACE_ID = "SZLHOLDINGS/killinchu"
|
| 23 |
-
HF_OVERLAY_BASE_REVISION = "
|
| 24 |
-
REVISION_OBSERVED_AT = "2026-07-
|
| 25 |
_HF_HEAD_CACHE: dict[str, Any] = {"at": 0.0, "value": None}
|
| 26 |
_HF_HEAD_LOCK = threading.Lock()
|
| 27 |
|
|
@@ -141,7 +142,19 @@ def source_attestation(force: bool = False) -> dict[str, Any]:
|
|
| 141 |
"repository": HF_SPACE_REPOSITORY,
|
| 142 |
"base_revision": HF_OVERLAY_BASE_REVISION,
|
| 143 |
"base_revision_semantics": (
|
| 144 |
-
"Hugging Face revision
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
),
|
| 146 |
},
|
| 147 |
"build_metadata": {
|
|
@@ -280,7 +293,7 @@ def runtime_status(app: Any, ns: str = "killinchu") -> dict[str, Any]:
|
|
| 280 |
|
| 281 |
|
| 282 |
def register(app: Any, ns: str = "killinchu") -> dict[str, Any]:
|
| 283 |
-
from starlette.responses import JSONResponse
|
| 284 |
from starlette.routing import Route
|
| 285 |
|
| 286 |
async def _health(_request):
|
|
@@ -314,7 +327,31 @@ def register(app: Any, ns: str = "killinchu") -> dict[str, Any]:
|
|
| 314 |
headers={"Cache-Control": "no-store", "X-Content-Type-Options": "nosniff"},
|
| 315 |
)
|
| 316 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 317 |
routes = [
|
|
|
|
|
|
|
| 318 |
Route("/health", _health, methods=["GET"], name="killinchu_public_health"),
|
| 319 |
Route(
|
| 320 |
f"/api/{ns}/v1/status",
|
|
@@ -353,6 +390,6 @@ if __name__ == "__main__":
|
|
| 353 |
"/api/killinchu/v1/mesh/state", lambda: {}, methods=["GET"]
|
| 354 |
)
|
| 355 |
result = register(candidate)
|
| 356 |
-
assert len(result["routes"]) ==
|
| 357 |
assert runtime_status(candidate)["transport_state"] == "REACHABLE"
|
| 358 |
print("SELFTEST OK")
|
|
|
|
| 6 |
"""
|
| 7 |
from __future__ import annotations
|
| 8 |
|
| 9 |
+
import inspect
|
| 10 |
import json
|
| 11 |
import os
|
| 12 |
import threading
|
|
|
|
| 18 |
|
| 19 |
GITHUB_REPOSITORY = "https://github.com/szl-holdings/killinchu"
|
| 20 |
GITHUB_REPOSITORY_ID = "szl-holdings/killinchu"
|
| 21 |
+
GITHUB_OBSERVED_REVISION = "c2695a83e35ceecb6d2ffef8deaec69a9a1f5ed4"
|
| 22 |
HF_SPACE_REPOSITORY = "https://huggingface.co/spaces/SZLHOLDINGS/killinchu"
|
| 23 |
HF_SPACE_ID = "SZLHOLDINGS/killinchu"
|
| 24 |
+
HF_OVERLAY_BASE_REVISION = "a46d703a53f2efccd14da96226f46897ffcc65d0"
|
| 25 |
+
REVISION_OBSERVED_AT = "2026-07-15T11:52:16.196467+00:00"
|
| 26 |
_HF_HEAD_CACHE: dict[str, Any] = {"at": 0.0, "value": None}
|
| 27 |
_HF_HEAD_LOCK = threading.Lock()
|
| 28 |
|
|
|
|
| 142 |
"repository": HF_SPACE_REPOSITORY,
|
| 143 |
"base_revision": HF_OVERLAY_BASE_REVISION,
|
| 144 |
"base_revision_semantics": (
|
| 145 |
+
"Exact Hugging Face parent revision of this corrective overlay"
|
| 146 |
+
),
|
| 147 |
+
"state": "HF_ONLY_CORRECTIVE_OVERLAY",
|
| 148 |
+
"documented_paths": [
|
| 149 |
+
{"path": "Dockerfile", "purpose": "copy the read-only public-contract module into the image"},
|
| 150 |
+
{"path": "serve.py", "purpose": "register read-only source, status, MELT, and OpenAPI contracts"},
|
| 151 |
+
{"path": "killinchu_public_contracts.py", "purpose": "emit fail-closed source/deployment evidence"},
|
| 152 |
+
{"path": "tests/test_public_contracts.py", "purpose": "regress contract behavior and runtime packaging"},
|
| 153 |
+
{"path": "README.md", "purpose": "publish stable discovery and thumbnail URLs"},
|
| 154 |
+
],
|
| 155 |
+
"scope_limit": (
|
| 156 |
+
"This list documents the corrective contract overlay only; it is not "
|
| 157 |
+
"a complete GitHub/Hugging Face byte-parity assertion."
|
| 158 |
),
|
| 159 |
},
|
| 160 |
"build_metadata": {
|
|
|
|
| 293 |
|
| 294 |
|
| 295 |
def register(app: Any, ns: str = "killinchu") -> dict[str, Any]:
|
| 296 |
+
from starlette.responses import JSONResponse, Response
|
| 297 |
from starlette.routing import Route
|
| 298 |
|
| 299 |
async def _health(_request):
|
|
|
|
| 327 |
headers={"Cache-Control": "no-store", "X-Content-Type-Options": "nosniff"},
|
| 328 |
)
|
| 329 |
|
| 330 |
+
async def _openapi_alias(_request):
|
| 331 |
+
"""Delegate discovery aliases to the existing fail-safe organ schema."""
|
| 332 |
+
organ_path = f"/api/{ns}/openapi.json"
|
| 333 |
+
for route in app.router.routes:
|
| 334 |
+
if getattr(route, "path", None) != organ_path:
|
| 335 |
+
continue
|
| 336 |
+
endpoint = getattr(route, "endpoint", None)
|
| 337 |
+
if not callable(endpoint):
|
| 338 |
+
continue
|
| 339 |
+
try:
|
| 340 |
+
payload = endpoint()
|
| 341 |
+
if inspect.isawaitable(payload):
|
| 342 |
+
payload = await payload
|
| 343 |
+
if isinstance(payload, Response):
|
| 344 |
+
payload.headers.setdefault("Cache-Control", "no-store")
|
| 345 |
+
payload.headers.setdefault("X-Content-Type-Options", "nosniff")
|
| 346 |
+
return payload
|
| 347 |
+
return JSONResponse(payload, headers={"Cache-Control": "no-store", "X-Content-Type-Options": "nosniff"})
|
| 348 |
+
except Exception as exc:
|
| 349 |
+
return JSONResponse({"schema": "szl.openapi-unavailable/v1", "state": "UNAVAILABLE", "error_type": type(exc).__name__}, status_code=503, headers={"Cache-Control": "no-store"})
|
| 350 |
+
return JSONResponse({"schema": "szl.openapi-unavailable/v1", "state": "UNAVAILABLE", "detail": f"{organ_path} is not registered"}, status_code=503, headers={"Cache-Control": "no-store"})
|
| 351 |
+
|
| 352 |
routes = [
|
| 353 |
+
Route("/openapi.json", _openapi_alias, methods=["GET"], name="killinchu_public_openapi"),
|
| 354 |
+
Route(f"/api/{ns}/v1/openapi.json", _openapi_alias, methods=["GET"], name="killinchu_v1_openapi"),
|
| 355 |
Route("/health", _health, methods=["GET"], name="killinchu_public_health"),
|
| 356 |
Route(
|
| 357 |
f"/api/{ns}/v1/status",
|
|
|
|
| 390 |
"/api/killinchu/v1/mesh/state", lambda: {}, methods=["GET"]
|
| 391 |
)
|
| 392 |
result = register(candidate)
|
| 393 |
+
assert len(result["routes"]) == 6
|
| 394 |
assert runtime_status(candidate)["transport_state"] == "REACHABLE"
|
| 395 |
print("SELFTEST OK")
|
serve.py
CHANGED
|
@@ -5537,6 +5537,20 @@ except Exception as _kc_wave_e: # pragma: no cover — never break SPA/other or
|
|
| 5537 |
# ============================================================================
|
| 5538 |
|
| 5539 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5540 |
if __name__ == "__main__":
|
| 5541 |
import uvicorn
|
| 5542 |
port = int(os.environ.get("PORT", "7860"))
|
|
|
|
| 5537 |
# ============================================================================
|
| 5538 |
|
| 5539 |
|
| 5540 |
+
|
| 5541 |
+
# ============================================================================
|
| 5542 |
+
# READ-ONLY PUBLIC CONTRACTS -- source/deployment attestation, runtime status,
|
| 5543 |
+
# MELT summary, and fail-safe OpenAPI discovery. Registered last and inserted at
|
| 5544 |
+
# the front so explicit machine-readable routes beat the SPA history fallback.
|
| 5545 |
+
# No targeting, collection, decision, or effector behavior is changed here.
|
| 5546 |
+
# ============================================================================
|
| 5547 |
+
try:
|
| 5548 |
+
import killinchu_public_contracts as _kc_public_contracts
|
| 5549 |
+
_kc_public_contract_status = _kc_public_contracts.register(app, ns="killinchu")
|
| 5550 |
+
print(f"[killinchu] public contracts registered: {_kc_public_contract_status}", file=sys.stderr)
|
| 5551 |
+
except Exception as _kc_public_contract_error: # pragma: no cover
|
| 5552 |
+
print(f"[killinchu] public contracts NOT registered: {_kc_public_contract_error!r}", file=sys.stderr)
|
| 5553 |
+
|
| 5554 |
if __name__ == "__main__":
|
| 5555 |
import uvicorn
|
| 5556 |
port = int(os.environ.get("PORT", "7860"))
|
tests/test_public_contracts.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import unittest
|
|
|
|
| 2 |
from unittest.mock import patch
|
| 3 |
|
| 4 |
from fastapi import FastAPI
|
|
@@ -90,6 +91,14 @@ class PublicContractTests(unittest.TestCase):
|
|
| 90 |
build_variable = extension["build_metadata"]["source_git_revision_variable"]
|
| 91 |
self.assertEqual(build_variable["value"], "source-build-sha")
|
| 92 |
self.assertFalse(build_variable["is_huggingface_deployment_revision"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
# Mirrors the identity checks in check_ecosystem_drift.compare.
|
| 95 |
identity_errors = []
|
|
@@ -125,5 +134,15 @@ class PublicContractTests(unittest.TestCase):
|
|
| 125 |
self.assertEqual(response.json()["openapi"], "3.1.0")
|
| 126 |
|
| 127 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
if __name__ == "__main__":
|
| 129 |
unittest.main()
|
|
|
|
| 1 |
import unittest
|
| 2 |
+
from pathlib import Path
|
| 3 |
from unittest.mock import patch
|
| 4 |
|
| 5 |
from fastapi import FastAPI
|
|
|
|
| 91 |
build_variable = extension["build_metadata"]["source_git_revision_variable"]
|
| 92 |
self.assertEqual(build_variable["value"], "source-build-sha")
|
| 93 |
self.assertFalse(build_variable["is_huggingface_deployment_revision"])
|
| 94 |
+
overlay = extension["overlay"]
|
| 95 |
+
self.assertEqual(overlay["state"], "HF_ONLY_CORRECTIVE_OVERLAY")
|
| 96 |
+
self.assertEqual(overlay["base_revision"], killinchu_public_contracts.HF_OVERLAY_BASE_REVISION)
|
| 97 |
+
self.assertEqual(
|
| 98 |
+
[item["path"] for item in overlay["documented_paths"]],
|
| 99 |
+
["Dockerfile", "serve.py", "killinchu_public_contracts.py", "tests/test_public_contracts.py", "README.md"],
|
| 100 |
+
)
|
| 101 |
+
self.assertIn("not a complete", overlay["scope_limit"])
|
| 102 |
|
| 103 |
# Mirrors the identity checks in check_ecosystem_drift.compare.
|
| 104 |
identity_errors = []
|
|
|
|
| 134 |
self.assertEqual(response.json()["openapi"], "3.1.0")
|
| 135 |
|
| 136 |
|
| 137 |
+
def test_runtime_wires_contracts_before_entrypoint(self):
|
| 138 |
+
root = Path(__file__).resolve().parents[1]
|
| 139 |
+
serve = (root / "serve.py").read_text(encoding="utf-8")
|
| 140 |
+
dockerfile = (root / "Dockerfile").read_text(encoding="utf-8")
|
| 141 |
+
registration = serve.index("_kc_public_contracts.register(app, ns=\"killinchu\")")
|
| 142 |
+
entrypoint = serve.index('if __name__ == "__main__":')
|
| 143 |
+
self.assertLess(registration, entrypoint)
|
| 144 |
+
self.assertIn("COPY killinchu_public_contracts.py ./", dockerfile)
|
| 145 |
+
|
| 146 |
+
|
| 147 |
if __name__ == "__main__":
|
| 148 |
unittest.main()
|