@@ -41,7 +41,7 @@ struct GatewayEnvironmentTests {
4141 #expect ( Semver . parse ( normalized2 ) == Semver ( major : 2026 , minor : 4 , patch : 2 ) )
4242 }
4343
44- @ Test func `failed global version probe falls back to local package` ( ) async throws {
44+ @ Test func `failed global version probe does not borrow the local package version ` ( ) async throws {
4545 let projectRoot = FileManager . default . temporaryDirectory
4646 . appendingPathComponent ( " openclaw-gateway-environment- \( UUID ( ) . uuidString ) " , isDirectory : true )
4747 try FileManager . default . createDirectory ( at : projectRoot , withIntermediateDirectories : true )
@@ -54,7 +54,58 @@ struct GatewayEnvironmentTests {
5454 projectRoot : projectRoot ,
5555 searchPaths : [ " /usr/bin " ] )
5656
57- #expect ( version == " 2026.7.29 " )
57+ #expect ( version == nil )
58+ #expect ( await GatewayEnvironment . installedGatewayVersion (
59+ gatewayBin : nil ,
60+ projectRoot : projectRoot ,
61+ searchPaths : [ " /usr/bin " ] ) == " 2026.7.29 " )
62+ }
63+
64+ @ Test func `failed gateway probe cannot validate version output from a broken executable` ( ) async throws {
65+ let root = try makeTempDirForTests ( )
66+ defer { try? FileManager . default . removeItem ( at : root ) }
67+ let gateway = root . appendingPathComponent ( " openclaw " )
68+ try " #!/bin/sh \n echo OpenClaw 2026.7.30 \n exit 1 \n "
69+ . write ( to : gateway , atomically : true , encoding : . utf8 )
70+ try FileManager . default . setAttributes ( [ . posixPermissions : 0o755 ] , ofItemAtPath : gateway . path )
71+
72+ let version = await GatewayEnvironment . installedGatewayVersion (
73+ gatewayBin : gateway . path ,
74+ projectRoot : root ,
75+ searchPaths : [ root . path , " /usr/bin " , " /bin " ] )
76+
77+ #expect ( version == nil )
78+ }
79+
80+ @ Test func `broken global gateway remains an actionable error beside a valid checkout` ( ) async throws {
81+ let root = try makeTempDirForTests ( )
82+ defer { try? FileManager . default . removeItem ( at : root ) }
83+ let bin = root . appendingPathComponent ( " node_modules/.bin " , isDirectory : true )
84+ try FileManager . default . createDirectory ( at : bin , withIntermediateDirectories : true )
85+ let node = bin . appendingPathComponent ( " node " )
86+ let gateway = bin . appendingPathComponent ( " openclaw " )
87+ try " #!/bin/sh \n echo v24.15.0 \n " . write ( to : node , atomically : true , encoding : . utf8 )
88+ try " #!/bin/sh \n exit 1 \n " . write ( to : gateway , atomically : true , encoding : . utf8 )
89+ for executable in [ node , gateway ] {
90+ try FileManager . default . setAttributes ( [ . posixPermissions : 0o755 ] , ofItemAtPath : executable . path )
91+ }
92+ let version = GatewayEnvironment . expectedGatewayVersionString ( ) ?? " 2026.7.30 "
93+ try Data ( #"{"version":" \#( version ) "}"# . utf8 ) . write ( to : root . appendingPathComponent ( " package.json " ) )
94+
95+ await TestIsolation . withIsolatedState (
96+ defaults : [ " openclaw.gatewayProjectRootPath " : root . path ] )
97+ {
98+ let gatewayStatus = await GatewayEnvironment . check ( )
99+
100+ guard case let . error ( message ) = gatewayStatus . kind else {
101+ Issue . record ( " Expected an actionable gateway failure, got \( gatewayStatus ) " )
102+ return
103+ }
104+ #expect ( message . contains ( gateway . path ) )
105+ #expect ( message . contains ( " repair " ) )
106+ #expect ( gatewayStatus . gatewayVersion == nil )
107+ #expect ( gatewayStatus . nodeVersion == " 24.15.0 " )
108+ }
58109 }
59110
60111 @ Test func `gateway version probe tolerates loaded host delay` ( ) async throws {
0 commit comments