Skip to content

Commit 1063155

Browse files
committed
fixup tests
1 parent 5f3122c commit 1063155

File tree

8 files changed

+39
-17
lines changed

8 files changed

+39
-17
lines changed

Coder-Desktop/Coder-Desktop/Preview Content/PreviewFileSync.swift

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import VPNLib
33
@MainActor
44
final class PreviewFileSync: FileSyncDaemon {
55
var logFile: URL = .init(filePath: "~/log.txt")!
6-
var lastPromptMessage: String?
76

87
var sessionState: [VPNLib.FileSyncSession] = []
98

@@ -21,7 +20,12 @@ final class PreviewFileSync: FileSyncDaemon {
2120
state = .stopped
2221
}
2322

24-
func createSession(arg _: CreateSyncSessionRequest) async throws(DaemonError) {}
23+
func createSession(
24+
arg _: CreateSyncSessionRequest,
25+
promptCallback _: (
26+
@MainActor (String) -> Void
27+
)?
28+
) async throws(DaemonError) {}
2529

2630
func deleteSessions(ids _: [String]) async throws(VPNLib.DaemonError) {}
2731

Coder-Desktop/Coder-Desktop/VPN/MenuState.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ struct VPNMenuState {
8787
wsName: workspace.name,
8888
wsID: wsID,
8989
// Hosts arrive sorted by length, the shortest looks best in the UI.
90-
primaryHost: nonEmptyHosts.first!,
90+
primaryHost: nonEmptyHosts.first!
9191
)
9292
}
9393

Coder-Desktop/Coder-Desktop/Views/FileSync/FileSyncSessionModal.swift

+10-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ struct FileSyncSessionModal<VPN: VPNService, FS: FileSyncDaemon>: View {
1515
@State private var createError: DaemonError?
1616
@State private var pickingRemote: Bool = false
1717

18+
@State private var lastPromptMessage: String?
19+
1820
var body: some View {
1921
let agents = vpn.menuState.onlineAgents
2022
VStack(spacing: 0) {
@@ -62,8 +64,11 @@ struct FileSyncSessionModal<VPN: VPNService, FS: FileSyncDaemon>: View {
6264
Divider()
6365
HStack {
6466
Spacer()
65-
if let lastMessage = fileSync.lastPromptMessage {
66-
Text(lastMessage).foregroundStyle(.secondary)
67+
if let msg = lastPromptMessage {
68+
Text(msg).foregroundStyle(.secondary)
69+
}
70+
if loading {
71+
ProgressView().controlSize(.small)
6772
}
6873
Button("Cancel", action: { dismiss() }).keyboardShortcut(.cancelAction)
6974
Button(existingSession == nil ? "Add" : "Save") { Task { await submit() }}
@@ -106,8 +111,10 @@ struct FileSyncSessionModal<VPN: VPNService, FS: FileSyncDaemon>: View {
106111
arg: .init(
107112
alpha: .init(path: localPath, protocolKind: .local),
108113
beta: .init(path: remotePath, protocolKind: .ssh(host: remoteHostname))
109-
)
114+
),
115+
promptCallback: { lastPromptMessage = $0 },
110116
)
117+
lastPromptMessage = nil
111118
} catch {
112119
createError = error
113120
return

Coder-Desktop/Coder-DesktopTests/AgentsTests.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ struct AgentsTests {
2727
status: status,
2828
hosts: ["a\($0).coder"],
2929
wsName: "ws\($0)",
30-
wsID: UUID()
30+
wsID: UUID(),
31+
primaryHost: "a\($0).coder",
3132
)
3233
return (agent.id, agent)
3334
})

Coder-Desktop/Coder-DesktopTests/Util.swift

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class MockVPNService: VPNService, ObservableObject {
3131
class MockFileSyncDaemon: FileSyncDaemon {
3232
var logFile: URL = .init(filePath: "~/log.txt")
3333

34+
var lastPromptMessage: String?
35+
3436
var sessionState: [VPNLib.FileSyncSession] = []
3537

3638
func refreshSessions() async {}
@@ -47,7 +49,10 @@ class MockFileSyncDaemon: FileSyncDaemon {
4749
[]
4850
}
4951

50-
func createSession(arg _: CreateSyncSessionRequest) async throws(DaemonError) {}
52+
func createSession(
53+
arg _: CreateSyncSessionRequest,
54+
promptCallback _: (@MainActor (String) -> Void)?
55+
) async throws(DaemonError) {}
5156

5257
func pauseSessions(ids _: [String]) async throws(VPNLib.DaemonError) {}
5358

Coder-Desktop/VPNLib/FileSync/FileSyncDaemon.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ public protocol FileSyncDaemon: ObservableObject {
1111
var state: DaemonState { get }
1212
var sessionState: [FileSyncSession] { get }
1313
var logFile: URL { get }
14-
var lastPromptMessage: String? { get }
1514
func tryStart() async
1615
func stop() async
1716
func refreshSessions() async
18-
func createSession(arg: CreateSyncSessionRequest) async throws(DaemonError)
17+
func createSession(
18+
arg: CreateSyncSessionRequest,
19+
promptCallback: (@MainActor (String) -> Void)?
20+
) async throws(DaemonError)
1921
func deleteSessions(ids: [String]) async throws(DaemonError)
2022
func pauseSessions(ids: [String]) async throws(DaemonError)
2123
func resumeSessions(ids: [String]) async throws(DaemonError)
@@ -48,8 +50,6 @@ public class MutagenDaemon: FileSyncDaemon {
4850

4951
public let logFile: URL
5052

51-
@Published public var lastPromptMessage: String?
52-
5353
// Managing sync sessions could take a while, especially with prompting
5454
let sessionMgmtReqTimeout: TimeAmount = .seconds(15)
5555

Coder-Desktop/VPNLib/FileSync/FileSyncManagement.swift

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ public extension MutagenDaemon {
1717
sessionState = sessions.sessionStates.map { FileSyncSession(state: $0) }
1818
}
1919

20-
func createSession(arg: CreateSyncSessionRequest) async throws(DaemonError) {
20+
func createSession(
21+
arg: CreateSyncSessionRequest,
22+
promptCallback: (@MainActor (String) -> Void)? = nil
23+
) async throws(DaemonError) {
2124
if case .stopped = state {
2225
do throws(DaemonError) {
2326
try await start()
@@ -26,7 +29,7 @@ public extension MutagenDaemon {
2629
throw error
2730
}
2831
}
29-
let (stream, promptID) = try await host()
32+
let (stream, promptID) = try await host(promptCallback: promptCallback)
3033
defer { stream.cancel() }
3134
let req = Synchronization_CreateRequest.with { req in
3235
req.prompter = promptID

Coder-Desktop/VPNLib/FileSync/FileSyncPrompting.swift

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import GRPC
33
extension MutagenDaemon {
44
typealias PromptStream = GRPCAsyncBidirectionalStreamingCall<Prompting_HostRequest, Prompting_HostResponse>
55

6-
func host(allowPrompts: Bool = true) async throws(DaemonError) -> (PromptStream, identifier: String) {
6+
func host(
7+
allowPrompts: Bool = true,
8+
promptCallback: (@MainActor (String) -> Void)? = nil
9+
) async throws(DaemonError) -> (PromptStream, identifier: String) {
710
let stream = client!.prompt.makeHostCall()
811

912
do {
@@ -28,7 +31,6 @@ extension MutagenDaemon {
2831
try initResp.ensureValid(first: true, allowPrompts: allowPrompts)
2932

3033
Task.detached(priority: .background) {
31-
defer { Task { @MainActor in self.lastPromptMessage = nil } }
3234
do {
3335
while let msg = try await iter.next() {
3436
try msg.ensureValid(first: false, allowPrompts: allowPrompts)
@@ -41,7 +43,7 @@ extension MutagenDaemon {
4143
// Any other messages that require a non-empty response will
4244
// cause the create op to fail, showing an error. This is ok for now.
4345
} else {
44-
Task { @MainActor in self.lastPromptMessage = msg.message }
46+
Task { @MainActor in promptCallback?(msg.message) }
4547
}
4648
try await stream.requestStream.send(reply)
4749
}

0 commit comments

Comments
 (0)