fix(macos): avoid hiding gateways by substring match

This commit is contained in:
Peter Steinberger
2026-01-11 00:47:01 +01:00
parent 7c76561569
commit f3882671c9
3 changed files with 30 additions and 9 deletions

View File

@@ -449,10 +449,10 @@ public final class GatewayDiscoveryModel {
{ {
return true return true
} }
if let service = normalizeServiceToken(serviceName) { if let serviceHost = normalizeServiceHostToken(serviceName),
for token in local.hostTokens where service.contains(token) { local.hostTokens.contains(serviceHost)
return true {
} return true
} }
return false return false
} }
@@ -542,11 +542,14 @@ public final class GatewayDiscoveryModel {
return trimmed.lowercased() return trimmed.lowercased()
} }
private nonisolated static func normalizeServiceToken(_ raw: String?) -> String? { private nonisolated static func normalizeServiceHostToken(_ raw: String?) -> String? {
guard let raw else { return nil } guard let raw else { return nil }
let trimmed = raw.trimmingCharacters(in: .whitespacesAndNewlines) let prettified = Self.prettifyInstanceName(raw)
if trimmed.isEmpty { return nil } let strippedBridge = prettified.replacingOccurrences(
return trimmed.lowercased() of: #"\s*-?\s*bridge$"#,
with: "",
options: .regularExpression)
return normalizeHostToken(strippedBridge)
} }
} }

View File

@@ -202,7 +202,7 @@ enum WideAreaGatewayDiscovery {
} }
process.waitUntilExit() process.waitUntilExit()
let data = outPipe.fileHandleForReading.readDataToEndOfFile() let data = (try? outPipe.fileHandleForReading.readToEnd()) ?? Data()
let output = String(data: data, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines) let output = String(data: data, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines)
return output?.isEmpty == false ? output : nil return output?.isEmpty == false ? output : nil
} }

View File

@@ -64,6 +64,24 @@ struct GatewayDiscoveryModelTests {
local: local)) local: local))
} }
@Test func serviceNameDoesNotFalsePositiveOnSubstringHostToken() {
let local = GatewayDiscoveryModel.LocalIdentity(
hostTokens: ["steipete"],
displayTokens: [])
#expect(!GatewayDiscoveryModel.isLocalGateway(
lanHost: nil,
tailnetDns: nil,
displayName: nil,
serviceName: "steipetacstudio (Clawdbot)",
local: local))
#expect(GatewayDiscoveryModel.isLocalGateway(
lanHost: nil,
tailnetDns: nil,
displayName: nil,
serviceName: "steipete (Clawdbot)",
local: local))
}
@Test func parsesGatewayTXTFields() { @Test func parsesGatewayTXTFields() {
let parsed = GatewayDiscoveryModel.parseGatewayTXT([ let parsed = GatewayDiscoveryModel.parseGatewayTXT([
"lanHost": " studio.local ", "lanHost": " studio.local ",