@voidhash/mimic-effect 0.0.9 → 1.0.0-beta.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/.turbo/turbo-build.log +136 -90
- package/README.md +385 -0
- package/dist/ColdStorage.cjs +60 -0
- package/dist/ColdStorage.d.cts +53 -0
- package/dist/ColdStorage.d.cts.map +1 -0
- package/dist/ColdStorage.d.mts +53 -0
- package/dist/ColdStorage.d.mts.map +1 -0
- package/dist/ColdStorage.mjs +60 -0
- package/dist/ColdStorage.mjs.map +1 -0
- package/dist/DocumentManager.cjs +263 -82
- package/dist/DocumentManager.d.cts +44 -22
- package/dist/DocumentManager.d.cts.map +1 -1
- package/dist/DocumentManager.d.mts +44 -22
- package/dist/DocumentManager.d.mts.map +1 -1
- package/dist/DocumentManager.mjs +259 -67
- package/dist/DocumentManager.mjs.map +1 -1
- package/dist/Errors.cjs +54 -0
- package/dist/Errors.d.cts +96 -0
- package/dist/Errors.d.cts.map +1 -0
- package/dist/Errors.d.mts +96 -0
- package/dist/Errors.d.mts.map +1 -0
- package/dist/Errors.mjs +48 -0
- package/dist/Errors.mjs.map +1 -0
- package/dist/HotStorage.cjs +100 -0
- package/dist/HotStorage.d.cts +70 -0
- package/dist/HotStorage.d.cts.map +1 -0
- package/dist/HotStorage.d.mts +70 -0
- package/dist/HotStorage.d.mts.map +1 -0
- package/dist/HotStorage.mjs +100 -0
- package/dist/HotStorage.mjs.map +1 -0
- package/dist/Metrics.cjs +143 -0
- package/dist/Metrics.d.cts +31 -0
- package/dist/Metrics.d.cts.map +1 -0
- package/dist/Metrics.d.mts +31 -0
- package/dist/Metrics.d.mts.map +1 -0
- package/dist/Metrics.mjs +126 -0
- package/dist/Metrics.mjs.map +1 -0
- package/dist/MimicAuthService.cjs +61 -45
- package/dist/MimicAuthService.d.cts +61 -48
- package/dist/MimicAuthService.d.cts.map +1 -1
- package/dist/MimicAuthService.d.mts +61 -48
- package/dist/MimicAuthService.d.mts.map +1 -1
- package/dist/MimicAuthService.mjs +60 -36
- package/dist/MimicAuthService.mjs.map +1 -1
- package/dist/MimicClusterServerEngine.cjs +521 -0
- package/dist/MimicClusterServerEngine.d.cts +17 -0
- package/dist/MimicClusterServerEngine.d.cts.map +1 -0
- package/dist/MimicClusterServerEngine.d.mts +17 -0
- package/dist/MimicClusterServerEngine.d.mts.map +1 -0
- package/dist/MimicClusterServerEngine.mjs +523 -0
- package/dist/MimicClusterServerEngine.mjs.map +1 -0
- package/dist/MimicServer.cjs +205 -96
- package/dist/MimicServer.d.cts +9 -110
- package/dist/MimicServer.d.cts.map +1 -1
- package/dist/MimicServer.d.mts +9 -110
- package/dist/MimicServer.d.mts.map +1 -1
- package/dist/MimicServer.mjs +206 -90
- package/dist/MimicServer.mjs.map +1 -1
- package/dist/MimicServerEngine.cjs +97 -0
- package/dist/MimicServerEngine.d.cts +78 -0
- package/dist/MimicServerEngine.d.cts.map +1 -0
- package/dist/MimicServerEngine.d.mts +78 -0
- package/dist/MimicServerEngine.d.mts.map +1 -0
- package/dist/MimicServerEngine.mjs +97 -0
- package/dist/MimicServerEngine.mjs.map +1 -0
- package/dist/PresenceManager.cjs +75 -91
- package/dist/PresenceManager.d.cts +17 -66
- package/dist/PresenceManager.d.cts.map +1 -1
- package/dist/PresenceManager.d.mts +17 -66
- package/dist/PresenceManager.d.mts.map +1 -1
- package/dist/PresenceManager.mjs +74 -78
- package/dist/PresenceManager.mjs.map +1 -1
- package/dist/Protocol.cjs +146 -0
- package/dist/Protocol.d.cts +203 -0
- package/dist/Protocol.d.cts.map +1 -0
- package/dist/Protocol.d.mts +203 -0
- package/dist/Protocol.d.mts.map +1 -0
- package/dist/Protocol.mjs +132 -0
- package/dist/Protocol.mjs.map +1 -0
- package/dist/Types.d.cts +172 -0
- package/dist/Types.d.cts.map +1 -0
- package/dist/Types.d.mts +172 -0
- package/dist/Types.d.mts.map +1 -0
- package/dist/_virtual/rolldown_runtime.cjs +1 -25
- package/dist/_virtual/rolldown_runtime.mjs +4 -1
- package/dist/index.cjs +37 -75
- package/dist/index.d.cts +13 -12
- package/dist/index.d.mts +13 -12
- package/dist/index.mjs +12 -12
- package/dist/testing/ColdStorageTestSuite.cjs +508 -0
- package/dist/testing/ColdStorageTestSuite.d.cts +36 -0
- package/dist/testing/ColdStorageTestSuite.d.cts.map +1 -0
- package/dist/testing/ColdStorageTestSuite.d.mts +36 -0
- package/dist/testing/ColdStorageTestSuite.d.mts.map +1 -0
- package/dist/testing/ColdStorageTestSuite.mjs +508 -0
- package/dist/testing/ColdStorageTestSuite.mjs.map +1 -0
- package/dist/testing/FailingStorage.cjs +135 -0
- package/dist/testing/FailingStorage.d.cts +43 -0
- package/dist/testing/FailingStorage.d.cts.map +1 -0
- package/dist/testing/FailingStorage.d.mts +43 -0
- package/dist/testing/FailingStorage.d.mts.map +1 -0
- package/dist/testing/FailingStorage.mjs +136 -0
- package/dist/testing/FailingStorage.mjs.map +1 -0
- package/dist/testing/HotStorageTestSuite.cjs +585 -0
- package/dist/testing/HotStorageTestSuite.d.cts +40 -0
- package/dist/testing/HotStorageTestSuite.d.cts.map +1 -0
- package/dist/testing/HotStorageTestSuite.d.mts +40 -0
- package/dist/testing/HotStorageTestSuite.d.mts.map +1 -0
- package/dist/testing/HotStorageTestSuite.mjs +585 -0
- package/dist/testing/HotStorageTestSuite.mjs.map +1 -0
- package/dist/testing/StorageIntegrationTestSuite.cjs +349 -0
- package/dist/testing/StorageIntegrationTestSuite.d.cts +35 -0
- package/dist/testing/StorageIntegrationTestSuite.d.cts.map +1 -0
- package/dist/testing/StorageIntegrationTestSuite.d.mts +35 -0
- package/dist/testing/StorageIntegrationTestSuite.d.mts.map +1 -0
- package/dist/testing/StorageIntegrationTestSuite.mjs +349 -0
- package/dist/testing/StorageIntegrationTestSuite.mjs.map +1 -0
- package/dist/testing/assertions.cjs +114 -0
- package/dist/testing/assertions.mjs +109 -0
- package/dist/testing/assertions.mjs.map +1 -0
- package/dist/testing/index.cjs +14 -0
- package/dist/testing/index.d.cts +6 -0
- package/dist/testing/index.d.mts +6 -0
- package/dist/testing/index.mjs +7 -0
- package/dist/testing/types.cjs +15 -0
- package/dist/testing/types.d.cts +90 -0
- package/dist/testing/types.d.cts.map +1 -0
- package/dist/testing/types.d.mts +90 -0
- package/dist/testing/types.d.mts.map +1 -0
- package/dist/testing/types.mjs +16 -0
- package/dist/testing/types.mjs.map +1 -0
- package/package.json +18 -3
- package/src/ColdStorage.ts +136 -0
- package/src/DocumentManager.ts +550 -190
- package/src/Errors.ts +114 -0
- package/src/HotStorage.ts +239 -0
- package/src/Metrics.ts +187 -0
- package/src/MimicAuthService.ts +126 -64
- package/src/MimicClusterServerEngine.ts +946 -0
- package/src/MimicServer.ts +448 -195
- package/src/MimicServerEngine.ts +276 -0
- package/src/PresenceManager.ts +169 -240
- package/src/Protocol.ts +350 -0
- package/src/Types.ts +231 -0
- package/src/index.ts +57 -23
- package/src/testing/ColdStorageTestSuite.ts +589 -0
- package/src/testing/FailingStorage.ts +286 -0
- package/src/testing/HotStorageTestSuite.ts +762 -0
- package/src/testing/StorageIntegrationTestSuite.ts +504 -0
- package/src/testing/assertions.ts +181 -0
- package/src/testing/index.ts +83 -0
- package/src/testing/types.ts +100 -0
- package/tests/ColdStorage.test.ts +24 -0
- package/tests/DocumentManager.test.ts +158 -287
- package/tests/HotStorage.test.ts +24 -0
- package/tests/MimicAuthService.test.ts +102 -134
- package/tests/MimicClusterServerEngine.test.ts +587 -0
- package/tests/MimicServer.test.ts +90 -226
- package/tests/MimicServerEngine.test.ts +521 -0
- package/tests/PresenceManager.test.ts +22 -63
- package/tests/Protocol.test.ts +190 -0
- package/tests/StorageIntegration.test.ts +259 -0
- package/tsconfig.json +1 -1
- package/tsdown.config.ts +1 -1
- package/dist/DocumentProtocol.cjs +0 -94
- package/dist/DocumentProtocol.d.cts +0 -113
- package/dist/DocumentProtocol.d.cts.map +0 -1
- package/dist/DocumentProtocol.d.mts +0 -113
- package/dist/DocumentProtocol.d.mts.map +0 -1
- package/dist/DocumentProtocol.mjs +0 -89
- package/dist/DocumentProtocol.mjs.map +0 -1
- package/dist/MimicConfig.cjs +0 -60
- package/dist/MimicConfig.d.cts +0 -141
- package/dist/MimicConfig.d.cts.map +0 -1
- package/dist/MimicConfig.d.mts +0 -141
- package/dist/MimicConfig.d.mts.map +0 -1
- package/dist/MimicConfig.mjs +0 -50
- package/dist/MimicConfig.mjs.map +0 -1
- package/dist/MimicDataStorage.cjs +0 -83
- package/dist/MimicDataStorage.d.cts +0 -113
- package/dist/MimicDataStorage.d.cts.map +0 -1
- package/dist/MimicDataStorage.d.mts +0 -113
- package/dist/MimicDataStorage.d.mts.map +0 -1
- package/dist/MimicDataStorage.mjs +0 -74
- package/dist/MimicDataStorage.mjs.map +0 -1
- package/dist/WebSocketHandler.cjs +0 -365
- package/dist/WebSocketHandler.d.cts +0 -34
- package/dist/WebSocketHandler.d.cts.map +0 -1
- package/dist/WebSocketHandler.d.mts +0 -34
- package/dist/WebSocketHandler.d.mts.map +0 -1
- package/dist/WebSocketHandler.mjs +0 -355
- package/dist/WebSocketHandler.mjs.map +0 -1
- package/dist/auth/NoAuth.cjs +0 -43
- package/dist/auth/NoAuth.d.cts +0 -22
- package/dist/auth/NoAuth.d.cts.map +0 -1
- package/dist/auth/NoAuth.d.mts +0 -22
- package/dist/auth/NoAuth.d.mts.map +0 -1
- package/dist/auth/NoAuth.mjs +0 -36
- package/dist/auth/NoAuth.mjs.map +0 -1
- package/dist/errors.cjs +0 -74
- package/dist/errors.d.cts +0 -89
- package/dist/errors.d.cts.map +0 -1
- package/dist/errors.d.mts +0 -89
- package/dist/errors.d.mts.map +0 -1
- package/dist/errors.mjs +0 -67
- package/dist/errors.mjs.map +0 -1
- package/dist/storage/InMemoryDataStorage.cjs +0 -57
- package/dist/storage/InMemoryDataStorage.d.cts +0 -19
- package/dist/storage/InMemoryDataStorage.d.cts.map +0 -1
- package/dist/storage/InMemoryDataStorage.d.mts +0 -19
- package/dist/storage/InMemoryDataStorage.d.mts.map +0 -1
- package/dist/storage/InMemoryDataStorage.mjs +0 -48
- package/dist/storage/InMemoryDataStorage.mjs.map +0 -1
- package/src/DocumentProtocol.ts +0 -112
- package/src/MimicConfig.ts +0 -211
- package/src/MimicDataStorage.ts +0 -157
- package/src/WebSocketHandler.ts +0 -735
- package/src/auth/NoAuth.ts +0 -46
- package/src/errors.ts +0 -113
- package/src/storage/InMemoryDataStorage.ts +0 -66
- package/tests/DocumentProtocol.test.ts +0 -113
- package/tests/InMemoryDataStorage.test.ts +0 -190
- package/tests/MimicConfig.test.ts +0 -290
- package/tests/MimicDataStorage.test.ts +0 -190
- package/tests/NoAuth.test.ts +0 -94
- package/tests/WebSocketHandler.test.ts +0 -321
- package/tests/errors.test.ts +0 -77
|
@@ -0,0 +1,762 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @voidhash/mimic-effect/testing - HotStorage Test Suite
|
|
3
|
+
*
|
|
4
|
+
* Comprehensive test suite for HotStorage (WAL) adapter implementations.
|
|
5
|
+
* These tests verify that an adapter correctly implements the HotStorage interface
|
|
6
|
+
* and can reliably store/retrieve WAL entries for document recovery.
|
|
7
|
+
*/
|
|
8
|
+
import { Effect } from "effect";
|
|
9
|
+
import { Transaction } from "@voidhash/mimic";
|
|
10
|
+
import { HotStorageTag } from "../HotStorage";
|
|
11
|
+
import { type HotStorageError, WalVersionGapError } from "../Errors";
|
|
12
|
+
import type { WalEntry } from "../Types";
|
|
13
|
+
import type { StorageTestCase, TestResults } from "./types";
|
|
14
|
+
import { TestError } from "./types";
|
|
15
|
+
import {
|
|
16
|
+
assertEqual,
|
|
17
|
+
assertLength,
|
|
18
|
+
assertEmpty,
|
|
19
|
+
assertSortedBy,
|
|
20
|
+
assertTrue,
|
|
21
|
+
} from "./assertions";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Error type for HotStorage tests - can be either a TestError, HotStorageError, or WalVersionGapError
|
|
25
|
+
*/
|
|
26
|
+
export type HotStorageTestError = TestError | HotStorageError | WalVersionGapError;
|
|
27
|
+
|
|
28
|
+
// =============================================================================
|
|
29
|
+
// Categories
|
|
30
|
+
// =============================================================================
|
|
31
|
+
|
|
32
|
+
export const Categories = {
|
|
33
|
+
BasicOperations: "Basic Operations",
|
|
34
|
+
VersionFiltering: "Version Filtering",
|
|
35
|
+
OrderingGuarantees: "Ordering Guarantees",
|
|
36
|
+
TruncationEdgeCases: "Truncation Edge Cases",
|
|
37
|
+
WalEntryIntegrity: "WAL Entry Integrity",
|
|
38
|
+
DocumentIsolation: "Document Isolation",
|
|
39
|
+
LargeScaleOperations: "Large-Scale Operations",
|
|
40
|
+
DocumentIdEdgeCases: "Document ID Edge Cases",
|
|
41
|
+
GapChecking: "Gap Checking",
|
|
42
|
+
} as const;
|
|
43
|
+
|
|
44
|
+
// =============================================================================
|
|
45
|
+
// Helper Functions
|
|
46
|
+
// =============================================================================
|
|
47
|
+
|
|
48
|
+
const makeEntry = (version: number, timestamp?: number): WalEntry => ({
|
|
49
|
+
transaction: Transaction.make([]),
|
|
50
|
+
version,
|
|
51
|
+
timestamp: timestamp ?? Date.now(),
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const makeEntryWithData = (
|
|
55
|
+
version: number,
|
|
56
|
+
data: unknown,
|
|
57
|
+
timestamp?: number
|
|
58
|
+
): WalEntry => ({
|
|
59
|
+
transaction: Transaction.make([
|
|
60
|
+
{ type: "set", path: ["data"], value: data },
|
|
61
|
+
]),
|
|
62
|
+
version,
|
|
63
|
+
timestamp: timestamp ?? Date.now(),
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// =============================================================================
|
|
67
|
+
// Test Definitions
|
|
68
|
+
// =============================================================================
|
|
69
|
+
|
|
70
|
+
const tests: StorageTestCase<HotStorageTestError, HotStorageTag>[] = [
|
|
71
|
+
// ---------------------------------------------------------------------------
|
|
72
|
+
// Basic Operations
|
|
73
|
+
// ---------------------------------------------------------------------------
|
|
74
|
+
{
|
|
75
|
+
name: "getEntries returns empty array for non-existent document",
|
|
76
|
+
category: Categories.BasicOperations,
|
|
77
|
+
run: Effect.gen(function* () {
|
|
78
|
+
const storage = yield* HotStorageTag;
|
|
79
|
+
const result = yield* storage.getEntries("non-existent-hot-doc", 0);
|
|
80
|
+
yield* assertEmpty(result, "Should return empty array for non-existent document");
|
|
81
|
+
}),
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
{
|
|
85
|
+
name: "append then getEntries returns the entry",
|
|
86
|
+
category: Categories.BasicOperations,
|
|
87
|
+
run: Effect.gen(function* () {
|
|
88
|
+
const storage = yield* HotStorageTag;
|
|
89
|
+
const entry = makeEntry(1);
|
|
90
|
+
yield* storage.append("basic-append", entry);
|
|
91
|
+
const entries = yield* storage.getEntries("basic-append", 0);
|
|
92
|
+
yield* assertLength(entries, 1, "Should have one entry");
|
|
93
|
+
yield* assertEqual(entries[0]!.version, 1, "Entry version should match");
|
|
94
|
+
}),
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
{
|
|
98
|
+
name: "multiple append calls accumulate entries",
|
|
99
|
+
category: Categories.BasicOperations,
|
|
100
|
+
run: Effect.gen(function* () {
|
|
101
|
+
const storage = yield* HotStorageTag;
|
|
102
|
+
yield* storage.append("multi-append", makeEntry(1));
|
|
103
|
+
yield* storage.append("multi-append", makeEntry(2));
|
|
104
|
+
yield* storage.append("multi-append", makeEntry(3));
|
|
105
|
+
const entries = yield* storage.getEntries("multi-append", 0);
|
|
106
|
+
yield* assertLength(entries, 3, "Should have three entries");
|
|
107
|
+
}),
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
{
|
|
111
|
+
name: "truncate removes entries with version <= upToVersion",
|
|
112
|
+
category: Categories.BasicOperations,
|
|
113
|
+
run: Effect.gen(function* () {
|
|
114
|
+
const storage = yield* HotStorageTag;
|
|
115
|
+
yield* storage.append("truncate-basic", makeEntry(1));
|
|
116
|
+
yield* storage.append("truncate-basic", makeEntry(2));
|
|
117
|
+
yield* storage.append("truncate-basic", makeEntry(3));
|
|
118
|
+
yield* storage.truncate("truncate-basic", 2);
|
|
119
|
+
const entries = yield* storage.getEntries("truncate-basic", 0);
|
|
120
|
+
yield* assertLength(entries, 1, "Should have one entry after truncate");
|
|
121
|
+
yield* assertEqual(entries[0]!.version, 3, "Only version 3 should remain");
|
|
122
|
+
}),
|
|
123
|
+
},
|
|
124
|
+
|
|
125
|
+
{
|
|
126
|
+
name: "truncate on non-existent document does not error",
|
|
127
|
+
category: Categories.BasicOperations,
|
|
128
|
+
run: Effect.gen(function* () {
|
|
129
|
+
const storage = yield* HotStorageTag;
|
|
130
|
+
yield* storage.truncate("non-existent-truncate", 100);
|
|
131
|
+
}),
|
|
132
|
+
},
|
|
133
|
+
|
|
134
|
+
// ---------------------------------------------------------------------------
|
|
135
|
+
// Version Filtering (Critical for Recovery)
|
|
136
|
+
// ---------------------------------------------------------------------------
|
|
137
|
+
{
|
|
138
|
+
name: "getEntries(doc, 0) returns all entries",
|
|
139
|
+
category: Categories.VersionFiltering,
|
|
140
|
+
run: Effect.gen(function* () {
|
|
141
|
+
const storage = yield* HotStorageTag;
|
|
142
|
+
yield* storage.append("filter-all", makeEntry(1));
|
|
143
|
+
yield* storage.append("filter-all", makeEntry(2));
|
|
144
|
+
yield* storage.append("filter-all", makeEntry(3));
|
|
145
|
+
const entries = yield* storage.getEntries("filter-all", 0);
|
|
146
|
+
yield* assertLength(entries, 3, "sinceVersion=0 should return all entries");
|
|
147
|
+
}),
|
|
148
|
+
},
|
|
149
|
+
|
|
150
|
+
{
|
|
151
|
+
name: "getEntries(doc, n) returns only entries with version > n",
|
|
152
|
+
category: Categories.VersionFiltering,
|
|
153
|
+
run: Effect.gen(function* () {
|
|
154
|
+
const storage = yield* HotStorageTag;
|
|
155
|
+
yield* storage.append("filter-n", makeEntry(1));
|
|
156
|
+
yield* storage.append("filter-n", makeEntry(2));
|
|
157
|
+
yield* storage.append("filter-n", makeEntry(3));
|
|
158
|
+
yield* storage.append("filter-n", makeEntry(4));
|
|
159
|
+
const entries = yield* storage.getEntries("filter-n", 2);
|
|
160
|
+
yield* assertLength(entries, 2, "Should return entries with version > 2");
|
|
161
|
+
yield* assertEqual(entries[0]!.version, 3, "First entry should be version 3");
|
|
162
|
+
yield* assertEqual(entries[1]!.version, 4, "Second entry should be version 4");
|
|
163
|
+
}),
|
|
164
|
+
},
|
|
165
|
+
|
|
166
|
+
{
|
|
167
|
+
name: "getEntries(doc, exactVersion) excludes that exact version",
|
|
168
|
+
category: Categories.VersionFiltering,
|
|
169
|
+
run: Effect.gen(function* () {
|
|
170
|
+
const storage = yield* HotStorageTag;
|
|
171
|
+
yield* storage.append("filter-exact", makeEntry(5));
|
|
172
|
+
yield* storage.append("filter-exact", makeEntry(6));
|
|
173
|
+
yield* storage.append("filter-exact", makeEntry(7));
|
|
174
|
+
const entries = yield* storage.getEntries("filter-exact", 6);
|
|
175
|
+
yield* assertLength(entries, 1, "Should exclude version 6");
|
|
176
|
+
yield* assertEqual(entries[0]!.version, 7, "Only version 7 should be returned");
|
|
177
|
+
}),
|
|
178
|
+
},
|
|
179
|
+
|
|
180
|
+
{
|
|
181
|
+
name: "getEntries(doc, maxVersion) returns empty array",
|
|
182
|
+
category: Categories.VersionFiltering,
|
|
183
|
+
run: Effect.gen(function* () {
|
|
184
|
+
const storage = yield* HotStorageTag;
|
|
185
|
+
yield* storage.append("filter-max", makeEntry(1));
|
|
186
|
+
yield* storage.append("filter-max", makeEntry(2));
|
|
187
|
+
yield* storage.append("filter-max", makeEntry(3));
|
|
188
|
+
const entries = yield* storage.getEntries("filter-max", 3);
|
|
189
|
+
yield* assertEmpty(entries, "sinceVersion >= maxVersion should return empty");
|
|
190
|
+
}),
|
|
191
|
+
},
|
|
192
|
+
|
|
193
|
+
{
|
|
194
|
+
name: "getEntries(doc, MAX_SAFE_INTEGER) returns empty array",
|
|
195
|
+
category: Categories.VersionFiltering,
|
|
196
|
+
run: Effect.gen(function* () {
|
|
197
|
+
const storage = yield* HotStorageTag;
|
|
198
|
+
yield* storage.append("filter-huge", makeEntry(1));
|
|
199
|
+
yield* storage.append("filter-huge", makeEntry(1000000));
|
|
200
|
+
const entries = yield* storage.getEntries("filter-huge", Number.MAX_SAFE_INTEGER);
|
|
201
|
+
yield* assertEmpty(entries, "sinceVersion=MAX_SAFE_INTEGER should return empty");
|
|
202
|
+
}),
|
|
203
|
+
},
|
|
204
|
+
|
|
205
|
+
// ---------------------------------------------------------------------------
|
|
206
|
+
// Ordering Guarantees
|
|
207
|
+
// ---------------------------------------------------------------------------
|
|
208
|
+
{
|
|
209
|
+
name: "entries returned sorted by version ascending",
|
|
210
|
+
category: Categories.OrderingGuarantees,
|
|
211
|
+
run: Effect.gen(function* () {
|
|
212
|
+
const storage = yield* HotStorageTag;
|
|
213
|
+
yield* storage.append("order-test", makeEntry(1));
|
|
214
|
+
yield* storage.append("order-test", makeEntry(2));
|
|
215
|
+
yield* storage.append("order-test", makeEntry(3));
|
|
216
|
+
const entries = yield* storage.getEntries("order-test", 0);
|
|
217
|
+
yield* assertSortedBy(entries, "version", "Entries should be sorted by version");
|
|
218
|
+
}),
|
|
219
|
+
},
|
|
220
|
+
|
|
221
|
+
{
|
|
222
|
+
name: "out-of-order appends are sorted correctly on retrieval",
|
|
223
|
+
category: Categories.OrderingGuarantees,
|
|
224
|
+
run: Effect.gen(function* () {
|
|
225
|
+
const storage = yield* HotStorageTag;
|
|
226
|
+
yield* storage.append("ooo-test", makeEntry(3));
|
|
227
|
+
yield* storage.append("ooo-test", makeEntry(1));
|
|
228
|
+
yield* storage.append("ooo-test", makeEntry(4));
|
|
229
|
+
yield* storage.append("ooo-test", makeEntry(2));
|
|
230
|
+
const entries = yield* storage.getEntries("ooo-test", 0);
|
|
231
|
+
yield* assertLength(entries, 4, "Should have all 4 entries");
|
|
232
|
+
yield* assertEqual(entries[0]!.version, 1, "First should be version 1");
|
|
233
|
+
yield* assertEqual(entries[1]!.version, 2, "Second should be version 2");
|
|
234
|
+
yield* assertEqual(entries[2]!.version, 3, "Third should be version 3");
|
|
235
|
+
yield* assertEqual(entries[3]!.version, 4, "Fourth should be version 4");
|
|
236
|
+
}),
|
|
237
|
+
},
|
|
238
|
+
|
|
239
|
+
// ---------------------------------------------------------------------------
|
|
240
|
+
// Truncation Edge Cases
|
|
241
|
+
// ---------------------------------------------------------------------------
|
|
242
|
+
{
|
|
243
|
+
name: "truncate(doc, 0) removes nothing (versions > 0 kept)",
|
|
244
|
+
category: Categories.TruncationEdgeCases,
|
|
245
|
+
run: Effect.gen(function* () {
|
|
246
|
+
const storage = yield* HotStorageTag;
|
|
247
|
+
yield* storage.append("trunc-0", makeEntry(1));
|
|
248
|
+
yield* storage.append("trunc-0", makeEntry(2));
|
|
249
|
+
yield* storage.truncate("trunc-0", 0);
|
|
250
|
+
const entries = yield* storage.getEntries("trunc-0", 0);
|
|
251
|
+
yield* assertLength(entries, 2, "truncate(0) should keep all entries with version > 0");
|
|
252
|
+
}),
|
|
253
|
+
},
|
|
254
|
+
|
|
255
|
+
{
|
|
256
|
+
name: "truncate(doc, maxVersion) removes all entries",
|
|
257
|
+
category: Categories.TruncationEdgeCases,
|
|
258
|
+
run: Effect.gen(function* () {
|
|
259
|
+
const storage = yield* HotStorageTag;
|
|
260
|
+
yield* storage.append("trunc-all", makeEntry(1));
|
|
261
|
+
yield* storage.append("trunc-all", makeEntry(2));
|
|
262
|
+
yield* storage.append("trunc-all", makeEntry(3));
|
|
263
|
+
yield* storage.truncate("trunc-all", 3);
|
|
264
|
+
const entries = yield* storage.getEntries("trunc-all", 0);
|
|
265
|
+
yield* assertEmpty(entries, "truncate(maxVersion) should remove all entries");
|
|
266
|
+
}),
|
|
267
|
+
},
|
|
268
|
+
|
|
269
|
+
{
|
|
270
|
+
name: "truncate(doc, middleVersion) removes correct entries",
|
|
271
|
+
category: Categories.TruncationEdgeCases,
|
|
272
|
+
run: Effect.gen(function* () {
|
|
273
|
+
const storage = yield* HotStorageTag;
|
|
274
|
+
yield* storage.append("trunc-mid", makeEntry(1));
|
|
275
|
+
yield* storage.append("trunc-mid", makeEntry(2));
|
|
276
|
+
yield* storage.append("trunc-mid", makeEntry(3));
|
|
277
|
+
yield* storage.append("trunc-mid", makeEntry(4));
|
|
278
|
+
yield* storage.append("trunc-mid", makeEntry(5));
|
|
279
|
+
yield* storage.truncate("trunc-mid", 3);
|
|
280
|
+
const entries = yield* storage.getEntries("trunc-mid", 0);
|
|
281
|
+
yield* assertLength(entries, 2, "Should keep versions 4 and 5");
|
|
282
|
+
yield* assertEqual(entries[0]!.version, 4, "First remaining should be 4");
|
|
283
|
+
yield* assertEqual(entries[1]!.version, 5, "Second remaining should be 5");
|
|
284
|
+
}),
|
|
285
|
+
},
|
|
286
|
+
|
|
287
|
+
{
|
|
288
|
+
name: "multiple truncates work correctly",
|
|
289
|
+
category: Categories.TruncationEdgeCases,
|
|
290
|
+
run: Effect.gen(function* () {
|
|
291
|
+
const storage = yield* HotStorageTag;
|
|
292
|
+
yield* storage.append("multi-trunc", makeEntry(1));
|
|
293
|
+
yield* storage.append("multi-trunc", makeEntry(2));
|
|
294
|
+
yield* storage.append("multi-trunc", makeEntry(3));
|
|
295
|
+
yield* storage.append("multi-trunc", makeEntry(4));
|
|
296
|
+
yield* storage.append("multi-trunc", makeEntry(5));
|
|
297
|
+
yield* storage.truncate("multi-trunc", 2);
|
|
298
|
+
yield* storage.truncate("multi-trunc", 4);
|
|
299
|
+
const entries = yield* storage.getEntries("multi-trunc", 0);
|
|
300
|
+
yield* assertLength(entries, 1, "Should only have version 5");
|
|
301
|
+
yield* assertEqual(entries[0]!.version, 5, "Only version 5 should remain");
|
|
302
|
+
}),
|
|
303
|
+
},
|
|
304
|
+
|
|
305
|
+
{
|
|
306
|
+
name: "truncate followed by append works correctly",
|
|
307
|
+
category: Categories.TruncationEdgeCases,
|
|
308
|
+
run: Effect.gen(function* () {
|
|
309
|
+
const storage = yield* HotStorageTag;
|
|
310
|
+
yield* storage.append("trunc-append", makeEntry(1));
|
|
311
|
+
yield* storage.append("trunc-append", makeEntry(2));
|
|
312
|
+
yield* storage.truncate("trunc-append", 2);
|
|
313
|
+
yield* storage.append("trunc-append", makeEntry(3));
|
|
314
|
+
yield* storage.append("trunc-append", makeEntry(4));
|
|
315
|
+
const entries = yield* storage.getEntries("trunc-append", 0);
|
|
316
|
+
yield* assertLength(entries, 2, "Should have versions 3 and 4");
|
|
317
|
+
yield* assertEqual(entries[0]!.version, 3, "First should be 3");
|
|
318
|
+
yield* assertEqual(entries[1]!.version, 4, "Second should be 4");
|
|
319
|
+
}),
|
|
320
|
+
},
|
|
321
|
+
|
|
322
|
+
// ---------------------------------------------------------------------------
|
|
323
|
+
// WAL Entry Data Integrity
|
|
324
|
+
// ---------------------------------------------------------------------------
|
|
325
|
+
{
|
|
326
|
+
name: "transaction data is preserved exactly",
|
|
327
|
+
category: Categories.WalEntryIntegrity,
|
|
328
|
+
run: Effect.gen(function* () {
|
|
329
|
+
const storage = yield* HotStorageTag;
|
|
330
|
+
const entry = makeEntryWithData(1, { key: "value", nested: { a: 1 } });
|
|
331
|
+
yield* storage.append("tx-data", entry);
|
|
332
|
+
const entries = yield* storage.getEntries("tx-data", 0);
|
|
333
|
+
yield* assertLength(entries, 1, "Should have one entry");
|
|
334
|
+
yield* assertEqual(
|
|
335
|
+
entries[0]!.transaction,
|
|
336
|
+
entry.transaction,
|
|
337
|
+
"Transaction should be preserved exactly"
|
|
338
|
+
);
|
|
339
|
+
}),
|
|
340
|
+
},
|
|
341
|
+
|
|
342
|
+
{
|
|
343
|
+
name: "version number is preserved exactly",
|
|
344
|
+
category: Categories.WalEntryIntegrity,
|
|
345
|
+
run: Effect.gen(function* () {
|
|
346
|
+
const storage = yield* HotStorageTag;
|
|
347
|
+
const version = 42;
|
|
348
|
+
const entry = makeEntry(version);
|
|
349
|
+
yield* storage.append("version-preserve", entry);
|
|
350
|
+
const entries = yield* storage.getEntries("version-preserve", 0);
|
|
351
|
+
yield* assertEqual(entries[0]!.version, version, "Version should be preserved exactly");
|
|
352
|
+
}),
|
|
353
|
+
},
|
|
354
|
+
|
|
355
|
+
{
|
|
356
|
+
name: "timestamp is preserved exactly",
|
|
357
|
+
category: Categories.WalEntryIntegrity,
|
|
358
|
+
run: Effect.gen(function* () {
|
|
359
|
+
const storage = yield* HotStorageTag;
|
|
360
|
+
const timestamp = 1704067200000;
|
|
361
|
+
const entry = makeEntry(1, timestamp);
|
|
362
|
+
yield* storage.append("timestamp-preserve", entry);
|
|
363
|
+
const entries = yield* storage.getEntries("timestamp-preserve", 0);
|
|
364
|
+
yield* assertEqual(
|
|
365
|
+
entries[0]!.timestamp,
|
|
366
|
+
timestamp,
|
|
367
|
+
"Timestamp should be preserved exactly"
|
|
368
|
+
);
|
|
369
|
+
}),
|
|
370
|
+
},
|
|
371
|
+
|
|
372
|
+
{
|
|
373
|
+
name: "complex transaction operations survive roundtrip",
|
|
374
|
+
category: Categories.WalEntryIntegrity,
|
|
375
|
+
run: Effect.gen(function* () {
|
|
376
|
+
const storage = yield* HotStorageTag;
|
|
377
|
+
const entry: WalEntry = {
|
|
378
|
+
transaction: Transaction.make([
|
|
379
|
+
{ type: "set", path: ["a"], value: 1 },
|
|
380
|
+
{ type: "set", path: ["b", "c"], value: "nested" },
|
|
381
|
+
{ type: "set", path: ["arr"], value: [1, 2, 3] },
|
|
382
|
+
]),
|
|
383
|
+
version: 1,
|
|
384
|
+
timestamp: Date.now(),
|
|
385
|
+
};
|
|
386
|
+
yield* storage.append("complex-tx", entry);
|
|
387
|
+
const entries = yield* storage.getEntries("complex-tx", 0);
|
|
388
|
+
yield* assertEqual(
|
|
389
|
+
entries[0]!.transaction,
|
|
390
|
+
entry.transaction,
|
|
391
|
+
"Complex transaction should survive roundtrip"
|
|
392
|
+
);
|
|
393
|
+
}),
|
|
394
|
+
},
|
|
395
|
+
|
|
396
|
+
// ---------------------------------------------------------------------------
|
|
397
|
+
// Document Isolation
|
|
398
|
+
// ---------------------------------------------------------------------------
|
|
399
|
+
{
|
|
400
|
+
name: "different documents have independent entry lists",
|
|
401
|
+
category: Categories.DocumentIsolation,
|
|
402
|
+
run: Effect.gen(function* () {
|
|
403
|
+
const storage = yield* HotStorageTag;
|
|
404
|
+
yield* storage.append("iso-hot-1", makeEntry(1));
|
|
405
|
+
yield* storage.append("iso-hot-1", makeEntry(2));
|
|
406
|
+
yield* storage.append("iso-hot-2", makeEntry(10));
|
|
407
|
+
const entries1 = yield* storage.getEntries("iso-hot-1", 0);
|
|
408
|
+
const entries2 = yield* storage.getEntries("iso-hot-2", 0);
|
|
409
|
+
yield* assertLength(entries1, 2, "Doc 1 should have 2 entries");
|
|
410
|
+
yield* assertLength(entries2, 1, "Doc 2 should have 1 entry");
|
|
411
|
+
yield* assertEqual(entries1[0]!.version, 1, "Doc 1 first entry version");
|
|
412
|
+
yield* assertEqual(entries2[0]!.version, 10, "Doc 2 first entry version");
|
|
413
|
+
}),
|
|
414
|
+
},
|
|
415
|
+
|
|
416
|
+
{
|
|
417
|
+
name: "appending to one doc does not affect others",
|
|
418
|
+
category: Categories.DocumentIsolation,
|
|
419
|
+
run: Effect.gen(function* () {
|
|
420
|
+
const storage = yield* HotStorageTag;
|
|
421
|
+
yield* storage.append("append-iso-1", makeEntry(1));
|
|
422
|
+
const beforeAppend = yield* storage.getEntries("append-iso-1", 0);
|
|
423
|
+
yield* storage.append("append-iso-2", makeEntry(100));
|
|
424
|
+
yield* storage.append("append-iso-2", makeEntry(101));
|
|
425
|
+
const afterAppend = yield* storage.getEntries("append-iso-1", 0);
|
|
426
|
+
yield* assertEqual(
|
|
427
|
+
beforeAppend.length,
|
|
428
|
+
afterAppend.length,
|
|
429
|
+
"Appending to doc 2 should not affect doc 1"
|
|
430
|
+
);
|
|
431
|
+
}),
|
|
432
|
+
},
|
|
433
|
+
|
|
434
|
+
{
|
|
435
|
+
name: "truncating one doc does not affect others",
|
|
436
|
+
category: Categories.DocumentIsolation,
|
|
437
|
+
run: Effect.gen(function* () {
|
|
438
|
+
const storage = yield* HotStorageTag;
|
|
439
|
+
yield* storage.append("trunc-iso-1", makeEntry(1));
|
|
440
|
+
yield* storage.append("trunc-iso-1", makeEntry(2));
|
|
441
|
+
yield* storage.append("trunc-iso-2", makeEntry(1));
|
|
442
|
+
yield* storage.append("trunc-iso-2", makeEntry(2));
|
|
443
|
+
yield* storage.truncate("trunc-iso-1", 2);
|
|
444
|
+
const entries1 = yield* storage.getEntries("trunc-iso-1", 0);
|
|
445
|
+
const entries2 = yield* storage.getEntries("trunc-iso-2", 0);
|
|
446
|
+
yield* assertEmpty(entries1, "Doc 1 should be empty after truncate");
|
|
447
|
+
yield* assertLength(entries2, 2, "Doc 2 should still have 2 entries");
|
|
448
|
+
}),
|
|
449
|
+
},
|
|
450
|
+
|
|
451
|
+
// ---------------------------------------------------------------------------
|
|
452
|
+
// Large-Scale Operations
|
|
453
|
+
// ---------------------------------------------------------------------------
|
|
454
|
+
{
|
|
455
|
+
name: "handle 1000+ entries per document",
|
|
456
|
+
category: Categories.LargeScaleOperations,
|
|
457
|
+
run: Effect.gen(function* () {
|
|
458
|
+
const storage = yield* HotStorageTag;
|
|
459
|
+
const count = 1000;
|
|
460
|
+
for (let i = 1; i <= count; i++) {
|
|
461
|
+
yield* storage.append("large-entries", makeEntry(i));
|
|
462
|
+
}
|
|
463
|
+
const entries = yield* storage.getEntries("large-entries", 0);
|
|
464
|
+
yield* assertLength(entries, count, `Should have ${count} entries`);
|
|
465
|
+
yield* assertSortedBy(entries, "version", "Should be sorted by version");
|
|
466
|
+
yield* assertEqual(entries[0]!.version, 1, "First should be version 1");
|
|
467
|
+
yield* assertEqual(entries[count - 1]!.version, count, `Last should be version ${count}`);
|
|
468
|
+
}),
|
|
469
|
+
},
|
|
470
|
+
|
|
471
|
+
{
|
|
472
|
+
name: "handle 100+ documents",
|
|
473
|
+
category: Categories.LargeScaleOperations,
|
|
474
|
+
run: Effect.gen(function* () {
|
|
475
|
+
const storage = yield* HotStorageTag;
|
|
476
|
+
const docCount = 100;
|
|
477
|
+
for (let i = 0; i < docCount; i++) {
|
|
478
|
+
yield* storage.append(`multi-doc-${i}`, makeEntry(1));
|
|
479
|
+
yield* storage.append(`multi-doc-${i}`, makeEntry(2));
|
|
480
|
+
}
|
|
481
|
+
let totalEntries = 0;
|
|
482
|
+
for (let i = 0; i < docCount; i++) {
|
|
483
|
+
const entries = yield* storage.getEntries(`multi-doc-${i}`, 0);
|
|
484
|
+
totalEntries += entries.length;
|
|
485
|
+
yield* assertLength(entries, 2, `Doc ${i} should have 2 entries`);
|
|
486
|
+
}
|
|
487
|
+
yield* assertEqual(totalEntries, docCount * 2, "Total entries should match");
|
|
488
|
+
}),
|
|
489
|
+
},
|
|
490
|
+
|
|
491
|
+
{
|
|
492
|
+
name: "large transaction data (10KB+) survives roundtrip",
|
|
493
|
+
category: Categories.LargeScaleOperations,
|
|
494
|
+
run: Effect.gen(function* () {
|
|
495
|
+
const storage = yield* HotStorageTag;
|
|
496
|
+
const largeData = "x".repeat(10 * 1024);
|
|
497
|
+
const entry = makeEntryWithData(1, { content: largeData });
|
|
498
|
+
yield* storage.append("large-tx", entry);
|
|
499
|
+
const entries = yield* storage.getEntries("large-tx", 0);
|
|
500
|
+
yield* assertLength(entries, 1, "Should have one entry");
|
|
501
|
+
yield* assertEqual(
|
|
502
|
+
entries[0]!.transaction,
|
|
503
|
+
entry.transaction,
|
|
504
|
+
"Large transaction data should survive roundtrip"
|
|
505
|
+
);
|
|
506
|
+
}),
|
|
507
|
+
},
|
|
508
|
+
|
|
509
|
+
// ---------------------------------------------------------------------------
|
|
510
|
+
// Document ID Edge Cases
|
|
511
|
+
// ---------------------------------------------------------------------------
|
|
512
|
+
{
|
|
513
|
+
name: "long documentId (1000+ chars) works",
|
|
514
|
+
category: Categories.DocumentIdEdgeCases,
|
|
515
|
+
run: Effect.gen(function* () {
|
|
516
|
+
const storage = yield* HotStorageTag;
|
|
517
|
+
const longId = "h".repeat(1000);
|
|
518
|
+
const entry = makeEntry(1);
|
|
519
|
+
yield* storage.append(longId, entry);
|
|
520
|
+
const entries = yield* storage.getEntries(longId, 0);
|
|
521
|
+
yield* assertLength(entries, 1, "Long documentId should work");
|
|
522
|
+
}),
|
|
523
|
+
},
|
|
524
|
+
|
|
525
|
+
{
|
|
526
|
+
name: "unicode documentId works",
|
|
527
|
+
category: Categories.DocumentIdEdgeCases,
|
|
528
|
+
run: Effect.gen(function* () {
|
|
529
|
+
const storage = yield* HotStorageTag;
|
|
530
|
+
const unicodeId = "hot-doc-id";
|
|
531
|
+
const entry = makeEntry(1);
|
|
532
|
+
yield* storage.append(unicodeId, entry);
|
|
533
|
+
const entries = yield* storage.getEntries(unicodeId, 0);
|
|
534
|
+
yield* assertLength(entries, 1, "Unicode documentId should work");
|
|
535
|
+
}),
|
|
536
|
+
},
|
|
537
|
+
|
|
538
|
+
{
|
|
539
|
+
name: "documentId with special chars works",
|
|
540
|
+
category: Categories.DocumentIdEdgeCases,
|
|
541
|
+
run: Effect.gen(function* () {
|
|
542
|
+
const storage = yield* HotStorageTag;
|
|
543
|
+
const specialId = "hot/path:to.wal";
|
|
544
|
+
const entry = makeEntry(1);
|
|
545
|
+
yield* storage.append(specialId, entry);
|
|
546
|
+
const entries = yield* storage.getEntries(specialId, 0);
|
|
547
|
+
yield* assertLength(entries, 1, "DocumentId with special chars should work");
|
|
548
|
+
}),
|
|
549
|
+
},
|
|
550
|
+
|
|
551
|
+
{
|
|
552
|
+
name: "documentId with spaces works",
|
|
553
|
+
category: Categories.DocumentIdEdgeCases,
|
|
554
|
+
run: Effect.gen(function* () {
|
|
555
|
+
const storage = yield* HotStorageTag;
|
|
556
|
+
const spacedId = "hot doc with spaces";
|
|
557
|
+
const entry = makeEntry(1);
|
|
558
|
+
yield* storage.append(spacedId, entry);
|
|
559
|
+
const entries = yield* storage.getEntries(spacedId, 0);
|
|
560
|
+
yield* assertLength(entries, 1, "DocumentId with spaces should work");
|
|
561
|
+
}),
|
|
562
|
+
},
|
|
563
|
+
|
|
564
|
+
{
|
|
565
|
+
name: "version 0 entry is handled correctly",
|
|
566
|
+
category: Categories.VersionFiltering,
|
|
567
|
+
run: Effect.gen(function* () {
|
|
568
|
+
const storage = yield* HotStorageTag;
|
|
569
|
+
yield* storage.append("version-0-entry", makeEntry(0));
|
|
570
|
+
yield* storage.append("version-0-entry", makeEntry(1));
|
|
571
|
+
const entriesFromNeg = yield* storage.getEntries("version-0-entry", -1);
|
|
572
|
+
yield* assertTrue(
|
|
573
|
+
entriesFromNeg.some((e) => e.version === 0),
|
|
574
|
+
"Version 0 entry should be retrievable with sinceVersion < 0"
|
|
575
|
+
);
|
|
576
|
+
const entriesFrom0 = yield* storage.getEntries("version-0-entry", 0);
|
|
577
|
+
yield* assertTrue(
|
|
578
|
+
!entriesFrom0.some((e) => e.version === 0),
|
|
579
|
+
"Version 0 entry should be excluded with sinceVersion = 0"
|
|
580
|
+
);
|
|
581
|
+
}),
|
|
582
|
+
},
|
|
583
|
+
|
|
584
|
+
// ---------------------------------------------------------------------------
|
|
585
|
+
// Gap Checking (appendWithCheck)
|
|
586
|
+
// ---------------------------------------------------------------------------
|
|
587
|
+
{
|
|
588
|
+
name: "appendWithCheck succeeds for first entry (expectedVersion=1)",
|
|
589
|
+
category: Categories.GapChecking,
|
|
590
|
+
run: Effect.gen(function* () {
|
|
591
|
+
const storage = yield* HotStorageTag;
|
|
592
|
+
const entry = makeEntry(1);
|
|
593
|
+
yield* storage.appendWithCheck("gap-check-first", entry, 1);
|
|
594
|
+
const entries = yield* storage.getEntries("gap-check-first", 0);
|
|
595
|
+
yield* assertLength(entries, 1, "Should have one entry");
|
|
596
|
+
yield* assertEqual(entries[0]!.version, 1, "Entry version should be 1");
|
|
597
|
+
}),
|
|
598
|
+
},
|
|
599
|
+
|
|
600
|
+
{
|
|
601
|
+
name: "appendWithCheck succeeds for consecutive versions",
|
|
602
|
+
category: Categories.GapChecking,
|
|
603
|
+
run: Effect.gen(function* () {
|
|
604
|
+
const storage = yield* HotStorageTag;
|
|
605
|
+
yield* storage.appendWithCheck("gap-check-consecutive", makeEntry(1), 1);
|
|
606
|
+
yield* storage.appendWithCheck("gap-check-consecutive", makeEntry(2), 2);
|
|
607
|
+
yield* storage.appendWithCheck("gap-check-consecutive", makeEntry(3), 3);
|
|
608
|
+
const entries = yield* storage.getEntries("gap-check-consecutive", 0);
|
|
609
|
+
yield* assertLength(entries, 3, "Should have three entries");
|
|
610
|
+
yield* assertEqual(entries[0]!.version, 1, "First entry version should be 1");
|
|
611
|
+
yield* assertEqual(entries[1]!.version, 2, "Second entry version should be 2");
|
|
612
|
+
yield* assertEqual(entries[2]!.version, 3, "Third entry version should be 3");
|
|
613
|
+
}),
|
|
614
|
+
},
|
|
615
|
+
|
|
616
|
+
{
|
|
617
|
+
name: "appendWithCheck fails for version gap (skipping version 2)",
|
|
618
|
+
category: Categories.GapChecking,
|
|
619
|
+
run: Effect.gen(function* () {
|
|
620
|
+
const storage = yield* HotStorageTag;
|
|
621
|
+
yield* storage.appendWithCheck("gap-check-fail", makeEntry(1), 1);
|
|
622
|
+
// Attempt to append version 3, skipping version 2
|
|
623
|
+
const result = yield* Effect.either(
|
|
624
|
+
storage.appendWithCheck("gap-check-fail", makeEntry(3), 3)
|
|
625
|
+
);
|
|
626
|
+
yield* assertTrue(
|
|
627
|
+
result._tag === "Left",
|
|
628
|
+
"appendWithCheck should fail when there's a version gap"
|
|
629
|
+
);
|
|
630
|
+
if (result._tag === "Left") {
|
|
631
|
+
yield* assertTrue(
|
|
632
|
+
result.left._tag === "WalVersionGapError",
|
|
633
|
+
"Error should be WalVersionGapError"
|
|
634
|
+
);
|
|
635
|
+
}
|
|
636
|
+
// Verify version 3 was not appended
|
|
637
|
+
const entries = yield* storage.getEntries("gap-check-fail", 0);
|
|
638
|
+
yield* assertLength(entries, 1, "Should only have version 1");
|
|
639
|
+
yield* assertEqual(entries[0]!.version, 1, "Only version 1 should exist");
|
|
640
|
+
}),
|
|
641
|
+
},
|
|
642
|
+
|
|
643
|
+
{
|
|
644
|
+
name: "appendWithCheck fails if first entry is not version 1",
|
|
645
|
+
category: Categories.GapChecking,
|
|
646
|
+
run: Effect.gen(function* () {
|
|
647
|
+
const storage = yield* HotStorageTag;
|
|
648
|
+
// Attempt to append version 2 as first entry (expecting gap error)
|
|
649
|
+
const result = yield* Effect.either(
|
|
650
|
+
storage.appendWithCheck("gap-check-not-first", makeEntry(2), 2)
|
|
651
|
+
);
|
|
652
|
+
yield* assertTrue(
|
|
653
|
+
result._tag === "Left",
|
|
654
|
+
"appendWithCheck should fail when first entry is not version 1"
|
|
655
|
+
);
|
|
656
|
+
if (result._tag === "Left") {
|
|
657
|
+
yield* assertTrue(
|
|
658
|
+
result.left._tag === "WalVersionGapError",
|
|
659
|
+
"Error should be WalVersionGapError"
|
|
660
|
+
);
|
|
661
|
+
}
|
|
662
|
+
// Verify nothing was appended
|
|
663
|
+
const entries = yield* storage.getEntries("gap-check-not-first", 0);
|
|
664
|
+
yield* assertEmpty(entries, "No entries should exist after failed append");
|
|
665
|
+
}),
|
|
666
|
+
},
|
|
667
|
+
|
|
668
|
+
{
|
|
669
|
+
name: "appendWithCheck fails when entry already exists at expectedVersion",
|
|
670
|
+
category: Categories.GapChecking,
|
|
671
|
+
run: Effect.gen(function* () {
|
|
672
|
+
const storage = yield* HotStorageTag;
|
|
673
|
+
yield* storage.appendWithCheck("gap-check-duplicate", makeEntry(1), 1);
|
|
674
|
+
// Attempt to append another version 1
|
|
675
|
+
const result = yield* Effect.either(
|
|
676
|
+
storage.appendWithCheck("gap-check-duplicate", makeEntry(1), 1)
|
|
677
|
+
);
|
|
678
|
+
yield* assertTrue(
|
|
679
|
+
result._tag === "Left",
|
|
680
|
+
"appendWithCheck should fail when version already exists"
|
|
681
|
+
);
|
|
682
|
+
// Verify still only one entry
|
|
683
|
+
const entries = yield* storage.getEntries("gap-check-duplicate", 0);
|
|
684
|
+
yield* assertLength(entries, 1, "Should still only have one entry");
|
|
685
|
+
}),
|
|
686
|
+
},
|
|
687
|
+
|
|
688
|
+
{
|
|
689
|
+
name: "appendWithCheck after truncate works correctly",
|
|
690
|
+
category: Categories.GapChecking,
|
|
691
|
+
run: Effect.gen(function* () {
|
|
692
|
+
const storage = yield* HotStorageTag;
|
|
693
|
+
// Append versions 1, 2, 3
|
|
694
|
+
yield* storage.appendWithCheck("gap-check-truncate", makeEntry(1), 1);
|
|
695
|
+
yield* storage.appendWithCheck("gap-check-truncate", makeEntry(2), 2);
|
|
696
|
+
yield* storage.appendWithCheck("gap-check-truncate", makeEntry(3), 3);
|
|
697
|
+
// Truncate up to version 2
|
|
698
|
+
yield* storage.truncate("gap-check-truncate", 2);
|
|
699
|
+
// Now append version 4 (should succeed since last entry is version 3)
|
|
700
|
+
yield* storage.appendWithCheck("gap-check-truncate", makeEntry(4), 4);
|
|
701
|
+
const entries = yield* storage.getEntries("gap-check-truncate", 0);
|
|
702
|
+
yield* assertLength(entries, 2, "Should have versions 3 and 4");
|
|
703
|
+
yield* assertEqual(entries[0]!.version, 3, "First should be version 3");
|
|
704
|
+
yield* assertEqual(entries[1]!.version, 4, "Second should be version 4");
|
|
705
|
+
}),
|
|
706
|
+
},
|
|
707
|
+
];
|
|
708
|
+
|
|
709
|
+
// =============================================================================
|
|
710
|
+
// Exports
|
|
711
|
+
// =============================================================================
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* Get all HotStorage test cases.
|
|
715
|
+
*
|
|
716
|
+
* @returns Array of test cases that require HotStorageTag
|
|
717
|
+
*/
|
|
718
|
+
export const makeTests = (): StorageTestCase<
|
|
719
|
+
HotStorageTestError,
|
|
720
|
+
HotStorageTag
|
|
721
|
+
>[] => tests;
|
|
722
|
+
|
|
723
|
+
/**
|
|
724
|
+
* Run all tests and collect results.
|
|
725
|
+
*
|
|
726
|
+
* @returns Effect that produces TestResults
|
|
727
|
+
*/
|
|
728
|
+
export const runAll = (): Effect.Effect<
|
|
729
|
+
TestResults<HotStorageTestError, HotStorageTag>,
|
|
730
|
+
never,
|
|
731
|
+
HotStorageTag
|
|
732
|
+
> =>
|
|
733
|
+
Effect.gen(function* () {
|
|
734
|
+
const passed: StorageTestCase<HotStorageTestError, HotStorageTag>[] = [];
|
|
735
|
+
const failed: Array<{
|
|
736
|
+
test: StorageTestCase<HotStorageTestError, HotStorageTag>;
|
|
737
|
+
error: HotStorageTestError;
|
|
738
|
+
}> = [];
|
|
739
|
+
|
|
740
|
+
for (const test of tests) {
|
|
741
|
+
const result = yield* Effect.either(test.run);
|
|
742
|
+
if (result._tag === "Right") {
|
|
743
|
+
passed.push(test);
|
|
744
|
+
} else {
|
|
745
|
+
failed.push({ test, error: result.left });
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
return {
|
|
750
|
+
passed,
|
|
751
|
+
failed,
|
|
752
|
+
total: tests.length,
|
|
753
|
+
passCount: passed.length,
|
|
754
|
+
failCount: failed.length,
|
|
755
|
+
};
|
|
756
|
+
});
|
|
757
|
+
|
|
758
|
+
export const HotStorageTestSuite = {
|
|
759
|
+
Categories,
|
|
760
|
+
makeTests,
|
|
761
|
+
runAll,
|
|
762
|
+
};
|