Junhao Wu commited on
Commit
7a90b8c
·
verified ·
1 Parent(s): 2909fe6

Add watermark artifact repository specification v1.0

Browse files
README.md CHANGED
@@ -1,3 +1,77 @@
1
  ---
2
  license: apache-2.0
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
+ tags:
4
+ - robotics
5
+ - adversarial-watermark
6
+ - libero
7
+ - robotwin
8
  ---
9
+
10
+ # Attack-WAM Watermark Artifacts
11
+
12
+ This repository stores generated watermark artifacts for RoboTwin and four
13
+ LIBERO suites. It separates full-data runs from dataset-ablation runs and uses
14
+ one stable layout across machines.
15
+
16
+ ## Coverage
17
+
18
+ - Benchmarks: `libero`, `robotwin`
19
+ - LIBERO suites: `long`, `goal`, `object`, `spatial`
20
+ - RoboTwin suite key: `main`
21
+ - Regimes: `full`, `ablation/episode_pool`, `ablation/task_fraction`
22
+ - Variants:
23
+ - `direct_A1V0`
24
+ - `direct_A0V1`
25
+ - `direct_A1V1`
26
+ - `de_proj_A1V0`
27
+ - `de_proj_A0V1`
28
+ - `bisect_A1V1`
29
+
30
+ ## Canonical paths
31
+
32
+ ```text
33
+ artifacts/full/libero/<long|goal|object|spatial>/<variant>/
34
+ artifacts/full/robotwin/main/<variant>/
35
+
36
+ artifacts/ablation/episode_pool/libero/<suite>/top_<10|20|30|40|50>/<variant>/
37
+ artifacts/ablation/episode_pool/robotwin/main/top_<10|20|30|40|50>/<variant>/
38
+
39
+ artifacts/ablation/task_fraction/libero/<suite>/p<10..90>/<variant>/
40
+ artifacts/ablation/task_fraction/robotwin/main/p<10..90>/<variant>/
41
+ ```
42
+
43
+ Each leaf directory follows:
44
+
45
+ ```text
46
+ <variant>/
47
+ ├── metadata.json # required
48
+ ├── top1.npy # required
49
+ ├── top2.npy # recommended
50
+ ├── top3.npy # recommended
51
+ ├── top4.npy # recommended
52
+ ├── top5.npy # recommended
53
+ ├── final.npy # recommended
54
+ └── optimization.jsonl # optional
55
+ ```
56
+
57
+ `top1.npy` is the default artifact for evaluation. `final.npy` is the last
58
+ optimization state and is not necessarily the best state.
59
+
60
+ See [SPEC.md](SPEC.md) for naming, metadata, and upload requirements.
61
+
62
+ ## Validation
63
+
64
+ Run before every upload:
65
+
66
+ ```bash
67
+ python tools/validate_repository.py /path/to/local/repository
68
+ ```
69
+
70
+ Use `--require-complete-full` to require all 30 full-data combinations
71
+ (five dataset suites times six variants).
72
+
73
+ ## Repository manifest
74
+
75
+ `manifest.json` is the machine-readable index. Uploading machines must update
76
+ it after placing artifacts. Paths in the manifest are repository-relative and
77
+ must never contain local filesystem paths or credentials.
SPEC.md ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Watermark Repository Specification
2
+
3
+ ## 1. Version
4
+
5
+ The current schema version is `1.0.0`. Every `metadata.json` and the root
6
+ `manifest.json` must declare this version.
7
+
8
+ ## 2. Dataset identities
9
+
10
+ | Benchmark | Suite key | Display name |
11
+ |---|---|---|
12
+ | `libero` | `long` | LIBERO-Long |
13
+ | `libero` | `goal` | LIBERO-Goal |
14
+ | `libero` | `object` | LIBERO-Object |
15
+ | `libero` | `spatial` | LIBERO-Spatial |
16
+ | `robotwin` | `main` | RoboTwin |
17
+
18
+ Do not use machine-specific aliases as suite keys.
19
+
20
+ ## 3. Regimes
21
+
22
+ ### Full data
23
+
24
+ ```text
25
+ artifacts/full/<benchmark>/<suite>/<variant>/
26
+ ```
27
+
28
+ Full runs must have:
29
+
30
+ - `ablation: null`
31
+ - no task-range restriction
32
+ - no episode-pool restriction
33
+ - the complete official suite for the declared dataset revision
34
+
35
+ ### Episode-pool ablation
36
+
37
+ ```text
38
+ artifacts/ablation/episode_pool/<benchmark>/<suite>/top_<N>/<variant>/
39
+ ```
40
+
41
+ `N` is one of `10, 20, 30, 40, 50`. One episode is selected per task, but the
42
+ random choice is restricted to the first `N` episodes. Metadata must record
43
+ the random seed and `episode_pool_limit`.
44
+
45
+ ### Task-fraction ablation
46
+
47
+ ```text
48
+ artifacts/ablation/task_fraction/<benchmark>/<suite>/p<P>/<variant>/
49
+ ```
50
+
51
+ `P` is one of `10, 20, ..., 90`. Metadata must record the exact selected task
52
+ count, exact task identifiers, epochs, and target optimization budget. Do not
53
+ infer the selected tasks only from the percentage.
54
+
55
+ ## 4. Variant identities
56
+
57
+ `A` means action-loss weight and `V` means video-loss weight.
58
+
59
+ | Variant | Method | Action weight | Video weight |
60
+ |---|---:|---:|---:|
61
+ | `direct_A1V0` | `direct` | 1 | 0 |
62
+ | `direct_A0V1` | `direct` | 0 | 1 |
63
+ | `direct_A1V1` | `direct` | 1 | 1 |
64
+ | `de_proj_A1V0` | `de_proj` | 1 | 0 |
65
+ | `de_proj_A0V1` | `de_proj` | 0 | 1 |
66
+ | `bisect_A1V1` | `bisect` | 1 | 1 |
67
+
68
+ The directory name is authoritative. Metadata weights must agree with it.
69
+
70
+ ## 5. Required artifact semantics
71
+
72
+ - `top1.npy`: best-ranked patch under the run's declared selection metric.
73
+ - `top2.npy` through `top5.npy`: remaining ranked patches.
74
+ - `final.npy`: patch at termination.
75
+ - `optimization.jsonl`: optional per-step trace.
76
+ - `metadata.json`: required provenance and integrity record.
77
+
78
+ Watermarks must be stored as NumPy arrays. For the current eye-in-hand setup,
79
+ the expected logical patch size is `128 x 128`; the exact array layout and
80
+ dtype must be declared in metadata.
81
+
82
+ ## 6. Metadata requirements
83
+
84
+ Every metadata file must include:
85
+
86
+ - benchmark, suite, regime, variant, and weights
87
+ - public dataset repository and immutable revision
88
+ - public model repository and immutable revision
89
+ - selected tasks/episodes or the explicit full-data declaration
90
+ - seed, camera, patch parameters, optimization settings, and stopping reason
91
+ - Attack-WAM commit and hashes of the three critical source files
92
+ - Python, PyTorch, CUDA build, runtime cuDNN, GPU, and SDPA policy
93
+ - artifact paths, byte sizes, and SHA-256 hashes
94
+ - run status and any recovered anomaly
95
+
96
+ Never upload local absolute paths, access tokens, usernames, hostnames, or
97
+ private cache paths.
98
+
99
+ ## 7. Status values
100
+
101
+ - `complete`: clean completion.
102
+ - `complete_with_note`: usable completion with a documented recovered event.
103
+ - `failed`: not valid for evaluation.
104
+
105
+ Only `complete` and `complete_with_note` runs belong in the root manifest.
106
+
107
+ ## 8. Upload rules
108
+
109
+ 1. Stage artifacts outside the source-code repository.
110
+ 2. Rename artifacts to the canonical filenames.
111
+ 3. Generate SHA-256 hashes and update metadata.
112
+ 4. Update `manifest.json`.
113
+ 5. Run the validator.
114
+ 6. Upload only the staging directory.
115
+
116
+ Example:
117
+
118
+ ```bash
119
+ hf upload Wjjjh/Attack /path/to/staging . \
120
+ --exclude "**/.DS_Store" \
121
+ --exclude "**/__pycache__/**"
122
+ ```
123
+
124
+ Do not run `hf upload Wjjjh/Attack .` from an Attack-WAM source checkout.
manifest.json ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "schema_version": "1.0.0",
3
+ "repository": "Wjjjh/Attack",
4
+ "artifact_root": "artifacts",
5
+ "datasets": [
6
+ {"benchmark": "libero", "suite": "long"},
7
+ {"benchmark": "libero", "suite": "goal"},
8
+ {"benchmark": "libero", "suite": "object"},
9
+ {"benchmark": "libero", "suite": "spatial"},
10
+ {"benchmark": "robotwin", "suite": "main"}
11
+ ],
12
+ "variants": [
13
+ "direct_A1V0",
14
+ "direct_A0V1",
15
+ "direct_A1V1",
16
+ "de_proj_A1V0",
17
+ "de_proj_A0V1",
18
+ "bisect_A1V1"
19
+ ],
20
+ "runs": []
21
+ }
schemas/manifest.schema.json ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://huggingface.co/Wjjjh/Attack/raw/main/schemas/manifest.schema.json",
4
+ "title": "Attack-WAM artifact manifest",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": ["schema_version", "repository", "artifact_root", "datasets", "variants", "runs"],
8
+ "properties": {
9
+ "schema_version": {"const": "1.0.0"},
10
+ "repository": {"const": "Wjjjh/Attack"},
11
+ "artifact_root": {"const": "artifacts"},
12
+ "datasets": {
13
+ "type": "array",
14
+ "items": {
15
+ "type": "object",
16
+ "additionalProperties": false,
17
+ "required": ["benchmark", "suite"],
18
+ "properties": {
19
+ "benchmark": {"enum": ["libero", "robotwin"]},
20
+ "suite": {"enum": ["long", "goal", "object", "spatial", "main"]}
21
+ }
22
+ }
23
+ },
24
+ "variants": {
25
+ "type": "array",
26
+ "items": {
27
+ "enum": [
28
+ "direct_A1V0", "direct_A0V1", "direct_A1V1",
29
+ "de_proj_A1V0", "de_proj_A0V1", "bisect_A1V1"
30
+ ]
31
+ }
32
+ },
33
+ "runs": {
34
+ "type": "array",
35
+ "items": {
36
+ "type": "object",
37
+ "additionalProperties": false,
38
+ "required": ["experiment_id", "metadata_path", "status"],
39
+ "properties": {
40
+ "experiment_id": {"type": "string", "minLength": 1},
41
+ "metadata_path": {"type": "string", "pattern": "^artifacts/.+/metadata\\.json$"},
42
+ "status": {"enum": ["complete", "complete_with_note"]}
43
+ }
44
+ }
45
+ }
46
+ }
47
+ }
schemas/metadata.schema.json ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://huggingface.co/Wjjjh/Attack/raw/main/schemas/metadata.schema.json",
4
+ "title": "Attack-WAM watermark run metadata",
5
+ "type": "object",
6
+ "required": [
7
+ "schema_version", "experiment_id", "status", "benchmark", "suite",
8
+ "regime", "ablation", "variant", "data", "model", "attack", "result",
9
+ "code", "environment", "artifacts"
10
+ ],
11
+ "properties": {
12
+ "schema_version": {"const": "1.0.0"},
13
+ "experiment_id": {"type": "string", "minLength": 1},
14
+ "status": {"enum": ["complete", "complete_with_note", "failed"]},
15
+ "benchmark": {"enum": ["libero", "robotwin"]},
16
+ "suite": {"enum": ["long", "goal", "object", "spatial", "main"]},
17
+ "regime": {"enum": ["full", "episode_pool", "task_fraction"]},
18
+ "ablation": {"type": ["object", "null"]},
19
+ "variant": {
20
+ "type": "object",
21
+ "required": ["name", "method", "action_loss_weight", "video_loss_weight", "vae_loss_weight"],
22
+ "properties": {
23
+ "name": {
24
+ "enum": [
25
+ "direct_A1V0", "direct_A0V1", "direct_A1V1",
26
+ "de_proj_A1V0", "de_proj_A0V1", "bisect_A1V1"
27
+ ]
28
+ },
29
+ "method": {"enum": ["direct", "de_proj", "bisect"]},
30
+ "action_loss_weight": {"type": "number"},
31
+ "video_loss_weight": {"type": "number"},
32
+ "vae_loss_weight": {"type": "number"}
33
+ }
34
+ },
35
+ "data": {"type": "object"},
36
+ "model": {"type": "object"},
37
+ "attack": {"type": "object"},
38
+ "result": {"type": "object"},
39
+ "code": {"type": "object"},
40
+ "environment": {"type": "object"},
41
+ "artifacts": {
42
+ "type": "array",
43
+ "minItems": 1,
44
+ "items": {
45
+ "type": "object",
46
+ "required": ["role", "path", "sha256", "bytes"],
47
+ "properties": {
48
+ "role": {"enum": ["top1", "top2", "top3", "top4", "top5", "final", "optimization"]},
49
+ "path": {"type": "string"},
50
+ "sha256": {"type": "string", "pattern": "^[0-9a-f]{64}$"},
51
+ "bytes": {"type": "integer", "minimum": 0}
52
+ }
53
+ }
54
+ }
55
+ }
56
+ }
templates/metadata.json ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "schema_version": "1.0.0",
3
+ "experiment_id": "full/libero/goal/direct_A1V0",
4
+ "status": "complete",
5
+ "benchmark": "libero",
6
+ "suite": "goal",
7
+ "regime": "full",
8
+ "ablation": null,
9
+ "variant": {
10
+ "name": "direct_A1V0",
11
+ "method": "direct",
12
+ "action_loss_weight": 1.0,
13
+ "video_loss_weight": 0.0,
14
+ "vae_loss_weight": 0.0
15
+ },
16
+ "data": {
17
+ "repo_id": "yifengzhu-hf/LIBERO-datasets",
18
+ "revision": "REPLACE_WITH_IMMUTABLE_REVISION",
19
+ "is_full_suite": true,
20
+ "task_count": 10,
21
+ "episodes_per_task": 50,
22
+ "selected_task_ids": []
23
+ },
24
+ "model": {
25
+ "repo_id": "REPLACE_WITH_MODEL_REPO",
26
+ "revision": "REPLACE_WITH_IMMUTABLE_REVISION",
27
+ "checkpoint_file": "transformer/diffusion_pytorch_model.safetensors"
28
+ },
29
+ "attack": {
30
+ "seed": 42,
31
+ "fixed_seed": false,
32
+ "camera": "observation.images.eye_in_hand_rgb",
33
+ "patch_size": [128, 128],
34
+ "patch_position": [0, 0],
35
+ "patch_alpha": 0.12549,
36
+ "patch_lr": 0.01,
37
+ "frames_per_episode": 64,
38
+ "frame_batch_size": 4,
39
+ "video_inference_steps": 2,
40
+ "action_inference_steps": 5,
41
+ "dataset_epochs": 60,
42
+ "save_every_steps": 160,
43
+ "early_stop_patience": 8,
44
+ "top5_selection": "all"
45
+ },
46
+ "result": {
47
+ "final_step": 0,
48
+ "stop_reason": "early_stopping",
49
+ "selection_metric": "all",
50
+ "notes": []
51
+ },
52
+ "code": {
53
+ "repo_id": "MisterRpeng/Attack-WAM",
54
+ "commit": "REPLACE_WITH_COMMIT",
55
+ "critical_file_sha256": {
56
+ "wan_va/modules/model.py": "REPLACE_WITH_SHA256",
57
+ "wan_va/wan_va_server.py": "REPLACE_WITH_SHA256",
58
+ "attack/adversarial_attack/attack_vae_transformer_freeze_manual.py": "REPLACE_WITH_SHA256"
59
+ }
60
+ },
61
+ "environment": {
62
+ "python": "3.10.16",
63
+ "pytorch": "REPLACE",
64
+ "torch_cuda_build": "REPLACE",
65
+ "runtime_cudnn": "REPLACE",
66
+ "gpu": "REPLACE",
67
+ "compute_capability": "REPLACE",
68
+ "attention_mode": "torch",
69
+ "cudnn_sdpa_enabled": true,
70
+ "cudnn_sdpa_forced": false
71
+ },
72
+ "artifacts": [
73
+ {
74
+ "role": "top1",
75
+ "path": "top1.npy",
76
+ "sha256": "REPLACE_WITH_SHA256",
77
+ "bytes": 0,
78
+ "dtype": "REPLACE",
79
+ "shape": []
80
+ }
81
+ ]
82
+ }
tools/validate_repository.py ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Validate an Attack-WAM Hugging Face artifact staging directory."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import argparse
7
+ import hashlib
8
+ import json
9
+ import re
10
+ import sys
11
+ from pathlib import Path
12
+
13
+ SCHEMA_VERSION = "1.0.0"
14
+ VARIANTS = {
15
+ "direct_A1V0": ("direct", 1.0, 0.0),
16
+ "direct_A0V1": ("direct", 0.0, 1.0),
17
+ "direct_A1V1": ("direct", 1.0, 1.0),
18
+ "de_proj_A1V0": ("de_proj", 1.0, 0.0),
19
+ "de_proj_A0V1": ("de_proj", 0.0, 1.0),
20
+ "bisect_A1V1": ("bisect", 1.0, 1.0),
21
+ }
22
+ DATASETS = {
23
+ ("libero", "long"),
24
+ ("libero", "goal"),
25
+ ("libero", "object"),
26
+ ("libero", "spatial"),
27
+ ("robotwin", "main"),
28
+ }
29
+ SHA256_RE = re.compile(r"^[0-9a-f]{64}$")
30
+
31
+
32
+ def digest(path: Path) -> str:
33
+ value = hashlib.sha256()
34
+ with path.open("rb") as handle:
35
+ for chunk in iter(lambda: handle.read(1024 * 1024), b""):
36
+ value.update(chunk)
37
+ return value.hexdigest()
38
+
39
+
40
+ def expected_metadata_path(root: Path, meta: dict) -> Path:
41
+ benchmark = meta["benchmark"]
42
+ suite = meta["suite"]
43
+ variant = meta["variant"]["name"]
44
+ regime = meta["regime"]
45
+ if regime == "full":
46
+ return root / "artifacts" / "full" / benchmark / suite / variant / "metadata.json"
47
+ ablation = meta.get("ablation") or {}
48
+ if regime == "episode_pool":
49
+ limit = int(ablation["episode_pool_limit"])
50
+ return (
51
+ root / "artifacts" / "ablation" / "episode_pool" / benchmark /
52
+ suite / f"top_{limit}" / variant / "metadata.json"
53
+ )
54
+ if regime == "task_fraction":
55
+ percent = int(ablation["task_fraction_percent"])
56
+ return (
57
+ root / "artifacts" / "ablation" / "task_fraction" / benchmark /
58
+ suite / f"p{percent}" / variant / "metadata.json"
59
+ )
60
+ raise ValueError(f"unsupported regime: {regime!r}")
61
+
62
+
63
+ def validate_metadata(root: Path, path: Path) -> list[str]:
64
+ errors: list[str] = []
65
+ try:
66
+ meta = json.loads(path.read_text(encoding="utf-8"))
67
+ except Exception as exc:
68
+ return [f"{path}: invalid JSON: {exc}"]
69
+
70
+ required = {
71
+ "schema_version", "experiment_id", "status", "benchmark", "suite",
72
+ "regime", "variant", "data", "model", "attack", "result", "code",
73
+ "environment", "artifacts",
74
+ }
75
+ missing = sorted(required - set(meta))
76
+ if missing:
77
+ errors.append(f"{path}: missing keys: {', '.join(missing)}")
78
+ return errors
79
+ if meta["schema_version"] != SCHEMA_VERSION:
80
+ errors.append(f"{path}: unsupported schema_version {meta['schema_version']!r}")
81
+ dataset = (meta["benchmark"], meta["suite"])
82
+ if dataset not in DATASETS:
83
+ errors.append(f"{path}: invalid benchmark/suite pair {dataset!r}")
84
+ variant_name = meta["variant"].get("name")
85
+ if variant_name not in VARIANTS:
86
+ errors.append(f"{path}: invalid variant {variant_name!r}")
87
+ else:
88
+ method, action_weight, video_weight = VARIANTS[variant_name]
89
+ actual = (
90
+ meta["variant"].get("method"),
91
+ float(meta["variant"].get("action_loss_weight", -1)),
92
+ float(meta["variant"].get("video_loss_weight", -1)),
93
+ )
94
+ expected = (method, action_weight, video_weight)
95
+ if actual != expected:
96
+ errors.append(f"{path}: variant fields {actual!r} do not match {expected!r}")
97
+ try:
98
+ expected_path = expected_metadata_path(root, meta).resolve()
99
+ if path.resolve() != expected_path:
100
+ errors.append(f"{path}: canonical location is {expected_path}")
101
+ except Exception as exc:
102
+ errors.append(f"{path}: cannot derive canonical path: {exc}")
103
+
104
+ roles: set[str] = set()
105
+ for artifact in meta.get("artifacts", []):
106
+ role = artifact.get("role")
107
+ roles.add(role)
108
+ relative = artifact.get("path", "")
109
+ artifact_path = path.parent / relative
110
+ if Path(relative).is_absolute() or ".." in Path(relative).parts:
111
+ errors.append(f"{path}: unsafe artifact path {relative!r}")
112
+ continue
113
+ if not artifact_path.is_file():
114
+ errors.append(f"{path}: missing artifact {relative!r}")
115
+ continue
116
+ expected_bytes = artifact.get("bytes")
117
+ if expected_bytes != artifact_path.stat().st_size:
118
+ errors.append(
119
+ f"{path}: size mismatch for {relative}: "
120
+ f"{expected_bytes} != {artifact_path.stat().st_size}"
121
+ )
122
+ expected_hash = artifact.get("sha256", "")
123
+ if not SHA256_RE.fullmatch(expected_hash):
124
+ errors.append(f"{path}: invalid SHA-256 for {relative}")
125
+ elif digest(artifact_path) != expected_hash:
126
+ errors.append(f"{path}: SHA-256 mismatch for {relative}")
127
+ if meta["status"] in {"complete", "complete_with_note"} and "top1" not in roles:
128
+ errors.append(f"{path}: completed run does not declare a top1 artifact")
129
+ return errors
130
+
131
+
132
+ def main() -> int:
133
+ parser = argparse.ArgumentParser()
134
+ parser.add_argument("root", nargs="?", default=".")
135
+ parser.add_argument("--require-complete-full", action="store_true")
136
+ args = parser.parse_args()
137
+ root = Path(args.root).resolve()
138
+ errors: list[str] = []
139
+
140
+ manifest_path = root / "manifest.json"
141
+ if not manifest_path.is_file():
142
+ errors.append(f"missing {manifest_path}")
143
+ manifest = {}
144
+ else:
145
+ try:
146
+ manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
147
+ except Exception as exc:
148
+ errors.append(f"{manifest_path}: invalid JSON: {exc}")
149
+ manifest = {}
150
+ if manifest and manifest.get("schema_version") != SCHEMA_VERSION:
151
+ errors.append(f"{manifest_path}: schema_version must be {SCHEMA_VERSION}")
152
+
153
+ metadata_paths = sorted((root / "artifacts").glob("**/metadata.json"))
154
+ for path in metadata_paths:
155
+ errors.extend(validate_metadata(root, path))
156
+
157
+ indexed = {
158
+ item.get("metadata_path")
159
+ for item in manifest.get("runs", [])
160
+ if isinstance(item, dict)
161
+ }
162
+ discovered = {str(path.relative_to(root)) for path in metadata_paths}
163
+ for path in sorted(discovered - indexed):
164
+ errors.append(f"manifest does not index {path}")
165
+ for path in sorted(indexed - discovered):
166
+ errors.append(f"manifest indexes missing metadata {path}")
167
+
168
+ if args.require_complete_full:
169
+ expected = {
170
+ str(Path("artifacts/full") / benchmark / suite / variant / "metadata.json")
171
+ for benchmark, suite in DATASETS
172
+ for variant in VARIANTS
173
+ }
174
+ for path in sorted(expected - discovered):
175
+ errors.append(f"missing full-data run {path}")
176
+
177
+ if errors:
178
+ print("VALIDATION FAILED")
179
+ for error in errors:
180
+ print(f"- {error}")
181
+ return 1
182
+ print(
183
+ f"VALIDATION OK: {len(metadata_paths)} runs, "
184
+ f"{len(manifest.get('runs', []))} manifest entries"
185
+ )
186
+ return 0
187
+
188
+
189
+ if __name__ == "__main__":
190
+ sys.exit(main())