File size: 15,964 Bytes
4173e02 1e688c9 4173e02 1e688c9 4173e02 1e688c9 4173e02 1e688c9 4173e02 1e688c9 4173e02 1e688c9 4173e02 1e688c9 4173e02 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 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 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 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 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 | #!/usr/bin/env python3
"""Validate the public 12-task card and walkthrough surface.
This gate is deliberately about presentation integrity, not model quality. The
repo keeps snake_case artifact ids for reproducibility, but the public website
task cards and interactive player should use research-readable names and clear
input/process/output wording.
"""
from __future__ import annotations
import json
import re
from datetime import datetime, timezone
from pathlib import Path
from typing import Any
ROOT = Path(__file__).resolve().parents[1]
TASK_JSON = ROOT / "docs/data/task_walkthroughs.json"
WEBSITE = ROOT / "docs/index.html"
WALKTHROUGH_MD = ROOT / "results/episode_task_suite/task_walkthroughs/TASK_WALKTHROUGHS.md"
OUTPUT = ROOT / "docs/data/task_surface_integrity.json"
EXPECTED_TASKS = {
"timeline_action": "Action Recognition",
"timeline_subtask": "Procedure Step Recognition",
"transition_detection": "Action Boundary Detection",
"next_action": "Next-Action Prediction",
"hand_trajectory_forecast": "Hand Trajectory Forecasting",
"contact_prediction": "Contact State Prediction",
"object_relevance": "Object Relevance Prediction",
"caption_grounding": "Language Grounding",
"cross_modal_retrieval": "Cross-Modal Retrieval",
"modality_reconstruction": "Cross-Modal Reconstruction",
"temporal_order": "Temporal Order Verification",
"misalignment_detection": "Multimodal Synchronization Detection",
}
EXPECTED_EXTENSION_NAMES = {
"body_motion_intensity": "Body and Hand Motion Intensity",
"multi_view_consistency_retrieval": "Multi-View Consistency Retrieval",
"action_phase_progress": "Action Phase Progress Estimation",
"ego_motion_forecast": "Short-Horizon Ego-Motion Forecasting",
}
REQUIRED_TASK_FIELDS = {
"display_name",
"research_name",
"task_family",
"architecture_family",
"primary_direction",
"card_blurb",
"input_short",
"process_short",
"output_short",
"modalities",
"poster_modality",
"case_study",
"input",
"output",
"middle_modules",
"metric",
"failure_mode",
"artifact_id",
"plain_goal",
}
DISPLAY_FIELDS = {
"display_name",
"research_name",
"card_blurb",
"input_short",
"process_short",
"output_short",
"plain_goal",
}
ALLOWED_FAMILIES = {"supervised", "forecast", "retrieval", "diagnostic"}
MODALITY_ASSETS = {
"video": "docs/assets/modalities/video.jpg",
"audio": "docs/assets/modalities/audio.png",
"depth": "docs/assets/modalities/depth.jpg",
"pose_slam": "docs/assets/modalities/pose_slam.png",
"motion_capture": "docs/assets/modalities/motion_capture.png",
"inertial": "docs/assets/modalities/inertial.png",
"language": "docs/assets/modalities/language.png",
}
RAW_ID_PATTERN = re.compile(r"\b[a-z]+(?:_[a-z0-9]+)+\b")
def load_json(path: Path) -> dict[str, Any]:
return json.loads(path.read_text(encoding="utf-8"))
def check(condition: bool, name: str, failures: list[dict[str, Any]], **details: Any) -> dict[str, Any]:
record = {"name": name, "status": "pass" if condition else "fail", **details}
if not condition:
failures.append(record)
return record
def function_body(source: str, name: str) -> str:
marker = f"function {name}("
start = source.find(marker)
if start < 0:
return ""
brace = source.find("{", start)
if brace < 0:
return ""
depth = 0
for index in range(brace, len(source)):
char = source[index]
if char == "{":
depth += 1
elif char == "}":
depth -= 1
if depth == 0:
return source[start : index + 1]
return source[start:]
def validate_tasks(payload: dict[str, Any], failures: list[dict[str, Any]]) -> list[dict[str, Any]]:
checks: list[dict[str, Any]] = []
tasks = payload.get("tasks", {})
checks.append(check(isinstance(tasks, dict), "tasks_object_present", failures))
if not isinstance(tasks, dict):
return checks
task_ids = set(tasks)
checks.append(
check(
len(tasks) == len(EXPECTED_TASKS),
"exactly_12_tasks",
failures,
observed=len(tasks),
expected=len(EXPECTED_TASKS),
)
)
checks.append(
check(
task_ids == set(EXPECTED_TASKS),
"expected_task_ids_present",
failures,
missing=sorted(set(EXPECTED_TASKS) - task_ids),
extra=sorted(task_ids - set(EXPECTED_TASKS)),
)
)
for task_id, task in tasks.items():
if not isinstance(task, dict):
checks.append(check(False, f"{task_id}: task_record_object", failures))
continue
missing_fields = sorted(REQUIRED_TASK_FIELDS - set(task))
checks.append(
check(not missing_fields, f"{task_id}: required_fields", failures, missing=missing_fields)
)
expected_name = EXPECTED_TASKS.get(task_id)
checks.append(
check(
task.get("display_name") == expected_name,
f"{task_id}: human_readable_display_name",
failures,
expected=expected_name,
observed=task.get("display_name"),
)
)
checks.append(
check(
task.get("artifact_id") == task_id,
f"{task_id}: artifact_id_matches_key",
failures,
observed=task.get("artifact_id"),
)
)
for field in DISPLAY_FIELDS:
value = str(task.get(field, ""))
raw_hits = [hit for hit in RAW_ID_PATTERN.findall(value) if hit in EXPECTED_TASKS or hit in MODALITY_ASSETS]
checks.append(
check(
not raw_hits,
f"{task_id}: public_field_{field}_is_human_readable",
failures,
value=value,
raw_hits=raw_hits,
)
)
family = task.get("task_family")
checks.append(
check(
family in ALLOWED_FAMILIES,
f"{task_id}: known_task_family",
failures,
observed=family,
allowed=sorted(ALLOWED_FAMILIES),
)
)
modalities = task.get("modalities", [])
checks.append(
check(
isinstance(modalities, list) and modalities,
f"{task_id}: modality_list_present",
failures,
observed=modalities,
)
)
if isinstance(modalities, list):
unknown = [item for item in modalities if item not in MODALITY_ASSETS]
missing_assets = [
MODALITY_ASSETS[item]
for item in modalities
if item in MODALITY_ASSETS and not (ROOT / MODALITY_ASSETS[item]).exists()
]
checks.append(
check(
not unknown,
f"{task_id}: known_modalities",
failures,
unknown=unknown,
)
)
checks.append(
check(
not missing_assets,
f"{task_id}: modality_assets_exist",
failures,
missing=missing_assets,
)
)
checks.append(
check(
task.get("poster_modality") in modalities,
f"{task_id}: poster_modality_in_task_modalities",
failures,
poster_modality=task.get("poster_modality"),
modalities=modalities,
)
)
metric = task.get("metric", {})
metric_ok = (
isinstance(metric, dict)
and isinstance(metric.get("name"), str)
and isinstance(metric.get("direction"), str)
and isinstance(metric.get("minimal"), (int, float))
and isinstance(metric.get("neural_mlp"), (int, float))
)
checks.append(
check(
metric_ok,
f"{task_id}: numeric_minimal_and_neural_metrics",
failures,
metric=metric,
)
)
checks.append(
check(
isinstance(task.get("middle_modules"), list) and len(task.get("middle_modules", [])) >= 3,
f"{task_id}: middle_modules_explain_process",
failures,
observed_count=len(task.get("middle_modules", [])) if isinstance(task.get("middle_modules"), list) else 0,
)
)
return checks
def validate_markdown(source: str, tasks: dict[str, Any], failures: list[dict[str, Any]]) -> list[dict[str, Any]]:
checks: list[dict[str, Any]] = []
for task_id, display_name in EXPECTED_TASKS.items():
expected_heading = f"### {display_name} (`{task_id}`)"
checks.append(
check(
expected_heading in source,
f"markdown_heading_present:{task_id}",
failures,
expected=expected_heading,
)
)
checks.append(
check(
source.count("### ") == len(EXPECTED_TASKS),
"markdown_has_12_task_sections",
failures,
observed=source.count("### "),
)
)
checks.append(
check(
all(str(task.get("case_study", "")) in source for task in tasks.values()),
"markdown_contains_case_studies",
failures,
)
)
return checks
def validate_website(source: str, failures: list[dict[str, Any]]) -> list[dict[str, Any]]:
checks: list[dict[str, Any]] = []
required_markers = [
'id="taskPlayer"',
'id="taskGrid"',
'id="walkthroughSelector"',
'id="playerStoryboard"',
'id="playerFrameChip"',
'id="playerFrameCaption"',
'id="playerScrub"',
'fetch("data/task_walkthroughs.json"',
'class="task-card"',
'class="task-card-media"',
'class="story-button',
'class="flow-step',
'id="playerPlay"',
'id="playerPrev"',
'id="playerNext"',
]
for marker in required_markers:
checks.append(
check(marker in source, f"website_marker_present:{marker}", failures, marker=marker)
)
task_card_renderer = function_body(source, "renderTaskCards")
selector_renderer = function_body(source, "renderSelector")
player_renderer = function_body(source, "renderPlayer")
checks.append(
check(
"artifact-id" not in source,
"website_no_artifact_id_css_or_markup",
failures,
)
)
checks.append(
check(
"artifact_id" not in task_card_renderer,
"task_cards_do_not_render_artifact_ids",
failures,
)
)
checks.append(
check(
"task.display_name" in task_card_renderer and "task.research_name" in task_card_renderer,
"task_cards_render_human_names",
failures,
)
)
checks.append(
check(
"task.input_short" in task_card_renderer and "task.process_short" in task_card_renderer and "task.output_short" in task_card_renderer,
"task_cards_render_input_process_output",
failures,
)
)
checks.append(
check(
"task.poster_modality" in task_card_renderer and "task-card-media" in task_card_renderer,
"task_cards_use_representative_modality_thumbnail",
failures,
)
)
checks.append(
check(
all(
needle in player_renderer
for needle in ["playerPoster", "middle_modules"]
)
and all(needle in source for needle in ["playerProgress", "renderStageFrame(task, index)"])
and all(needle in source for needle in ['id="playerPlay"', 'id="playerPrev"', 'id="playerNext"']),
"interactive_player_wired_to_task_metadata",
failures,
)
)
checks.append(
check(
all(needle in source for needle in ["function setActiveStage", "function advancePlayer", "playerScrub"]),
"interactive_video_storyboard_controls_present",
failures,
)
)
checks.append(
check(
"task.display_name" in selector_renderer and "artifact_id" not in selector_renderer,
"selector_uses_human_names",
failures,
)
)
for artifact_id, display_name in EXPECTED_EXTENSION_NAMES.items():
checks.append(
check(
f"<h3>{artifact_id}</h3>" not in source and display_name in source,
f"extension_probe_uses_human_name:{artifact_id}",
failures,
expected=display_name,
)
)
return checks
def build_report() -> dict[str, Any]:
failures: list[dict[str, Any]] = []
checks: list[dict[str, Any]] = []
inputs_present = {
"task_walkthroughs_json": TASK_JSON.exists(),
"website_index": WEBSITE.exists(),
"walkthrough_markdown": WALKTHROUGH_MD.exists(),
}
checks.append(
check(
all(inputs_present.values()),
"required_task_surface_inputs_present",
failures,
inputs=inputs_present,
)
)
if not all(inputs_present.values()):
return {
"status": "fail",
"generated_at_utc": datetime.now(timezone.utc).isoformat(timespec="seconds"),
"summary": {"task_count": 0, "failure_count": len(failures)},
"checks": checks,
"failures": failures,
}
task_payload = load_json(TASK_JSON)
website_source = WEBSITE.read_text(encoding="utf-8")
markdown_source = WALKTHROUGH_MD.read_text(encoding="utf-8")
tasks = task_payload.get("tasks", {}) if isinstance(task_payload.get("tasks", {}), dict) else {}
checks.extend(validate_tasks(task_payload, failures))
checks.extend(validate_markdown(markdown_source, tasks, failures))
checks.extend(validate_website(website_source, failures))
task_families = {}
task_modalities = {}
for task in tasks.values():
family = task.get("task_family")
if isinstance(family, str):
task_families[family] = task_families.get(family, 0) + 1
for modality in task.get("modalities", []):
task_modalities[modality] = task_modalities.get(modality, 0) + 1
return {
"status": "pass" if not failures else "fail",
"generated_at_utc": datetime.now(timezone.utc).isoformat(timespec="seconds"),
"summary": {
"task_count": len(tasks),
"expected_task_count": len(EXPECTED_TASKS),
"task_family_counts": dict(sorted(task_families.items())),
"modality_usage_counts": dict(sorted(task_modalities.items())),
"interactive_surface": "task cards plus scrub/play/chapter walkthrough storyboard",
"failure_count": len(failures),
},
"checks": checks,
"failures": failures,
}
def main() -> int:
report = build_report()
OUTPUT.parent.mkdir(parents=True, exist_ok=True)
OUTPUT.write_text(json.dumps(report, indent=2) + "\n", encoding="utf-8")
print(f"{report['status'].upper()}: wrote {OUTPUT}")
if report["status"] != "pass":
for failure in report["failures"][:40]:
print(f"- {failure['name']}")
if len(report["failures"]) > 40:
print(f"- ... {len(report['failures']) - 40} more failures")
return 1
return 0
if __name__ == "__main__":
raise SystemExit(main())
|