From c9d1a9fdbb2b5b0e92f7bf5e4bf74b63bb2f8da5 Mon Sep 17 00:00:00 2001 From: Virgil Date: Thu, 2 Apr 2026 04:38:35 +0000 Subject: [PATCH] feat(lns): align by-name aliases with label-aware lookups --- lns.go | 36 ++++++++++++------------------------ lns_test.go | 16 ++++++++++++++++ 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/lns.go b/lns.go index 885471b..42efa25 100644 --- a/lns.go +++ b/lns.go @@ -135,23 +135,17 @@ func (s *Service) HasReserved(name any) bool { return ok } -// GetReservedByName looks up a reserved name using the raw catalog label. +// GetReservedByName is an alias for GetReservedName. // -// This mirrors the covenant package helper without requiring .lthn -// canonicalisation first. +// This keeps the service-level name lookup helpers consistent: callers can +// pass either a raw catalog label or a canonical `.lthn` name. func (s *Service) GetReservedByName(name any) (covenant.ReservedName, bool) { - label, ok := catalogLabel(name) - if !ok { - return covenant.ReservedName{}, false - } - - return covenant.GetReservedName(label) + return s.GetReservedName(name) } -// HasReservedByName reports whether the raw catalog label is reserved. +// HasReservedByName is an alias for HasReservedName. func (s *Service) HasReservedByName(name any) bool { - _, ok := s.GetReservedByName(name) - return ok + return s.HasReservedName(name) } // HasReservedName reports whether a reserved name exists using the raw @@ -225,23 +219,17 @@ func (s *Service) HasLocked(name any) bool { return ok } -// GetLockedByName looks up a locked name using the raw catalog label. +// GetLockedByName is an alias for GetLockedName. // -// This mirrors the covenant package helper without requiring .lthn -// canonicalisation first. +// This keeps the service-level name lookup helpers consistent: callers can +// pass either a raw catalog label or a canonical `.lthn` name. func (s *Service) GetLockedByName(name any) (covenant.LockedName, bool) { - label, ok := catalogLabel(name) - if !ok { - return covenant.LockedName{}, false - } - - return covenant.GetLockedName(label) + return s.GetLockedName(name) } -// HasLockedByName reports whether the raw catalog label is locked. +// HasLockedByName is an alias for HasLockedName. func (s *Service) HasLockedByName(name any) bool { - _, ok := s.GetLockedByName(name) - return ok + return s.HasLockedName(name) } // HasLockedName reports whether a locked name exists using the raw catalog diff --git a/lns_test.go b/lns_test.go index c5e8a9c..e31f778 100644 --- a/lns_test.go +++ b/lns_test.go @@ -183,6 +183,10 @@ func TestServiceGetReservedByName(t *testing.T) { t.Fatal("GetReservedByName([]byte) should find the reserved reference entry") } + if _, ok := svc.GetReservedByName("RESERVED.lthn"); !ok { + t.Fatal("GetReservedByName should also accept canonical reserved names") + } + if _, ok := svc.GetReservedByName(123); ok { t.Fatal("GetReservedByName should reject unsupported input types") } @@ -199,6 +203,10 @@ func TestServiceHasReservedByName(t *testing.T) { t.Fatal("HasReservedByName([]byte) should report reserved catalog labels") } + if !svc.HasReservedByName("reserved.lthn") { + t.Fatal("HasReservedByName should report canonical reserved names") + } + if svc.HasReservedByName("not-reserved") { t.Fatal("HasReservedByName should return false for unknown labels") } @@ -355,6 +363,10 @@ func TestServiceGetLockedByName(t *testing.T) { t.Fatal("GetLockedByName([]byte) should find the locked reference entry") } + if _, ok := svc.GetLockedByName("NEC.lthn"); !ok { + t.Fatal("GetLockedByName should also accept canonical locked names") + } + if _, ok := svc.GetLockedByName(123); ok { t.Fatal("GetLockedByName should reject unsupported input types") } @@ -371,6 +383,10 @@ func TestServiceHasLockedByName(t *testing.T) { t.Fatal("HasLockedByName([]byte) should report locked catalog labels") } + if !svc.HasLockedByName("nec.lthn") { + t.Fatal("HasLockedByName should report canonical locked names") + } + if svc.HasLockedByName("not-locked") { t.Fatal("HasLockedByName should return false for unknown labels") }