@ibgib/core-gib 0.1.38 → 0.1.40

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 (37) hide show
  1. package/dist/common/other/graph-helper.d.mts.map +1 -1
  2. package/dist/common/other/graph-helper.mjs +18 -3
  3. package/dist/common/other/graph-helper.mjs.map +1 -1
  4. package/dist/sync/graft-info/graft-info-helpers.mjs +1 -1
  5. package/dist/sync/graft-info/graft-info-helpers.mjs.map +1 -1
  6. package/dist/sync/sync-conflict-adv-multitimelines.respec.mjs +321 -235
  7. package/dist/sync/sync-conflict-adv-multitimelines.respec.mjs.map +1 -1
  8. package/dist/sync/sync-conflict-basic-multitimelines.respec.mjs +6 -6
  9. package/dist/sync/sync-conflict-basic-multitimelines.respec.mjs.map +1 -1
  10. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs +1 -1
  11. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs.map +1 -1
  12. package/dist/sync/sync-saga-coordinator.d.mts.map +1 -1
  13. package/dist/sync/sync-saga-coordinator.mjs +49 -12
  14. package/dist/sync/sync-saga-coordinator.mjs.map +1 -1
  15. package/dist/sync/sync-saga-message/sync-saga-message-types.d.mts +4 -0
  16. package/dist/sync/sync-saga-message/sync-saga-message-types.d.mts.map +1 -1
  17. package/dist/test-helpers.d.mts +104 -47
  18. package/dist/test-helpers.d.mts.map +1 -1
  19. package/dist/test-helpers.mjs +335 -131
  20. package/dist/test-helpers.mjs.map +1 -1
  21. package/dist/test-types.d.mts +25 -7
  22. package/dist/test-types.d.mts.map +1 -1
  23. package/dist/witness/space/reconciliation-space/reconciliation-space-helper.mjs +2 -2
  24. package/dist/witness/space/reconciliation-space/reconciliation-space-helper.mjs.map +1 -1
  25. package/package.json +1 -1
  26. package/src/common/other/graph-helper.mts +14 -2
  27. package/src/sync/SYNC_TESTING.md +135 -70
  28. package/src/sync/graft-info/graft-info-helpers.mts +1 -1
  29. package/src/sync/sync-conflict-adv-multitimelines.respec.mts +332 -245
  30. package/src/sync/sync-conflict-basic-multitimelines.respec.mts +5 -5
  31. package/src/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mts +1 -1
  32. package/src/sync/sync-saga-coordinator.mts +58 -14
  33. package/src/sync/sync-saga-message/sync-saga-message-types.mts +4 -0
  34. package/src/test-helpers.mts +429 -152
  35. package/src/test-types.mts +30 -7
  36. package/src/witness/space/reconciliation-space/reconciliation-space-helper.mts +2 -2
  37. package/tmp.md +205 -1160
@@ -216,7 +216,7 @@ await respecfully(sir, `Two different fields and rel8d`, async () => {
216
216
 
217
217
  // Verify Receiver has correct KV (Pre-Sync Check)
218
218
  // This ensures the conflict precondition exists.
219
- await ifWeMight(sir, 'verify receiver KV pre-sync', async () => {
219
+ await ifWe(sir, 'verify receiver KV pre-sync', async () => {
220
220
  try {
221
221
  const destKV = await receiverCoordinator.getKnowledgeMap({
222
222
  space: destSpace,
@@ -317,7 +317,7 @@ await respecfully(sir, `Two different fields and rel8d`, async () => {
317
317
  const resTip = await getFromSpace({ space: sourceSpace, addr: sourceTipAddr });
318
318
  const newTip = resTip.ibGibs![0] as IbGib_V1<TestData>;
319
319
 
320
- await ifWeMight(sir, 'basics of alpha merge', async () => {
320
+ await ifWe(sir, 'basics of alpha merge', async () => {
321
321
  iReckon(sir, sourceTipAddr).asTo(`Source Tip (${sourceTipAddr}) should NOT be alpha_v3_source_rel8beta`).not.isGonnaBe(getIbGibAddr({ ibGib: alpha_v3_source_rel8beta }));
322
322
  iReckon(sir, sourceTipAddr).asTo(`Source Tip (${sourceTipAddr}) should NOT be v2dest`).not.isGonnaBe(getIbGibAddr({ ibGib: alpha_v2_dest }));
323
323
 
@@ -330,7 +330,7 @@ await respecfully(sir, `Two different fields and rel8d`, async () => {
330
330
  // Check Graft Structure
331
331
  // Look for 'graftinfo' rel8n
332
332
 
333
- await ifWeMight(sir, 'graft info is valid', async () => {
333
+ await ifWe(sir, 'graft info is valid', async () => {
334
334
  if (!newTip.rel8ns) { throw new Error(`(UNEXPECTED) newTip.rel8ns falsy? (E: eb4078712ea2f02c7ee84b983ed77826)`); }
335
335
  const graftInfoRel = newTip.rel8ns[GRAFT_INFO_REL8N_NAME];
336
336
  iReckon(sir, graftInfoRel).asTo('New Tip should have graftinfo rel8n').isGonnaBeTruthy();
@@ -354,7 +354,7 @@ await respecfully(sir, `Two different fields and rel8d`, async () => {
354
354
  iReckon(sir, orphanRel![0]).asTo('orphan rel8ns will be later addr').isGonnaBe(orphanAddr);
355
355
  });
356
356
 
357
- await ifWeMight(sir, 'alpha and deps synced', async () => {
357
+ await ifWe(sir, 'alpha and deps synced', async () => {
358
358
  // alpha's full dep graph should exist on dest
359
359
  const [beta_dest] = await getIbGibsFromCache_fallbackToSpaces({
360
360
  addrs: [betaAddr_v0],
@@ -374,7 +374,7 @@ await respecfully(sir, `Two different fields and rel8d`, async () => {
374
374
  }
375
375
  });
376
376
 
377
- await ifWeMight(sir, 'beta and deps synced', async () => {
377
+ await ifWe(sir, 'beta and deps synced', async () => {
378
378
  // beta's full dep graph should exist on dest
379
379
  const [beta_dest] = await getIbGibsFromCache_fallbackToSpaces({
380
380
  addrs: [betaAddr_v0],
@@ -253,7 +253,7 @@ export class SyncPeerInnerspace_V1 extends SyncPeer_V1<InitializeSyncPeerInnersp
253
253
  if (logalot) { console.log(`${lcPut} starting... (I: 4133e736b4c80d2cf94448b87b206826)`); }
254
254
 
255
255
  // 2 seconds...i want to see huge blocks of logs entries for this to see this happening
256
- const delayMs = 20;
256
+ const delayMs = 2;
257
257
  for (let i = 0; i < 10; i++) {
258
258
  console.warn(`${lc} ARTIFICIALLY DELAYING PAYLOADS TO MIMIC TRANSFER LATENCY. REMOVE THIS DELAY!! (W: 5e7b28f1daa82d955897e9d8cdb16f26)`)
259
259
  await delay(delayMs);
@@ -59,6 +59,7 @@ import { FlatIbGibGraph } from "../common/other/graph-types.mjs";
59
59
  import { graftTimelines, } from "./graft-info/graft-info-helpers.mjs";
60
60
  import { GRAFT_INFO_REL8N_NAME } from "./graft-info/graft-info-constants.mjs";
61
61
  import { GraftInfoIbGib_V1 } from "./graft-info/graft-info-types.mjs";
62
+ import { validateIbGibIntrinsically } from "@ibgib/ts-gib/dist/V1/validate-helper.mjs";
62
63
 
63
64
 
64
65
  const logalot = GLOBAL_LOG_A_LOT;
@@ -234,11 +235,7 @@ export class SyncSagaCoordinator {
234
235
  }
235
236
  })();
236
237
 
237
- return {
238
- sagaId,
239
- updates$,
240
- done
241
- };
238
+ return { sagaId, updates$, done };
242
239
  }
243
240
 
244
241
  /**
@@ -1674,7 +1671,7 @@ export class SyncSagaCoordinator {
1674
1671
  const { conflictStrategy } = sagaIbGib.data;
1675
1672
  const { deltaRequestAddrInfos, payloadAddrsDomain, proposeCommit, } = deltaData;
1676
1673
 
1677
- const peerProposesCommit = deltaData.proposeCommit || false;
1674
+ const peerProposesCommit = deltaData.proposeCommit ?? false;
1678
1675
 
1679
1676
  /**
1680
1677
  * these are already in the local/receiver temp space
@@ -1723,8 +1720,12 @@ export class SyncSagaCoordinator {
1723
1720
  // we need to get our own delta dep graph, based off of the
1724
1721
  // LCA, and then we need to perform the optimistic graft
1725
1722
 
1723
+ if (unresolvedConflict.latestCommonFrameAddr) {
1724
+
1725
+ }
1726
+
1726
1727
  const {
1727
- latestCommonFrameAddr,
1728
+ // latestCommonFrameAddr, // is not defined yet
1728
1729
  receiverKnowledgeTimelineAddrs,
1729
1730
  senderKnowledgeTimelineAddrs,
1730
1731
  reason,
@@ -1741,6 +1742,7 @@ export class SyncSagaCoordinator {
1741
1742
 
1742
1743
  const depGraph = await getDependencyGraph({
1743
1744
  ibGibAddrs: [receiverTipAddr],
1745
+ live: true,
1744
1746
  space: mySpace,
1745
1747
  });
1746
1748
  const depGraphIbGibs = Object.values(depGraph);
@@ -1753,6 +1755,24 @@ export class SyncSagaCoordinator {
1753
1755
  await registerNewIbGib({ ibGib: timelineIbGib, space: myTempSpace });
1754
1756
  }
1755
1757
 
1758
+
1759
+ // get the latest common point in the two timelines
1760
+ const latestCommonFrameAddr = senderKnowledgeTimelineAddrs.findLast(addrA => receiverKnowledgeTimelineAddrs.includes(addrA));
1761
+ if (!latestCommonFrameAddr) { throw new Error(`(UNEXPECTED) latestCommonFrameAddr falsy? how we can have a conflict without a common point in history? (E: 53de0a181838b3e5bf98d0887994b826)`); }
1762
+
1763
+ // no matter what, we want to transmit our branch on this
1764
+ // end (the receiver). when grafting, it may end up being
1765
+ // orphaned, or it may end up being the base branch. Either
1766
+ // way, the sender does not have our (usually unique) delta
1767
+ // ibgibs.
1768
+ const ourDeltaDepGraph = await getDeltaDependencyGraph({
1769
+ ibGibAddr: unresolvedConflict.receiverTipAddr,
1770
+ latestCommonFrameAddr,
1771
+ live: true,
1772
+ space: mySpace,
1773
+ });
1774
+ Object.values(ourDeltaDepGraph).forEach(ourIbGib => outgoingPayload.push(ourIbGib));
1775
+
1756
1776
  /**
1757
1777
  * ATOW (01/31/2026) on initial implementation, these are
1758
1778
  * already persisted AND registered in the space
@@ -1767,6 +1787,8 @@ export class SyncSagaCoordinator {
1767
1787
  space: myTempSpace,
1768
1788
  });
1769
1789
 
1790
+ // need to get orphaned delta
1791
+
1770
1792
  const {
1771
1793
  dnasCreatedInGraft,
1772
1794
  dnasReplayed,
@@ -1775,7 +1797,9 @@ export class SyncSagaCoordinator {
1775
1797
  graftInfoCreated,
1776
1798
  } = resGraft;
1777
1799
 
1800
+
1778
1801
  unresolvedConflict.createdDnaAddrs = dnasCreatedInGraft.map(x => getIbGibAddr({ ibGib: x }));
1802
+ unresolvedConflict.replayedDnaAddrs = dnasReplayed.map(x => getIbGibAddr({ ibGib: x }));
1779
1803
  unresolvedConflict.createdDomainAddrs = [
1780
1804
  ...intermediateIbGibsCreatedInGraft.map(x => getIbGibAddr({ ibGib: x })),
1781
1805
  getIbGibAddr({ ibGib: graftInfoCreated }),
@@ -1790,16 +1814,33 @@ export class SyncSagaCoordinator {
1790
1814
 
1791
1815
  // add to ibgibs created in graft to both conflict info (via
1792
1816
  // addrs) and the outgoingPayload
1793
- unresolvedConflict.accretivePayloadAddrs ??= [];
1794
- [
1817
+
1818
+ const ibGibsCreatedOrReplayedInGraft = [
1795
1819
  dnasCreatedInGraft,
1820
+ dnasReplayed,
1796
1821
  intermediateIbGibsCreatedInGraft,
1797
1822
  [graftInfoCreated, newGraftTip]
1798
- ].forEach(
1799
- ibGibsCreatedInGraft => ibGibsCreatedInGraft
1823
+ ];
1824
+
1825
+ // #region debug
1826
+ for (const ibGib of ibGibsCreatedOrReplayedInGraft.flat()) {
1827
+ const validationErrors = await validateIbGibIntrinsically({ ibGib }) ?? [];
1828
+ if (validationErrors.length > 0) {
1829
+ console.dir(ibGib);
1830
+ debugger;
1831
+ console.log(pretty(ibGib));
1832
+ }
1833
+ }
1834
+ // #endregion debug
1835
+
1836
+ unresolvedConflict.accretivePayloadAddrs ??= [];
1837
+
1838
+ ibGibsCreatedOrReplayedInGraft.forEach(
1839
+ ibGibsCreatedOrReplayedInGraft => ibGibsCreatedOrReplayedInGraft
1800
1840
  .forEach(ibGibCreated => {
1801
1841
  const addrCreated = getIbGibAddr({ ibGib: ibGibCreated });
1802
- const alreadyExistsInAccretivePayloadAddrs = unresolvedConflict.accretivePayloadAddrs!.includes(addrCreated);
1842
+ const alreadyExistsInAccretivePayloadAddrs =
1843
+ unresolvedConflict.accretivePayloadAddrs!.includes(addrCreated);
1803
1844
  if (!alreadyExistsInAccretivePayloadAddrs) {
1804
1845
  unresolvedConflict.accretivePayloadAddrs!.push(addrCreated)
1805
1846
  }
@@ -2121,13 +2162,14 @@ export class SyncSagaCoordinator {
2121
2162
  });
2122
2163
  const finalConflictGraftInfo = resGetGraftIbGibs.at(0) as GraftInfoIbGib_V1;
2123
2164
  if (!finalConflictGraftInfo) { throw new Error(`(UNEXPECTED) couldn't get finalConflictGraftInfo from localTempSpace (${localTempSpace})? (E: 35e3c8130608d991e8fb295807812826)`); }
2124
- const { createdDnaAddrs, createdDomainAddrs } = finalConflict;
2165
+ const { createdDnaAddrs, replayedDnaAddrs, createdDomainAddrs } = finalConflict;
2125
2166
  if (!createdDnaAddrs || createdDnaAddrs.length === 0) { throw new Error(`(UNEXPECTED) finalConflict.createdDnaAddrs falsy/empty? (E: 9689f8be5bd19650b8d4a058b65db826)`); }
2167
+ if (!replayedDnaAddrs || replayedDnaAddrs.length === 0) { throw new Error(`(UNEXPECTED) finalConflict.replayedDnaAddrs falsy/empty? (E: f42878ed1cee3e9828567c5ab8179526)`); }
2126
2168
  if (!createdDomainAddrs || createdDomainAddrs.length === 0) { throw new Error(`(UNEXPECTED) finalConflict.createdDomainAddrs falsy/empty? (E: cc41251d1acfe91a48d1b6080259ed26)`); }
2127
2169
 
2128
2170
  /** throws if not all found */
2129
2171
  const resGetCreated = await getIbGibsFromCache_fallbackToSpaces({
2130
- addrs: [...createdDnaAddrs, ...createdDomainAddrs],
2172
+ addrs: [...createdDnaAddrs, ...replayedDnaAddrs, ...createdDomainAddrs],
2131
2173
  space: localTempSpace,
2132
2174
  });
2133
2175
  resGetCreated.forEach(x => createdFromConflictGraftsIbGibs.push(x));
@@ -2343,6 +2385,8 @@ export class SyncSagaCoordinator {
2343
2385
  metaspace,
2344
2386
  });
2345
2387
 
2388
+ // debugger; // edited on dest exists in myTempSpace and mySpace?
2389
+
2346
2390
  // todo: implement explicit cleanup logic here and in peer
2347
2391
  console.error(`${lc} NAG ERROR (NOT THROWN): implement cleanup logic, including add a cleanup method to the peer (E: 3a9a24befb98a981a88fbdbf52920e26)`);
2348
2392
  if (logalot) { console.log(`${lc} Peer committed. Finalizing saga locally. Saga Complete.`); }
@@ -211,6 +211,10 @@ export interface SyncSagaConflictInfo {
211
211
  * stage.
212
212
  */
213
213
  createdDnaAddrs?: IbGibAddr[];
214
+ /**
215
+ * dna ibgibs that were replayed to create the graft.
216
+ */
217
+ replayedDnaAddrs?: IbGibAddr[];
214
218
  /**
215
219
  * newly created ibgibs - IN ORDER - created as a result of a graft
216
220
  *