RFTSystems commited on
Commit
2976335
·
verified ·
1 Parent(s): 10846ce

Update drp/bundle.py

Browse files
Files changed (1) hide show
  1. drp/bundle.py +10 -9
drp/bundle.py CHANGED
@@ -5,7 +5,7 @@ import zipfile
5
  from dataclasses import dataclass
6
  from typing import Any, Dict, List, Optional, Tuple
7
 
8
- from .canon import DRP_BUNDLE_SPEC, DRP_EVENT_SPEC, canon, hash_event, now_utc_iso
9
 
10
 
11
  @dataclass
@@ -55,7 +55,6 @@ def verify_bundle(zip_path: str) -> Tuple[bool, Dict[str, Any]]:
55
  issues.append("no events found")
56
  return (False, {"ok": False, "issues": issues})
57
 
58
- # verify event specs + hashes + chain
59
  prev_hash: Optional[str] = None
60
  for idx, ev in enumerate(events):
61
  if ev.get("spec") != DRP_EVENT_SPEC:
@@ -65,10 +64,7 @@ def verify_bundle(zip_path: str) -> Tuple[bool, Dict[str, Any]]:
65
  if ev.get("hash") != computed:
66
  issues.append(f"event[{idx}] hash mismatch")
67
 
68
- if idx == 0:
69
- # first event may have prev = None / "" or absent
70
- pass
71
- else:
72
  if ev.get("prev") != prev_hash:
73
  issues.append(f"event[{idx}] prev pointer mismatch")
74
 
@@ -82,6 +78,7 @@ def verify_bundle(zip_path: str) -> Tuple[bool, Dict[str, Any]]:
82
  "run_id": b.manifest.get("run_id"),
83
  "created_at": b.manifest.get("created_at"),
84
  "framework": b.manifest.get("framework"),
 
85
  }
86
  return (ok, summary)
87
 
@@ -95,6 +92,8 @@ def write_bundle_zip(
95
  env_fingerprint: Dict[str, Any],
96
  events_payloads: List[Dict[str, Any]],
97
  created_at: Optional[str] = None,
 
 
98
  ) -> str:
99
  """
100
  Creates a DRP bundle zip:
@@ -103,7 +102,7 @@ def write_bundle_zip(
103
  """
104
  created_at = created_at or now_utc_iso()
105
 
106
- manifest = {
107
  "spec": DRP_BUNDLE_SPEC,
108
  "run_id": run_id,
109
  "created_at": created_at,
@@ -111,6 +110,10 @@ def write_bundle_zip(
111
  "model_id": model_id,
112
  "env": env_fingerprint,
113
  }
 
 
 
 
114
 
115
  events: List[Dict[str, Any]] = []
116
  prev_hash: Optional[str] = None
@@ -128,11 +131,9 @@ def write_bundle_zip(
128
  prev_hash = ev["hash"]
129
  events.append(ev)
130
 
131
- # write zip
132
  os.makedirs(os.path.dirname(out_zip_path) or ".", exist_ok=True)
133
  with zipfile.ZipFile(out_zip_path, "w", compression=zipfile.ZIP_DEFLATED) as z:
134
  z.writestr("manifest.json", json.dumps(manifest, ensure_ascii=False, indent=2))
135
- # jsonl
136
  buf = io.StringIO()
137
  for ev in events:
138
  buf.write(json.dumps(ev, ensure_ascii=False, separators=(",", ":")))
 
5
  from dataclasses import dataclass
6
  from typing import Any, Dict, List, Optional, Tuple
7
 
8
+ from .canon import DRP_BUNDLE_SPEC, DRP_EVENT_SPEC, hash_event, now_utc_iso
9
 
10
 
11
  @dataclass
 
55
  issues.append("no events found")
56
  return (False, {"ok": False, "issues": issues})
57
 
 
58
  prev_hash: Optional[str] = None
59
  for idx, ev in enumerate(events):
60
  if ev.get("spec") != DRP_EVENT_SPEC:
 
64
  if ev.get("hash") != computed:
65
  issues.append(f"event[{idx}] hash mismatch")
66
 
67
+ if idx > 0:
 
 
 
68
  if ev.get("prev") != prev_hash:
69
  issues.append(f"event[{idx}] prev pointer mismatch")
70
 
 
78
  "run_id": b.manifest.get("run_id"),
79
  "created_at": b.manifest.get("created_at"),
80
  "framework": b.manifest.get("framework"),
81
+ "model_id": b.manifest.get("model_id"),
82
  }
83
  return (ok, summary)
84
 
 
92
  env_fingerprint: Dict[str, Any],
93
  events_payloads: List[Dict[str, Any]],
94
  created_at: Optional[str] = None,
95
+ replay: Optional[Dict[str, Any]] = None,
96
+ run_url: Optional[str] = None,
97
  ) -> str:
98
  """
99
  Creates a DRP bundle zip:
 
102
  """
103
  created_at = created_at or now_utc_iso()
104
 
105
+ manifest: Dict[str, Any] = {
106
  "spec": DRP_BUNDLE_SPEC,
107
  "run_id": run_id,
108
  "created_at": created_at,
 
110
  "model_id": model_id,
111
  "env": env_fingerprint,
112
  }
113
+ if replay:
114
+ manifest["replay"] = replay
115
+ if run_url:
116
+ manifest["run_url"] = run_url
117
 
118
  events: List[Dict[str, Any]] = []
119
  prev_hash: Optional[str] = None
 
131
  prev_hash = ev["hash"]
132
  events.append(ev)
133
 
 
134
  os.makedirs(os.path.dirname(out_zip_path) or ".", exist_ok=True)
135
  with zipfile.ZipFile(out_zip_path, "w", compression=zipfile.ZIP_DEFLATED) as z:
136
  z.writestr("manifest.json", json.dumps(manifest, ensure_ascii=False, indent=2))
 
137
  buf = io.StringIO()
138
  for ev in events:
139
  buf.write(json.dumps(ev, ensure_ascii=False, separators=(",", ":")))