File size: 26,872 Bytes
a340c71
 
 
 
8faf8f4
a340c71
 
 
 
 
 
 
 
8cfcd63
 
a340c71
 
 
db1d246
a340c71
 
 
 
 
 
 
6760b34
a340c71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ec1d592
 
 
 
 
 
 
 
 
 
 
4148050
 
 
 
 
 
 
 
 
 
 
efbbd05
8faf8f4
 
efbbd05
 
 
 
 
 
 
 
bc3641c
8faf8f4
 
 
bc3641c
8faf8f4
 
 
 
bc3641c
 
c51a5c8
 
 
 
 
 
 
 
 
 
 
5dabf7e
 
 
 
 
 
 
 
 
 
 
b4d66a1
 
 
 
 
 
 
 
 
 
 
5e53692
 
 
 
 
 
 
 
 
 
 
9a61006
 
 
 
 
 
 
 
 
 
 
9b52e4d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a340c71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4148050
efbbd05
c51a5c8
5dabf7e
 
b4d66a1
9b52e4d
 
8faf8f4
c51a5c8
 
db1d246
5e53692
 
 
 
9a61006
ec1d592
 
a340c71
 
 
 
9a61006
a340c71
 
 
 
 
 
 
 
 
4148050
efbbd05
c51a5c8
5dabf7e
 
b4d66a1
9b52e4d
 
8faf8f4
c51a5c8
 
db1d246
5e53692
 
 
 
9a61006
ec1d592
 
a340c71
 
 
 
9a61006
a340c71
 
 
 
 
 
4148050
 
 
 
efbbd05
c51a5c8
5dabf7e
 
b4d66a1
9b52e4d
 
8faf8f4
c51a5c8
 
137388d
9a61006
ec1d592
 
4148050
a340c71
 
 
 
 
 
4148050
 
 
 
efbbd05
c51a5c8
5dabf7e
 
b4d66a1
9b52e4d
 
8faf8f4
c51a5c8
 
137388d
9a61006
ec1d592
 
4148050
a340c71
 
 
 
6760b34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a340c71
 
 
 
 
 
 
 
 
 
 
 
 
db1d246
 
 
 
 
a340c71
 
 
 
 
 
 
 
 
 
 
db1d246
a340c71
 
 
 
 
 
 
 
 
 
aa697ff
 
 
 
 
 
 
 
 
 
 
 
a340c71
8cfcd63
 
 
a340c71
 
 
 
 
 
 
 
 
 
8cfcd63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a340c71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6760b34
a340c71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
#!/usr/bin/env python3
"""Verify the already-published GitHub Pages and Hugging Face mirrors.

This is the post-publish companion to the local publication gates. It fetches
public URLs and compares them with the local release artifacts so a reader can
see that the live surfaces match the repo/HF bundles that were prepared.
"""

from __future__ import annotations

import argparse
import hashlib
import json
import subprocess
import tempfile
from datetime import datetime, timezone
from pathlib import Path
from urllib.error import HTTPError, URLError
from urllib.parse import urlsplit, urlunsplit
from urllib.request import Request, urlopen


ROOT = Path(__file__).resolve().parents[1]
DEFAULT_OUTPUT = ROOT / "docs/data/live_publication_status.json"
TIMEOUT_SECONDS = 30
USER_AGENT = "ropedia-xperience-10m-live-verifier/1.0"
LOCAL_PATH_FORBIDDEN_MARKERS = ["/" + "Users/", "/" + "private/"]


HASH_GROUPS = [
    {
        "id": "task_suite_infographic",
        "title": "Task-suite infographic",
        "local_path": "docs/assets/task_suite_infographic.png",
        "urls": {
            "github_pages": "https://chaoyue0307.github.io/ropedia-xperience-10m-task-suite/assets/task_suite_infographic.png",
            "hf_space": "https://huggingface.co/spaces/cy0307/ropedia-xperience-10m-task-suite/resolve/main/assets/task_suite_infographic.png",
            "hf_artifacts": "https://huggingface.co/datasets/cy0307/ropedia-xperience-10m-task-suite-artifacts/resolve/main/docs/assets/task_suite_infographic.png",
            "hf_model": "https://huggingface.co/cy0307/ropedia-xperience-10m-task-baselines/resolve/main/assets/task_suite_infographic.png",
        },
    },
    {
        "id": "quality_gates_json",
        "title": "Quality-gate JSON",
        "local_path": "docs/data/quality_gates.json",
        "urls": {
            "github_pages": "https://chaoyue0307.github.io/ropedia-xperience-10m-task-suite/data/quality_gates.json",
            "hf_space": "https://huggingface.co/spaces/cy0307/ropedia-xperience-10m-task-suite/raw/main/data/quality_gates.json",
            "hf_artifacts": "https://huggingface.co/datasets/cy0307/ropedia-xperience-10m-task-suite-artifacts/resolve/main/docs/data/quality_gates.json",
            "hf_model": "https://huggingface.co/cy0307/ropedia-xperience-10m-task-baselines/resolve/main/metrics/quality_gates.json",
        },
    },
    {
        "id": "public_surface_qa_json",
        "title": "Public-surface QA JSON",
        "local_path": "docs/data/public_surface_qa.json",
        "urls": {
            "github_pages": "https://chaoyue0307.github.io/ropedia-xperience-10m-task-suite/data/public_surface_qa.json",
            "hf_space": "https://huggingface.co/spaces/cy0307/ropedia-xperience-10m-task-suite/raw/main/data/public_surface_qa.json",
            "hf_artifacts": "https://huggingface.co/datasets/cy0307/ropedia-xperience-10m-task-suite-artifacts/resolve/main/docs/data/public_surface_qa.json",
            "hf_model": "https://huggingface.co/cy0307/ropedia-xperience-10m-task-baselines/resolve/main/metrics/public_surface_qa.json",
        },
    },
    {
        "id": "xperience10m_dataset_card_alignment_json",
        "title": "Official Xperience-10M dataset-card alignment JSON",
        "local_path": "docs/data/xperience10m_dataset_card_alignment.json",
        "urls": {
            "github_pages": "https://chaoyue0307.github.io/ropedia-xperience-10m-task-suite/data/xperience10m_dataset_card_alignment.json",
            "hf_space": "https://huggingface.co/spaces/cy0307/ropedia-xperience-10m-task-suite/raw/main/data/xperience10m_dataset_card_alignment.json",
            "hf_artifacts": "https://huggingface.co/datasets/cy0307/ropedia-xperience-10m-task-suite-artifacts/resolve/main/docs/data/xperience10m_dataset_card_alignment.json",
            "hf_model": "https://huggingface.co/cy0307/ropedia-xperience-10m-task-baselines/resolve/main/metrics/xperience10m_dataset_card_alignment.json",
        },
    },
    {
        "id": "source_alignment_json",
        "title": "Source-alignment JSON",
        "local_path": "docs/data/source_alignment_audit.json",
        "urls": {
            "github_pages": "https://chaoyue0307.github.io/ropedia-xperience-10m-task-suite/data/source_alignment_audit.json",
            "hf_space": "https://huggingface.co/spaces/cy0307/ropedia-xperience-10m-task-suite/raw/main/data/source_alignment_audit.json",
            "hf_artifacts": "https://huggingface.co/datasets/cy0307/ropedia-xperience-10m-task-suite-artifacts/resolve/main/docs/data/source_alignment_audit.json",
            "hf_model": "https://huggingface.co/cy0307/ropedia-xperience-10m-task-baselines/resolve/main/metrics/source_alignment_audit.json",
        },
    },
    {
        "id": "project_status_json",
        "title": "Project status JSON",
        "local_path": "docs/data/project_status.json",
        "urls": {
            "github_pages": "https://chaoyue0307.github.io/ropedia-xperience-10m-task-suite/data/project_status.json",
            "hf_space": "https://huggingface.co/spaces/cy0307/ropedia-xperience-10m-task-suite/raw/main/data/project_status.json",
            "hf_artifacts": "https://huggingface.co/datasets/cy0307/ropedia-xperience-10m-task-suite-artifacts/resolve/main/docs/data/project_status.json",
            "hf_model": "https://huggingface.co/cy0307/ropedia-xperience-10m-task-baselines/resolve/main/metrics/project_status.json",
        },
    },
    {
        "id": "evaluation_protocol_json",
        "title": "Evaluation protocol JSON",
        "local_path": "docs/data/evaluation_protocol.json",
        "urls": {
            "github_pages": "https://chaoyue0307.github.io/ropedia-xperience-10m-task-suite/data/evaluation_protocol.json",
            "hf_space": "https://huggingface.co/spaces/cy0307/ropedia-xperience-10m-task-suite/raw/main/data/evaluation_protocol.json",
            "hf_artifacts": "https://huggingface.co/datasets/cy0307/ropedia-xperience-10m-task-suite-artifacts/resolve/main/docs/data/evaluation_protocol.json",
            "hf_model": "https://huggingface.co/cy0307/ropedia-xperience-10m-task-baselines/resolve/main/metrics/evaluation_protocol.json",
        },
    },
    {
        "id": "research_takeaways_json",
        "title": "Research takeaways JSON",
        "local_path": "docs/data/research_takeaways.json",
        "urls": {
            "github_pages": "https://chaoyue0307.github.io/ropedia-xperience-10m-task-suite/data/research_takeaways.json",
            "hf_space": "https://huggingface.co/spaces/cy0307/ropedia-xperience-10m-task-suite/raw/main/data/research_takeaways.json",
            "hf_artifacts": "https://huggingface.co/datasets/cy0307/ropedia-xperience-10m-task-suite-artifacts/resolve/main/docs/data/research_takeaways.json",
            "hf_model": "https://huggingface.co/cy0307/ropedia-xperience-10m-task-baselines/resolve/main/metrics/research_takeaways.json",
        },
    },
    {
        "id": "figure_index_json",
        "title": "Figure index JSON",
        "local_path": "docs/data/figure_index.json",
        "urls": {
            "github_pages": "https://chaoyue0307.github.io/ropedia-xperience-10m-task-suite/data/figure_index.json",
            "hf_space": "https://huggingface.co/spaces/cy0307/ropedia-xperience-10m-task-suite/raw/main/data/figure_index.json",
            "hf_artifacts": "https://huggingface.co/datasets/cy0307/ropedia-xperience-10m-task-suite-artifacts/resolve/main/docs/data/figure_index.json",
            "hf_model": "https://huggingface.co/cy0307/ropedia-xperience-10m-task-baselines/resolve/main/metrics/figure_index.json",
        },
    },
    {
        "id": "task_walkthroughs_json",
        "title": "Task walkthrough JSON",
        "local_path": "docs/data/task_walkthroughs.json",
        "urls": {
            "github_pages": "https://chaoyue0307.github.io/ropedia-xperience-10m-task-suite/data/task_walkthroughs.json",
            "hf_space": "https://huggingface.co/spaces/cy0307/ropedia-xperience-10m-task-suite/raw/main/data/task_walkthroughs.json",
            "hf_artifacts": "https://huggingface.co/datasets/cy0307/ropedia-xperience-10m-task-suite-artifacts/resolve/main/docs/data/task_walkthroughs.json",
            "hf_model": "https://huggingface.co/cy0307/ropedia-xperience-10m-task-baselines/resolve/main/metrics/task_walkthroughs.json",
        },
    },
    {
        "id": "task_surface_integrity_json",
        "title": "Task-surface integrity JSON",
        "local_path": "docs/data/task_surface_integrity.json",
        "urls": {
            "github_pages": "https://chaoyue0307.github.io/ropedia-xperience-10m-task-suite/data/task_surface_integrity.json",
            "hf_space": "https://huggingface.co/spaces/cy0307/ropedia-xperience-10m-task-suite/raw/main/data/task_surface_integrity.json",
            "hf_artifacts": "https://huggingface.co/datasets/cy0307/ropedia-xperience-10m-task-suite-artifacts/resolve/main/docs/data/task_surface_integrity.json",
            "hf_model": "https://huggingface.co/cy0307/ropedia-xperience-10m-task-baselines/resolve/main/metrics/task_surface_integrity.json",
        },
    },
    {
        "id": "brand_assets_json",
        "title": "Brand assets JSON",
        "local_path": "docs/data/brand_assets.json",
        "urls": {
            "github_pages": "https://chaoyue0307.github.io/ropedia-xperience-10m-task-suite/data/brand_assets.json",
            "hf_space": "https://huggingface.co/spaces/cy0307/ropedia-xperience-10m-task-suite/raw/main/data/brand_assets.json",
            "hf_artifacts": "https://huggingface.co/datasets/cy0307/ropedia-xperience-10m-task-suite-artifacts/resolve/main/docs/data/brand_assets.json",
            "hf_model": "https://huggingface.co/cy0307/ropedia-xperience-10m-task-baselines/resolve/main/metrics/brand_assets.json",
        },
    },
    {
        "id": "brand_logo_social_card",
        "title": "Brand logo social card",
        "local_path": "docs/assets/brand/xperience10m-logo-social-card.png",
        "urls": {
            "github_pages": "https://chaoyue0307.github.io/ropedia-xperience-10m-task-suite/assets/brand/xperience10m-logo-social-card.png",
            "hf_space": "https://huggingface.co/spaces/cy0307/ropedia-xperience-10m-task-suite/resolve/main/assets/brand/xperience10m-logo-social-card.png",
            "hf_artifacts": "https://huggingface.co/datasets/cy0307/ropedia-xperience-10m-task-suite-artifacts/resolve/main/docs/assets/brand/xperience10m-logo-social-card.png",
            "hf_model": "https://huggingface.co/cy0307/ropedia-xperience-10m-task-baselines/resolve/main/assets/brand/xperience10m-logo-social-card.png",
        },
    },
    {
        "id": "quality_gates_markdown",
        "title": "Quality-gate Markdown",
        "local_path": "QUALITY_GATES.md",
        "urls": {
            "github_raw": "https://raw.githubusercontent.com/ChaoYue0307/ropedia-xperience-10m-task-suite/main/QUALITY_GATES.md",
            "hf_space": "https://huggingface.co/spaces/cy0307/ropedia-xperience-10m-task-suite/raw/main/QUALITY_GATES.md",
            "hf_artifacts": "https://huggingface.co/datasets/cy0307/ropedia-xperience-10m-task-suite-artifacts/raw/main/QUALITY_GATES.md",
            "hf_model": "https://huggingface.co/cy0307/ropedia-xperience-10m-task-baselines/raw/main/QUALITY_GATES.md",
        },
    },
]


MARKER_CHECKS = [
    {
        "id": "github_pages_index_current",
        "title": "GitHub Pages index contains current publication markers",
        "url": "https://chaoyue0307.github.io/ropedia-xperience-10m-task-suite/",
        "required": [
            "Release gates are explicit",
            "quality_gates.json",
            "xperience10m_dataset_card_alignment.json",
            "source_alignment_audit.json",
            "evaluation_protocol.json",
            "research_takeaways.json",
            "Research Takeaways",
            "figure_index.json",
            "brand_assets.json",
            "xperience10m-logo-social-card.png",
            "project_status.json",
            "cc-by-nc-4.0",
            "12,103 episode folders",
            "xperience10m-taskfirst-v12-modality-xl",
            "Interactive task walkthrough.",
            "taskPlayer",
            "Action Recognition",
            "data/task_walkthroughs.json",
            "task_surface_integrity.json",
            "public_surface_qa.json",
            "Public surface QA",
        ],
        "forbidden": [
            "xperience10m-" + "taskfirst-v10",
            "xperience10m-" + "modalities-v9-large-atlas",
            "artifact-id",
        ],
    },
    {
        "id": "hf_space_index_current",
        "title": "HF Space index contains current publication markers",
        "url": "https://huggingface.co/spaces/cy0307/ropedia-xperience-10m-task-suite/raw/main/index.html",
        "required": [
            "Release gates are explicit",
            "quality_gates.json",
            "xperience10m_dataset_card_alignment.json",
            "source_alignment_audit.json",
            "evaluation_protocol.json",
            "research_takeaways.json",
            "Research Takeaways",
            "figure_index.json",
            "brand_assets.json",
            "xperience10m-logo-social-card.png",
            "project_status.json",
            "cc-by-nc-4.0",
            "12,103 episode folders",
            "xperience10m-taskfirst-v12-modality-xl",
            "Interactive task walkthrough.",
            "taskPlayer",
            "Action Recognition",
            "data/task_walkthroughs.json",
            "task_surface_integrity.json",
            "public_surface_qa.json",
            "Public surface QA",
        ],
        "forbidden": [
            "xperience10m-" + "taskfirst-v10",
            "xperience10m-" + "modalities-v9-large-atlas",
            "artifact-id",
        ],
    },
    {
        "id": "hf_artifacts_card_current",
        "title": "HF artifact card links quality gates",
        "url": "https://huggingface.co/datasets/cy0307/ropedia-xperience-10m-task-suite-artifacts/raw/main/README.md",
        "required": [
            "QUALITY_GATES.md",
            "docs/data/quality_gates.json",
            "xperience10m_dataset_card_alignment.json",
            "source_alignment_audit.json",
            "evaluation_protocol.json",
            "research_takeaways.json",
            "Research Takeaways",
            "figure_index.json",
            "brand_assets.json",
            "xperience10m-logo-social-card.png",
            "project_status.json",
            "cc-by-nc-4.0",
            "12,103 episode folders",
            "interactive scrub/play walkthrough storyboard",
            "task_surface_integrity.json",
            "public_surface_qa.json",
            "Public surface QA",
        ],
        "forbidden": ["xperience10m-" + "taskfirst-v10"],
    },
    {
        "id": "hf_model_card_current",
        "title": "HF model card links quality gates",
        "url": "https://huggingface.co/cy0307/ropedia-xperience-10m-task-baselines/raw/main/README.md",
        "required": [
            "QUALITY_GATES.md",
            "metrics/quality_gates.json",
            "xperience10m_dataset_card_alignment.json",
            "source_alignment_audit.json",
            "evaluation_protocol.json",
            "research_takeaways.json",
            "Research Takeaways",
            "figure_index.json",
            "brand_assets.json",
            "xperience10m-logo-social-card.png",
            "project_status.json",
            "cc-by-nc-4.0",
            "12,103 episode folders",
            "interactive scrub/play storyboard",
            "task_surface_integrity.json",
            "public_surface_qa.json",
            "Public surface QA",
        ],
        "forbidden": ["xperience10m-" + "taskfirst-v10"],
    },
]

PATH_HYGIENE_REPORTS = {
    "mirror_parity": {
        "title": "Mirror parity JSON hides local paths",
        "paths": {
            "github_pages": "https://chaoyue0307.github.io/ropedia-xperience-10m-task-suite/data/mirror_parity.json",
            "hf_space": "https://huggingface.co/spaces/cy0307/ropedia-xperience-10m-task-suite/raw/main/data/mirror_parity.json",
            "hf_artifacts": "https://huggingface.co/datasets/cy0307/ropedia-xperience-10m-task-suite-artifacts/resolve/main/docs/data/mirror_parity.json",
            "hf_model": "https://huggingface.co/cy0307/ropedia-xperience-10m-task-baselines/resolve/main/metrics/mirror_parity.json",
        },
    },
    "publication_audit": {
        "title": "Publication audit JSON hides local paths",
        "paths": {
            "github_pages": "https://chaoyue0307.github.io/ropedia-xperience-10m-task-suite/data/publication_audit.json",
            "hf_space": "https://huggingface.co/spaces/cy0307/ropedia-xperience-10m-task-suite/raw/main/data/publication_audit.json",
            "hf_artifacts": "https://huggingface.co/datasets/cy0307/ropedia-xperience-10m-task-suite-artifacts/resolve/main/docs/data/publication_audit.json",
            "hf_model": "https://huggingface.co/cy0307/ropedia-xperience-10m-task-baselines/resolve/main/metrics/publication_audit.json",
        },
    },
    "website_integrity": {
        "title": "Website integrity JSON hides local paths",
        "paths": {
            "github_pages": "https://chaoyue0307.github.io/ropedia-xperience-10m-task-suite/data/website_integrity.json",
            "hf_space": "https://huggingface.co/spaces/cy0307/ropedia-xperience-10m-task-suite/raw/main/data/website_integrity.json",
            "hf_artifacts": "https://huggingface.co/datasets/cy0307/ropedia-xperience-10m-task-suite-artifacts/resolve/main/docs/data/website_integrity.json",
            "hf_model": "https://huggingface.co/cy0307/ropedia-xperience-10m-task-baselines/resolve/main/metrics/website_integrity.json",
        },
    },
    "public_surface_qa": {
        "title": "Public-surface QA JSON hides local paths",
        "paths": {
            "github_pages": "https://chaoyue0307.github.io/ropedia-xperience-10m-task-suite/data/public_surface_qa.json",
            "hf_space": "https://huggingface.co/spaces/cy0307/ropedia-xperience-10m-task-suite/raw/main/data/public_surface_qa.json",
            "hf_artifacts": "https://huggingface.co/datasets/cy0307/ropedia-xperience-10m-task-suite-artifacts/resolve/main/docs/data/public_surface_qa.json",
            "hf_model": "https://huggingface.co/cy0307/ropedia-xperience-10m-task-baselines/resolve/main/metrics/public_surface_qa.json",
        },
    },
}


def path_hygiene_checks() -> list[dict]:
    checks = []
    for report_id, report in PATH_HYGIENE_REPORTS.items():
        for surface, url in report["paths"].items():
            checks.append({
                "id": f"{surface}_{report_id}_path_hygiene",
                "title": f"{surface}: {report['title']}",
                "url": url,
                "required": ['"status": "pass"'],
                "forbidden": LOCAL_PATH_FORBIDDEN_MARKERS,
            })
    return checks


def sha256_bytes(data: bytes) -> str:
    return hashlib.sha256(data).hexdigest()


def sha256_file(path: Path) -> str:
    digest = hashlib.sha256()
    with path.open("rb") as handle:
        for chunk in iter(lambda: handle.read(1024 * 1024), b""):
            digest.update(chunk)
    return digest.hexdigest()


def sanitize_url(url: str) -> str:
    parts = urlsplit(url)
    return urlunsplit((parts.scheme, parts.netloc, parts.path, "", ""))


def fetch(url: str) -> dict:
    request = Request(url, headers={"User-Agent": USER_AGENT})
    try:
        with urlopen(request, timeout=TIMEOUT_SECONDS) as response:
            body = response.read()
            return {
                "ok": True,
                "status_code": int(getattr(response, "status", 200)),
                "bytes": len(body),
                "sha256": sha256_bytes(body),
                "body": body,
                "final_url": sanitize_url(response.geturl()),
            }
    except HTTPError as exc:
        return {
            "ok": False,
            "status_code": exc.code,
            "bytes": 0,
            "sha256": None,
            "error": str(exc),
            "final_url": url,
        }
    except (TimeoutError, OSError) as exc:
        fallback = fetch_with_curl(url)
        if fallback["ok"]:
            return fallback
        return {
            "ok": False,
            "status_code": None,
            "bytes": 0,
            "sha256": None,
            "error": str(exc),
            "final_url": url,
        }
    except URLError as exc:
        fallback = fetch_with_curl(url)
        if fallback["ok"]:
            return fallback
        return {
            "ok": False,
            "status_code": None,
            "bytes": 0,
            "sha256": None,
            "error": str(exc.reason),
            "final_url": url,
        }


def fetch_with_curl(url: str) -> dict:
    with tempfile.NamedTemporaryFile(delete=False) as tmp:
        tmp_path = Path(tmp.name)
    try:
        result = subprocess.run(
            [
                "curl",
                "-L",
                "-sS",
                "--max-time",
                str(TIMEOUT_SECONDS),
                "-A",
                USER_AGENT,
                "-o",
                str(tmp_path),
                "-w",
                "%{http_code}\n%{url_effective}",
                url,
            ],
            check=False,
            capture_output=True,
            text=True,
        )
        status_text, _, final_url = result.stdout.partition("\n")
        status_code = int(status_text.strip() or "0")
        body = tmp_path.read_bytes() if tmp_path.exists() else b""
        if result.returncode != 0:
            return {
                "ok": False,
                "status_code": status_code or None,
                "bytes": 0,
                "sha256": None,
                "error": result.stderr.strip() or f"curl exited {result.returncode}",
                "final_url": sanitize_url(final_url.strip() or url),
            }
        return {
            "ok": 200 <= status_code < 400,
            "status_code": status_code,
            "bytes": len(body),
            "sha256": sha256_bytes(body),
            "body": body,
            "final_url": sanitize_url(final_url.strip() or url),
        }
    finally:
        tmp_path.unlink(missing_ok=True)


def hash_group_record(group: dict) -> dict:
    local_path = ROOT / group["local_path"]
    local = {
        "path": group["local_path"],
        "exists": local_path.exists(),
        "bytes": local_path.stat().st_size if local_path.exists() else 0,
        "sha256": sha256_file(local_path) if local_path.exists() else None,
    }
    mirrors = {}
    failures = []
    if not local["exists"]:
        failures.append({"surface": "local", "kind": "missing", "path": group["local_path"]})
    for surface, url in group["urls"].items():
        result = fetch(url)
        record = {key: value for key, value in result.items() if key != "body"}
        record["url"] = url
        mirrors[surface] = record
        if not result["ok"]:
            failures.append({"surface": surface, "kind": "fetch_failed", "url": url, "error": result.get("error")})
            continue
        if local["exists"] and result["sha256"] != local["sha256"]:
            failures.append(
                {
                    "surface": surface,
                    "kind": "hash_mismatch",
                    "url": url,
                    "expected_sha256": local["sha256"],
                    "actual_sha256": result["sha256"],
                }
            )
    return {
        "id": group["id"],
        "title": group["title"],
        "status": "pass" if not failures else "fail",
        "local": local,
        "mirrors": mirrors,
        "failures": failures,
    }


def marker_record(check: dict) -> dict:
    result = fetch(check["url"])
    failures = []
    missing = []
    forbidden_hits = []
    if not result["ok"]:
        failures.append({"kind": "fetch_failed", "url": check["url"], "error": result.get("error")})
        text = ""
    else:
        text = result["body"].decode("utf-8", errors="ignore")
        missing = [marker for marker in check["required"] if marker not in text]
        forbidden_hits = [marker for marker in check["forbidden"] if marker in text]
        if missing:
            failures.append({"kind": "missing_required_markers", "markers": missing})
        if forbidden_hits:
            failures.append({"kind": "forbidden_markers_present", "markers": forbidden_hits})
    return {
        "id": check["id"],
        "title": check["title"],
        "url": check["url"],
        "status": "pass" if not failures else "fail",
        "fetch": {key: value for key, value in result.items() if key != "body"},
        "required_marker_count": len(check["required"]),
        "missing_markers": missing,
        "forbidden_markers_present": forbidden_hits,
        "failures": failures,
    }


def build_report() -> dict:
    hash_records = [hash_group_record(group) for group in HASH_GROUPS]
    marker_records = [marker_record(check) for check in [*MARKER_CHECKS, *path_hygiene_checks()]]
    failures = [
        {"check": record["id"], **failure}
        for record in [*hash_records, *marker_records]
        for failure in record["failures"]
    ]
    return {
        "title": "Ropedia Xperience-10M Live Publication Status",
        "status": "pass" if not failures else "fail",
        "checked_at_utc": datetime.now(timezone.utc).isoformat(timespec="seconds"),
        "scope": "Live GitHub Pages, GitHub raw, Hugging Face Space, artifact dataset, and model card mirrors.",
        "hash_groups": hash_records,
        "marker_checks": marker_records,
        "failure_count": len(failures),
        "failures": failures,
    }


def main() -> int:
    parser = argparse.ArgumentParser()
    parser.add_argument("--output", type=Path, default=DEFAULT_OUTPUT)
    parser.add_argument("--no-write", action="store_true", help="Verify and print status without updating the report file.")
    args = parser.parse_args()

    report = build_report()
    if not args.no_write:
        args.output.parent.mkdir(parents=True, exist_ok=True)
        args.output.write_text(json.dumps(report, indent=2) + "\n", encoding="utf-8")
        print(f"{report['status'].upper()}: wrote {args.output}")
    else:
        print(f"{report['status'].upper()}: live publication verification")
    if report["status"] != "pass":
        for failure in report["failures"][:20]:
            print(f"- {failure}")
        if len(report["failures"]) > 20:
            print(f"- ... {len(report['failures']) - 20} more failures")
        return 1
    return 0


if __name__ == "__main__":
    raise SystemExit(main())