verae-mcp-timestamping-server/tests/test_metadata_history.py
Cursor Agent 394c46ebfc
Send global stamps as a verae-meta-git/1 history.
Optional metadata or restamp builds the same commit history as node-red. A call that omits both stays digest-only with restamp false. Local and shared stamps reject metadata.
2026-10-11 05:37:25 +00:00

59 lines
2 KiB
Python

"""Golden verae-meta-git/1 ids shared with node-red-contrib-verae."""
from verae_mcp_timestamping_server.metadata_history import append_metadata
HEAD_1 = "161ff3344ba776ae7201b73914c0e7500116ac9dde02e1967a761b7089c41fa7"
HEAD_2 = "c606e41ccbf4c0f9f653b21759df83ecda25262621075db3a153b592270fd918"
def test_append_matches_node_reference():
first = append_metadata(
None,
{"title": "deed", "tags": ["a"]},
restamp=False,
at="2026-10-11T01:00:00.000Z",
message="stamp",
)
assert first["head"] == HEAD_1
second = append_metadata(
first,
{"title": "deed-2", "tags": ["b"], "place": "office"},
restamp=True,
at="2026-10-11T02:00:00.000Z",
message="correct the title",
)
assert second["head"] == HEAD_2
assert second["snapshot"] == {"title": "deed-2", "tags": ["a", "b"], "place": "office"}
assert second["commits"][1]["parent"] == HEAD_1
assert "removed" not in second["commits"][1]["changes"]
def test_blank_restamp_keeps_snapshot():
nxt = append_metadata(
{"title": "deed", "note": "keep", "tags": ["a"]},
{"title": "", "note": None, "tags": []},
restamp=True,
at="2026-10-11T01:47:00.000Z",
prior_at="2026-10-11T01:00:00.000Z",
)
assert nxt["snapshot"]["title"] == "deed"
assert nxt["snapshot"]["note"] == "keep"
assert nxt["snapshot"]["tags"] == ["a"]
assert len(nxt["commits"]) == 2
def test_omit_when_empty():
assert append_metadata(None, None, restamp=False, at="2026-10-11T01:00:00.000Z") is None
assert append_metadata(None, {}, restamp=False, at="2026-10-11T01:00:00.000Z") is None
def test_history_document_is_not_rewritten_by_append_of_itself():
first = append_metadata(
None,
{"title": "deed", "tags": ["a"]},
restamp=False,
at="2026-10-11T01:00:00.000Z",
message="stamp",
)
assert first["schema"] == "verae-meta-git/1"
assert first["commits"][0]["parent"] is None