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
}
if let service = normalizeServiceToken(serviceName) {
for token in local.hostTokens where service.contains(token) {
return true
}
if let serviceHost = normalizeServiceHostToken(serviceName),
local.hostTokens.contains(serviceHost)
{
return true
}
return false
}
@@ -542,11 +542,14 @@ public final class GatewayDiscoveryModel {
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 }
let trimmed = raw.trimmingCharacters(in: .whitespacesAndNewlines)
if trimmed.isEmpty { return nil }
return trimmed.lowercased()
let prettified = Self.prettifyInstanceName(raw)
let strippedBridge = prettified.replacingOccurrences(
of: #"\s*-?\s*bridge$"#,
with: "",
options: .regularExpression)
return normalizeHostToken(strippedBridge)
}
}

View File

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

View File

@@ -64,6 +64,24 @@ struct GatewayDiscoveryModelTests {
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() {
let parsed = GatewayDiscoveryModel.parseGatewayTXT([
"lanHost": " studio.local ",