Skip to content

Commit 13c2f4f

Browse files
committed
Close mp-300k gate review findings
1 parent cd71d63 commit 13c2f4f

4 files changed

Lines changed: 54 additions & 16 deletions

File tree

src/microplex_us/pipelines/mp300k_artifact_gates.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,14 +464,23 @@ def _runtime_gate(
464464
if runtime_smoke_payload is None:
465465
return _gate("unmeasured", "runtime smoke benchmark has not been attached")
466466
payload = dict(runtime_smoke_payload)
467-
threshold = float(payload.get("runtime_ratio_threshold", runtime_ratio_threshold))
467+
threshold = float(runtime_ratio_threshold)
468468
ratio = payload.get("runtime_ratio")
469469
candidate_seconds = payload.get("candidate_seconds")
470470
baseline_seconds = payload.get("baseline_seconds")
471471
if ratio is None and candidate_seconds is not None and baseline_seconds:
472472
ratio = float(candidate_seconds) / float(baseline_seconds)
473473
passes = payload.get("passes_runtime_gate")
474474
details: dict[str, Any] = {}
475+
reported_threshold = payload.get("runtime_ratio_threshold")
476+
reported_threshold_matches = False
477+
try:
478+
reported_threshold_matches = float(reported_threshold) == threshold
479+
except (TypeError, ValueError):
480+
pass
481+
if reported_threshold is not None and not reported_threshold_matches:
482+
details["reported_runtime_ratio_threshold"] = reported_threshold
483+
details["enforced_runtime_ratio_threshold"] = threshold
475484
if ratio is None:
476485
return _gate(
477486
"unmeasured",

src/microplex_us/pipelines/mp300k_gate_inputs.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,15 @@ def _resolve_baseline_dataset_path(
165165
return baseline_path
166166

167167

168+
def _safe_archive_relpath(candidate: Path, *, fallback: Path) -> Path:
169+
if candidate.is_absolute() or ".." in candidate.parts:
170+
return fallback
171+
normalized_parts = [part for part in candidate.parts if part not in ("", ".")]
172+
if not normalized_parts:
173+
return fallback
174+
return Path(*normalized_parts)
175+
176+
168177
def _candidate_archive_relpath(
169178
manifest: dict[str, Any],
170179
*,
@@ -175,9 +184,10 @@ def _candidate_archive_relpath(
175184
return Path(candidate_dataset.name)
176185
dataset_name = dict(manifest.get("artifacts", {})).get("policyengine_dataset")
177186
if isinstance(dataset_name, str) and dataset_name:
178-
relpath = Path(dataset_name)
179-
if not relpath.is_absolute():
180-
return relpath
187+
return _safe_archive_relpath(
188+
Path(dataset_name),
189+
fallback=Path(candidate_dataset.name),
190+
)
181191
return Path(candidate_dataset.name)
182192

183193

@@ -191,9 +201,10 @@ def _baseline_archive_relpath(
191201
return Path("baseline") / baseline_dataset.name
192202
value = dict(manifest.get("config", {})).get("policyengine_baseline_dataset")
193203
if isinstance(value, str) and value:
194-
relpath = Path(value)
195-
if not relpath.is_absolute():
196-
return relpath
204+
return _safe_archive_relpath(
205+
Path(value),
206+
fallback=Path("baseline") / baseline_dataset.name,
207+
)
197208
return Path("baseline") / baseline_dataset.name
198209

199210

tests/pipelines/test_mp300k_artifact_gates.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,11 @@ def test_runtime_gate_ignores_contradictory_producer_verdict(tmp_path):
280280
},
281281
runtime_smoke_payload={
282282
"runtime_ratio": 10.0,
283-
"runtime_ratio_threshold": 1.25,
283+
"runtime_ratio_threshold": 100.0,
284284
"passes_runtime_gate": True,
285285
},
286286
benchmark_manifest_path=benchmark_manifest,
287+
runtime_ratio_threshold=1.25,
287288
compute_native_scores=False,
288289
update_manifest=False,
289290
)
@@ -293,6 +294,9 @@ def test_runtime_gate_ignores_contradictory_producer_verdict(tmp_path):
293294

294295
assert record["summary"]["status"] == "failed"
295296
assert runtime_gate["status"] == "fail"
297+
assert runtime_gate["metrics"]["runtime_ratio_threshold"] == 1.25
298+
assert runtime_gate["details"]["reported_runtime_ratio_threshold"] == 100.0
299+
assert runtime_gate["details"]["enforced_runtime_ratio_threshold"] == 1.25
296300
assert runtime_gate["details"]["reported_passes_runtime_gate"] is True
297301
assert runtime_gate["details"]["computed_passes_runtime_gate"] is False
298302

tests/pipelines/test_mp300k_gate_inputs.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,21 @@ def _write_minimal_policyengine_dataset(path: Path, *, period: int = 2024) -> Pa
2828
return write_policyengine_us_time_period_dataset(arrays, path)
2929

3030

31-
def _write_manifest(artifact_dir: Path) -> None:
31+
def _write_manifest(
32+
artifact_dir: Path,
33+
*,
34+
candidate_path: str = "policyengine_us.h5",
35+
baseline_path: str = "baseline/enhanced_cps_2024.h5",
36+
) -> None:
3237
(artifact_dir / "manifest.json").write_text(
3338
json.dumps(
3439
{
3540
"created_at": "2026-05-27T00:00:00+00:00",
3641
"config": {
3742
"policyengine_dataset_year": 2024,
38-
"policyengine_baseline_dataset": "baseline/enhanced_cps_2024.h5",
43+
"policyengine_baseline_dataset": baseline_path,
3944
},
40-
"artifacts": {"policyengine_dataset": "policyengine_us.h5"},
45+
"artifacts": {"policyengine_dataset": candidate_path},
4146
}
4247
)
4348
)
@@ -129,21 +134,29 @@ def test_main_packages_gate_inputs(tmp_path, capsys):
129134
def test_packaged_inputs_run_gates_from_clean_extract(tmp_path):
130135
artifact_dir = tmp_path / "artifact"
131136
artifact_dir.mkdir()
132-
_write_manifest(artifact_dir)
133-
external_candidate = _write_minimal_policyengine_dataset(tmp_path / "candidate.h5")
134-
external_baseline = _write_minimal_policyengine_dataset(tmp_path / "baseline.h5")
137+
_write_manifest(
138+
artifact_dir,
139+
candidate_path="../candidate.h5",
140+
baseline_path="../baseline.h5",
141+
)
142+
_write_minimal_policyengine_dataset(tmp_path / "candidate.h5")
143+
_write_minimal_policyengine_dataset(tmp_path / "baseline.h5")
135144
benchmark_manifest = tmp_path / "benchmark.json"
136145
benchmark_manifest.write_text(json.dumps({"schema_version": 1}))
137146
output_dir = tmp_path / "gate-inputs"
138147

139148
package_mp300k_gate_inputs(
140149
artifact_dir,
141150
output_dir,
142-
candidate_dataset_path=external_candidate,
143-
baseline_dataset_path=external_baseline,
144151
benchmark_manifest_path=benchmark_manifest,
145152
)
146153

154+
packaged_manifest = _archive_manifest(output_dir / "artifact.tar.gz")
155+
assert packaged_manifest["artifacts"]["policyengine_dataset"] == "candidate.h5"
156+
assert (
157+
packaged_manifest["config"]["policyengine_baseline_dataset"]
158+
== "baseline/baseline.h5"
159+
)
147160
extract_root = tmp_path / "extract"
148161
with tarfile.open(output_dir / "artifact.tar.gz") as archive:
149162
archive.extractall(extract_root, filter="data")
@@ -168,5 +181,6 @@ def test_packaged_inputs_run_gates_from_clean_extract(tmp_path):
168181
report = json.loads(report_path.read_text())
169182

170183
assert report["summary"]["status"] == "passed"
184+
assert report["candidate_dataset"]["path"].startswith(str(packaged_artifact_dir))
171185
assert report["baseline_dataset"]["path"].startswith(str(packaged_artifact_dir))
172186
assert report["gates"]["artifact_size"]["status"] == "pass"

0 commit comments

Comments
 (0)