feat(ax): expose normalization helpers for agent usage

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-03 23:40:38 +00:00
parent 5d002f8192
commit f6afe97b35
2 changed files with 32 additions and 0 deletions

View file

@ -1040,6 +1040,14 @@ func normalizeIP(ip string) string {
return parsed.String()
}
// NormalizeIP normalizes a raw IP string into its canonical textual form.
//
// normalized := dns.NormalizeIP("010.000.000.001")
// // normalized == "10.0.0.1"
func NormalizeIP(ip string) string {
return normalizeIP(ip)
}
func computeTreeRoot(records map[string]NameRecords) string {
names := make([]string, 0, len(records))
for name := range records {
@ -1183,6 +1191,14 @@ func normalizeName(name string) string {
return trimmed
}
// NormalizeName normalizes a raw DNS name for cache lookups and action handling.
//
// normalized := dns.NormalizeName("Gateway.Charon.lthn.")
// // normalized == "gateway.charon.lthn"
func NormalizeName(name string) string {
return normalizeName(name)
}
// String returns a compact debug representation of the service.
//
// fmt.Println(service)

View file

@ -3016,6 +3016,22 @@ func TestStringActionValueRejectsWhitespaceOnlyArgument(t *testing.T) {
}
}
func TestNormalizeNameAndNormalizeIPArePublicWrappers(t *testing.T) {
normalizedName := NormalizeName(" Gateway.Charon.lthn. ")
if normalizedName != "gateway.charon.lthn" {
t.Fatalf("expected normalized DNS name, got %q", normalizedName)
}
normalizedIP := NormalizeIP(" 2001:0DB8::0001 ")
if normalizedIP != "2001:db8::1" {
t.Fatalf("expected normalized IP, got %q", normalizedIP)
}
if NormalizeIP("invalid") != "" {
t.Fatal("expected invalid IP to normalize to empty string")
}
}
func TestIntActionValueRejectsNonIntegerFloat(t *testing.T) {
_, err := intActionValue(map[string]any{
actionArgPort: 53.9,