From 02bf939d141e33f3b940e8132bd69776ebaaa39c Mon Sep 17 00:00:00 2001 From: Bhagirath Mehta Date: Mon, 14 Sep 2026 13:14:57 -0500 Subject: [PATCH] Avoid session sidecars for in-memory storage Treat SQLite's :memory: cache path as non-file-backed so telemetry fallback does not leave a physical .ses file in the working directory. Files changed: - lib/offline/LogSessionDataProvider.cpp - tests/functests/LogSessionDataFuncTests.cpp Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: f2382f49-919c-48fe-b04f-5c2b9b2c744c --- lib/offline/LogSessionDataProvider.cpp | 7 ++++--- tests/functests/LogSessionDataFuncTests.cpp | 21 +++++++++++++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/lib/offline/LogSessionDataProvider.cpp b/lib/offline/LogSessionDataProvider.cpp index 68e152d0e..e457dff5b 100644 --- a/lib/offline/LogSessionDataProvider.cpp +++ b/lib/offline/LogSessionDataProvider.cpp @@ -97,7 +97,8 @@ namespace MAT_NS_BEGIN void LogSessionDataProvider::DeleteLogSessionDataFromFile() { - std::string sessionPath = m_cacheFilePath.empty() ? "" : (m_cacheFilePath + ".ses").c_str(); + std::string sessionPath = + (m_cacheFilePath.empty() || m_cacheFilePath == ":memory:") ? "" : m_cacheFilePath + ".ses"; if (!sessionPath.empty() && MAT::FileExists(sessionPath.c_str())) { MAT::FileDelete(sessionPath.c_str()); @@ -108,7 +109,8 @@ namespace MAT_NS_BEGIN { uint64_t sessionFirstTimeLaunch = 0; std::string sessionSDKUid; - std::string sessionPath = m_cacheFilePath.empty() ? "" : (m_cacheFilePath + ".ses").c_str(); + std::string sessionPath = + (m_cacheFilePath.empty() || m_cacheFilePath == ":memory:") ? "" : m_cacheFilePath + ".ses"; if (!sessionPath.empty()) { if (MAT::FileExists(sessionPath.c_str())) @@ -209,4 +211,3 @@ namespace MAT_NS_BEGIN } } MAT_NS_END - diff --git a/tests/functests/LogSessionDataFuncTests.cpp b/tests/functests/LogSessionDataFuncTests.cpp index f1f1dbe68..f675eb36a 100644 --- a/tests/functests/LogSessionDataFuncTests.cpp +++ b/tests/functests/LogSessionDataFuncTests.cpp @@ -14,14 +14,18 @@ using namespace MAT; const std::string SessionFileArgument = "test"; const char* const SessionFile = "test.ses"; +const char* const MemorySessionFile = ":memory:.ses"; class LogSessionDataFuncTests : public ::testing::Test { void CleanupLocalSessionFile() { - if (MAT::FileExists(SessionFile)) + for (const auto* sessionFile : {SessionFile, MemorySessionFile}) { - MAT::FileDelete(SessionFile); + if (MAT::FileExists(sessionFile)) + { + MAT::FileDelete(sessionFile); + } } } @@ -76,6 +80,19 @@ TEST_F(LogSessionDataFuncTests, Constructor_SessionFile_FileCreated) ASSERT_TRUE(MAT::FileExists(SessionFile)); } +TEST_F(LogSessionDataFuncTests, Constructor_InMemoryCache_NoSessionFileCreated) +{ + auto logSessionDataProvider = LogSessionDataProvider(":memory:"); + logSessionDataProvider.CreateLogSessionData(); + ASSERT_NE(logSessionDataProvider.GetLogSessionData(), nullptr); + EXPECT_FALSE(MAT::FileExists(MemorySessionFile)); + + logSessionDataProvider.ResetLogSessionData(); + EXPECT_FALSE(MAT::FileExists(MemorySessionFile)); + logSessionDataProvider.DeleteLogSessionData(); + EXPECT_FALSE(MAT::FileExists(MemorySessionFile)); +} + TEST_F(LogSessionDataFuncTests, Constructor_ValidSessionFileExists_MembersSetToExistingFile) { const std::string validSessionFirstTime{ "123456" };