fix: canonicalize numeric legacy timestamps
This commit is contained in:
parent
826874a47e
commit
b649ea7168
2 changed files with 18 additions and 0 deletions
|
|
@ -60,6 +60,8 @@ def _datetime(value: Any, default: datetime | None = None) -> datetime:
|
||||||
return value if value.tzinfo else value.replace(tzinfo=timezone.utc)
|
return value if value.tzinfo else value.replace(tzinfo=timezone.utc)
|
||||||
if isinstance(value, str) and value:
|
if isinstance(value, str) and value:
|
||||||
return datetime.fromisoformat(value.replace("Z", "+00:00"))
|
return datetime.fromisoformat(value.replace("Z", "+00:00"))
|
||||||
|
if isinstance(value, (int, float)) and not isinstance(value, bool):
|
||||||
|
return datetime.fromtimestamp(value, tz=timezone.utc)
|
||||||
return default or _now()
|
return default or _now()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,22 @@ def test_validation_rejects_secret_material_and_digest_drift():
|
||||||
assert any("bundleSha256" in error for error in report["errors"])
|
assert any("bundleSha256" in error for error in report["errors"])
|
||||||
|
|
||||||
|
|
||||||
|
def test_numeric_legacy_timestamps_have_deterministic_content_hashes():
|
||||||
|
numeric = bundle()
|
||||||
|
numeric["records"]["interactionEvents"][0]["metadata"]["recordedAt"] = 1
|
||||||
|
numeric["bundleSha256"] = bundle_digest(numeric)
|
||||||
|
textual = bundle()
|
||||||
|
textual["records"]["interactionEvents"][0]["metadata"]["recordedAt"] = (
|
||||||
|
"1970-01-01T00:00:01Z"
|
||||||
|
)
|
||||||
|
textual["bundleSha256"] = bundle_digest(textual)
|
||||||
|
|
||||||
|
assert (
|
||||||
|
validate_bundle(numeric)["contentHashes"]["interactionEvents"]
|
||||||
|
== validate_bundle(textual)["contentHashes"]["interactionEvents"]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_import_is_idempotent_and_exports_all_seven_collections(tmp_path):
|
def test_import_is_idempotent_and_exports_all_seven_collections(tmp_path):
|
||||||
async def run():
|
async def run():
|
||||||
store = await make_store(tmp_path)
|
store = await make_store(tmp_path)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue