Skip to content

Commit b423966

Browse files
test: pendingCloudResync flag suppresses upgrade conflict text
tests that toggling local-saves-only off results in generic conflict text, while an app update results in upgrade-specific text. uses real Robolectric-backed DataStore instead of mock.
1 parent a7d47f8 commit b423966

1 file changed

Lines changed: 75 additions & 0 deletions

File tree

app/src/test/java/app/gamenative/service/SteamAutoCloudTest.kt

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package app.gamenative.service
33
import android.content.Context
44
import androidx.room.Room
55
import androidx.test.core.app.ApplicationProvider
6+
import app.gamenative.PrefManager
67
import app.gamenative.data.ConfigInfo
78
import app.gamenative.data.FileChangeLists
89
import app.gamenative.data.PostSyncInfo
@@ -25,6 +26,7 @@ import `in`.dragonbra.javasteam.steam.handlers.steamcloud.SteamCloud
2526
import `in`.dragonbra.javasteam.steam.handlers.steamcloud.FileDownloadInfo
2627
import `in`.dragonbra.javasteam.steam.steamclient.configuration.SteamConfiguration
2728
import app.gamenative.enums.SyncResult
29+
import app.gamenative.utils.CURRENT_UFS_PARSE_VERSION
2830
import `in`.dragonbra.javasteam.util.crypto.CryptoHelper
2931
import kotlinx.coroutines.runBlocking
3032
import okhttp3.Call
@@ -69,6 +71,10 @@ class SteamAutoCloudTest {
6971
@Before
7072
fun setUp() {
7173
context = ApplicationProvider.getApplicationContext()
74+
75+
// PrefManager uses a real Robolectric-backed DataStore so pendingCloudResync persists
76+
PrefManager.init(context)
77+
7278
tempDir = File.createTempFile("steam_autocloud_test_", null)
7379
tempDir.delete()
7480
tempDir.mkdirs()
@@ -234,6 +240,8 @@ class SteamAutoCloudTest {
234240

235241
@After
236242
fun tearDown() {
243+
PrefManager.pendingCloudResync = emptySet()
244+
237245
// Clean up ImageFs directory first (files created in wineprefix)
238246
// This is critical because ImageFs uses context.getFilesDir() which is inside Robolectric's temp directory
239247
try {
@@ -2052,5 +2060,72 @@ class SteamAutoCloudTest {
20522060
assertEquals(SyncResult.Success, result!!.syncResult)
20532061
assertTrue("Should have downloaded files", result.filesDownloaded > 0)
20542062
}
2063+
2064+
// ── Scenario 14: pendingCloudResync flag suppresses upgrade conflict text ──
2065+
// When local-saves-only is toggled off, the cache is cleared and the appId is added
2066+
// to pendingCloudResync. The conflict should still fire, but conflictUfsVersion
2067+
// should be null (generic text, not upgrade-specific).
2068+
@Test
2069+
fun cacheCleared_pendingResync_conflictWithoutUpgradeText() = runBlocking {
2070+
db.appChangeNumbersDao().deleteByAppId(steamAppId)
2071+
db.appFileChangeListsDao().deleteByAppId(steamAppId)
2072+
assertTrue("Precondition: local save files exist", saveFilesDir.listFiles()!!.isNotEmpty())
2073+
2074+
// simulate local-saves toggle-off: appId in pendingCloudResync
2075+
PrefManager.pendingCloudResync = setOf(steamAppId)
2076+
2077+
every { mockSteamCloud.getAppFileListChange(any(), any(), any()) } returns
2078+
CompletableFuture.completedFuture(makeCloudFileChangeList(cloudChangeNumber = 5))
2079+
2080+
val testApp = db.steamAppDao().findApp(steamAppId)!!
2081+
val result = SteamAutoCloud.syncUserFiles(
2082+
appInfo = testApp,
2083+
clientId = clientId,
2084+
steamInstance = mockSteamService,
2085+
steamCloud = mockSteamCloud,
2086+
preferredSave = SaveLocation.None,
2087+
prefixToPath = makePrefixToPath(),
2088+
).await()
2089+
2090+
assertNotNull(result)
2091+
assertEquals("Should still be Conflict", SyncResult.Conflict, result!!.syncResult)
2092+
assertNull(
2093+
"conflictUfsVersion should be null — generic text, not upgrade",
2094+
result.conflictUfsVersion,
2095+
)
2096+
}
2097+
2098+
// ── Scenario 15: Without pendingCloudResync, conflict sets conflictUfsVersion ──
2099+
// Same setup as scenario 14 but without the flag — should get upgrade text.
2100+
@Test
2101+
fun cacheCleared_noPendingResync_conflictWithUpgradeText() = runBlocking {
2102+
db.appChangeNumbersDao().deleteByAppId(steamAppId)
2103+
db.appFileChangeListsDao().deleteByAppId(steamAppId)
2104+
assertTrue("Precondition: local save files exist", saveFilesDir.listFiles()!!.isNotEmpty())
2105+
2106+
// no pendingCloudResync flag
2107+
PrefManager.pendingCloudResync = emptySet()
2108+
2109+
every { mockSteamCloud.getAppFileListChange(any(), any(), any()) } returns
2110+
CompletableFuture.completedFuture(makeCloudFileChangeList(cloudChangeNumber = 5))
2111+
2112+
val testApp = db.steamAppDao().findApp(steamAppId)!!
2113+
val result = SteamAutoCloud.syncUserFiles(
2114+
appInfo = testApp,
2115+
clientId = clientId,
2116+
steamInstance = mockSteamService,
2117+
steamCloud = mockSteamCloud,
2118+
preferredSave = SaveLocation.None,
2119+
prefixToPath = makePrefixToPath(),
2120+
).await()
2121+
2122+
assertNotNull(result)
2123+
assertEquals("Should be Conflict", SyncResult.Conflict, result!!.syncResult)
2124+
assertEquals(
2125+
"conflictUfsVersion should be set for upgrade text",
2126+
CURRENT_UFS_PARSE_VERSION,
2127+
result.conflictUfsVersion,
2128+
)
2129+
}
20552130
}
20562131

0 commit comments

Comments
 (0)