mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-31 03:41:51 +00:00
fix(macos): strip "OpenClaw " prefix before parsing gateway version
`openclaw --version` outputs "OpenClaw 2026.x.y-z" but readGatewayVersion() passed the full string to Semver.parse(), which failed on the "OpenClaw " prefix. This caused the app to fall back to reading package.json from a local source checkout (~/Projects/openclaw), reporting a false version mismatch. Strip the product name prefix before parsing so the installed CLI version is correctly recognized.
This commit is contained in:
@@ -317,8 +317,13 @@ enum GatewayEnvironment {
|
||||
bin=\(binary, privacy: .public)
|
||||
""")
|
||||
}
|
||||
let raw = String(data: data, encoding: .utf8)?
|
||||
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)
|
||||
} catch {
|
||||
let elapsedMs = Int(Date().timeIntervalSince(start) * 1000)
|
||||
|
||||
@@ -19,6 +19,9 @@ struct GatewayEnvironmentTests {
|
||||
#expect(Semver.parse("invalid") == nil)
|
||||
#expect(Semver.parse("1.2") == nil)
|
||||
#expect(Semver.parse("1.2.x") == nil)
|
||||
// Product-prefixed output from `openclaw --version` should NOT parse as semver
|
||||
// (the prefix must be stripped by the caller, not the parser).
|
||||
#expect(Semver.parse("OpenClaw 2026.3.23-1") == nil)
|
||||
}
|
||||
|
||||
@Test func `semver compatibility requires same major and not older`() {
|
||||
|
||||
Reference in New Issue
Block a user