package dto

import (
	"encoding/json"
	"testing"
)

func TestRepositoryContainersKeepWireKey(t *testing.T) {
	ref := &ResourceRepositoryRef{ID: "rr_1", RepoRole: "canonical"}
	cases := map[string]any{
		"skill":  SkillRepositories{Primary: ref},
		"memory": MemoryRepositories{Primary: ref},
		"kb":     KBSourceDetailRepositories{Primary: ref},
	}
	for name, value := range cases {
		t.Run(name, func(t *testing.T) {
			payload, err := json.Marshal(value)
			if err != nil {
				t.Fatal(err)
			}
			var decoded map[string]any
			if err := json.Unmarshal(payload, &decoded); err != nil {
				t.Fatal(err)
			}
			if _, ok := decoded["canonical"]; !ok {
				t.Fatalf("canonical repository key missing: %s", payload)
			}
			if _, ok := decoded["primary"]; ok {
				t.Fatalf("unexpected primary repository protocol key: %s", payload)
			}
		})
	}
}
