Fix Game Pass library sync when subscription plan rows are omitted (#1193)

This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-10-20 11:14:06 -04:00
1 parent 49d1311808
commit ece1df0da8
6 files changed
+185 -9

No files matched your search

@@ -19,6 +19,55 @@ class XboxCatalogTest {
private fun envelope(vararg rows: JSONObject) = JSONObject().put("schema", 1).put("account", "test@example.test")
.put("market", "US").put("checkedAt", now.toString()).put("entitlements", JSONArray(rows.toList()))
private fun access(vararg rows: JSONObject) = XboxCatalog.access(envelope(*rows), "test@example.test", "US", now)
private fun membership() = JSONObject().put("productId", plan).put("status", "Active").put("endDate", "2099-01-01T00:00:00Z")
private fun withMembership(json: JSONObject, vararg plans: JSONObject) = json.put("subscriptions", JSONArray(plans.toList()))
@Test fun separateMembershipRestoresSubscriptionChildrenWithoutInventingOwnership() {
val json = withMembership(envelope(row(game), row(parent, plan)), membership())
assertEquals(mapOf(game to "owned", parent to "gamepass"), XboxCatalog.access(json, "test@example.test", "US", now))
assertTrue(XboxCatalog.access(withMembership(envelope(), membership()), "test@example.test", "US", now).isEmpty())
assertEquals(mapOf(game to "gamepass", parent to "gamepass"), XboxCatalog.access(
withMembership(envelope(row(game, parent), row(parent, plan)), membership()), "test@example.test", "US", now))
}
@Test fun separateMembershipPreservesProductRestrictionsAndExistingPlanEvidence() {
for (member in listOf(membership().put("status", "Expired"), membership().put("endDate", now.toString()))) {
assertTrue(XboxCatalog.access(withMembership(envelope(row(game, plan)), member), "test@example.test", "US", now).isEmpty())
}
assertEquals(mapOf(game to "gamepass"), XboxCatalog.access(
withMembership(envelope(row(game, plan), row(plan))), "test@example.test", "US", now))
for ((key, value) in listOf("status" to "Expired", "isTrial" to true, "special" to true,
"sharingSource" to "Family", "endDate" to now.toString())) {
for (rows in listOf(arrayOf(row(game, plan).put(key, value)), arrayOf(row(game, plan), row(plan).put(key, value)))) {
assertTrue(XboxCatalog.access(withMembership(envelope(*rows), membership()), "test@example.test", "US", now).isEmpty())
}
}
}
@Test fun malformedMembershipFailsTheRefreshInsteadOfBecomingAnEmptySuccessfulLibrary() {
for (json in listOf(
withMembership(envelope(row(game, plan)), membership().put("endDate", "invalid")),
withMembership(envelope(row(game, plan)), membership(), membership()),
withMembership(envelope(row(game, plan)), membership().put("productId", game)),
envelope(row(game, plan)).put("subscriptions", JSONObject.NULL),
)) {
assertThrows(Exception::class.java) { XboxCatalog.access(json, "test@example.test", "US", now) }
}
}
@Test fun membershipCannotCrossAccountMarketOrFreshnessBoundaries() {
for ((key, value) in listOf("account" to "other@example.test", "market" to "GB", "checkedAt" to "2020-01-01T00:00:00Z")) {
val json = withMembership(envelope(row(game, plan)).put(key, value), membership())
assertThrows(IllegalArgumentException::class.java) { XboxCatalog.access(json, "test@example.test", "US", now) }
}
}
@Test fun libraryDiagnosticsContainCountsWithoutAccountOrProductIdentifiers() {
val lines = mutableListOf<String>()
XboxCatalog.access(envelope(row(game), row(parent, plan)), "test@example.test", "US", now, lines::add)
assertEquals(listOf("library entitlements=2 invalid=0 restricted=0 unverified-plan=1 owned=1 gamepass=0"), lines)
assertFalse(lines.single().contains(game) || lines.single().contains(parent) || lines.single().contains("@"))
}
@Test fun purchasedAndSubscriptionAccessRemainDistinct() {
assertEquals(mapOf(game to "owned", parent to "gamepass"), access(row(game), row(parent, plan), row(plan)))