style: swiftformat sweep

This commit is contained in:
Peter Steinberger
2026-01-08 02:36:29 +00:00
parent 7f0f82e869
commit 1e1293cc0a
44 changed files with 85 additions and 89 deletions

View File

@@ -13,7 +13,7 @@ public struct WakeWordSegment: Sendable, Equatable {
self.range = range self.range = range
} }
public var end: TimeInterval { self.start + self.duration } public var end: TimeInterval { start + duration }
} }
public struct WakeWordGateConfig: Sendable, Equatable { public struct WakeWordGateConfig: Sendable, Equatable {
@@ -62,10 +62,10 @@ public enum WakeWordGate {
segments: [WakeWordSegment], segments: [WakeWordSegment],
config: WakeWordGateConfig) config: WakeWordGateConfig)
-> WakeWordGateMatch? { -> WakeWordGateMatch? {
let triggerTokens = self.normalizeTriggers(config.triggers) let triggerTokens = normalizeTriggers(config.triggers)
guard !triggerTokens.isEmpty else { return nil } guard !triggerTokens.isEmpty else { return nil }
let tokens = self.normalizeSegments(segments) let tokens = normalizeSegments(segments)
guard !tokens.isEmpty else { return nil } guard !tokens.isEmpty else { return nil }
var best: (index: Int, triggerEnd: TimeInterval, gap: TimeInterval)? var best: (index: Int, triggerEnd: TimeInterval, gap: TimeInterval)?
@@ -89,7 +89,7 @@ public enum WakeWordGate {
} }
guard let best else { return nil } guard let best else { return nil }
let command = self.commandText(transcript: transcript, segments: segments, triggerEndTime: best.triggerEnd) let command = commandText(transcript: transcript, segments: segments, triggerEndTime: best.triggerEnd)
.trimmingCharacters(in: Self.whitespaceAndPunctuation) .trimmingCharacters(in: Self.whitespaceAndPunctuation)
guard command.count >= config.minCommandLength else { return nil } guard command.count >= config.minCommandLength else { return nil }
return WakeWordGateMatch(triggerEndTime: best.triggerEnd, postGap: best.gap, command: command) return WakeWordGateMatch(triggerEndTime: best.triggerEnd, postGap: best.gap, command: command)
@@ -111,7 +111,7 @@ public enum WakeWordGate {
} }
let text = segments let text = segments
.filter { $0.start >= threshold && !self.normalizeToken($0.text).isEmpty } .filter { $0.start >= threshold && !normalizeToken($0.text).isEmpty }
.map(\.text) .map(\.text)
.joined(separator: " ") .joined(separator: " ")
return text.trimmingCharacters(in: Self.whitespaceAndPunctuation) return text.trimmingCharacters(in: Self.whitespaceAndPunctuation)
@@ -121,7 +121,7 @@ public enum WakeWordGate {
guard !text.isEmpty else { return false } guard !text.isEmpty else { return false }
let normalized = text.lowercased() let normalized = text.lowercased()
for trigger in triggers { for trigger in triggers {
let token = trigger.trimmingCharacters(in: self.whitespaceAndPunctuation).lowercased() let token = trigger.trimmingCharacters(in: whitespaceAndPunctuation).lowercased()
if token.isEmpty { continue } if token.isEmpty { continue }
if normalized.contains(token) { return true } if normalized.contains(token) { return true }
} }
@@ -131,11 +131,11 @@ public enum WakeWordGate {
public static func stripWake(text: String, triggers: [String]) -> String { public static func stripWake(text: String, triggers: [String]) -> String {
var out = text var out = text
for trigger in triggers { for trigger in triggers {
let token = trigger.trimmingCharacters(in: self.whitespaceAndPunctuation) let token = trigger.trimmingCharacters(in: whitespaceAndPunctuation)
guard !token.isEmpty else { continue } guard !token.isEmpty else { continue }
out = out.replacingOccurrences(of: token, with: "", options: [.caseInsensitive]) out = out.replacingOccurrences(of: token, with: "", options: [.caseInsensitive])
} }
return out.trimmingCharacters(in: self.whitespaceAndPunctuation) return out.trimmingCharacters(in: whitespaceAndPunctuation)
} }
private static func normalizeTriggers(_ triggers: [String]) -> [TriggerTokens] { private static func normalizeTriggers(_ triggers: [String]) -> [TriggerTokens] {
@@ -143,7 +143,7 @@ public enum WakeWordGate {
for trigger in triggers { for trigger in triggers {
let tokens = trigger let tokens = trigger
.split(whereSeparator: { $0.isWhitespace }) .split(whereSeparator: { $0.isWhitespace })
.map { self.normalizeToken(String($0)) } .map { normalizeToken(String($0)) }
.filter { !$0.isEmpty } .filter { !$0.isEmpty }
if tokens.isEmpty { continue } if tokens.isEmpty { continue }
output.append(TriggerTokens(tokens: tokens)) output.append(TriggerTokens(tokens: tokens))
@@ -153,7 +153,7 @@ public enum WakeWordGate {
private static func normalizeSegments(_ segments: [WakeWordSegment]) -> [Token] { private static func normalizeSegments(_ segments: [WakeWordSegment]) -> [Token] {
segments.compactMap { segment in segments.compactMap { segment in
let normalized = self.normalizeToken(segment.text) let normalized = normalizeToken(segment.text)
guard !normalized.isEmpty else { return nil } guard !normalized.isEmpty else { return nil }
return Token( return Token(
normalized: normalized, normalized: normalized,
@@ -166,7 +166,7 @@ public enum WakeWordGate {
private static func normalizeToken(_ token: String) -> String { private static func normalizeToken(_ token: String) -> String {
token token
.trimmingCharacters(in: self.whitespaceAndPunctuation) .trimmingCharacters(in: whitespaceAndPunctuation)
.lowercased() .lowercased()
} }

View File

@@ -1,6 +1,6 @@
import Foundation import Foundation
import Testing
import SwabbleKit import SwabbleKit
import Testing
@Suite struct WakeWordGateTests { @Suite struct WakeWordGateTests {
@Test func matchRequiresGapAfterTrigger() { @Test func matchRequiresGapAfterTrigger() {

View File

@@ -5,7 +5,8 @@ import Testing
@Test func errorDescriptionsAreStable() { @Test func errorDescriptionsAreStable() {
#expect(CameraController.CameraError.cameraUnavailable.errorDescription == "Camera unavailable") #expect(CameraController.CameraError.cameraUnavailable.errorDescription == "Camera unavailable")
#expect(CameraController.CameraError.microphoneUnavailable.errorDescription == "Microphone unavailable") #expect(CameraController.CameraError.microphoneUnavailable.errorDescription == "Microphone unavailable")
#expect(CameraController.CameraError.permissionDenied(kind: "Camera").errorDescription == "Camera permission denied") #expect(CameraController.CameraError.permissionDenied(kind: "Camera")
.errorDescription == "Camera permission denied")
#expect(CameraController.CameraError.invalidParams("bad").errorDescription == "bad") #expect(CameraController.CameraError.invalidParams("bad").errorDescription == "bad")
#expect(CameraController.CameraError.captureFailed("nope").errorDescription == "nope") #expect(CameraController.CameraError.captureFailed("nope").errorDescription == "nope")
#expect(CameraController.CameraError.exportFailed("export").errorDescription == "export") #expect(CameraController.CameraError.exportFailed("export").errorDescription == "export")

View File

@@ -20,4 +20,3 @@ import Testing
#expect(triggers == nil) #expect(triggers == nil)
} }
} }

View File

@@ -1,6 +1,6 @@
import Foundation import Foundation
import Testing
import SwabbleKit import SwabbleKit
import Testing
@testable import Clawdbot @testable import Clawdbot
@Suite struct VoiceWakeManagerExtractCommandTests { @Suite struct VoiceWakeManagerExtractCommandTests {

View File

@@ -1,6 +1,6 @@
import Foundation import Foundation
import Testing
import SwabbleKit import SwabbleKit
import Testing
@testable import Clawdbot @testable import Clawdbot
@Suite(.serialized) struct VoiceWakeManagerStateTests { @Suite(.serialized) struct VoiceWakeManagerStateTests {

View File

@@ -55,8 +55,8 @@ final class RemotePortTunnel {
let sshHost = parsed.host.trimmingCharacters(in: .whitespacesAndNewlines) let sshHost = parsed.host.trimmingCharacters(in: .whitespacesAndNewlines)
let remotePortOverride = let remotePortOverride =
allowRemoteUrlOverride && remotePort == GatewayEnvironment.gatewayPort() allowRemoteUrlOverride && remotePort == GatewayEnvironment.gatewayPort()
? Self.resolveRemotePortOverride(for: sshHost) ? Self.resolveRemotePortOverride(for: sshHost)
: nil : nil
let resolvedRemotePort = remotePortOverride ?? remotePort let resolvedRemotePort = remotePortOverride ?? remotePort
if let override = remotePortOverride { if let override = remotePortOverride {
Self.logger.info( Self.logger.info(

View File

@@ -1,6 +1,6 @@
import ClawdbotProtocol
import Foundation import Foundation
import Testing import Testing
import ClawdbotProtocol
@testable import Clawdbot @testable import Clawdbot
@Suite @Suite

View File

@@ -29,4 +29,3 @@ struct AnthropicOAuthCodeStateTests {
#expect(parsed == .init(code: "abcDEF1234", state: "stateXYZ9876")) #expect(parsed == .init(code: "abcDEF1234", state: "stateXYZ9876"))
} }
} }

View File

@@ -19,4 +19,3 @@ import Testing
#expect(high.quality == 1.0) #expect(high.quality == 1.0)
} }
} }

View File

@@ -59,4 +59,3 @@ import Testing
} }
} }
} }

View File

@@ -8,7 +8,8 @@ import Testing
@MainActor @MainActor
struct CanvasWindowSmokeTests { struct CanvasWindowSmokeTests {
@Test func panelControllerShowsAndHides() async throws { @Test func panelControllerShowsAndHides() async throws {
let root = FileManager.default.temporaryDirectory.appendingPathComponent("clawdbot-canvas-test-\(UUID().uuidString)") let root = FileManager.default.temporaryDirectory
.appendingPathComponent("clawdbot-canvas-test-\(UUID().uuidString)")
try FileManager.default.createDirectory(at: root, withIntermediateDirectories: true) try FileManager.default.createDirectory(at: root, withIntermediateDirectories: true)
defer { try? FileManager.default.removeItem(at: root) } defer { try? FileManager.default.removeItem(at: root) }
@@ -30,7 +31,8 @@ struct CanvasWindowSmokeTests {
} }
@Test func windowControllerShowsAndCloses() async throws { @Test func windowControllerShowsAndCloses() async throws {
let root = FileManager.default.temporaryDirectory.appendingPathComponent("clawdbot-canvas-test-\(UUID().uuidString)") let root = FileManager.default.temporaryDirectory
.appendingPathComponent("clawdbot-canvas-test-\(UUID().uuidString)")
try FileManager.default.createDirectory(at: root, withIntermediateDirectories: true) try FileManager.default.createDirectory(at: root, withIntermediateDirectories: true)
defer { try? FileManager.default.removeItem(at: root) } defer { try? FileManager.default.removeItem(at: root) }

View File

@@ -10,8 +10,7 @@ struct ConfigStoreTests {
await ConfigStore._testSetOverrides(.init( await ConfigStore._testSetOverrides(.init(
isRemoteMode: { true }, isRemoteMode: { true },
loadLocal: { localHit = true; return ["local": true] }, loadLocal: { localHit = true; return ["local": true] },
loadRemote: { remoteHit = true; return ["remote": true] } loadRemote: { remoteHit = true; return ["remote": true] }))
))
let result = await ConfigStore.load() let result = await ConfigStore.load()
@@ -27,8 +26,7 @@ struct ConfigStoreTests {
await ConfigStore._testSetOverrides(.init( await ConfigStore._testSetOverrides(.init(
isRemoteMode: { false }, isRemoteMode: { false },
loadLocal: { localHit = true; return ["local": true] }, loadLocal: { localHit = true; return ["local": true] },
loadRemote: { remoteHit = true; return ["remote": true] } loadRemote: { remoteHit = true; return ["remote": true] }))
))
let result = await ConfigStore.load() let result = await ConfigStore.load()
@@ -44,8 +42,7 @@ struct ConfigStoreTests {
await ConfigStore._testSetOverrides(.init( await ConfigStore._testSetOverrides(.init(
isRemoteMode: { true }, isRemoteMode: { true },
saveLocal: { _ in localHit = true }, saveLocal: { _ in localHit = true },
saveRemote: { _ in remoteHit = true } saveRemote: { _ in remoteHit = true }))
))
try await ConfigStore.save(["remote": true]) try await ConfigStore.save(["remote": true])
@@ -60,8 +57,7 @@ struct ConfigStoreTests {
await ConfigStore._testSetOverrides(.init( await ConfigStore._testSetOverrides(.init(
isRemoteMode: { false }, isRemoteMode: { false },
saveLocal: { _ in localHit = true }, saveLocal: { _ in localHit = true },
saveRemote: { _ in remoteHit = true } saveRemote: { _ in remoteHit = true }))
))
try await ConfigStore.save(["local": true]) try await ConfigStore.save(["local": true])

View File

@@ -12,7 +12,7 @@ struct CronModelsTests {
} }
@Test func scheduleEveryEncodesAndDecodesWithAnchor() throws { @Test func scheduleEveryEncodesAndDecodesWithAnchor() throws {
let schedule = CronSchedule.every(everyMs: 5_000, anchorMs: 10_000) let schedule = CronSchedule.every(everyMs: 5000, anchorMs: 10000)
let data = try JSONEncoder().encode(schedule) let data = try JSONEncoder().encode(schedule)
let decoded = try JSONDecoder().decode(CronSchedule.self, from: data) let decoded = try JSONDecoder().decode(CronSchedule.self, from: data)
#expect(decoded == schedule) #expect(decoded == schedule)

View File

@@ -5,8 +5,10 @@ import Testing
struct DeviceModelCatalogTests { struct DeviceModelCatalogTests {
@Test @Test
func symbolPrefersModelIdentifierPrefixes() { func symbolPrefersModelIdentifierPrefixes() {
#expect(DeviceModelCatalog.symbol(deviceFamily: "iPad", modelIdentifier: "iPad16,6", friendlyName: nil) == "ipad") #expect(DeviceModelCatalog
#expect(DeviceModelCatalog.symbol(deviceFamily: "iPhone", modelIdentifier: "iPhone17,3", friendlyName: nil) == "iphone") .symbol(deviceFamily: "iPad", modelIdentifier: "iPad16,6", friendlyName: nil) == "ipad")
#expect(DeviceModelCatalog
.symbol(deviceFamily: "iPhone", modelIdentifier: "iPhone17,3", friendlyName: nil) == "iphone")
} }
@Test @Test

View File

@@ -21,4 +21,3 @@ import Testing
#expect(GatewayAgentChannel(raw: "unknown") == .last) #expect(GatewayAgentChannel(raw: "unknown") == .last)
} }
} }

View File

@@ -29,4 +29,3 @@ struct GatewayAutostartPolicyTests {
attachExistingOnly: false)) attachExistingOnly: false))
} }
} }

View File

@@ -70,7 +70,7 @@ struct GatewayDiscoveryModelTests {
"tailnetDns": " peters-mac-studio-1.ts.net ", "tailnetDns": " peters-mac-studio-1.ts.net ",
"sshPort": " 2222 ", "sshPort": " 2222 ",
"gatewayPort": " 18799 ", "gatewayPort": " 18799 ",
"cliPath": " /opt/clawdbot " "cliPath": " /opt/clawdbot ",
]) ])
#expect(parsed.lanHost == "studio.local") #expect(parsed.lanHost == "studio.local")
#expect(parsed.tailnetDns == "peters-mac-studio-1.ts.net") #expect(parsed.tailnetDns == "peters-mac-studio-1.ts.net")
@@ -84,7 +84,7 @@ struct GatewayDiscoveryModelTests {
"lanHost": " ", "lanHost": " ",
"tailnetDns": "\n", "tailnetDns": "\n",
"gatewayPort": "nope", "gatewayPort": "nope",
"sshPort": "nope" "sshPort": "nope",
]) ])
#expect(parsed.lanHost == nil) #expect(parsed.lanHost == nil)
#expect(parsed.tailnetDns == nil) #expect(parsed.tailnetDns == nil)

View File

@@ -1,7 +1,7 @@
import AppKit import AppKit
import ClawdbotProtocol
import Foundation import Foundation
import Testing import Testing
import ClawdbotProtocol
@testable import Clawdbot @testable import Clawdbot
@@ -98,17 +98,17 @@ struct LowCoverageHelperTests {
[ [
"CLAWDBOT_GATEWAY_BIND": "Lan", "CLAWDBOT_GATEWAY_BIND": "Lan",
"CLAWDBOT_GATEWAY_TOKEN": " secret ", "CLAWDBOT_GATEWAY_TOKEN": " secret ",
]) ]) {
{ #expect(GatewayLaunchAgentManager._testPreferredGatewayBind() == "lan")
#expect(GatewayLaunchAgentManager._testPreferredGatewayBind() == "lan") #expect(GatewayLaunchAgentManager._testPreferredGatewayToken() == "secret")
#expect(GatewayLaunchAgentManager._testPreferredGatewayToken() == "secret") #expect(
#expect( GatewayLaunchAgentManager._testEscapePlistValue("a&b<c>\"'") ==
GatewayLaunchAgentManager._testEscapePlistValue("a&b<c>\"'") == "a&amp;b&lt;c&gt;&quot;&apos;")
"a&amp;b&lt;c&gt;&quot;&apos;")
#expect(GatewayLaunchAgentManager._testGatewayExecutablePath(bundlePath: "/App") == "/App/Contents/Resources/Relay/clawdbot") #expect(GatewayLaunchAgentManager
#expect(GatewayLaunchAgentManager._testRelayDir(bundlePath: "/App") == "/App/Contents/Resources/Relay") ._testGatewayExecutablePath(bundlePath: "/App") == "/App/Contents/Resources/Relay/clawdbot")
} #expect(GatewayLaunchAgentManager._testRelayDir(bundlePath: "/App") == "/App/Contents/Resources/Relay")
}
} }
@Test func portGuardianParsesListenersAndBuildsReports() { @Test func portGuardianParsesListenersAndBuildsReports() {

View File

@@ -1,7 +1,7 @@
import AppKit import AppKit
import ClawdbotProtocol
import SwiftUI import SwiftUI
import Testing import Testing
import ClawdbotProtocol
@testable import Clawdbot @testable import Clawdbot

View File

@@ -138,7 +138,7 @@ private func waitForListenerReady(_ listener: NWListener, timeoutSeconds: Double
switch state { switch state {
case .ready: case .ready:
finish(.success(())) finish(.success(()))
case .failed(let err): case let .failed(err):
finish(.failure(err)) finish(.failure(err))
case .cancelled: case .cancelled:
finish(.failure(ListenerTimeoutError())) finish(.failure(ListenerTimeoutError()))

View File

@@ -15,7 +15,7 @@ struct MacNodeRuntimeTests {
@Test func handleInvokeRejectsEmptySystemRun() async throws { @Test func handleInvokeRejectsEmptySystemRun() async throws {
let runtime = MacNodeRuntime() let runtime = MacNodeRuntime()
let params = ClawdbotSystemRunParams(command: []) let params = ClawdbotSystemRunParams(command: [])
let json = String(data: try JSONEncoder().encode(params), encoding: .utf8) let json = try String(data: JSONEncoder().encode(params), encoding: .utf8)
let response = await runtime.handleInvoke( let response = await runtime.handleInvoke(
BridgeInvokeRequest(id: "req-2", command: ClawdbotSystemCommand.run.rawValue, paramsJSON: json)) BridgeInvokeRequest(id: "req-2", command: ClawdbotSystemCommand.run.rawValue, paramsJSON: json))
#expect(response.ok == false) #expect(response.ok == false)
@@ -24,7 +24,7 @@ struct MacNodeRuntimeTests {
@Test func handleInvokeRejectsEmptyNotification() async throws { @Test func handleInvokeRejectsEmptyNotification() async throws {
let runtime = MacNodeRuntime() let runtime = MacNodeRuntime()
let params = ClawdbotSystemNotifyParams(title: "", body: "") let params = ClawdbotSystemNotifyParams(title: "", body: "")
let json = String(data: try JSONEncoder().encode(params), encoding: .utf8) let json = try String(data: JSONEncoder().encode(params), encoding: .utf8)
let response = await runtime.handleInvoke( let response = await runtime.handleInvoke(
BridgeInvokeRequest(id: "req-3", command: ClawdbotSystemCommand.notify.rawValue, paramsJSON: json)) BridgeInvokeRequest(id: "req-3", command: ClawdbotSystemCommand.notify.rawValue, paramsJSON: json))
#expect(response.ok == false) #expect(response.ok == false)
@@ -71,7 +71,7 @@ struct MacNodeRuntimeTests {
let runtime = MacNodeRuntime(makeMainActorServices: { services }) let runtime = MacNodeRuntime(makeMainActorServices: { services })
let params = MacNodeScreenRecordParams(durationMs: 250) let params = MacNodeScreenRecordParams(durationMs: 250)
let json = String(data: try JSONEncoder().encode(params), encoding: .utf8) let json = try String(data: JSONEncoder().encode(params), encoding: .utf8)
let response = await runtime.handleInvoke( let response = await runtime.handleInvoke(
BridgeInvokeRequest(id: "req-5", command: MacNodeScreenCommand.record.rawValue, paramsJSON: json)) BridgeInvokeRequest(id: "req-5", command: MacNodeScreenCommand.record.rawValue, paramsJSON: json))
#expect(response.ok == true) #expect(response.ok == true)

View File

@@ -51,4 +51,3 @@ struct ModelCatalogLoaderTests {
#expect(choices.isEmpty) #expect(choices.isEmpty)
} }
} }

View File

@@ -43,4 +43,3 @@ import Testing
#expect(!bins.contains(missingNodeBin.path)) #expect(!bins.contains(missingNodeBin.path))
} }
} }

View File

@@ -9,6 +9,6 @@ import Testing
} }
@Test func policyUsesSlowSafetyInterval() { @Test func policyUsesSlowSafetyInterval() {
#expect(NodePairingReconcilePolicy.activeIntervalMs >= 10_000) #expect(NodePairingReconcilePolicy.activeIntervalMs >= 10000)
} }
} }

View File

@@ -1,6 +1,6 @@
import ClawdbotProtocol
import SwiftUI import SwiftUI
import Testing import Testing
import ClawdbotProtocol
@testable import Clawdbot @testable import Clawdbot
@Suite(.serialized) @Suite(.serialized)

View File

@@ -1,6 +1,6 @@
import Testing
import ClawdbotIPC import ClawdbotIPC
import CoreLocation import CoreLocation
import Testing
@testable import Clawdbot @testable import Clawdbot
@Suite(.serialized) @Suite(.serialized)

View File

@@ -19,4 +19,3 @@ struct ScreenshotSizeTests {
#expect(ScreenshotSize.readPNGSize(data: Data("nope".utf8)) == nil) #expect(ScreenshotSize.readPNGSize(data: Data("nope".utf8)) == nil)
} }
} }

View File

@@ -14,7 +14,7 @@ struct SessionDataTests {
@Test func sessionTokenStatsFormatKTokensRoundsAsExpected() { @Test func sessionTokenStatsFormatKTokensRoundsAsExpected() {
#expect(SessionTokenStats.formatKTokens(999) == "999") #expect(SessionTokenStats.formatKTokens(999) == "999")
#expect(SessionTokenStats.formatKTokens(1000) == "1.0k") #expect(SessionTokenStats.formatKTokens(1000) == "1.0k")
#expect(SessionTokenStats.formatKTokens(12_340) == "12k") #expect(SessionTokenStats.formatKTokens(12340) == "12k")
} }
@Test func sessionTokenStatsPercentUsedClampsTo100() { @Test func sessionTokenStatsPercentUsedClampsTo100() {

View File

@@ -1,5 +1,5 @@
import Testing
import ClawdbotProtocol import ClawdbotProtocol
import Testing
@testable import Clawdbot @testable import Clawdbot
@Suite(.serialized) @Suite(.serialized)

View File

@@ -84,13 +84,13 @@ private func makeWav16Mono(sampleRate: UInt32, samples: Int) -> Data {
return data return data
} }
private extension Data { extension Data {
mutating func appendLEUInt16(_ value: UInt16) { fileprivate mutating func appendLEUInt16(_ value: UInt16) {
var v = value.littleEndian var v = value.littleEndian
Swift.withUnsafeBytes(of: &v) { append(contentsOf: $0) } Swift.withUnsafeBytes(of: &v) { append(contentsOf: $0) }
} }
mutating func appendLEUInt32(_ value: UInt32) { fileprivate mutating func appendLEUInt32(_ value: UInt32) {
var v = value.littleEndian var v = value.littleEndian
Swift.withUnsafeBytes(of: &v) { append(contentsOf: $0) } Swift.withUnsafeBytes(of: &v) { append(contentsOf: $0) }
} }

View File

@@ -98,14 +98,14 @@ enum TestIsolation {
_ values: [String: String?], _ values: [String: String?],
_ body: () async throws -> T) async rethrows -> T _ body: () async throws -> T) async rethrows -> T
{ {
try await Self.withIsolatedState(env: values, defaults: [:], body) try await self.withIsolatedState(env: values, defaults: [:], body)
} }
static func withUserDefaultsValues<T>( static func withUserDefaultsValues<T>(
_ values: [String: Any?], _ values: [String: Any?],
_ body: () async throws -> T) async rethrows -> T _ body: () async throws -> T) async rethrows -> T
{ {
try await Self.withIsolatedState(env: [:], defaults: values, body) try await self.withIsolatedState(env: [:], defaults: values, body)
} }
nonisolated static func tempConfigPath() -> String { nonisolated static func tempConfigPath() -> String {

View File

@@ -26,4 +26,3 @@ struct VoiceWakeOverlayViewSmokeTests {
_ = view.body _ = view.body
} }
} }

View File

@@ -1,6 +1,6 @@
import Foundation import Foundation
import Testing
import SwabbleKit import SwabbleKit
import Testing
@testable import Clawdbot @testable import Clawdbot
@Suite struct VoiceWakeRuntimeTests { @Suite struct VoiceWakeRuntimeTests {

View File

@@ -1,6 +1,6 @@
import Foundation import Foundation
import Testing
import SwabbleKit import SwabbleKit
import Testing
struct VoiceWakeTesterTests { struct VoiceWakeTesterTests {
@Test func matchRespectsGapRequirement() { @Test func matchRespectsGapRequirement() {

View File

@@ -1,6 +1,6 @@
import ClawdbotProtocol
import Foundation import Foundation
import Testing import Testing
import ClawdbotProtocol
@testable import Clawdbot @testable import Clawdbot
@Suite @Suite

View File

@@ -1,5 +1,5 @@
@testable import ClawdbotChatUI
import Testing import Testing
@testable import ClawdbotChatUI
@Suite struct AssistantTextParserTests { @Suite struct AssistantTextParserTests {
@Test func splitsThinkAndFinalSegments() { @Test func splitsThinkAndFinalSegments() {

View File

@@ -24,4 +24,3 @@ import Testing
#expect(BonjourEscapes.decode("Hello\\065World") == "HelloAWorld") #expect(BonjourEscapes.decode("Hello\\065World") == "HelloAWorld")
} }
} }

View File

@@ -40,4 +40,3 @@ import Testing
} }
} }
} }

View File

@@ -13,4 +13,3 @@ import Testing
#expect(decoded.format == .jpeg) #expect(decoded.format == .jpeg)
} }
} }

View File

@@ -1,6 +1,6 @@
@testable import ClawdbotChatUI
import Foundation import Foundation
import Testing import Testing
@testable import ClawdbotChatUI
#if os(macOS) #if os(macOS)
import AppKit import AppKit

View File

@@ -1,7 +1,7 @@
@testable import ClawdbotChatUI
import ClawdbotKit import ClawdbotKit
import Foundation import Foundation
import Testing import Testing
@testable import ClawdbotChatUI
private struct TimeoutError: Error, CustomStringConvertible { private struct TimeoutError: Error, CustomStringConvertible {
let label: String let label: String
@@ -118,20 +118,20 @@ private final class TestChatTransport: @unchecked Sendable, ClawdbotChatTranspor
} }
} }
private extension TestChatTransportState { extension TestChatTransportState {
func setHistoryCallCount(_ v: Int) { fileprivate func setHistoryCallCount(_ v: Int) {
self.historyCallCount = v self.historyCallCount = v
} }
func setSessionsCallCount(_ v: Int) { fileprivate func setSessionsCallCount(_ v: Int) {
self.sessionsCallCount = v self.sessionsCallCount = v
} }
func sentRunIdsAppend(_ v: String) { fileprivate func sentRunIdsAppend(_ v: String) {
self.sentRunIds.append(v) self.sentRunIds.append(v)
} }
func abortedRunIdsAppend(_ v: String) { fileprivate func abortedRunIdsAppend(_ v: String) {
self.abortedRunIds.append(v) self.abortedRunIds.append(v)
} }
} }
@@ -177,7 +177,9 @@ private extension TestChatTransportState {
ts: Int(Date().timeIntervalSince1970 * 1000), ts: Int(Date().timeIntervalSince1970 * 1000),
data: ["text": AnyCodable("streaming…")]))) data: ["text": AnyCodable("streaming…")])))
try await waitUntil("assistant stream visible") { await MainActor.run { vm.streamingAssistantText == "streaming…" } } try await waitUntil("assistant stream visible") {
await MainActor.run { vm.streamingAssistantText == "streaming…" }
}
transport.emit( transport.emit(
.agent( .agent(
@@ -206,7 +208,9 @@ private extension TestChatTransportState {
errorMessage: nil))) errorMessage: nil)))
try await waitUntil("pending run clears") { await MainActor.run { vm.pendingRunCount == 0 } } try await waitUntil("pending run clears") { await MainActor.run { vm.pendingRunCount == 0 } }
try await waitUntil("history refresh") { await MainActor.run { vm.messages.contains(where: { $0.role == "assistant" }) } } try await waitUntil("history refresh") {
await MainActor.run { vm.messages.contains(where: { $0.role == "assistant" }) }
}
#expect(await MainActor.run { vm.streamingAssistantText } == nil) #expect(await MainActor.run { vm.streamingAssistantText } == nil)
#expect(await MainActor.run { vm.pendingToolCalls.isEmpty }) #expect(await MainActor.run { vm.pendingToolCalls.isEmpty })
} }
@@ -247,7 +251,9 @@ private extension TestChatTransportState {
"args": AnyCodable(["x": 1]), "args": AnyCodable(["x": 1]),
]))) ])))
try await waitUntil("streaming active") { await MainActor.run { vm.streamingAssistantText == "external stream" } } try await waitUntil("streaming active") {
await MainActor.run { vm.streamingAssistantText == "external stream" }
}
try await waitUntil("tool call pending") { await MainActor.run { vm.pendingToolCalls.count == 1 } } try await waitUntil("tool call pending") { await MainActor.run { vm.pendingToolCalls.count == 1 } }
transport.emit( transport.emit(
@@ -436,7 +442,9 @@ private extension TestChatTransportState {
ts: Int(Date().timeIntervalSince1970 * 1000), ts: Int(Date().timeIntervalSince1970 * 1000),
data: ["text": AnyCodable("external stream")]))) data: ["text": AnyCodable("external stream")])))
try await waitUntil("streaming active") { await MainActor.run { vm.streamingAssistantText == "external stream" } } try await waitUntil("streaming active") {
await MainActor.run { vm.streamingAssistantText == "external stream" }
}
transport.emit( transport.emit(
.chat( .chat(

View File

@@ -80,7 +80,8 @@ import UniformTypeIdentifiers
} }
let encoded = NSMutableData() let encoded = NSMutableData()
guard let dest = CGImageDestinationCreateWithData(encoded, UTType.jpeg.identifier as CFString, 1, nil) else { guard let dest = CGImageDestinationCreateWithData(encoded, UTType.jpeg.identifier as CFString, 1, nil)
else {
throw NSError(domain: "JPEGTranscoderTests", code: 9) throw NSError(domain: "JPEGTranscoderTests", code: 9)
} }
CGImageDestinationAddImage(dest, img, nil) CGImageDestinationAddImage(dest, img, nil)

View File

@@ -13,4 +13,3 @@ final class TalkPromptBuilderTests: XCTestCase {
XCTAssertTrue(prompt.contains("Assistant speech interrupted at 1.2s.")) XCTAssertTrue(prompt.contains("Assistant speech interrupted at 1.2s."))
} }
} }