mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-04 02:40:24 +00:00
macOS: test gateway version normalization
This commit is contained in:
@@ -291,6 +291,17 @@ enum GatewayEnvironment {
|
||||
|
||||
// MARK: - Internals
|
||||
|
||||
/// Exposed for tests so CLI version output normalization stays local to gateway checks.
|
||||
static func normalizeGatewayVersionOutput(_ raw: String?) -> String? {
|
||||
guard var normalized = raw?.trimmingCharacters(in: .whitespacesAndNewlines), !normalized.isEmpty else {
|
||||
return nil
|
||||
}
|
||||
if normalized.lowercased().hasPrefix("openclaw ") {
|
||||
normalized = String(normalized.dropFirst("openclaw ".count))
|
||||
}
|
||||
return normalized
|
||||
}
|
||||
|
||||
private static func readGatewayVersion(binary: String) -> Semver? {
|
||||
let start = Date()
|
||||
let process = Process()
|
||||
@@ -317,14 +328,8 @@ enum GatewayEnvironment {
|
||||
bin=\(binary, privacy: .public)
|
||||
""")
|
||||
}
|
||||
var raw = String(data: data, encoding: .utf8)?
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
// `openclaw --version` outputs "OpenClaw 2026.x.y"; strip the product prefix
|
||||
// so Semver.parse receives only the version token.
|
||||
if let r = raw, r.lowercased().hasPrefix("openclaw ") {
|
||||
raw = String(r.dropFirst("openclaw ".count))
|
||||
}
|
||||
return Semver.parse(raw)
|
||||
let raw = String(data: data, encoding: .utf8)
|
||||
return Semver.parse(self.normalizeGatewayVersionOutput(raw))
|
||||
} catch {
|
||||
let elapsedMs = Int(Date().timeIntervalSince(start) * 1000)
|
||||
self.logger.error(
|
||||
|
||||
@@ -24,6 +24,12 @@ struct GatewayEnvironmentTests {
|
||||
#expect(Semver.parse("OpenClaw 2026.3.23-1") == nil)
|
||||
}
|
||||
|
||||
@Test func `gateway version output strips product prefix before parsing`() {
|
||||
let normalized = GatewayEnvironment.normalizeGatewayVersionOutput(" OpenClaw 2026.3.23-1 \n")
|
||||
#expect(normalized == "2026.3.23-1")
|
||||
#expect(Semver.parse(normalized) == Semver(major: 2026, minor: 3, patch: 23))
|
||||
}
|
||||
|
||||
@Test func `semver compatibility requires same major and not older`() {
|
||||
let required = Semver(major: 2, minor: 1, patch: 0)
|
||||
#expect(Semver(major: 2, minor: 1, patch: 0).compatible(with: required))
|
||||
|
||||
Reference in New Issue
Block a user