From 95cea1434d44a03fa960a112ef642f6df369b57e Mon Sep 17 00:00:00 2001 From: Seongmin Lee Date: Mon, 7 Sep 2026 20:06:15 +0900 Subject: [PATCH] knotmirror: fallback to repoDid as push actor Signed-off-by: Seongmin Lee --- knotfeed/legacy.go | 9 +++++++-- knotfeed/legacy_test.go | 16 ++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/knotfeed/legacy.go b/knotfeed/legacy.go index e437c824c..5ca01a501 100644 --- a/knotfeed/legacy.go +++ b/knotfeed/legacy.go @@ -42,7 +42,7 @@ type legacyRefUpdate struct { Ref string `json:"ref"` OldSha string `json:"oldSha"` NewSha string `json:"newSha"` - CommitterDid syntax.DID `json:"committerDid"` + CommitterDid string `json:"committerDid"` PushOptions []string `json:"pushOptions"` } @@ -92,9 +92,14 @@ func legacyRefOp(payload json.RawMessage, commit *Commit) error { Prior: ParsePriorSha(event.OldSha), } if !newSha.IsZero() { + // old knots leave committerDid empty; attribute those pushes to the repo itself + editor, err := syntax.ParseDID(event.CommitterDid) + if err != nil { + editor = event.Repo + } record, err := encodeRefRecord(RefRecord{ Sha: newSha, - Editor: event.CommitterDid, + Editor: editor, PushOptions: event.PushOptions, }) if err != nil { diff --git a/knotfeed/legacy_test.go b/knotfeed/legacy_test.go index f8fca9f9e..e81720ddc 100644 --- a/knotfeed/legacy_test.go +++ b/knotfeed/legacy_test.go @@ -118,7 +118,7 @@ func TestLegacyFrameReadsAsCommit(t *testing.T) { Repo: "did:plc:scallop", Seq: 11, Records: []RecordOp{refOp(t, "refs/heads/new", zeroSha1, - RefRecord{Sha: sha(t, legacyNewSha)})}, + RefRecord{Sha: sha(t, legacyNewSha), Editor: "did:plc:scallop"})}, }, }, { @@ -128,7 +128,19 @@ func TestLegacyFrameReadsAsCommit(t *testing.T) { Repo: "did:plc:scallop", Seq: 11, Records: []RecordOp{refOp(t, "refs/heads/new", "", - RefRecord{Sha: sha(t, legacyNewSha)})}, + RefRecord{Sha: sha(t, legacyNewSha), Editor: "did:plc:scallop"})}, + }, + }, + { + name: "push with an empty committerDid", + frame: `{"nsid":"sh.tangled.git.refUpdate","created":11,` + + `"event":{"ref":"refs/heads/main","repo":"did:plc:scallop","committerDid":"",` + + `"oldSha":"` + legacyOldSha + `","newSha":"` + legacyNewSha + `"}}`, + want: Commit{ + Repo: "did:plc:scallop", + Seq: 11, + Records: []RecordOp{refOp(t, "refs/heads/main", legacyOldSha, + RefRecord{Sha: sha(t, legacyNewSha), Editor: "did:plc:scallop"})}, }, }, { -- 2.51.2