-
Notifications
You must be signed in to change notification settings - Fork 3
feat: pass agent updates to UI #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,22 @@ final class Inspection<V> { | |
} | ||
} | ||
} | ||
|
||
extension UUID { | ||
var uuidData: Data { | ||
withUnsafePointer(to: uuid) { | ||
Data(bytes: $0, count: MemoryLayout.size(ofValue: uuid)) | ||
} | ||
} | ||
|
||
init?(uuidData: Data) { | ||
guard uuidData.count == 16 else { | ||
return nil | ||
} | ||
var uuid: uuid_t = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very funny: there's no fixed size arrays in Swift (probably cause of objc), so |
||
withUnsafeMutableBytes(of: &uuid) { | ||
$0.copyBytes(from: uuidData) | ||
} | ||
self.init(uuid: uuid) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
@testable import Coder_Desktop | ||
import Testing | ||
@testable import VPNLib | ||
|
||
@MainActor | ||
@Suite | ||
struct CoderVPNServiceTests { | ||
let service = CoderVPNService() | ||
|
||
init() { | ||
service.workspaces = [:] | ||
service.agents = [:] | ||
} | ||
|
||
@Test | ||
func testApplyPeerUpdate_upsertsAgents() async throws { | ||
let agentID = UUID() | ||
let workspaceID = UUID() | ||
service.workspaces[workspaceID] = "foo" | ||
|
||
let update = Vpn_PeerUpdate.with { | ||
$0.upsertedAgents = [Vpn_Agent.with { | ||
$0.id = agentID.uuidData | ||
$0.workspaceID = workspaceID.uuidData | ||
$0.name = "dev" | ||
$0.lastHandshake = .init(date: Date.now) | ||
$0.fqdn = ["foo.coder"] | ||
}] | ||
} | ||
|
||
service.applyPeerUpdate(with: update) | ||
|
||
let agent = try #require(service.agents[agentID]) | ||
#expect(agent.name == "dev") | ||
#expect(agent.wsID == workspaceID) | ||
#expect(agent.wsName == "foo") | ||
#expect(agent.copyableDNS == "foo.coder") | ||
#expect(agent.status == .okay) | ||
} | ||
|
||
@Test | ||
func testApplyPeerUpdate_deletesAgentsAndWorkspaces() async throws { | ||
let agentID = UUID() | ||
let workspaceID = UUID() | ||
|
||
service.agents[agentID] = Agent( | ||
id: agentID, name: "agent1", status: .okay, | ||
copyableDNS: "foo.coder", wsName: "foo", wsID: workspaceID | ||
) | ||
service.workspaces[workspaceID] = "foo" | ||
|
||
let update = Vpn_PeerUpdate.with { | ||
$0.deletedAgents = [Vpn_Agent.with { $0.id = agentID.uuidData }] | ||
$0.deletedWorkspaces = [Vpn_Workspace.with { $0.id = workspaceID.uuidData }] | ||
} | ||
|
||
service.applyPeerUpdate(with: update) | ||
|
||
#expect(service.agents[agentID] == nil) | ||
#expect(service.workspaces[workspaceID] == nil) | ||
} | ||
|
||
@Test | ||
func testApplyPeerUpdate_unhealthyAgent() async throws { | ||
let agentID = UUID() | ||
let workspaceID = UUID() | ||
service.workspaces[workspaceID] = "foo" | ||
|
||
let update = Vpn_PeerUpdate.with { | ||
$0.upsertedAgents = [Vpn_Agent.with { | ||
$0.id = agentID.uuidData | ||
$0.workspaceID = workspaceID.uuidData | ||
$0.name = "agent1" | ||
$0.lastHandshake = .init(date: Date.now.addingTimeInterval(-600)) | ||
$0.fqdn = ["foo.coder"] | ||
}] | ||
} | ||
|
||
service.applyPeerUpdate(with: update) | ||
|
||
let agent = try #require(service.agents[agentID]) | ||
#expect(agent.status == .off) | ||
} | ||
|
||
@Test | ||
func testApplyPeerUpdate_replaceOldAgent() async throws { | ||
let workspaceID = UUID() | ||
let oldAgentID = UUID() | ||
let newAgentID = UUID() | ||
service.workspaces[workspaceID] = "foo" | ||
|
||
service.agents[oldAgentID] = Agent( | ||
id: oldAgentID, name: "agent1", status: .off, | ||
copyableDNS: "foo.coder", wsName: "foo", wsID: workspaceID | ||
) | ||
|
||
let update = Vpn_PeerUpdate.with { | ||
$0.upsertedAgents = [Vpn_Agent.with { | ||
$0.id = newAgentID.uuidData | ||
$0.workspaceID = workspaceID.uuidData | ||
$0.name = "agent1" // Same name as old agent | ||
$0.lastHandshake = .init(date: Date.now) | ||
$0.fqdn = ["foo.coder"] | ||
}] | ||
} | ||
|
||
service.applyPeerUpdate(with: update) | ||
|
||
#expect(service.agents[oldAgentID] == nil) | ||
let newAgent = try #require(service.agents[newAgentID]) | ||
#expect(newAgent.name == "agent1") | ||
#expect(newAgent.wsID == workspaceID) | ||
#expect(newAgent.copyableDNS == "foo.coder") | ||
#expect(newAgent.status == .okay) | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ name: "Coder Desktop" | |
options: | ||
bundleIdPrefix: com.coder | ||
deploymentTarget: | ||
macOS: "14.6" | ||
macOS: "14.0" | ||
xcodeVersion: "1600" | ||
minimumXcodeGenVersion: "2.42.0" | ||
|
||
|
@@ -146,7 +146,7 @@ targets: | |
dependencies: | ||
- target: CoderSDK | ||
embed: true | ||
- target: VPNXPC | ||
- target: VPNLib | ||
embed: true | ||
- target: VPN | ||
embed: without-signing # Embed without signing. | ||
|
@@ -220,8 +220,6 @@ targets: | |
embed: true | ||
- target: CoderSDK | ||
embed: true | ||
- target: VPNXPC | ||
embed: true | ||
- sdk: NetworkExtension.framework | ||
|
||
VPNLib: | ||
|
@@ -299,20 +297,4 @@ targets: | |
settings: | ||
base: | ||
TEST_HOST: "$(BUILT_PRODUCTS_DIR)/Coder Desktop.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Coder Desktop" | ||
PRODUCT_BUNDLE_IDENTIFIER: com.coder.Coder-Desktop.CoderSDKTests | ||
|
||
VPNXPC: | ||
type: framework | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that we import VPNLib into the app for the peer update protobuf type, we might as well just put the contents of this framework there. |
||
platform: macOS | ||
sources: | ||
- path: VPNXPC | ||
settings: | ||
base: | ||
INFOPLIST_KEY_NSHumanReadableCopyright: "" | ||
PRODUCT_NAME: "$(TARGET_NAME:c99extidentifier)" | ||
SWIFT_EMIT_LOC_STRINGS: YES | ||
GENERATE_INFOPLIST_FILE: YES | ||
DYLIB_COMPATIBILITY_VERSION: 1 | ||
DYLIB_CURRENT_VERSION: 1 | ||
DYLIB_INSTALL_NAME_BASE: "@rpath" | ||
dependencies: [] | ||
PRODUCT_BUNDLE_IDENTIFIER: com.coder.Coder-Desktop.CoderSDKTests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
macOS can tell us when the Network Extension changes state, including if there was an error that caused it to disconnect, e.g. NE crashes,
ptp.cancelTunnelWithError
, start/stopcompletionHandler(err)