From 8405bfe8f585b1dc1e30d25979d680e6af938962 Mon Sep 17 00:00:00 2001 From: shum Date: Thu, 19 Feb 2026 06:33:45 +0000 Subject: [PATCH] core: fix flaky testAppSettings for virtual terminal getDiff race Long command echo may be split by virtual terminal getDiff when readTerminalOutput observes intermediate window states between individual termCommand atomically blocks. Skip echo check for long commands and search for the expected response instead. --- tests/ChatTests/Direct.hs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tests/ChatTests/Direct.hs b/tests/ChatTests/Direct.hs index 2490e97af6..ee4a8fd9f7 100644 --- a/tests/ChatTests/Direct.hs +++ b/tests/ChatTests/Direct.hs @@ -16,7 +16,8 @@ import ChatTests.DBUtils import ChatTests.Utils import Control.Concurrent (threadDelay) import Control.Concurrent.Async (concurrently_) -import Control.Monad (forM_, void) +import Control.Monad (forM_, unless, void) +import System.Timeout (timeout) import Data.Aeson (ToJSON) import qualified Data.Aeson as J import qualified Data.ByteString.Char8 as B @@ -2770,15 +2771,24 @@ testAppSettings ps = withNewTestChat ps "alice" aliceProfile $ \alice -> do let settings = T.unpack . safeDecodeUtf8 . LB.toStrict $ J.encode defaultAppSettings settingsApp = T.unpack . safeDecodeUtf8 . LB.toStrict $ J.encode defaultAppSettings {AS.webrtcICEServers = Just ["non-default.value.com"]} + -- Long command echo may be split by virtual terminal getDiff; + -- skip non-matching lines to find the expected response, then drain artifacts + sendFindResponse cmd resp = do + alice `send` cmd + let go 0 = error $ "expected but not received: " <> resp + go n = do + line <- getTermLine alice + unless (line == resp) $ go (n - 1) + go (50 :: Int) + let drain = timeout 50000 (getTermLine alice) >>= mapM_ (\_ -> drain) + drain -- app-provided defaults - alice ##> ("/_get app settings " <> settingsApp) - alice <## ("app settings: " <> settingsApp) + sendFindResponse ("/_get app settings " <> settingsApp) ("app settings: " <> settingsApp) -- parser defaults fallback alice ##> "/_get app settings" alice <## ("app settings: " <> settings) -- store - alice ##> ("/_save app settings " <> settingsApp) - alice <## "ok" + sendFindResponse ("/_save app settings " <> settingsApp) "ok" -- read back alice ##> "/_get app settings" alice <## ("app settings: " <> settingsApp)