@ibgib/core-gib 0.1.13 → 0.1.14

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.
Files changed (100) hide show
  1. package/dist/keystone/keystone-helpers.mjs +3 -3
  2. package/dist/keystone/keystone-helpers.mjs.map +1 -1
  3. package/dist/sync/sync-constants.d.mts +4 -1
  4. package/dist/sync/sync-constants.d.mts.map +1 -1
  5. package/dist/sync/sync-constants.mjs +3 -0
  6. package/dist/sync/sync-constants.mjs.map +1 -1
  7. package/dist/sync/sync-helpers.d.mts +18 -2
  8. package/dist/sync/sync-helpers.d.mts.map +1 -1
  9. package/dist/sync/sync-helpers.mjs +84 -3
  10. package/dist/sync/sync-helpers.mjs.map +1 -1
  11. package/dist/sync/sync-innerspace.respec.d.mts +0 -6
  12. package/dist/sync/sync-innerspace.respec.d.mts.map +1 -1
  13. package/dist/sync/sync-innerspace.respec.mjs +395 -404
  14. package/dist/sync/sync-innerspace.respec.mjs.map +1 -1
  15. package/dist/sync/sync-peer/sync-peer-types.d.mts +31 -0
  16. package/dist/sync/sync-peer/sync-peer-types.d.mts.map +1 -0
  17. package/dist/sync/sync-peer/sync-peer-types.mjs +5 -0
  18. package/dist/sync/sync-peer/sync-peer-types.mjs.map +1 -0
  19. package/dist/sync/sync-peer/sync-peer-v1.d.mts +22 -0
  20. package/dist/sync/sync-peer/sync-peer-v1.d.mts.map +1 -0
  21. package/dist/sync/sync-peer/sync-peer-v1.mjs +13 -0
  22. package/dist/sync/sync-peer/sync-peer-v1.mjs.map +1 -0
  23. package/dist/sync/sync-saga-context/sync-saga-context-constants.d.mts +8 -0
  24. package/dist/sync/sync-saga-context/sync-saga-context-constants.d.mts.map +1 -0
  25. package/dist/sync/sync-saga-context/sync-saga-context-constants.mjs +8 -0
  26. package/dist/sync/sync-saga-context/sync-saga-context-constants.mjs.map +1 -0
  27. package/dist/sync/sync-saga-context/sync-saga-context-helpers.d.mts +54 -0
  28. package/dist/sync/sync-saga-context/sync-saga-context-helpers.d.mts.map +1 -0
  29. package/dist/sync/sync-saga-context/sync-saga-context-helpers.mjs +87 -0
  30. package/dist/sync/sync-saga-context/sync-saga-context-helpers.mjs.map +1 -0
  31. package/dist/sync/sync-saga-context/sync-saga-context-types.d.mts +66 -0
  32. package/dist/sync/sync-saga-context/sync-saga-context-types.d.mts.map +1 -0
  33. package/dist/sync/sync-saga-context/sync-saga-context-types.mjs +12 -0
  34. package/dist/sync/sync-saga-context/sync-saga-context-types.mjs.map +1 -0
  35. package/dist/sync/sync-saga-coordinator.d.mts +115 -125
  36. package/dist/sync/sync-saga-coordinator.d.mts.map +1 -1
  37. package/dist/sync/sync-saga-coordinator.mjs +539 -456
  38. package/dist/sync/sync-saga-coordinator.mjs.map +1 -1
  39. package/dist/sync/sync-saga-coordinator.respec.mjs +7 -7
  40. package/dist/sync/sync-saga-coordinator.respec.mjs.map +1 -1
  41. package/dist/sync/sync-saga-message/sync-saga-message-constants.d.mts +2 -0
  42. package/dist/sync/sync-saga-message/sync-saga-message-constants.d.mts.map +1 -0
  43. package/dist/sync/sync-saga-message/sync-saga-message-constants.mjs +2 -0
  44. package/dist/sync/sync-saga-message/sync-saga-message-constants.mjs.map +1 -0
  45. package/dist/sync/sync-saga-message/sync-saga-message-helpers.d.mts +15 -0
  46. package/dist/sync/sync-saga-message/sync-saga-message-helpers.d.mts.map +1 -0
  47. package/dist/sync/sync-saga-message/sync-saga-message-helpers.mjs +43 -0
  48. package/dist/sync/sync-saga-message/sync-saga-message-helpers.mjs.map +1 -0
  49. package/dist/sync/sync-saga-message/sync-saga-message-types.d.mts +39 -0
  50. package/dist/sync/sync-saga-message/sync-saga-message-types.d.mts.map +1 -0
  51. package/dist/sync/sync-saga-message/sync-saga-message-types.mjs +2 -0
  52. package/dist/sync/sync-saga-message/sync-saga-message-types.mjs.map +1 -0
  53. package/dist/sync/sync-types.d.mts +81 -3
  54. package/dist/sync/sync-types.d.mts.map +1 -1
  55. package/dist/sync/sync-types.mjs +27 -1
  56. package/dist/sync/sync-types.mjs.map +1 -1
  57. package/dist/timeline/timeline-api.d.mts +16 -3
  58. package/dist/timeline/timeline-api.d.mts.map +1 -1
  59. package/dist/timeline/timeline-api.mjs +7 -7
  60. package/dist/timeline/timeline-api.mjs.map +1 -1
  61. package/dist/witness/space/outer-space/outer-space-types.d.mts +2 -0
  62. package/dist/witness/space/outer-space/outer-space-types.d.mts.map +1 -1
  63. package/dist/witness/space/space-base-v1.d.mts +19 -1
  64. package/dist/witness/space/space-base-v1.d.mts.map +1 -1
  65. package/dist/witness/space/space-base-v1.mjs +66 -6
  66. package/dist/witness/space/space-base-v1.mjs.map +1 -1
  67. package/dist/witness/space/space-helper.d.mts +14 -0
  68. package/dist/witness/space/space-helper.d.mts.map +1 -1
  69. package/dist/witness/space/space-helper.mjs +44 -1
  70. package/dist/witness/space/space-helper.mjs.map +1 -1
  71. package/dist/witness/space/space-respec-helper.d.mts.map +1 -1
  72. package/dist/witness/space/space-respec-helper.mjs +1 -1
  73. package/dist/witness/space/space-respec-helper.mjs.map +1 -1
  74. package/dist/witness/space/space-types.d.mts +12 -1
  75. package/dist/witness/space/space-types.d.mts.map +1 -1
  76. package/dist/witness/space/space-types.mjs +4 -0
  77. package/dist/witness/space/space-types.mjs.map +1 -1
  78. package/package.json +2 -2
  79. package/src/keystone/keystone-helpers.mts +3 -3
  80. package/src/sync/README.md +275 -0
  81. package/src/sync/sync-constants.mts +5 -0
  82. package/src/sync/sync-helpers.mts +105 -6
  83. package/src/sync/sync-innerspace.respec.mts +458 -457
  84. package/src/sync/sync-peer/sync-peer-types.mts +43 -0
  85. package/src/sync/sync-peer/sync-peer-v1.mts +28 -0
  86. package/src/sync/sync-saga-context/sync-saga-context-constants.mts +8 -0
  87. package/src/sync/sync-saga-context/sync-saga-context-helpers.mts +147 -0
  88. package/src/sync/sync-saga-context/sync-saga-context-types.mts +80 -0
  89. package/src/sync/sync-saga-coordinator.mts +709 -526
  90. package/src/sync/sync-saga-coordinator.respec.mts +7 -7
  91. package/src/sync/sync-saga-message/sync-saga-message-constants.mts +1 -0
  92. package/src/sync/sync-saga-message/sync-saga-message-helpers.mts +59 -0
  93. package/src/sync/sync-saga-message/sync-saga-message-types.mts +53 -0
  94. package/src/sync/sync-types.mts +103 -3
  95. package/src/timeline/timeline-api.mts +20 -4
  96. package/src/witness/space/space-base-v1.mts +62 -12
  97. package/src/witness/space/space-helper.mts +50 -1
  98. package/src/witness/space/space-respec-helper.mts +2 -1
  99. package/src/witness/space/space-types.mts +13 -1
  100. package/tmp.md +3 -9
@@ -1,405 +1,396 @@
1
- /**
2
- * @module sync-innerspace.respec
3
- *
4
- * Verifies SyncSagaCoordinator using InnerSpace (in-memory/local) spaces.
5
- * This avoids disk I/O issues and focuses on the synchronization logic.
6
- */
7
- import { respecfully, iReckon, ifWeMight } from '@ibgib/helper-gib/dist/respec-gib/respec-gib.mjs';
8
- const maam = `[${import.meta.url}]`, sir = maam;
9
- import { pretty } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
10
- import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs';
11
- import { SyncSagaCoordinator } from './sync-saga-coordinator.mjs';
12
- import { putInSpace, getFromSpace } from '../witness/space/space-helper.mjs';
13
- import { Metaspace_Innerspace } from '../witness/space/metaspace/metaspace-innerspace/metaspace-innerspace.mjs';
14
- import { InnerSpace_V1 } from '../witness/space/inner-space/inner-space-v1.mjs';
15
- import { createTimelineRootHelper, getTestKeystoneServiceHelper } from '../agent-helpers.mjs';
16
- import { mut8Timeline } from '../timeline/timeline-api.mjs';
17
- import { getDependencyGraph } from '../common/other/graph-helper.mjs';
18
- import { getTjpAddr } from '../common/other/ibgib-helper.mjs';
19
- const logalot = true;
20
- const lc = `[sync-innerspace.respec]`;
21
- /**
22
- * naive helper function to determine if two dependency graphs are equal.
23
- *
24
- * naive: only checks length of keys and if keys all match.
25
- *
26
- * @param a dependency graph from one space
27
- * @param b dep. graph from another space
28
- * @returns true if graphs are equal in size and keys, else false.
29
- */
30
- function naiveGraphsAreEqual(a, b) {
31
- const keysA = Object.keys(a);
32
- const keysB = Object.keys(b);
33
- if (keysA.length !== keysB.length) {
34
- false;
35
- }
36
- return keysA.every(key => !!b[key]);
37
- }
38
- await respecfully(sir, `Sync InnerSpaces`, async () => {
39
- let metaspace;
40
- let sourceSpace;
41
- let destSpace;
42
- // Setup before each test? Or once?
43
- // For now, let's just do it inside the test block to be safe/simple.
44
- // await ifWeMight(sir, `Basic Push Sync (Source -> Dest)`, async () => {
45
- // // 1. Setup Spaces
46
- // metaspace = new Metaspace_Innerspace(undefined);
47
- // await metaspace.initialize({
48
- // getFnAlert: () => async ({ title, msg }) => { console.log(`[Alert] ${title}: ${msg}`); },
49
- // getFnPrompt: () => async ({ title, msg }) => { console.log(`[Prompt] ${title}: ${msg}`); return ''; },
50
- // getFnPromptPassword: () => async (title, msg) => { console.log(`[PromptPwd] ${title}: ${msg}`); return null; },
51
- // });
52
- // // Create two distinct inner spaces manually or via metaspace if supported
53
- // // Metaspace_Innerspace typically manages one local user space, but we can instantiate InnerSpace_V1 directly.
54
- // sourceSpace = new InnerSpace_V1({ name: 'source', uuid: 'source_uuid' } as any);
55
- // await (sourceSpace as any).initialize();
56
- // destSpace = new InnerSpace_V1({ name: 'dest', uuid: 'dest_uuid' } as any);
57
- // await (destSpace as any).initialize();
58
- // // 2. Seed Source Data
59
- // // 2.1 Create a "Stone"
60
- // console.log(`${lc} Creating Stone...`);
61
- // const stone = await createStoneHelper({
62
- // ib: 'stone_data',
63
- // data: { some: 'data' },
64
- // });
65
- // const stoneAddr = getIbGibAddr({ ibGib: stone });
66
- // await putInSpace({ space: sourceSpace, ibGibs: [stone] });
67
- // // 2.2 Create a "Living" Timeline (Root)
68
- // console.log(`${lc} Creating Timeline Root...`);
69
- // const root = await createTimelineRootHelper({
70
- // ib: 'timeline_root',
71
- // data: { type: 'root', n: 0 },
72
- // space: sourceSpace,
73
- // });
74
- // const rootAddr = getIbGibAddr({ ibGib: root });
75
- // // 2.3 Evolve Timeline (Root -> Child)
76
- // // using mut8Timeline to simulate evolution
77
- // console.log(`${lc} Evolving Timeline...`);
78
- // const child = await mut8Timeline({
79
- // timeline: root,
80
- // mut8Opts: {
81
- // dataToAddOrPatch: { type: 'child', n: 1 }
82
- // },
83
- // metaspace,
84
- // space: sourceSpace,
85
- // // We use skipLock=true for simplicity in single-threaded test setup if locking is complex,
86
- // // but timeline-api handles locking. Let's try default first.
87
- // // Actually InnerSpace locking might be no-op or simple.
88
- // });
89
- // const childAddr = getIbGibAddr({ ibGib: child });
90
- // // 2.4 Rel8 Child to Stone (Dependency)
91
- // console.log(`${lc} Linking Child to Stone...`);
92
- // const childWithRel = await appendToTimeline({
93
- // timeline: child,
94
- // rel8nInfos: [{
95
- // rel8nName: 'linked_stone',
96
- // ibGibs: [stone]
97
- // }],
98
- // metaspace,
99
- // space: sourceSpace,
100
- // });
101
- // const childWithRelAddr = getIbGibAddr({ ibGib: childWithRel });
102
- // // 3. Setup Sync Coordinator
103
- // console.log(`${lc} Setting up Coordinator...`);
104
- // const mockKeystone = await getTestKeystoneServiceHelper();
105
- // const identity = await (mockKeystone as any).getIdentity();
106
- // const coordinator = new SyncSagaCoordinator(mockKeystone);
107
- // // 4. Run Sync
108
- // console.log(`${lc} Running Sync...`);
109
- // const syncRes = await coordinator.sync({
110
- // source: sourceSpace,
111
- // dest: destSpace,
112
- // domainIbGibs: [childWithRel], // Sync starting from the tip
113
- // identity
114
- // });
115
- // // 5. Verify Dest (Full Dependency Graph)
116
- // console.log(`${lc} Verifying Destination (Full Graph)...`);
117
- // // We expect the graph to contain:
118
- // // 1. childWithRel
119
- // // 2. child (past of childWithRel)
120
- // // 3. root (ancestor of child, past of child)
121
- // // 4. stone (linked to childWithRel)
122
- // // 5. primitives (timeline_root, child, stone_data, identity, fork, mut8, rel8, root^gib, etc.)
123
- // // Let's get the graph from the source first to know what to expect (ground truth)
124
- // const sourceGraph = await getDependencyGraph({
125
- // ibGibs: [childWithRel],
126
- // space: sourceSpace,
127
- // });
128
- // const sourceAddrs = Object.keys(sourceGraph);
129
- // console.log(`${lc} Source Graph Size: ${sourceAddrs.length}`);
130
- // // Now get the graph from the destination
131
- // const destGraph = await getDependencyGraph({
132
- // ibGibs: [childWithRel],
133
- // space: destSpace,
134
- // });
135
- // const destAddrs = Object.keys(destGraph);
136
- // console.log(`${lc} Dest Graph Size: ${destAddrs.length}`);
137
- // // Assert
138
- // iReckon(sir, destAddrs.length).asTo('dest graph size').isGonnaBe(sourceAddrs.length);
139
- // for (const addr of sourceAddrs) {
140
- // const inDest = !!destGraph[addr];
141
- // if (!inDest) {
142
- // console.error(`${lc} Missing in dest: ${addr}`);
143
- // }
144
- // iReckon(sir, inDest).asTo(`addr present in dest: ${addr}`).isGonnaBeTrue();
145
- // }
146
- // console.log(`${lc} Verified Full Dependency Graph synced.`);
147
- // });
148
- // await ifWeMight(sir, `Idempotency (No-op if already synced)`, async () => {
149
- // // 1. Setup Spaces
150
- // const metaspace = new Metaspace_Innerspace(undefined);
151
- // await metaspace.initialize({
152
- // getFnAlert: () => async ({ title, msg }) => { console.log(`[Alert] ${title}: ${msg}`); },
153
- // getFnPrompt: () => async ({ title, msg }) => { console.log(`[Prompt] ${title}: ${msg}`); return ''; },
154
- // getFnPromptPassword: () => async (title, msg) => { console.log(`[PromptPwd] ${title}: ${msg}`); return null; },
155
- // });
156
- // const sourceSpace = new InnerSpace_V1({ name: 'source_idem', uuid: 'source_idem_uuid' } as any);
157
- // await (sourceSpace as any).initialize();
158
- // const destSpace = new InnerSpace_V1({ name: 'dest_idem', uuid: 'dest_idem_uuid' } as any);
159
- // await (destSpace as any).initialize();
160
- // // 2. Seed Source and Sync ONCE
161
- // const root = await createTimelineRootHelper({
162
- // ib: 'timeline_root',
163
- // data: { type: 'root', n: 0 },
164
- // space: sourceSpace,
165
- // });
166
- // const mockKeystone = await getTestKeystoneServiceHelper();
167
- // const identity = await (mockKeystone as any).getIdentity();
168
- // const coordinator = new SyncSagaCoordinator(mockKeystone);
169
- // console.log(`${lc} Running First Sync...`);
170
- // await coordinator.sync({
171
- // source: sourceSpace,
172
- // dest: destSpace,
173
- // domainIbGibs: [root],
174
- // identity
175
- // });
176
- // // Verify Initial State
177
- // const rootAddr = getIbGibAddr({ ibGib: root });
178
- // const getRoot1 = await getFromSpace({ space: destSpace, addr: rootAddr });
179
- // iReckon(sir, getRoot1.success).asTo('First Sync success').isGonnaBeTrue();
180
- // // 3. Run Sync AGAIN (Should be No-op)
181
- // console.log(`${lc} Running Second Sync...`);
182
- // await coordinator.sync({
183
- // source: sourceSpace,
184
- // dest: destSpace,
185
- // domainIbGibs: [root],
186
- // identity
187
- // });
188
- // // 4. Verify State Unchanged / Still Valid
189
- // const getRoot2 = await getFromSpace({ space: destSpace, addr: rootAddr });
190
- // iReckon(sir, getRoot2.success).asTo('Second Sync success').isGonnaBeTrue();
191
- // // Ensure no duplication or errors in destination (checking count in dependency graph might be good proxy?)
192
- // const destGraph = await getDependencyGraph({
193
- // ibGibs: [root],
194
- // space: destSpace,
195
- // });
196
- // iReckon(sir, Object.keys(destGraph).length).asTo('Dest Graph Size unchanged').isGonnaBe(Object.keys(destGraph).length); // Trivial assertion, mostly checking for no throw
197
- // console.log(`${lc} Verified Idempotency.`);
198
- // });
199
- await ifWeMight(sir, `Dest Ahead (Pull/Fast-Backward)`, async () => {
200
- // 1. Setup Spaces
201
- // Metaspace_Innerspace automatically initializes spaces so we don't need manual initialize calls for these if they were standard.
202
- // But here we are instantiating them directly.
203
- // User pointed out initialize is called in constructor.
204
- const metaspace = new Metaspace_Innerspace(undefined);
205
- await metaspace.initialize({
206
- getFnAlert: () => async ({ title, msg }) => { console.log(`[Alert] ${title}: ${msg}`); },
207
- getFnPrompt: () => async ({ title, msg }) => { console.log(`[Prompt] ${title}: ${msg}`); return ''; },
208
- getFnPromptPassword: () => async (title, msg) => { console.log(`[PromptPwd] ${title}: ${msg}`); return null; },
209
- });
210
- // const sourceSpace = new InnerSpace_V1({ name: 'source_pull', uuid: 'source_pull_uuid' } as any);
211
- const sourceSpace = new InnerSpace_V1({ name: 'source_pull', });
212
- // await (sourceSpace as any).initialize(); // Already initialized in ctor
213
- // const destSpace = new InnerSpace_V1({ name: 'dest_pull', uuid: 'dest_pull_uuid' } as any);
214
- const destSpace = new InnerSpace_V1({ name: 'dest_pull', });
215
- // await (destSpace as any).initialize(); // Already initialized in ctor
216
- // 2. Setup Initial Shared State
217
- // Create root in Source, Sync to Dest
218
- console.log(`${lc} Seeding initial shared state...`);
219
- const root = await createTimelineRootHelper({
220
- ib: 'timeline_pull',
221
- data: { type: 'root', state: 'initial' },
222
- space: sourceSpace,
223
- });
224
- const rootAddr = getIbGibAddr({ ibGib: root });
225
- if (logalot) {
226
- console.log(`${lc} rootAddr: ${rootAddr} (I: 486bcba15f0a3307f8e6aa88089d1825)`);
227
- }
228
- const tjpAddr = getTjpAddr({ ibGib: root, defaultIfNone: 'incomingAddr' }) || rootAddr; // Root is typically its own TJP if not explicit
229
- if (logalot) {
230
- console.log(`${lc} tjpAddr: ${tjpAddr} (I: b9326dfb66b8efe8a829673335869c25)`);
231
- }
232
- if (logalot) {
233
- console.log(`${lc} root:\n${pretty(root)} (I: 3051584310780a36c8435d7881d2f825)`);
234
- }
235
- const mockKeystone = await getTestKeystoneServiceHelper();
236
- const identity = await mockKeystone.getIdentity();
237
- const coordinator = new SyncSagaCoordinator(mockKeystone);
238
- await coordinator.sync({
239
- source: sourceSpace,
240
- dest: destSpace,
241
- domainIbGibs: [root],
242
- identity
243
- });
244
- let rootGraph_source = await getDependencyGraph({ ibGib: root, space: sourceSpace });
245
- let rootGraph_dest = await getDependencyGraph({ ibGib: root, space: destSpace });
246
- let rootsSynced = naiveGraphsAreEqual(rootGraph_source, rootGraph_dest);
247
- if (rootsSynced) {
248
- if (logalot) {
249
- console.log(`${lc} rootsSynced (I: 493982dbc9f40170fd26a0d8e0b69825)`);
250
- }
251
- }
252
- else {
253
- throw new Error(`(UNEXPECTED) graphs are not equal after simple root push sync? (E: f10be8a3d285f260989419c8b99bc225)`);
254
- }
255
- // 3. Evolve DESTINATION (Simulate external update)
256
- // We act "as if" we are on Dest side evolving it. This is like we are
257
- // syncing with the remote, and there were changes created by someone
258
- // else but we have no local changes.
259
- console.log(`${lc} Evolving Destination (making Source behind)...`);
260
- const childDest = await mut8Timeline({
261
- timeline: root, // works because mut8Timeline just needs the ib/data/rel8ns/n, doesn't need to be "in" the space object-wise, but we persist to destSpace
262
- mut8Opts: { dataToAddOrPatch: { type: 'modified in dest', state: 'ahead' } },
263
- metaspace,
264
- space: destSpace,
265
- });
266
- const childDestAddr = getIbGibAddr({ ibGib: childDest });
267
- if (logalot) {
268
- console.log(`${lc} childDest:\n${pretty(childDest)}(I: ff4868842d8757df98cfe59ec5bea825)`);
269
- }
270
- // Log debugging info for TJP
271
- const childDestTjpAddr = getTjpAddr({ ibGib: childDest });
272
- console.log(`${lc} childDestAddr: ${childDestAddr}`);
273
- console.log(`${lc} rootAddr (Expected TJP?): ${rootAddr}`);
274
- console.log(`${lc} childDest TJP Addr: ${childDestTjpAddr}`);
275
- // If TJP is missing or mismatched, that's why getLatestAddrs fails
276
- if (!childDestTjpAddr || childDestTjpAddr !== tjpAddr) {
277
- // NOTE: THIS DOES NOT HIT
278
- console.warn(`${lc} WARNING: childDest TJP (${childDestTjpAddr}) does not match root/expected TJP (${tjpAddr}). This likely causes sync to miss it.`);
279
- // Hack fix for test verification if mut8Timeline is slightly broken on TJP propagation for raw tests
280
- if (!childDest.rel8ns) {
281
- childDest.rel8ns = {};
282
- }
283
- childDest.rel8ns.tjp = [tjpAddr];
284
- // Re-put to update index?? No, InnerSpace uses in-memory map references often if we modified object.
285
- // Better to re-put explicitly if we modified it.
286
- await putInSpace({ space: destSpace, ibGibs: [childDest] });
287
- }
288
- console.log(`${lc} sourceSpace UUID: ${sourceSpace.data.uuid}`);
289
- console.log(`${lc} destSpace UUID: ${destSpace.data.uuid}`);
290
- // Verify Source DOES NOT have childDest
291
- const getChildInSource = await getFromSpace({ space: sourceSpace, addr: childDestAddr });
292
- iReckon(sir, getChildInSource.success).asTo('Source is behind').isGonnaBeFalse(); // Or success=true/addrsNotFound depending on impl
293
- // 4. Run Sync from Source
294
- // Checks:
295
- // - Source should detect it is behind (or "conflict" in current generic terms).
296
- // - Source should Pull 'childDest' from Dest.
297
- // - Source should update itself.
298
- console.log(`${lc} Running Sync (Pull)...`);
299
- await coordinator.sync({
300
- source: sourceSpace,
301
- dest: destSpace,
302
- domainIbGibs: [root], // We start with what Source knows (root)
303
- identity
304
- });
305
- // 5. Verify Source Caught Up
306
- const getChildInSourcePost = await getFromSpace({ space: sourceSpace, addr: childDestAddr });
307
- console.log(`${lc} getChildInSourcePost success: ${getChildInSourcePost.success}`);
308
- if (getChildInSourcePost.ibGibs) {
309
- console.log(`${lc} getChildInSourcePost found: ${getChildInSourcePost.ibGibs.length} ibGibs`);
310
- }
311
- else {
312
- console.log(`${lc} getChildInSourcePost found: 0 ibGibs (undefined)`);
313
- }
314
- iReckon(sir, getChildInSourcePost.success).asTo('Source pulled new frame').isGonnaBeTrue();
315
- iReckon(sir, getChildInSourcePost.ibGibs?.[0]).asTo('Source has childDest').isGonnaBeTruthy();
316
- console.log(`${lc} Verified Dest Ahead / Pull.`);
317
- });
318
- // await ifWeMight(sir, `Divergent (Conflict Detection)`, async () => {
319
- // interface TestData extends IbGibData_V1 {
320
- // type: string;
321
- // state?: string;
322
- // branch?: string;
323
- // }
324
- // // 1. Setup
325
- // const metaspace = new Metaspace_Innerspace(undefined);
326
- // await metaspace.initialize({
327
- // getFnAlert: () => async ({ title, msg }) => { console.log(`[Alert] ${title}: ${msg}`); },
328
- // getFnPrompt: () => async ({ title, msg }) => { console.log(`[Prompt] ${title}: ${msg}`); return ''; },
329
- // getFnPromptPassword: () => async (title, msg) => { console.log(`[PromptPwd] ${title}: ${msg}`); return null; },
330
- // });
331
- // const sourceSpace = new InnerSpace_V1({ name: 'source_div', uuid: 'source_div_uuid' } as any);
332
- // // await (sourceSpace as any).initialize();
333
- // const destSpace = new InnerSpace_V1({ name: 'dest_div', uuid: 'dest_div_uuid' } as any);
334
- // // await (destSpace as any).initialize();
335
- // // 2. Setup Shared Root
336
- // const root = await createTimelineRootHelper<TestData>({
337
- // ib: 'timeline_div',
338
- // data: { type: 'root' },
339
- // space: sourceSpace,
340
- // });
341
- // const rootAddr = getIbGibAddr({ ibGib: root });
342
- // const tjpAddr = getTjpAddr({ ibGib: root }) || rootAddr;
343
- // // Sync root to dest so they share base
344
- // await putInSpace({ space: destSpace, ibGibs: [root] });
345
- // // NOTE: Must manually index TJP in dest if putInSpace doesn't trigger full indexing (InnerSpace might need register)
346
- // // Ideally we run a sync to init, but manual put + hack fix is faster for setup.
347
- // // Actually, let's use coordinator to sync root first to ensure clean state.
348
- // const mockKeystone = await getTestKeystoneServiceHelper();
349
- // const identity = await (mockKeystone as any).getIdentity();
350
- // const coordinator = new SyncSagaCoordinator(mockKeystone);
351
- // await coordinator.sync({
352
- // source: sourceSpace,
353
- // dest: destSpace,
354
- // domainIbGibs: [root],
355
- // identity
356
- // });
357
- // // 3. Diverge!
358
- // // Source creates Child A
359
- // const childA = await mut8Timeline({
360
- // timeline: root,
361
- // mut8Opts: { dataToAddOrPatch: { branch: 'A' } },
362
- // metaspace,
363
- // space: sourceSpace,
364
- // });
365
- // const childAAddr = getIbGibAddr({ ibGib: childA });
366
- // // Dest (simulated) creates Child B from Root (Forking history)
367
- // const childB = await mut8Timeline({
368
- // timeline: root,
369
- // mut8Opts: { dataToAddOrPatch: { branch: 'B' } }, // Logic: same n=1, but different content/hash
370
- // metaspace,
371
- // space: destSpace,
372
- // });
373
- // const childBAddr = getIbGibAddr({ ibGib: childB });
374
- // // Ensure TJP indexing on Dest (test hack)
375
- // const childBTjp = getTjpAddr({ ibGib: childB });
376
- // if (!childBTjp || childBTjp !== tjpAddr) {
377
- // if (!childB.rel8ns) childB.rel8ns = {};
378
- // childB.rel8ns.tjp = [tjpAddr];
379
- // await putInSpace({ space: destSpace, ibGibs: [childB] });
380
- // }
381
- // console.log(`${lc} Divergence Setup:`);
382
- // console.log(`${lc} Root: ${rootAddr}`);
383
- // console.log(`${lc} Source Tip (A): ${childAAddr}`);
384
- // console.log(`${lc} Dest Tip (B): ${childBAddr}`);
385
- // // 4. Sync with Strategy: 'abort' (Expect Error)
386
- // console.log(`${lc} Running Sync (Abort Strategy)...`);
387
- // let caughtError;
388
- // try {
389
- // await coordinator.sync({
390
- // source: sourceSpace,
391
- // dest: destSpace,
392
- // domainIbGibs: [childA],
393
- // identity,
394
- // conflictStrategy: 'abort', // Should throw
395
- // });
396
- // } catch (e) {
397
- // caughtError = e;
398
- // console.log(`${lc} Caught expected error: ${e.message}`);
399
- // }
400
- // iReckon(sir, caughtError).asTo('Should throw on conflict with abort strategy').isGonnaBeTruthy();
401
- // // 5. Sync with Strategy: 'optimistic' (Expect Merge)
402
- // // TODO: Implement optimistic merging
403
- // });
404
- });
1
+ // /**
2
+ // * @module sync-innerspace.respec
3
+ // *
4
+ // * Verifies SyncSagaCoordinator using InnerSpace (in-memory/local) spaces.
5
+ // * This avoids disk I/O issues and focuses on the synchronization logic.
6
+ // */
7
+ export {};
8
+ // import {
9
+ // respecfully, lastOfAll, ifWe, iReckon,
10
+ // ifWeMight
11
+ // } from '@ibgib/helper-gib/dist/respec-gib/respec-gib.mjs';
12
+ // const maam = `[${import.meta.url}]`, sir = maam;
13
+ // import { pretty } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
14
+ // import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs';
15
+ // import { IbGibData_V1 } from '@ibgib/ts-gib/dist/V1/types.mjs';
16
+ // import { SyncSagaCoordinator } from './sync-saga-coordinator.mjs';
17
+ // import { putInSpace, getFromSpace } from '../witness/space/space-helper.mjs';
18
+ // import { Metaspace_Innerspace } from '../witness/space/metaspace/metaspace-innerspace/metaspace-innerspace.mjs';
19
+ // import { InnerSpace_V1 } from '../witness/space/inner-space/inner-space-v1.mjs';
20
+ // import { createStoneHelper, createTimelineRootHelper, getTestKeystoneServiceHelper } from '../agent-helpers.mjs';
21
+ // import { mut8Timeline, appendToTimeline, getLatestTimelineIbGibDto_nonLocking } from '../timeline/timeline-api.mjs';
22
+ // import { getDependencyGraph } from '../common/other/graph-helper.mjs';
23
+ // import { getTjpAddr } from '../common/other/ibgib-helper.mjs';
24
+ // import { FlatIbGibGraph } from '../common/other/graph-types.mjs';
25
+ // import { SyncConflictStrategy } from './sync-types.mjs';
26
+ // const logalot = true;
27
+ // const lc = `[sync-innerspace.respec]`;
28
+ // /**
29
+ // * naive helper function to determine if two dependency graphs are equal.
30
+ // *
31
+ // * naive: only checks length of keys and if keys all match.
32
+ // *
33
+ // * @param a dependency graph from one space
34
+ // * @param b dep. graph from another space
35
+ // * @returns true if graphs are equal in size and keys, else false.
36
+ // */
37
+ // function naiveGraphsAreEqual(a: FlatIbGibGraph, b: FlatIbGibGraph): boolean {
38
+ // const keysA = Object.keys(a);
39
+ // const keysB = Object.keys(b);
40
+ // if (keysA.length !== keysB.length) { false; }
41
+ // return keysA.every(key => !!b[key]);
42
+ // }
43
+ // await respecfully(sir, `Sync InnerSpaces`, async () => {
44
+ // let metaspace: Metaspace_Innerspace;
45
+ // let sourceSpace: InnerSpace_V1;
46
+ // let destSpace: InnerSpace_V1;
47
+ // // Setup before each test? Or once?
48
+ // // For now, let's just do it inside the test block to be safe/simple.
49
+ // await ifWeMight(sir, `Basic Push Sync (Source -> Dest)`, async () => {
50
+ // // 1. Setup Spaces
51
+ // metaspace = new Metaspace_Innerspace(undefined);
52
+ // await metaspace.initialize({
53
+ // getFnAlert: () => async ({ title, msg }) => { console.log(`[Alert] ${title}: ${msg}`); },
54
+ // getFnPrompt: () => async ({ title, msg }) => { console.log(`[Prompt] ${title}: ${msg}`); return ''; },
55
+ // getFnPromptPassword: () => async (title, msg) => { console.log(`[PromptPwd] ${title}: ${msg}`); return null; },
56
+ // });
57
+ // // Create two distinct inner spaces manually or via metaspace if supported
58
+ // // Metaspace_Innerspace typically manages one local user space, but we can instantiate InnerSpace_V1 directly.
59
+ // sourceSpace = new InnerSpace_V1({ name: 'source', uuid: 'source_uuid' } as any);
60
+ // await (sourceSpace as any).initialize();
61
+ // destSpace = new InnerSpace_V1({ name: 'dest', uuid: 'dest_uuid' } as any);
62
+ // await (destSpace as any).initialize();
63
+ // // 2. Seed Source Data
64
+ // // 2.1 Create a "Stone"
65
+ // console.log(`${lc} Creating Stone...`);
66
+ // const stone = await createStoneHelper({
67
+ // ib: 'stone_data',
68
+ // data: { some: 'data' },
69
+ // });
70
+ // const stoneAddr = getIbGibAddr({ ibGib: stone });
71
+ // await putInSpace({ space: sourceSpace, ibGibs: [stone] });
72
+ // // 2.2 Create a "Living" Timeline (Root)
73
+ // console.log(`${lc} Creating Timeline Root...`);
74
+ // const root = await createTimelineRootHelper({
75
+ // ib: 'timeline_root',
76
+ // data: { type: 'root', n: 0 },
77
+ // space: sourceSpace,
78
+ // });
79
+ // const rootAddr = getIbGibAddr({ ibGib: root });
80
+ // // 2.3 Evolve Timeline (Root -> Child)
81
+ // // using mut8Timeline to simulate evolution
82
+ // console.log(`${lc} Evolving Timeline...`);
83
+ // const child = await mut8Timeline({
84
+ // timeline: root,
85
+ // mut8Opts: {
86
+ // dataToAddOrPatch: { type: 'child', n: 1 }
87
+ // },
88
+ // metaspace,
89
+ // space: sourceSpace,
90
+ // // We use skipLock=true for simplicity in single-threaded test setup if locking is complex,
91
+ // // but timeline-api handles locking. Let's try default first.
92
+ // // Actually InnerSpace locking might be no-op or simple.
93
+ // });
94
+ // const childAddr = getIbGibAddr({ ibGib: child });
95
+ // // 2.4 Rel8 Child to Stone (Dependency)
96
+ // console.log(`${lc} Linking Child to Stone...`);
97
+ // const childWithRel = await appendToTimeline({
98
+ // timeline: child,
99
+ // rel8nInfos: [{
100
+ // rel8nName: 'linked_stone',
101
+ // ibGibs: [stone]
102
+ // }],
103
+ // metaspace,
104
+ // space: sourceSpace,
105
+ // });
106
+ // const childWithRelAddr = getIbGibAddr({ ibGib: childWithRel });
107
+ // // 3. Setup Sync Coordinator
108
+ // console.log(`${lc} Setting up Coordinator...`);
109
+ // const mockKeystone = await getTestKeystoneServiceHelper();
110
+ // const identity = await (mockKeystone as any).getIdentity();
111
+ // const coordinator = new SyncSagaCoordinator(mockKeystone);
112
+ // // 4. Run Sync
113
+ // console.log(`${lc} Running Sync...`);
114
+ // const syncRes = await coordinator.sync({
115
+ // source: sourceSpace,
116
+ // dest: destSpace,
117
+ // domainIbGibs: [childWithRel], // Sync starting from the tip
118
+ // identity
119
+ // });
120
+ // // 5. Verify Dest (Full Dependency Graph)
121
+ // console.log(`${lc} Verifying Destination (Full Graph)...`);
122
+ // // We expect the graph to contain:
123
+ // // 1. childWithRel
124
+ // // 2. child (past of childWithRel)
125
+ // // 3. root (ancestor of child, past of child)
126
+ // // 4. stone (linked to childWithRel)
127
+ // // 5. primitives (timeline_root, child, stone_data, identity, fork, mut8, rel8, root^gib, etc.)
128
+ // // Let's get the graph from the source first to know what to expect (ground truth)
129
+ // const sourceGraph = await getDependencyGraph({
130
+ // ibGibs: [childWithRel],
131
+ // space: sourceSpace,
132
+ // });
133
+ // const sourceAddrs = Object.keys(sourceGraph);
134
+ // console.log(`${lc} Source Graph Size: ${sourceAddrs.length}`);
135
+ // // Now get the graph from the destination
136
+ // const destGraph = await getDependencyGraph({
137
+ // ibGibs: [childWithRel],
138
+ // space: destSpace,
139
+ // });
140
+ // const destAddrs = Object.keys(destGraph);
141
+ // console.log(`${lc} Dest Graph Size: ${destAddrs.length}`);
142
+ // // Assert
143
+ // iReckon(sir, destAddrs.length).asTo('dest graph size').isGonnaBe(sourceAddrs.length);
144
+ // for (const addr of sourceAddrs) {
145
+ // const inDest = !!destGraph[addr];
146
+ // if (!inDest) {
147
+ // console.error(`${lc} Missing in dest: ${addr}`);
148
+ // }
149
+ // iReckon(sir, inDest).asTo(`addr present in dest: ${addr}`).isGonnaBeTrue();
150
+ // }
151
+ // console.log(`${lc} Verified Full Dependency Graph synced.`);
152
+ // });
153
+ // await ifWeMight(sir, `Idempotency (No-op if already synced)`, async () => {
154
+ // // 1. Setup Spaces
155
+ // const metaspace = new Metaspace_Innerspace(undefined);
156
+ // await metaspace.initialize({
157
+ // getFnAlert: () => async ({ title, msg }) => { console.log(`[Alert] ${title}: ${msg}`); },
158
+ // getFnPrompt: () => async ({ title, msg }) => { console.log(`[Prompt] ${title}: ${msg}`); return ''; },
159
+ // getFnPromptPassword: () => async (title, msg) => { console.log(`[PromptPwd] ${title}: ${msg}`); return null; },
160
+ // });
161
+ // const sourceSpace = new InnerSpace_V1({ name: 'source_idem', uuid: 'source_idem_uuid' } as any);
162
+ // await (sourceSpace as any).initialize();
163
+ // const destSpace = new InnerSpace_V1({ name: 'dest_idem', uuid: 'dest_idem_uuid' } as any);
164
+ // await (destSpace as any).initialize();
165
+ // // 2. Seed Source and Sync ONCE
166
+ // const root = await createTimelineRootHelper({
167
+ // ib: 'timeline_root',
168
+ // data: { type: 'root', n: 0 },
169
+ // space: sourceSpace,
170
+ // });
171
+ // const mockKeystone = await getTestKeystoneServiceHelper();
172
+ // const identity = await (mockKeystone as any).getIdentity();
173
+ // const coordinator = new SyncSagaCoordinator(mockKeystone);
174
+ // console.log(`${lc} Running First Sync...`);
175
+ // await coordinator.sync({
176
+ // source: sourceSpace,
177
+ // dest: destSpace,
178
+ // domainIbGibs: [root],
179
+ // identity
180
+ // });
181
+ // // Verify Initial State
182
+ // const rootAddr = getIbGibAddr({ ibGib: root });
183
+ // const getRoot1 = await getFromSpace({ space: destSpace, addr: rootAddr });
184
+ // iReckon(sir, getRoot1.success).asTo('First Sync success').isGonnaBeTrue();
185
+ // // 3. Run Sync AGAIN (Should be No-op)
186
+ // console.log(`${lc} Running Second Sync...`);
187
+ // await coordinator.sync({
188
+ // source: sourceSpace,
189
+ // dest: destSpace,
190
+ // domainIbGibs: [root],
191
+ // identity
192
+ // });
193
+ // // 4. Verify State Unchanged / Still Valid
194
+ // const getRoot2 = await getFromSpace({ space: destSpace, addr: rootAddr });
195
+ // iReckon(sir, getRoot2.success).asTo('Second Sync success').isGonnaBeTrue();
196
+ // // Ensure no duplication or errors in destination (checking count in dependency graph might be good proxy?)
197
+ // const destGraph = await getDependencyGraph({
198
+ // ibGibs: [root],
199
+ // space: destSpace,
200
+ // });
201
+ // iReckon(sir, Object.keys(destGraph).length).asTo('Dest Graph Size unchanged').isGonnaBe(Object.keys(destGraph).length); // Trivial assertion, mostly checking for no throw
202
+ // console.log(`${lc} Verified Idempotency.`);
203
+ // });
204
+ // await ifWeMight(sir, `Dest Ahead (Pull/Fast-Backward)`, async () => {
205
+ // // 1. Setup Spaces
206
+ // // Metaspace_Innerspace automatically initializes spaces so we don't need manual initialize calls for these if they were standard.
207
+ // // But here we are instantiating them directly.
208
+ // // User pointed out initialize is called in constructor.
209
+ // const metaspace = new Metaspace_Innerspace(undefined);
210
+ // await metaspace.initialize({
211
+ // getFnAlert: () => async ({ title, msg }) => { console.log(`[Alert] ${title}: ${msg}`); },
212
+ // getFnPrompt: () => async ({ title, msg }) => { console.log(`[Prompt] ${title}: ${msg}`); return ''; },
213
+ // getFnPromptPassword: () => async (title, msg) => { console.log(`[PromptPwd] ${title}: ${msg}`); return null; },
214
+ // });
215
+ // // const sourceSpace = new InnerSpace_V1({ name: 'source_pull', uuid: 'source_pull_uuid' } as any);
216
+ // const sourceSpace = new InnerSpace_V1({ name: 'source_pull', } as any);
217
+ // // await (sourceSpace as any).initialize(); // Already initialized in ctor
218
+ // // const destSpace = new InnerSpace_V1({ name: 'dest_pull', uuid: 'dest_pull_uuid' } as any);
219
+ // const destSpace = new InnerSpace_V1({ name: 'dest_pull', } as any);
220
+ // // await (destSpace as any).initialize(); // Already initialized in ctor
221
+ // // 2. Setup Initial Shared State
222
+ // // Create root in Source, Sync to Dest
223
+ // console.log(`${lc} Seeding initial shared state...`);
224
+ // const root = await createTimelineRootHelper({
225
+ // ib: 'timeline_pull',
226
+ // data: { type: 'root', state: 'initial' },
227
+ // space: sourceSpace,
228
+ // });
229
+ // const rootAddr = getIbGibAddr({ ibGib: root });
230
+ // if (logalot) { console.log(`${lc} rootAddr: ${rootAddr} (I: 486bcba15f0a3307f8e6aa88089d1825)`); }
231
+ // const tjpAddr = getTjpAddr({ ibGib: root, defaultIfNone: 'incomingAddr' }) || rootAddr; // Root is typically its own TJP if not explicit
232
+ // if (logalot) { console.log(`${lc} tjpAddr: ${tjpAddr} (I: b9326dfb66b8efe8a829673335869c25)`); }
233
+ // if (logalot) { console.log(`${lc} root:\n${pretty(root)} (I: 3051584310780a36c8435d7881d2f825)`); }
234
+ // const mockKeystone = await getTestKeystoneServiceHelper();
235
+ // const identity = await (mockKeystone as any).getIdentity();
236
+ // const coordinator = new SyncSagaCoordinator(mockKeystone);
237
+ // await coordinator.sync({
238
+ // source: sourceSpace,
239
+ // dest: destSpace,
240
+ // domainIbGibs: [root],
241
+ // identity
242
+ // });
243
+ // let rootGraph_source: FlatIbGibGraph = await getDependencyGraph({ ibGib: root, space: sourceSpace });
244
+ // let rootGraph_dest: FlatIbGibGraph = await getDependencyGraph({ ibGib: root, space: destSpace });
245
+ // let rootsSynced = naiveGraphsAreEqual(rootGraph_source, rootGraph_dest);
246
+ // if (rootsSynced) {
247
+ // if (logalot) { console.log(`${lc} rootsSynced (I: 493982dbc9f40170fd26a0d8e0b69825)`); }
248
+ // } else {
249
+ // throw new Error(`(UNEXPECTED) graphs are not equal after simple root push sync? (E: f10be8a3d285f260989419c8b99bc225)`);
250
+ // }
251
+ // // 3. Evolve DESTINATION (Simulate external update)
252
+ // // We act "as if" we are on Dest side evolving it. This is like we are
253
+ // // syncing with the remote, and there were changes created by someone
254
+ // // else but we have no local changes.
255
+ // console.log(`${lc} Evolving Destination (making Source behind)...`);
256
+ // const childDest = await mut8Timeline({
257
+ // timeline: root, // works because mut8Timeline just needs the ib/data/rel8ns/n, doesn't need to be "in" the space object-wise, but we persist to destSpace
258
+ // mut8Opts: { dataToAddOrPatch: { type: 'modified in dest', state: 'ahead' } },
259
+ // metaspace,
260
+ // space: destSpace,
261
+ // });
262
+ // const childDestAddr = getIbGibAddr({ ibGib: childDest });
263
+ // if (logalot) { console.log(`${lc} childDest:\n${pretty(childDest)}(I: ff4868842d8757df98cfe59ec5bea825)`); }
264
+ // // Log debugging info for TJP
265
+ // const childDestTjpAddr = getTjpAddr({ ibGib: childDest });
266
+ // console.log(`${lc} childDestAddr: ${childDestAddr}`);
267
+ // console.log(`${lc} rootAddr (Expected TJP?): ${rootAddr}`);
268
+ // console.log(`${lc} childDest TJP Addr: ${childDestTjpAddr}`);
269
+ // // If TJP is missing or mismatched, that's why getLatestAddrs fails
270
+ // if (!childDestTjpAddr || childDestTjpAddr !== tjpAddr) {
271
+ // // NOTE: THIS DOES NOT HIT
272
+ // console.warn(`${lc} WARNING: childDest TJP (${childDestTjpAddr}) does not match root/expected TJP (${tjpAddr}). This likely causes sync to miss it.`);
273
+ // // Hack fix for test verification if mut8Timeline is slightly broken on TJP propagation for raw tests
274
+ // if (!childDest.rel8ns) { childDest.rel8ns = {}; }
275
+ // childDest.rel8ns.tjp = [tjpAddr];
276
+ // // Re-put to update index?? No, InnerSpace uses in-memory map references often if we modified object.
277
+ // // Better to re-put explicitly if we modified it.
278
+ // await putInSpace({ space: destSpace, ibGibs: [childDest] });
279
+ // }
280
+ // console.log(`${lc} sourceSpace UUID: ${(sourceSpace as any).data.uuid}`);
281
+ // console.log(`${lc} destSpace UUID: ${(destSpace as any).data.uuid}`);
282
+ // // Verify Source DOES NOT have childDest
283
+ // const getChildInSource = await getFromSpace({ space: sourceSpace, addr: childDestAddr });
284
+ // iReckon(sir, getChildInSource.success).asTo('Source is behind').isGonnaBeFalse(); // Or success=true/addrsNotFound depending on impl
285
+ // // 4. Run Sync from Source
286
+ // // Checks:
287
+ // // - Source should detect it is behind (or "conflict" in current generic terms).
288
+ // // - Source should Pull 'childDest' from Dest.
289
+ // // - Source should update itself.
290
+ // console.log(`${lc} Running Sync (Pull)...`);
291
+ // await coordinator.sync({
292
+ // source: sourceSpace,
293
+ // dest: destSpace,
294
+ // domainIbGibs: [root], // We start with what Source knows (root)
295
+ // identity
296
+ // });
297
+ // // 5. Verify Source Caught Up
298
+ // const getChildInSourcePost = await getFromSpace({ space: sourceSpace, addr: childDestAddr });
299
+ // console.log(`${lc} getChildInSourcePost success: ${getChildInSourcePost.success}`);
300
+ // if (getChildInSourcePost.ibGibs) {
301
+ // console.log(`${lc} getChildInSourcePost found: ${getChildInSourcePost.ibGibs.length} ibGibs`);
302
+ // } else {
303
+ // console.log(`${lc} getChildInSourcePost found: 0 ibGibs (undefined)`);
304
+ // }
305
+ // iReckon(sir, getChildInSourcePost.success).asTo('Source pulled new frame').isGonnaBeTrue();
306
+ // iReckon(sir, getChildInSourcePost.ibGibs?.[0]).asTo('Source has childDest').isGonnaBeTruthy();
307
+ // console.log(`${lc} Verified Dest Ahead / Pull.`);
308
+ // });
309
+ // await ifWeMight(sir, `Divergent (Conflict Detection)`, async () => {
310
+ // interface TestData extends IbGibData_V1 {
311
+ // type: string;
312
+ // state?: string;
313
+ // branch?: string;
314
+ // }
315
+ // // 1. Setup
316
+ // const metaspace = new Metaspace_Innerspace(undefined);
317
+ // await metaspace.initialize({
318
+ // getFnAlert: () => async ({ title, msg }) => { console.log(`[Alert] ${title}: ${msg}`); },
319
+ // getFnPrompt: () => async ({ title, msg }) => { console.log(`[Prompt] ${title}: ${msg}`); return ''; },
320
+ // getFnPromptPassword: () => async (title, msg) => { console.log(`[PromptPwd] ${title}: ${msg}`); return null; },
321
+ // });
322
+ // const sourceSpace = new InnerSpace_V1({ name: 'source_div', uuid: 'source_div_uuid' } as any);
323
+ // // await (sourceSpace as any).initialize();
324
+ // const destSpace = new InnerSpace_V1({ name: 'dest_div', uuid: 'dest_div_uuid' } as any);
325
+ // // await (destSpace as any).initialize();
326
+ // // 2. Setup Shared Root
327
+ // const root = await createTimelineRootHelper<TestData>({
328
+ // ib: 'timeline_div',
329
+ // data: { type: 'root' },
330
+ // space: sourceSpace,
331
+ // });
332
+ // const rootAddr = getIbGibAddr({ ibGib: root });
333
+ // const tjpAddr = getTjpAddr({ ibGib: root }) || rootAddr;
334
+ // // Sync root to dest so they share base
335
+ // await putInSpace({ space: destSpace, ibGibs: [root] });
336
+ // // NOTE: Must manually index TJP in dest if putInSpace doesn't trigger full indexing (InnerSpace might need register)
337
+ // // Ideally we run a sync to init, but manual put + hack fix is faster for setup.
338
+ // // Actually, let's use coordinator to sync root first to ensure clean state.
339
+ // const mockKeystone = await getTestKeystoneServiceHelper();
340
+ // const identity = await (mockKeystone as any).getIdentity();
341
+ // const coordinator = new SyncSagaCoordinator(mockKeystone);
342
+ // await coordinator.sync({
343
+ // source: sourceSpace,
344
+ // dest: destSpace,
345
+ // domainIbGibs: [root],
346
+ // identity
347
+ // });
348
+ // // 3. Diverge!
349
+ // // Source creates Child A
350
+ // const childA = await mut8Timeline({
351
+ // timeline: root,
352
+ // mut8Opts: { dataToAddOrPatch: { branch: 'A' } },
353
+ // metaspace,
354
+ // space: sourceSpace,
355
+ // });
356
+ // const childAAddr = getIbGibAddr({ ibGib: childA });
357
+ // // Dest (simulated) creates Child B from Root (Forking history)
358
+ // const childB = await mut8Timeline({
359
+ // timeline: root,
360
+ // mut8Opts: { dataToAddOrPatch: { branch: 'B' } }, // Logic: same n=1, but different content/hash
361
+ // metaspace,
362
+ // space: destSpace,
363
+ // });
364
+ // const childBAddr = getIbGibAddr({ ibGib: childB });
365
+ // // Ensure TJP indexing on Dest (test hack)
366
+ // const childBTjp = getTjpAddr({ ibGib: childB });
367
+ // if (!childBTjp || childBTjp !== tjpAddr) {
368
+ // if (!childB.rel8ns) childB.rel8ns = {};
369
+ // childB.rel8ns.tjp = [tjpAddr];
370
+ // await putInSpace({ space: destSpace, ibGibs: [childB] });
371
+ // }
372
+ // console.log(`${lc} Divergence Setup:`);
373
+ // console.log(`${lc} Root: ${rootAddr}`);
374
+ // console.log(`${lc} Source Tip (A): ${childAAddr}`);
375
+ // console.log(`${lc} Dest Tip (B): ${childBAddr}`);
376
+ // // 4. Sync with Strategy: 'abort' (Expect Error)
377
+ // console.log(`${lc} Running Sync (Abort Strategy)...`);
378
+ // let caughtError;
379
+ // try {
380
+ // await coordinator.sync({
381
+ // source: sourceSpace,
382
+ // dest: destSpace,
383
+ // domainIbGibs: [childA],
384
+ // identity,
385
+ // conflictStrategy: SyncConflictStrategy.abort, // Should throw
386
+ // });
387
+ // } catch (e) {
388
+ // caughtError = e;
389
+ // console.log(`${lc} Caught expected error: ${e.message}`);
390
+ // }
391
+ // iReckon(sir, caughtError).asTo('Should throw on conflict with abort strategy').isGonnaBeTruthy();
392
+ // // 5. Sync with Strategy: 'optimistic' (Expect Merge)
393
+ // // TODO: Implement optimistic merging
394
+ // });
395
+ // });
405
396
  //# sourceMappingURL=sync-innerspace.respec.mjs.map