@quenty/saveslot 1.11.0 → 1.13.0
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 +10 -0
- package/package.json +23 -22
- package/src/Server/Binders/HasSaveSlots.spec.lua +7 -83
- package/src/Server/SaveSlotLoadFlow.spec.lua +0 -6
- package/src/Server/SaveSlotOverflow.spec.lua +0 -8
- package/src/Server/SaveSlotService.spec.lua +101 -120
- package/src/Shared/Cmdr/SaveSlotCmdrUtils.spec.lua +0 -11
- package/src/Shared/Data/SaveSlotData.spec.lua +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
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.13.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/saveslot@1.12.0...@quenty/saveslot@1.13.0) (2026-07-23)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- Add baseline player-mock and support across Nevermore for mocked players. ([567d121](https://github.com/Quenty/NevermoreEngine/commit/567d121ffc014b42391554088189a1a6296dda83))
|
|
11
|
+
|
|
12
|
+
# [1.12.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/saveslot@1.11.0...@quenty/saveslot@1.12.0) (2026-07-22)
|
|
13
|
+
|
|
14
|
+
**Note:** Version bump only for package @quenty/saveslot
|
|
15
|
+
|
|
6
16
|
# [1.11.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/saveslot@1.10.0...@quenty/saveslot@1.11.0) (2026-07-21)
|
|
7
17
|
|
|
8
18
|
### Bug Fixes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/saveslot",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0",
|
|
4
4
|
"description": "PlayerDataStoreService wrapper for save slots",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -28,33 +28,34 @@
|
|
|
28
28
|
"Quenty"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@quenty/adorneedata": "7.
|
|
32
|
-
"@quenty/attributeutils": "14.
|
|
33
|
-
"@quenty/baseobject": "10.
|
|
34
|
-
"@quenty/binder": "14.
|
|
35
|
-
"@quenty/brio": "14.
|
|
36
|
-
"@quenty/cmdrservice": "13.
|
|
37
|
-
"@quenty/datastore": "13.
|
|
38
|
-
"@quenty/instanceutils": "13.
|
|
31
|
+
"@quenty/adorneedata": "7.38.0",
|
|
32
|
+
"@quenty/attributeutils": "14.33.0",
|
|
33
|
+
"@quenty/baseobject": "10.15.0",
|
|
34
|
+
"@quenty/binder": "14.41.0",
|
|
35
|
+
"@quenty/brio": "14.33.0",
|
|
36
|
+
"@quenty/cmdrservice": "13.51.0",
|
|
37
|
+
"@quenty/datastore": "13.46.0",
|
|
38
|
+
"@quenty/instanceutils": "13.33.0",
|
|
39
39
|
"@quenty/loader": "10.11.0",
|
|
40
|
-
"@quenty/maid": "3.
|
|
41
|
-
"@quenty/nevermore-test-runner": "1.
|
|
42
|
-
"@quenty/observablecollection": "12.
|
|
43
|
-
"@quenty/playerbinder": "14.
|
|
44
|
-
"@quenty/
|
|
45
|
-
"@quenty/
|
|
46
|
-
"@quenty/
|
|
47
|
-
"@quenty/
|
|
48
|
-
"@quenty/
|
|
40
|
+
"@quenty/maid": "3.11.0",
|
|
41
|
+
"@quenty/nevermore-test-runner": "1.5.0",
|
|
42
|
+
"@quenty/observablecollection": "12.42.0",
|
|
43
|
+
"@quenty/playerbinder": "14.41.0",
|
|
44
|
+
"@quenty/playermock": "1.1.0",
|
|
45
|
+
"@quenty/promise": "10.21.0",
|
|
46
|
+
"@quenty/propertyvalue": "7.33.0",
|
|
47
|
+
"@quenty/remoting": "12.36.0",
|
|
48
|
+
"@quenty/rx": "13.31.0",
|
|
49
|
+
"@quenty/servicebag": "11.20.0",
|
|
49
50
|
"@quenty/signal": "7.13.1",
|
|
50
51
|
"@quenty/table": "3.9.2",
|
|
51
|
-
"@quenty/teleportserviceutils": "9.
|
|
52
|
-
"@quenty/tie": "10.
|
|
53
|
-
"@quenty/valueobject": "13.
|
|
52
|
+
"@quenty/teleportserviceutils": "9.38.0",
|
|
53
|
+
"@quenty/tie": "10.44.0",
|
|
54
|
+
"@quenty/valueobject": "13.34.0",
|
|
54
55
|
"@quentystudios/jest-lua": "3.10.0-quenty.2"
|
|
55
56
|
},
|
|
56
57
|
"publishConfig": {
|
|
57
58
|
"access": "public"
|
|
58
59
|
},
|
|
59
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "1de37218a2bedb8e3f8614a2e09bba9eddc812da"
|
|
60
61
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
--!strict
|
|
2
2
|
--[[
|
|
3
|
-
Integration coverage for the real HasSaveSlots binder, driven against a mocked datastore.
|
|
4
|
-
|
|
5
|
-
PlayerDataStoreManager
|
|
6
|
-
|
|
3
|
+
Integration coverage for the real HasSaveSlots binder, driven against a mocked datastore. A
|
|
4
|
+
PlayerMock with a seeded UserId stands in for a Player -- the load path only reads the UserId,
|
|
5
|
+
which PlayerDataStoreManager resolves natively from the mock; everything else exercises the
|
|
6
|
+
real code.
|
|
7
7
|
|
|
8
8
|
@class HasSaveSlots.spec.lua
|
|
9
9
|
]]
|
|
@@ -12,8 +12,8 @@ local require = require(script.Parent.loader).load(script)
|
|
|
12
12
|
local DataStoreMock = require("DataStoreMock")
|
|
13
13
|
local Jest = require("Jest")
|
|
14
14
|
local Observable = require("Observable")
|
|
15
|
-
local PlayerDataStoreManager = require("PlayerDataStoreManager")
|
|
16
15
|
local PlayerDataStoreService = require("PlayerDataStoreService")
|
|
16
|
+
local PlayerMock = require("PlayerMock")
|
|
17
17
|
local PromiseTestUtils = require("PromiseTestUtils")
|
|
18
18
|
local Rx = require("Rx")
|
|
19
19
|
local SaveSlotDataService = require("SaveSlotDataService")
|
|
@@ -25,49 +25,24 @@ local Workspace = game:GetService("Workspace")
|
|
|
25
25
|
local describe = Jest.Globals.describe
|
|
26
26
|
local expect = Jest.Globals.expect
|
|
27
27
|
local it = Jest.Globals.it
|
|
28
|
-
local afterEach = Jest.Globals.afterEach
|
|
29
28
|
|
|
30
29
|
local FAKE_USER_ID = 424242
|
|
31
30
|
|
|
32
|
-
-- Real implementation, captured at load so the patch can fall through for anything but the fake player.
|
|
33
|
-
local originalToUserId = PlayerDataStoreManager._toPlayerUserIdOrError
|
|
34
|
-
|
|
35
|
-
-- We monkeypatch _toPlayerUserIdOrError directly rather than jest.spyOn: after jest.restoreAllMocks(),
|
|
36
|
-
-- re-spying the same method on the next test is a no-op (spyOn hands back the stale, already-restored
|
|
37
|
-
-- spy without re-patching the object), so only the first test's spy took effect and every later Bind
|
|
38
|
-
-- threw "Bad playerOrUserId". A direct swap re-patches deterministically each setup.
|
|
39
|
-
afterEach(function()
|
|
40
|
-
PlayerDataStoreManager._toPlayerUserIdOrError = originalToUserId
|
|
41
|
-
end)
|
|
42
|
-
|
|
43
31
|
local function setup(mock: DataStoreMock.DataStoreMock?)
|
|
44
32
|
mock = mock or DataStoreMock.new()
|
|
45
33
|
|
|
46
34
|
local serviceBag = ServiceBag.new()
|
|
47
35
|
serviceBag:GetService(require("TeleportDataService"))
|
|
48
|
-
|
|
49
|
-
-- cast to the instance type before calling instance methods.
|
|
50
|
-
local playerDataStoreService = (
|
|
36
|
+
local playerDataStoreService: PlayerDataStoreService.PlayerDataStoreService =
|
|
51
37
|
serviceBag:GetService(PlayerDataStoreService) :: any
|
|
52
|
-
) :: PlayerDataStoreService.PlayerDataStoreService
|
|
53
38
|
local binder = serviceBag:GetService(require("HasSaveSlots"))
|
|
54
39
|
serviceBag:Init()
|
|
55
40
|
playerDataStoreService:SetRobloxDataStore(mock)
|
|
56
41
|
serviceBag:Start()
|
|
57
42
|
|
|
58
|
-
|
|
59
|
-
local fakePlayer = (Instance.new("Folder") :: any) :: Player
|
|
60
|
-
fakePlayer.Name = "FakePlayer"
|
|
43
|
+
local fakePlayer = PlayerMock.new({ UserId = FAKE_USER_ID })
|
|
61
44
|
fakePlayer.Parent = Workspace
|
|
62
45
|
|
|
63
|
-
-- Intercept only the UserId read so a Folder can stand in for a Player. Restored after each test.
|
|
64
|
-
PlayerDataStoreManager._toPlayerUserIdOrError = function(self, playerOrUserId)
|
|
65
|
-
if playerOrUserId == fakePlayer then
|
|
66
|
-
return FAKE_USER_ID
|
|
67
|
-
end
|
|
68
|
-
return originalToUserId(self, playerOrUserId)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
46
|
local hasSaveSlots = assert(binder:Bind(fakePlayer), "Failed to bind HasSaveSlots")
|
|
72
47
|
hasSaveSlots.MaxSlotCount.Value = 5
|
|
73
48
|
|
|
@@ -243,9 +218,6 @@ describe("HasSaveSlots against a fake player (healthy datastore)", function()
|
|
|
243
218
|
end
|
|
244
219
|
deselectPromise:Yield()
|
|
245
220
|
|
|
246
|
-
-- The store observable kills its brio when the slot is cleared. This is the reactive teardown the
|
|
247
|
-
-- game relies on: on deselect the server unbinds per-slot data and removes the character purely
|
|
248
|
-
-- because this brio dies -- no bespoke deselect handling.
|
|
249
221
|
expect(activeBrio:IsDead()).toEqual(true)
|
|
250
222
|
|
|
251
223
|
subscription:Destroy()
|
|
@@ -314,8 +286,6 @@ describe("HasSaveSlots against a fake player (healthy datastore)", function()
|
|
|
314
286
|
return
|
|
315
287
|
end
|
|
316
288
|
|
|
317
|
-
-- Switching slots kills the old slot's store brio and emits a fresh one, so per-slot server state
|
|
318
|
-
-- (data bindings, checkpoints, the character) rebuilds against the newly-selected slot.
|
|
319
289
|
expect(firstBrio:IsDead()).toEqual(true)
|
|
320
290
|
expect(currentBrio:IsDead()).toEqual(false)
|
|
321
291
|
|
|
@@ -444,7 +414,6 @@ describe("HasSaveSlots against a fake player (healthy datastore)", function()
|
|
|
444
414
|
expect(context.hasSaveSlots.ActiveSlotId.Value).toBeNil()
|
|
445
415
|
expect(context.hasSaveSlots.LastActiveSlotId.Value).toEqual(slotId)
|
|
446
416
|
|
|
447
|
-
-- The slot is deselected, not deleted: the last-active pointer still resolves it
|
|
448
417
|
local lastPromise = context.hasSaveSlots:PromiseLastActiveSlotId()
|
|
449
418
|
if not PromiseTestUtils.awaitSettled(lastPromise, 10) then
|
|
450
419
|
expect("lastActive hung").toEqual("lastActive settled")
|
|
@@ -477,7 +446,6 @@ describe("HasSaveSlots against a fake player (healthy datastore)", function()
|
|
|
477
446
|
end
|
|
478
447
|
selectPromise:Yield()
|
|
479
448
|
|
|
480
|
-
-- Deselect first, matching how the cmdr command frees the active slot before deleting it.
|
|
481
449
|
local deselectPromise = context.hasSaveSlots:PromiseDeselectSlot()
|
|
482
450
|
if not PromiseTestUtils.awaitSettled(deselectPromise, 10) then
|
|
483
451
|
expect("deselect hung").toEqual("deselect settled")
|
|
@@ -486,7 +454,6 @@ describe("HasSaveSlots against a fake player (healthy datastore)", function()
|
|
|
486
454
|
end
|
|
487
455
|
deselectPromise:Yield()
|
|
488
456
|
|
|
489
|
-
-- Deselection deliberately keeps remembering the slot for "Continue"...
|
|
490
457
|
expect(context.hasSaveSlots.LastActiveSlotId.Value).toEqual(slotId)
|
|
491
458
|
|
|
492
459
|
local deletePromise = context.hasSaveSlots:PromiseDeleteSlot(slotId)
|
|
@@ -497,7 +464,6 @@ describe("HasSaveSlots against a fake player (healthy datastore)", function()
|
|
|
497
464
|
end
|
|
498
465
|
deletePromise:Yield()
|
|
499
466
|
|
|
500
|
-
-- ...but once that slot is deleted, there is nothing to continue on.
|
|
501
467
|
expect(context.hasSaveSlots.LastActiveSlotId.Value).toBeNil()
|
|
502
468
|
|
|
503
469
|
local lastPromise = context.hasSaveSlots:PromiseLastActiveSlotId()
|
|
@@ -512,7 +478,6 @@ describe("HasSaveSlots against a fake player (healthy datastore)", function()
|
|
|
512
478
|
end)
|
|
513
479
|
|
|
514
480
|
it("deleting a non-last-active slot leaves the continue pointer intact", function()
|
|
515
|
-
-- The clear must be scoped to the resumable slot: deleting some other slot must not wipe it.
|
|
516
481
|
local context = setup()
|
|
517
482
|
|
|
518
483
|
local firstPromise = context.hasSaveSlots:PromiseCreateSlot(1)
|
|
@@ -531,7 +496,6 @@ describe("HasSaveSlots against a fake player (healthy datastore)", function()
|
|
|
531
496
|
end
|
|
532
497
|
local _, secondSlotId = secondPromise:Yield()
|
|
533
498
|
|
|
534
|
-
-- Slot 1 is the last-active; slot 2 is just another slot, and stays deletable while 1 is deselected.
|
|
535
499
|
local selectPromise = context.hasSaveSlots:PromiseSelectSlot(firstSlotId)
|
|
536
500
|
if not PromiseTestUtils.awaitSettled(selectPromise, 10) then
|
|
537
501
|
expect("select hung").toEqual("select settled")
|
|
@@ -635,7 +599,6 @@ describe("HasSaveSlots against a fake player (healthy datastore)", function()
|
|
|
635
599
|
end
|
|
636
600
|
selectPromise:Yield()
|
|
637
601
|
|
|
638
|
-
-- Simulate returning to the menu: no active slot, but the last active is remembered
|
|
639
602
|
context.hasSaveSlots.ActiveSlotId.Value = nil
|
|
640
603
|
expect(context.hasSaveSlots.LastActiveSlotId.Value).toEqual(slotId)
|
|
641
604
|
|
|
@@ -744,7 +707,6 @@ describe("HasSaveSlots against a fake player (healthy datastore)", function()
|
|
|
744
707
|
it("PromiseSelectNewSaveSlot reuses the lowest free index after a deletion", function()
|
|
745
708
|
local context = setup()
|
|
746
709
|
|
|
747
|
-
-- Fill indices 1, 2, 3 (nothing is selected, so all remain deletable)
|
|
748
710
|
local slotIdsByIndex = {}
|
|
749
711
|
for index = 1, 3 do
|
|
750
712
|
local createPromise = context.hasSaveSlots:PromiseCreateSlot(index)
|
|
@@ -757,7 +719,6 @@ describe("HasSaveSlots against a fake player (healthy datastore)", function()
|
|
|
757
719
|
slotIdsByIndex[index] = slotId
|
|
758
720
|
end
|
|
759
721
|
|
|
760
|
-
-- Open a gap at index 2
|
|
761
722
|
local deletePromise = context.hasSaveSlots:PromiseDeleteSlot(slotIdsByIndex[2])
|
|
762
723
|
if not PromiseTestUtils.awaitSettled(deletePromise, 10) then
|
|
763
724
|
expect("delete hung").toEqual("delete settled")
|
|
@@ -766,7 +727,6 @@ describe("HasSaveSlots against a fake player (healthy datastore)", function()
|
|
|
766
727
|
end
|
|
767
728
|
deletePromise:Yield()
|
|
768
729
|
|
|
769
|
-
-- The next new slot fills the gap at 2 rather than appending at 4
|
|
770
730
|
local newPromise = context.hasSaveSlots:PromiseSelectNewSaveSlot()
|
|
771
731
|
if not PromiseTestUtils.awaitSettled(newPromise, 10) then
|
|
772
732
|
expect("new game hung").toEqual("new game settled")
|
|
@@ -798,7 +758,6 @@ describe("HasSaveSlots against a fake player (healthy datastore)", function()
|
|
|
798
758
|
end
|
|
799
759
|
local _, slotId = createPromise:Yield()
|
|
800
760
|
|
|
801
|
-
-- Seed the source slot with some saved data to copy across
|
|
802
761
|
local tracker: any = context.hasSaveSlots
|
|
803
762
|
tracker:_getSlotStore(slotId):Store("Coins", 500)
|
|
804
763
|
|
|
@@ -812,7 +771,6 @@ describe("HasSaveSlots against a fake player (healthy datastore)", function()
|
|
|
812
771
|
expect(type(newSlotId)).toEqual("string")
|
|
813
772
|
expect(newSlotId ~= slotId).toEqual(true)
|
|
814
773
|
|
|
815
|
-
-- The copy lands at the next free index with a marked name
|
|
816
774
|
local metadataPromise = context.hasSaveSlots:PromiseGetSlotMetadata(newSlotId)
|
|
817
775
|
if not PromiseTestUtils.awaitSettled(metadataPromise, 10) then
|
|
818
776
|
expect("metadata hung").toEqual("metadata settled")
|
|
@@ -823,7 +781,6 @@ describe("HasSaveSlots against a fake player (healthy datastore)", function()
|
|
|
823
781
|
expect(metadata.SlotIndex).toEqual(2)
|
|
824
782
|
expect(metadata.SlotName).toEqual("Adventure (Copy)")
|
|
825
783
|
|
|
826
|
-
-- The saved data carried across into the new slot's own store
|
|
827
784
|
local dataPromise = tracker:_getSlotStore(newSlotId):Load("Coins")
|
|
828
785
|
if not PromiseTestUtils.awaitSettled(dataPromise, 10) then
|
|
829
786
|
expect("data hung").toEqual("data settled")
|
|
@@ -838,8 +795,6 @@ describe("HasSaveSlots against a fake player (healthy datastore)", function()
|
|
|
838
795
|
it("PromiseDuplicateSlot into the default slot preserves the system store", function()
|
|
839
796
|
local context = setup()
|
|
840
797
|
|
|
841
|
-
-- Only a non-default slot exists, so the duplicate lands at the free default index (1), whose
|
|
842
|
-
-- store is the shared root alongside the SaveSlots system data.
|
|
843
798
|
local createPromise = context.hasSaveSlots:PromiseCreateSlot(2, { SlotName = "Save" })
|
|
844
799
|
if not PromiseTestUtils.awaitSettled(createPromise, 10) then
|
|
845
800
|
expect("create hung").toEqual("create settled")
|
|
@@ -867,7 +822,6 @@ describe("HasSaveSlots against a fake player (healthy datastore)", function()
|
|
|
867
822
|
end
|
|
868
823
|
expect((metadataPromise:Wait()).SlotIndex).toEqual(1)
|
|
869
824
|
|
|
870
|
-
-- The original slot still resolves -- merging into root did not clobber the system store
|
|
871
825
|
local sourceStillThere = context.hasSaveSlots:PromiseSlotIdFromIndex(2)
|
|
872
826
|
if not PromiseTestUtils.awaitSettled(sourceStillThere, 10) then
|
|
873
827
|
expect("lookup hung").toEqual("lookup settled")
|
|
@@ -876,7 +830,6 @@ describe("HasSaveSlots against a fake player (healthy datastore)", function()
|
|
|
876
830
|
end
|
|
877
831
|
expect((sourceStillThere:Wait())).toEqual(slotId)
|
|
878
832
|
|
|
879
|
-
-- The copied game data landed in the default (root) store
|
|
880
833
|
local dataPromise = tracker:_getSlotStore(newSlotId):Load("Coins")
|
|
881
834
|
if not PromiseTestUtils.awaitSettled(dataPromise, 10) then
|
|
882
835
|
expect("data hung").toEqual("data settled")
|
|
@@ -921,7 +874,6 @@ describe("HasSaveSlots against a fake player (healthy datastore)", function()
|
|
|
921
874
|
end
|
|
922
875
|
selectPromise:Yield()
|
|
923
876
|
|
|
924
|
-
-- Seed the active slot with saved progress the reset must clear
|
|
925
877
|
local tracker: any = context.hasSaveSlots
|
|
926
878
|
tracker:_getSlotStore(slotId):Store("Coins", 500)
|
|
927
879
|
|
|
@@ -935,7 +887,6 @@ describe("HasSaveSlots against a fake player (healthy datastore)", function()
|
|
|
935
887
|
expect(type(newSlotId)).toEqual("string")
|
|
936
888
|
expect(newSlotId ~= slotId).toEqual(true)
|
|
937
889
|
|
|
938
|
-
-- The fresh slot is selected and the old one is gone
|
|
939
890
|
expect(context.hasSaveSlots.ActiveSlotId.Value).toEqual(newSlotId)
|
|
940
891
|
local hasOldPromise = context.hasSaveSlots:PromiseHasSlot(slotId)
|
|
941
892
|
if not PromiseTestUtils.awaitSettled(hasOldPromise, 10) then
|
|
@@ -945,7 +896,6 @@ describe("HasSaveSlots against a fake player (healthy datastore)", function()
|
|
|
945
896
|
end
|
|
946
897
|
expect((hasOldPromise:Wait())).toEqual(false)
|
|
947
898
|
|
|
948
|
-
-- Same index and name carried across into the fresh slot
|
|
949
899
|
local metadataPromise = context.hasSaveSlots:PromiseGetSlotMetadata(newSlotId)
|
|
950
900
|
if not PromiseTestUtils.awaitSettled(metadataPromise, 10) then
|
|
951
901
|
expect("metadata hung").toEqual("metadata settled")
|
|
@@ -956,7 +906,6 @@ describe("HasSaveSlots against a fake player (healthy datastore)", function()
|
|
|
956
906
|
expect(metadata.SlotIndex).toEqual(2)
|
|
957
907
|
expect(metadata.SlotName).toEqual("Adventure")
|
|
958
908
|
|
|
959
|
-
-- The saved progress did not survive into the fresh slot's store
|
|
960
909
|
local dataPromise = tracker:_getSlotStore(newSlotId):Load("Coins")
|
|
961
910
|
if not PromiseTestUtils.awaitSettled(dataPromise, 10) then
|
|
962
911
|
expect("data hung").toEqual("data settled")
|
|
@@ -971,8 +920,6 @@ describe("HasSaveSlots against a fake player (healthy datastore)", function()
|
|
|
971
920
|
it("PromiseResetActiveSlot resets the default slot in place, preserving the system store", function()
|
|
972
921
|
local context = setup()
|
|
973
922
|
|
|
974
|
-
-- Index 1 is the default slot, whose store is the shared root alongside the SaveSlots
|
|
975
|
-
-- system data; the reset must wipe the game data without clobbering that system store.
|
|
976
923
|
local createPromise = context.hasSaveSlots:PromiseCreateSlot(1, { SlotName = "Save" })
|
|
977
924
|
if not PromiseTestUtils.awaitSettled(createPromise, 10) then
|
|
978
925
|
expect("create hung").toEqual("create settled")
|
|
@@ -1000,7 +947,6 @@ describe("HasSaveSlots against a fake player (healthy datastore)", function()
|
|
|
1000
947
|
end
|
|
1001
948
|
local newSlotId = resetPromise:Wait()
|
|
1002
949
|
|
|
1003
|
-
-- The system store survived: the fresh default slot still resolves at index 1
|
|
1004
950
|
local lookupPromise = context.hasSaveSlots:PromiseSlotIdFromIndex(1)
|
|
1005
951
|
if not PromiseTestUtils.awaitSettled(lookupPromise, 10) then
|
|
1006
952
|
expect("lookup hung").toEqual("lookup settled")
|
|
@@ -1009,7 +955,6 @@ describe("HasSaveSlots against a fake player (healthy datastore)", function()
|
|
|
1009
955
|
end
|
|
1010
956
|
expect((lookupPromise:Wait())).toEqual(newSlotId)
|
|
1011
957
|
|
|
1012
|
-
-- The game data in the shared root store was wiped
|
|
1013
958
|
local dataPromise = tracker:_getSlotStore(newSlotId):Load("Coins")
|
|
1014
959
|
if not PromiseTestUtils.awaitSettled(dataPromise, 10) then
|
|
1015
960
|
expect("data hung").toEqual("data settled")
|
|
@@ -1039,7 +984,6 @@ describe("HasSaveSlots against a fake player (healthy datastore)", function()
|
|
|
1039
984
|
it("PromiseResetSlot wipes a non-active slot without touching the active selection", function()
|
|
1040
985
|
local context = setup()
|
|
1041
986
|
|
|
1042
|
-
-- Slot 1 is active; slot 2 is the one we reset and must stay unselected throughout.
|
|
1043
987
|
local activePromise = context.hasSaveSlots:PromiseCreateSlot(1)
|
|
1044
988
|
if not PromiseTestUtils.awaitSettled(activePromise, 10) then
|
|
1045
989
|
expect("active create hung").toEqual("active create settled")
|
|
@@ -1077,10 +1021,8 @@ describe("HasSaveSlots against a fake player (healthy datastore)", function()
|
|
|
1077
1021
|
expect(type(newSlotId)).toEqual("string")
|
|
1078
1022
|
expect(newSlotId ~= targetSlotId).toEqual(true)
|
|
1079
1023
|
|
|
1080
|
-
-- The active slot is untouched and the fresh slot is not selected
|
|
1081
1024
|
expect(context.hasSaveSlots.ActiveSlotId.Value).toEqual(activeSlotId)
|
|
1082
1025
|
|
|
1083
|
-
-- Same index and name carried across; saved progress was wiped
|
|
1084
1026
|
local metadataPromise = context.hasSaveSlots:PromiseGetSlotMetadata(newSlotId)
|
|
1085
1027
|
if not PromiseTestUtils.awaitSettled(metadataPromise, 10) then
|
|
1086
1028
|
expect("metadata hung").toEqual("metadata settled")
|
|
@@ -1105,7 +1047,6 @@ describe("HasSaveSlots against a fake player (healthy datastore)", function()
|
|
|
1105
1047
|
it("PromiseResetSlot keeps the continue pointer on the reset slot when it was last-active", function()
|
|
1106
1048
|
local context = setup()
|
|
1107
1049
|
|
|
1108
|
-
-- Select then deselect so the slot is the resumable last-active but no longer selected.
|
|
1109
1050
|
local createPromise = context.hasSaveSlots:PromiseCreateSlot(1)
|
|
1110
1051
|
if not PromiseTestUtils.awaitSettled(createPromise, 10) then
|
|
1111
1052
|
expect("create hung").toEqual("create settled")
|
|
@@ -1139,7 +1080,6 @@ describe("HasSaveSlots against a fake player (healthy datastore)", function()
|
|
|
1139
1080
|
end
|
|
1140
1081
|
local newSlotId = resetPromise:Wait()
|
|
1141
1082
|
|
|
1142
|
-
-- The resume pointer follows the reset slot to its fresh id, and "Continue" still resolves it
|
|
1143
1083
|
expect(context.hasSaveSlots.ActiveSlotId.Value).toBeNil()
|
|
1144
1084
|
expect(context.hasSaveSlots.LastActiveSlotId.Value).toEqual(newSlotId)
|
|
1145
1085
|
|
|
@@ -1172,7 +1112,6 @@ describe("HasSaveSlots against a fake player (healthy datastore)", function()
|
|
|
1172
1112
|
local context = setup()
|
|
1173
1113
|
context.hasSaveSlots.MaxSlotCount.Value = math.huge
|
|
1174
1114
|
|
|
1175
|
-
-- Index 6 is beyond the setup's finite cap of 5; unbounded must accept it
|
|
1176
1115
|
local createPromise = context.hasSaveSlots:PromiseCreateSlot(6)
|
|
1177
1116
|
if not PromiseTestUtils.awaitSettled(createPromise, 10) then
|
|
1178
1117
|
expect("create hung").toEqual("create settled")
|
|
@@ -1190,7 +1129,6 @@ describe("HasSaveSlots against a fake player (healthy datastore)", function()
|
|
|
1190
1129
|
local context = setup()
|
|
1191
1130
|
context.hasSaveSlots.MaxSlotCount.Value = math.huge
|
|
1192
1131
|
|
|
1193
|
-
-- Allocate past the finite cap of 5; every call still yields a fresh slot
|
|
1194
1132
|
for _ = 1, 7 do
|
|
1195
1133
|
local newPromise = context.hasSaveSlots:PromiseSelectNewSaveSlot()
|
|
1196
1134
|
if not PromiseTestUtils.awaitSettled(newPromise, 10) then
|
|
@@ -1248,7 +1186,6 @@ describe("HasSaveSlots playtime tracking", function()
|
|
|
1248
1186
|
local firstSlotId = createAndSelect(context, 1)
|
|
1249
1187
|
local secondSlotId = createAndSelect(context, 2)
|
|
1250
1188
|
|
|
1251
|
-
-- Returning to the first slot is a second session for it, a first for the second slot
|
|
1252
1189
|
local reselectPromise = context.hasSaveSlots:PromiseSelectSlot(firstSlotId)
|
|
1253
1190
|
if not PromiseTestUtils.awaitSettled(reselectPromise, 10) then
|
|
1254
1191
|
expect("reselect hung").toEqual("reselect settled")
|
|
@@ -1285,7 +1222,6 @@ describe("HasSaveSlots playtime tracking", function()
|
|
|
1285
1222
|
it("does not accrue time before any slot is selected", function()
|
|
1286
1223
|
local context = setup()
|
|
1287
1224
|
|
|
1288
|
-
-- No active slot -> the session is closed, so a flush lands nowhere
|
|
1289
1225
|
local tracker: any = context.hasSaveSlots
|
|
1290
1226
|
tracker:_flushPlaytime()
|
|
1291
1227
|
|
|
@@ -1322,7 +1258,6 @@ describe("HasSaveSlots playtime tracking", function()
|
|
|
1322
1258
|
|
|
1323
1259
|
local afterDeselect = getMetadata(context, slotId).TimePlayed
|
|
1324
1260
|
|
|
1325
|
-
-- A flush after deselection lands nowhere: the session is closed, so the total must not move
|
|
1326
1261
|
tracker._playSessionStart = os.time() - 120
|
|
1327
1262
|
tracker._playSessionLastFlush = os.time() - 120
|
|
1328
1263
|
tracker:_flushPlaytime()
|
|
@@ -1333,8 +1268,6 @@ describe("HasSaveSlots playtime tracking", function()
|
|
|
1333
1268
|
end)
|
|
1334
1269
|
|
|
1335
1270
|
describe("HasSaveSlots summary providers", function()
|
|
1336
|
-
-- Selecting a slot drives the reactive summary aggregation; poll the slot metadata until the
|
|
1337
|
-
-- Summary settles into the expected shape.
|
|
1338
1271
|
local function readSummary(context: any, slotId): any
|
|
1339
1272
|
local promise = context.hasSaveSlots:PromiseGetSlotMetadata(slotId)
|
|
1340
1273
|
if not PromiseTestUtils.awaitSettled(promise, 10) then
|
|
@@ -1506,7 +1439,6 @@ describe("HasSaveSlots against a fake player (datastore down)", function()
|
|
|
1506
1439
|
end)
|
|
1507
1440
|
|
|
1508
1441
|
describe("HasSaveSlots ephemeral slots", function()
|
|
1509
|
-
-- Settles a promise (failing the test on a hang) and returns its value.
|
|
1510
1442
|
local function resolve(promise, timeout: number?)
|
|
1511
1443
|
expect(PromiseTestUtils.awaitSettled(promise, timeout or 10)).toEqual(true)
|
|
1512
1444
|
local ok, value = promise:Yield()
|
|
@@ -1524,7 +1456,6 @@ describe("HasSaveSlots ephemeral slots", function()
|
|
|
1524
1456
|
return slotId
|
|
1525
1457
|
end
|
|
1526
1458
|
|
|
1527
|
-
-- The container SaveSlotDataService lists over; a real slot's folder lives here, an ephemeral one never does.
|
|
1528
1459
|
local function slotContainerHasChild(context: any, slotId): boolean
|
|
1529
1460
|
local container = context.fakePlayer:FindFirstChild("SaveSlots")
|
|
1530
1461
|
return container ~= nil and container:FindFirstChild(slotId) ~= nil
|
|
@@ -1578,9 +1509,6 @@ describe("HasSaveSlots ephemeral slots", function()
|
|
|
1578
1509
|
it("persists a real slot's data but never an ephemeral slot's", function()
|
|
1579
1510
|
local context = setup()
|
|
1580
1511
|
|
|
1581
|
-
-- A real slot whose data is flushed to the datastore -- selecting the ephemeral slot below saves the
|
|
1582
|
-
-- outgoing real slot -- giving a positive control alongside the ephemeral negative. Distinctive values
|
|
1583
|
-
-- so a substring search can't match them coincidentally elsewhere in the serialized blob.
|
|
1584
1512
|
local realId = createAndSelectReal(context, 2)
|
|
1585
1513
|
resolve(context.hasSaveSlots:PromiseActiveSlotStore()):Store("coins", 12321)
|
|
1586
1514
|
|
|
@@ -1596,10 +1524,8 @@ describe("HasSaveSlots ephemeral slots", function()
|
|
|
1596
1524
|
local ephemeralIdFound = string.find(encoded, ephemeralId, 1, true) ~= nil
|
|
1597
1525
|
local ephemeralValueFound = string.find(encoded, "98789", 1, true) ~= nil
|
|
1598
1526
|
|
|
1599
|
-
-- The real slot and its value reached the datastore...
|
|
1600
1527
|
expect(realIdFound).toEqual(true)
|
|
1601
1528
|
expect(realValueFound).toEqual(true)
|
|
1602
|
-
-- ...but nothing of the ephemeral slot did: not its id, not the value written through its store.
|
|
1603
1529
|
expect(ephemeralIdFound).toEqual(false)
|
|
1604
1530
|
expect(ephemeralValueFound).toEqual(false)
|
|
1605
1531
|
|
|
@@ -1626,7 +1552,6 @@ describe("HasSaveSlots ephemeral slots", function()
|
|
|
1626
1552
|
local context = setup()
|
|
1627
1553
|
|
|
1628
1554
|
local realId = createAndSelectReal(context, 1)
|
|
1629
|
-
-- Selecting the ephemeral slot must leave the replicated last-active pinned to the real slot.
|
|
1630
1555
|
selectEphemeral(context)
|
|
1631
1556
|
|
|
1632
1557
|
expect(context.hasSaveSlots.LastActiveSlotId.Value).toEqual(realId)
|
|
@@ -1706,7 +1631,6 @@ describe("HasSaveSlots ephemeral slots", function()
|
|
|
1706
1631
|
local realId = createAndSelectReal(context, 2)
|
|
1707
1632
|
resolve(context.hasSaveSlots:PromiseDeselectSlot())
|
|
1708
1633
|
|
|
1709
|
-
-- An ephemeral round trip in the middle must not steal the Continue slot.
|
|
1710
1634
|
selectEphemeral(context)
|
|
1711
1635
|
resolve(context.hasSaveSlots:PromiseDeselectSlot())
|
|
1712
1636
|
|
|
@@ -20,9 +20,6 @@ local describe = Jest.Globals.describe
|
|
|
20
20
|
local expect = Jest.Globals.expect
|
|
21
21
|
local it = Jest.Globals.it
|
|
22
22
|
|
|
23
|
-
-- Builds a ServiceBag with a mock-injected PlayerDataStoreService, owned by a Maid so destroy() tears
|
|
24
|
-
-- down the service (and the session-locked stores its manager owns), mirroring how the save-slot
|
|
25
|
-
-- system resolves a player's datastore. Read controller.mock to seed or fail the datastore.
|
|
26
23
|
local function setup(mock)
|
|
27
24
|
local maid = Maid.new()
|
|
28
25
|
mock = mock or DataStoreMock.new()
|
|
@@ -42,7 +39,6 @@ local function setup(mock)
|
|
|
42
39
|
}
|
|
43
40
|
end
|
|
44
41
|
|
|
45
|
-
-- Resolves the session-locked datastore for a userId (bounded); returns nil on failure to settle.
|
|
46
42
|
local function resolveDataStore(playerDataStoreService, userId)
|
|
47
43
|
local promise = playerDataStoreService:PromiseDataStore(userId)
|
|
48
44
|
if not PromiseTestUtils.awaitSettled(promise, 10) then
|
|
@@ -94,7 +90,6 @@ describe("save slot load flow (healthy datastore)", function()
|
|
|
94
90
|
local dataStore = resolveDataStore(controller.playerDataStoreService, 1)
|
|
95
91
|
expect(dataStore).never.toBeNil()
|
|
96
92
|
|
|
97
|
-
-- Slot stores live at SaveSlots.slots.<slotId>, matching HasSaveSlots._getSlotStore.
|
|
98
93
|
local slotStore = dataStore
|
|
99
94
|
:GetSubStore(SaveSlotConstants.SYSTEM_STORE_KEY)
|
|
100
95
|
:GetSubStore(SaveSlotConstants.SLOT_STORE_KEY)
|
|
@@ -135,7 +130,6 @@ describe("save slot load flow (datastore down)", function()
|
|
|
135
130
|
local dataStore = resolveDataStore(controller.playerDataStoreService, 1)
|
|
136
131
|
expect(dataStore).never.toBeNil()
|
|
137
132
|
|
|
138
|
-
-- The first actual read (loading slot metadata) triggers the session-locked load.
|
|
139
133
|
local metadataStore =
|
|
140
134
|
dataStore:GetSubStore(SaveSlotConstants.SYSTEM_STORE_KEY):GetSubStore(SaveSlotConstants.METADATA_STORE_KEY)
|
|
141
135
|
|
|
@@ -22,9 +22,6 @@ local describe = Jest.Globals.describe
|
|
|
22
22
|
local expect = Jest.Globals.expect
|
|
23
23
|
local it = Jest.Globals.it
|
|
24
24
|
|
|
25
|
-
-- Builds a ServiceBag with a mock-injected PlayerDataStoreService, owned by a Maid so destroy() tears
|
|
26
|
-
-- down the service (and the session-locked stores its manager owns). Read controller.mock to seed,
|
|
27
|
-
-- fail, or size-limit the datastore.
|
|
28
25
|
local function setup(mock)
|
|
29
26
|
local maid = Maid.new()
|
|
30
27
|
mock = mock or DataStoreMock.new()
|
|
@@ -44,7 +41,6 @@ local function setup(mock)
|
|
|
44
41
|
}
|
|
45
42
|
end
|
|
46
43
|
|
|
47
|
-
-- Resolves the session-locked datastore for a userId (bounded); returns nil on failure to settle.
|
|
48
44
|
local function resolveDataStore(playerDataStoreService, userId)
|
|
49
45
|
local promise = playerDataStoreService:PromiseDataStore(userId)
|
|
50
46
|
if not PromiseTestUtils.awaitSettled(promise, 10) then
|
|
@@ -57,7 +53,6 @@ local function resolveDataStore(playerDataStoreService, userId)
|
|
|
57
53
|
return dataStore
|
|
58
54
|
end
|
|
59
55
|
|
|
60
|
-
-- Slot stores live at SaveSlots.slots.<slotId>, matching HasSaveSlots._getSlotStore.
|
|
61
56
|
local function getSlotStore(dataStore, slotId)
|
|
62
57
|
return dataStore
|
|
63
58
|
:GetSubStore(SaveSlotConstants.SYSTEM_STORE_KEY)
|
|
@@ -74,13 +69,11 @@ describe("save slot overflow save", function()
|
|
|
74
69
|
|
|
75
70
|
local slotStore = getSlotStore(dataStore, "slot-abc")
|
|
76
71
|
|
|
77
|
-
-- A first, well-sized save acquires the session lock and writes the slot.
|
|
78
72
|
slotStore:Store("coins", 25)
|
|
79
73
|
local firstSave = dataStore:Save()
|
|
80
74
|
expect(PromiseTestUtils.awaitSettled(firstSave, 10)).toEqual(true)
|
|
81
75
|
expect((firstSave:Yield())).toEqual(true)
|
|
82
76
|
|
|
83
|
-
-- Now overflow the slot with more data than the key can serialize.
|
|
84
77
|
controller.mock:SetMaxValueLength(8192)
|
|
85
78
|
slotStore:Store("blob", string.rep("A", 32768))
|
|
86
79
|
|
|
@@ -115,7 +108,6 @@ describe("save slot overflow save", function()
|
|
|
115
108
|
expect(PromiseTestUtils.awaitSettled(savePromise, 10)).toEqual(true)
|
|
116
109
|
expect((savePromise:Yield())).toEqual(false)
|
|
117
110
|
|
|
118
|
-
-- The rejected write must not have corrupted the coins we already stored.
|
|
119
111
|
controller.mock:SetMaxValueLength(nil)
|
|
120
112
|
local loadPromise = slotStore:Load("coins")
|
|
121
113
|
expect(PromiseTestUtils.awaitSettled(loadPromise, 10)).toEqual(true)
|
|
@@ -11,7 +11,9 @@ local require = require(script.Parent.loader).load(script)
|
|
|
11
11
|
|
|
12
12
|
local DataStoreMock = require("DataStoreMock")
|
|
13
13
|
local Jest = require("Jest")
|
|
14
|
+
local Maid = require("Maid")
|
|
14
15
|
local PlayerDataStoreService = require("PlayerDataStoreService")
|
|
16
|
+
local PlayerMock = require("PlayerMock")
|
|
15
17
|
local PromiseTestUtils = require("PromiseTestUtils")
|
|
16
18
|
local SaveSlotConstants = require("SaveSlotConstants")
|
|
17
19
|
local SaveSlotService = require("SaveSlotService")
|
|
@@ -23,164 +25,160 @@ local describe = Jest.Globals.describe
|
|
|
23
25
|
local expect = Jest.Globals.expect
|
|
24
26
|
local it = Jest.Globals.it
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
local
|
|
29
|
-
local
|
|
30
|
-
local playerDataStoreService = (
|
|
28
|
+
local function setup()
|
|
29
|
+
local maid = Maid.new()
|
|
30
|
+
local serviceBag = maid:Add(ServiceBag.new())
|
|
31
|
+
local playerDataStoreService: PlayerDataStoreService.PlayerDataStoreService =
|
|
31
32
|
serviceBag:GetService(PlayerDataStoreService) :: any
|
|
32
|
-
) ::
|
|
33
|
-
local
|
|
34
|
-
local teleportDataService = (
|
|
33
|
+
local saveSlotService: SaveSlotService.SaveSlotService = serviceBag:GetService(SaveSlotService) :: any
|
|
34
|
+
local teleportDataService: TeleportDataService.TeleportDataService =
|
|
35
35
|
serviceBag:GetService(TeleportDataService) :: any
|
|
36
|
-
) :: TeleportDataService.TeleportDataService
|
|
37
36
|
serviceBag:Init()
|
|
38
37
|
playerDataStoreService:SetRobloxDataStore(DataStoreMock.new())
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
39
|
+
return {
|
|
40
|
+
serviceBag = serviceBag,
|
|
41
|
+
saveSlotService = saveSlotService,
|
|
42
|
+
teleportDataService = teleportDataService,
|
|
43
|
+
fakePlayer = function(userId: number?): Player
|
|
44
|
+
return maid:Add(PlayerMock.new(if userId ~= nil then { UserId = userId } else nil))
|
|
45
|
+
end,
|
|
46
|
+
awaitBool = function(promise: any): boolean
|
|
47
|
+
expect(PromiseTestUtils.awaitSettled(promise, 5)).toEqual(true)
|
|
48
|
+
local ok, value = promise:Yield()
|
|
49
|
+
expect(ok).toEqual(true)
|
|
50
|
+
return value
|
|
51
|
+
end,
|
|
52
|
+
destroy = function(_self)
|
|
53
|
+
maid:DoCleaning()
|
|
54
|
+
end,
|
|
55
|
+
}
|
|
57
56
|
end
|
|
58
57
|
|
|
59
58
|
describe("SaveSlotService initialization", function()
|
|
60
59
|
it("should initialize and start without a bound player", function()
|
|
61
|
-
local
|
|
60
|
+
local controller = setup()
|
|
62
61
|
|
|
63
62
|
expect(function()
|
|
64
|
-
serviceBag:Start()
|
|
63
|
+
controller.serviceBag:Start()
|
|
65
64
|
end).never.toThrow()
|
|
66
|
-
expect(saveSlotService).never.toBeNil()
|
|
65
|
+
expect(controller.saveSlotService).never.toBeNil()
|
|
67
66
|
|
|
68
|
-
|
|
67
|
+
controller:destroy()
|
|
69
68
|
end)
|
|
70
69
|
end)
|
|
71
70
|
|
|
72
71
|
describe("SaveSlotService.GetExplicitSelectionRequired", function()
|
|
73
72
|
it("should default to false", function()
|
|
74
|
-
local
|
|
73
|
+
local controller = setup()
|
|
75
74
|
|
|
76
|
-
expect(saveSlotService:GetExplicitSelectionRequired()).toEqual(false)
|
|
75
|
+
expect(controller.saveSlotService:GetExplicitSelectionRequired()).toEqual(false)
|
|
77
76
|
|
|
78
|
-
|
|
77
|
+
controller:destroy()
|
|
79
78
|
end)
|
|
80
79
|
|
|
81
80
|
it("should be true after RequireExplicitSelection", function()
|
|
82
|
-
local
|
|
81
|
+
local controller = setup()
|
|
83
82
|
|
|
84
|
-
saveSlotService:RequireExplicitSelection()
|
|
85
|
-
expect(saveSlotService:GetExplicitSelectionRequired()).toEqual(true)
|
|
83
|
+
controller.saveSlotService:RequireExplicitSelection()
|
|
84
|
+
expect(controller.saveSlotService:GetExplicitSelectionRequired()).toEqual(true)
|
|
86
85
|
|
|
87
|
-
|
|
86
|
+
controller:destroy()
|
|
88
87
|
end)
|
|
89
88
|
end)
|
|
90
89
|
|
|
91
90
|
describe("SaveSlotService configuration guards", function()
|
|
92
91
|
it("should reject RequireExplicitSelection after Start", function()
|
|
93
|
-
local
|
|
94
|
-
serviceBag:Start()
|
|
92
|
+
local controller = setup()
|
|
93
|
+
controller.serviceBag:Start()
|
|
95
94
|
|
|
96
95
|
expect(function()
|
|
97
|
-
saveSlotService:RequireExplicitSelection()
|
|
96
|
+
controller.saveSlotService:RequireExplicitSelection()
|
|
98
97
|
end).toThrow("RequireExplicitSelection must be called before Start")
|
|
99
98
|
|
|
100
|
-
|
|
99
|
+
controller:destroy()
|
|
101
100
|
end)
|
|
102
101
|
|
|
103
102
|
it("should reject SetMaxSlotCount after Start", function()
|
|
104
|
-
local
|
|
105
|
-
serviceBag:Start()
|
|
103
|
+
local controller = setup()
|
|
104
|
+
controller.serviceBag:Start()
|
|
106
105
|
|
|
107
106
|
expect(function()
|
|
108
|
-
saveSlotService:SetMaxSlotCount(3)
|
|
107
|
+
controller.saveSlotService:SetMaxSlotCount(3)
|
|
109
108
|
end).toThrow("SetMaxSlotCount must be called before Start")
|
|
110
109
|
|
|
111
|
-
|
|
110
|
+
controller:destroy()
|
|
112
111
|
end)
|
|
113
112
|
|
|
114
113
|
it("should accept a valid SetMaxSlotCount before Start", function()
|
|
115
|
-
local
|
|
114
|
+
local controller = setup()
|
|
116
115
|
|
|
117
116
|
expect(function()
|
|
118
|
-
saveSlotService:SetMaxSlotCount(3)
|
|
117
|
+
controller.saveSlotService:SetMaxSlotCount(3)
|
|
119
118
|
end).never.toThrow()
|
|
120
119
|
|
|
121
|
-
|
|
120
|
+
controller:destroy()
|
|
122
121
|
end)
|
|
123
122
|
|
|
124
123
|
it("should reject a SetMaxSlotCount below 1", function()
|
|
125
|
-
local
|
|
124
|
+
local controller = setup()
|
|
126
125
|
|
|
127
126
|
expect(function()
|
|
128
|
-
saveSlotService:SetMaxSlotCount(0)
|
|
127
|
+
controller.saveSlotService:SetMaxSlotCount(0)
|
|
129
128
|
end).toThrow("Bad maxSlotCount")
|
|
130
129
|
|
|
131
|
-
|
|
130
|
+
controller:destroy()
|
|
132
131
|
end)
|
|
133
132
|
|
|
134
133
|
it("should accept SetUnlimitedSlots before Start", function()
|
|
135
|
-
local
|
|
134
|
+
local controller = setup()
|
|
136
135
|
|
|
137
136
|
expect(function()
|
|
138
|
-
saveSlotService:SetUnlimitedSlots()
|
|
137
|
+
controller.saveSlotService:SetUnlimitedSlots()
|
|
139
138
|
end).never.toThrow()
|
|
140
139
|
|
|
141
|
-
|
|
140
|
+
controller:destroy()
|
|
142
141
|
end)
|
|
143
142
|
|
|
144
143
|
it("should reject SetUnlimitedSlots after Start", function()
|
|
145
|
-
local
|
|
146
|
-
serviceBag:Start()
|
|
144
|
+
local controller = setup()
|
|
145
|
+
controller.serviceBag:Start()
|
|
147
146
|
|
|
148
|
-
-- Delegates to SetMaxSlotCount, so it surfaces the same before-Start guard
|
|
149
147
|
expect(function()
|
|
150
|
-
saveSlotService:SetUnlimitedSlots()
|
|
148
|
+
controller.saveSlotService:SetUnlimitedSlots()
|
|
151
149
|
end).toThrow("SetMaxSlotCount must be called before Start")
|
|
152
150
|
|
|
153
|
-
|
|
151
|
+
controller:destroy()
|
|
154
152
|
end)
|
|
155
153
|
|
|
156
154
|
it("should reject a non-function default summary provider", function()
|
|
157
|
-
local
|
|
155
|
+
local controller = setup()
|
|
158
156
|
|
|
159
157
|
expect(function()
|
|
160
|
-
saveSlotService:RegisterDefaultSummaryProvider("progress", "not a function" :: any)
|
|
158
|
+
controller.saveSlotService:RegisterDefaultSummaryProvider("progress", "not a function" :: any)
|
|
161
159
|
end).toThrow("Bad provider")
|
|
162
160
|
|
|
163
|
-
|
|
161
|
+
controller:destroy()
|
|
164
162
|
end)
|
|
165
163
|
|
|
166
164
|
it("should reject a non-string default summary provider name", function()
|
|
167
|
-
local
|
|
165
|
+
local controller = setup()
|
|
168
166
|
|
|
169
167
|
expect(function()
|
|
170
|
-
saveSlotService:RegisterDefaultSummaryProvider(nil :: any, function()
|
|
168
|
+
controller.saveSlotService:RegisterDefaultSummaryProvider(nil :: any, function()
|
|
171
169
|
return nil :: any
|
|
172
170
|
end)
|
|
173
171
|
end).toThrow("Bad name")
|
|
174
172
|
|
|
175
|
-
|
|
173
|
+
controller:destroy()
|
|
176
174
|
end)
|
|
177
175
|
|
|
178
176
|
it("registers a default summary provider and returns an unregister function", function()
|
|
179
|
-
local
|
|
177
|
+
local controller = setup()
|
|
180
178
|
|
|
181
179
|
local unregister
|
|
182
180
|
expect(function()
|
|
183
|
-
unregister = saveSlotService:RegisterDefaultSummaryProvider("progress", function()
|
|
181
|
+
unregister = controller.saveSlotService:RegisterDefaultSummaryProvider("progress", function()
|
|
184
182
|
return nil :: any
|
|
185
183
|
end)
|
|
186
184
|
end).never.toThrow()
|
|
@@ -190,111 +188,94 @@ describe("SaveSlotService configuration guards", function()
|
|
|
190
188
|
unregister()
|
|
191
189
|
end).never.toThrow()
|
|
192
190
|
|
|
193
|
-
|
|
191
|
+
controller:destroy()
|
|
194
192
|
end)
|
|
195
193
|
end)
|
|
196
194
|
|
|
197
195
|
describe("SaveSlotService internal teleport", function()
|
|
198
196
|
it("should register a provider that carries a single player's active slot id", function()
|
|
199
|
-
local
|
|
200
|
-
serviceBag:Start()
|
|
197
|
+
local controller = setup()
|
|
198
|
+
controller.serviceBag:Start()
|
|
201
199
|
|
|
202
|
-
local player = fakePlayer(111)
|
|
200
|
+
local player = controller.fakePlayer(111)
|
|
203
201
|
player:SetAttribute("ActiveSlotId", "slot-xyz")
|
|
204
202
|
|
|
205
|
-
local data = teleportDataService:BuildTeleportData({ player })
|
|
203
|
+
local data = controller.teleportDataService:BuildTeleportData({ player })
|
|
206
204
|
local slice = TeleportDataEnvelopeUtils.readSlice(data, 111)
|
|
207
205
|
expect(slice and slice[SaveSlotConstants.TELEPORT_DATA_SLOT_KEY]).toEqual("slot-xyz")
|
|
208
206
|
|
|
209
|
-
|
|
210
|
-
serviceBag:Destroy()
|
|
207
|
+
controller:destroy()
|
|
211
208
|
end)
|
|
212
209
|
|
|
213
210
|
it("should not carry a slot id when the single player has no active slot", function()
|
|
214
|
-
local
|
|
215
|
-
serviceBag:Start()
|
|
211
|
+
local controller = setup()
|
|
212
|
+
controller.serviceBag:Start()
|
|
216
213
|
|
|
217
|
-
local player = fakePlayer(111)
|
|
214
|
+
local player = controller.fakePlayer(111)
|
|
218
215
|
|
|
219
|
-
local data = teleportDataService:BuildTeleportData({ player })
|
|
216
|
+
local data = controller.teleportDataService:BuildTeleportData({ player })
|
|
220
217
|
local slice = TeleportDataEnvelopeUtils.readSlice(data, 111)
|
|
221
218
|
expect(slice and slice[SaveSlotConstants.TELEPORT_DATA_SLOT_KEY]).toBeNil()
|
|
222
219
|
|
|
223
|
-
|
|
224
|
-
serviceBag:Destroy()
|
|
220
|
+
controller:destroy()
|
|
225
221
|
end)
|
|
226
222
|
|
|
227
223
|
it("should carry each player's own active slot id for a multi-player teleport", function()
|
|
228
|
-
local
|
|
229
|
-
serviceBag:Start()
|
|
224
|
+
local controller = setup()
|
|
225
|
+
controller.serviceBag:Start()
|
|
230
226
|
|
|
231
|
-
local playerA = fakePlayer(111)
|
|
232
|
-
local playerB = fakePlayer(222)
|
|
227
|
+
local playerA = controller.fakePlayer(111)
|
|
228
|
+
local playerB = controller.fakePlayer(222)
|
|
233
229
|
playerA:SetAttribute("ActiveSlotId", "slot-a")
|
|
234
230
|
playerB:SetAttribute("ActiveSlotId", "slot-b")
|
|
235
231
|
|
|
236
|
-
local data = teleportDataService:BuildTeleportData({ playerA, playerB })
|
|
232
|
+
local data = controller.teleportDataService:BuildTeleportData({ playerA, playerB })
|
|
237
233
|
local sliceA = TeleportDataEnvelopeUtils.readSlice(data, 111)
|
|
238
234
|
local sliceB = TeleportDataEnvelopeUtils.readSlice(data, 222)
|
|
239
235
|
expect(sliceA and sliceA[SaveSlotConstants.TELEPORT_DATA_SLOT_KEY]).toEqual("slot-a")
|
|
240
236
|
expect(sliceB and sliceB[SaveSlotConstants.TELEPORT_DATA_SLOT_KEY]).toEqual("slot-b")
|
|
241
237
|
|
|
242
|
-
|
|
243
|
-
playerB:Destroy()
|
|
244
|
-
serviceBag:Destroy()
|
|
238
|
+
controller:destroy()
|
|
245
239
|
end)
|
|
246
240
|
|
|
247
|
-
-- Awaits a boolean read promise and returns its fulfilled value.
|
|
248
|
-
local function awaitBool(promise: any): boolean
|
|
249
|
-
expect(PromiseTestUtils.awaitSettled(promise, 5)).toEqual(true)
|
|
250
|
-
local ok, value = promise:Yield()
|
|
251
|
-
expect(ok).toEqual(true)
|
|
252
|
-
return value
|
|
253
|
-
end
|
|
254
|
-
|
|
255
241
|
it("should report a client-initiated teleport (non-trusted band) as internal", function()
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
local serviceBag, saveSlotService, teleportDataService = newServiceBag()
|
|
259
|
-
serviceBag:Start()
|
|
242
|
+
local controller = setup()
|
|
243
|
+
controller.serviceBag:Start()
|
|
260
244
|
|
|
261
|
-
local arrived = fakePlayer(111)
|
|
262
|
-
teleportDataService:SetNonTrustedArrivedTeleportDataForTesting(arrived, {
|
|
245
|
+
local arrived = controller.fakePlayer(111)
|
|
246
|
+
controller.teleportDataService:SetNonTrustedArrivedTeleportDataForTesting(arrived, {
|
|
263
247
|
[SaveSlotConstants.TELEPORT_DATA_SLOT_KEY] = "slot-1",
|
|
264
248
|
})
|
|
265
249
|
|
|
266
|
-
expect(awaitBool(saveSlotService:PromiseIsInternalTeleport(arrived))).toEqual(true)
|
|
250
|
+
expect(controller.awaitBool(controller.saveSlotService:PromiseIsInternalTeleport(arrived))).toEqual(true)
|
|
267
251
|
|
|
268
|
-
|
|
269
|
-
serviceBag:Destroy()
|
|
252
|
+
controller:destroy()
|
|
270
253
|
end)
|
|
271
254
|
|
|
272
255
|
it("should report a server-initiated teleport (trusted band) as internal", function()
|
|
273
|
-
local
|
|
274
|
-
serviceBag:Start()
|
|
256
|
+
local controller = setup()
|
|
257
|
+
controller.serviceBag:Start()
|
|
275
258
|
|
|
276
|
-
local arrived = fakePlayer(111)
|
|
277
|
-
teleportDataService:SetTrustedArrivedTeleportDataForTesting(arrived, {
|
|
259
|
+
local arrived = controller.fakePlayer(111)
|
|
260
|
+
controller.teleportDataService:SetTrustedArrivedTeleportDataForTesting(arrived, {
|
|
278
261
|
[SaveSlotConstants.TELEPORT_DATA_SLOT_KEY] = "slot-1",
|
|
279
262
|
})
|
|
280
|
-
teleportDataService:SetNonTrustedArrivedTeleportDataForTesting(arrived, nil) -- no client band; seals
|
|
263
|
+
controller.teleportDataService:SetNonTrustedArrivedTeleportDataForTesting(arrived, nil) -- no client band; seals
|
|
281
264
|
|
|
282
|
-
expect(awaitBool(saveSlotService:PromiseIsInternalTeleport(arrived))).toEqual(true)
|
|
265
|
+
expect(controller.awaitBool(controller.saveSlotService:PromiseIsInternalTeleport(arrived))).toEqual(true)
|
|
283
266
|
|
|
284
|
-
|
|
285
|
-
serviceBag:Destroy()
|
|
267
|
+
controller:destroy()
|
|
286
268
|
end)
|
|
287
269
|
|
|
288
270
|
it("should report a fresh join (no arrived data) as not internal", function()
|
|
289
|
-
local
|
|
290
|
-
serviceBag:Start()
|
|
271
|
+
local controller = setup()
|
|
272
|
+
controller.serviceBag:Start()
|
|
291
273
|
|
|
292
|
-
local fresh = fakePlayer(111)
|
|
293
|
-
teleportDataService:SetNonTrustedArrivedTeleportDataForTesting(fresh, nil) -- fresh-join sentinel; seals
|
|
274
|
+
local fresh = controller.fakePlayer(111)
|
|
275
|
+
controller.teleportDataService:SetNonTrustedArrivedTeleportDataForTesting(fresh, nil) -- fresh-join sentinel; seals
|
|
294
276
|
|
|
295
|
-
expect(awaitBool(saveSlotService:PromiseIsInternalTeleport(fresh))).toEqual(false)
|
|
277
|
+
expect(controller.awaitBool(controller.saveSlotService:PromiseIsInternalTeleport(fresh))).toEqual(false)
|
|
296
278
|
|
|
297
|
-
|
|
298
|
-
serviceBag:Destroy()
|
|
279
|
+
controller:destroy()
|
|
299
280
|
end)
|
|
300
281
|
end)
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
--!strict
|
|
2
2
|
--[[
|
|
3
|
-
Coverage for the "slotIndex"/"slotIndices" Cmdr types, focused on the "." shorthand (Cmdr's
|
|
4
|
-
Default callback) that resolves to the player's current slot -- the active slot, or the last one
|
|
5
|
-
they played. Cmdr itself is stubbed so the type's Default/Transform can be exercised directly.
|
|
6
|
-
|
|
7
3
|
@class SaveSlotCmdrUtils.spec.lua
|
|
8
4
|
]]
|
|
9
5
|
local require = require(script.Parent.loader).load(script)
|
|
@@ -15,10 +11,8 @@ local describe = Jest.Globals.describe
|
|
|
15
11
|
local expect = Jest.Globals.expect
|
|
16
12
|
local it = Jest.Globals.it
|
|
17
13
|
|
|
18
|
-
-- A stand-in player. The fake data service keys off nothing, so any sentinel works.
|
|
19
14
|
local FAKE_PLAYER = newproxy(false)
|
|
20
15
|
|
|
21
|
-
-- Minimal SaveSlotDataService driven by a mutable `state`. Mirrors the real methods the type uses.
|
|
22
16
|
local function newFakeDataService(state)
|
|
23
17
|
return {
|
|
24
18
|
GetSlotList = function(_self, _player)
|
|
@@ -38,9 +32,6 @@ local function newFakeDataService(state)
|
|
|
38
32
|
}
|
|
39
33
|
end
|
|
40
34
|
|
|
41
|
-
-- Enough of Cmdr for registerSlotIndexType: a substring fuzzy finder, a listable wrapper that copies
|
|
42
|
-
-- fields the way the real Util.MakeListableType does (so Default propagation is exercised), and a
|
|
43
|
-
-- registry that captures the registered definitions.
|
|
44
35
|
local function newFakeCmdr()
|
|
45
36
|
local registered: { [string]: any } = {}
|
|
46
37
|
local cmdr = {
|
|
@@ -76,7 +67,6 @@ local function newFakeCmdr()
|
|
|
76
67
|
return cmdr, registered
|
|
77
68
|
end
|
|
78
69
|
|
|
79
|
-
-- Registers the types against a fake data service backed by `state` and returns the registered types.
|
|
80
70
|
local function registerSlotIndex(state)
|
|
81
71
|
local cmdr, registered = newFakeCmdr()
|
|
82
72
|
SaveSlotCmdrUtils.registerSlotIndexType(cmdr :: any, newFakeDataService(state))
|
|
@@ -106,7 +96,6 @@ describe("SaveSlotCmdrUtils.registerSlotIndexType", function()
|
|
|
106
96
|
end)
|
|
107
97
|
|
|
108
98
|
it("returns nil from Default when the remembered slot no longer exists", function()
|
|
109
|
-
-- Last-active points at a deleted slot: GetSlotMetadata finds nothing, so "." resolves to nothing.
|
|
110
99
|
local slotIndex = registerSlotIndex({
|
|
111
100
|
lastActiveSlotId = "id-gone",
|
|
112
101
|
slots = {
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
--!nonstrict
|
|
2
2
|
--[[
|
|
3
|
-
Covers the Summary metadata field, which is JSON-encoded into a single attribute so a structured,
|
|
4
|
-
provider-keyed summary survives the attribute round-trip (attributes cannot hold tables directly).
|
|
5
|
-
|
|
6
3
|
@class SaveSlotData.spec.lua
|
|
7
4
|
]]
|
|
8
5
|
local require = require(script.Parent.loader).load(script)
|
|
@@ -39,8 +36,6 @@ describe("SaveSlotData.Summary", function()
|
|
|
39
36
|
end)
|
|
40
37
|
|
|
41
38
|
it("tolerates a legacy plain-string Summary without erroring", function()
|
|
42
|
-
-- Before the summary was structured it was a single string. A slot saved then still loads: the
|
|
43
|
-
-- value survives (as a string) until the active slot's providers regenerate it as a table.
|
|
44
39
|
local folder = Instance.new("Folder")
|
|
45
40
|
|
|
46
41
|
expect(function()
|