PrintToVeraeTimeStamp/internal/metadatahist/history_test.go
Cursor Agent 8f55e17f73
Send a document title as a verae-meta-git/1 history.
A non-blank document name is the first snapshot title, with restamp left false so a reprint keeps the first job. A blank name stays digest-only.
2026-10-11 05:37:25 +00:00

52 lines
1.9 KiB
Go

package metadatahist
import "testing"
func TestAppendMatchesNodeReference(t *testing.T) {
first := Append(nil, map[string]any{"title": "deed", "tags": []any{"a"}}, false, "2026-10-11T01:00:00.000Z", "", "stamp")
if first["head"] != "161ff3344ba776ae7201b73914c0e7500116ac9dde02e1967a761b7089c41fa7" {
t.Fatalf("head1=%v", first["head"])
}
second := Append(first, map[string]any{"title": "deed-2", "tags": []any{"b"}, "place": "office"}, true, "2026-10-11T02:00:00.000Z", "", "correct the title")
if second["head"] != "c606e41ccbf4c0f9f653b21759df83ecda25262621075db3a153b592270fd918" {
t.Fatalf("head2=%v", second["head"])
}
snap := second["snapshot"].(map[string]any)
if snap["title"] != "deed-2" || snap["place"] != "office" {
t.Fatalf("snapshot=%v", snap)
}
tags := snap["tags"].([]any)
if len(tags) != 2 || tags[0] != "a" || tags[1] != "b" {
t.Fatalf("tags=%v", tags)
}
commits := second["commits"].([]any)
tip := commits[1].(map[string]any)
if tip["parent"] != first["head"] {
t.Fatalf("parent=%v", tip["parent"])
}
if _, ok := tip["changes"].(map[string]any)["removed"]; ok {
t.Fatal("removed key")
}
}
func TestBlankRestampKeepsSnapshot(t *testing.T) {
base := map[string]any{"title": "deed", "note": "keep", "tags": []any{"a"}}
next := Append(base, map[string]any{"title": "", "note": nil, "tags": []any{}}, true, "2026-10-11T01:47:00.000Z", "2026-10-11T01:00:00.000Z", "")
snap := next["snapshot"].(map[string]any)
if snap["title"] != "deed" || snap["note"] != "keep" {
t.Fatalf("snapshot=%v", snap)
}
commits := next["commits"].([]any)
if len(commits) != 2 {
t.Fatalf("commits=%d", len(commits))
}
}
func TestOmitWhenEmpty(t *testing.T) {
if Append(nil, nil, false, "2026-10-11T01:00:00.000Z", "", "") != nil {
t.Fatal("expected omit")
}
if Append(nil, map[string]any{}, false, "2026-10-11T01:00:00.000Z", "", "") != nil {
t.Fatal("expected omit")
}
}