Skip to content

Commit 46bcb28

Browse files
committed
Fix Stage 2 target config checksum format
1 parent a91c9c2 commit 46bcb28

3 files changed

Lines changed: 37 additions & 8 deletions

File tree

policyengine_us_data/calibration_package/specs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def resolve_target_config_identity(
155155
)
156156
return TargetConfigIdentity(
157157
path=logical_path,
158-
sha256=compute_file_checksum(resolved_path),
158+
sha256=f"sha256:{compute_file_checksum(resolved_path)}",
159159
mode=mode,
160160
resolved_path=str(resolved_path),
161161
)

tests/unit/calibration_package/test_specs.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,16 @@
1212
calibration_package_artifact_paths,
1313
resolve_target_config_identity,
1414
)
15+
from policyengine_us_data.stage_contracts.calibration_package import (
16+
CalibrationPackageParameters,
17+
)
1518
from policyengine_us_data.utils.manifest import compute_file_checksum
1619

1720

21+
def _sha256_digest(path: Path) -> str:
22+
return f"sha256:{compute_file_checksum(path)}"
23+
24+
1825
def _write_default_target_config(repo_root: Path, body: str = "include: []\n") -> Path:
1926
config_path = repo_root / DEFAULT_TARGET_CONFIG_PATH
2027
config_path.parent.mkdir(parents=True)
@@ -29,13 +36,13 @@ def test_default_target_config_identity_resolution(tmp_path):
2936

3037
assert identity == TargetConfigIdentity(
3138
path=DEFAULT_TARGET_CONFIG_PATH,
32-
sha256=compute_file_checksum(config_path),
39+
sha256=_sha256_digest(config_path),
3340
mode="default",
3441
resolved_path=str(config_path.resolve()),
3542
)
3643
assert identity.to_parameters() == {
3744
"target_config": DEFAULT_TARGET_CONFIG_PATH,
38-
"target_config_sha256": compute_file_checksum(config_path),
45+
"target_config_sha256": _sha256_digest(config_path),
3946
"target_config_mode": "default",
4047
}
4148

@@ -49,11 +56,33 @@ def test_explicit_target_config_identity_resolution(tmp_path):
4956
)
5057

5158
assert identity.path == DEFAULT_TARGET_CONFIG_PATH
52-
assert identity.sha256 == compute_file_checksum(config_path)
59+
assert identity.sha256 == _sha256_digest(config_path)
5360
assert identity.mode == "explicit"
5461
assert identity.resolved_path == str(config_path.resolve())
5562

5663

64+
def test_resolved_target_config_identity_is_contract_compatible(tmp_path):
65+
_write_default_target_config(tmp_path)
66+
identity = resolve_target_config_identity(repo_root=tmp_path)
67+
68+
params = CalibrationPackageParameters.from_runtime_args(
69+
workers=8,
70+
n_clones=430,
71+
target_config_path=identity.path,
72+
target_config_sha256=identity.sha256,
73+
target_config_mode=identity.mode,
74+
skip_county=True,
75+
skip_source_impute=True,
76+
skip_takeup_rerandomize=False,
77+
chunked_matrix=False,
78+
chunk_size=25_000,
79+
parallel=False,
80+
num_matrix_workers=50,
81+
)
82+
83+
assert params.target_config_sha256 == identity.sha256
84+
85+
5786
def test_all_active_targets_identity_resolution():
5887
identity = resolve_target_config_identity(all_active_targets=True)
5988

tests/unit/test_pipeline.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ def test_calibration_package_parameters_track_matrix_mode():
4949
assert params["chunked_matrix"] is True
5050
assert "workers" not in params
5151
assert params["target_config"] == DEFAULT_TARGET_CONFIG_PATH
52-
assert params["target_config_sha256"] == compute_file_checksum(
53-
DEFAULT_TARGET_CONFIG_PATH
52+
assert params["target_config_sha256"] == (
53+
f"sha256:{compute_file_checksum(DEFAULT_TARGET_CONFIG_PATH)}"
5454
)
5555
assert params["target_config_mode"] == "default"
5656
assert params["chunk_size"] == 10_000
@@ -73,8 +73,8 @@ def test_calibration_package_parameters_ignore_unused_matrix_options():
7373
assert params["chunked_matrix"] is False
7474
assert params["workers"] == 50
7575
assert params["target_config"] == DEFAULT_TARGET_CONFIG_PATH
76-
assert params["target_config_sha256"] == compute_file_checksum(
77-
DEFAULT_TARGET_CONFIG_PATH
76+
assert params["target_config_sha256"] == (
77+
f"sha256:{compute_file_checksum(DEFAULT_TARGET_CONFIG_PATH)}"
7878
)
7979
assert params["target_config_mode"] == "default"
8080
assert "chunk_size" not in params

0 commit comments

Comments
 (0)