Monorepo for Tangled tangled.org
5

Configure Feed

Select the types of activity you want to include in your feed.

1package knotcompat 2 3import ( 4 "encoding/json" 5 "testing" 6 7 "tangled.org/core/api/tangled" 8) 9 10func ptr[T any](v T) *T { return &v } 11 12func TestCollaboratorShadowsRepoDid(t *testing.T) { 13 rec := &tangled.RepoCollaborator{ 14 CreatedAt: "2026-05-08T00:00:00Z", 15 Repo: "did:plc:abalone", 16 Subject: "did:plc:limpet", 17 } 18 19 out, err := json.Marshal(Collaborator(rec)) 20 if err != nil { 21 t.Fatalf("marshal: %v", err) 22 } 23 24 var got map[string]any 25 if err := json.Unmarshal(out, &got); err != nil { 26 t.Fatalf("unmarshal: %v", err) 27 } 28 29 if got["$type"] != "sh.tangled.repo.collaborator" { 30 t.Errorf("$type = %v, want sh.tangled.repo.collaborator", got["$type"]) 31 } 32 if got["repo"] != "did:plc:abalone" { 33 t.Errorf("repo = %v, want did:plc:abalone", got["repo"]) 34 } 35 if got["repoDid"] != "did:plc:abalone" { 36 t.Errorf("repoDid shadow missing or wrong: got %v", got["repoDid"]) 37 } 38} 39 40func TestPullShadowsTargetRepoDid(t *testing.T) { 41 rec := &tangled.RepoPull{ 42 CreatedAt: "2026-05-08T00:00:00Z", 43 Title: "rename whelk handler", 44 Target: &tangled.RepoPull_Target{ 45 Branch: "main", 46 Repo: "did:plc:scallop", 47 }, 48 Source: &tangled.RepoPull_Source{ 49 Branch: "feature-1", 50 }, 51 } 52 53 out, err := json.Marshal(Pull(rec)) 54 if err != nil { 55 t.Fatalf("marshal: %v", err) 56 } 57 58 var got map[string]any 59 if err := json.Unmarshal(out, &got); err != nil { 60 t.Fatalf("unmarshal: %v", err) 61 } 62 63 target, ok := got["target"].(map[string]any) 64 if !ok { 65 t.Fatalf("target missing or wrong type: %v", got["target"]) 66 } 67 if target["repo"] != "did:plc:scallop" { 68 t.Errorf("target.repo = %v", target["repo"]) 69 } 70 if target["repoDid"] != "did:plc:scallop" { 71 t.Errorf("target.repoDid shadow missing: %v", target["repoDid"]) 72 } 73 74 if _, has := got["repoDid"]; has { 75 t.Errorf("top-level repoDid should not be set on pull: %v", got["repoDid"]) 76 } 77} 78 79func TestPullShadowsForkSourceRepoDid(t *testing.T) { 80 rec := &tangled.RepoPull{ 81 CreatedAt: "2026-05-08T00:00:00Z", 82 Title: "fork-based PR", 83 Target: &tangled.RepoPull_Target{ 84 Branch: "main", 85 Repo: "did:plc:scallop", 86 }, 87 Source: &tangled.RepoPull_Source{ 88 Branch: "feature-2", 89 Repo: ptr("did:plc:periwinkle"), 90 }, 91 } 92 93 out, err := json.Marshal(Pull(rec)) 94 if err != nil { 95 t.Fatalf("marshal: %v", err) 96 } 97 98 var got map[string]any 99 if err := json.Unmarshal(out, &got); err != nil { 100 t.Fatalf("unmarshal: %v", err) 101 } 102 103 source, ok := got["source"].(map[string]any) 104 if !ok { 105 t.Fatalf("source missing: %v", got["source"]) 106 } 107 if source["repo"] != "did:plc:periwinkle" { 108 t.Errorf("source.repo = %v", source["repo"]) 109 } 110 if source["repoDid"] != "did:plc:periwinkle" { 111 t.Errorf("source.repoDid shadow missing: %v", source["repoDid"]) 112 } 113}