Spaces:
Running
Running
deploy(hf): sync szl-holdings/killinchu@main derived COPY set
Browse filesReusable Dockerfile-COPY-derived deploy from szl-holdings/killinchu main.
Files: 886 Pruned: 0
Derived from Dockerfile COPY sources (NO hand-maintained allowlist).
Signed-off-by: SZL Holdings <noreply@szlholdings.ai>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- .well-known/szl-source.json +61 -0
- README.md +3 -0
- killinchu_elite_console.py +13 -14
- killinchu_nav_wireup.py +22 -14
- killinchu_public_route_repair.py +177 -0
- serve.py +39 -12
- szl_spaces_proxy.py +262 -383
- szl_spaces_surface.py +237 -85
.well-known/szl-source.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"schema": "szl.deployment-source/v2",
|
| 3 |
+
"source": {
|
| 4 |
+
"repository": "szl-holdings/killinchu",
|
| 5 |
+
"commit": "9958c34a2066ba05e9679ce96ae4841fd67b1db6",
|
| 6 |
+
"path": "",
|
| 7 |
+
"relation": "current-github-main-reference",
|
| 8 |
+
"commit_state": "MEASURED_GITHUB_MAIN_REFERENCE_AT_AUDIT",
|
| 9 |
+
"sync_state": "PENDING_GITHUB_SYNC",
|
| 10 |
+
"build_source_state": "NOT_PROVEN"
|
| 11 |
+
},
|
| 12 |
+
"deployment": {
|
| 13 |
+
"hf_space": "SZLHOLDINGS/killinchu",
|
| 14 |
+
"audited_live_hf_revision": "bba71e38fc3955fb1809a76965911675a94041b2",
|
| 15 |
+
"audited_live_hf_revision_state": "MEASURED_LIVE_REFERENCE_AT_OBSERVATION",
|
| 16 |
+
"audited_live_stage": "RUNNING",
|
| 17 |
+
"audited_live_hardware": "cpu-basic",
|
| 18 |
+
"audited_live_last_modified": "2026-07-16T18:09:53.000Z",
|
| 19 |
+
"current_hf_revision": null,
|
| 20 |
+
"current_hf_revision_state": "NOT_CLAIMED",
|
| 21 |
+
"running_process_revision": "NOT_CLAIMED",
|
| 22 |
+
"deployed_equivalence_state": "NOT_CLAIMED"
|
| 23 |
+
},
|
| 24 |
+
"artifact_basis": {
|
| 25 |
+
"github_reference_commit": "9958c34a2066ba05e9679ce96ae4841fd67b1db6",
|
| 26 |
+
"hf_observed_revision": "bba71e38fc3955fb1809a76965911675a94041b2",
|
| 27 |
+
"semantics": "Two independently recorded references at audit time; their content parity and build relationship are not claimed."
|
| 28 |
+
},
|
| 29 |
+
"observed_at": "2026-07-16T18:09:53.000Z",
|
| 30 |
+
"transport_state": "REFERENCE_RECORDED",
|
| 31 |
+
"evidence_state": "SNAPSHOT",
|
| 32 |
+
"verification_state": "STRUCTURAL_ONLY",
|
| 33 |
+
"authority_state": "READ_ONLY",
|
| 34 |
+
"alignment_state": "PENDING_GITHUB_SYNC",
|
| 35 |
+
"attestation_state": "UNSIGNED_STRUCTURAL",
|
| 36 |
+
"claims": {
|
| 37 |
+
"github_parity": "NOT_CLAIMED",
|
| 38 |
+
"hugging_face_parity": "NOT_CLAIMED",
|
| 39 |
+
"deployed_equivalence": "NOT_CLAIMED",
|
| 40 |
+
"reproducible_build": "NOT_CLAIMED",
|
| 41 |
+
"build_provenance": "NOT_CLAIMED",
|
| 42 |
+
"current_hf_head": "NOT_CLAIMED"
|
| 43 |
+
},
|
| 44 |
+
"extensions": {
|
| 45 |
+
"schema": "szl.static-deployment-source-evidence/v1",
|
| 46 |
+
"overlay": {
|
| 47 |
+
"source_reference_commit": "9958c34a2066ba05e9679ce96ae4841fd67b1db6",
|
| 48 |
+
"artifact_path": ".well-known/szl-source.json",
|
| 49 |
+
"worktree_scope_state": "NOT_ATTESTED",
|
| 50 |
+
"sync_state": "PENDING_GITHUB_SYNC"
|
| 51 |
+
}
|
| 52 |
+
},
|
| 53 |
+
"limits": [
|
| 54 |
+
"This file is an unsigned structural snapshot and grants no mutation authority.",
|
| 55 |
+
"The GitHub commit is the current origin/main reference observed during this audit, not a commit containing this pending worktree overlay.",
|
| 56 |
+
"This snapshot does not prove that the pending overlay has been applied atop the referenced GitHub commit.",
|
| 57 |
+
"The Hugging Face revision is an observed live reference at 2026-07-16T18:09:53.000Z, not a claim about the current head.",
|
| 58 |
+
"No byte parity, build provenance, reproducible build, or deployed equivalence is claimed.",
|
| 59 |
+
"PENDING_GITHUB_SYNC must remain until an independently observable published commit contains this artifact."
|
| 60 |
+
]
|
| 61 |
+
}
|
README.md
CHANGED
|
@@ -62,7 +62,10 @@ ecosystem-stage: "operational"
|
|
| 62 |
- Space URL: https://szlholdings-killinchu.hf.space
|
| 63 |
- Health: `curl -s https://szlholdings-killinchu.hf.space/api/killinchu/v1/honest | jq .kernel_commit` → `"c7c0ba17"`
|
| 64 |
- Source/deployment attestation: https://szlholdings-killinchu.hf.space/.well-known/szl-source.json
|
|
|
|
| 65 |
- OpenAPI: https://szlholdings-killinchu.hf.space/openapi.json
|
|
|
|
|
|
|
| 66 |
- Docs: https://szl-holdings.github.io/docs-site/flagships/killinchu
|
| 67 |
- Release: [v1.0.0](https://github.com/szl-holdings/killinchu/releases/tag/v1.0.0)
|
| 68 |
|
|
|
|
| 62 |
- Space URL: https://szlholdings-killinchu.hf.space
|
| 63 |
- Health: `curl -s https://szlholdings-killinchu.hf.space/api/killinchu/v1/honest | jq .kernel_commit` → `"c7c0ba17"`
|
| 64 |
- Source/deployment attestation: https://szlholdings-killinchu.hf.space/.well-known/szl-source.json
|
| 65 |
+
(unsigned structural snapshot; its `PENDING_GITHUB_SYNC` / `NOT_CLAIMED` fields are authoritative)
|
| 66 |
- OpenAPI: https://szlholdings-killinchu.hf.space/openapi.json
|
| 67 |
+
- Spaces registry: https://szlholdings-killinchu.hf.space/spaces
|
| 68 |
+
(apps open on canonical isolated HF origins; legacy `/spaces/<slug>` links are no-store 307 handoffs)
|
| 69 |
- Docs: https://szl-holdings.github.io/docs-site/flagships/killinchu
|
| 70 |
- Release: [v1.0.0](https://github.com/szl-holdings/killinchu/releases/tag/v1.0.0)
|
| 71 |
|
killinchu_elite_console.py
CHANGED
|
@@ -2435,8 +2435,8 @@ window.autoPill=function(gateId){ return '<span class="badge b-live" style="font
|
|
| 2435 |
|
| 2436 |
/* ── Auto-crawl scheduler status (Task #742) — surfaces the live intel feed's
|
| 2437 |
self-refresh health from GET /api/killinchu/crawl/status. Honest by design:
|
| 2438 |
-
a run that did not get fresh data
|
| 2439 |
-
|
| 2440 |
function _csRel(iso, future){
|
| 2441 |
if(!iso) return '\u2014';
|
| 2442 |
try{
|
|
@@ -2457,35 +2457,34 @@ async function crawlStatusLoad(id){
|
|
| 2457 |
var enabled=(cfg.enabled!==false)&&wired;
|
| 2458 |
var health=String((j&&j.health)||(j&&j.status)||'unverified').toLowerCase();
|
| 2459 |
var halted=!!(j&&j.circuit_open)||health==='failed';
|
|
|
|
| 2460 |
var last=String(sch.last_status||'').toLowerCase();
|
| 2461 |
var outcome, oc;
|
| 2462 |
-
if(
|
| 2463 |
else if(!sch.last_run_at){ outcome='NO RUN YET'; oc='#c9a05f'; }
|
| 2464 |
else if(last==='live'){ outcome='OK'; oc='#5fb3a3'; }
|
| 2465 |
-
else
|
| 2466 |
-
|
| 2467 |
-
|
| 2468 |
-
var schTxt=halted?'CIRCUIT OPEN':(enabled?'ENABLED':(wired?'DISABLED':'NOT WIRED'));
|
| 2469 |
-
var schC=(halted||!enabled)?'#ff7b7b':'#5fb3a3';
|
| 2470 |
var cf=sch.consecutive_failures||0;
|
| 2471 |
-
var boTxt=halted?'fail-closed \u00b7 no retries':(cf>0?('backing off \u00b7 '+cf+' consecutive miss'+(cf===1?'':'es')):'nominal');
|
| 2472 |
-
var boC=
|
| 2473 |
var ivl=cfg.interval_seconds!=null?(cfg.interval_seconds+'s'):'\u2014';
|
| 2474 |
var freshness=String((j&&j.freshness)||'unverified').toUpperCase();
|
| 2475 |
-
var title='Intel feed \u00b7 '+(
|
| 2476 |
var cell=function(label,val,color){ return '<div class="kpi" style="padding:.5rem .7rem"><div class="k">'+esc(label)+'</div><div class="v" style="font-size:1rem;color:'+(color||'var(--cream)')+'">'+val+'</div></div>'; };
|
| 2477 |
var remediation=halted&&j.operator_action
|
| 2478 |
? '<div class="row mono" style="font-size:11px;color:#ff7b7b;margin-top:.5rem;word-break:break-word">operator action: '+esc(String(j.operator_action))+'</div>' : '';
|
| 2479 |
-
var note=((outcome==='DEGRADED'||outcome==='
|
| 2480 |
? '<div class="row mono" style="font-size:11px;color:#f5b301;margin-top:.5rem;word-break:break-word">last issue: '+esc(String(sch.last_error))+'</div>'
|
| 2481 |
-
: (
|
| 2482 |
box.innerHTML=
|
| 2483 |
'<div class="card-h"><span class="card-t">↻ '+esc(title)+'</span><span class="card-ep">GET /api/killinchu/crawl/status \u00b7 adsb.lol military ADS-B</span></div>'+
|
| 2484 |
'<div class="kpis" style="grid-template-columns:repeat(auto-fit,minmax(118px,1fr));gap:.5rem;margin:0">'+
|
| 2485 |
cell('Scheduler',schTxt,schC)+
|
| 2486 |
cell('Last run',_csRel(sch.last_run_at,false),'var(--cream)')+
|
| 2487 |
cell('Outcome',outcome,oc)+
|
| 2488 |
-
cell('Next run',(enabled&&!
|
| 2489 |
cell('Backoff',boTxt,boC)+
|
| 2490 |
cell('Interval',ivl,'var(--dim)')+
|
| 2491 |
'</div>'+note+remediation;
|
|
|
|
| 2435 |
|
| 2436 |
/* ── Auto-crawl scheduler status (Task #742) — surfaces the live intel feed's
|
| 2437 |
self-refresh health from GET /api/killinchu/crawl/status. Honest by design:
|
| 2438 |
+
a run that did not get fresh data is labelled DEGRADED; a disabled/not-wired
|
| 2439 |
+
scheduler or an open storage circuit is STOPPED — never shown healthy. ── */
|
| 2440 |
function _csRel(iso, future){
|
| 2441 |
if(!iso) return '\u2014';
|
| 2442 |
try{
|
|
|
|
| 2457 |
var enabled=(cfg.enabled!==false)&&wired;
|
| 2458 |
var health=String((j&&j.health)||(j&&j.status)||'unverified').toLowerCase();
|
| 2459 |
var halted=!!(j&&j.circuit_open)||health==='failed';
|
| 2460 |
+
var stopped=halted||!enabled||health==='disabled';
|
| 2461 |
var last=String(sch.last_status||'').toLowerCase();
|
| 2462 |
var outcome, oc;
|
| 2463 |
+
if(stopped){ outcome='STOPPED'; oc='#ff7b7b'; }
|
| 2464 |
else if(!sch.last_run_at){ outcome='NO RUN YET'; oc='#c9a05f'; }
|
| 2465 |
else if(last==='live'){ outcome='OK'; oc='#5fb3a3'; }
|
| 2466 |
+
else { outcome='DEGRADED'; oc='#f5b301'; } // cached / degraded / error / skipped — not fresh
|
| 2467 |
+
var schTxt=halted?'CIRCUIT OPEN':(enabled?'ENABLED':'STOPPED');
|
| 2468 |
+
var schC=stopped?'#ff7b7b':'#5fb3a3';
|
|
|
|
|
|
|
| 2469 |
var cf=sch.consecutive_failures||0;
|
| 2470 |
+
var boTxt=halted?'fail-closed \u00b7 no retries':(!enabled?'scheduler stopped':(cf>0?('backing off \u00b7 '+cf+' consecutive miss'+(cf===1?'':'es')):'nominal'));
|
| 2471 |
+
var boC=stopped?'#ff7b7b':(cf>0?'#f5b301':'var(--dim)');
|
| 2472 |
var ivl=cfg.interval_seconds!=null?(cfg.interval_seconds+'s'):'\u2014';
|
| 2473 |
var freshness=String((j&&j.freshness)||'unverified').toUpperCase();
|
| 2474 |
+
var title='Intel feed \u00b7 '+(stopped?'STOPPED':freshness);
|
| 2475 |
var cell=function(label,val,color){ return '<div class="kpi" style="padding:.5rem .7rem"><div class="k">'+esc(label)+'</div><div class="v" style="font-size:1rem;color:'+(color||'var(--cream)')+'">'+val+'</div></div>'; };
|
| 2476 |
var remediation=halted&&j.operator_action
|
| 2477 |
? '<div class="row mono" style="font-size:11px;color:#ff7b7b;margin-top:.5rem;word-break:break-word">operator action: '+esc(String(j.operator_action))+'</div>' : '';
|
| 2478 |
+
var note=((outcome==='DEGRADED'||outcome==='STOPPED')&&sch.last_error)
|
| 2479 |
? '<div class="row mono" style="font-size:11px;color:#f5b301;margin-top:.5rem;word-break:break-word">last issue: '+esc(String(sch.last_error))+'</div>'
|
| 2480 |
+
: (last==='skipped' ? '<div class="row mono dim" style="font-size:11px;margin-top:.5rem">a run was still in progress \u2014 this cycle was skipped to avoid pile-up</div>' : '');
|
| 2481 |
box.innerHTML=
|
| 2482 |
'<div class="card-h"><span class="card-t">↻ '+esc(title)+'</span><span class="card-ep">GET /api/killinchu/crawl/status \u00b7 adsb.lol military ADS-B</span></div>'+
|
| 2483 |
'<div class="kpis" style="grid-template-columns:repeat(auto-fit,minmax(118px,1fr));gap:.5rem;margin:0">'+
|
| 2484 |
cell('Scheduler',schTxt,schC)+
|
| 2485 |
cell('Last run',_csRel(sch.last_run_at,false),'var(--cream)')+
|
| 2486 |
cell('Outcome',outcome,oc)+
|
| 2487 |
+
cell('Next run',(enabled&&!stopped)?_csRel(sch.next_run_at,true):'\u2014','var(--cream)')+
|
| 2488 |
cell('Backoff',boTxt,boC)+
|
| 2489 |
cell('Interval',ivl,'var(--dim)')+
|
| 2490 |
'</div>'+note+remediation;
|
killinchu_nav_wireup.py
CHANGED
|
@@ -24,8 +24,8 @@
|
|
| 24 |
# markup; it removes nothing and never clobbers another lane's nav.
|
| 25 |
#
|
| 26 |
# DOCTRINE (v11): locked = 8 @ c7c0ba17; Λ = Conjecture 1 (NOT a theorem);
|
| 27 |
-
# 0 visible codenames (
|
| 28 |
-
#
|
| 29 |
# honest labels only; never weakens a gate; never commits a key; additive-only.
|
| 30 |
#
|
| 31 |
# Signed-off-by: Stephen P. Lutar Jr. <stephenlutar2@gmail.com>
|
|
@@ -72,6 +72,7 @@ _LEGACY_FOLD_REDIRECTS = {
|
|
| 72 |
|
| 73 |
# The a11oy-hosted Restraint surfaces (same estate, NOT a third-party CDN).
|
| 74 |
_A11OY_BASE = "https://szlholdings-a11oy.hf.space"
|
|
|
|
| 75 |
_RESTRAINT_URL = _A11OY_BASE + "/restraint"
|
| 76 |
_RESTRAINT_BENCH_URL = _A11OY_BASE + "/restraint-bench"
|
| 77 |
|
|
@@ -105,12 +106,12 @@ _FLAGSHIP_PATHS = {"/ecosystem", "/estate-organism", "/counter-uas"}
|
|
| 105 |
def _build_nav_item() -> bytes:
|
| 106 |
"""ONE Restraint nav-item, mirroring killinchu's own nav-item markup
|
| 107 |
(class="nav-item" + <span class="ico"> + label). Navigates cross-app to the
|
| 108 |
-
a11oy Restraint surface via
|
| 109 |
item = (
|
| 110 |
-
'<
|
| 111 |
-
'
|
| 112 |
'title="a11oy Restraint — governed code-minimization / dependency-frugality (aligns with, not certified)">'
|
| 113 |
-
'<span class="ico">\u27c2</span>Restraint (Governed Frugality)</
|
| 114 |
) % _RESTRAINT_URL
|
| 115 |
return item.encode("utf-8")
|
| 116 |
|
|
@@ -120,6 +121,8 @@ def _build_related_strip(current_path: str) -> bytes:
|
|
| 120 |
cluster from killinchu. Inline-styled (0 CDN). Honest labels."""
|
| 121 |
rel = [
|
| 122 |
("/ecosystem", "Estate Hub"),
|
|
|
|
|
|
|
| 123 |
(_A11OY_BASE + "/nemo", "SZL-Nemo"),
|
| 124 |
(_A11OY_BASE + "/autoreview", "Auto-Review"),
|
| 125 |
(_A11OY_BASE + "/factory", "Factory"),
|
|
@@ -134,15 +137,17 @@ def _build_related_strip(current_path: str) -> bytes:
|
|
| 134 |
if path == current_path:
|
| 135 |
continue
|
| 136 |
links.append(
|
| 137 |
-
'<a href="%s" style="color:#d4a444;text-decoration:none;'
|
| 138 |
-
'
|
|
|
|
| 139 |
)
|
| 140 |
strip = (
|
| 141 |
'<nav data-related-restraint="r5" aria-label="Related surfaces" '
|
| 142 |
-
'style="margin:1.25rem auto;max-width:1100px;padding:.6rem .9rem;'
|
|
|
|
| 143 |
'border-top:1px solid #1d2632;font:13px/1.6 system-ui,sans-serif;'
|
| 144 |
'color:#7c8794;text-align:center">'
|
| 145 |
-
'<span style="color:#7c8794;margin-right:.
|
| 146 |
+ "".join(links)
|
| 147 |
+ "</nav>"
|
| 148 |
)
|
|
@@ -410,7 +415,7 @@ if __name__ == "__main__":
|
|
| 410 |
assert "Operate</div>" in h1, "must NOT remove existing nav group"
|
| 411 |
assert "footer</div>" in h1, "must NOT remove footer"
|
| 412 |
# placed immediately before the footer
|
| 413 |
-
assert 'Restraint (Governed Frugality)</
|
| 414 |
assert h1 == h2, "second render must be byte-identical (idempotent)"
|
| 415 |
|
| 416 |
e1 = c.get("/ecosystem").text
|
|
@@ -418,19 +423,22 @@ if __name__ == "__main__":
|
|
| 418 |
assert e1.count('data-related-restraint="r5"') == 1, "cross-link strip must inject once"
|
| 419 |
assert e2.count('data-related-restraint="r5"') == 1, "cross-link strip must be idempotent"
|
| 420 |
assert _RESTRAINT_URL in e1 and "/autoreview" in e1, "strip must cross-link Restraint + flagships"
|
|
|
|
|
|
|
| 421 |
# /ecosystem is the current page -> omitted from its own strip
|
| 422 |
inner = e1.split('data-related-restraint="r5"')[1].split("</nav>")[0]
|
| 423 |
-
assert "/ecosystem" not in inner, "strip must omit the current page (/ecosystem)"
|
| 424 |
assert e1 == e2, "second ecosystem render must be byte-identical"
|
| 425 |
|
| 426 |
# Doctrine guard: 0 CDN (only the same-estate a11oy URL), 0 script, 0 codename.
|
| 427 |
injected = (_build_nav_item().decode() + _build_related_strip("/ecosystem").decode())
|
| 428 |
low = injected.lower()
|
| 429 |
assert "<script" not in low, "nav markup must inject no script"
|
| 430 |
-
# the ONLY absolute URLs allowed are same-estate a11oy
|
| 431 |
import re
|
| 432 |
urls = re.findall(r'https?://[^\'"\s]+', injected)
|
| 433 |
-
assert all(u.startswith(_A11OY_BASE) for u in urls),
|
|
|
|
| 434 |
|
| 435 |
print("killinchu_nav_wireup: ALL OK (Restraint nav item + cross-link strip; "
|
| 436 |
"idempotent; additive; 0 codenames; 0 CDN; same-estate cross-link only)")
|
|
|
|
| 24 |
# markup; it removes nothing and never clobbers another lane's nav.
|
| 25 |
#
|
| 26 |
# DOCTRINE (v11): locked = 8 @ c7c0ba17; Λ = Conjecture 1 (NOT a theorem);
|
| 27 |
+
# 0 visible codenames (labels are the surfaces' own honest titles); 0 CDN (the
|
| 28 |
+
# absolute URLs are same-estate a11oy surfaces, not third-party CDN assets);
|
| 29 |
# honest labels only; never weakens a gate; never commits a key; additive-only.
|
| 30 |
#
|
| 31 |
# Signed-off-by: Stephen P. Lutar Jr. <stephenlutar2@gmail.com>
|
|
|
|
| 72 |
|
| 73 |
# The a11oy-hosted Restraint surfaces (same estate, NOT a third-party CDN).
|
| 74 |
_A11OY_BASE = "https://szlholdings-a11oy.hf.space"
|
| 75 |
+
_A11OY_PUBLIC_BASE = "https://a-11-oy.com"
|
| 76 |
_RESTRAINT_URL = _A11OY_BASE + "/restraint"
|
| 77 |
_RESTRAINT_BENCH_URL = _A11OY_BASE + "/restraint-bench"
|
| 78 |
|
|
|
|
| 106 |
def _build_nav_item() -> bytes:
|
| 107 |
"""ONE Restraint nav-item, mirroring killinchu's own nav-item markup
|
| 108 |
(class="nav-item" + <span class="ico"> + label). Navigates cross-app to the
|
| 109 |
+
a11oy Restraint surface via a real anchor. 0 CDN, 0 inline <style>, no codename."""
|
| 110 |
item = (
|
| 111 |
+
'<a class="nav-item" data-nav-restraint="r5" href="%s" '
|
| 112 |
+
'style="cursor:pointer;text-decoration:none" '
|
| 113 |
'title="a11oy Restraint — governed code-minimization / dependency-frugality (aligns with, not certified)">'
|
| 114 |
+
'<span class="ico">\u27c2</span>Restraint (Governed Frugality)</a>'
|
| 115 |
) % _RESTRAINT_URL
|
| 116 |
return item.encode("utf-8")
|
| 117 |
|
|
|
|
| 121 |
cluster from killinchu. Inline-styled (0 CDN). Honest labels."""
|
| 122 |
rel = [
|
| 123 |
("/ecosystem", "Estate Hub"),
|
| 124 |
+
(_A11OY_PUBLIC_BASE + "/ecosystem", "a11oy Ecosystem"),
|
| 125 |
+
(_A11OY_PUBLIC_BASE + "/anatomy-v5", "Anatomy v5"),
|
| 126 |
(_A11OY_BASE + "/nemo", "SZL-Nemo"),
|
| 127 |
(_A11OY_BASE + "/autoreview", "Auto-Review"),
|
| 128 |
(_A11OY_BASE + "/factory", "Factory"),
|
|
|
|
| 137 |
if path == current_path:
|
| 138 |
continue
|
| 139 |
links.append(
|
| 140 |
+
'<a href="%s" style="color:#d4a444;text-decoration:none;display:inline-flex;'
|
| 141 |
+
'align-items:center;min-height:44px;padding:.35rem .2rem;white-space:nowrap">%s</a>'
|
| 142 |
+
% (path, label)
|
| 143 |
)
|
| 144 |
strip = (
|
| 145 |
'<nav data-related-restraint="r5" aria-label="Related surfaces" '
|
| 146 |
+
'style="margin:1.25rem auto;max-width:1100px;padding:.6rem .9rem;display:flex;'
|
| 147 |
+
'flex-wrap:wrap;align-items:center;justify-content:center;gap:.15rem .35rem;'
|
| 148 |
'border-top:1px solid #1d2632;font:13px/1.6 system-ui,sans-serif;'
|
| 149 |
'color:#7c8794;text-align:center">'
|
| 150 |
+
'<span style="color:#7c8794;margin-right:.2em">Related surfaces:</span>'
|
| 151 |
+ "".join(links)
|
| 152 |
+ "</nav>"
|
| 153 |
)
|
|
|
|
| 415 |
assert "Operate</div>" in h1, "must NOT remove existing nav group"
|
| 416 |
assert "footer</div>" in h1, "must NOT remove footer"
|
| 417 |
# placed immediately before the footer
|
| 418 |
+
assert 'Restraint (Governed Frugality)</a><div class="side-foot">' in h1, "must place before footer"
|
| 419 |
assert h1 == h2, "second render must be byte-identical (idempotent)"
|
| 420 |
|
| 421 |
e1 = c.get("/ecosystem").text
|
|
|
|
| 423 |
assert e1.count('data-related-restraint="r5"') == 1, "cross-link strip must inject once"
|
| 424 |
assert e2.count('data-related-restraint="r5"') == 1, "cross-link strip must be idempotent"
|
| 425 |
assert _RESTRAINT_URL in e1 and "/autoreview" in e1, "strip must cross-link Restraint + flagships"
|
| 426 |
+
assert _A11OY_PUBLIC_BASE + "/ecosystem" in e1, "strip must link the public a11oy ecosystem"
|
| 427 |
+
assert _A11OY_PUBLIC_BASE + "/anatomy-v5" in e1, "strip must link public Anatomy v5"
|
| 428 |
# /ecosystem is the current page -> omitted from its own strip
|
| 429 |
inner = e1.split('data-related-restraint="r5"')[1].split("</nav>")[0]
|
| 430 |
+
assert 'href="/ecosystem"' not in inner, "strip must omit the current local page (/ecosystem)"
|
| 431 |
assert e1 == e2, "second ecosystem render must be byte-identical"
|
| 432 |
|
| 433 |
# Doctrine guard: 0 CDN (only the same-estate a11oy URL), 0 script, 0 codename.
|
| 434 |
injected = (_build_nav_item().decode() + _build_related_strip("/ecosystem").decode())
|
| 435 |
low = injected.lower()
|
| 436 |
assert "<script" not in low, "nav markup must inject no script"
|
| 437 |
+
# the ONLY absolute URLs allowed are same-estate a11oy app/public-domain links
|
| 438 |
import re
|
| 439 |
urls = re.findall(r'https?://[^\'"\s]+', injected)
|
| 440 |
+
assert all(u.startswith((_A11OY_BASE, _A11OY_PUBLIC_BASE)) for u in urls), \
|
| 441 |
+
"only same-estate a11oy URLs allowed: %s" % urls
|
| 442 |
|
| 443 |
print("killinchu_nav_wireup: ALL OK (Restraint nav item + cross-link strip; "
|
| 444 |
"idempotent; additive; 0 codenames; 0 CDN; same-estate cross-link only)")
|
killinchu_public_route_repair.py
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Fail-closed public discovery routes for the Killinchu Space.
|
| 2 |
+
|
| 3 |
+
The application has a large, additive router. Two public discovery contracts
|
| 4 |
+
must win before its SPA catch-all:
|
| 5 |
+
|
| 6 |
+
* ``/openapi.json`` delegates to the already-hardened namespaced generator.
|
| 7 |
+
* ``/.well-known/szl-source.json`` serves the on-disk attestation artifact.
|
| 8 |
+
|
| 9 |
+
This module deliberately does not manufacture either contract. If the real
|
| 10 |
+
generator or artifact is unavailable, callers receive an explicit JSON 503
|
| 11 |
+
instead of a misleading HTML shell or a synthetic success response.
|
| 12 |
+
"""
|
| 13 |
+
|
| 14 |
+
from __future__ import annotations
|
| 15 |
+
|
| 16 |
+
import inspect
|
| 17 |
+
import json
|
| 18 |
+
import os
|
| 19 |
+
from pathlib import Path
|
| 20 |
+
from typing import Any
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
_OPENAPI_ROUTE_NAME = "killinchu_p0_openapi_alias"
|
| 24 |
+
_SOURCE_ROUTE_NAME = "killinchu_p0_source_artifact"
|
| 25 |
+
_MAX_SOURCE_BYTES = 2 * 1024 * 1024
|
| 26 |
+
_JSON_HEADERS = {
|
| 27 |
+
"Cache-Control": "no-store",
|
| 28 |
+
"X-Content-Type-Options": "nosniff",
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def _head_from(response: Any, response_cls: Any) -> Any:
|
| 33 |
+
"""Return a bodyless response while preserving GET status and headers."""
|
| 34 |
+
|
| 35 |
+
return response_cls(
|
| 36 |
+
content=b"",
|
| 37 |
+
status_code=response.status_code,
|
| 38 |
+
headers=dict(response.headers),
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def register(
|
| 43 |
+
app: Any,
|
| 44 |
+
*,
|
| 45 |
+
ns: str = "killinchu",
|
| 46 |
+
artifact_path: str | os.PathLike[str] | None = None,
|
| 47 |
+
) -> dict[str, Any]:
|
| 48 |
+
"""Register exact public routes ahead of defaults and the SPA catch-all."""
|
| 49 |
+
|
| 50 |
+
from starlette.responses import JSONResponse, Response
|
| 51 |
+
from starlette.routing import Route
|
| 52 |
+
|
| 53 |
+
organ_path = f"/api/{ns}/openapi.json"
|
| 54 |
+
organ_endpoint = next(
|
| 55 |
+
(
|
| 56 |
+
getattr(route, "endpoint", None)
|
| 57 |
+
for route in app.router.routes
|
| 58 |
+
if getattr(route, "path", None) == organ_path
|
| 59 |
+
and callable(getattr(route, "endpoint", None))
|
| 60 |
+
),
|
| 61 |
+
None,
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
if artifact_path is None:
|
| 65 |
+
configured_path = os.environ.get("KILLINCHU_SOURCE_ATTESTATION_PATH", "").strip()
|
| 66 |
+
if configured_path:
|
| 67 |
+
source_path = Path(configured_path)
|
| 68 |
+
else:
|
| 69 |
+
app_root = Path(os.environ.get("KILLINCHU_ROOT", "/app"))
|
| 70 |
+
source_path = app_root / ".well-known" / "szl-source.json"
|
| 71 |
+
else:
|
| 72 |
+
source_path = Path(artifact_path)
|
| 73 |
+
|
| 74 |
+
def unavailable(schema: str, reason: str, method: str) -> Any:
|
| 75 |
+
response = JSONResponse(
|
| 76 |
+
{
|
| 77 |
+
"schema": schema,
|
| 78 |
+
"state": "UNAVAILABLE",
|
| 79 |
+
"reason": reason,
|
| 80 |
+
},
|
| 81 |
+
status_code=503,
|
| 82 |
+
headers=_JSON_HEADERS,
|
| 83 |
+
)
|
| 84 |
+
return _head_from(response, Response) if method == "HEAD" else response
|
| 85 |
+
|
| 86 |
+
async def public_openapi(request: Any) -> Any:
|
| 87 |
+
if organ_endpoint is None:
|
| 88 |
+
return unavailable(
|
| 89 |
+
"szl.openapi-unavailable/v1",
|
| 90 |
+
"generated OpenAPI contract is unavailable",
|
| 91 |
+
request.method,
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
try:
|
| 95 |
+
generated = organ_endpoint()
|
| 96 |
+
if inspect.isawaitable(generated):
|
| 97 |
+
generated = await generated
|
| 98 |
+
|
| 99 |
+
status_code = 200
|
| 100 |
+
if isinstance(generated, Response):
|
| 101 |
+
status_code = generated.status_code
|
| 102 |
+
raw_body = getattr(generated, "body", None)
|
| 103 |
+
if raw_body is None:
|
| 104 |
+
raise ValueError("schema response is not materialized JSON")
|
| 105 |
+
payload = json.loads(bytes(raw_body).decode("utf-8"))
|
| 106 |
+
else:
|
| 107 |
+
payload = generated
|
| 108 |
+
|
| 109 |
+
if status_code >= 400 or not isinstance(payload, dict) or not payload.get("openapi"):
|
| 110 |
+
raise ValueError("schema response is not a valid OpenAPI document")
|
| 111 |
+
except Exception:
|
| 112 |
+
return unavailable(
|
| 113 |
+
"szl.openapi-unavailable/v1",
|
| 114 |
+
"generated OpenAPI contract is unavailable",
|
| 115 |
+
request.method,
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
+
response = JSONResponse(payload, headers=_JSON_HEADERS)
|
| 119 |
+
return _head_from(response, Response) if request.method == "HEAD" else response
|
| 120 |
+
|
| 121 |
+
async def source_attestation(request: Any) -> Any:
|
| 122 |
+
try:
|
| 123 |
+
raw = source_path.read_bytes()
|
| 124 |
+
if not raw or len(raw) > _MAX_SOURCE_BYTES:
|
| 125 |
+
raise ValueError("source attestation has an invalid size")
|
| 126 |
+
parsed = json.loads(raw.decode("utf-8"))
|
| 127 |
+
if not isinstance(parsed, dict):
|
| 128 |
+
raise ValueError("source attestation must be a JSON object")
|
| 129 |
+
except (OSError, UnicodeError, ValueError, json.JSONDecodeError):
|
| 130 |
+
return unavailable(
|
| 131 |
+
"szl.source-attestation-unavailable/v1",
|
| 132 |
+
"source attestation artifact is unavailable or invalid",
|
| 133 |
+
request.method,
|
| 134 |
+
)
|
| 135 |
+
|
| 136 |
+
response = Response(content=raw, media_type="application/json", headers=_JSON_HEADERS)
|
| 137 |
+
return _head_from(response, Response) if request.method == "HEAD" else response
|
| 138 |
+
|
| 139 |
+
existing_names = {getattr(route, "name", None) for route in app.router.routes}
|
| 140 |
+
routes: list[Any] = []
|
| 141 |
+
registered: list[str] = []
|
| 142 |
+
|
| 143 |
+
if _OPENAPI_ROUTE_NAME not in existing_names:
|
| 144 |
+
routes.append(
|
| 145 |
+
Route(
|
| 146 |
+
"/openapi.json",
|
| 147 |
+
endpoint=public_openapi,
|
| 148 |
+
methods=["GET", "HEAD"],
|
| 149 |
+
name=_OPENAPI_ROUTE_NAME,
|
| 150 |
+
)
|
| 151 |
+
)
|
| 152 |
+
registered.append("/openapi.json")
|
| 153 |
+
|
| 154 |
+
if _SOURCE_ROUTE_NAME not in existing_names:
|
| 155 |
+
routes.append(
|
| 156 |
+
Route(
|
| 157 |
+
"/.well-known/szl-source.json",
|
| 158 |
+
endpoint=source_attestation,
|
| 159 |
+
methods=["GET", "HEAD"],
|
| 160 |
+
name=_SOURCE_ROUTE_NAME,
|
| 161 |
+
)
|
| 162 |
+
)
|
| 163 |
+
registered.append("/.well-known/szl-source.json")
|
| 164 |
+
|
| 165 |
+
# Starlette resolves in declaration order. Front insertion ensures these
|
| 166 |
+
# exact contracts win over FastAPI's broken default and /{full_path:path}.
|
| 167 |
+
if routes:
|
| 168 |
+
app.router.routes[0:0] = routes
|
| 169 |
+
|
| 170 |
+
return {
|
| 171 |
+
"registered": registered,
|
| 172 |
+
"openapi_source": organ_path,
|
| 173 |
+
"source_artifact": str(source_path),
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
__all__ = ["register"]
|
serve.py
CHANGED
|
@@ -5382,32 +5382,34 @@ except Exception as _sapa_e: # pragma: no cover
|
|
| 5382 |
|
| 5383 |
|
| 5384 |
# ============================================================================
|
| 5385 |
-
#
|
| 5386 |
-
# (1) szl_spaces_proxy:
|
| 5387 |
-
#
|
| 5388 |
-
#
|
| 5389 |
-
#
|
| 5390 |
-
#
|
| 5391 |
-
#
|
| 5392 |
-
#
|
| 5393 |
-
# SPA + Node-proxy catch-alls. Doctrine v11: locked=8 @ c7c0ba17; Λ=Conjecture 1;
|
| 5394 |
-
# Khipu=Conjecture 2; honest 502/unknown beats a fake 200; no codenames; no key.
|
| 5395 |
# Signed-off-by: Stephen Lutar <stephenlutar2@gmail.com>
|
| 5396 |
# Co-Authored-By: Perplexity Computer Agent <agent@perplexity.ai>
|
| 5397 |
# ============================================================================
|
| 5398 |
try:
|
| 5399 |
try: # substrate-finish repoint: prefer shared pkg, fall back to vendored copy
|
| 5400 |
from szl_substrate import szl_spaces_proxy as _szl_spaces_proxy # single source of truth
|
|
|
|
|
|
|
| 5401 |
except Exception:
|
| 5402 |
import szl_spaces_proxy as _szl_spaces_proxy
|
| 5403 |
_szl_spaces_proxy_status = _szl_spaces_proxy.register(app, ns="killinchu")
|
| 5404 |
-
print(f"[killinchu] Spaces
|
| 5405 |
except Exception as _szl_sp_e: # pragma: no cover
|
| 5406 |
-
print(f"[killinchu] Spaces
|
| 5407 |
|
| 5408 |
try:
|
| 5409 |
try: # substrate-finish repoint: prefer shared pkg, fall back to vendored copy
|
| 5410 |
from szl_substrate import szl_spaces_surface as _szl_spaces_surface # single source of truth
|
|
|
|
|
|
|
| 5411 |
except Exception:
|
| 5412 |
import szl_spaces_surface as _szl_spaces_surface
|
| 5413 |
_szl_spaces_surface_status = _szl_spaces_surface.register(app, ns="killinchu")
|
|
@@ -5542,6 +5544,31 @@ except Exception as _kc_wave_e: # pragma: no cover — never break SPA/other or
|
|
| 5542 |
# ============================================================================
|
| 5543 |
|
| 5544 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5545 |
if __name__ == "__main__":
|
| 5546 |
import uvicorn
|
| 5547 |
port = int(os.environ.get("PORT", "7860"))
|
|
|
|
| 5382 |
|
| 5383 |
|
| 5384 |
# ============================================================================
|
| 5385 |
+
# HUGGING FACE SPACES REGISTRY (Dev2+3) — all 26 audited Spaces.
|
| 5386 |
+
# (1) szl_spaces_proxy: legacy /spaces/<name>/<path> links are no-store 307
|
| 5387 |
+
# handoffs to canonical isolated HF app origins. It never proxies upstream bytes,
|
| 5388 |
+
# JavaScript, cookies, or authentication into the Killinchu origin.
|
| 5389 |
+
# (2) szl_spaces_surface: /api/<ns>/v1/spaces/health (REAL probe + HF-API stage),
|
| 5390 |
+
# /spaces canonical-origin tiles, + ONE idempotent nav item. Both front-insert
|
| 5391 |
+
# exact routes before the SPA catch-all. Runtime health remains honestly measured;
|
| 5392 |
+
# no missing probe becomes a fabricated green state.
|
|
|
|
|
|
|
| 5393 |
# Signed-off-by: Stephen Lutar <stephenlutar2@gmail.com>
|
| 5394 |
# Co-Authored-By: Perplexity Computer Agent <agent@perplexity.ai>
|
| 5395 |
# ============================================================================
|
| 5396 |
try:
|
| 5397 |
try: # substrate-finish repoint: prefer shared pkg, fall back to vendored copy
|
| 5398 |
from szl_substrate import szl_spaces_proxy as _szl_spaces_proxy # single source of truth
|
| 5399 |
+
if getattr(_szl_spaces_proxy, "SPACE_HANDOFF_MODE", None) != "canonical-redirect-only/v1":
|
| 5400 |
+
raise ImportError("shared Spaces module lacks redirect-only security contract")
|
| 5401 |
except Exception:
|
| 5402 |
import szl_spaces_proxy as _szl_spaces_proxy
|
| 5403 |
_szl_spaces_proxy_status = _szl_spaces_proxy.register(app, ns="killinchu")
|
| 5404 |
+
print(f"[killinchu] Spaces canonical handoffs registered: {_szl_spaces_proxy_status}", file=__import__("sys").stderr)
|
| 5405 |
except Exception as _szl_sp_e: # pragma: no cover
|
| 5406 |
+
print(f"[killinchu] Spaces canonical handoffs NOT registered: {_szl_sp_e!r}; SPA + API unaffected", file=__import__("sys").stderr)
|
| 5407 |
|
| 5408 |
try:
|
| 5409 |
try: # substrate-finish repoint: prefer shared pkg, fall back to vendored copy
|
| 5410 |
from szl_substrate import szl_spaces_surface as _szl_spaces_surface # single source of truth
|
| 5411 |
+
if getattr(_szl_spaces_surface, "SPACE_TILE_ORIGIN_MODE", None) != "canonical-isolated-hf/v1":
|
| 5412 |
+
raise ImportError("shared Spaces surface lacks canonical-origin contract")
|
| 5413 |
except Exception:
|
| 5414 |
import szl_spaces_surface as _szl_spaces_surface
|
| 5415 |
_szl_spaces_surface_status = _szl_spaces_surface.register(app, ns="killinchu")
|
|
|
|
| 5544 |
# ============================================================================
|
| 5545 |
|
| 5546 |
|
| 5547 |
+
# ============================================================================
|
| 5548 |
+
# BEGIN: P0 PUBLIC DISCOVERY ROUTE REPAIR (ADDITIVE)
|
| 5549 |
+
# Exact JSON contracts must resolve before FastAPI's default /openapi.json and
|
| 5550 |
+
# the SPA /{full_path:path} fallback. The helper delegates to the existing
|
| 5551 |
+
# hardened namespaced OpenAPI generator and serves the existing source artifact
|
| 5552 |
+
# from disk; missing evidence fails closed as JSON 503 (never synthetic HTML).
|
| 5553 |
+
# ============================================================================
|
| 5554 |
+
try:
|
| 5555 |
+
import killinchu_public_route_repair as _kc_public_route_repair
|
| 5556 |
+
_kc_public_route_status = _kc_public_route_repair.register(app, ns="killinchu")
|
| 5557 |
+
print(
|
| 5558 |
+
f"[killinchu] P0 public discovery routes registered: {_kc_public_route_status}",
|
| 5559 |
+
file=sys.stderr,
|
| 5560 |
+
)
|
| 5561 |
+
except Exception as _kc_public_route_e: # pragma: no cover - preserve startup
|
| 5562 |
+
print(
|
| 5563 |
+
f"[killinchu] P0 public discovery routes NOT registered: {_kc_public_route_e!r}; "
|
| 5564 |
+
"other organs unaffected",
|
| 5565 |
+
file=sys.stderr,
|
| 5566 |
+
)
|
| 5567 |
+
# ============================================================================
|
| 5568 |
+
# END: P0 PUBLIC DISCOVERY ROUTE REPAIR
|
| 5569 |
+
# ============================================================================
|
| 5570 |
+
|
| 5571 |
+
|
| 5572 |
if __name__ == "__main__":
|
| 5573 |
import uvicorn
|
| 5574 |
port = int(os.environ.get("PORT", "7860"))
|
szl_spaces_proxy.py
CHANGED
|
@@ -1,444 +1,323 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
# SPDX-License-Identifier: Apache-2.0
|
| 3 |
# © 2026 Lutar, Stephen P. — SZL Holdings · ORCID 0009-0001-0110-4173
|
| 4 |
-
"""
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
proxies each live Hugging Face Space to a same-origin path:
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
only (no open proxy); unknown names -> 404. a11oy is NOT self-proxied (would loop) and
|
| 25 |
-
killinchu is served on its own host — both are listed as TILES (by szl_spaces_surface)
|
| 26 |
-
linking to their canonical hosts, but are NOT in the reverse-proxy allowlist here.
|
| 27 |
-
|
| 28 |
-
No auth token is forwarded to HF — these are PUBLIC Spaces.
|
| 29 |
-
|
| 30 |
-
Routes are inserted at the FRONT of app.router.routes (app.router.routes[0:0] = new)
|
| 31 |
-
so they win over the /api/<ns>/{path:path} Node proxy + the /{full_path:path} SPA
|
| 32 |
-
catch-all (the same route-to-front idiom a11oy_hf_assets.py uses).
|
| 33 |
-
|
| 34 |
-
Doctrine v11: locked-proven = EXACTLY 8 {F1,F4,F7,F11,F12,F18,F19,F22} @ c7c0ba17;
|
| 35 |
-
Λ = Conjecture 1; Khipu = Conjecture 2; trust never 100%; 0 runtime CDN (server-side
|
| 36 |
-
fetch); no user-visible codenames (Space names are their own honest titles); never
|
| 37 |
-
commits a key; additive-only; never weakens a gate; honest 502 beats a fake 200.
|
| 38 |
|
| 39 |
Signed-off-by: Stephen Lutar <stephenlutar2@gmail.com>
|
| 40 |
-
Co-Authored-By: Perplexity Computer Agent <agent@perplexity.ai>
|
| 41 |
"""
|
| 42 |
from __future__ import annotations
|
| 43 |
|
|
|
|
| 44 |
import sys
|
| 45 |
from typing import Any
|
|
|
|
| 46 |
|
| 47 |
_ORG_PREFIX = "szlholdings-"
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
#
|
| 52 |
-
#
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
"
|
| 56 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
]
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
|
| 62 |
-
def
|
| 63 |
-
"""
|
| 64 |
-
return f"https://{_ORG_PREFIX}{name}.hf.space"
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
-
# Hop-by-hop headers (RFC 7230 §6.1) — never forwarded across the proxy boundary.
|
| 68 |
-
_HOP_BY_HOP = {
|
| 69 |
-
"connection", "keep-alive", "proxy-authenticate", "proxy-authorization",
|
| 70 |
-
"te", "trailers", "transfer-encoding", "upgrade",
|
| 71 |
-
# content-encoding/length are recomputed by our Response; strip to avoid mismatch.
|
| 72 |
-
"content-encoding", "content-length",
|
| 73 |
-
}
|
| 74 |
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
_PROXY_RETRIES = 3 # retry a transient flap several times before honest-degrading.
|
| 78 |
-
_MAX_BYTES = 25 * 1024 * 1024 # 25MB cap per proxied response (Spaces are light pages).
|
| 79 |
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
"<title>Space %s — starting / unreachable</title></head>"
|
| 88 |
-
"<body style=\"margin:0;background:#0b0f14;color:#cdd6e0;"
|
| 89 |
-
"font:15px/1.6 system-ui,-apple-system,Segoe UI,Roboto,sans-serif;"
|
| 90 |
-
"display:flex;min-height:100vh;align-items:center;justify-content:center\">"
|
| 91 |
-
"<main style=\"max-width:560px;padding:2rem;text-align:center\">"
|
| 92 |
-
"<div style=\"font-size:2.2rem;margin-bottom:.4rem\">⚡</div>"
|
| 93 |
-
"<h1 style=\"font-size:1.25rem;margin:0 0 .6rem;color:#e7eef6\">"
|
| 94 |
-
"Space “%s” is starting or unreachable</h1>"
|
| 95 |
-
"<p style=\"color:#8a96a3;margin:0 0 1.2rem\">The upstream Hugging Face Space did "
|
| 96 |
-
"not respond in time. This is an honest 502 — not a faked page. "
|
| 97 |
-
"It usually means the Space is waking from sleep; try again shortly.</p>"
|
| 98 |
-
"<p><a href=\"%s\" style=\"color:#d4a444;text-decoration:none;font-weight:600\">"
|
| 99 |
-
"Open %s directly on Hugging Face →</a></p>"
|
| 100 |
-
"<p style=\"margin-top:1.4rem\"><a href=\"/spaces\" "
|
| 101 |
-
"style=\"color:#7c8794;text-decoration:none\">← All Spaces</a></p>"
|
| 102 |
-
"</main></body></html>" % (name, name, url, name)
|
| 103 |
-
).encode("utf-8")
|
| 104 |
|
| 105 |
|
| 106 |
def _fallback_index() -> bytes:
|
| 107 |
-
"""
|
| 108 |
-
|
| 109 |
rows = []
|
| 110 |
-
for
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
local_label = "Open in a-11-oy.com"
|
| 117 |
rows.append(
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
"
|
|
|
|
|
|
|
|
|
|
| 122 |
)
|
| 123 |
return (
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
"
|
| 133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
"</main></body></html>"
|
| 135 |
).encode("utf-8")
|
| 136 |
|
| 137 |
|
| 138 |
-
def
|
| 139 |
-
"""
|
| 140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
try:
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
except Exception:
|
| 145 |
return None
|
|
|
|
|
|
|
|
|
|
| 146 |
|
| 147 |
|
| 148 |
-
def
|
| 149 |
-
"""
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
pass
|
| 179 |
-
return he.code, body, {k: v for k, v in (he.headers or {}).items()}
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
async def _to_thread(fn, *a, **kw):
|
| 183 |
-
import asyncio as _asyncio
|
| 184 |
-
return await _asyncio.get_event_loop().run_in_executor(None, lambda: fn(*a, **kw))
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
def _rewrite_html(body: bytes, name: str) -> bytes:
|
| 188 |
-
"""Inject <base href="/spaces/<name>/"> so the Space's root-relative asset URLs
|
| 189 |
-
(e.g. /assets/app.js, href="/"...) resolve back through this proxy. Idempotent:
|
| 190 |
-
if a base href for this proxy is already present, leave the body untouched."""
|
| 191 |
-
base_tag = ('<base href="/spaces/%s/">' % name).encode("utf-8")
|
| 192 |
-
if base_tag in body:
|
| 193 |
-
return body
|
| 194 |
-
low = body.lower()
|
| 195 |
-
# Prefer to place the <base> right after <head ...> so it applies to all assets.
|
| 196 |
-
h = low.find(b"<head")
|
| 197 |
-
if h != -1:
|
| 198 |
-
gt = body.find(b">", h)
|
| 199 |
-
if gt != -1:
|
| 200 |
-
return body[: gt + 1] + base_tag + body[gt + 1:]
|
| 201 |
-
# No <head> — try right after <html ...>.
|
| 202 |
-
h = low.find(b"<html")
|
| 203 |
-
if h != -1:
|
| 204 |
-
gt = body.find(b">", h)
|
| 205 |
-
if gt != -1:
|
| 206 |
-
return body[: gt + 1] + base_tag + body[gt + 1:]
|
| 207 |
-
# No usable anchor — prepend (still better than broken relative assets).
|
| 208 |
-
return base_tag + body
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
async def _proxy(name: str, subpath: str, request) -> Any:
|
| 212 |
-
"""Reverse-proxy one request to the named Space. Honest 502 on any upstream flap."""
|
| 213 |
-
from starlette.responses import Response
|
| 214 |
-
|
| 215 |
-
if name not in PROXY_SPACES:
|
| 216 |
-
# Not in the allowlist — either unknown, or a deliberately-skipped self/own-host
|
| 217 |
-
# Space. 404 (no open proxy). The skipped ones are reachable as tiles only.
|
| 218 |
-
return Response(content=b"Unknown or non-proxied Space.\n",
|
| 219 |
-
status_code=404, media_type="text/plain")
|
| 220 |
-
|
| 221 |
-
# Resolve the shared async httpx client if it's wired. On the LIVE box serve.py runs
|
| 222 |
-
# as __main__ (Dockerfile CMD ["python","serve.py"]), so `import serve` inside
|
| 223 |
-
# _resolve_client() binds a SECOND module object whose startup() never fired and whose
|
| 224 |
-
# _http_client is therefore None — even though the real __main__ app has a live client.
|
| 225 |
-
# We must NOT 502 on a None client: the stdlib urllib path below is the PROVEN outbound
|
| 226 |
-
# path on this box (it is exactly what szl_spaces_surface's health probe uses to report
|
| 227 |
-
# app_reachable=true). So client==None simply means "skip httpx, use urllib" — never an
|
| 228 |
-
# automatic honest-502. An honest 502 is reserved for a GENUINE upstream flap (both the
|
| 229 |
-
# httpx attempt AND the urllib fallback exhausted their retries).
|
| 230 |
-
client = _resolve_client()
|
| 231 |
-
|
| 232 |
-
target = hf_url(name) + "/" + subpath
|
| 233 |
-
# Send a CLEAN, minimal header set rather than forwarding the raw browser headers.
|
| 234 |
-
# Forwarding the incoming Host (a-11-oy.com) makes HF route to the wrong vhost -> 404,
|
| 235 |
-
# and forwarding the full browser header set (incl. Accept-Encoding: br, X-Forwarded-*)
|
| 236 |
-
# was tripping the upstream fetch on the live box. We mirror the proven-working probe:
|
| 237 |
-
# identity encoding, a simple UA, and only the few request headers that are safe to
|
| 238 |
-
# pass through. No Host, no cookies, no auth token (public Spaces).
|
| 239 |
-
_SAFE_PASS = {"accept", "accept-language", "range", "content-type"}
|
| 240 |
-
fwd_headers = {
|
| 241 |
-
"User-Agent": "szl-spaces-proxy/1.0",
|
| 242 |
-
"Accept-Encoding": "identity",
|
| 243 |
-
}
|
| 244 |
-
for k, v in request.headers.items():
|
| 245 |
-
if k.lower() in _SAFE_PASS:
|
| 246 |
-
fwd_headers[k] = v
|
| 247 |
-
fwd_headers.setdefault("Accept", "*/*")
|
| 248 |
-
method = request.method.upper()
|
| 249 |
-
|
| 250 |
-
status = None
|
| 251 |
-
body = b""
|
| 252 |
-
up_headers: dict = {}
|
| 253 |
-
last_exc = None
|
| 254 |
-
|
| 255 |
-
# Try the shared async httpx client first (streaming-capable, preferred).
|
| 256 |
-
if client is not None:
|
| 257 |
-
for _attempt in range(_PROXY_RETRIES + 1):
|
| 258 |
-
try:
|
| 259 |
-
upstream = await client.request(
|
| 260 |
-
method, target, headers=fwd_headers,
|
| 261 |
-
timeout=_PROXY_TIMEOUT, follow_redirects=True,
|
| 262 |
-
)
|
| 263 |
-
status = upstream.status_code
|
| 264 |
-
body = upstream.content or b""
|
| 265 |
-
up_headers = {k: v for k, v in upstream.headers.items()}
|
| 266 |
-
break
|
| 267 |
-
except Exception as e: # connect/timeout/read error -> try fallback below
|
| 268 |
-
last_exc = e
|
| 269 |
-
status = None
|
| 270 |
-
import asyncio as _a
|
| 271 |
-
await _a.sleep(0.4 * (_attempt + 1)) # brief backoff across a flap
|
| 272 |
-
|
| 273 |
-
# Fallback to the PROVEN stdlib urllib path if httpx was None or failed.
|
| 274 |
-
if status is None:
|
| 275 |
-
import asyncio as _a
|
| 276 |
-
for _attempt in range(_PROXY_RETRIES + 1):
|
| 277 |
-
try:
|
| 278 |
-
status, body, up_headers = await _to_thread(
|
| 279 |
-
_urllib_fetch, method, target, fwd_headers, _PROXY_TIMEOUT)
|
| 280 |
-
break
|
| 281 |
-
except Exception as e: # genuine upstream flap -> honest 502
|
| 282 |
-
last_exc = e
|
| 283 |
-
status = None
|
| 284 |
-
await _a.sleep(0.5 * (_attempt + 1)) # brief backoff across a flap
|
| 285 |
-
|
| 286 |
-
if status is None:
|
| 287 |
-
print("[spaces-proxy] upstream flap for %s: %r" % (name, last_exc),
|
| 288 |
-
file=sys.stderr)
|
| 289 |
-
# Surface the real upstream error class in an honest diagnostic header (the body
|
| 290 |
-
# stays the clean honest-502 page). Never fabricates a 200.
|
| 291 |
-
return Response(content=_honest_502(name), status_code=502,
|
| 292 |
-
media_type="text/html",
|
| 293 |
-
headers={"x-szl-proxy-error": type(last_exc).__name__ if last_exc else "none",
|
| 294 |
-
"x-szl-proxy-target": target})
|
| 295 |
-
|
| 296 |
-
if len(body) > _MAX_BYTES:
|
| 297 |
-
body = body[:_MAX_BYTES]
|
| 298 |
-
ct = (up_headers.get("content-type") or up_headers.get("Content-Type") or "").lower()
|
| 299 |
-
|
| 300 |
-
# HTML: inject <base href> so assets resolve under /spaces/<name>/.
|
| 301 |
-
if "text/html" in ct:
|
| 302 |
-
body = _rewrite_html(body, name)
|
| 303 |
-
|
| 304 |
-
out_headers = {
|
| 305 |
-
k: v for k, v in up_headers.items()
|
| 306 |
-
if k.lower() not in _HOP_BY_HOP
|
| 307 |
-
}
|
| 308 |
-
# HEAD must carry no body.
|
| 309 |
-
if method == "HEAD":
|
| 310 |
-
body = b""
|
| 311 |
-
|
| 312 |
-
return Response(content=body, status_code=status,
|
| 313 |
-
headers=out_headers,
|
| 314 |
-
media_type=ct or None)
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
def register(app, ns: str = "a11oy") -> str:
|
| 318 |
-
"""ADDITIVE: mount the /spaces reverse-proxy routes at the FRONT of the router so
|
| 319 |
-
they beat the SPA + Node-proxy catch-alls. try/except-guarded by the caller."""
|
| 320 |
try:
|
| 321 |
from starlette.responses import Response
|
| 322 |
-
|
| 323 |
-
|
|
|
|
| 324 |
|
| 325 |
n_before = len(app.router.routes)
|
| 326 |
|
| 327 |
-
async def _spaces_index(request):
|
| 328 |
-
|
| 329 |
-
# fallback index only renders if that module isn't present. Idempotent: this
|
| 330 |
-
# route is inserted only once per register() and register() is guarded upstream.
|
| 331 |
if request.method.upper() == "HEAD":
|
| 332 |
-
return Response(content=b"", status_code=200, media_type="text/html")
|
| 333 |
-
return Response(
|
| 334 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
|
| 336 |
-
async def _spaces_name(request):
|
| 337 |
-
|
| 338 |
-
return await _proxy(name, "", request)
|
| 339 |
|
| 340 |
-
async def _spaces_path(request):
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
|
|
|
|
|
|
| 344 |
|
| 345 |
-
from starlette.routing import Route
|
| 346 |
-
# NOTE: szl_spaces_surface registers its OWN richer /spaces tiles page and inserts
|
| 347 |
-
# it at the front AFTER this module (it's registered second in serve.py), so the
|
| 348 |
-
# tiles page wins over this fallback index — by design. Both are idempotent.
|
| 349 |
routes = [
|
| 350 |
-
Route("/spaces", _spaces_index, methods=["GET", "HEAD"]),
|
| 351 |
-
Route("/spaces/{name}", _spaces_name, methods=["GET", "HEAD"]),
|
| 352 |
-
Route(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 353 |
]
|
| 354 |
-
|
| 355 |
-
app.router.routes.append(r)
|
| 356 |
-
|
| 357 |
new = app.router.routes[n_before:]
|
| 358 |
del app.router.routes[n_before:]
|
| 359 |
app.router.routes[0:0] = new
|
| 360 |
-
print("[%s] Spaces reverse-proxy registered: /spaces + /spaces/{name} + "
|
| 361 |
-
"/spaces/{name}/{path} (%d proxied: %s) [moved %d routes to front]"
|
| 362 |
-
% (ns, len(PROXY_SPACES), ",".join(PROXY_SPACES), len(new)), file=sys.stderr)
|
| 363 |
-
return "ok: %d proxied spaces, %d routes" % (len(PROXY_SPACES), len(new))
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
# ---------------------------------------------------------------------------
|
| 367 |
-
# Self-test — pure stdlib + starlette TestClient; no real network. Stubs the shared
|
| 368 |
-
# client to assert: allowlist enforced (unknown -> 404), honest 502 on a dead client,
|
| 369 |
-
# <base href> injection, HEAD carries no body, and the fallback index lists all 11.
|
| 370 |
-
# ---------------------------------------------------------------------------
|
| 371 |
-
if __name__ == "__main__":
|
| 372 |
-
import ast as _ast
|
| 373 |
-
# parse-self guard
|
| 374 |
-
with open(__file__, "r", encoding="utf-8") as _fh:
|
| 375 |
-
_ast.parse(_fh.read())
|
| 376 |
-
|
| 377 |
-
# base-href injection
|
| 378 |
-
out = _rewrite_html(b"<html><head><title>x</title></head><body>hi</body></html>", "immune")
|
| 379 |
-
assert b'<base href="/spaces/immune/">' in out, "must inject base href"
|
| 380 |
-
assert _rewrite_html(out, "immune") == out, "base href injection must be idempotent"
|
| 381 |
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 385 |
|
| 386 |
-
# allowlist
|
| 387 |
-
assert "a11oy" not in PROXY_SPACES and "killinchu" not in PROXY_SPACES, "self/own-host skipped"
|
| 388 |
-
assert len(ALL_SPACES) == 11 and len(PROXY_SPACES) == 9, (len(ALL_SPACES), len(PROXY_SPACES))
|
| 389 |
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 394 |
|
| 395 |
from starlette.applications import Starlette
|
| 396 |
from starlette.responses import PlainTextResponse
|
| 397 |
-
from starlette.routing import Route
|
| 398 |
from starlette.testclient import TestClient
|
| 399 |
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
assert
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
r200 = c.get("/spaces/immune")
|
| 437 |
-
assert r200.status_code == 200, r200.status_code
|
| 438 |
-
assert b'<base href="/spaces/immune/">' in r200.content, "must inject base href on proxied HTML"
|
| 439 |
-
finally:
|
| 440 |
-
_self_mod._urllib_fetch = _orig_fetch
|
| 441 |
-
|
| 442 |
-
print("szl_spaces_proxy: ALL OK (allowlist; honest 502 on genuine flap; client==None "
|
| 443 |
-
"falls through to urllib not auto-502; base-href idempotent; "
|
| 444 |
-
"%d proxied of %d; 0 CDN server-side fetch)" % (len(PROXY_SPACES), len(ALL_SPACES)))
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
# SPDX-License-Identifier: Apache-2.0
|
| 3 |
# © 2026 Lutar, Stephen P. — SZL Holdings · ORCID 0009-0001-0110-4173
|
| 4 |
+
"""Canonical-origin handoffs for the audited Hugging Face Spaces estate.
|
| 5 |
|
| 6 |
+
This shared module keeps the historical ``/spaces/<slug>`` links working without
|
| 7 |
+
executing another Space inside the a11oy or Killinchu origin:
|
|
|
|
| 8 |
|
| 9 |
+
* ``GET/HEAD /spaces`` renders a minimal fallback index when the richer tiles
|
| 10 |
+
surface is not registered.
|
| 11 |
+
* ``GET/HEAD /spaces/{name}`` returns a no-store 307 to the audited Space's
|
| 12 |
+
canonical Hugging Face application origin.
|
| 13 |
+
* ``GET/HEAD /spaces/{name}/{path}`` preserves the suffix and raw query string
|
| 14 |
+
in the same no-store 307 handoff.
|
| 15 |
|
| 16 |
+
There is no upstream fetch path in this module. It never copies upstream HTML,
|
| 17 |
+
JavaScript, response bytes, authentication state, or ``Set-Cookie`` into the
|
| 18 |
+
host application. Interactive apps, streaming, cookies, and authentication stay
|
| 19 |
+
isolated on Hugging Face. Unknown identifiers fail closed with 404, so these
|
| 20 |
+
routes cannot become an open redirect.
|
| 21 |
|
| 22 |
+
Routes are front-inserted so exact compatibility links beat the application's
|
| 23 |
+
SPA catch-all. The audited 26-Space identity list is static; runtime reachability
|
| 24 |
+
continues to be measured honestly by ``szl_spaces_surface``.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
Signed-off-by: Stephen Lutar <stephenlutar2@gmail.com>
|
|
|
|
| 27 |
"""
|
| 28 |
from __future__ import annotations
|
| 29 |
|
| 30 |
+
import html
|
| 31 |
import sys
|
| 32 |
from typing import Any
|
| 33 |
+
from urllib.parse import quote
|
| 34 |
|
| 35 |
_ORG_PREFIX = "szlholdings-"
|
| 36 |
+
_ORG = "SZLHOLDINGS"
|
| 37 |
+
SPACE_HANDOFF_MODE = "canonical-redirect-only/v1"
|
| 38 |
+
|
| 39 |
+
# Audited 26-Space public estate. Runtime state is deliberately absent here.
|
| 40 |
+
# ``slug`` is the lowercase legacy route key; SDK selects the canonical app host.
|
| 41 |
+
SPACE_INVENTORY: list[dict[str, str]] = [
|
| 42 |
+
{"name": "a11oy", "slug": "a11oy", "title": "a11oy — Command Center", "sdk": "docker"},
|
| 43 |
+
{"name": "anatomy", "slug": "anatomy", "title": "SZL Living Anatomy", "sdk": "docker"},
|
| 44 |
+
{"name": "cosmos", "slug": "cosmos", "title": "SZL Cosmos", "sdk": "docker"},
|
| 45 |
+
{"name": "david-leads", "slug": "david-leads", "title": "David Leads — Sovereign Insurance Intelligence", "sdk": "docker"},
|
| 46 |
+
{"name": "energy-attest-holo", "slug": "energy-attest-holo", "title": "Energy Attestation Holo", "sdk": "static"},
|
| 47 |
+
{"name": "energy-attested-runs", "slug": "energy-attested-runs", "title": "Energy-Attested Inference Runs", "sdk": "gradio"},
|
| 48 |
+
{"name": "governed-norm-holo", "slug": "governed-norm-holo", "title": "Governed Norms — WILLAY classifiers", "sdk": "static"},
|
| 49 |
+
{"name": "governed-receipt-verifier", "slug": "governed-receipt-verifier", "title": "Governed Receipt Verifier", "sdk": "static"},
|
| 50 |
+
{"name": "guardrail-receipt", "slug": "guardrail-receipt", "title": "Guardrail Decision-Receipt", "sdk": "gradio"},
|
| 51 |
+
{"name": "hatun-mcp", "slug": "hatun-mcp", "title": "hatun — MCP Server", "sdk": "docker"},
|
| 52 |
+
{"name": "holographic", "slug": "holographic", "title": "Holographic Estate", "sdk": "docker"},
|
| 53 |
+
{"name": "immune", "slug": "immune", "title": "IMMUNE — Verifiable AI Defense Matrix", "sdk": "docker"},
|
| 54 |
+
{"name": "killinchu", "slug": "killinchu", "title": "killinchu — Andean Drone Intelligence", "sdk": "docker"},
|
| 55 |
+
{"name": "lambda-gate-holo", "slug": "lambda-gate-holo", "title": "Λ Gate — Conjecture 1, never green", "sdk": "static"},
|
| 56 |
+
{"name": "llm-router-live", "slug": "llm-router-live", "title": "SZL LLM Router", "sdk": "docker"},
|
| 57 |
+
{"name": "README", "slug": "readme", "title": "SZL Holdings — Governed-AI Command Platform", "sdk": "static"},
|
| 58 |
+
{"name": "receipt-chain-live", "slug": "receipt-chain-live", "title": "Receipt Chain Live", "sdk": "static"},
|
| 59 |
+
{"name": "sda", "slug": "sda", "title": "SZL SDA", "sdk": "docker"},
|
| 60 |
+
{"name": "szl-blocked-live", "slug": "szl-blocked-live", "title": "szl-blocked-live", "sdk": "static"},
|
| 61 |
+
{"name": "szl-estate-live", "slug": "szl-estate-live", "title": "Khipu Loom — Governed AI Estate", "sdk": "static"},
|
| 62 |
+
{"name": "szl-forge-lab", "slug": "szl-forge-lab", "title": "SZL Forge Lab", "sdk": "gradio"},
|
| 63 |
+
{"name": "szl-govsign-live", "slug": "szl-govsign-live", "title": "szl-govsign-live", "sdk": "static"},
|
| 64 |
+
{"name": "szl-kernels-live", "slug": "szl-kernels-live", "title": "SZL Kernel Operations Hub", "sdk": "static"},
|
| 65 |
+
{"name": "szl-model-inference-lab", "slug": "szl-model-inference-lab", "title": "SZL Model Inference Lab", "sdk": "docker"},
|
| 66 |
+
{"name": "szl-provctl-live", "slug": "szl-provctl-live", "title": "szl-provctl-live", "sdk": "static"},
|
| 67 |
+
{"name": "yarqa", "slug": "yarqa", "title": "yarqa — Plug-Flow Compartments (live or sample, always honest)", "sdk": "docker"},
|
| 68 |
]
|
| 69 |
+
_SPACE_BY_NAME = {sp["name"]: sp for sp in SPACE_INVENTORY}
|
| 70 |
+
_SPACE_BY_SLUG = {sp["slug"]: sp for sp in SPACE_INVENTORY}
|
| 71 |
+
|
| 72 |
+
ALL_SPACES = [sp["slug"] for sp in SPACE_INVENTORY]
|
| 73 |
+
HANDOFF_SPACES = list(ALL_SPACES)
|
| 74 |
+
# Backwards-compatible public name retained for downstream inventory checks.
|
| 75 |
+
PROXY_SPACES = HANDOFF_SPACES
|
| 76 |
+
|
| 77 |
+
_NO_STORE_HEADERS = {
|
| 78 |
+
"Cache-Control": "no-store",
|
| 79 |
+
"Referrer-Policy": "no-referrer",
|
| 80 |
+
"X-SZL-Space-Handoff": "canonical-origin",
|
| 81 |
+
}
|
| 82 |
|
| 83 |
|
| 84 |
+
def _space_record(identifier: str) -> dict[str, str]:
|
| 85 |
+
"""Resolve only audited inventory identifiers; fail closed otherwise."""
|
|
|
|
| 86 |
|
| 87 |
+
record = _SPACE_BY_NAME.get(identifier) or _SPACE_BY_SLUG.get(identifier)
|
| 88 |
+
if record is None:
|
| 89 |
+
raise ValueError("unknown Space identifier: %s" % identifier)
|
| 90 |
+
return record
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
+
def hf_url(name: str) -> str:
|
| 94 |
+
"""Return the canonical isolated application origin for an audited Space."""
|
|
|
|
|
|
|
| 95 |
|
| 96 |
+
record = _space_record(name)
|
| 97 |
+
suffix = ".static.hf.space" if record["sdk"] == "static" else ".hf.space"
|
| 98 |
+
return f"https://{_ORG_PREFIX}{record['slug']}{suffix}"
|
| 99 |
|
| 100 |
+
|
| 101 |
+
def hf_repo_url(name: str) -> str:
|
| 102 |
+
"""Return the canonical Hugging Face repository page for an audited Space."""
|
| 103 |
+
|
| 104 |
+
record = _space_record(name)
|
| 105 |
+
return f"https://huggingface.co/spaces/{_ORG}/{record['name']}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
|
| 108 |
def _fallback_index() -> bytes:
|
| 109 |
+
"""Render the dependency-free fallback registry with canonical links only."""
|
| 110 |
+
|
| 111 |
rows = []
|
| 112 |
+
for record in SPACE_INVENTORY:
|
| 113 |
+
title = html.escape(record["title"])
|
| 114 |
+
name = html.escape(record["name"])
|
| 115 |
+
sdk = html.escape(record["sdk"])
|
| 116 |
+
canonical = html.escape(hf_url(record["slug"]), quote=True)
|
| 117 |
+
repository = html.escape(hf_repo_url(record["slug"]), quote=True)
|
|
|
|
| 118 |
rows.append(
|
| 119 |
+
'<li style="margin:.4rem 0"><strong style="color:#e7eef6">%s</strong> '
|
| 120 |
+
'<small style="color:#697787">%s · %s</small> '
|
| 121 |
+
'· <a href="%s" rel="noopener" target="_blank" '
|
| 122 |
+
'style="color:#d4a444;text-decoration:none">Open canonical app ↗</a> '
|
| 123 |
+
'· <a href="%s" rel="noopener" target="_blank" '
|
| 124 |
+
'style="color:#7c8794;text-decoration:none">View repository ↗</a></li>'
|
| 125 |
+
% (title, name, sdk, canonical, repository)
|
| 126 |
)
|
| 127 |
return (
|
| 128 |
+
'<!doctype html><html lang="en"><head><meta charset="utf-8">'
|
| 129 |
+
'<meta name="viewport" content="width=device-width,initial-scale=1">'
|
| 130 |
+
'<title>Hugging Face Spaces</title>'
|
| 131 |
+
'<style>*{box-sizing:border-box}li{overflow-wrap:anywhere}'
|
| 132 |
+
'li a{display:inline-flex;align-items:center;min-height:44px;padding:.3rem .15rem}'
|
| 133 |
+
'@media(max-width:375px){body{padding:1rem!important}}</style></head>'
|
| 134 |
+
'<body style="margin:0;background:#0b0f14;color:#cdd6e0;'
|
| 135 |
+
'font:15px/1.6 system-ui,-apple-system,Segoe UI,Roboto,sans-serif;padding:2rem">'
|
| 136 |
+
'<main style="max-width:760px;margin:0 auto">'
|
| 137 |
+
'<h1 style="color:#e7eef6">Hugging Face Spaces</h1>'
|
| 138 |
+
'<p style="color:#8a96a3">All 26 audited Spaces open on their canonical isolated '
|
| 139 |
+
'Hugging Face origins. Legacy <code>/spaces/<slug></code> links are no-store '
|
| 140 |
+
'307 handoffs; no upstream response bytes or cookies cross this application.</p>'
|
| 141 |
+
'<ul style="list-style:none;padding:0">' + "".join(rows) + "</ul>"
|
| 142 |
"</main></body></html>"
|
| 143 |
).encode("utf-8")
|
| 144 |
|
| 145 |
|
| 146 |
+
def _canonical_target(name: str, subpath: str = "", query: str = "") -> str:
|
| 147 |
+
"""Build a fixed-origin redirect target without accepting an arbitrary host."""
|
| 148 |
+
|
| 149 |
+
record = _SPACE_BY_SLUG.get(name)
|
| 150 |
+
if record is None or name not in HANDOFF_SPACES:
|
| 151 |
+
raise ValueError("unknown Space identifier: %s" % name)
|
| 152 |
+
target = hf_url(name)
|
| 153 |
+
if subpath:
|
| 154 |
+
encoded_path = quote(subpath.lstrip("/"), safe="/:@!$&'()*+,;=-._~")
|
| 155 |
+
target += "/" + encoded_path
|
| 156 |
+
if query:
|
| 157 |
+
target += "?" + quote(query, safe="=&;%:+,/?@-._~")
|
| 158 |
+
return target
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
def _raw_query(request: Any) -> str | None:
|
| 162 |
+
raw = request.scope.get("query_string", b"")
|
| 163 |
try:
|
| 164 |
+
query = bytes(raw).decode("ascii")
|
| 165 |
+
except (UnicodeDecodeError, TypeError, ValueError):
|
|
|
|
| 166 |
return None
|
| 167 |
+
if "\r" in query or "\n" in query:
|
| 168 |
+
return None
|
| 169 |
+
return query
|
| 170 |
|
| 171 |
|
| 172 |
+
async def _proxy(name: str, subpath: str, request: Any) -> Any:
|
| 173 |
+
"""Legacy function name; perform a redirect-only canonical-origin handoff."""
|
| 174 |
+
|
| 175 |
+
from starlette.responses import RedirectResponse, Response
|
| 176 |
+
|
| 177 |
+
if name not in HANDOFF_SPACES:
|
| 178 |
+
return Response(
|
| 179 |
+
content=b"Unknown or non-handoff Space.\n",
|
| 180 |
+
status_code=404,
|
| 181 |
+
media_type="text/plain",
|
| 182 |
+
headers={"Cache-Control": "no-store"},
|
| 183 |
+
)
|
| 184 |
+
|
| 185 |
+
query = _raw_query(request)
|
| 186 |
+
if query is None:
|
| 187 |
+
return Response(
|
| 188 |
+
content=b"Invalid query string.\n",
|
| 189 |
+
status_code=400,
|
| 190 |
+
media_type="text/plain",
|
| 191 |
+
headers={"Cache-Control": "no-store"},
|
| 192 |
+
)
|
| 193 |
+
|
| 194 |
+
target = _canonical_target(name, subpath, query)
|
| 195 |
+
|
| 196 |
+
return RedirectResponse(target, status_code=307, headers=_NO_STORE_HEADERS)
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
def register(app: Any, ns: str = "a11oy") -> str:
|
| 200 |
+
"""Front-insert the fallback index and redirect-only compatibility routes."""
|
| 201 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
try:
|
| 203 |
from starlette.responses import Response
|
| 204 |
+
from starlette.routing import Route
|
| 205 |
+
except Exception as exc: # pragma: no cover
|
| 206 |
+
return "unavailable: %r" % (exc,)
|
| 207 |
|
| 208 |
n_before = len(app.router.routes)
|
| 209 |
|
| 210 |
+
async def _spaces_index(request: Any) -> Any:
|
| 211 |
+
headers = {"Cache-Control": "no-store"}
|
|
|
|
|
|
|
| 212 |
if request.method.upper() == "HEAD":
|
| 213 |
+
return Response(content=b"", status_code=200, media_type="text/html", headers=headers)
|
| 214 |
+
return Response(
|
| 215 |
+
content=_fallback_index(),
|
| 216 |
+
status_code=200,
|
| 217 |
+
media_type="text/html",
|
| 218 |
+
headers=headers,
|
| 219 |
+
)
|
| 220 |
|
| 221 |
+
async def _spaces_name(request: Any) -> Any:
|
| 222 |
+
return await _proxy(request.path_params.get("name", ""), "", request)
|
|
|
|
| 223 |
|
| 224 |
+
async def _spaces_path(request: Any) -> Any:
|
| 225 |
+
return await _proxy(
|
| 226 |
+
request.path_params.get("name", ""),
|
| 227 |
+
request.path_params.get("path", ""),
|
| 228 |
+
request,
|
| 229 |
+
)
|
| 230 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
routes = [
|
| 232 |
+
Route("/spaces", _spaces_index, methods=["GET", "HEAD"], name="spaces-fallback-index"),
|
| 233 |
+
Route("/spaces/{name}", _spaces_name, methods=["GET", "HEAD"], name="spaces-handoff-root"),
|
| 234 |
+
Route(
|
| 235 |
+
"/spaces/{name}/{path:path}",
|
| 236 |
+
_spaces_path,
|
| 237 |
+
methods=["GET", "HEAD"],
|
| 238 |
+
name="spaces-handoff-path",
|
| 239 |
+
),
|
| 240 |
]
|
| 241 |
+
app.router.routes.extend(routes)
|
|
|
|
|
|
|
| 242 |
new = app.router.routes[n_before:]
|
| 243 |
del app.router.routes[n_before:]
|
| 244 |
app.router.routes[0:0] = new
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
|
| 246 |
+
print(
|
| 247 |
+
"[%s] Spaces canonical-origin handoffs registered: /spaces + "
|
| 248 |
+
"/spaces/{name} + /spaces/{name}/{path} (%d audited handoffs; %d routes)"
|
| 249 |
+
% (ns, len(HANDOFF_SPACES), len(new)),
|
| 250 |
+
file=sys.stderr,
|
| 251 |
+
)
|
| 252 |
+
return "ok: %d canonical handoff spaces, %d routes" % (len(HANDOFF_SPACES), len(new))
|
| 253 |
|
|
|
|
|
|
|
|
|
|
| 254 |
|
| 255 |
+
if __name__ == "__main__":
|
| 256 |
+
import ast
|
| 257 |
+
from pathlib import Path
|
| 258 |
+
|
| 259 |
+
source = Path(__file__).read_text(encoding="utf-8")
|
| 260 |
+
ast.parse(source)
|
| 261 |
+
assert "urllib" + ".request" not in source
|
| 262 |
+
assert "client." + "request(" not in source
|
| 263 |
+
assert "upstream." + "content" not in source
|
| 264 |
+
|
| 265 |
+
assert len(ALL_SPACES) == len(HANDOFF_SPACES) == 26
|
| 266 |
+
assert hf_url("README") == "https://szlholdings-readme.static.hf.space"
|
| 267 |
+
assert hf_url("immune") == "https://szlholdings-immune.hf.space"
|
| 268 |
+
try:
|
| 269 |
+
hf_url("notreal")
|
| 270 |
+
raise AssertionError("unknown Space identifier must fail closed")
|
| 271 |
+
except ValueError:
|
| 272 |
+
pass
|
| 273 |
+
|
| 274 |
+
fallback = _fallback_index()
|
| 275 |
+
for space in SPACE_INVENTORY:
|
| 276 |
+
assert space["name"].encode() in fallback
|
| 277 |
+
assert space["title"].encode() in fallback
|
| 278 |
+
assert hf_url(space["slug"]).encode() in fallback
|
| 279 |
+
assert hf_repo_url(space["slug"]).encode() in fallback
|
| 280 |
+
assert b'href="/spaces/' not in fallback
|
| 281 |
+
assert b"reverse proxy" not in fallback.lower()
|
| 282 |
|
| 283 |
from starlette.applications import Starlette
|
| 284 |
from starlette.responses import PlainTextResponse
|
| 285 |
+
from starlette.routing import Route
|
| 286 |
from starlette.testclient import TestClient
|
| 287 |
|
| 288 |
+
app = Starlette(routes=[Route("/{full_path:path}", lambda req: PlainTextResponse("SPA"))])
|
| 289 |
+
status = register(app, ns="killinchu")
|
| 290 |
+
assert status.startswith("ok:")
|
| 291 |
+
client = TestClient(app)
|
| 292 |
+
|
| 293 |
+
root = client.get(
|
| 294 |
+
"/spaces/immune",
|
| 295 |
+
headers={"Cookie": "private=session", "Authorization": "Bearer private"},
|
| 296 |
+
follow_redirects=False,
|
| 297 |
+
)
|
| 298 |
+
assert root.status_code == 307
|
| 299 |
+
assert root.headers["location"] == "https://szlholdings-immune.hf.space"
|
| 300 |
+
assert root.headers["cache-control"] == "no-store"
|
| 301 |
+
assert root.headers["x-szl-space-handoff"] == "canonical-origin"
|
| 302 |
+
assert "set-cookie" not in root.headers and root.content == b""
|
| 303 |
+
|
| 304 |
+
nested = client.get(
|
| 305 |
+
"/spaces/immune/api/events?cursor=a%2Fb&cursor=two+words",
|
| 306 |
+
follow_redirects=False,
|
| 307 |
+
)
|
| 308 |
+
assert nested.status_code == 307
|
| 309 |
+
assert nested.headers["location"] == (
|
| 310 |
+
"https://szlholdings-immune.hf.space/api/events?cursor=a%2Fb&cursor=two+words"
|
| 311 |
+
)
|
| 312 |
+
head = client.head("/spaces/immune/assets/app.js?build=7", follow_redirects=False)
|
| 313 |
+
assert head.status_code == 307 and head.content == b""
|
| 314 |
+
assert head.headers["location"].endswith("/assets/app.js?build=7")
|
| 315 |
+
assert client.get("/spaces/notreal", follow_redirects=False).status_code == 404
|
| 316 |
+
own = client.get("/spaces/a11oy", follow_redirects=False)
|
| 317 |
+
assert own.status_code == 307
|
| 318 |
+
assert own.headers["location"] == "https://szlholdings-a11oy.hf.space"
|
| 319 |
+
|
| 320 |
+
print(
|
| 321 |
+
"szl_spaces_proxy: ALL OK (26 audited redirect-only handoffs; "
|
| 322 |
+
"path/query preserved; no-store; no upstream bytes/Set-Cookie)"
|
| 323 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
szl_spaces_surface.py
CHANGED
|
@@ -3,8 +3,8 @@
|
|
| 3 |
# © 2026 Lutar, Stephen P. — SZL Holdings · ORCID 0009-0001-0110-4173
|
| 4 |
"""szl_spaces_surface.py — console "Spaces" surface (health API + tiles + nav).
|
| 5 |
|
| 6 |
-
ADDITIVE, self-contained, SHARED
|
| 7 |
-
|
| 8 |
clean tiles page and ONE idempotent nav item, following the additive-injector pattern
|
| 9 |
(a11oy_nav_wireup.py / killinchu_nav_wireup.py).
|
| 10 |
|
|
@@ -12,20 +12,21 @@ ROUTES (additive, inserted at the FRONT of the router so they beat the SPA + Nod
|
|
| 12 |
catch-alls — same route-to-front idiom as a11oy_hf_assets.py):
|
| 13 |
|
| 14 |
GET /api/<ns>/v1/spaces/health -> for each Space, an HONEST status:
|
| 15 |
-
{name, title, stage, app_reachable, url, proxy_url}
|
| 16 |
- stage : runtime.stage from the HF API
|
| 17 |
(https://huggingface.co/api/spaces/SZLHOLDINGS/<name>),
|
| 18 |
or "unknown" if that API call degrades. LABELLED as HF-API.
|
| 19 |
-
- app_reachable : a REAL
|
| 20 |
https://szlholdings-<name>.hf.space/ (HEAD, short timeout).
|
| 21 |
true ONLY when the probe really succeeded. Never fabricated.
|
| 22 |
Degrade -> stage:"unknown", app_reachable:false. NEVER a faked stage/200.
|
| 23 |
|
| 24 |
GET/HEAD /spaces -> a clean tiles page (one card per Space: honest
|
| 25 |
-
title, live status dot fed by /health,
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
CDN
|
|
|
|
| 29 |
|
| 30 |
NAV: a BaseHTTPMiddleware injector adds ONE nav item "Spaces" -> /spaces into the
|
| 31 |
console left-nav (before <div class="side-foot">, with nav-group / nav-item fallbacks).
|
|
@@ -54,25 +55,46 @@ from typing import Any
|
|
| 54 |
|
| 55 |
_ORG = "SZLHOLDINGS"
|
| 56 |
_ORG_PREFIX = "szlholdings-"
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
#
|
| 60 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
SPACES: list[dict[str, str]] = [
|
| 62 |
-
{"name": "
|
| 63 |
-
{"name": "
|
| 64 |
-
{"name": "
|
| 65 |
-
{"name": "
|
| 66 |
-
{"name": "energy",
|
| 67 |
-
{"name": "
|
| 68 |
-
{"name": "
|
| 69 |
-
{"name": "
|
| 70 |
-
{"name": "
|
| 71 |
-
{"name": "
|
| 72 |
-
{"name": "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
]
|
| 74 |
-
|
| 75 |
-
|
|
|
|
| 76 |
_OWN_HOST = {"a11oy", "killinchu"}
|
| 77 |
|
| 78 |
_DOCTRINE = {
|
|
@@ -85,22 +107,47 @@ _DOCTRINE = {
|
|
| 85 |
|
| 86 |
_PROBE_TIMEOUT = 6.0
|
| 87 |
_HF_API_TIMEOUT = 6.0
|
| 88 |
-
_HEALTH_CACHE_TTL = 20.0 # seconds — keep the tiles page snappy without re-probing
|
| 89 |
_HEALTH_CACHE: dict[str, Any] = {"ts": 0.0, "payload": None}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
|
| 92 |
def hf_url(name: str) -> str:
|
| 93 |
-
|
|
|
|
|
|
|
| 94 |
|
| 95 |
|
| 96 |
def hf_api_url(name: str) -> str:
|
| 97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
|
| 100 |
def proxy_url(name: str) -> str:
|
| 101 |
-
"""
|
| 102 |
-
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
|
| 106 |
def _resolve_client() -> Any:
|
|
@@ -143,17 +190,21 @@ async def _probe_one(client: Any, sp: dict[str, str]) -> dict[str, Any]:
|
|
| 143 |
"""HONEST per-Space status. app_reachable is a REAL HEAD probe; stage is from the
|
| 144 |
HF API. Any failure degrades to honest false/'unknown' — never fabricated."""
|
| 145 |
name = sp["name"]
|
|
|
|
| 146 |
result: dict[str, Any] = {
|
| 147 |
"name": name,
|
|
|
|
| 148 |
"title": sp["title"],
|
|
|
|
| 149 |
"url": hf_url(name),
|
|
|
|
| 150 |
"proxy_url": proxy_url(name),
|
| 151 |
-
"own_host":
|
| 152 |
"stage": "unknown", # from HF API; HF-API-labelled below
|
| 153 |
"stage_source": "hf-api",
|
| 154 |
"app_reachable": False, # REAL probe; only true when the probe truly succeeds
|
| 155 |
}
|
| 156 |
-
# (1) REAL
|
| 157 |
# client first; on None/failure fall back to the PROVEN stdlib urllib path.
|
| 158 |
probed = False
|
| 159 |
if client is not None:
|
|
@@ -214,14 +265,45 @@ async def _probe_one(client: Any, sp: dict[str, str]) -> dict[str, Any]:
|
|
| 214 |
except Exception as e:
|
| 215 |
result["stage_error"] = type(e).__name__
|
| 216 |
|
|
|
|
| 217 |
return result
|
| 218 |
|
| 219 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
async def spaces_health() -> dict[str, Any]:
|
| 221 |
-
"""Aggregate honest health for
|
| 222 |
now = time.monotonic()
|
| 223 |
if _HEALTH_CACHE["payload"] is not None and (now - _HEALTH_CACHE["ts"]) < _HEALTH_CACHE_TTL:
|
| 224 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
|
| 226 |
client = _resolve_client()
|
| 227 |
# Probe every Space concurrently. _probe_one handles client=None internally by
|
|
@@ -231,14 +313,17 @@ async def spaces_health() -> dict[str, Any]:
|
|
| 231 |
spaces = list(await _asyncio.gather(*[_probe_one(client, sp) for sp in SPACES]))
|
| 232 |
|
| 233 |
payload = {
|
|
|
|
| 234 |
"count": len(spaces),
|
| 235 |
"spaces": spaces,
|
| 236 |
"labels": {
|
|
|
|
|
|
|
| 237 |
"stage": "HF API runtime.stage (https://huggingface.co/api/spaces/SZLHOLDINGS/<name>)",
|
| 238 |
-
"app_reachable": "REAL
|
| 239 |
"degrade": "stage:'unknown' + app_reachable:false; never fabricated",
|
| 240 |
},
|
| 241 |
-
"note": "Server-side probed; 0 browser CDN. Honest
|
| 242 |
"doctrine": _DOCTRINE,
|
| 243 |
"fetchedAt": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()),
|
| 244 |
}
|
|
@@ -256,52 +341,71 @@ def _tiles_page(ns: str) -> bytes:
|
|
| 256 |
cards = []
|
| 257 |
for sp in SPACES:
|
| 258 |
name = sp["name"]
|
|
|
|
| 259 |
title = sp["title"]
|
| 260 |
-
primary =
|
| 261 |
-
primary_label = "Open
|
| 262 |
cards.append(
|
| 263 |
'<article class="sp-card" data-space="%s">'
|
| 264 |
'<header class="sp-head">'
|
| 265 |
'<span class="sp-dot" data-dot="%s" title="status">●</span>'
|
| 266 |
'<h2 class="sp-title">%s</h2></header>'
|
|
|
|
| 267 |
'<div class="sp-stage" data-stage="%s">stage: <span>checking…</span></div>'
|
| 268 |
'<div class="sp-links">'
|
| 269 |
-
'<a class="sp-open" href="%s">%s</a>'
|
| 270 |
-
'<a class="sp-hf" href="%s" rel="noopener" target="_blank">
|
| 271 |
'</div></article>'
|
| 272 |
-
% (
|
|
|
|
| 273 |
)
|
| 274 |
html = (
|
| 275 |
'<!doctype html><html lang="en"><head><meta charset="utf-8">'
|
| 276 |
'<meta name="viewport" content="width=device-width,initial-scale=1">'
|
| 277 |
-
'<title>Spaces ·
|
| 278 |
'<style>'
|
| 279 |
':root{color-scheme:dark}'
|
| 280 |
'*{box-sizing:border-box}'
|
| 281 |
'body{margin:0;background:#0b0f14;color:#cdd6e0;'
|
| 282 |
'font:15px/1.6 system-ui,-apple-system,Segoe UI,Roboto,sans-serif}'
|
| 283 |
-
'.sp-wrap{max-width:1100px;margin:0 auto;padding:2rem 1.25rem}'
|
| 284 |
'.sp-h1{color:#e7eef6;font-size:1.6rem;margin:0 0 .25rem}'
|
| 285 |
-
'.sp-sub{color:#8a96a3;margin:0 0
|
| 286 |
-
'.sp-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
'grid-template-columns:repeat(auto-fill,minmax(260px,1fr))}'
|
| 288 |
'.sp-card{background:#121821;border:1px solid #1d2632;border-radius:12px;'
|
| 289 |
-
'padding:1rem 1.1rem;display:flex;flex-direction:column;gap:.5rem}'
|
| 290 |
-
'.sp-head{display:flex;align-items:center;gap:.55rem}'
|
| 291 |
'.sp-dot{color:#5b6675;font-size:.7rem;line-height:1}'
|
| 292 |
'.sp-dot.up{color:#3ad07a}.sp-dot.down{color:#e0593a}.sp-dot.unknown{color:#c9a23a}'
|
| 293 |
-
'.sp-title{font-size:1rem;margin:0;color:#e7eef6;font-weight:600}'
|
| 294 |
-
'.sp-
|
|
|
|
| 295 |
'.sp-stage span{color:#9fb0c0}'
|
| 296 |
'.sp-links{margin-top:auto;display:flex;gap:.9rem;flex-wrap:wrap;padding-top:.4rem}'
|
|
|
|
| 297 |
'.sp-open{color:#d4a444;text-decoration:none;font-weight:600}'
|
| 298 |
'.sp-hf{color:#7c8794;text-decoration:none}'
|
| 299 |
-
'.sp-foot{color:#5b6675;font-size:.8rem;margin-top:1.6rem}'
|
|
|
|
|
|
|
|
|
|
| 300 |
'</style></head>'
|
| 301 |
'<body><main class="sp-wrap">'
|
| 302 |
'<h1 class="sp-h1">Hugging Face Spaces</h1>'
|
| 303 |
-
'<p class="sp-sub">All
|
| 304 |
-
'
|
|
|
|
|
|
|
|
|
|
| 305 |
'<div class="sp-grid">' + "".join(cards) + '</div>'
|
| 306 |
'<p class="sp-foot">Status dot & stage are filled from the same-origin '
|
| 307 |
'<code>/api/' + ns + '/v1/spaces/health</code> endpoint (real server-side probe '
|
|
@@ -309,16 +413,33 @@ def _tiles_page(ns: str) -> bytes:
|
|
| 309 |
'</main>'
|
| 310 |
'<script>'
|
| 311 |
'(function(){'
|
| 312 |
-
'
|
| 313 |
-
'
|
| 314 |
-
'var
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
'var dot=card.querySelector(".sp-dot");'
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
'if(dot){dot.classList.remove("up","down","unknown");'
|
| 317 |
-
'dot.classList.add(
|
| 318 |
-
'dot.title=(s.app_reachable?"reachable":"unreachable")+" / stage:"+(s.stage||"unknown");}'
|
| 319 |
'var st=card.querySelector(".sp-stage span");'
|
| 320 |
-
'if(st){st.textContent=
|
| 321 |
-
'
|
|
|
|
| 322 |
'})();'
|
| 323 |
'</script>'
|
| 324 |
'</body></html>'
|
|
@@ -340,9 +461,9 @@ def _nav_item() -> bytes:
|
|
| 340 |
"""ONE 'Spaces' nav item, mirroring the console's own nav-item markup so it inherits
|
| 341 |
the console styling (0 CDN, 0 codename). Globe glyph; honest label."""
|
| 342 |
return (
|
| 343 |
-
'<
|
| 344 |
-
'
|
| 345 |
-
'<span class="ico">\U0001F310</span>Spaces</
|
| 346 |
).encode("utf-8")
|
| 347 |
|
| 348 |
|
|
@@ -404,7 +525,6 @@ def register(app, ns: str = "a11oy") -> str:
|
|
| 404 |
at the FRONT of the router (beat the SPA + Node-proxy catch-alls), and attach the
|
| 405 |
idempotent 'Spaces' nav injector. try/except-guarded by the caller."""
|
| 406 |
try:
|
| 407 |
-
from fastapi.responses import JSONResponse # noqa: F401
|
| 408 |
from starlette.responses import Response, JSONResponse as _JSON
|
| 409 |
except Exception as e: # pragma: no cover
|
| 410 |
return "unavailable: %r" % (e,)
|
|
@@ -414,12 +534,13 @@ def register(app, ns: str = "a11oy") -> str:
|
|
| 414 |
|
| 415 |
async def _health(request):
|
| 416 |
payload = await spaces_health()
|
| 417 |
-
return _JSON(payload)
|
| 418 |
|
| 419 |
async def _tiles(request):
|
|
|
|
| 420 |
if request.method.upper() == "HEAD":
|
| 421 |
-
return Response(content=b"", status_code=200, media_type="text/html")
|
| 422 |
-
return Response(content=tiles, status_code=200, media_type="text/html")
|
| 423 |
|
| 424 |
from starlette.routing import Route
|
| 425 |
routes = [
|
|
@@ -446,7 +567,7 @@ def register(app, ns: str = "a11oy") -> str:
|
|
| 446 |
# ---------------------------------------------------------------------------
|
| 447 |
# Self-test — pure stdlib + starlette TestClient; no real network. Stubs the shared
|
| 448 |
# client to assert: health degrades honestly (no client -> stage unknown + reachable
|
| 449 |
-
# false), tiles page lists ALL
|
| 450 |
# once + is idempotent + removes nothing, /spaces is NOT nav-injected.
|
| 451 |
# ---------------------------------------------------------------------------
|
| 452 |
if __name__ == "__main__":
|
|
@@ -454,15 +575,33 @@ if __name__ == "__main__":
|
|
| 454 |
with open(__file__, "r", encoding="utf-8") as _fh:
|
| 455 |
_ast.parse(_fh.read())
|
| 456 |
|
| 457 |
-
assert len(SPACES) ==
|
| 458 |
tp = _tiles_page("a11oy")
|
| 459 |
for sp in SPACES:
|
| 460 |
assert sp["name"].encode() in tp, "tiles missing %s" % sp["name"]
|
| 461 |
assert sp["title"].encode() in tp, "tiles missing title %s" % sp["title"]
|
|
|
|
|
|
|
|
|
|
| 462 |
assert b"/api/a11oy/v1/spaces/health" in tp, "tiles must fetch the health endpoint"
|
| 463 |
assert b"http://" not in tp, "tiles must be 0 CDN (no http://)"
|
| 464 |
-
|
| 465 |
-
assert
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 466 |
|
| 467 |
from starlette.applications import Starlette
|
| 468 |
from starlette.responses import HTMLResponse, PlainTextResponse
|
|
@@ -489,23 +628,36 @@ if __name__ == "__main__":
|
|
| 489 |
assert st.startswith("ok:"), st
|
| 490 |
c = TestClient(app)
|
| 491 |
|
| 492 |
-
# health: no httpx client wired -> falls back to the stdlib urllib probe
|
| 493 |
-
# outbound path
|
| 494 |
-
#
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 498 |
for s in h["spaces"]:
|
| 499 |
-
assert
|
| 500 |
-
assert
|
| 501 |
-
|
| 502 |
-
if not s["app_reachable"] and s["stage"] == "unknown":
|
| 503 |
-
pass # honest degrade -- allowed
|
| 504 |
assert h["doctrine"]["locked_proven"] == ["F1", "F4", "F7", "F11", "F12", "F18", "F19", "F22"]
|
| 505 |
|
| 506 |
# tiles page resolves + lists all names
|
| 507 |
t = c.get("/spaces")
|
| 508 |
assert t.status_code == 200 and "text/html" in t.headers["content-type"], t.status_code
|
|
|
|
| 509 |
for sp in SPACES:
|
| 510 |
assert sp["name"] in t.text, "tiles page missing %s" % sp["name"]
|
| 511 |
|
|
@@ -514,12 +666,12 @@ if __name__ == "__main__":
|
|
| 514 |
p2 = c.get("/console").text
|
| 515 |
assert p1.count('data-nav-spaces="hf1"') == 1, "nav must inject exactly once"
|
| 516 |
assert p2.count('data-nav-spaces="hf1"') == 1, "nav must be idempotent"
|
| 517 |
-
assert
|
| 518 |
assert "Operate</div>" in p1 and "Existing</div>" in p1 and "footer</div>" in p1, \
|
| 519 |
"must remove nothing from the SPA source"
|
| 520 |
assert p1 == p2, "second console render must be byte-identical (idempotent)"
|
| 521 |
# the tiles page itself must NOT be nav-injected (it has no console sidebar)
|
| 522 |
assert 'data-nav-spaces="hf1"' not in c.get("/spaces").text, "/spaces must not be nav-injected"
|
| 523 |
|
| 524 |
-
print("szl_spaces_surface: ALL OK (
|
| 525 |
-
"idempotent + additive; /spaces not self-injected)")
|
|
|
|
| 3 |
# © 2026 Lutar, Stephen P. — SZL Holdings · ORCID 0009-0001-0110-4173
|
| 4 |
"""szl_spaces_surface.py — console "Spaces" surface (health API + tiles + nav).
|
| 5 |
|
| 6 |
+
ADDITIVE, self-contained, SHARED across a11oy + killinchu. The console companion to
|
| 7 |
+
the canonical handoff module: a LIVE health view of the whole HF Spaces estate plus a
|
| 8 |
clean tiles page and ONE idempotent nav item, following the additive-injector pattern
|
| 9 |
(a11oy_nav_wireup.py / killinchu_nav_wireup.py).
|
| 10 |
|
|
|
|
| 12 |
catch-alls — same route-to-front idiom as a11oy_hf_assets.py):
|
| 13 |
|
| 14 |
GET /api/<ns>/v1/spaces/health -> for each Space, an HONEST status:
|
| 15 |
+
{name, slug, title, sdk, stage, app_reachable, url, canonical_url, proxy_url}
|
| 16 |
- stage : runtime.stage from the HF API
|
| 17 |
(https://huggingface.co/api/spaces/SZLHOLDINGS/<name>),
|
| 18 |
or "unknown" if that API call degrades. LABELLED as HF-API.
|
| 19 |
+
- app_reachable : a REAL server-side probe of
|
| 20 |
https://szlholdings-<name>.hf.space/ (HEAD, short timeout).
|
| 21 |
true ONLY when the probe really succeeded. Never fabricated.
|
| 22 |
Degrade -> stage:"unknown", app_reachable:false. NEVER a faked stage/200.
|
| 23 |
|
| 24 |
GET/HEAD /spaces -> a clean tiles page (one card per Space: honest
|
| 25 |
+
title, live status dot fed by /health, canonical isolated hf.space app link,
|
| 26 |
+
and a separate huggingface.co repository link).
|
| 27 |
+
No upstream app executes inside the a11oy or Killinchu origin. Pure inline
|
| 28 |
+
markup, 0 browser CDN. Status dots are filled by a tiny inline fetch of the
|
| 29 |
+
SAME-ORIGIN /health JSON (our own server-side-probed endpoint).
|
| 30 |
|
| 31 |
NAV: a BaseHTTPMiddleware injector adds ONE nav item "Spaces" -> /spaces into the
|
| 32 |
console left-nav (before <div class="side-foot">, with nav-group / nav-item fallbacks).
|
|
|
|
| 55 |
|
| 56 |
_ORG = "SZLHOLDINGS"
|
| 57 |
_ORG_PREFIX = "szlholdings-"
|
| 58 |
+
SPACE_TILE_ORIGIN_MODE = "canonical-isolated-hf/v1"
|
| 59 |
+
|
| 60 |
+
# Audited 26-Space public estate. Names are exact Hub repository names and titles are
|
| 61 |
+
# the current public card titles observed during the 2026-07-16 alignment audit. Runtime
|
| 62 |
+
# state is deliberately NOT frozen here: /health measures it on every cache refresh and
|
| 63 |
+
# degrades to unknown/false when evidence is unavailable. ``slug`` is the lowercase,
|
| 64 |
+
# same-origin route key; it differs from ``name`` only for the Hub repository ``README``.
|
| 65 |
+
# a11oy + killinchu retain the historical own-host classification in the health payload,
|
| 66 |
+
# but every tile now opens its canonical isolated Hugging Face application origin.
|
| 67 |
SPACES: list[dict[str, str]] = [
|
| 68 |
+
{"name": "a11oy", "slug": "a11oy", "title": "a11oy — Command Center", "sdk": "docker"},
|
| 69 |
+
{"name": "anatomy", "slug": "anatomy", "title": "SZL Living Anatomy", "sdk": "docker"},
|
| 70 |
+
{"name": "cosmos", "slug": "cosmos", "title": "SZL Cosmos", "sdk": "docker"},
|
| 71 |
+
{"name": "david-leads", "slug": "david-leads", "title": "David Leads — Sovereign Insurance Intelligence", "sdk": "docker"},
|
| 72 |
+
{"name": "energy-attest-holo", "slug": "energy-attest-holo", "title": "Energy Attestation Holo", "sdk": "static"},
|
| 73 |
+
{"name": "energy-attested-runs", "slug": "energy-attested-runs", "title": "Energy-Attested Inference Runs", "sdk": "gradio"},
|
| 74 |
+
{"name": "governed-norm-holo", "slug": "governed-norm-holo", "title": "Governed Norms — WILLAY classifiers", "sdk": "static"},
|
| 75 |
+
{"name": "governed-receipt-verifier", "slug": "governed-receipt-verifier", "title": "Governed Receipt Verifier", "sdk": "static"},
|
| 76 |
+
{"name": "guardrail-receipt", "slug": "guardrail-receipt", "title": "Guardrail Decision-Receipt", "sdk": "gradio"},
|
| 77 |
+
{"name": "hatun-mcp", "slug": "hatun-mcp", "title": "hatun — MCP Server", "sdk": "docker"},
|
| 78 |
+
{"name": "holographic", "slug": "holographic", "title": "Holographic Estate", "sdk": "docker"},
|
| 79 |
+
{"name": "immune", "slug": "immune", "title": "IMMUNE — Verifiable AI Defense Matrix", "sdk": "docker"},
|
| 80 |
+
{"name": "killinchu", "slug": "killinchu", "title": "killinchu — Andean Drone Intelligence", "sdk": "docker"},
|
| 81 |
+
{"name": "lambda-gate-holo", "slug": "lambda-gate-holo", "title": "Λ Gate — Conjecture 1, never green", "sdk": "static"},
|
| 82 |
+
{"name": "llm-router-live", "slug": "llm-router-live", "title": "SZL LLM Router", "sdk": "docker"},
|
| 83 |
+
{"name": "README", "slug": "readme", "title": "SZL Holdings — Governed-AI Command Platform", "sdk": "static"},
|
| 84 |
+
{"name": "receipt-chain-live", "slug": "receipt-chain-live", "title": "Receipt Chain Live", "sdk": "static"},
|
| 85 |
+
{"name": "sda", "slug": "sda", "title": "SZL SDA", "sdk": "docker"},
|
| 86 |
+
{"name": "szl-blocked-live", "slug": "szl-blocked-live", "title": "szl-blocked-live", "sdk": "static"},
|
| 87 |
+
{"name": "szl-estate-live", "slug": "szl-estate-live", "title": "Khipu Loom — Governed AI Estate", "sdk": "static"},
|
| 88 |
+
{"name": "szl-forge-lab", "slug": "szl-forge-lab", "title": "SZL Forge Lab", "sdk": "gradio"},
|
| 89 |
+
{"name": "szl-govsign-live", "slug": "szl-govsign-live", "title": "szl-govsign-live", "sdk": "static"},
|
| 90 |
+
{"name": "szl-kernels-live", "slug": "szl-kernels-live", "title": "SZL Kernel Operations Hub", "sdk": "static"},
|
| 91 |
+
{"name": "szl-model-inference-lab", "slug": "szl-model-inference-lab", "title": "SZL Model Inference Lab", "sdk": "docker"},
|
| 92 |
+
{"name": "szl-provctl-live", "slug": "szl-provctl-live", "title": "szl-provctl-live", "sdk": "static"},
|
| 93 |
+
{"name": "yarqa", "slug": "yarqa", "title": "yarqa — Plug-Flow Compartments (live or sample, always honest)", "sdk": "docker"},
|
| 94 |
]
|
| 95 |
+
_SPACE_BY_NAME = {sp["name"]: sp for sp in SPACES}
|
| 96 |
+
_SPACE_BY_SLUG = {sp["slug"]: sp for sp in SPACES}
|
| 97 |
+
# Product Spaces retained as metadata for consumers that distinguish flagship hosts.
|
| 98 |
_OWN_HOST = {"a11oy", "killinchu"}
|
| 99 |
|
| 100 |
_DOCTRINE = {
|
|
|
|
| 107 |
|
| 108 |
_PROBE_TIMEOUT = 6.0
|
| 109 |
_HF_API_TIMEOUT = 6.0
|
| 110 |
+
_HEALTH_CACHE_TTL = 20.0 # seconds — keep the tiles page snappy without re-probing 26x.
|
| 111 |
_HEALTH_CACHE: dict[str, Any] = {"ts": 0.0, "payload": None}
|
| 112 |
+
_RUNNING_STAGES = {"RUNNING"}
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
def _space_record(identifier: str) -> dict[str, str]:
|
| 116 |
+
"""Resolve only audited inventory identifiers; fail closed for unknown names."""
|
| 117 |
+
record = _SPACE_BY_NAME.get(identifier) or _SPACE_BY_SLUG.get(identifier)
|
| 118 |
+
if record is None:
|
| 119 |
+
raise ValueError("unknown Space identifier: %s" % identifier)
|
| 120 |
+
return record
|
| 121 |
|
| 122 |
|
| 123 |
def hf_url(name: str) -> str:
|
| 124 |
+
record = _space_record(name)
|
| 125 |
+
host_suffix = ".static.hf.space" if record["sdk"] == "static" else ".hf.space"
|
| 126 |
+
return f"https://{_ORG_PREFIX}{record['slug']}{host_suffix}"
|
| 127 |
|
| 128 |
|
| 129 |
def hf_api_url(name: str) -> str:
|
| 130 |
+
record = _space_record(name)
|
| 131 |
+
return f"https://huggingface.co/api/spaces/{_ORG}/{record['name']}"
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def hf_repo_url(name: str) -> str:
|
| 135 |
+
record = _space_record(name)
|
| 136 |
+
return f"https://huggingface.co/spaces/{_ORG}/{record['name']}"
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def canonical_url(name: str) -> str:
|
| 140 |
+
"""Canonical isolated application origin for an audited Space."""
|
| 141 |
+
return hf_url(name)
|
| 142 |
|
| 143 |
|
| 144 |
def proxy_url(name: str) -> str:
|
| 145 |
+
"""Deprecated compatibility alias for ``canonical_url``.
|
| 146 |
+
|
| 147 |
+
No upstream Space executes under the host application's origin; interactive
|
| 148 |
+
apps, streaming, cookies, and authentication stay isolated on Hugging Face.
|
| 149 |
+
"""
|
| 150 |
+
return canonical_url(name)
|
| 151 |
|
| 152 |
|
| 153 |
def _resolve_client() -> Any:
|
|
|
|
| 190 |
"""HONEST per-Space status. app_reachable is a REAL HEAD probe; stage is from the
|
| 191 |
HF API. Any failure degrades to honest false/'unknown' — never fabricated."""
|
| 192 |
name = sp["name"]
|
| 193 |
+
slug = sp["slug"]
|
| 194 |
result: dict[str, Any] = {
|
| 195 |
"name": name,
|
| 196 |
+
"slug": slug,
|
| 197 |
"title": sp["title"],
|
| 198 |
+
"sdk": sp["sdk"],
|
| 199 |
"url": hf_url(name),
|
| 200 |
+
"canonical_url": canonical_url(name),
|
| 201 |
"proxy_url": proxy_url(name),
|
| 202 |
+
"own_host": slug in _OWN_HOST,
|
| 203 |
"stage": "unknown", # from HF API; HF-API-labelled below
|
| 204 |
"stage_source": "hf-api",
|
| 205 |
"app_reachable": False, # REAL probe; only true when the probe truly succeeds
|
| 206 |
}
|
| 207 |
+
# (1) REAL liveness probe of the canonical Space app. Try the shared async httpx
|
| 208 |
# client first; on None/failure fall back to the PROVEN stdlib urllib path.
|
| 209 |
probed = False
|
| 210 |
if client is not None:
|
|
|
|
| 265 |
except Exception as e:
|
| 266 |
result["stage_error"] = type(e).__name__
|
| 267 |
|
| 268 |
+
result["state"] = _space_health_state(result)
|
| 269 |
return result
|
| 270 |
|
| 271 |
|
| 272 |
+
def _space_health_state(space: dict[str, Any]) -> str:
|
| 273 |
+
"""Derive one conservative, user-facing state from observed row evidence."""
|
| 274 |
+
reachable = bool(space.get("app_reachable"))
|
| 275 |
+
stage = str(space.get("stage") or "unknown").upper()
|
| 276 |
+
if reachable and stage in _RUNNING_STAGES:
|
| 277 |
+
return "LIVE"
|
| 278 |
+
if not reachable and stage == "UNKNOWN":
|
| 279 |
+
return "UNAVAILABLE"
|
| 280 |
+
return "DEGRADED"
|
| 281 |
+
|
| 282 |
+
|
| 283 |
+
def _aggregate_health_state(spaces: list[dict[str, Any]]) -> str:
|
| 284 |
+
"""Derive a conservative top-level state from the observed Space rows."""
|
| 285 |
+
if not spaces:
|
| 286 |
+
return "UNAVAILABLE"
|
| 287 |
+
states = [_space_health_state(row) for row in spaces]
|
| 288 |
+
if all(state == "LIVE" for state in states):
|
| 289 |
+
return "LIVE"
|
| 290 |
+
if all(state == "UNAVAILABLE" for state in states):
|
| 291 |
+
return "UNAVAILABLE"
|
| 292 |
+
return "DEGRADED"
|
| 293 |
+
|
| 294 |
+
|
| 295 |
async def spaces_health() -> dict[str, Any]:
|
| 296 |
+
"""Aggregate honest health for the audited 26-Space estate (short TTL cache)."""
|
| 297 |
now = time.monotonic()
|
| 298 |
if _HEALTH_CACHE["payload"] is not None and (now - _HEALTH_CACHE["ts"]) < _HEALTH_CACHE_TTL:
|
| 299 |
+
cached = _HEALTH_CACHE["payload"]
|
| 300 |
+
# Return a new top-level mapping: label the transport as CACHED while
|
| 301 |
+
# preserving the original aggregate verdict for auditability.
|
| 302 |
+
return {
|
| 303 |
+
**cached,
|
| 304 |
+
"state": "CACHED",
|
| 305 |
+
"cached_state": cached.get("state", "UNAVAILABLE"),
|
| 306 |
+
}
|
| 307 |
|
| 308 |
client = _resolve_client()
|
| 309 |
# Probe every Space concurrently. _probe_one handles client=None internally by
|
|
|
|
| 313 |
spaces = list(await _asyncio.gather(*[_probe_one(client, sp) for sp in SPACES]))
|
| 314 |
|
| 315 |
payload = {
|
| 316 |
+
"state": _aggregate_health_state(spaces),
|
| 317 |
"count": len(spaces),
|
| 318 |
"spaces": spaces,
|
| 319 |
"labels": {
|
| 320 |
+
"state": "Fresh: LIVE only when every app is reachable and HF reports RUNNING; otherwise DEGRADED or UNAVAILABLE. TTL reuse is CACHED with cached_state.",
|
| 321 |
+
"space_state": "LIVE requires app_reachable:true plus HF stage RUNNING; partial evidence is DEGRADED",
|
| 322 |
"stage": "HF API runtime.stage (https://huggingface.co/api/spaces/SZLHOLDINGS/<name>)",
|
| 323 |
+
"app_reachable": "REAL server-side HEAD/GET probe of the canonical Space app",
|
| 324 |
"degrade": "stage:'unknown' + app_reachable:false; never fabricated",
|
| 325 |
},
|
| 326 |
+
"note": "Server-side probed; 0 browser CDN. Honest LIVE/DEGRADED/UNAVAILABLE; cache reuse is explicitly CACHED.",
|
| 327 |
"doctrine": _DOCTRINE,
|
| 328 |
"fetchedAt": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()),
|
| 329 |
}
|
|
|
|
| 341 |
cards = []
|
| 342 |
for sp in SPACES:
|
| 343 |
name = sp["name"]
|
| 344 |
+
slug = sp["slug"]
|
| 345 |
title = sp["title"]
|
| 346 |
+
primary = canonical_url(name)
|
| 347 |
+
primary_label = "Open isolated app"
|
| 348 |
cards.append(
|
| 349 |
'<article class="sp-card" data-space="%s">'
|
| 350 |
'<header class="sp-head">'
|
| 351 |
'<span class="sp-dot" data-dot="%s" title="status">●</span>'
|
| 352 |
'<h2 class="sp-title">%s</h2></header>'
|
| 353 |
+
'<div class="sp-kind">%s · %s</div>'
|
| 354 |
'<div class="sp-stage" data-stage="%s">stage: <span>checking…</span></div>'
|
| 355 |
'<div class="sp-links">'
|
| 356 |
+
'<a class="sp-open" href="%s" rel="noopener" target="_blank">%s ↗</a>'
|
| 357 |
+
'<a class="sp-hf" href="%s" rel="noopener" target="_blank">View repository ↗</a>'
|
| 358 |
'</div></article>'
|
| 359 |
+
% (slug, slug, title, name, sp["sdk"], slug,
|
| 360 |
+
primary, primary_label, hf_repo_url(name))
|
| 361 |
)
|
| 362 |
html = (
|
| 363 |
'<!doctype html><html lang="en"><head><meta charset="utf-8">'
|
| 364 |
'<meta name="viewport" content="width=device-width,initial-scale=1">'
|
| 365 |
+
'<title>Spaces · ' + ns + '</title>'
|
| 366 |
'<style>'
|
| 367 |
':root{color-scheme:dark}'
|
| 368 |
'*{box-sizing:border-box}'
|
| 369 |
'body{margin:0;background:#0b0f14;color:#cdd6e0;'
|
| 370 |
'font:15px/1.6 system-ui,-apple-system,Segoe UI,Roboto,sans-serif}'
|
| 371 |
+
'.sp-wrap{max-width:1100px;margin:0 auto;padding:2rem 1.25rem;min-width:0}'
|
| 372 |
'.sp-h1{color:#e7eef6;font-size:1.6rem;margin:0 0 .25rem}'
|
| 373 |
+
'.sp-sub{color:#8a96a3;margin:0 0 .75rem;overflow-wrap:anywhere}'
|
| 374 |
+
'.sp-health{display:flex;align-items:center;gap:.45rem;min-height:44px;'
|
| 375 |
+
'color:#8a96a3;margin:0 0 1rem}'
|
| 376 |
+
'.sp-health strong{border:1px solid #3b4654;border-radius:999px;padding:.22rem .55rem;'
|
| 377 |
+
'color:#9fb0c0;font-size:.76rem;letter-spacing:.04em}'
|
| 378 |
+
'.sp-health strong.live{border-color:#3ad07a;color:#3ad07a}'
|
| 379 |
+
'.sp-health strong.degraded{border-color:#c9a23a;color:#c9a23a}'
|
| 380 |
+
'.sp-health strong.unavailable{border-color:#e0593a;color:#e0593a}'
|
| 381 |
+
'.sp-health strong.cached,.sp-health strong.checking{border-color:#697787;color:#9fb0c0}'
|
| 382 |
+
'.sp-grid{display:grid;gap:1rem;min-width:0;'
|
| 383 |
'grid-template-columns:repeat(auto-fill,minmax(260px,1fr))}'
|
| 384 |
'.sp-card{background:#121821;border:1px solid #1d2632;border-radius:12px;'
|
| 385 |
+
'padding:1rem 1.1rem;display:flex;flex-direction:column;gap:.5rem;min-width:0}'
|
| 386 |
+
'.sp-head{display:flex;align-items:center;gap:.55rem;min-width:0}'
|
| 387 |
'.sp-dot{color:#5b6675;font-size:.7rem;line-height:1}'
|
| 388 |
'.sp-dot.up{color:#3ad07a}.sp-dot.down{color:#e0593a}.sp-dot.unknown{color:#c9a23a}'
|
| 389 |
+
'.sp-title{font-size:1rem;margin:0;color:#e7eef6;font-weight:600;min-width:0;overflow-wrap:anywhere}'
|
| 390 |
+
'.sp-kind{color:#697787;font-size:.76rem;overflow-wrap:anywhere}'
|
| 391 |
+
'.sp-stage{color:#7c8794;font-size:.82rem;overflow-wrap:anywhere}'
|
| 392 |
'.sp-stage span{color:#9fb0c0}'
|
| 393 |
'.sp-links{margin-top:auto;display:flex;gap:.9rem;flex-wrap:wrap;padding-top:.4rem}'
|
| 394 |
+
'.sp-links a{display:inline-flex;align-items:center;min-height:44px;padding:.4rem .15rem}'
|
| 395 |
'.sp-open{color:#d4a444;text-decoration:none;font-weight:600}'
|
| 396 |
'.sp-hf{color:#7c8794;text-decoration:none}'
|
| 397 |
+
'.sp-foot{color:#5b6675;font-size:.8rem;margin-top:1.6rem;overflow-wrap:anywhere}'
|
| 398 |
+
'@media(max-width:375px){'
|
| 399 |
+
'.sp-wrap{padding:1.25rem .75rem}.sp-grid{grid-template-columns:minmax(0,1fr)}'
|
| 400 |
+
'.sp-links{gap:.15rem}.sp-links a{flex:1 1 100%}}'
|
| 401 |
'</style></head>'
|
| 402 |
'<body><main class="sp-wrap">'
|
| 403 |
'<h1 class="sp-h1">Hugging Face Spaces</h1>'
|
| 404 |
+
'<p class="sp-sub">All 26 audited Spaces in one evidence-labelled registry. '
|
| 405 |
+
'Apps open on their canonical isolated Hugging Face origin; health is probed '
|
| 406 |
+
'server-side. Legacy <code>/spaces/<slug></code> links are no-store 307 handoffs.</p>'
|
| 407 |
+
'<p class="sp-health">Estate health: '
|
| 408 |
+
'<strong id="sp-estate-health" class="checking" aria-live="polite">CHECKING</strong></p>'
|
| 409 |
'<div class="sp-grid">' + "".join(cards) + '</div>'
|
| 410 |
'<p class="sp-foot">Status dot & stage are filled from the same-origin '
|
| 411 |
'<code>/api/' + ns + '/v1/spaces/health</code> endpoint (real server-side probe '
|
|
|
|
| 413 |
'</main>'
|
| 414 |
'<script>'
|
| 415 |
'(function(){'
|
| 416 |
+
'var estate=document.getElementById("sp-estate-health");'
|
| 417 |
+
'function estateState(raw,cached){'
|
| 418 |
+
'var allowed={LIVE:1,DEGRADED:1,UNAVAILABLE:1,CACHED:1};'
|
| 419 |
+
'raw=String(raw||"UNAVAILABLE").toUpperCase();if(!allowed[raw])raw="UNAVAILABLE";'
|
| 420 |
+
'var label=raw;if(raw==="CACHED")label="CACHED \\u00b7 "+String(cached||"UNAVAILABLE").toUpperCase()+" snapshot";'
|
| 421 |
+
'if(estate){estate.className=raw.toLowerCase();estate.textContent=label;}}'
|
| 422 |
+
'function healthUnavailable(){estateState("UNAVAILABLE");'
|
| 423 |
+
'var cards=document.querySelectorAll(".sp-card");for(var i=0;i<cards.length;i++){'
|
| 424 |
+
'var dot=cards[i].querySelector(".sp-dot");if(dot){dot.classList.remove("up","unknown");'
|
| 425 |
+
'dot.classList.add("down");dot.title="UNAVAILABLE / health fetch failed";}'
|
| 426 |
+
'var st=cards[i].querySelector(".sp-stage span");if(st)st.textContent="UNAVAILABLE \\u00b7 health fetch failed";}}'
|
| 427 |
+
'fetch("/api/' + ns + '/v1/spaces/health").then(function(r){'
|
| 428 |
+
'if(!r.ok)throw new Error("health "+r.status);return r.json();})'
|
| 429 |
+
'.then(function(d){estateState(d.state,d.cached_state);(d.spaces||[]).forEach(function(s){'
|
| 430 |
+
'var card=document.querySelector(\'[data-space="\'+(s.slug||s.name)+\'"]\');if(!card)return;'
|
| 431 |
'var dot=card.querySelector(".sp-dot");'
|
| 432 |
+
'var stage=String(s.stage||"unknown").toUpperCase();'
|
| 433 |
+
'var state=String(s.state||((s.app_reachable&&stage==="RUNNING")?"LIVE":'
|
| 434 |
+
'((s.app_reachable||stage!=="UNKNOWN")?"DEGRADED":"UNAVAILABLE"))).toUpperCase();'
|
| 435 |
+
'if(state!=="LIVE"&&state!=="DEGRADED"&&state!=="UNAVAILABLE")state="UNAVAILABLE";'
|
| 436 |
'if(dot){dot.classList.remove("up","down","unknown");'
|
| 437 |
+
'dot.classList.add(state==="LIVE"?"up":(state==="DEGRADED"?"unknown":"down"));'
|
| 438 |
+
'dot.title=state+" / "+(s.app_reachable?"reachable":"unreachable")+" / stage:"+(s.stage||"unknown");}'
|
| 439 |
'var st=card.querySelector(".sp-stage span");'
|
| 440 |
+
'if(st){st.textContent=state+" \\u00b7 "+(s.stage||"unknown")+'
|
| 441 |
+
'(s.app_reachable?" \\u00b7 reachable":" \\u00b7 unreachable");}'
|
| 442 |
+
'});}).catch(healthUnavailable);'
|
| 443 |
'})();'
|
| 444 |
'</script>'
|
| 445 |
'</body></html>'
|
|
|
|
| 461 |
"""ONE 'Spaces' nav item, mirroring the console's own nav-item markup so it inherits
|
| 462 |
the console styling (0 CDN, 0 codename). Globe glyph; honest label."""
|
| 463 |
return (
|
| 464 |
+
'<a class="nav-item" data-nav-spaces="hf1" data-wireup-path="/spaces" '
|
| 465 |
+
'href="/spaces" style="cursor:pointer;text-decoration:none">'
|
| 466 |
+
'<span class="ico">\U0001F310</span>Spaces</a>'
|
| 467 |
).encode("utf-8")
|
| 468 |
|
| 469 |
|
|
|
|
| 525 |
at the FRONT of the router (beat the SPA + Node-proxy catch-alls), and attach the
|
| 526 |
idempotent 'Spaces' nav injector. try/except-guarded by the caller."""
|
| 527 |
try:
|
|
|
|
| 528 |
from starlette.responses import Response, JSONResponse as _JSON
|
| 529 |
except Exception as e: # pragma: no cover
|
| 530 |
return "unavailable: %r" % (e,)
|
|
|
|
| 534 |
|
| 535 |
async def _health(request):
|
| 536 |
payload = await spaces_health()
|
| 537 |
+
return _JSON(payload, headers={"Cache-Control": "no-store"})
|
| 538 |
|
| 539 |
async def _tiles(request):
|
| 540 |
+
headers = {"Cache-Control": "no-store"}
|
| 541 |
if request.method.upper() == "HEAD":
|
| 542 |
+
return Response(content=b"", status_code=200, media_type="text/html", headers=headers)
|
| 543 |
+
return Response(content=tiles, status_code=200, media_type="text/html", headers=headers)
|
| 544 |
|
| 545 |
from starlette.routing import Route
|
| 546 |
routes = [
|
|
|
|
| 567 |
# ---------------------------------------------------------------------------
|
| 568 |
# Self-test — pure stdlib + starlette TestClient; no real network. Stubs the shared
|
| 569 |
# client to assert: health degrades honestly (no client -> stage unknown + reachable
|
| 570 |
+
# false), tiles page lists ALL 26 names + has the health-fetch JS, nav injects exactly
|
| 571 |
# once + is idempotent + removes nothing, /spaces is NOT nav-injected.
|
| 572 |
# ---------------------------------------------------------------------------
|
| 573 |
if __name__ == "__main__":
|
|
|
|
| 575 |
with open(__file__, "r", encoding="utf-8") as _fh:
|
| 576 |
_ast.parse(_fh.read())
|
| 577 |
|
| 578 |
+
assert len(SPACES) == 26, len(SPACES)
|
| 579 |
tp = _tiles_page("a11oy")
|
| 580 |
for sp in SPACES:
|
| 581 |
assert sp["name"].encode() in tp, "tiles missing %s" % sp["name"]
|
| 582 |
assert sp["title"].encode() in tp, "tiles missing title %s" % sp["title"]
|
| 583 |
+
assert canonical_url(sp["name"]).encode() in tp, "tiles missing canonical app origin"
|
| 584 |
+
assert hf_repo_url(sp["name"]).encode() in tp, "tiles missing repository link"
|
| 585 |
+
assert proxy_url(sp["name"]) == canonical_url(sp["name"]), "primary link must stay isolated"
|
| 586 |
assert b"/api/a11oy/v1/spaces/health" in tp, "tiles must fetch the health endpoint"
|
| 587 |
assert b"http://" not in tp, "tiles must be 0 CDN (no http://)"
|
| 588 |
+
assert b'href="/spaces/' not in tp, "tiles must not execute an app under this origin"
|
| 589 |
+
assert b"canonical isolated Hugging Face origin" in tp
|
| 590 |
+
# Repository anchors are navigation only; no browser asset is loaded from HF.
|
| 591 |
+
assert tp.count(b"https://huggingface.co/spaces/") == len(SPACES)
|
| 592 |
+
assert b'<script src="https://' not in tp and b'<link href="https://' not in tp
|
| 593 |
+
|
| 594 |
+
running = {"app_reachable": True, "app_status": 200, "stage": "RUNNING"}
|
| 595 |
+
unknown = {"app_reachable": False, "stage": "unknown"}
|
| 596 |
+
http_200_unknown = {"app_reachable": True, "app_status": 200, "stage": "unknown"}
|
| 597 |
+
assert _aggregate_health_state([running, dict(running)]) == "LIVE"
|
| 598 |
+
assert _aggregate_health_state([unknown, dict(unknown)]) == "UNAVAILABLE"
|
| 599 |
+
assert _aggregate_health_state([running, unknown]) == "DEGRADED"
|
| 600 |
+
assert _aggregate_health_state([http_200_unknown]) == "DEGRADED", \
|
| 601 |
+
"HTTP 200 alone must never upgrade aggregate state to LIVE"
|
| 602 |
+
assert _space_health_state(running) == "LIVE"
|
| 603 |
+
assert _space_health_state(unknown) == "UNAVAILABLE"
|
| 604 |
+
assert _space_health_state(http_200_unknown) == "DEGRADED"
|
| 605 |
|
| 606 |
from starlette.applications import Starlette
|
| 607 |
from starlette.responses import HTMLResponse, PlainTextResponse
|
|
|
|
| 628 |
assert st.startswith("ok:"), st
|
| 629 |
c = TestClient(app)
|
| 630 |
|
| 631 |
+
# health: no httpx client wired -> falls back to the stdlib urllib probe. Stub that
|
| 632 |
+
# final outbound path so this self-test is hermetic and verifies the exact honest
|
| 633 |
+
# degrade contract for every audited Space (no network, no fabricated green state).
|
| 634 |
+
_self_mod = sys.modules[__name__]
|
| 635 |
+
_orig_probe = _self_mod._urllib_probe
|
| 636 |
+
def _offline(*_a, **_k):
|
| 637 |
+
raise OSError("simulated offline audit")
|
| 638 |
+
_self_mod._urllib_probe = _offline
|
| 639 |
+
_HEALTH_CACHE["ts"] = 0.0
|
| 640 |
+
_HEALTH_CACHE["payload"] = None
|
| 641 |
+
try:
|
| 642 |
+
health_response = c.get("/api/a11oy/v1/spaces/health")
|
| 643 |
+
h = health_response.json()
|
| 644 |
+
finally:
|
| 645 |
+
_self_mod._urllib_probe = _orig_probe
|
| 646 |
+
_HEALTH_CACHE["ts"] = 0.0
|
| 647 |
+
_HEALTH_CACHE["payload"] = None
|
| 648 |
+
assert h["count"] == 26, h["count"]
|
| 649 |
+
assert h["state"] == "UNAVAILABLE", h["state"]
|
| 650 |
+
assert health_response.headers["cache-control"] == "no-store"
|
| 651 |
for s in h["spaces"]:
|
| 652 |
+
assert s["app_reachable"] is False, "offline probe must honestly degrade false"
|
| 653 |
+
assert s["stage"] == "unknown", "offline HF API must honestly degrade unknown"
|
| 654 |
+
assert s["state"] == "UNAVAILABLE", "offline row must fail closed"
|
|
|
|
|
|
|
| 655 |
assert h["doctrine"]["locked_proven"] == ["F1", "F4", "F7", "F11", "F12", "F18", "F19", "F22"]
|
| 656 |
|
| 657 |
# tiles page resolves + lists all names
|
| 658 |
t = c.get("/spaces")
|
| 659 |
assert t.status_code == 200 and "text/html" in t.headers["content-type"], t.status_code
|
| 660 |
+
assert t.headers["cache-control"] == "no-store"
|
| 661 |
for sp in SPACES:
|
| 662 |
assert sp["name"] in t.text, "tiles page missing %s" % sp["name"]
|
| 663 |
|
|
|
|
| 666 |
p2 = c.get("/console").text
|
| 667 |
assert p1.count('data-nav-spaces="hf1"') == 1, "nav must inject exactly once"
|
| 668 |
assert p2.count('data-nav-spaces="hf1"') == 1, "nav must be idempotent"
|
| 669 |
+
assert 'href="/spaces"' in p1, "nav must link /spaces with a real anchor"
|
| 670 |
assert "Operate</div>" in p1 and "Existing</div>" in p1 and "footer</div>" in p1, \
|
| 671 |
"must remove nothing from the SPA source"
|
| 672 |
assert p1 == p2, "second console render must be byte-identical (idempotent)"
|
| 673 |
# the tiles page itself must NOT be nav-injected (it has no console sidebar)
|
| 674 |
assert 'data-nav-spaces="hf1"' not in c.get("/spaces").text, "/spaces must not be nav-injected"
|
| 675 |
|
| 676 |
+
print("szl_spaces_surface: ALL OK (26 canonical isolated links; honest degrade; "
|
| 677 |
+
"tiles 0-CDN + no-store; nav idempotent + additive; /spaces not self-injected)")
|