@quenty/saveslot 1.14.0 → 1.14.1
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 +6 -0
- package/package.json +2 -2
- package/src/Server/SaveSlotLateSettle.spec.lua +122 -0
- package/src/Server/SaveSlotService.lua +54 -23
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
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
|
+
## [1.14.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/saveslot@1.14.0...@quenty/saveslot@1.14.1) (2026-07-23)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **saveslot:** selection chain consumes loads that settle after the player leaves ([f8716a3](https://github.com/Quenty/NevermoreEngine/commit/f8716a37028db5474578ccad1b0d9aa811edd64c))
|
|
11
|
+
|
|
6
12
|
# [1.14.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/saveslot@1.13.1...@quenty/saveslot@1.14.0) (2026-07-23)
|
|
7
13
|
|
|
8
14
|
**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": "1.14.
|
|
3
|
+
"version": "1.14.1",
|
|
4
4
|
"description": "PlayerDataStoreService wrapper for save slots",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"publishConfig": {
|
|
58
58
|
"access": "public"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "327ee65e14e312ad387d864ef8781574e5470ec4"
|
|
61
61
|
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
--!strict
|
|
2
|
+
--[[
|
|
3
|
+
The per-player selection chain (slots loaded -> teleport read -> default slot) runs against
|
|
4
|
+
datastore reads that can settle long after the player left — session-lock and datastore
|
|
5
|
+
retries outlive a leave. A continuation that then calls into the destroyed
|
|
6
|
+
(metatable-stripped) HasSaveSlots binder throws "attempt to call missing method ..." as a
|
|
7
|
+
stray error that fails the whole run. The chain must consume a late settle silently: every
|
|
8
|
+
hop is maid-owned (cancelled with the binder's brio) and re-checks the binder is alive.
|
|
9
|
+
|
|
10
|
+
@class SaveSlotLateSettle.spec.lua
|
|
11
|
+
]]
|
|
12
|
+
local require = require(script.Parent.loader).load(script)
|
|
13
|
+
|
|
14
|
+
local Workspace = game:GetService("Workspace")
|
|
15
|
+
|
|
16
|
+
local DataStoreMock = require("DataStoreMock")
|
|
17
|
+
local Jest = require("Jest")
|
|
18
|
+
local Maid = require("Maid")
|
|
19
|
+
local PlayerMock = require("PlayerMock")
|
|
20
|
+
local PromiseTestUtils = require("PromiseTestUtils")
|
|
21
|
+
local ServiceBag = require("ServiceBag")
|
|
22
|
+
|
|
23
|
+
local afterEach = Jest.Globals.afterEach
|
|
24
|
+
local describe = Jest.Globals.describe
|
|
25
|
+
local expect = Jest.Globals.expect
|
|
26
|
+
local it = Jest.Globals.it
|
|
27
|
+
|
|
28
|
+
local USER_ID = 636363
|
|
29
|
+
|
|
30
|
+
-- Every datastore read yields this long, so the spec can land the unbind inside a chosen
|
|
31
|
+
-- read's in-flight window.
|
|
32
|
+
local READ_YIELD_SECONDS = 0.5
|
|
33
|
+
|
|
34
|
+
local activeController: any = nil
|
|
35
|
+
|
|
36
|
+
afterEach(function()
|
|
37
|
+
-- Safety net for a failing test: destroy is idempotent, so this is a no-op after the test's
|
|
38
|
+
-- own controller:destroy() and a full teardown when an assertion threw before reaching it.
|
|
39
|
+
if activeController then
|
|
40
|
+
local controller = activeController
|
|
41
|
+
activeController = nil
|
|
42
|
+
controller:destroy()
|
|
43
|
+
end
|
|
44
|
+
end)
|
|
45
|
+
|
|
46
|
+
local function setup()
|
|
47
|
+
local maid = Maid.new()
|
|
48
|
+
|
|
49
|
+
local mock = DataStoreMock.new()
|
|
50
|
+
mock:SetYieldTime(READ_YIELD_SECONDS)
|
|
51
|
+
|
|
52
|
+
local serviceBag = maid:Add(ServiceBag.new())
|
|
53
|
+
local playerDataStoreService: any = serviceBag:GetService(require("PlayerDataStoreService"))
|
|
54
|
+
local hasSaveSlotsBinder: any = serviceBag:GetService(require("HasSaveSlots"))
|
|
55
|
+
serviceBag:GetService(require("SaveSlotService"))
|
|
56
|
+
serviceBag:Init()
|
|
57
|
+
playerDataStoreService:SetRobloxDataStore(mock)
|
|
58
|
+
serviceBag:Start()
|
|
59
|
+
|
|
60
|
+
local fakePlayer = maid:Add(PlayerMock.new({ UserId = USER_ID }))
|
|
61
|
+
fakePlayer.Parent = Workspace
|
|
62
|
+
|
|
63
|
+
local destroyed = false
|
|
64
|
+
local controller: any
|
|
65
|
+
controller = {
|
|
66
|
+
hasSaveSlotsBinder = hasSaveSlotsBinder,
|
|
67
|
+
fakePlayer = fakePlayer,
|
|
68
|
+
destroy = function(self: any)
|
|
69
|
+
if destroyed then
|
|
70
|
+
return
|
|
71
|
+
end
|
|
72
|
+
destroyed = true
|
|
73
|
+
if activeController == self then
|
|
74
|
+
activeController = nil
|
|
75
|
+
end
|
|
76
|
+
serviceBag:Destroy()
|
|
77
|
+
maid:DoCleaning()
|
|
78
|
+
-- Any straggler continuation blows up here, inside the test that owns it, rather
|
|
79
|
+
-- than as flake in a later suite.
|
|
80
|
+
task.wait(READ_YIELD_SECONDS * 3)
|
|
81
|
+
end,
|
|
82
|
+
}
|
|
83
|
+
activeController = controller
|
|
84
|
+
|
|
85
|
+
return controller
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
describe("SaveSlotService selection chain vs a player who leaves mid-load", function()
|
|
89
|
+
it("consumes a slots-load still pending when the binder dies", function()
|
|
90
|
+
local controller = setup()
|
|
91
|
+
|
|
92
|
+
local hasSaveSlots =
|
|
93
|
+
assert(controller.hasSaveSlotsBinder:Bind(controller.fakePlayer), "Failed to bind HasSaveSlots")
|
|
94
|
+
local slotsLoaded = hasSaveSlots:PromiseSlotsLoaded()
|
|
95
|
+
|
|
96
|
+
-- Let the service's chain attach to the (still pending) load, then "leave".
|
|
97
|
+
task.wait()
|
|
98
|
+
expect(PromiseTestUtils.awaitSettled(slotsLoaded, 0)).toEqual(false)
|
|
99
|
+
controller.hasSaveSlotsBinder:Unbind(controller.fakePlayer)
|
|
100
|
+
|
|
101
|
+
controller:destroy()
|
|
102
|
+
end)
|
|
103
|
+
|
|
104
|
+
it("consumes a default-slot read that settles after the binder died", function()
|
|
105
|
+
local controller = setup()
|
|
106
|
+
|
|
107
|
+
local hasSaveSlots =
|
|
108
|
+
assert(controller.hasSaveSlotsBinder:Bind(controller.fakePlayer), "Failed to bind HasSaveSlots")
|
|
109
|
+
|
|
110
|
+
-- Play the chain forward to the default-slot resolution: slots loaded, teleport read
|
|
111
|
+
-- consumed, and the last-active-slot datastore read now in its in-flight window.
|
|
112
|
+
expect(PromiseTestUtils.awaitSettled(hasSaveSlots:PromiseSlotsLoaded(), 10)).toEqual(true)
|
|
113
|
+
task.wait()
|
|
114
|
+
|
|
115
|
+
-- The player leaves inside that window; the read settles after the binder is gone.
|
|
116
|
+
-- With the regression, the settle's continuation calls the destroyed binder and a
|
|
117
|
+
-- stray "attempt to call missing method" error fails the run.
|
|
118
|
+
controller.hasSaveSlotsBinder:Unbind(controller.fakePlayer)
|
|
119
|
+
|
|
120
|
+
controller:destroy()
|
|
121
|
+
end)
|
|
122
|
+
end)
|
|
@@ -101,13 +101,24 @@ function SaveSlotService.Start(self: SaveSlotService)
|
|
|
101
101
|
pairMaid:GiveTask(hasSaveSlots:RegisterSummaryProvider(name, provider))
|
|
102
102
|
end))
|
|
103
103
|
|
|
104
|
-
-- Select the slot the player teleported in with, or proceed with the default flow
|
|
105
|
-
|
|
106
|
-
|
|
104
|
+
-- Select the slot the player teleported in with, or proceed with the default flow.
|
|
105
|
+
-- The loads can settle long after this player is gone (session-lock or datastore
|
|
106
|
+
-- retries outlive a leave), so the maid must own the INNER promise too, and each
|
|
107
|
+
-- continuation re-checks the binder is alive: a continuation queued before the maid
|
|
108
|
+
-- died still runs, and calling any method on the destroyed (metatable-stripped)
|
|
109
|
+
-- binder throws.
|
|
110
|
+
maid:GivePromise(hasSaveSlots:PromiseSlotsLoaded()):Then(function(): any
|
|
111
|
+
if not hasSaveSlots.Destroy then
|
|
112
|
+
return nil -- The binder died while the load settled
|
|
113
|
+
end
|
|
114
|
+
return maid:GivePromise(hasSaveSlots:PromiseLoadSaveSlotFromTeleport()):Then(function(loadedSlotId): any
|
|
107
115
|
if loadedSlotId then
|
|
108
|
-
return -- Teleported in with a valid slot; it is now selected
|
|
116
|
+
return nil -- Teleported in with a valid slot; it is now selected
|
|
117
|
+
end
|
|
118
|
+
if not hasSaveSlots.Destroy then
|
|
119
|
+
return nil -- The binder died while the teleport read settled
|
|
109
120
|
end
|
|
110
|
-
return self:_promiseSelectDefaultSlot(hasSaveSlots)
|
|
121
|
+
return self:_promiseSelectDefaultSlot(maid, hasSaveSlots)
|
|
111
122
|
end)
|
|
112
123
|
end)
|
|
113
124
|
end))
|
|
@@ -116,33 +127,53 @@ end
|
|
|
116
127
|
--[=[
|
|
117
128
|
Selects the player's last active slot, or creates and selects the default slot.
|
|
118
129
|
Does nothing when explicit selection is required.
|
|
130
|
+
|
|
131
|
+
Every hop is maid-owned and re-checks the binder for the same reason as the caller: any of
|
|
132
|
+
these reads can settle after the player left, and continuing into the destroyed binder throws.
|
|
119
133
|
]=]
|
|
120
|
-
function SaveSlotService._promiseSelectDefaultSlot(
|
|
134
|
+
function SaveSlotService._promiseSelectDefaultSlot(
|
|
135
|
+
self: SaveSlotService,
|
|
136
|
+
maid: any,
|
|
137
|
+
hasSaveSlots: any
|
|
138
|
+
): Promise.Promise<any>?
|
|
121
139
|
if self._selectionRequired then
|
|
122
140
|
return nil -- Consumer handles selection
|
|
123
141
|
end
|
|
124
142
|
|
|
125
|
-
return hasSaveSlots:PromiseLastActiveSlotId()
|
|
126
|
-
|
|
127
|
-
if
|
|
128
|
-
return
|
|
143
|
+
return maid:GivePromise(hasSaveSlots:PromiseLastActiveSlotId())
|
|
144
|
+
:Then(function(lastActiveSlotId: SaveSlotData.SlotId?): any
|
|
145
|
+
if not hasSaveSlots.Destroy then
|
|
146
|
+
return nil
|
|
129
147
|
end
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
:Then(function(defaultSlotId: SaveSlotData.SlotId?)
|
|
135
|
-
if defaultSlotId then
|
|
136
|
-
return defaultSlotId
|
|
137
|
-
else
|
|
138
|
-
return hasSaveSlots:PromiseCreateSlot(SaveSlotConstants.DEFAULT_SLOT_INDEX)
|
|
148
|
+
return maid:GivePromise(hasSaveSlots:PromiseHasSlot(lastActiveSlotId))
|
|
149
|
+
:Then(function(hasLastSlot: boolean): any
|
|
150
|
+
if not hasSaveSlots.Destroy then
|
|
151
|
+
return nil
|
|
139
152
|
end
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
153
|
+
if hasLastSlot then
|
|
154
|
+
return hasSaveSlots:PromiseSelectSlot(lastActiveSlotId)
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
-- Or create and select default slot
|
|
158
|
+
return maid:GivePromise(hasSaveSlots:PromiseSlotIdFromIndex(SaveSlotConstants.DEFAULT_SLOT_INDEX))
|
|
159
|
+
:Then(function(defaultSlotId: SaveSlotData.SlotId?): any
|
|
160
|
+
if not hasSaveSlots.Destroy then
|
|
161
|
+
return nil
|
|
162
|
+
end
|
|
163
|
+
if defaultSlotId then
|
|
164
|
+
return defaultSlotId
|
|
165
|
+
else
|
|
166
|
+
return hasSaveSlots:PromiseCreateSlot(SaveSlotConstants.DEFAULT_SLOT_INDEX)
|
|
167
|
+
end
|
|
168
|
+
end)
|
|
169
|
+
:Then(function(slotId: SaveSlotData.SlotId?): any
|
|
170
|
+
if not slotId or not hasSaveSlots.Destroy then
|
|
171
|
+
return nil
|
|
172
|
+
end
|
|
173
|
+
return hasSaveSlots:PromiseSelectSlot(slotId)
|
|
174
|
+
end)
|
|
143
175
|
end)
|
|
144
176
|
end)
|
|
145
|
-
end)
|
|
146
177
|
end
|
|
147
178
|
|
|
148
179
|
--[=[
|