@quenty/saveslot 2.6.1 → 2.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/package.json +3 -3
- package/src/Server/Binders/HasSaveSlots.Code.spec.lua +5 -0
- package/src/Server/Binders/HasSaveSlots.ExportImport.spec.lua +5 -0
- package/src/Server/Binders/HasSaveSlots.PreSelect.spec.lua +5 -0
- package/src/Server/Binders/HasSaveSlots.SharedStore.spec.lua +5 -0
- package/src/Server/Binders/HasSaveSlots.TransferableEphemeral.spec.lua +5 -0
- package/src/Server/Binders/HasSaveSlots.lua +85 -46
- package/src/Server/Binders/HasSaveSlots.spec.lua +5 -0
- package/src/Server/SaveSlotLateSettle.spec.lua +68 -1
- package/src/Server/SaveSlotLoadFlow.spec.lua +5 -0
- package/src/Server/SaveSlotOverflow.spec.lua +5 -0
- package/src/Server/SaveSlotService.spec.lua +5 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,15 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [2.6.2](https://github.com/Quenty/NevermoreEngine/compare/@quenty/saveslot@2.6.1...@quenty/saveslot@2.6.2) (2026-07-30)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **saveslot:** give the slots-load continuation a consistent return so the type check passes ([43dd6e7](https://github.com/Quenty/NevermoreEngine/commit/43dd6e7a7bc1dc87f3c2e2936f4c05f064edba2b))
|
|
11
|
+
- **saveslot:** guard the import read, and reject rather than fulfil nil when destroyed ([14d551b](https://github.com/Quenty/NevermoreEngine/commit/14d551b7adebae6780cac69b57676328c30ab821))
|
|
12
|
+
- **saveslot:** guard the slots load against settling after the player left ([d274aee](https://github.com/Quenty/NevermoreEngine/commit/d274aee8f135fa0ae3eaccf29c121acda2ea0be6))
|
|
13
|
+
- **saveslot:** guard the transferable-ephemeral read, and pin the seeded slot ([2b76762](https://github.com/Quenty/NevermoreEngine/commit/2b76762320468ba9c0d496857bff5c34b87e1c39))
|
|
14
|
+
|
|
6
15
|
## [2.6.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/saveslot@2.6.0...@quenty/saveslot@2.6.1) (2026-07-30)
|
|
7
16
|
|
|
8
17
|
**Note:** Version bump only for package @quenty/saveslot
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/saveslot",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.2",
|
|
4
4
|
"description": "PlayerDataStoreService wrapper for save slots",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"@quenty/binder": "14.43.1",
|
|
35
35
|
"@quenty/brio": "14.35.1",
|
|
36
36
|
"@quenty/cmdrservice": "13.56.0",
|
|
37
|
-
"@quenty/datastore": "13.51.
|
|
37
|
+
"@quenty/datastore": "13.51.1",
|
|
38
38
|
"@quenty/instanceutils": "13.35.1",
|
|
39
39
|
"@quenty/loader": "10.11.0",
|
|
40
40
|
"@quenty/maid": "3.11.0",
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"publishConfig": {
|
|
58
58
|
"access": "public"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "03307dd337fa003fce541cac45106b0df6fbf7d9"
|
|
61
61
|
}
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
local require = require(script.Parent.loader).load(script)
|
|
9
9
|
|
|
10
10
|
local DataStoreMock = require("DataStoreMock")
|
|
11
|
+
local DataStoreTestUtils = require("DataStoreTestUtils")
|
|
11
12
|
local Jest = require("Jest")
|
|
12
13
|
local PlayerDataStoreService = require("PlayerDataStoreService")
|
|
13
14
|
local PlayerMock = require("PlayerMock")
|
|
@@ -48,6 +49,10 @@ local function setup()
|
|
|
48
49
|
hasSaveSlots.MaxSlotCount.Value = 5
|
|
49
50
|
|
|
50
51
|
local function destroy()
|
|
52
|
+
-- The store the spec loaded is only destroyed by a removal, and a PlayerMock never fires the
|
|
53
|
+
-- real Players.PlayerRemoving, so shut down the way Roblox does or its auto-save loop outlives
|
|
54
|
+
-- this spec and fires inside a later package's window.
|
|
55
|
+
DataStoreTestUtils.awaitServiceShutdown(playerDataStoreService)
|
|
51
56
|
fakePlayer:Destroy()
|
|
52
57
|
serviceBag:Destroy()
|
|
53
58
|
end
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
local require = require(script.Parent.loader).load(script)
|
|
10
10
|
|
|
11
11
|
local DataStoreMock = require("DataStoreMock")
|
|
12
|
+
local DataStoreTestUtils = require("DataStoreTestUtils")
|
|
12
13
|
local Jest = require("Jest")
|
|
13
14
|
local PlayerDataStoreService = require("PlayerDataStoreService")
|
|
14
15
|
local PlayerMock = require("PlayerMock")
|
|
@@ -44,6 +45,10 @@ local function setup()
|
|
|
44
45
|
hasSaveSlots.MaxSlotCount.Value = 5
|
|
45
46
|
|
|
46
47
|
local function destroy()
|
|
48
|
+
-- The store the spec loaded is only destroyed by a removal, and a PlayerMock never fires the
|
|
49
|
+
-- real Players.PlayerRemoving, so shut down the way Roblox does or its auto-save loop outlives
|
|
50
|
+
-- this spec and fires inside a later package's window.
|
|
51
|
+
DataStoreTestUtils.awaitServiceShutdown(playerDataStoreService)
|
|
47
52
|
fakePlayer:Destroy()
|
|
48
53
|
serviceBag:Destroy()
|
|
49
54
|
end
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
local require = require(script.Parent.loader).load(script)
|
|
9
9
|
|
|
10
10
|
local DataStoreMock = require("DataStoreMock")
|
|
11
|
+
local DataStoreTestUtils = require("DataStoreTestUtils")
|
|
11
12
|
local Jest = require("Jest")
|
|
12
13
|
local PlayerDataStoreService = require("PlayerDataStoreService")
|
|
13
14
|
local PlayerMock = require("PlayerMock")
|
|
@@ -73,6 +74,10 @@ local function setup()
|
|
|
73
74
|
activeContext = nil
|
|
74
75
|
end
|
|
75
76
|
|
|
77
|
+
-- The store the spec loaded is only destroyed by a removal, and a PlayerMock never fires the
|
|
78
|
+
-- real Players.PlayerRemoving, so shut down the way Roblox does or its auto-save loop outlives
|
|
79
|
+
-- this spec and fires inside a later package's window.
|
|
80
|
+
DataStoreTestUtils.awaitServiceShutdown(playerDataStoreService)
|
|
76
81
|
fakePlayer:Destroy()
|
|
77
82
|
serviceBag:Destroy()
|
|
78
83
|
end
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
local require = require(script.Parent.loader).load(script)
|
|
9
9
|
|
|
10
10
|
local DataStoreMock = require("DataStoreMock")
|
|
11
|
+
local DataStoreTestUtils = require("DataStoreTestUtils")
|
|
11
12
|
local Jest = require("Jest")
|
|
12
13
|
local PlayerDataStoreService = require("PlayerDataStoreService")
|
|
13
14
|
local PlayerMock = require("PlayerMock")
|
|
@@ -47,6 +48,10 @@ local function setup()
|
|
|
47
48
|
hasSaveSlots.MaxSlotCount.Value = 5
|
|
48
49
|
|
|
49
50
|
local function destroy()
|
|
51
|
+
-- The store the spec loaded is only destroyed by a removal, and a PlayerMock never fires the
|
|
52
|
+
-- real Players.PlayerRemoving, so shut down the way Roblox does or its auto-save loop outlives
|
|
53
|
+
-- this spec and fires inside a later package's window.
|
|
54
|
+
DataStoreTestUtils.awaitServiceShutdown(playerDataStoreService)
|
|
50
55
|
fakePlayer:Destroy()
|
|
51
56
|
serviceBag:Destroy()
|
|
52
57
|
end
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
local require = require(script.Parent.loader).load(script)
|
|
10
10
|
|
|
11
11
|
local DataStoreMock = require("DataStoreMock")
|
|
12
|
+
local DataStoreTestUtils = require("DataStoreTestUtils")
|
|
12
13
|
local Jest = require("Jest")
|
|
13
14
|
local PlayerDataStoreService = require("PlayerDataStoreService")
|
|
14
15
|
local PlayerMock = require("PlayerMock")
|
|
@@ -49,6 +50,10 @@ local function setup()
|
|
|
49
50
|
hasSaveSlots.MaxSlotCount.Value = 5
|
|
50
51
|
|
|
51
52
|
local function destroy()
|
|
53
|
+
-- The store the spec loaded is only destroyed by a removal, and a PlayerMock never fires the
|
|
54
|
+
-- real Players.PlayerRemoving, so shut down the way Roblox does or its auto-save loop outlives
|
|
55
|
+
-- this spec and fires inside a later package's window.
|
|
56
|
+
DataStoreTestUtils.awaitServiceShutdown(playerDataStoreService)
|
|
52
57
|
fakePlayer:Destroy()
|
|
53
58
|
serviceBag:Destroy()
|
|
54
59
|
end
|
|
@@ -418,7 +418,13 @@ function HasSaveSlots.PromiseImportSlotFromSharedDataStore(
|
|
|
418
418
|
self: HasSaveSlots,
|
|
419
419
|
key: string
|
|
420
420
|
): Promise.Promise<SaveSlotData.SlotId>
|
|
421
|
-
|
|
421
|
+
-- Maid-owned like the other shared-store reads: this one is not even gated behind _loadPromise, so
|
|
422
|
+
-- nothing upstream rejects it when the player leaves mid-read.
|
|
423
|
+
return self._maid:GivePromise(self._sharedSaveSlotDataStoreService:PromiseRead(key)):Then(function(export)
|
|
424
|
+
if not self.Destroy then
|
|
425
|
+
return (Promise :: any).rejected() -- Destroyed. Empty, so it stays out of the logs
|
|
426
|
+
end
|
|
427
|
+
|
|
422
428
|
if export == nil then
|
|
423
429
|
return (Promise :: any).rejected(`No save slot stored under \{{key}\}`)
|
|
424
430
|
end
|
|
@@ -440,7 +446,15 @@ function HasSaveSlots.PromiseSelectTransferableEphemeralSlot(
|
|
|
440
446
|
key: string
|
|
441
447
|
): Promise.Promise<SaveSlotData.SlotId>
|
|
442
448
|
return (self._loadPromise :: any):Then(function()
|
|
443
|
-
|
|
449
|
+
-- Maid-owned for the same reason as _promiseLoadSlots: this read runs on the join path (a teleport
|
|
450
|
+
-- arriving with an ephemeral key) and outlives a leave, and its continuation builds a slot.
|
|
451
|
+
return self._maid:GivePromise(self._sharedSaveSlotDataStoreService:PromiseRead(key)):Then(function(export)
|
|
452
|
+
if not self.Destroy then
|
|
453
|
+
-- Destroyed. Rejecting keeps the Promise<SlotId> contract honest -- a nil fulfilment reads as
|
|
454
|
+
-- "imported, no slot" to a caller like SaveSlotCmdrService. Empty, so it stays out of the logs.
|
|
455
|
+
return (Promise :: any).rejected()
|
|
456
|
+
end
|
|
457
|
+
|
|
444
458
|
if export == nil then
|
|
445
459
|
return (Promise :: any).rejected(`No save slot stored under \{{key}\}`)
|
|
446
460
|
end
|
|
@@ -1102,61 +1116,86 @@ function HasSaveSlots.PromiseIncomingSlotId(self: HasSaveSlots): Promise.Promise
|
|
|
1102
1116
|
end)
|
|
1103
1117
|
end
|
|
1104
1118
|
|
|
1119
|
+
-- Maid-owning every hop is what makes this safe, for the same reason as the selection chain in
|
|
1120
|
+
-- SaveSlotService: a session-locked or retrying read settles long after the player left, and Promise has no
|
|
1121
|
+
-- cancellation, so owning only the outermost promise detaches nothing upstream. Calling into this destroyed
|
|
1122
|
+
-- (metatable-stripped) object -- or into its destroyed stores -- throws, and because a datastore load
|
|
1123
|
+
-- resolves inside its UpdateAsync transform, that throw surfaces as a "Transform function error" and takes
|
|
1124
|
+
-- the transform's write down with it. The liveness checks cover a settle that lands mid-teardown, before
|
|
1125
|
+
-- this promise's own maid task was reached. See SaveSlotLateSettle.spec.
|
|
1105
1126
|
function HasSaveSlots._promiseLoadSlots(self: HasSaveSlots): Promise.Promise<{}>
|
|
1106
|
-
return self._playerDataStoreService:PromiseDataStore(self._obj):Then(function(dataStore)
|
|
1127
|
+
return self._maid:GivePromise(self._playerDataStoreService:PromiseDataStore(self._obj)):Then(function(dataStore)
|
|
1128
|
+
if not self.Destroy then
|
|
1129
|
+
return nil -- Destroyed
|
|
1130
|
+
end
|
|
1131
|
+
|
|
1107
1132
|
self._dataStore = dataStore
|
|
1108
1133
|
self._systemStore = dataStore:GetSubStore(SaveSlotConstants.SYSTEM_STORE_KEY)
|
|
1109
1134
|
self._metadataStore = self._systemStore:GetSubStore(SaveSlotConstants.METADATA_STORE_KEY)
|
|
1110
1135
|
|
|
1111
|
-
return self._metadataStore:LoadAll({}):Then(function(metadata)
|
|
1136
|
+
return self._maid:GivePromise(self._metadataStore:LoadAll({})):Then(function(metadata)
|
|
1137
|
+
if not self.Destroy then
|
|
1138
|
+
return nil -- Destroyed
|
|
1139
|
+
end
|
|
1140
|
+
|
|
1112
1141
|
for slotId, data in metadata do
|
|
1113
1142
|
self:_buildSlot(slotId, data)
|
|
1114
1143
|
end
|
|
1115
1144
|
|
|
1116
|
-
return self.
|
|
1117
|
-
self.
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
-- slots. This replaces StoreOnValueChange so an ephemeral selection is invisible to both:
|
|
1122
|
-
-- entering one leaves them pinned to the real slot, and the ephemeral slot is torn down the
|
|
1123
|
-
-- moment it stops being active. We track the id we are leaving to know which of those to do.
|
|
1124
|
-
local previousActiveSlotId: SaveSlotData.SlotId? = activeId
|
|
1125
|
-
|
|
1126
|
-
self._maid:GiveTask(self.ActiveSlotId.Changed:Connect(function()
|
|
1127
|
-
local active = self.ActiveSlotId.Value
|
|
1128
|
-
|
|
1129
|
-
-- Replicate the active transferable-ephemeral slot's shared-store key (nil otherwise) so a
|
|
1130
|
-
-- client-initiated teleport can carry it forward (SaveSlotServiceClient's provider reads this).
|
|
1131
|
-
self.ActiveTransferableEphemeralKey.Value = if active
|
|
1132
|
-
then self._transferableEphemeralKeys[active]
|
|
1133
|
-
else nil
|
|
1134
|
-
|
|
1135
|
-
local leftSlotId = previousActiveSlotId
|
|
1136
|
-
-- Read before the retire below, while the outgoing slot is still in the map.
|
|
1137
|
-
local leavingEphemeral = self:_isEphemeral(leftSlotId)
|
|
1138
|
-
previousActiveSlotId = active
|
|
1139
|
-
|
|
1140
|
-
-- Persist the pointer + remember the Continue target only for real-slot transitions
|
|
1141
|
-
-- (real -> real, real -> nil deselect, nil -> real). Skip both ephemeral cases: entering an
|
|
1142
|
-
-- ephemeral slot must stay invisible to persistence, and leaving one back to no slot must
|
|
1143
|
-
-- leave the real pointer pinned where it was.
|
|
1144
|
-
local enteringEphemeral = self:_isEphemeral(active)
|
|
1145
|
-
local leavingEphemeralToMenu = leavingEphemeral and active == nil
|
|
1146
|
-
if not (enteringEphemeral or leavingEphemeralToMenu) then
|
|
1147
|
-
self._systemStore:Store("activeSlotId", active)
|
|
1148
|
-
if active ~= nil then
|
|
1149
|
-
self._lastActiveSlotId = active
|
|
1150
|
-
self.LastActiveSlotId.Value = active
|
|
1151
|
-
end
|
|
1145
|
+
return self._maid
|
|
1146
|
+
:GivePromise(self._systemStore:Load("activeSlotId"))
|
|
1147
|
+
:Then(function(activeId: SaveSlotData.SlotId?)
|
|
1148
|
+
if not self.Destroy then
|
|
1149
|
+
return nil -- Destroyed
|
|
1152
1150
|
end
|
|
1153
1151
|
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1152
|
+
self._lastActiveSlotId = activeId
|
|
1153
|
+
self.LastActiveSlotId.Value = activeId
|
|
1154
|
+
|
|
1155
|
+
-- The persisted active-slot pointer and the replicated "Continue" target only ever track real
|
|
1156
|
+
-- slots. This replaces StoreOnValueChange so an ephemeral selection is invisible to both:
|
|
1157
|
+
-- entering one leaves them pinned to the real slot, and the ephemeral slot is torn down the
|
|
1158
|
+
-- moment it stops being active. We track the id we are leaving to know which of those to do.
|
|
1159
|
+
local previousActiveSlotId: SaveSlotData.SlotId? = activeId
|
|
1160
|
+
|
|
1161
|
+
self._maid:GiveTask(self.ActiveSlotId.Changed:Connect(function()
|
|
1162
|
+
local active = self.ActiveSlotId.Value
|
|
1163
|
+
|
|
1164
|
+
-- Replicate the active transferable-ephemeral slot's shared-store key (nil otherwise) so a
|
|
1165
|
+
-- client-initiated teleport can carry it forward (SaveSlotServiceClient's provider reads this).
|
|
1166
|
+
self.ActiveTransferableEphemeralKey.Value = if active
|
|
1167
|
+
then self._transferableEphemeralKeys[active]
|
|
1168
|
+
else nil
|
|
1169
|
+
|
|
1170
|
+
local leftSlotId = previousActiveSlotId
|
|
1171
|
+
-- Read before the retire below, while the outgoing slot is still in the map.
|
|
1172
|
+
local leavingEphemeral = self:_isEphemeral(leftSlotId)
|
|
1173
|
+
previousActiveSlotId = active
|
|
1174
|
+
|
|
1175
|
+
-- Persist the pointer + remember the Continue target only for real-slot transitions
|
|
1176
|
+
-- (real -> real, real -> nil deselect, nil -> real). Skip both ephemeral cases: entering an
|
|
1177
|
+
-- ephemeral slot must stay invisible to persistence, and leaving one back to no slot must
|
|
1178
|
+
-- leave the real pointer pinned where it was.
|
|
1179
|
+
local enteringEphemeral = self:_isEphemeral(active)
|
|
1180
|
+
local leavingEphemeralToMenu = leavingEphemeral and active == nil
|
|
1181
|
+
if not (enteringEphemeral or leavingEphemeralToMenu) then
|
|
1182
|
+
self._systemStore:Store("activeSlotId", active)
|
|
1183
|
+
if active ~= nil then
|
|
1184
|
+
self._lastActiveSlotId = active
|
|
1185
|
+
self.LastActiveSlotId.Value = active
|
|
1186
|
+
end
|
|
1187
|
+
end
|
|
1188
|
+
|
|
1189
|
+
-- An ephemeral slot exists only while it is the active slot; retire the one we just left.
|
|
1190
|
+
if leavingEphemeral and leftSlotId ~= active then
|
|
1191
|
+
self:_destroyEphemeralSlot(leftSlotId :: SaveSlotData.SlotId)
|
|
1192
|
+
end
|
|
1193
|
+
end))
|
|
1194
|
+
|
|
1195
|
+
-- Matches the liveness-guard returns above, which make this callback's inferred return
|
|
1196
|
+
-- type nil; falling off the end instead returns no values at all.
|
|
1197
|
+
return nil
|
|
1198
|
+
end)
|
|
1160
1199
|
end)
|
|
1161
1200
|
end)
|
|
1162
1201
|
end
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
local require = require(script.Parent.loader).load(script)
|
|
11
11
|
|
|
12
12
|
local DataStoreMock = require("DataStoreMock")
|
|
13
|
+
local DataStoreTestUtils = require("DataStoreTestUtils")
|
|
13
14
|
local Jest = require("Jest")
|
|
14
15
|
local Maid = require("Maid")
|
|
15
16
|
local Observable = require("Observable")
|
|
@@ -50,6 +51,10 @@ local function setup(mock: DataStoreMock.DataStoreMock?)
|
|
|
50
51
|
hasSaveSlots.MaxSlotCount.Value = 5
|
|
51
52
|
|
|
52
53
|
local function destroy()
|
|
54
|
+
-- The store the spec loaded is only destroyed by a removal, and a PlayerMock never fires the
|
|
55
|
+
-- real Players.PlayerRemoving, so shut down the way Roblox does or its auto-save loop outlives
|
|
56
|
+
-- this spec and fires inside a later package's window.
|
|
57
|
+
DataStoreTestUtils.awaitServiceShutdown(playerDataStoreService)
|
|
53
58
|
fakePlayer:Destroy()
|
|
54
59
|
serviceBag:Destroy()
|
|
55
60
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
--!strict
|
|
2
2
|
--[[
|
|
3
|
-
The per-player selection chain (slots loaded -> teleport read -> default slot) runs against
|
|
3
|
+
The per-player load and selection chain (slots loaded -> teleport read -> default slot) runs against
|
|
4
4
|
datastore reads that can settle long after the player left — session-lock and datastore
|
|
5
5
|
retries outlive a leave. A continuation that then calls into the destroyed
|
|
6
6
|
(metatable-stripped) HasSaveSlots binder throws "attempt to call missing method ..." as a
|
|
@@ -14,10 +14,12 @@ local require = require(script.Parent.loader).load(script)
|
|
|
14
14
|
local Workspace = game:GetService("Workspace")
|
|
15
15
|
|
|
16
16
|
local DataStoreMock = require("DataStoreMock")
|
|
17
|
+
local DataStoreTestUtils = require("DataStoreTestUtils")
|
|
17
18
|
local Jest = require("Jest")
|
|
18
19
|
local Maid = require("Maid")
|
|
19
20
|
local PlayerMock = require("PlayerMock")
|
|
20
21
|
local PromiseTestUtils = require("PromiseTestUtils")
|
|
22
|
+
local SaveSlotConstants = require("SaveSlotConstants")
|
|
21
23
|
local ServiceBag = require("ServiceBag")
|
|
22
24
|
|
|
23
25
|
local afterEach = Jest.Globals.afterEach
|
|
@@ -26,6 +28,7 @@ local expect = Jest.Globals.expect
|
|
|
26
28
|
local it = Jest.Globals.it
|
|
27
29
|
|
|
28
30
|
local USER_ID = 636363
|
|
31
|
+
local EXISTING_SLOT_ID = "e6f0c1a2-late-settle"
|
|
29
32
|
|
|
30
33
|
-- Every datastore read yields this long, so the spec can land the unbind inside a chosen
|
|
31
34
|
-- read's in-flight window.
|
|
@@ -65,6 +68,7 @@ local function setup()
|
|
|
65
68
|
controller = {
|
|
66
69
|
hasSaveSlotsBinder = hasSaveSlotsBinder,
|
|
67
70
|
fakePlayer = fakePlayer,
|
|
71
|
+
mock = mock,
|
|
68
72
|
destroy = function(self: any)
|
|
69
73
|
if destroyed then
|
|
70
74
|
return
|
|
@@ -73,6 +77,10 @@ local function setup()
|
|
|
73
77
|
if activeController == self then
|
|
74
78
|
activeController = nil
|
|
75
79
|
end
|
|
80
|
+
-- The store the spec loaded is only destroyed by a removal, and a PlayerMock never fires the
|
|
81
|
+
-- real Players.PlayerRemoving, so shut down the way Roblox does or its auto-save loop outlives
|
|
82
|
+
-- this spec and fires inside a later package's window.
|
|
83
|
+
DataStoreTestUtils.awaitServiceShutdown(playerDataStoreService)
|
|
76
84
|
serviceBag:Destroy()
|
|
77
85
|
maid:DoCleaning()
|
|
78
86
|
-- Any straggler continuation blows up here, inside the test that owns it, rather
|
|
@@ -85,6 +93,22 @@ local function setup()
|
|
|
85
93
|
return controller
|
|
86
94
|
end
|
|
87
95
|
|
|
96
|
+
-- A returning player's persisted slot, written straight into the mock the way a previous session left it.
|
|
97
|
+
local function seedExistingSlot(controller: any)
|
|
98
|
+
controller.mock:SetRaw(tostring(USER_ID), {
|
|
99
|
+
[SaveSlotConstants.SYSTEM_STORE_KEY] = {
|
|
100
|
+
[SaveSlotConstants.METADATA_STORE_KEY] = {
|
|
101
|
+
[EXISTING_SLOT_ID] = {
|
|
102
|
+
SlotIndex = SaveSlotConstants.DEFAULT_SLOT_INDEX,
|
|
103
|
+
SlotName = "Slot 1",
|
|
104
|
+
CreatedTime = 1,
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
activeSlotId = EXISTING_SLOT_ID,
|
|
108
|
+
},
|
|
109
|
+
})
|
|
110
|
+
end
|
|
111
|
+
|
|
88
112
|
describe("SaveSlotService selection chain vs a player who leaves mid-load", function()
|
|
89
113
|
it("consumes a slots-load still pending when the binder dies", function()
|
|
90
114
|
local controller = setup()
|
|
@@ -101,6 +125,49 @@ describe("SaveSlotService selection chain vs a player who leaves mid-load", func
|
|
|
101
125
|
controller:destroy()
|
|
102
126
|
end)
|
|
103
127
|
|
|
128
|
+
-- Pins that seedExistingSlot really lands where the load reads it. Without this, drift in the raw
|
|
129
|
+
-- layout would quietly reduce the late-settle test below to the empty-metadata case it exists to
|
|
130
|
+
-- replace -- green, and no longer reaching _buildSlot at all.
|
|
131
|
+
it("loads the seeded slot when the player stays", function()
|
|
132
|
+
local controller = setup()
|
|
133
|
+
seedExistingSlot(controller)
|
|
134
|
+
|
|
135
|
+
local hasSaveSlots =
|
|
136
|
+
assert(controller.hasSaveSlotsBinder:Bind(controller.fakePlayer), "Failed to bind HasSaveSlots")
|
|
137
|
+
expect(PromiseTestUtils.awaitSettled(hasSaveSlots:PromiseSlotsLoaded(), 10)).toEqual(true)
|
|
138
|
+
|
|
139
|
+
local hasSlotStatus, hasSlot = PromiseTestUtils.awaitOutcome(hasSaveSlots:PromiseHasSlot(EXISTING_SLOT_ID), 10)
|
|
140
|
+
expect(hasSlotStatus).toEqual("resolved")
|
|
141
|
+
expect(hasSlot).toEqual(true)
|
|
142
|
+
|
|
143
|
+
-- Waiting on the selection itself, rather than PromiseLastActiveSlotId (which can answer from
|
|
144
|
+
-- _lastActiveSlotId while the selection is still in flight), also quiesces the chain before teardown.
|
|
145
|
+
expect(PromiseTestUtils.awaitValue(function()
|
|
146
|
+
return hasSaveSlots.ActiveSlotId.Value == EXISTING_SLOT_ID
|
|
147
|
+
end, 10)).toEqual(true)
|
|
148
|
+
|
|
149
|
+
controller:destroy()
|
|
150
|
+
end)
|
|
151
|
+
|
|
152
|
+
it("consumes a returning player's slots-load that settles after the binder died", function()
|
|
153
|
+
local controller = setup()
|
|
154
|
+
|
|
155
|
+
-- A returning player, so the load settles with metadata to build slots from. The empty-metadata
|
|
156
|
+
-- case above never reaches _buildSlot, which is how a live server kept throwing there
|
|
157
|
+
-- ("attempt to call missing method '_buildSlot'") while that test stayed green.
|
|
158
|
+
seedExistingSlot(controller)
|
|
159
|
+
|
|
160
|
+
local hasSaveSlots =
|
|
161
|
+
assert(controller.hasSaveSlotsBinder:Bind(controller.fakePlayer), "Failed to bind HasSaveSlots")
|
|
162
|
+
local slotsLoaded = hasSaveSlots:PromiseSlotsLoaded()
|
|
163
|
+
|
|
164
|
+
task.wait()
|
|
165
|
+
expect(PromiseTestUtils.awaitSettled(slotsLoaded, 0)).toEqual(false)
|
|
166
|
+
controller.hasSaveSlotsBinder:Unbind(controller.fakePlayer)
|
|
167
|
+
|
|
168
|
+
controller:destroy()
|
|
169
|
+
end)
|
|
170
|
+
|
|
104
171
|
it("consumes a default-slot read that settles after the binder died", function()
|
|
105
172
|
local controller = setup()
|
|
106
173
|
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
local require = require(script.Parent.loader).load(script)
|
|
11
11
|
|
|
12
12
|
local DataStoreMock = require("DataStoreMock")
|
|
13
|
+
local DataStoreTestUtils = require("DataStoreTestUtils")
|
|
13
14
|
local Jest = require("Jest")
|
|
14
15
|
local Maid = require("Maid")
|
|
15
16
|
local PromiseTestUtils = require("PromiseTestUtils")
|
|
@@ -34,6 +35,10 @@ local function setup(mock)
|
|
|
34
35
|
playerDataStoreService = playerDataStoreService,
|
|
35
36
|
mock = mock,
|
|
36
37
|
destroy = function()
|
|
38
|
+
-- The store the spec loaded is only destroyed by a removal, and a PlayerMock never fires the
|
|
39
|
+
-- real Players.PlayerRemoving, so shut down the way Roblox does or its auto-save loop outlives
|
|
40
|
+
-- this spec and fires inside a later package's window.
|
|
41
|
+
DataStoreTestUtils.awaitServiceShutdown(playerDataStoreService)
|
|
37
42
|
maid:DoCleaning()
|
|
38
43
|
end,
|
|
39
44
|
}
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
local require = require(script.Parent.loader).load(script)
|
|
13
13
|
|
|
14
14
|
local DataStoreMock = require("DataStoreMock")
|
|
15
|
+
local DataStoreTestUtils = require("DataStoreTestUtils")
|
|
15
16
|
local Jest = require("Jest")
|
|
16
17
|
local Maid = require("Maid")
|
|
17
18
|
local PromiseTestUtils = require("PromiseTestUtils")
|
|
@@ -36,6 +37,10 @@ local function setup(mock)
|
|
|
36
37
|
playerDataStoreService = playerDataStoreService,
|
|
37
38
|
mock = mock,
|
|
38
39
|
destroy = function()
|
|
40
|
+
-- The store the spec loaded is only destroyed by a removal, and a PlayerMock never fires the
|
|
41
|
+
-- real Players.PlayerRemoving, so shut down the way Roblox does or its auto-save loop outlives
|
|
42
|
+
-- this spec and fires inside a later package's window.
|
|
43
|
+
DataStoreTestUtils.awaitServiceShutdown(playerDataStoreService)
|
|
39
44
|
maid:DoCleaning()
|
|
40
45
|
end,
|
|
41
46
|
}
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
local require = require(script.Parent.loader).load(script)
|
|
11
11
|
|
|
12
12
|
local DataStoreMock = require("DataStoreMock")
|
|
13
|
+
local DataStoreTestUtils = require("DataStoreTestUtils")
|
|
13
14
|
local Jest = require("Jest")
|
|
14
15
|
local Maid = require("Maid")
|
|
15
16
|
local PlayerDataStoreService = require("PlayerDataStoreService")
|
|
@@ -51,6 +52,10 @@ local function setup()
|
|
|
51
52
|
return value
|
|
52
53
|
end,
|
|
53
54
|
destroy = function(_self)
|
|
55
|
+
-- The store the spec loaded is only destroyed by a removal, and a PlayerMock never fires the
|
|
56
|
+
-- real Players.PlayerRemoving, so shut down the way Roblox does or its auto-save loop outlives
|
|
57
|
+
-- this spec and fires inside a later package's window.
|
|
58
|
+
DataStoreTestUtils.awaitServiceShutdown(playerDataStoreService)
|
|
54
59
|
maid:DoCleaning()
|
|
55
60
|
end,
|
|
56
61
|
}
|