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.
This commit is contained in:
Cursor Agent 2026-10-11 05:37:25 +00:00
commit 394c46ebfc
No known key found for this signature in database
2 changed files with 469 additions and 21 deletions

View file

@ -380,3 +380,36 @@ async def test_global_hash_report_uses_api_hash():
assert methods_urls[0] == ("GET", f"https://api.veraetime.net/api/hash/{SHA256_EMPTY}")
assert methods_urls[1][0] == "POST"
assert methods_urls[1][1].endswith("/api/verify")
async def test_restamp_sends_verae_meta_git_history():
class HistoryHttp(FakeHttp):
def request(self, method, url, payload, headers):
self.calls.append((method, url, payload, headers))
if url.endswith(f"/api/hash/{SHA256_EMPTY}"):
return _Resp(200, {"receipts": [{"jobId": "job-old", "certificate": "QmOld"}]})
if url.endswith("/api/status/job-old"):
return _Resp(200, {"status": "completed", "metadata": {"title": "deed", "tags": ["a"]}})
if url.endswith("/api/timestamp"):
return _Resp(202, {"jobId": "job-new"})
if url.endswith("/api/status/job-new"):
return _Resp(200, {"status": "completed", "result": "QmNew", "metadata": {"schema": "verae-meta-git/1"}})
raise AssertionError(f"unexpected {method} {url}")
http = HistoryHttp()
client = GlobalClient("https://api.veraetime.net", token="secret", http=http)
rec = client.submit(
SHA256_EMPTY,
metadata={"place": "office"},
restamp=True,
message="add the place",
at="2026-10-11T02:00:00.000Z",
)
post = next(call for call in http.calls if call[1].endswith("/api/timestamp"))
body = post[2]
assert body["restamp"] is True
assert body["metadata"]["schema"] == "verae-meta-git/1"
assert body["metadata"]["snapshot"]["title"] == "deed"
assert body["metadata"]["snapshot"]["place"] == "office"
assert body["metadata"]["snapshot"]["tags"] == ["a"]
assert rec.receipt_id == "QmNew"

View file

@ -0,0 +1,59 @@
"""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