ihuarraquax commited on
Commit
5e6aded
·
verified ·
1 Parent(s): a4baf3a

Deploy runtime files (de6aee9a2d)

Browse files
Files changed (2) hide show
  1. config/labels.json +78 -0
  2. main.py +28 -3
config/labels.json ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "schema_version": 1,
3
+ "description": "Canonical whitelist for backend ingestion. The runtime source of truth lives at HF dataset `sets-sto/sto-icon-dataset:config/labels.json`; this file is the bootstrap fallback baked into the backend, mirrored on disk so PRs can change the whitelist via code review.",
4
+ "screen_types": [
5
+ "SPACE_EQ",
6
+ "GROUND_EQ",
7
+ "TRAITS",
8
+ "SPACE_TRAITS",
9
+ "GROUND_TRAITS",
10
+ "BOFFS",
11
+ "SPACE_BOFFS",
12
+ "GROUND_BOFFS",
13
+ "SPECIALIZATIONS",
14
+ "SPACE_MIXED",
15
+ "GROUND_MIXED",
16
+ "SKILLS",
17
+ "SPACE_SKILLS",
18
+ "GROUND_SKILLS",
19
+ "DISCARD"
20
+ ],
21
+ "slots": {
22
+ "SPACE_EQ": [
23
+ "Fore Weapons", "Deflector", "Sec-Def", "Engines", "Warp Core", "Shield",
24
+ "Aft Weapons", "Experimental", "Devices", "Universal Consoles",
25
+ "Engineering Consoles", "Science Consoles", "Tactical Consoles", "Hangars",
26
+ "Ship Name", "Ship Type", "Ship Tier"
27
+ ],
28
+ "GROUND_EQ": [
29
+ "Body Armor", "EV Suit", "Personal Shield", "Weapons", "Kit", "Kit Modules", "Ground Devices"
30
+ ],
31
+ "TRAITS": [
32
+ "Personal Space Traits", "Starship Traits", "Space Reputation", "Active Space Rep",
33
+ "Personal Ground Traits", "Ground Reputation", "Active Ground Rep"
34
+ ],
35
+ "SPACE_TRAITS": [
36
+ "Personal Space Traits", "Starship Traits", "Space Reputation", "Active Space Rep"
37
+ ],
38
+ "GROUND_TRAITS": [
39
+ "Personal Ground Traits", "Ground Reputation", "Active Ground Rep"
40
+ ],
41
+ "BOFFS": [
42
+ "Boff Tactical", "Boff Engineering", "Boff Science",
43
+ "Boff Intelligence", "Boff Command", "Boff Pilot", "Boff Miracle Worker", "Boff Temporal"
44
+ ],
45
+ "SPACE_BOFFS": [
46
+ "Boff Tactical", "Boff Engineering", "Boff Science",
47
+ "Boff Intelligence", "Boff Command", "Boff Pilot", "Boff Miracle Worker", "Boff Temporal"
48
+ ],
49
+ "GROUND_BOFFS": [
50
+ "Boff Tactical", "Boff Engineering", "Boff Science",
51
+ "Boff Intelligence", "Boff Command", "Boff Pilot", "Boff Miracle Worker", "Boff Temporal"
52
+ ],
53
+ "SPECIALIZATIONS": [
54
+ "Primary Specialization", "Secondary Specialization"
55
+ ],
56
+ "SPACE_MIXED": [
57
+ "Fore Weapons", "Deflector", "Sec-Def", "Engines", "Warp Core", "Shield",
58
+ "Aft Weapons", "Experimental", "Devices", "Universal Consoles",
59
+ "Engineering Consoles", "Science Consoles", "Tactical Consoles", "Hangars",
60
+ "Ship Name", "Ship Type", "Ship Tier",
61
+ "Personal Space Traits", "Starship Traits", "Space Reputation", "Active Space Rep",
62
+ "Boff Tactical", "Boff Engineering", "Boff Science",
63
+ "Boff Intelligence", "Boff Command", "Boff Pilot", "Boff Miracle Worker", "Boff Temporal",
64
+ "Primary Specialization", "Secondary Specialization"
65
+ ],
66
+ "GROUND_MIXED": [
67
+ "Body Armor", "EV Suit", "Personal Shield", "Weapons", "Kit", "Kit Modules", "Ground Devices",
68
+ "Personal Ground Traits", "Ground Reputation", "Active Ground Rep",
69
+ "Boff Tactical", "Boff Engineering", "Boff Science",
70
+ "Boff Intelligence", "Boff Command", "Boff Pilot", "Boff Miracle Worker", "Boff Temporal",
71
+ "Primary Specialization", "Secondary Specialization"
72
+ ],
73
+ "SKILLS": [],
74
+ "SPACE_SKILLS": [],
75
+ "GROUND_SKILLS": [],
76
+ "DISCARD": []
77
+ }
78
+ }
main.py CHANGED
@@ -249,7 +249,17 @@ class AnchorsRequest(BaseModel):
249
 
250
  @app.get('/health')
251
  async def health():
252
- return {'status': 'ok', 'repo': HF_REPO_ID}
 
 
 
 
 
 
 
 
 
 
253
 
254
 
255
  @app.get('/model/version')
@@ -587,7 +597,16 @@ async def upload_anchors(req: AnchorsRequest, request: Request):
587
  rejected += 1
588
  reasons.append(f'build_type {grid.build_type!r} not in whitelist')
589
  continue
590
- allowed_slots = set(slot_whitelist.get(grid.build_type) or [])
 
 
 
 
 
 
 
 
 
591
  if allowed_slots:
592
  stray = [k for k in slots.keys() if k not in allowed_slots]
593
  if stray:
@@ -913,7 +932,13 @@ def _load_labels_bundled() -> dict:
913
  try:
914
  return json.loads(path.read_text(encoding='utf-8'))
915
  except Exception as e:
916
- log.warning(f'bundled labels.json load failed: {e}')
 
 
 
 
 
 
917
  return {'schema_version': 1, 'screen_types': [], 'slots': {}}
918
 
919
 
 
249
 
250
  @app.get('/health')
251
  async def health():
252
+ # `validation` is here because an empty whitelist disables every ingestion
253
+ # gate: without it on the outside, a backend running wide open looks
254
+ # exactly like a healthy one.
255
+ labels = _get_labels()
256
+ n_types = len(labels.get('screen_types') or [])
257
+ return {
258
+ 'status': 'ok',
259
+ 'repo': HF_REPO_ID,
260
+ 'validation': 'enforcing' if n_types else 'DISABLED (empty whitelist)',
261
+ 'screen_types': n_types,
262
+ }
263
 
264
 
265
  @app.get('/model/version')
 
597
  rejected += 1
598
  reasons.append(f'build_type {grid.build_type!r} not in whitelist')
599
  continue
600
+ # A declared-but-empty slot list means "this screen has no icon slots"
601
+ # (DISCARD, the skill trees, SPECIALIZATIONS) — an anchor grid for it
602
+ # is invalid by definition. Only a *missing* entry leaves enforcement
603
+ # off, which is the fail-open above.
604
+ declared_slots = grid.build_type in slot_whitelist
605
+ allowed_slots = set(slot_whitelist.get(grid.build_type) or [])
606
+ if declared_slots and not allowed_slots:
607
+ rejected += 1
608
+ reasons.append(f'build_type {grid.build_type!r} has no icon slots')
609
+ continue
610
  if allowed_slots:
611
  stray = [k for k in slots.keys() if k not in allowed_slots]
612
  if stray:
 
932
  try:
933
  return json.loads(path.read_text(encoding='utf-8'))
934
  except Exception as e:
935
+ # An empty whitelist switches every gate off (see the ingestion
936
+ # endpoints). That fail-open is deliberate for a transient outage, but
937
+ # a missing bundled file is not transient — it silently runs the
938
+ # backend with no validation at all, which is how this shipped for
939
+ # months. Loud, and visible on /health.
940
+ log.error(f'bundled labels.json load failed: {e} — '
941
+ f'INGESTION VALIDATION IS DISABLED')
942
  return {'schema_version': 1, 'screen_types': [], 'slots': {}}
943
 
944