Artifact 970c57e67cd48b91ebe74940be93fdce68214ecf3c86a2b03bb9ce181ab74614:
- File
internal/tag/timestamp_test.go
— part of check-in
[fa1895d56b]
at
2026-10-18 18:15:05
on branch main
— fix(manifest): record check-in and tag times to the millisecond (#440)
Fossil and zit write D cards with exactly three fractional digits. go-libfossil wrote whatever precision the time carried, and the default clock time carries nanoseconds: legal under artifact-format ยง4.6.4, but zit cannot read a D card with more than three digits (danmestas/zit#244), so zit could not open a repository go-libfossil had committed to.
Checkin and AddTag now truncate the time to the millisecond, whether the caller supplied it or the clock did. Parsed artifacts are untouched: the marshaller still keeps any precision it read, so existing artifacts round-trip byte for byte. (user: [email protected], size: 1323) [annotate] [blame] [check-ins using] [more...]
package tag_test import ( "regexp" "testing" "time" "github.com/danmestas/go-libfossil/internal/content" "github.com/danmestas/go-libfossil/internal/manifest" "github.com/danmestas/go-libfossil/internal/tag" ) // TestAddTagWritesMillisecondTimestamps tags a check-in with a time carrying // nanoseconds and checks the control artifact's D card has exactly three // fractional digits, as fossil and zit write it. func TestAddTagWritesMillisecondTimestamps(t *testing.T) { r := setupTestRepo(t) rid, _, err := manifest.Checkin(r, manifest.CheckinOpts{ Files: []manifest.File{{Name: "hello.txt", Content: []byte("hello")}}, Comment: "initial commit", User: "testuser", Time: time.Date(2024, 1, 15, 10, 0, 0, 0, time.UTC), }) if err != nil { t.Fatalf("Checkin: %v", err) } tagRid, err := tag.AddTag(r, tag.TagOpts{ TargetRID: rid, TagName: "testlabel", TagType: tag.TagSingleton, User: "testuser", Time: time.Date(2024, 1, 15, 11, 0, 0, 987654321, time.UTC), }) if err != nil { t.Fatalf("tag.AddTag: %v", err) } data, err := content.Expand(r.DB(), tagRid) if err != nil { t.Fatalf("Expand: %v", err) } millis := regexp.MustCompile(`(?m)^D 2024-01-15T11:00:00\.987$`) if !millis.Match(data) { t.Fatalf("D card is not millisecond precision:\n%s", data) } }