@ibgib/core-gib 0.1.60 → 0.1.61

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 (179) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/dist/common/other/graph-helper.d.mts.map +1 -1
  3. package/dist/common/other/graph-helper.mjs +7 -6
  4. package/dist/common/other/graph-helper.mjs.map +1 -1
  5. package/dist/keystone/keystone-config-builder.d.mts +1 -2
  6. package/dist/keystone/keystone-config-builder.d.mts.map +1 -1
  7. package/dist/keystone/keystone-config-builder.mjs +4 -19
  8. package/dist/keystone/keystone-config-builder.mjs.map +1 -1
  9. package/dist/keystone/keystone-constants.d.mts +2 -0
  10. package/dist/keystone/keystone-constants.d.mts.map +1 -1
  11. package/dist/keystone/keystone-constants.mjs +2 -0
  12. package/dist/keystone/keystone-constants.mjs.map +1 -1
  13. package/dist/keystone/keystone-helpers.d.mts +5 -15
  14. package/dist/keystone/keystone-helpers.d.mts.map +1 -1
  15. package/dist/keystone/keystone-helpers.mjs +59 -73
  16. package/dist/keystone/keystone-helpers.mjs.map +1 -1
  17. package/dist/keystone/keystone-policy-types.d.mts +6 -4
  18. package/dist/keystone/keystone-policy-types.d.mts.map +1 -1
  19. package/dist/keystone/keystone-service-v1.d.mts.map +1 -1
  20. package/dist/keystone/keystone-service-v1.mjs +4 -8
  21. package/dist/keystone/keystone-service-v1.mjs.map +1 -1
  22. package/dist/keystone/keystone-service-v1.respec.mjs +182 -33
  23. package/dist/keystone/keystone-service-v1.respec.mjs.map +1 -1
  24. package/dist/keystone/keystone-types.d.mts +4 -11
  25. package/dist/keystone/keystone-types.d.mts.map +1 -1
  26. package/dist/keystone/policy/keystone-profile-builder.d.mts +25 -0
  27. package/dist/keystone/policy/keystone-profile-builder.d.mts.map +1 -0
  28. package/dist/keystone/policy/keystone-profile-builder.mjs +117 -0
  29. package/dist/keystone/policy/keystone-profile-builder.mjs.map +1 -0
  30. package/dist/keystone/policy/profiles/profile-high.json +84 -0
  31. package/dist/keystone/policy/profiles/profile-low.json +84 -0
  32. package/dist/keystone/policy/profiles/profile-medium.json +84 -0
  33. package/dist/keystone/policy/profiles/profile-session.json +84 -0
  34. package/dist/keystone/policy/profiles/profile-test.json +84 -0
  35. package/dist/keystone/policy/schemas/connect-pool.high.schema.json +23 -0
  36. package/dist/keystone/policy/schemas/connect-pool.low.schema.json +23 -0
  37. package/dist/keystone/policy/schemas/connect-pool.medium.schema.json +23 -0
  38. package/dist/keystone/policy/schemas/keystone.high.schema.json +26 -0
  39. package/dist/keystone/policy/schemas/keystone.low.schema.json +26 -0
  40. package/dist/keystone/policy/schemas/keystone.medium.schema.json +26 -0
  41. package/dist/keystone/policy/schemas/manage-pool.high.schema.json +23 -0
  42. package/dist/keystone/policy/schemas/manage-pool.low.schema.json +23 -0
  43. package/dist/keystone/policy/schemas/manage-pool.medium.schema.json +23 -0
  44. package/dist/keystone/policy/schemas/revoke-pool.high.schema.json +23 -0
  45. package/dist/keystone/policy/schemas/revoke-pool.low.schema.json +23 -0
  46. package/dist/keystone/policy/schemas/revoke-pool.medium.schema.json +23 -0
  47. package/dist/keystone/policy/schemas/sign-pool.high.schema.json +23 -0
  48. package/dist/keystone/policy/schemas/sign-pool.low.schema.json +23 -0
  49. package/dist/keystone/policy/schemas/sign-pool.medium.schema.json +23 -0
  50. package/dist/keystone/policy/schemas/sync-pool.high.schema.json +23 -0
  51. package/dist/keystone/policy/schemas/sync-pool.low.schema.json +23 -0
  52. package/dist/keystone/policy/schemas/sync-pool.medium.schema.json +23 -0
  53. package/dist/sync/sync-conflict-adv-multitimelines.withid.respec.d.mts +8 -0
  54. package/dist/sync/sync-conflict-adv-multitimelines.withid.respec.d.mts.map +1 -0
  55. package/dist/sync/sync-conflict-adv-multitimelines.withid.respec.mjs +582 -0
  56. package/dist/sync/sync-conflict-adv-multitimelines.withid.respec.mjs.map +1 -0
  57. package/dist/sync/sync-conflict-basic-divergence.withid.respec.d.mts +7 -0
  58. package/dist/sync/sync-conflict-basic-divergence.withid.respec.d.mts.map +1 -0
  59. package/dist/sync/sync-conflict-basic-divergence.withid.respec.mjs +274 -0
  60. package/dist/sync/sync-conflict-basic-divergence.withid.respec.mjs.map +1 -0
  61. package/dist/sync/sync-conflict-basic-multitimelines.withid.respec.d.mts +8 -0
  62. package/dist/sync/sync-conflict-basic-multitimelines.withid.respec.d.mts.map +1 -0
  63. package/dist/sync/sync-conflict-basic-multitimelines.withid.respec.mjs +322 -0
  64. package/dist/sync/sync-conflict-basic-multitimelines.withid.respec.mjs.map +1 -0
  65. package/dist/sync/sync-conflict-text-merge.withid.respec.d.mts +7 -0
  66. package/dist/sync/sync-conflict-text-merge.withid.respec.d.mts.map +1 -0
  67. package/dist/sync/sync-conflict-text-merge.withid.respec.mjs +307 -0
  68. package/dist/sync/sync-conflict-text-merge.withid.respec.mjs.map +1 -0
  69. package/dist/sync/sync-innerspace-constants.withid.respec.d.mts +8 -0
  70. package/dist/sync/sync-innerspace-constants.withid.respec.d.mts.map +1 -0
  71. package/dist/sync/sync-innerspace-constants.withid.respec.mjs +233 -0
  72. package/dist/sync/sync-innerspace-constants.withid.respec.mjs.map +1 -0
  73. package/dist/sync/sync-innerspace-deep-updates.withid.respec.d.mts +7 -0
  74. package/dist/sync/sync-innerspace-deep-updates.withid.respec.d.mts.map +1 -0
  75. package/dist/sync/sync-innerspace-deep-updates.withid.respec.mjs +233 -0
  76. package/dist/sync/sync-innerspace-deep-updates.withid.respec.mjs.map +1 -0
  77. package/dist/sync/sync-innerspace-dest-ahead.withid.respec.d.mts +7 -0
  78. package/dist/sync/sync-innerspace-dest-ahead.withid.respec.d.mts.map +1 -0
  79. package/dist/sync/sync-innerspace-dest-ahead.withid.respec.mjs +225 -0
  80. package/dist/sync/sync-innerspace-dest-ahead.withid.respec.mjs.map +1 -0
  81. package/dist/sync/sync-innerspace-multiple-timelines.respec.mjs.map +1 -1
  82. package/dist/sync/sync-innerspace-multiple-timelines.withid.respec.d.mts +7 -0
  83. package/dist/sync/sync-innerspace-multiple-timelines.withid.respec.d.mts.map +1 -0
  84. package/dist/sync/sync-innerspace-multiple-timelines.withid.respec.mjs +235 -0
  85. package/dist/sync/sync-innerspace-multiple-timelines.withid.respec.mjs.map +1 -0
  86. package/dist/sync/sync-innerspace-partial-update.withid.respec.d.mts +7 -0
  87. package/dist/sync/sync-innerspace-partial-update.withid.respec.d.mts.map +1 -0
  88. package/dist/sync/sync-innerspace-partial-update.withid.respec.mjs +211 -0
  89. package/dist/sync/sync-innerspace-partial-update.withid.respec.mjs.map +1 -0
  90. package/dist/sync/sync-innerspace.withid.respec.d.mts +8 -0
  91. package/dist/sync/sync-innerspace.withid.respec.d.mts.map +1 -0
  92. package/dist/sync/sync-innerspace.withid.respec.mjs +260 -0
  93. package/dist/sync/sync-innerspace.withid.respec.mjs.map +1 -0
  94. package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-peer-websocket-receiver-v1.d.mts +1 -0
  95. package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-peer-websocket-receiver-v1.d.mts.map +1 -1
  96. package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-peer-websocket-receiver-v1.mjs +13 -4
  97. package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-peer-websocket-receiver-v1.mjs.map +1 -1
  98. package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-websocket-peer-helpers.d.mts +1 -1
  99. package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-websocket-peer-helpers.d.mts.map +1 -1
  100. package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-websocket-peer-helpers.mjs +5 -3
  101. package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-websocket-peer-helpers.mjs.map +1 -1
  102. package/dist/sync/sync-saga-coordinator.d.mts.map +1 -1
  103. package/dist/sync/sync-saga-coordinator.mjs +165 -145
  104. package/dist/sync/sync-saga-coordinator.mjs.map +1 -1
  105. package/dist/sync/sync-withid.pingpong.respec.mjs +8 -8
  106. package/dist/sync/sync-withid.pingpong.respec.mjs.map +1 -1
  107. package/dist/timeline/timeline-api.d.mts.map +1 -1
  108. package/dist/timeline/timeline-api.mjs +1 -14
  109. package/dist/timeline/timeline-api.mjs.map +1 -1
  110. package/dist/witness/space/reconciliation-space/reconciliation-space-base.d.mts.map +1 -1
  111. package/dist/witness/space/reconciliation-space/reconciliation-space-base.mjs +0 -40
  112. package/dist/witness/space/reconciliation-space/reconciliation-space-base.mjs.map +1 -1
  113. package/dist/witness/space/reconciliation-space/reconciliation-space-helper.d.mts.map +1 -1
  114. package/dist/witness/space/reconciliation-space/reconciliation-space-helper.mjs +6 -6
  115. package/dist/witness/space/reconciliation-space/reconciliation-space-helper.mjs.map +1 -1
  116. package/ibgib-foundations.md +2 -1
  117. package/package.json +1 -1
  118. package/src/common/other/graph-helper.mts +7 -6
  119. package/src/keystone/README.md +19 -15
  120. package/src/keystone/docs/CRYPTANALYSIS.md +185 -0
  121. package/src/keystone/docs/architecture.md +24 -1
  122. package/src/keystone/docs/profiles.md +124 -0
  123. package/src/keystone/keystone-config-builder.mts +3 -21
  124. package/src/keystone/keystone-constants.mts +2 -0
  125. package/src/keystone/keystone-helpers.mts +74 -77
  126. package/src/keystone/keystone-policy-types.mts +6 -4
  127. package/src/keystone/keystone-service-v1.mts +4 -9
  128. package/src/keystone/keystone-service-v1.respec.mts +214 -32
  129. package/src/keystone/keystone-types.mts +5 -9
  130. package/src/keystone/policy/IMPLEMENTATION.md +60 -0
  131. package/src/keystone/policy/README.md +94 -0
  132. package/src/keystone/policy/keystone-profile-builder.mts +131 -0
  133. package/src/keystone/policy/profiles/profile-high.json +84 -0
  134. package/src/keystone/policy/profiles/profile-low.json +84 -0
  135. package/src/keystone/policy/profiles/profile-medium.json +84 -0
  136. package/src/keystone/policy/profiles/profile-session.json +84 -0
  137. package/src/keystone/policy/profiles/profile-test.json +84 -0
  138. package/src/keystone/policy/schemas/connect-pool.high.schema.json +23 -0
  139. package/src/keystone/policy/schemas/connect-pool.low.schema.json +23 -0
  140. package/src/keystone/policy/schemas/connect-pool.medium.schema.json +23 -0
  141. package/src/keystone/policy/schemas/keystone.high.schema.json +26 -0
  142. package/src/keystone/policy/schemas/keystone.low.schema.json +26 -0
  143. package/src/keystone/policy/schemas/keystone.medium.schema.json +26 -0
  144. package/src/keystone/policy/schemas/manage-pool.high.schema.json +23 -0
  145. package/src/keystone/policy/schemas/manage-pool.low.schema.json +23 -0
  146. package/src/keystone/policy/schemas/manage-pool.medium.schema.json +23 -0
  147. package/src/keystone/policy/schemas/revoke-pool.high.schema.json +23 -0
  148. package/src/keystone/policy/schemas/revoke-pool.low.schema.json +23 -0
  149. package/src/keystone/policy/schemas/revoke-pool.medium.schema.json +23 -0
  150. package/src/keystone/policy/schemas/sign-pool.high.schema.json +23 -0
  151. package/src/keystone/policy/schemas/sign-pool.low.schema.json +23 -0
  152. package/src/keystone/policy/schemas/sign-pool.medium.schema.json +23 -0
  153. package/src/keystone/policy/schemas/sync-pool.high.schema.json +23 -0
  154. package/src/keystone/policy/schemas/sync-pool.low.schema.json +23 -0
  155. package/src/keystone/policy/schemas/sync-pool.medium.schema.json +23 -0
  156. package/src/sync/docs/security.md +54 -21
  157. package/src/sync/sync-conflict-adv-multitimelines.withid.respec.mts +706 -0
  158. package/src/sync/sync-conflict-basic-divergence.withid.respec.mts +321 -0
  159. package/src/sync/sync-conflict-basic-multitimelines.withid.respec.mts +374 -0
  160. package/src/sync/sync-conflict-text-merge.withid.respec.mts +347 -0
  161. package/src/sync/sync-innerspace-constants.withid.respec.mts +264 -0
  162. package/src/sync/sync-innerspace-deep-updates.withid.respec.mts +272 -0
  163. package/src/sync/sync-innerspace-dest-ahead.withid.respec.mts +266 -0
  164. package/src/sync/sync-innerspace-multiple-timelines.respec.mts +0 -1
  165. package/src/sync/sync-innerspace-multiple-timelines.withid.respec.mts +273 -0
  166. package/src/sync/sync-innerspace-partial-update.withid.respec.mts +249 -0
  167. package/src/sync/sync-innerspace.withid.respec.mts +265 -0
  168. package/src/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-peer-websocket-receiver-v1.mts +12 -4
  169. package/src/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-websocket-peer-helpers.mts +5 -3
  170. package/src/sync/sync-saga-coordinator.mts +159 -143
  171. package/src/sync/sync-withid.pingpong.respec.mts +8 -8
  172. package/src/timeline/timeline-api.mts +1 -15
  173. package/src/timeline/timeline-api.respec.mts +3 -3
  174. package/src/witness/space/reconciliation-space/reconciliation-space-base.mts +0 -46
  175. package/src/witness/space/reconciliation-space/reconciliation-space-helper.mts +6 -5
  176. package/tsconfig.json +6 -1
  177. package/src/keystone/keystone-policy.schema.json +0 -51
  178. package/src/witness/space/reconciliation-space/reconciliation-space-base.mts.OLD.md +0 -884
  179. package/src/witness/space/reconciliation-space/reconciliation-space-helper.mts.OLD.md +0 -125
@@ -0,0 +1,272 @@
1
+ /**
2
+ * @module sync-innerspace-deep-updates.withid.respec
3
+ *
4
+ * Verifies syncing timelines with deep mutation histories (multiple updates) with Identity.
5
+ */
6
+
7
+ import {
8
+ respecfully, respecfullyDear, iReckon, ifWe, ifWeMight
9
+ } from '@ibgib/helper-gib/dist/respec-gib/respec-gib.mjs';
10
+ const maam = `[${import.meta.url}]`, sir = maam;
11
+ import { clone, delay } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
12
+ import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs';
13
+
14
+ import { GLOBAL_LOG_A_LOT } from '../core-constants.mjs';
15
+ import { SyncSagaCoordinator } from './sync-saga-coordinator.mjs';
16
+ import { getFromSpace } from '../witness/space/space-helper.mjs';
17
+ import { Metaspace_Innerspace } from '../witness/space/metaspace/metaspace-innerspace/metaspace-innerspace.mjs';
18
+ import { InnerSpace_V1 } from '../witness/space/inner-space/inner-space-v1.mjs';
19
+ import { createTimelineRootTestHelper } from '../test-helpers.mjs';
20
+ import { mut8Timeline } from '../timeline/timeline-api.mjs';
21
+ import { DEFAULT_INNER_SPACE_DATA_V1 } from '../witness/space/inner-space/inner-space-types.mjs';
22
+ import { SyncPeerInnerspace_V1 } from './sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs';
23
+ import { SYNC_PEER_INNERSPACE_DEFAULT_DATA_V1 } from './sync-peer/sync-peer-innerspace/sync-peer-innerspace-constants.mjs';
24
+ import { getDependencyGraph, graphsAreEquivalent } from '../common/other/graph-helper.mjs';
25
+
26
+ import { KeystoneService_V1 } from '../keystone/keystone-service-v1.mjs';
27
+ import {
28
+ KEYSTONE_VERB_SYNC, POOL_ID_SYNC,
29
+ } from '../keystone/keystone-constants.mjs';
30
+ import { createStandardPoolConfig } from '../keystone/keystone-config-builder.mjs';
31
+ import { KeystoneReplenishStrategy, KeystoneIbGib_V1 } from '../keystone/keystone-types.mjs';
32
+
33
+ const logalot = GLOBAL_LOG_A_LOT || true;
34
+ const lc = `[sync-innerspace-deep-updates.withid.respec]`;
35
+
36
+ const SENDER_SECRET = 'test-sender-secret-deep-updates-withid';
37
+
38
+ const SENDER_IDENTITY_SYNC_POOL_CONFIG = createStandardPoolConfig({
39
+ id: POOL_ID_SYNC,
40
+ salt: 'senderidentitysyncsaltdeepupdateswithid',
41
+ verbs: [KEYSTONE_VERB_SYNC],
42
+ size: 200,
43
+ sequential: 1,
44
+ random: 1,
45
+ targetBinding: 2,
46
+ replenishStrategy: KeystoneReplenishStrategy.topUp,
47
+ });
48
+
49
+ await respecfully(sir, `Sync InnerSpaces (Deep Updates) with Identity`, async () => {
50
+
51
+ let metaspace: Metaspace_Innerspace;
52
+ let sourceSpace: InnerSpace_V1;
53
+ let destSpace: InnerSpace_V1;
54
+
55
+ interface TestData {
56
+ type: string;
57
+ label?: string;
58
+ uuid?: string;
59
+ n?: number;
60
+ }
61
+
62
+ // #region Round 1 - Deep Updates Push Sync
63
+ await respecfully(sir, `Deep Updates (Push Source -> Dest with Identity)`, async () => {
64
+ // 1. Setup Spaces
65
+ metaspace = new Metaspace_Innerspace(undefined);
66
+ await metaspace.initialize({
67
+ getFnAlert: () => async ({ title, msg }) => { console.log(`[Alert] ${title}: ${msg}`); },
68
+ getFnPrompt: () => async ({ title, msg }) => { console.log(`[Prompt] ${title}: ${msg}`); return ''; },
69
+ getFnPromptPassword: () => async (title, msg) => { console.log(`[PromptPwd] ${title}: ${msg}`); return null; },
70
+ });
71
+ while (!metaspace.initialized) { await delay(10); }
72
+
73
+ sourceSpace = new InnerSpace_V1({
74
+ ...DEFAULT_INNER_SPACE_DATA_V1,
75
+ name: 'source',
76
+ uuid: 'source_uuid',
77
+ description: 'source test space',
78
+ });
79
+ await sourceSpace.initialized;
80
+
81
+ destSpace = new InnerSpace_V1({
82
+ ...DEFAULT_INNER_SPACE_DATA_V1,
83
+ name: 'dest',
84
+ uuid: 'dest_uuid',
85
+ description: 'dest test space',
86
+ });
87
+ await destSpace.initialized;
88
+
89
+ // 2. Setup Identities
90
+ const keystoneSvc = new KeystoneService_V1();
91
+ const r1_senderIdentity_v0_source = await keystoneSvc.genesis({
92
+ masterSecret: SENDER_SECRET,
93
+ configs: [SENDER_IDENTITY_SYNC_POOL_CONFIG],
94
+ metaspace,
95
+ space: sourceSpace,
96
+ });
97
+
98
+ // Register sender identity on destination space as well
99
+ await metaspace.put({ ibGib: r1_senderIdentity_v0_source, space: destSpace });
100
+ await metaspace.registerNewIbGib({ ibGib: r1_senderIdentity_v0_source, space: destSpace });
101
+
102
+ // #region r1 setup
103
+ // 3. Seed Source Data (Deep History)
104
+ console.log(`${lc} Creating deep data in Source...`);
105
+
106
+ // Root (V0)
107
+ const r1_alpha_v0_source = await createTimelineRootTestHelper<TestData>({
108
+ ib: 'timeline_root_deep',
109
+ data: { type: 'root', label: 'Root' },
110
+ space: sourceSpace,
111
+ });
112
+
113
+ // Comment (V1)
114
+ const r1_alpha_v1_source = await mut8Timeline<TestData>({
115
+ timeline: r1_alpha_v0_source,
116
+ mut8Opts: { dataToAddOrPatch: { type: 'comment', label: 'Hello World' } },
117
+ metaspace,
118
+ space: sourceSpace,
119
+ });
120
+
121
+ // Edit Comment (V2)
122
+ const r1_alpha_v2_source = await mut8Timeline<TestData>({
123
+ timeline: r1_alpha_v1_source,
124
+ mut8Opts: { dataToAddOrPatch: { type: 'comment', label: 'Hello Sync' } },
125
+ metaspace,
126
+ space: sourceSpace,
127
+ });
128
+ const r1_alpha_v2_source_addr = getIbGibAddr({ ibGib: r1_alpha_v2_source });
129
+ // #endregion r1 setup
130
+
131
+ // #region r1 verify pre
132
+ await respecfully(sir, `r1 verify pre`, async () => {
133
+ await ifWe(sir, `Dest does not have any of the alpha frames initially`, async () => {
134
+ const getV2 = await getFromSpace({ space: destSpace, addr: r1_alpha_v2_source_addr });
135
+ const getV1 = await getFromSpace({ space: destSpace, addr: getIbGibAddr({ ibGib: r1_alpha_v1_source }) });
136
+ const getV0 = await getFromSpace({ space: destSpace, addr: getIbGibAddr({ ibGib: r1_alpha_v0_source }) });
137
+ iReckon(sir, getV2.success || getV1.success || getV0.success).asTo('Dest initially lacks alpha frames').isGonnaBeFalse();
138
+ });
139
+ });
140
+ // #endregion r1 verify pre
141
+
142
+ // 4. Setup Coordinator & Peer
143
+ const senderCoordinator = new SyncSagaCoordinator();
144
+ const receiverCoordinator = new SyncSagaCoordinator();
145
+
146
+ const peer = new SyncPeerInnerspace_V1(clone(SYNC_PEER_INNERSPACE_DEFAULT_DATA_V1));
147
+ await peer.initialized;
148
+ await peer.initializeOpts({
149
+ sagaId: '',
150
+ localMetaspace: metaspace,
151
+ localSpace: sourceSpace, // "Client"
152
+ receiverSpace: destSpace, // "Server"
153
+ receiverCoordinator,
154
+ receiverMetaspace: metaspace,
155
+ });
156
+
157
+ // #region r1 syncs
158
+ // 5. Run Sync (Sync the Tip V2)
159
+ console.log(`${lc} Running Sync...`);
160
+ const resSync = await senderCoordinator.sync({
161
+ peer: peer,
162
+ localSpace: sourceSpace,
163
+ metaspace: metaspace,
164
+ domainIbGibs: [r1_alpha_v2_source],
165
+ senderIdentity: r1_senderIdentity_v0_source,
166
+ fnSenderSecret: async () => SENDER_SECRET,
167
+ });
168
+ await resSync.done;
169
+ // #endregion r1 syncs
170
+
171
+ // #region r1 verify post
172
+ await respecfully(sir, `r1 verify post`, async () => {
173
+ await ifWe(sir, `verify deep timeline present and correct in Dest`, async () => {
174
+ // Verify Tip (V2)
175
+ const getV2 = await getFromSpace({ space: destSpace, addr: r1_alpha_v2_source_addr });
176
+ iReckon(sir, getV2.success).asTo('Tip V2 present').isGonnaBeTrue();
177
+ const v2IbGib = getV2.ibGibs![0];
178
+ iReckon(sir, v2IbGib.data!.label).asTo('Label V2 match').isGonnaBe('Hello Sync');
179
+
180
+ // Verify Past Frame (V1)
181
+ const pastAddr = v2IbGib.rel8ns?.past?.at(-1);
182
+ iReckon(sir, !!pastAddr).asTo('Past address in V2 rel8ns is truthy').isGonnaBeTrue();
183
+ if (pastAddr) {
184
+ const getV1 = await getFromSpace({ space: destSpace, addr: pastAddr });
185
+ iReckon(sir, getV1.success).asTo('Past Frame (V1) present').isGonnaBeTrue();
186
+ iReckon(sir, getV1.ibGibs?.[0]?.data?.label).asTo('Label V1 match').isGonnaBe('Hello World');
187
+ }
188
+
189
+ // Verify Full Graph Integrity
190
+ const graph = await getDependencyGraph({ ibGib: v2IbGib, space: destSpace });
191
+ iReckon(sir, !!graph).asTo('Dependency Graph resolvable in Dest').isGonnaBeTrue();
192
+ if (graph) {
193
+ iReckon(sir, Object.keys(graph).length >= 3).asTo('Graph size >= 3').isGonnaBeTrue();
194
+ }
195
+ });
196
+
197
+ await ifWe(sir, 'sessionIdentity evolved the expected number of times', async () => {
198
+ const latestS = peer.currentSessionIdentity;
199
+ iReckon(sir, latestS).asTo('latest session identity exists on peer').isGonnaBeTruthy();
200
+ if (latestS) {
201
+ iReckon(sir, latestS.data?.n).asTo('session identity data.n').isGonnaBe(2);
202
+ }
203
+ });
204
+
205
+ await ifWe(sir, 'sender durable space has I (evolved frame)', async () => {
206
+ const latestSenderIdentityAddr = await metaspace.getLatestAddr({
207
+ addr: getIbGibAddr({ ibGib: r1_senderIdentity_v0_source }),
208
+ space: sourceSpace,
209
+ });
210
+ iReckon(sir, latestSenderIdentityAddr).asTo('latestSenderIdentityAddr exists').isGonnaBeTruthy();
211
+ if (latestSenderIdentityAddr) {
212
+ const resGetSourceI = await getFromSpace({ space: sourceSpace, addr: latestSenderIdentityAddr });
213
+ iReckon(sir, resGetSourceI.success && resGetSourceI.ibGibs?.length === 1).asTo('evolved I exists in sourceSpace').isGonnaBeTrue();
214
+ if (resGetSourceI.success && resGetSourceI.ibGibs?.[0]) {
215
+ const evolvedI = resGetSourceI.ibGibs[0];
216
+ iReckon(sir, evolvedI.data?.n).asTo('evolved I data.n').isGonnaBe(1);
217
+ }
218
+ }
219
+ });
220
+
221
+ await ifWe(sir, 'receiver durable space has I (evolved frame)', async () => {
222
+ const latestSenderIdentityAddr = await metaspace.getLatestAddr({
223
+ addr: getIbGibAddr({ ibGib: r1_senderIdentity_v0_source }),
224
+ space: sourceSpace,
225
+ });
226
+ iReckon(sir, latestSenderIdentityAddr).asTo('latestSenderIdentityAddr exists').isGonnaBeTruthy();
227
+ if (latestSenderIdentityAddr) {
228
+ const resGetDestI = await getFromSpace({ space: destSpace, addr: latestSenderIdentityAddr });
229
+ iReckon(sir, resGetDestI.success && resGetDestI.ibGibs?.length === 1).asTo('evolved I exists in destSpace').isGonnaBeTrue();
230
+ if (resGetDestI.success && resGetDestI.ibGibs?.[0]) {
231
+ const evolvedI = resGetDestI.ibGibs[0];
232
+ iReckon(sir, evolvedI.data?.n).asTo('evolved I data.n').isGonnaBe(1);
233
+ }
234
+ }
235
+ });
236
+
237
+ await ifWe(sir, 'sender durable space has full S dep graph', async () => {
238
+ const latestS = peer.currentSessionIdentity;
239
+ iReckon(sir, latestS).asTo('latestS exists').isGonnaBeTruthy();
240
+ if (latestS) {
241
+ const depGraphS = await getDependencyGraph({ ibGib: latestS, space: sourceSpace });
242
+ const addrs = Object.keys(depGraphS);
243
+ iReckon(sir, addrs.length > 2).asTo('number of nodes in S graph > 2').isGonnaBeTrue();
244
+ }
245
+ });
246
+
247
+ await ifWe(sir, 'receiver durable space has full S dep graph', async () => {
248
+ const latestS = peer.currentSessionIdentity;
249
+ iReckon(sir, latestS).asTo('latestS exists').isGonnaBeTruthy();
250
+ if (latestS) {
251
+ const depGraphS = await getDependencyGraph({ ibGib: latestS, space: destSpace });
252
+ const addrs = Object.keys(depGraphS);
253
+ iReckon(sir, addrs.length > 2).asTo('number of nodes in S graph in destSpace > 2').isGonnaBeTrue();
254
+ }
255
+ });
256
+
257
+ await ifWe(sir, 'session keystone dependency graphs are equivalent on source and dest', async () => {
258
+ const latestS = peer.currentSessionIdentity;
259
+ iReckon(sir, latestS).asTo('latestS exists').isGonnaBeTruthy();
260
+ if (latestS) {
261
+ const depGraphSource = await getDependencyGraph({ ibGib: latestS, space: sourceSpace });
262
+ const depGraphDest = await getDependencyGraph({ ibGib: latestS, space: destSpace });
263
+ const equal = graphsAreEquivalent({ graphA: depGraphSource, graphB: depGraphDest });
264
+ iReckon(sir, equal).asTo('session graphs are equivalent').isGonnaBeTrue();
265
+ }
266
+ });
267
+ });
268
+ // #endregion r1 verify post
269
+ });
270
+ // #endregion Round 1 - Deep Updates Push Sync
271
+
272
+ });
@@ -0,0 +1,266 @@
1
+ /**
2
+ * @module sync-innerspace-dest-ahead.withid.respec
3
+ *
4
+ * Verifies Destination Ahead (Remote Newer) Sync Scenario using InnerSpace with Identity.
5
+ */
6
+
7
+ import {
8
+ respecfully, respecfullyDear, iReckon, ifWe,
9
+ ifWeMight
10
+ } from '@ibgib/helper-gib/dist/respec-gib/respec-gib.mjs';
11
+ const maam = `[${import.meta.url}]`, sir = maam;
12
+ import { clone, delay } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
13
+ import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs';
14
+
15
+ import { GLOBAL_LOG_A_LOT } from '../core-constants.mjs';
16
+ import { SyncSagaCoordinator } from './sync-saga-coordinator.mjs';
17
+ import { getFromSpace, putInSpace, registerNewIbGib } 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 { createTimelineRootTestHelper } from '../test-helpers.mjs';
21
+ import { mut8Timeline } from '../timeline/timeline-api.mjs';
22
+ import { DEFAULT_INNER_SPACE_DATA_V1 } from '../witness/space/inner-space/inner-space-types.mjs';
23
+ import { SyncPeerInnerspace_V1 } from './sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs';
24
+ import { SYNC_PEER_INNERSPACE_DEFAULT_DATA_V1 } from './sync-peer/sync-peer-innerspace/sync-peer-innerspace-constants.mjs';
25
+ import { getDependencyGraph, graphsAreEquivalent } from '../common/other/graph-helper.mjs';
26
+
27
+ import { KeystoneService_V1 } from '../keystone/keystone-service-v1.mjs';
28
+ import {
29
+ KEYSTONE_VERB_SYNC, POOL_ID_SYNC,
30
+ } from '../keystone/keystone-constants.mjs';
31
+ import { createStandardPoolConfig } from '../keystone/keystone-config-builder.mjs';
32
+ import { KeystoneReplenishStrategy } from '../keystone/keystone-types.mjs';
33
+
34
+ const logalot = GLOBAL_LOG_A_LOT || true;
35
+ const lc = `[sync-innerspace-dest-ahead.withid.respec]`;
36
+
37
+ const SENDER_SECRET = 'test-sender-secret-dest-ahead-withid';
38
+
39
+ const SENDER_IDENTITY_SYNC_POOL_CONFIG = createStandardPoolConfig({
40
+ id: POOL_ID_SYNC,
41
+ salt: 'senderidentitysyncsaltdestaheadwithid',
42
+ verbs: [KEYSTONE_VERB_SYNC],
43
+ size: 200,
44
+ sequential: 1,
45
+ random: 1,
46
+ targetBinding: 2,
47
+ replenishStrategy: KeystoneReplenishStrategy.topUp,
48
+ });
49
+
50
+ await respecfully(sir, `Sync InnerSpaces (Dest Ahead) with Identity`, async () => {
51
+
52
+ let metaspace: Metaspace_Innerspace;
53
+ let sourceSpace: InnerSpace_V1;
54
+ let destSpace: InnerSpace_V1;
55
+
56
+ interface TestData {
57
+ type: string;
58
+ label?: string;
59
+ uuid?: string;
60
+ n?: number;
61
+ }
62
+
63
+ // #region Round 1 - Dest Ahead Sync with Identity
64
+ await respecfully(sir, `Dest Ahead (Remote Newer with Identity)`, async () => {
65
+ // 1. Setup Spaces
66
+ metaspace = new Metaspace_Innerspace(undefined);
67
+ await metaspace.initialize({
68
+ getFnAlert: () => async ({ title, msg }) => { console.log(`[Alert] ${title}: ${msg}`); },
69
+ getFnPrompt: () => async ({ title, msg }) => { console.log(`[Prompt] ${title}: ${msg}`); return ''; },
70
+ getFnPromptPassword: () => async (title, msg) => { console.log(`[PromptPwd] ${title}: ${msg}`); return null; },
71
+ });
72
+ while (!metaspace.initialized) { await delay(10); }
73
+
74
+ sourceSpace = new InnerSpace_V1({
75
+ ...DEFAULT_INNER_SPACE_DATA_V1,
76
+ name: 'source',
77
+ uuid: 'source_uuid',
78
+ description: 'source test space',
79
+ });
80
+ await sourceSpace.initialized;
81
+
82
+ destSpace = new InnerSpace_V1({
83
+ ...DEFAULT_INNER_SPACE_DATA_V1,
84
+ name: 'dest',
85
+ uuid: 'dest_uuid',
86
+ description: 'dest test space',
87
+ });
88
+ await destSpace.initialized;
89
+
90
+ // 2. Setup Identities
91
+ const keystoneSvc = new KeystoneService_V1();
92
+ const r1_senderIdentity_v0_source = await keystoneSvc.genesis({
93
+ masterSecret: SENDER_SECRET,
94
+ configs: [SENDER_IDENTITY_SYNC_POOL_CONFIG],
95
+ metaspace,
96
+ space: sourceSpace,
97
+ });
98
+
99
+ // Register sender identity on destination space as well
100
+ await metaspace.put({ ibGib: r1_senderIdentity_v0_source, space: destSpace });
101
+ await metaspace.registerNewIbGib({ ibGib: r1_senderIdentity_v0_source, space: destSpace });
102
+
103
+ // #region r1 setup
104
+ // 3. Seed Data (Dest Ahead)
105
+ // Root -> V1 (Shared) -> V2 (Dest has New)
106
+ // Source only has V1.
107
+ console.log(`${lc} Seeding data for Dest Ahead scenario...`);
108
+
109
+ // Root (V0)
110
+ const r1_alpha_v0_source = await createTimelineRootTestHelper<TestData>({
111
+ ib: 'timeline_root_dest_ahead',
112
+ data: { type: 'root', label: 'Root' },
113
+ space: sourceSpace,
114
+ });
115
+ const r1_alpha_v0_source_addr = getIbGibAddr({ ibGib: r1_alpha_v0_source });
116
+
117
+ // V1 (Both have it, but we create in source and copy to dest)
118
+ const r1_alpha_v1_source = await mut8Timeline<TestData>({
119
+ timeline: r1_alpha_v0_source,
120
+ mut8Opts: { dataToAddOrPatch: { type: 'comment', label: 'V1' } },
121
+ metaspace,
122
+ space: sourceSpace,
123
+ });
124
+ const r1_alpha_v1_source_addr = getIbGibAddr({ ibGib: r1_alpha_v1_source });
125
+
126
+ // Transfer Root & V1 to Dest
127
+ const initialDepGraph = await getDependencyGraph({ ibGibs: [r1_alpha_v0_source, r1_alpha_v1_source], space: sourceSpace });
128
+ await putInSpace({ space: destSpace, ibGibs: Object.values(initialDepGraph) });
129
+ await registerNewIbGib({ space: destSpace, ibGib: r1_alpha_v0_source });
130
+ await registerNewIbGib({ space: destSpace, ibGib: r1_alpha_v1_source });
131
+
132
+ // V2 (Created in Dest ONLY)
133
+ const r1_alpha_v2_dest_newer = await mut8Timeline<TestData>({
134
+ timeline: r1_alpha_v1_source,
135
+ mut8Opts: { dataToAddOrPatch: { type: 'comment', label: 'V2' } },
136
+ metaspace,
137
+ space: destSpace, // Mutate in Dest
138
+ });
139
+ const r1_alpha_v2_dest_newer_addr = getIbGibAddr({ ibGib: r1_alpha_v2_dest_newer });
140
+ // #endregion r1 setup
141
+
142
+ // #region r1 verify pre
143
+ await respecfully(sir, `r1 verify pre`, async () => {
144
+ await ifWe(sir, `verify setup state matches expectations`, async () => {
145
+ const sourceHasV0 = await getFromSpace({ space: sourceSpace, addr: r1_alpha_v0_source_addr });
146
+ const sourceHasV1 = await getFromSpace({ space: sourceSpace, addr: r1_alpha_v1_source_addr });
147
+ const sourceHasV2 = await getFromSpace({ space: sourceSpace, addr: r1_alpha_v2_dest_newer_addr });
148
+
149
+ const destHasV0 = await getFromSpace({ space: destSpace, addr: r1_alpha_v0_source_addr });
150
+ const destHasV1 = await getFromSpace({ space: destSpace, addr: r1_alpha_v1_source_addr });
151
+ const destHasV2 = await getFromSpace({ space: destSpace, addr: r1_alpha_v2_dest_newer_addr });
152
+
153
+ iReckon(sir, sourceHasV0.success).asTo('source has V0').isGonnaBeTrue();
154
+ iReckon(sir, sourceHasV1.success).asTo('source has V1').isGonnaBeTrue();
155
+ iReckon(sir, sourceHasV2.success).asTo('source does NOT have V2').isGonnaBeFalse();
156
+
157
+ iReckon(sir, destHasV0.success).asTo('dest has V0').isGonnaBeTrue();
158
+ iReckon(sir, destHasV1.success).asTo('dest has V1').isGonnaBeTrue();
159
+ iReckon(sir, destHasV2.success).asTo('dest has V2').isGonnaBeTrue();
160
+ });
161
+ });
162
+ // #endregion r1 verify pre
163
+
164
+ // 4. Setup Coordinator & Peer
165
+ const senderCoordinator = new SyncSagaCoordinator();
166
+ const receiverCoordinator = new SyncSagaCoordinator();
167
+
168
+ const peer = new SyncPeerInnerspace_V1(clone(SYNC_PEER_INNERSPACE_DEFAULT_DATA_V1));
169
+ await peer.initialized;
170
+ await peer.initializeOpts({
171
+ sagaId: '',
172
+ localMetaspace: metaspace,
173
+ localSpace: sourceSpace, // "Client"
174
+ receiverSpace: destSpace, // "Server"
175
+ receiverCoordinator,
176
+ receiverMetaspace: metaspace,
177
+ });
178
+
179
+ // #region r1 syncs
180
+ // 5. Run Sync (Source Pushes V1, but Remote is Ahead with V2)
181
+ console.log(`${lc} Running Sync...`);
182
+ const resSync = await senderCoordinator.sync({
183
+ peer: peer,
184
+ localSpace: sourceSpace,
185
+ metaspace: metaspace,
186
+ domainIbGibs: [r1_alpha_v1_source],
187
+ senderIdentity: r1_senderIdentity_v0_source,
188
+ fnSenderSecret: async () => SENDER_SECRET,
189
+ });
190
+ await resSync.done;
191
+ // #endregion r1 syncs
192
+
193
+ // #region r1 verify post
194
+ await respecfully(sir, `r1 verify post`, async () => {
195
+ await ifWe(sir, `verify V2 and its history are now present on Source`, async () => {
196
+ const sourceHasV2 = await getFromSpace({ space: sourceSpace, addr: r1_alpha_v2_dest_newer_addr });
197
+ iReckon(sir, sourceHasV2.success).asTo('Source now has V2').isGonnaBeTrue();
198
+ if (sourceHasV2.success && sourceHasV2.ibGibs?.[0]) {
199
+ const v2IbGib = sourceHasV2.ibGibs[0];
200
+ iReckon(sir, v2IbGib.data?.label).asTo('V2 label matches').isGonnaBe('V2');
201
+ }
202
+
203
+ // Verify V2 dependency graph equivalence
204
+ const sourceV2Graph = await getDependencyGraph({ ibGibAddr: r1_alpha_v2_dest_newer_addr, space: sourceSpace });
205
+ const destV2Graph = await getDependencyGraph({ ibGibAddr: r1_alpha_v2_dest_newer_addr, space: destSpace });
206
+ const graphsEqual = graphsAreEquivalent({ graphA: sourceV2Graph, graphB: destV2Graph });
207
+ iReckon(sir, graphsEqual).asTo('V2 dependency graphs are identical on source and dest').isGonnaBeTrue();
208
+ });
209
+
210
+ await ifWe(sir, 'sessionIdentity evolved the expected number of times', async () => {
211
+ const latestS = peer.currentSessionIdentity;
212
+ iReckon(sir, latestS).asTo('latest session identity exists on peer').isGonnaBeTruthy();
213
+ if (latestS) {
214
+ // Connect handshake is no-op, init request = n=1, commit request = n=2
215
+ iReckon(sir, latestS.data?.n).asTo('session identity data.n').isGonnaBe(2);
216
+ }
217
+ });
218
+
219
+ await ifWe(sir, 'sender durable space has I (evolved frame)', async () => {
220
+ const latestSenderIdentityAddr = await metaspace.getLatestAddr({
221
+ addr: getIbGibAddr({ ibGib: r1_senderIdentity_v0_source }),
222
+ space: sourceSpace,
223
+ });
224
+ iReckon(sir, latestSenderIdentityAddr).asTo('latestSenderIdentityAddr exists').isGonnaBeTruthy();
225
+ if (latestSenderIdentityAddr) {
226
+ const resGetSourceI = await getFromSpace({ space: sourceSpace, addr: latestSenderIdentityAddr });
227
+ iReckon(sir, resGetSourceI.success && resGetSourceI.ibGibs?.length === 1).asTo('evolved I exists in sourceSpace').isGonnaBeTrue();
228
+ if (resGetSourceI.success && resGetSourceI.ibGibs?.[0]) {
229
+ const evolvedI = resGetSourceI.ibGibs[0];
230
+ iReckon(sir, evolvedI.data?.n).asTo('evolved I data.n').isGonnaBe(1);
231
+ }
232
+ }
233
+ });
234
+
235
+ await ifWe(sir, 'receiver durable space has I (evolved frame)', async () => {
236
+ const latestSenderIdentityAddr = await metaspace.getLatestAddr({
237
+ addr: getIbGibAddr({ ibGib: r1_senderIdentity_v0_source }),
238
+ space: sourceSpace,
239
+ });
240
+ iReckon(sir, latestSenderIdentityAddr).asTo('latestSenderIdentityAddr exists').isGonnaBeTruthy();
241
+ if (latestSenderIdentityAddr) {
242
+ const resGetDestI = await getFromSpace({ space: destSpace, addr: latestSenderIdentityAddr });
243
+ iReckon(sir, resGetDestI.success && resGetDestI.ibGibs?.length === 1).asTo('evolved I exists in destSpace').isGonnaBeTrue();
244
+ if (resGetDestI.success && resGetDestI.ibGibs?.[0]) {
245
+ const evolvedI = resGetDestI.ibGibs[0];
246
+ iReckon(sir, evolvedI.data?.n).asTo('evolved I data.n').isGonnaBe(1);
247
+ }
248
+ }
249
+ });
250
+
251
+ await ifWe(sir, 'session keystone dependency graphs are equivalent on source and dest', async () => {
252
+ const latestS = peer.currentSessionIdentity;
253
+ iReckon(sir, latestS).asTo('latestS exists').isGonnaBeTruthy();
254
+ if (latestS) {
255
+ const depGraphSource = await getDependencyGraph({ ibGib: latestS, space: sourceSpace });
256
+ const depGraphDest = await getDependencyGraph({ ibGib: latestS, space: destSpace });
257
+ const equal = graphsAreEquivalent({ graphA: depGraphSource, graphB: depGraphDest });
258
+ iReckon(sir, equal).asTo('session graphs are equivalent').isGonnaBeTrue();
259
+ }
260
+ });
261
+ });
262
+ // #endregion r1 verify post
263
+ });
264
+ // #endregion Round 1 - Dest Ahead Sync with Identity
265
+
266
+ });
@@ -20,7 +20,6 @@ import { InnerSpace_V1 } from '../witness/space/inner-space/inner-space-v1.mjs';
20
20
  import { createTimelineRootTestHelper, } from '../test-helpers.mjs';
21
21
  import { mut8Timeline } from '../timeline/timeline-api.mjs';
22
22
  import { DEFAULT_INNER_SPACE_DATA_V1 } from '../witness/space/inner-space/inner-space-types.mjs';
23
- import { toDto } from '../common/other/ibgib-helper.mjs';
24
23
  import { SyncPeerInnerspace_V1 } from './sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs';
25
24
  import { SYNC_PEER_INNERSPACE_DEFAULT_DATA_V1 } from './sync-peer/sync-peer-innerspace/sync-peer-innerspace-constants.mjs';
26
25