@fluidframework/id-compressor 2.118.1 → 3.0.1

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 (53) hide show
  1. package/CHANGELOG.md +34 -4
  2. package/README.md +10 -10
  3. package/{api-extractor.json → api-extractor/api-extractor-model.json} +1 -1
  4. package/dist/appendOnlySortedMap.js +6 -5
  5. package/dist/appendOnlySortedMap.js.map +1 -1
  6. package/dist/finalSpace.js +1 -3
  7. package/dist/finalSpace.js.map +1 -1
  8. package/dist/idCompressor.js +43 -37
  9. package/dist/idCompressor.js.map +1 -1
  10. package/dist/identifiers.js +1 -2
  11. package/dist/identifiers.js.map +1 -1
  12. package/dist/packageVersion.d.ts +1 -1
  13. package/dist/packageVersion.d.ts.map +1 -1
  14. package/dist/packageVersion.js +1 -1
  15. package/dist/packageVersion.js.map +1 -1
  16. package/dist/persistanceUtilities.js +6 -7
  17. package/dist/persistanceUtilities.js.map +1 -1
  18. package/dist/sessionSpaceNormalizer.js +3 -5
  19. package/dist/sessionSpaceNormalizer.js.map +1 -1
  20. package/dist/sessions.js +17 -15
  21. package/dist/sessions.js.map +1 -1
  22. package/dist/test/idCompressorTestUtilities.js +32 -15
  23. package/dist/test/idCompressorTestUtilities.js.map +1 -1
  24. package/dist/test/testCommon.js +7 -8
  25. package/dist/test/testCommon.js.map +1 -1
  26. package/dist/utilities.js +15 -16
  27. package/dist/utilities.js.map +1 -1
  28. package/lib/appendOnlySortedMap.js +6 -5
  29. package/lib/appendOnlySortedMap.js.map +1 -1
  30. package/lib/finalSpace.js +1 -3
  31. package/lib/finalSpace.js.map +1 -1
  32. package/lib/idCompressor.js +38 -32
  33. package/lib/idCompressor.js.map +1 -1
  34. package/lib/legacy.d.ts +1 -1
  35. package/lib/packageVersion.d.ts +1 -1
  36. package/lib/packageVersion.d.ts.map +1 -1
  37. package/lib/packageVersion.js +1 -1
  38. package/lib/packageVersion.js.map +1 -1
  39. package/lib/public.d.ts +1 -1
  40. package/lib/sessionSpaceNormalizer.js +3 -5
  41. package/lib/sessionSpaceNormalizer.js.map +1 -1
  42. package/lib/sessions.js +9 -7
  43. package/lib/sessions.js.map +1 -1
  44. package/lib/test/idCompressorTestUtilities.js +21 -4
  45. package/lib/test/idCompressorTestUtilities.js.map +1 -1
  46. package/package.json +33 -52
  47. package/src/packageVersion.ts +1 -1
  48. package/src/test/tsconfig.json +4 -1
  49. package/tsconfig.json +1 -1
  50. package/internal.d.ts +0 -11
  51. package/legacy.d.ts +0 -11
  52. /package/api-extractor/{api-extractor.current.json → api-extractor-report.current.json} +0 -0
  53. /package/api-extractor/{api-extractor.legacy.json → api-extractor-report.legacy.json} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"sessions.js","sourceRoot":"","sources":["../src/sessions.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAC7D,gEAAkD;AAIlD,iDAQwB;AAExB;;;GAGG;AACH,MAAa,QAAQ;IAOpB,YAAmB,QAAyD;QAN5E,6HAA6H;QAC7H,4DAA4D;QAC3C,cAAS,GAAG,IAAI,wBAAK,CAAuB,SAAS,EAAE,6BAAc,CAAC,CAAC;QACxF,sGAAsG;QACrF,iBAAY,GAAG,IAAI,GAAG,EAAsB,CAAC;QAG7D,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC5B,iBAAiB;YACjB,KAAK,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,QAAQ,EAAE,CAAC;gBAC3C,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAA,sCAAuB,EAAC,OAAO,CAAc,EAAE,OAAO,CAAC,CAAC;YAC/E,CAAC;YACD,IAAI,CAAC,SAAS,GAAG,IAAI,wBAAK,CAAC,QAAQ,EAAE,6BAAc,CAAC,CAAC;YACrD,IACC,IAAI,CAAC,YAAY,CAAC,IAAI,KAAK,QAAQ,CAAC,MAAM;gBAC1C,QAAQ,CAAC,MAAM,KAAK,IAAI,CAAC,SA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ChE,CAAC;AAVD,0CAUC;AAED;;GAEG;AACH,SAAgB,kBAAkB,CAAC,OAAkB;IACpD,OAAO,CAAE,OAAO,CAAC,WAAsB,GAAG,CAAC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAsB,CAAC;AACxF,CAAC;AAFD,gDAEC;AAED;;GAEG;AACH,SAAgB,kBAAkB,CAAC,OAAkB;IACpD,OAAO,CAAE,OAAO,CAAC,WAAsB,GAAG,CAAC,OAAO,CAAC,KAAK,GAAG,CAAC,CAAC,CAAsB,CAAC;AACrF,CAAC;AAFD,gDAEC;AAED;;GAEG;AACH,SAAgB,kBAAkB,CAAC,OAAkB;IACpD,OAAO,CAAE,OAAO,CAAC,WAAsB,GAAG,CAAC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAsB,CAAC;AACxF,CAAC;AAFD,gDAEC;AAED;;GAEG;AACH,SAAgB,kBAAkB,CAAC,OAAkB;IACpD,OAAO,CAAE,OAAO,CAAC,WAAsB,GAAG,CAAC,OAAO,CAAC,KAAK,GAAG,CAAC,CAAC,CAAsB,CAAC;AACrF,CAAC;AAFD,gDAEC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { BTree } from \"@tylerbu/sorted-btree-es6\";\n\nimport type { FinalCompressedId, LocalCompressedId, NumericUuid } from \"./identifiers.js\";\nimport type { SessionId, StableId } from \"./types/index.js\";\nimport {\n\tcompareBigints,\n\tgenCountFromLocalId,\n\tlocalIdFromGenCount,\n\tnumericUuidFromStableId,\n\toffsetNumericUuid,\n\tstableIdFromNumericUuid,\n\tsubtractNumericUuids,\n} from \"./utilities.js\";\n\n/**\n * A collection of all sessions known to the compressor (i.e. all finalized/acked allocated UUIDs and their corresponding local and final forms).\n * This collection of all sessions comprises a distributed document's IDs.\n */\nexport class Sessions {\n\t// A range-queryable store of all sessions. A btree is used as it solves the predecessor problem for any given UUID, allowing\n\t// us to quickly find the session that may have produced it.\n\tprivate readonly uuidSpace = new BTree<NumericUuid, Session>(undefined, compareBigints);\n\t// A fast lookup table from session ID to the session object, used to avoid accessing the slower btree\n\tprivate readonly sessionCache = new Map<SessionId, Session>();\n\n\tpublic constructor(sessions?: [sessionBase: NumericUuid, session: Session][]) {\n\t\tif (sessions !== undefined) {\n\t\t\t// bulk load path\n\t\t\tfor (const [numeric, session] of sessions) {\n\t\t\t\tthis.sessionCache.set(stableIdFromNumericUuid(numeric) as SessionId, session);\n\t\t\t}\n\t\t\tthis.uuidSpace = new BTree(sessions, compareBigints);\n\t\t\tif (\n\t\t\t\tthis.sessionCache.size !== sessions.length ||\n\t\t\t\tsessions.length !== this.uuidSpace.size\n\t\t\t) {\n\t\t\t\tthrow new Error(\"Cannot resume existing session.\");\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic sessions(): IterableIterator<Session> {\n\t\treturn this.sessionCache.values();\n\t}\n\n\tpublic getOrCreate(sessionId: SessionId): Session {\n\t\tconst existing = this.sessionCache.get(sessionId);\n\t\tif (existing !== undefined) {\n\t\t\treturn existing;\n\t\t}\n\t\tconst session = new Session(sessionId);\n\t\tassert(\n\t\t\tthis.uuidSpace.set(session.sessionUuid, session),\n\t\t\t0x760 /* Duplicate session in map. */,\n\t\t);\n\t\tthis.sessionCache.set(sessionId, session);\n\t\treturn session;\n\t}\n\n\tpublic get(sessionId: SessionId): Session | undefined {\n\t\treturn this.sessionCache.get(sessionId);\n\t}\n\n\tpublic getContainingCluster(\n\t\tquery: StableId,\n\t): [cluster: IdCluster, alignedLocal: LocalCompressedId] | undefined {\n\t\tconst numericStable = numericUuidFromStableId(query);\n\t\tconst possibleMatch = this.uuidSpace.getPairOrNextLower(numericStable);\n\t\tif (possibleMatch === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst [_, session] = possibleMatch;\n\t\tconst numericDelta = subtractNumericUuids(numericStable, session.sessionUuid);\n\t\tif (numericDelta > Number.MAX_SAFE_INTEGER) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst alignedLocal = localIdFromGenCount(Number(numericDelta) + 1);\n\t\tconst containingCluster = session.getClusterByLocal(alignedLocal, true);\n\t\tif (containingCluster === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn [containingCluster, alignedLocal];\n\t}\n\n\tpublic clusterCollides(cluster: IdCluster): boolean {\n\t\tconst { session: owningSession, baseLocalId, capacity } = cluster;\n\t\tconst clusterBaseNumeric = offsetNumericUuid(\n\t\t\towningSession.sessionUuid,\n\t\t\tgenCountFromLocalId(baseLocalId) - 1,\n\t\t);\n\t\tconst clusterMaxNumeric = offsetNumericUuid(clusterBaseNumeric, capacity - 1);\n\t\tlet closestMatch: [NumericUuid, Session] | undefined =\n\t\t\tthis.uuidSpace.getPairOrNextLower(clusterMaxNumeric);\n\t\t// Find the first session that is not the owner of this new cluster.\n\t\t// Once we have that, check to see if its cluster chain overlaps with the new cluster.\n\t\t// Consider the following diagram of UUID space:\n\t\t// Cluster chain A: |----------------------|\n\t\t// Cluster chain B: |----------|\n\t\t// Cluster chain C: |-------|\n\t\t// While it is true that when adding a cluster to chain C, we would find\n\t\t// the next lower session (which is B) and erroneously determine we do not collide\n\t\t// with any other session, but this situation is impossible to get into as B would\n\t\t// have detected that it collided with A (or the other way around, depending on ordering).\n\t\t// eslint-disable-next-line @typescript-eslint/prefer-optional-chain -- using ?. could change behavior\n\t\twhile (closestMatch !== undefined && closestMatch[1] === owningSession) {\n\t\t\tclosestMatch = this.uuidSpace.nextLowerPair(closestMatch[0]);\n\t\t}\n\t\tif (closestMatch === undefined) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst [_, session] = closestMatch;\n\t\tassert(session !== owningSession, 0x761 /* Failed to attempt to detect collisions. */);\n\t\tconst lastCluster = session.getLastCluster();\n\t\tif (lastCluster === undefined) {\n\t\t\t// If the closest session is empty (the local session), then it is guaranteed (probabilistically) that there are no\n\t\t\t// non-empty sessions that have a cluster chain that starts prior to the empty session and collides with the cluster\n\t\t\t// we are checking, so we can return false.\n\t\t\treturn false;\n\t\t}\n\t\tconst lastAllocatedNumeric = offsetNumericUuid(\n\t\t\tsession.sessionUuid,\n\t\t\tgenCountFromLocalId(lastAllocatedLocal(lastCluster)) - 1,\n\t\t);\n\t\treturn lastAllocatedNumeric >= clusterBaseNumeric;\n\t}\n\n\tpublic equals(other: Sessions, includeLocalState: boolean): boolean {\n\t\tconst checkIsSubset = (sessionsA: Sessions, sessionsB: Sessions): boolean => {\n\t\t\tconst first = sessionsA.sessions().next();\n\t\t\tconst firstSessionThis = first.done ? undefined : first.value;\n\t\t\tfor (const [stableId, session] of sessionsA.sessionCache.entries()) {\n\t\t\t\tconst otherSession = sessionsB.sessionCache.get(stableId);\n\t\t\t\tif (otherSession === undefined) {\n\t\t\t\t\tif (!session.isEmpty() || includeLocalState) {\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\tassert(\n\t\t\t\t\t\tsession === firstSessionThis,\n\t\t\t\t\t\t0x762 /* The only non-empty session must be the local session. */,\n\t\t\t\t\t);\n\t\t\t\t} else if (!session.equals(otherSession)) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t};\n\t\treturn checkIsSubset(this, other) && checkIsSubset(other, this);\n\t}\n}\n\n/**\n * The IDs created by a specific session, stored as a cluster chain to allow for fast conversions.\n */\nexport class Session {\n\t// All clusters created by this session, in creation order (thus sorted by base final and local ID).\n\tprivate readonly clusterChain: IdCluster[] = [];\n\t// The numeric form of the SessionId\n\tpublic readonly sessionUuid: NumericUuid;\n\n\tpublic constructor(sessionId: SessionId | NumericUuid) {\n\t\tthis.sessionUuid =\n\t\t\ttypeof sessionId === \"string\" ? numericUuidFromStableId(sessionId) : sessionId;\n\t}\n\n\t/**\n\t * Adds a new empty cluster to the cluster chain of this session.\n\t */\n\tpublic addNewCluster(\n\t\tbaseFinalId: FinalCompressedId,\n\t\tcapacity: number,\n\t\tcount: number,\n\t): IdCluster {\n\t\tconst lastCluster = this.getLastCluster();\n\t\tconst newCluster: IdCluster = {\n\t\t\tsession: this,\n\t\t\tbaseFinalId,\n\t\t\tbaseLocalId: (lastCluster === undefined\n\t\t\t\t? -1\n\t\t\t\t: lastAllocatedLocal(lastCluster) - 1) as LocalCompressedId,\n\t\t\tcapacity,\n\t\t\tcount,\n\t\t};\n\t\tthis.clusterChain.push(newCluster);\n\t\treturn newCluster;\n\t}\n\n\tpublic isEmpty(): boolean {\n\t\treturn this.clusterChain.length === 0;\n\t}\n\n\t/**\n\t * Returns the last cluster in this session's cluster chain, if any.\n\t */\n\tpublic getLastCluster(): IdCluster | undefined {\n\t\treturn this.clusterChain[this.clusterChain.length - 1];\n\t}\n\n\t/**\n\t * Converts the local ID from this session to a final ID, if possible.\n\t * @param includeAllocated - true if the conversion should succeed even if the local ID aligns with a part of the cluster that is allocated but not finalized.\n\t */\n\tpublic tryConvertToFinal(\n\t\tsearchLocal: LocalCompressedId,\n\t\tincludeAllocated: boolean,\n\t): FinalCompressedId | undefined {\n\t\tconst containingCluster = this.getClusterByLocal(searchLocal, includeAllocated);\n\t\tif (containingCluster === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn getAlignedFinal(containingCluster, searchLocal);\n\t}\n\n\t/**\n\t * Returns the cluster containing the supplied local ID, if possible.\n\t * @param includeAllocated - true if the conversion should succeed even if the local ID aligns with a part of the cluster that is allocated but not finalized.\n\t */\n\tpublic getClusterByLocal(\n\t\tlocalId: LocalCompressedId,\n\t\tincludeAllocated: boolean,\n\t): IdCluster | undefined {\n\t\tconst lastValidLocal: (cluster: IdCluster) => LocalCompressedId = includeAllocated\n\t\t\t? lastAllocatedLocal\n\t\t\t: lastFinalizedLocal;\n\t\tconst matchedCluster = Session.binarySearch(\n\t\t\tlocalId,\n\t\t\tthis.clusterChain,\n\t\t\t(local, cluster): number => {\n\t\t\t\tconst lastLocal = lastValidLocal(cluster);\n\t\t\t\tif (local < lastLocal) {\n\t\t\t\t\treturn 1;\n\t\t\t\t} else if (local > cluster.baseLocalId) {\n\t\t\t\t\treturn -1;\n\t\t\t\t} else {\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\t\treturn matchedCluster;\n\t}\n\n\t/**\n\t * Returns the cluster containing the supplied final ID, if possible.\n\t */\n\tpublic getClusterByAllocatedFinal(final: FinalCompressedId): IdCluster | undefined {\n\t\treturn Session.getContainingCluster(final, this.clusterChain);\n\t}\n\n\t/**\n\t * Returns the cluster from the supplied cluster chain containing the supplied final ID, if possible.\n\t * `clusterChain` must be sorted by final/local base ID.\n\t */\n\tpublic static getContainingCluster(\n\t\tfinalId: FinalCompressedId,\n\t\tclusterChain: readonly IdCluster[],\n\t): IdCluster | undefined {\n\t\treturn Session.binarySearch(finalId, clusterChain, (final, cluster) => {\n\t\t\tconst lastFinal = lastAllocatedFinal(cluster);\n\t\t\tif (final < cluster.baseFinalId) {\n\t\t\t\treturn -1;\n\t\t\t} else if (final > lastFinal) {\n\t\t\t\treturn 1;\n\t\t\t} else {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t});\n\t}\n\n\tstatic binarySearch<S, T>(\n\t\tsearch: S,\n\t\tarr: readonly T[],\n\t\tcomparator: (a: S, b: T) => number,\n\t): T | undefined {\n\t\tlet left = 0;\n\t\tlet right = arr.length - 1;\n\t\twhile (left <= right) {\n\t\t\tconst mid = Math.floor((left + right) / 2);\n\t\t\tconst value = arr[mid];\n\t\t\tassert(value !== undefined, 0x9dc /* value is undefined in Session.binarySearch */);\n\t\t\tconst c = comparator(search, value);\n\t\t\tif (c === 0) {\n\t\t\t\treturn value; // Found the target, return its index.\n\t\t\t} else if (c > 0) {\n\t\t\t\tleft = mid + 1; // Continue search on right half.\n\t\t\t} else {\n\t\t\t\tright = mid - 1; // Continue search on left half.\n\t\t\t}\n\t\t}\n\t\treturn undefined; // If we reach here, target is not in array.\n\t}\n\n\tpublic equals(other: Session): boolean {\n\t\tfor (const [index, value] of Object.entries(this.clusterChain)) {\n\t\t\tif (!clustersEqual(value, other.clusterChain[index] as IdCluster)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn this.sessionUuid === other.sessionUuid;\n\t}\n}\n\n/**\n * A cluster of final (sequenced via consensus), sequentially allocated compressed IDs.\n * A final ID in a cluster decompresses to a sequentially allocated UUID that is the result of adding its offset within\n * the cluster to base UUID for the session that created it.\n */\nexport interface IdCluster {\n\t/**\n\t * The session that created this cluster.\n\t */\n\treadonly session: Session;\n\n\t/**\n\t * The first final ID in the cluster.\n\t */\n\treadonly baseFinalId: FinalCompressedId;\n\n\t/**\n\t * The local ID aligned with `baseFinalId`.\n\t */\n\treadonly baseLocalId: LocalCompressedId;\n\n\t/**\n\t * The total number of final IDs reserved for allocation in the cluster.\n\t * Clusters are reserved in blocks as a performance optimization.\n\t */\n\tcapacity: number;\n\n\t/**\n\t * The number of final IDs currently allocated in the cluster.\n\t */\n\tcount: number;\n}\n\nexport function clustersEqual(a: IdCluster, b: IdCluster): boolean {\n\treturn (\n\t\ta.session.sessionUuid === b.session.sessionUuid &&\n\t\ta.baseFinalId === b.baseFinalId &&\n\t\ta.baseLocalId === b.baseLocalId &&\n\t\ta.capacity === b.capacity &&\n\t\ta.count === b.count\n\t);\n}\n\n/**\n * Returns the final ID that is aligned with the supplied local ID within a cluster.\n * Includes allocated IDs.\n */\nexport function getAlignedFinal(\n\tcluster: IdCluster,\n\tlocalWithin: LocalCompressedId,\n): FinalCompressedId | undefined {\n\tconst clusterOffset =\n\t\tgenCountFromLocalId(localWithin) - genCountFromLocalId(cluster.baseLocalId);\n\tif (clusterOffset < cluster.capacity) {\n\t\treturn ((cluster.baseFinalId as number) + clusterOffset) as FinalCompressedId;\n\t}\n\treturn undefined;\n}\n\n/**\n * Returns the local ID that is aligned with the supplied final ID within a cluster.\n * Fails if the supplied ID does not fall within the cluster bounds.\n */\nexport function getAlignedLocal(\n\tcluster: IdCluster,\n\tfinalWithin: FinalCompressedId,\n): LocalCompressedId {\n\tassert(\n\t\tfinalWithin >= cluster.baseFinalId && finalWithin <= lastAllocatedFinal(cluster),\n\t\t0x763 /* Supplied ID is not within the cluster. */,\n\t);\n\tconst finalDelta = finalWithin - cluster.baseFinalId;\n\treturn (cluster.baseLocalId - finalDelta) as LocalCompressedId;\n}\n\n/**\n * Returns the last allocated final ID (i.e. any ID between base final and base final + capacity) within a cluster\n */\nexport function lastAllocatedFinal(cluster: IdCluster): FinalCompressedId {\n\treturn ((cluster.baseFinalId as number) + (cluster.capacity - 1)) as FinalCompressedId;\n}\n\n/**\n * Returns the last allocated final ID (i.e. any ID between base final and base final + count) within a cluster\n */\nexport function lastFinalizedFinal(cluster: IdCluster): FinalCompressedId {\n\treturn ((cluster.baseFinalId as number) + (cluster.count - 1)) as FinalCompressedId;\n}\n\n/**\n * Returns the last allocated local ID (i.e. any ID between base local and base local + capacity) within a cluster\n */\nexport function lastAllocatedLocal(cluster: IdCluster): LocalCompressedId {\n\treturn ((cluster.baseLocalId as number) - (cluster.capacity - 1)) as LocalCompressedId;\n}\n\n/**\n * Returns the last allocated local ID (i.e. any ID between base local and base local + count) within a cluster\n */\nexport function lastFinalizedLocal(cluster: IdCluster): LocalCompressedId {\n\treturn ((cluster.baseLocalId as number) - (cluster.count - 1)) as LocalCompressedId;\n}\n"]}
1
+ {"version":3,"file":"sessions.js","sourceRoot":"","sources":["../src/sessions.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAkVH,sCAQC;AAMD,0CAUC;AAMD,0CAUC;AAKD,gDAEC;AAKD,gDAEC;AAKD,gDAEC;AAKD,gDAEC;AApZD,kEAA6D;AAC7D,gEAAkD;AAIlD,iDAQwB;AAExB;;;GAGG;AACH,MAAa,QAAQ;IACpB,6HAA6H;IAC7H,4DAA4D;IAC3C,SAAS,GAAG,IAAI,wBAAK,CAAuB,SAAS,EAAE,6BAAc,CAAC,CAAC;IACxF,sGAAsG;IACrF,YAAY,G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CAAC,CAAC;IAC7E,IAAI,aAAa,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;QACtC,OAAO,CAAE,OAAO,CAAC,WAAsB,GAAG,aAAa,CAAsB,CAAC;IAC/E,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC;AAED;;;GAGG;AACH,SAAgB,eAAe,CAC9B,OAAkB,EAClB,WAA8B;IAE9B,IAAA,iBAAM,EACL,WAAW,IAAI,OAAO,CAAC,WAAW,IAAI,WAAW,IAAI,kBAAkB,CAAC,OAAO,CAAC,EAChF,KAAK,CAAC,4CAA4C,CAClD,CAAC;IACF,MAAM,UAAU,GAAG,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IACrD,OAAO,CAAC,OAAO,CAAC,WAAW,GAAG,UAAU,CAAsB,CAAC;AAChE,CAAC;AAED;;GAEG;AACH,SAAgB,kBAAkB,CAAC,OAAkB;IACpD,OAAO,CAAE,OAAO,CAAC,WAAsB,GAAG,CAAC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAsB,CAAC;AACxF,CAAC;AAED;;GAEG;AACH,SAAgB,kBAAkB,CAAC,OAAkB;IACpD,OAAO,CAAE,OAAO,CAAC,WAAsB,GAAG,CAAC,OAAO,CAAC,KAAK,GAAG,CAAC,CAAC,CAAsB,CAAC;AACrF,CAAC;AAED;;GAEG;AACH,SAAgB,kBAAkB,CAAC,OAAkB;IACpD,OAAO,CAAE,OAAO,CAAC,WAAsB,GAAG,CAAC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAsB,CAAC;AACxF,CAAC;AAED;;GAEG;AACH,SAAgB,kBAAkB,CAAC,OAAkB;IACpD,OAAO,CAAE,OAAO,CAAC,WAAsB,GAAG,CAAC,OAAO,CAAC,KAAK,GAAG,CAAC,CAAC,CAAsB,CAAC;AACrF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { BTree } from \"@tylerbu/sorted-btree-es6\";\n\nimport type { FinalCompressedId, LocalCompressedId, NumericUuid } from \"./identifiers.js\";\nimport type { SessionId, StableId } from \"./types/index.js\";\nimport {\n\tcompareBigints,\n\tgenCountFromLocalId,\n\tlocalIdFromGenCount,\n\tnumericUuidFromStableId,\n\toffsetNumericUuid,\n\tstableIdFromNumericUuid,\n\tsubtractNumericUuids,\n} from \"./utilities.js\";\n\n/**\n * A collection of all sessions known to the compressor (i.e. all finalized/acked allocated UUIDs and their corresponding local and final forms).\n * This collection of all sessions comprises a distributed document's IDs.\n */\nexport class Sessions {\n\t// A range-queryable store of all sessions. A btree is used as it solves the predecessor problem for any given UUID, allowing\n\t// us to quickly find the session that may have produced it.\n\tprivate readonly uuidSpace = new BTree<NumericUuid, Session>(undefined, compareBigints);\n\t// A fast lookup table from session ID to the session object, used to avoid accessing the slower btree\n\tprivate readonly sessionCache = new Map<SessionId, Session>();\n\n\tpublic constructor(sessions?: [sessionBase: NumericUuid, session: Session][]) {\n\t\tif (sessions !== undefined) {\n\t\t\t// bulk load path\n\t\t\tfor (const [numeric, session] of sessions) {\n\t\t\t\tthis.sessionCache.set(stableIdFromNumericUuid(numeric) as SessionId, session);\n\t\t\t}\n\t\t\tthis.uuidSpace = new BTree(sessions, compareBigints);\n\t\t\tif (\n\t\t\t\tthis.sessionCache.size !== sessions.length ||\n\t\t\t\tsessions.length !== this.uuidSpace.size\n\t\t\t) {\n\t\t\t\tthrow new Error(\"Cannot resume existing session.\");\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic sessions(): IterableIterator<Session> {\n\t\treturn this.sessionCache.values();\n\t}\n\n\tpublic getOrCreate(sessionId: SessionId): Session {\n\t\tconst existing = this.sessionCache.get(sessionId);\n\t\tif (existing !== undefined) {\n\t\t\treturn existing;\n\t\t}\n\t\tconst session = new Session(sessionId);\n\t\tassert(\n\t\t\tthis.uuidSpace.set(session.sessionUuid, session),\n\t\t\t0x760 /* Duplicate session in map. */,\n\t\t);\n\t\tthis.sessionCache.set(sessionId, session);\n\t\treturn session;\n\t}\n\n\tpublic get(sessionId: SessionId): Session | undefined {\n\t\treturn this.sessionCache.get(sessionId);\n\t}\n\n\tpublic getContainingCluster(\n\t\tquery: StableId,\n\t): [cluster: IdCluster, alignedLocal: LocalCompressedId] | undefined {\n\t\tconst numericStable = numericUuidFromStableId(query);\n\t\tconst possibleMatch = this.uuidSpace.getPairOrNextLower(numericStable);\n\t\tif (possibleMatch === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst [_, session] = possibleMatch;\n\t\tconst numericDelta = subtractNumericUuids(numericStable, session.sessionUuid);\n\t\tif (numericDelta > Number.MAX_SAFE_INTEGER) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst alignedLocal = localIdFromGenCount(Number(numericDelta) + 1);\n\t\tconst containingCluster = session.getClusterByLocal(alignedLocal, true);\n\t\tif (containingCluster === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn [containingCluster, alignedLocal];\n\t}\n\n\tpublic clusterCollides(cluster: IdCluster): boolean {\n\t\tconst { session: owningSession, baseLocalId, capacity } = cluster;\n\t\tconst clusterBaseNumeric = offsetNumericUuid(\n\t\t\towningSession.sessionUuid,\n\t\t\tgenCountFromLocalId(baseLocalId) - 1,\n\t\t);\n\t\tconst clusterMaxNumeric = offsetNumericUuid(clusterBaseNumeric, capacity - 1);\n\t\tlet closestMatch: [NumericUuid, Session] | undefined =\n\t\t\tthis.uuidSpace.getPairOrNextLower(clusterMaxNumeric);\n\t\t// Find the first session that is not the owner of this new cluster.\n\t\t// Once we have that, check to see if its cluster chain overlaps with the new cluster.\n\t\t// Consider the following diagram of UUID space:\n\t\t// Cluster chain A: |----------------------|\n\t\t// Cluster chain B: |----------|\n\t\t// Cluster chain C: |-------|\n\t\t// While it is true that when adding a cluster to chain C, we would find\n\t\t// the next lower session (which is B) and erroneously determine we do not collide\n\t\t// with any other session, but this situation is impossible to get into as B would\n\t\t// have detected that it collided with A (or the other way around, depending on ordering).\n\t\t// eslint-disable-next-line @typescript-eslint/prefer-optional-chain -- using ?. could change behavior\n\t\twhile (closestMatch !== undefined && closestMatch[1] === owningSession) {\n\t\t\tclosestMatch = this.uuidSpace.nextLowerPair(closestMatch[0]);\n\t\t}\n\t\tif (closestMatch === undefined) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst [_, session] = closestMatch;\n\t\tassert(session !== owningSession, 0x761 /* Failed to attempt to detect collisions. */);\n\t\tconst lastCluster = session.getLastCluster();\n\t\tif (lastCluster === undefined) {\n\t\t\t// If the closest session is empty (the local session), then it is guaranteed (probabilistically) that there are no\n\t\t\t// non-empty sessions that have a cluster chain that starts prior to the empty session and collides with the cluster\n\t\t\t// we are checking, so we can return false.\n\t\t\treturn false;\n\t\t}\n\t\tconst lastAllocatedNumeric = offsetNumericUuid(\n\t\t\tsession.sessionUuid,\n\t\t\tgenCountFromLocalId(lastAllocatedLocal(lastCluster)) - 1,\n\t\t);\n\t\treturn lastAllocatedNumeric >= clusterBaseNumeric;\n\t}\n\n\tpublic equals(other: Sessions, includeLocalState: boolean): boolean {\n\t\tconst checkIsSubset = (sessionsA: Sessions, sessionsB: Sessions): boolean => {\n\t\t\tconst first = sessionsA.sessions().next();\n\t\t\tconst firstSessionThis = first.done ? undefined : first.value;\n\t\t\tfor (const [stableId, session] of sessionsA.sessionCache.entries()) {\n\t\t\t\tconst otherSession = sessionsB.sessionCache.get(stableId);\n\t\t\t\tif (otherSession === undefined) {\n\t\t\t\t\tif (!session.isEmpty() || includeLocalState) {\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\tassert(\n\t\t\t\t\t\tsession === firstSessionThis,\n\t\t\t\t\t\t0x762 /* The only non-empty session must be the local session. */,\n\t\t\t\t\t);\n\t\t\t\t} else if (!session.equals(otherSession)) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t};\n\t\treturn checkIsSubset(this, other) && checkIsSubset(other, this);\n\t}\n}\n\n/**\n * The IDs created by a specific session, stored as a cluster chain to allow for fast conversions.\n */\nexport class Session {\n\t// All clusters created by this session, in creation order (thus sorted by base final and local ID).\n\tprivate readonly clusterChain: IdCluster[] = [];\n\t// The numeric form of the SessionId\n\tpublic readonly sessionUuid: NumericUuid;\n\n\tpublic constructor(sessionId: SessionId | NumericUuid) {\n\t\tthis.sessionUuid =\n\t\t\ttypeof sessionId === \"string\" ? numericUuidFromStableId(sessionId) : sessionId;\n\t}\n\n\t/**\n\t * Adds a new empty cluster to the cluster chain of this session.\n\t */\n\tpublic addNewCluster(\n\t\tbaseFinalId: FinalCompressedId,\n\t\tcapacity: number,\n\t\tcount: number,\n\t): IdCluster {\n\t\tconst lastCluster = this.getLastCluster();\n\t\tconst newCluster: IdCluster = {\n\t\t\tsession: this,\n\t\t\tbaseFinalId,\n\t\t\tbaseLocalId: (lastCluster === undefined\n\t\t\t\t? -1\n\t\t\t\t: lastAllocatedLocal(lastCluster) - 1) as LocalCompressedId,\n\t\t\tcapacity,\n\t\t\tcount,\n\t\t};\n\t\tthis.clusterChain.push(newCluster);\n\t\treturn newCluster;\n\t}\n\n\tpublic isEmpty(): boolean {\n\t\treturn this.clusterChain.length === 0;\n\t}\n\n\t/**\n\t * Returns the last cluster in this session's cluster chain, if any.\n\t */\n\tpublic getLastCluster(): IdCluster | undefined {\n\t\treturn this.clusterChain[this.clusterChain.length - 1];\n\t}\n\n\t/**\n\t * Converts the local ID from this session to a final ID, if possible.\n\t * @param includeAllocated - true if the conversion should succeed even if the local ID aligns with a part of the cluster that is allocated but not finalized.\n\t */\n\tpublic tryConvertToFinal(\n\t\tsearchLocal: LocalCompressedId,\n\t\tincludeAllocated: boolean,\n\t): FinalCompressedId | undefined {\n\t\tconst containingCluster = this.getClusterByLocal(searchLocal, includeAllocated);\n\t\tif (containingCluster === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn getAlignedFinal(containingCluster, searchLocal);\n\t}\n\n\t/**\n\t * Returns the cluster containing the supplied local ID, if possible.\n\t * @param includeAllocated - true if the conversion should succeed even if the local ID aligns with a part of the cluster that is allocated but not finalized.\n\t */\n\tpublic getClusterByLocal(\n\t\tlocalId: LocalCompressedId,\n\t\tincludeAllocated: boolean,\n\t): IdCluster | undefined {\n\t\tconst lastValidLocal: (cluster: IdCluster) => LocalCompressedId = includeAllocated\n\t\t\t? lastAllocatedLocal\n\t\t\t: lastFinalizedLocal;\n\t\tconst matchedCluster = Session.binarySearch(\n\t\t\tlocalId,\n\t\t\tthis.clusterChain,\n\t\t\t(local, cluster): number => {\n\t\t\t\tconst lastLocal = lastValidLocal(cluster);\n\t\t\t\tif (local < lastLocal) {\n\t\t\t\t\treturn 1;\n\t\t\t\t} else if (local > cluster.baseLocalId) {\n\t\t\t\t\treturn -1;\n\t\t\t\t} else {\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\t\treturn matchedCluster;\n\t}\n\n\t/**\n\t * Returns the cluster containing the supplied final ID, if possible.\n\t */\n\tpublic getClusterByAllocatedFinal(final: FinalCompressedId): IdCluster | undefined {\n\t\treturn Session.getContainingCluster(final, this.clusterChain);\n\t}\n\n\t/**\n\t * Returns the cluster from the supplied cluster chain containing the supplied final ID, if possible.\n\t * `clusterChain` must be sorted by final/local base ID.\n\t */\n\tpublic static getContainingCluster(\n\t\tfinalId: FinalCompressedId,\n\t\tclusterChain: readonly IdCluster[],\n\t): IdCluster | undefined {\n\t\treturn Session.binarySearch(finalId, clusterChain, (final, cluster) => {\n\t\t\tconst lastFinal = lastAllocatedFinal(cluster);\n\t\t\tif (final < cluster.baseFinalId) {\n\t\t\t\treturn -1;\n\t\t\t} else if (final > lastFinal) {\n\t\t\t\treturn 1;\n\t\t\t} else {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t});\n\t}\n\n\tstatic binarySearch<S, T>(\n\t\tsearch: S,\n\t\tarr: readonly T[],\n\t\tcomparator: (a: S, b: T) => number,\n\t): T | undefined {\n\t\tlet left = 0;\n\t\tlet right = arr.length - 1;\n\t\twhile (left <= right) {\n\t\t\tconst mid = Math.floor((left + right) / 2);\n\t\t\tconst value = arr[mid];\n\t\t\tassert(value !== undefined, 0x9dc /* value is undefined in Session.binarySearch */);\n\t\t\tconst c = comparator(search, value);\n\t\t\tif (c === 0) {\n\t\t\t\treturn value; // Found the target, return its index.\n\t\t\t} else if (c > 0) {\n\t\t\t\tleft = mid + 1; // Continue search on right half.\n\t\t\t} else {\n\t\t\t\tright = mid - 1; // Continue search on left half.\n\t\t\t}\n\t\t}\n\t\treturn undefined; // If we reach here, target is not in array.\n\t}\n\n\tpublic equals(other: Session): boolean {\n\t\tfor (const [index, value] of Object.entries(this.clusterChain)) {\n\t\t\tif (!clustersEqual(value, other.clusterChain[index] as IdCluster)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn this.sessionUuid === other.sessionUuid;\n\t}\n}\n\n/**\n * A cluster of final (sequenced via consensus), sequentially allocated compressed IDs.\n * A final ID in a cluster decompresses to a sequentially allocated UUID that is the result of adding its offset within\n * the cluster to base UUID for the session that created it.\n */\nexport interface IdCluster {\n\t/**\n\t * The session that created this cluster.\n\t */\n\treadonly session: Session;\n\n\t/**\n\t * The first final ID in the cluster.\n\t */\n\treadonly baseFinalId: FinalCompressedId;\n\n\t/**\n\t * The local ID aligned with `baseFinalId`.\n\t */\n\treadonly baseLocalId: LocalCompressedId;\n\n\t/**\n\t * The total number of final IDs reserved for allocation in the cluster.\n\t * Clusters are reserved in blocks as a performance optimization.\n\t */\n\tcapacity: number;\n\n\t/**\n\t * The number of final IDs currently allocated in the cluster.\n\t */\n\tcount: number;\n}\n\nexport function clustersEqual(a: IdCluster, b: IdCluster): boolean {\n\treturn (\n\t\ta.session.sessionUuid === b.session.sessionUuid &&\n\t\ta.baseFinalId === b.baseFinalId &&\n\t\ta.baseLocalId === b.baseLocalId &&\n\t\ta.capacity === b.capacity &&\n\t\ta.count === b.count\n\t);\n}\n\n/**\n * Returns the final ID that is aligned with the supplied local ID within a cluster.\n * Includes allocated IDs.\n */\nexport function getAlignedFinal(\n\tcluster: IdCluster,\n\tlocalWithin: LocalCompressedId,\n): FinalCompressedId | undefined {\n\tconst clusterOffset =\n\t\tgenCountFromLocalId(localWithin) - genCountFromLocalId(cluster.baseLocalId);\n\tif (clusterOffset < cluster.capacity) {\n\t\treturn ((cluster.baseFinalId as number) + clusterOffset) as FinalCompressedId;\n\t}\n\treturn undefined;\n}\n\n/**\n * Returns the local ID that is aligned with the supplied final ID within a cluster.\n * Fails if the supplied ID does not fall within the cluster bounds.\n */\nexport function getAlignedLocal(\n\tcluster: IdCluster,\n\tfinalWithin: FinalCompressedId,\n): LocalCompressedId {\n\tassert(\n\t\tfinalWithin >= cluster.baseFinalId && finalWithin <= lastAllocatedFinal(cluster),\n\t\t0x763 /* Supplied ID is not within the cluster. */,\n\t);\n\tconst finalDelta = finalWithin - cluster.baseFinalId;\n\treturn (cluster.baseLocalId - finalDelta) as LocalCompressedId;\n}\n\n/**\n * Returns the last allocated final ID (i.e. any ID between base final and base final + capacity) within a cluster\n */\nexport function lastAllocatedFinal(cluster: IdCluster): FinalCompressedId {\n\treturn ((cluster.baseFinalId as number) + (cluster.capacity - 1)) as FinalCompressedId;\n}\n\n/**\n * Returns the last allocated final ID (i.e. any ID between base final and base final + count) within a cluster\n */\nexport function lastFinalizedFinal(cluster: IdCluster): FinalCompressedId {\n\treturn ((cluster.baseFinalId as number) + (cluster.count - 1)) as FinalCompressedId;\n}\n\n/**\n * Returns the last allocated local ID (i.e. any ID between base local and base local + capacity) within a cluster\n */\nexport function lastAllocatedLocal(cluster: IdCluster): LocalCompressedId {\n\treturn ((cluster.baseLocalId as number) - (cluster.capacity - 1)) as LocalCompressedId;\n}\n\n/**\n * Returns the last allocated local ID (i.e. any ID between base local and base local + count) within a cluster\n */\nexport function lastFinalizedLocal(cluster: IdCluster): LocalCompressedId {\n\treturn ((cluster.baseLocalId as number) - (cluster.count - 1)) as LocalCompressedId;\n}\n"]}
@@ -4,7 +4,17 @@
4
4
  * Licensed under the MIT License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.createAlwaysFinalizedIdCompressor = exports.generateCompressedIds = exports.performFuzzActions = exports.makeOpGenerator = exports.mergeArrayMaps = exports.expectSerializes = exports.roundtrip = exports.IdCompressorTestNetwork = exports.sessionIds = exports.buildHugeCompressor = exports.getClusterSize = exports.modifyClusterSize = exports.CompressorFactory = exports.DestinationClient = exports.OriginatingClient = exports.OutsideClient = exports.MetaClient = exports.Client = void 0;
7
+ exports.IdCompressorTestNetwork = exports.sessionIds = exports.CompressorFactory = exports.DestinationClient = exports.OriginatingClient = exports.OutsideClient = exports.MetaClient = exports.Client = void 0;
8
+ exports.modifyClusterSize = modifyClusterSize;
9
+ exports.getClusterSize = getClusterSize;
10
+ exports.buildHugeCompressor = buildHugeCompressor;
11
+ exports.roundtrip = roundtrip;
12
+ exports.expectSerializes = expectSerializes;
13
+ exports.mergeArrayMaps = mergeArrayMaps;
14
+ exports.makeOpGenerator = makeOpGenerator;
15
+ exports.performFuzzActions = performFuzzActions;
16
+ exports.generateCompressedIds = generateCompressedIds;
17
+ exports.createAlwaysFinalizedIdCompressor = createAlwaysFinalizedIdCompressor;
8
18
  const node_assert_1 = require("node:assert");
9
19
  const stochastic_test_utils_1 = require("@fluid-private/stochastic-test-utils");
10
20
  const idCompressor_js_1 = require("../idCompressor.js");
@@ -67,7 +77,6 @@ function modifyClusterSize(compressor, newClusterSize) {
67
77
  // eslint-disable-next-line @typescript-eslint/dot-notation
68
78
  compressor["nextRequestedClusterSize"] = newClusterSize;
69
79
  }
70
- exports.modifyClusterSize = modifyClusterSize;
71
80
  /**
72
81
  * Returns the current cluster size of the compressor.
73
82
  * @privateRemarks
@@ -78,7 +87,6 @@ function getClusterSize(compressor) {
78
87
  // eslint-disable-next-line @typescript-eslint/dot-notation
79
88
  return compressor["nextRequestedClusterSize"];
80
89
  }
81
- exports.getClusterSize = getClusterSize;
82
90
  function verifyCompressorLike(compressor) {
83
91
  (0, node_assert_1.strict)(
84
92
  // Some IdCompressor tests wrap underlying compressors with proxies--allow this for now.
@@ -118,7 +126,6 @@ function buildHugeCompressor(numSessions = 10000, capacity = 10, numClustersPerS
118
126
  }
119
127
  return compressor;
120
128
  }
121
- exports.buildHugeCompressor = buildHugeCompressor;
122
129
  function makeSessionIds() {
123
130
  const stableIds = new Map();
124
131
  const clients = Object.values(Client);
@@ -139,12 +146,29 @@ exports.sessionIds = makeSessionIds();
139
146
  * Not suitable for performance testing.
140
147
  */
141
148
  class IdCompressorTestNetwork {
149
+ initialClusterSize;
150
+ /**
151
+ * The compressors used in this network
152
+ */
153
+ compressors;
154
+ /**
155
+ * The log of operations seen by the server so far. Append-only.
156
+ */
157
+ serverOperations = [];
158
+ /**
159
+ * An index into `serverOperations` for each client which represents how many operations have been delivered to that client
160
+ */
161
+ clientProgress;
162
+ /**
163
+ * All ids (local and sequenced) that a client has created or received, in order.
164
+ */
165
+ idLogs;
166
+ /**
167
+ * All ids that a client has received from the server, in order.
168
+ */
169
+ sequencedIdLogs;
142
170
  constructor(initialClusterSize = 5) {
143
171
  this.initialClusterSize = initialClusterSize;
144
- /**
145
- * The log of operations seen by the server so far. Append-only.
146
- */
147
- this.serverOperations = [];
148
172
  const compressors = new Map();
149
173
  const clientProgress = new Map();
150
174
  const clientIds = new Map();
@@ -518,7 +542,6 @@ function roundtrip(compressor, withSession) {
518
542
  return [nonLocalSerialized, roundtripped];
519
543
  }
520
544
  }
521
- exports.roundtrip = roundtrip;
522
545
  /**
523
546
  * Asserts that the supplied compressor correctly roundtrips through serialization/deserialization.
524
547
  */
@@ -540,7 +563,6 @@ function expectSerializes(compressor) {
540
563
  expectSerializesWithSession(true),
541
564
  ];
542
565
  }
543
- exports.expectSerializes = expectSerializes;
544
566
  /**
545
567
  * Merges 'from' into 'to', and returns 'to'.
546
568
  */
@@ -556,7 +578,6 @@ function mergeArrayMaps(to, from) {
556
578
  }
557
579
  return to;
558
580
  }
559
- exports.mergeArrayMaps = mergeArrayMaps;
560
581
  const defaultOptions = {
561
582
  maxClusterSize: 25,
562
583
  validateInterval: 200,
@@ -628,7 +649,6 @@ function makeOpGenerator(options) {
628
649
  [reconnectGenerator, 1],
629
650
  ]), (0, stochastic_test_utils_1.take)(1, (0, stochastic_test_utils_1.repeat)({ type: "validate" })), validateInterval);
630
651
  }
631
- exports.makeOpGenerator = makeOpGenerator;
632
652
  /**
633
653
  * Performs random actions on a test network.
634
654
  * @param generator - the generator used to provide operations
@@ -685,7 +705,6 @@ function performFuzzActions(generator, network, seed, observerClient, synchroniz
685
705
  validator?.(network);
686
706
  }
687
707
  }
688
- exports.performFuzzActions = performFuzzActions;
689
708
  /**
690
709
  * Helper to generate a fixed number of IDs.
691
710
  */
@@ -696,7 +715,6 @@ function generateCompressedIds(compressor, count) {
696
715
  }
697
716
  return ids;
698
717
  }
699
- exports.generateCompressedIds = generateCompressedIds;
700
718
  function createAlwaysFinalizedIdCompressor(sessionIdOrLogger, loggerOrUndefined, seed) {
701
719
  const random = seed === undefined ? (0, stochastic_test_utils_1.makeRandom)() : (0, stochastic_test_utils_1.makeRandom)(seed);
702
720
  const sessionId = typeof sessionIdOrLogger === "string" ? sessionIdOrLogger : random.uuid4();
@@ -711,5 +729,4 @@ function createAlwaysFinalizedIdCompressor(sessionIdOrLogger, loggerOrUndefined,
711
729
  compressor.startGhostSession(sessionId);
712
730
  return (0, index_js_1.toIdCompressorWithCore)(compressor);
713
731
  }
714
- exports.createAlwaysFinalizedIdCompressor = createAlwaysFinalizedIdCompressor;
715
732
  //# sourceMappingURL=idCompressorTestUtilities.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"idCompressorTestUtilities.js","sourceRoot":"","sources":["../../src/test/idCompressorTestUtilities.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,6CAA+C;AAE/C,gFAU8C;AAG9C,wDAAkD;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Aa;IAEb,MAAM,GAAG,GAA+B,EAAE,CAAC;IAC3C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;QAChC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,oBAAoB,EAAE,CAAC,CAAC;IAC7C,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC;AATD,sDASC;AAkBD,SAAgB,iCAAiC,CAChD,iBAAoD,EACpD,iBAAwC,EACxC,IAAa;IAEb,MAAM,MAAM,GAAG,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,IAAA,kCAAU,GAAE,CAAC,CAAC,CAAC,IAAA,kCAAU,EAAC,IAAI,CAAC,CAAC;IACpE,MAAM,SAAS,GACd,OAAO,iBAAiB,KAAK,QAAQ,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAE,MAAM,CAAC,KAAK,EAAgB,CAAC;IAC3F,MAAM,MAAM,GACX,CAAC,iBAAiB,IAAI,OAAO,iBAAiB,KAAK,QAAQ,CAAC;QAC3D,CAAC,CAAE,iBAA0C;QAC7C,CAAC,CAAC,SAAS,CAAC;IACd,6GAA6G;IAC7G,0GAA0G;IAC1G,6CAA6C;IAC7C,MAAM,UAAU,GAAG,IAAA,6BAAkB,EAAC,MAAM,CAAC,KAAK,EAAe,EAAE,MAAM,CAAC,CAAC;IAC3E,oDAAoD;IACnD,UAA2B,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;IAC1D,OAAO,IAAA,iCAAsB,EAAC,UAAU,CAAC,CAAC;AAC3C,CAAC;AAnBD,8EAmBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { strict as assert } from \"node:assert\";\n\nimport {\n\ttype BaseFuzzTestState,\n\ttype Generator,\n\ttype SaveInfo,\n\tcreateWeightedGenerator,\n\tinterleave,\n\tmakeRandom,\n\tperformFuzzActions as performFuzzActionsBase,\n\trepeat,\n\ttake,\n} from \"@fluid-private/stochastic-test-utils\";\nimport type { ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\n\nimport { IdCompressor } from \"../idCompressor.js\";\nimport {\n\ttype IIdCompressor,\n\ttype IIdCompressorCore,\n\ttype IdCreationRange,\n\ttype OpSpaceCompressedId,\n\ttype SerializedIdCompressorWithNoSession,\n\ttype SerializedIdCompressorWithOngoingSession,\n\ttype SessionId,\n\ttype SessionSpaceCompressedId,\n\ttype StableId,\n\tcreateIdCompressor,\n\ttoIdCompressorWithCore,\n} from \"../index.js\";\nimport { SessionSpaceNormalizer } from \"../sessionSpaceNormalizer.js\";\nimport { assertIsSessionId, createSessionId, localIdFromGenCount } from \"../utilities.js\";\n\nimport {\n\ttype FinalCompressedId,\n\ttype ReadonlyIdCompressor,\n\tfail,\n\tgetOrCreate,\n\tincrementStableId,\n\tisFinalId,\n\tisLocalId,\n} from \"./testCommon.js\";\n\n/**\n * A readonly `Map` which is known to contain a value for every possible key\n */\nexport interface ClosedMap<K, V> extends Omit<Map<K, V>, \"delete\" | \"clear\"> {\n\tget(key: K): V;\n}\n\n/**\n * Identifies a compressor in a network\n */\nexport enum Client {\n\tClient1 = \"Client1\",\n\tClient2 = \"Client2\",\n\tClient3 = \"Client3\",\n}\n\n/**\n * Identifies categories of compressors\n */\nexport enum MetaClient {\n\tAll = \"All\",\n}\n\n/**\n * Identifies a compressor inside the network but outside the three specially tracked clients.\n */\nexport enum OutsideClient {\n\tRemote = \"Remote\",\n}\n\n/**\n * Used to attribute actions to clients in a distributed collaboration session.\n * `Local` implies a local and unsequenced operation. All others imply sequenced operations.\n */\nexport type OriginatingClient = Client | OutsideClient;\nexport const OriginatingClient = { ...Client, ...OutsideClient };\n\n/**\n * Identifies a compressor to which to send an operation\n */\nexport type DestinationClient = Client | MetaClient;\nexport const DestinationClient = { ...Client, ...MetaClient };\n\n// eslint-disable-next-line @typescript-eslint/no-extraneous-class\nexport class CompressorFactory {\n\t/**\n\t * Creates a new compressor with the supplied cluster capacity.\n\t */\n\tpublic static createCompressor(\n\t\tclient: Client,\n\t\tclusterCapacity = 5,\n\t\tlogger?: ITelemetryBaseLogger,\n\t): IdCompressor {\n\t\treturn CompressorFactory.createCompressorWithSession(\n\t\t\tsessionIds.get(client),\n\t\t\tclusterCapacity,\n\t\t\tlogger,\n\t\t);\n\t}\n\n\t/**\n\t * Creates a new compressor with the supplied cluster capacity.\n\t */\n\tpublic static createCompressorWithSession(\n\t\tsessionId: SessionId,\n\t\tclusterCapacity = 5,\n\t\tlogger?: ITelemetryBaseLogger,\n\t): IdCompressor {\n\t\tconst compressor = createIdCompressor(sessionId, logger) as IdCompressor;\n\t\tmodifyClusterSize(compressor, clusterCapacity);\n\t\treturn compressor;\n\t}\n}\n\n/**\n * Modify the requested cluster size of the provided compressor.\n * @remarks\n * This is useful for testing purposes for a few reasons:\n * - Id compressor bugs are often related to edge cases that occur on cluster boundaries\n * - Smaller cluster sizes can enable writing tests without for loops generating \"ids until a new cluster is created\"\n */\nexport function modifyClusterSize(compressor: IIdCompressor, newClusterSize: number): void {\n\tverifyCompressorLike(compressor);\n\t// eslint-disable-next-line @typescript-eslint/dot-notation\n\tcompressor[\"nextRequestedClusterSize\"] = newClusterSize;\n}\n\n/**\n * Returns the current cluster size of the compressor.\n * @privateRemarks\n * This is useful in writing tests to avoid having to hardcode the (currently constant) cluster size.\n */\nexport function getClusterSize(compressor: ReadonlyIdCompressor): number {\n\tverifyCompressorLike(compressor);\n\t// eslint-disable-next-line @typescript-eslint/dot-notation\n\treturn compressor[\"nextRequestedClusterSize\"] as number;\n}\n\nfunction verifyCompressorLike(compressor: ReadonlyIdCompressor | IIdCompressor): void {\n\tassert(\n\t\t// Some IdCompressor tests wrap underlying compressors with proxies--allow this for now.\n\t\t// Because of id-compressor's dynamic import in container-runtime, instanceof checks for IdCompressor\n\t\t// also won't necessarily work nicely. Get a small amount of validation that this function should work\n\t\t// as intended by at least verifying the property name exists.\n\t\t// eslint-disable-next-line @typescript-eslint/dot-notation\n\t\ttypeof compressor[\"nextRequestedClusterSize\"] === \"number\",\n\t);\n}\n\n/**\n * Utility for building a huge compressor.\n * Build via the compressor factory.\n */\nexport function buildHugeCompressor(\n\tnumSessions = 10000,\n\tcapacity = 10,\n\tnumClustersPerSession = 3,\n): IdCompressor {\n\tconst compressor = CompressorFactory.createCompressorWithSession(\n\t\tcreateSessionId(),\n\t\tcapacity,\n\t);\n\tconst sessions: SessionId[] = [];\n\tfor (let i = 0; i < numSessions; i++) {\n\t\tsessions.push(createSessionId());\n\t}\n\tfor (let i = 0; i < numSessions * numClustersPerSession; i++) {\n\t\tconst sessionId = sessions[i % numSessions];\n\t\tif (Math.random() > 0.1) {\n\t\t\tfor (let j = 0; j < Math.round(capacity / 2); j++) {\n\t\t\t\tcompressor.generateCompressedId();\n\t\t\t}\n\t\t\tcompressor.finalizeCreationRange(compressor.takeNextCreationRange());\n\t\t}\n\t\tcompressor.finalizeCreationRange({\n\t\t\tsessionId,\n\t\t\tids: {\n\t\t\t\tfirstGenCount: Math.floor(i / numSessions) * capacity + 1,\n\t\t\t\tcount: capacity,\n\t\t\t\trequestedClusterSize: capacity,\n\t\t\t\tlocalIdRanges: [], // remote session, can safely ignore in tests\n\t\t\t},\n\t\t});\n\t}\n\treturn compressor;\n}\n\n/**\n * A closed map from NamedClient to T.\n */\nexport type ClientMap<T> = ClosedMap<Client, T>;\n\nfunction makeSessionIds(): ClientMap<SessionId> {\n\tconst stableIds = new Map<Client, SessionId>();\n\tconst clients = Object.values(Client);\n\tfor (let i = 0; i < clients.length; i++) {\n\t\t// Place session uuids roughly in the middle of uuid space to increase odds of encountering interesting\n\t\t// orderings in sorted collections\n\t\tconst sessionId = assertIsSessionId(`88888888-8888-4888-b${i}88-888888888888`);\n\t\tstableIds.set(clients[i], sessionId);\n\t}\n\treturn stableIds as ClientMap<SessionId>;\n}\n\n/**\n * An array of session ID strings corresponding to all non-local `Client` entries.\n */\nexport const sessionIds = makeSessionIds();\n\n/**\n * Information about a generated ID in a network to be validated by tests\n */\nexport interface TestIdData {\n\treadonly id: SessionSpaceCompressedId;\n\treadonly originatingClient: OriginatingClient;\n\treadonly sessionId: SessionId;\n\treadonly isSequenced: boolean;\n}\n\n/**\n * Simulates a network of ID compressors.\n * Not suitable for performance testing.\n */\nexport class IdCompressorTestNetwork {\n\t/**\n\t * The compressors used in this network\n\t */\n\tprivate readonly compressors: ClientMap<IdCompressor>;\n\t/**\n\t * The log of operations seen by the server so far. Append-only.\n\t */\n\tprivate readonly serverOperations: [\n\t\tcreationRange: IdCreationRange,\n\t\topSpaceIds: OpSpaceCompressedId[],\n\t\tclientFrom: OriginatingClient,\n\t\tsessionIdFrom: SessionId,\n\t][] = [];\n\t/**\n\t * An index into `serverOperations` for each client which represents how many operations have been delivered to that client\n\t */\n\tprivate readonly clientProgress: ClientMap<number>;\n\t/**\n\t * All ids (local and sequenced) that a client has created or received, in order.\n\t */\n\tprivate readonly idLogs: ClientMap<TestIdData[]>;\n\t/**\n\t * All ids that a client has received from the server, in order.\n\t */\n\tprivate readonly sequencedIdLogs: ClientMap<TestIdData[]>;\n\n\tpublic constructor(public readonly initialClusterSize = 5) {\n\t\tconst compressors = new Map<Client, IdCompressor>();\n\t\tconst clientProgress = new Map<Client, number>();\n\t\tconst clientIds = new Map<Client, TestIdData[]>();\n\t\tconst clientSequencedIds = new Map<Client, TestIdData[]>();\n\t\tfor (const client of Object.values(Client)) {\n\t\t\tconst compressor = CompressorFactory.createCompressor(client, initialClusterSize);\n\t\t\tcompressors.set(client, compressor);\n\t\t\tclientProgress.set(client, 0);\n\t\t\tclientIds.set(client, []);\n\t\t\tclientSequencedIds.set(client, []);\n\t\t}\n\t\tthis.compressors = compressors as ClientMap<IdCompressor>;\n\t\tthis.clientProgress = clientProgress as ClientMap<number>;\n\t\tthis.idLogs = clientIds as ClientMap<TestIdData[]>;\n\t\tthis.sequencedIdLogs = clientSequencedIds as ClientMap<TestIdData[]>;\n\t}\n\n\t/**\n\t * Returns the number of undelivered operations for the given client that are in flight in the network.\n\t */\n\tpublic getPendingOperations(destination: Client): number {\n\t\treturn this.serverOperations.length - this.clientProgress.get(destination);\n\t}\n\n\t/**\n\t * Returns an immutable handle to a compressor in the network.\n\t */\n\tpublic getCompressor(client: Client): ReadonlyIdCompressor {\n\t\tconst compressors = this.compressors;\n\t\tconst handler = {\n\t\t\tget<P extends keyof IdCompressor>(_: unknown, property: P): IdCompressor[P] {\n\t\t\t\treturn compressors.get(client)[property];\n\t\t\t},\n\t\t\tset<P extends keyof IdCompressor>(\n\t\t\t\t_: unknown,\n\t\t\t\tproperty: P,\n\t\t\t\tvalue: IdCompressor[P],\n\t\t\t): boolean {\n\t\t\t\tcompressors.get(client)[property] = value;\n\t\t\t\treturn true;\n\t\t\t},\n\t\t};\n\t\treturn new Proxy<IdCompressor>({} as unknown as IdCompressor, handler);\n\t}\n\n\t/**\n\t * Returns a mutable handle to a compressor in the network. Use of mutation methods will break the network invariants and\n\t * should only be used if the network will not be used again.\n\t */\n\tpublic getCompressorUnsafe(client: Client): IdCompressor {\n\t\treturn this.getCompressor(client) as IdCompressor;\n\t}\n\n\t/**\n\t * Returns a mutable handle to a compressor in the network. Use of mutation methods will break the network invariants and\n\t * should only be used if the network will not be used again. Additionally, the returned compressor will be invalidated/unusable\n\t * if any network operations cause it to be regenerated (serialization/deserialization, etc.).\n\t */\n\tpublic getCompressorUnsafeNoProxy(client: Client): IdCompressor {\n\t\treturn this.compressors.get(client);\n\t}\n\n\t/**\n\t * Returns data for all IDs created and received by this client, including ack's of their own (i.e. their own IDs will appear twice)\n\t */\n\tpublic getIdLog(client: Client): readonly TestIdData[] {\n\t\treturn this.idLogs.get(client);\n\t}\n\n\t/**\n\t * Returns data for all IDs received by this client, including ack's of their own.\n\t */\n\tpublic getSequencedIdLog(client: Client): readonly TestIdData[] {\n\t\treturn this.sequencedIdLogs.get(client);\n\t}\n\n\t/**\n\t * Get all compressors for the given destination\n\t */\n\tpublic getTargetCompressors(clientTo: DestinationClient): [Client, IdCompressor][] {\n\t\treturn clientTo === MetaClient.All\n\t\t\t? [...this.compressors.entries()]\n\t\t\t: ([[clientTo, this.getCompressor(clientTo)]] as [Client, IdCompressor][]);\n\t}\n\n\t/**\n\t * Changes the capacity request amount for a client. It will take effect immediately.\n\t */\n\tpublic changeCapacity(client: Client, newClusterCapacity: number): void {\n\t\tmodifyClusterSize(this.compressors.get(client), newClusterCapacity);\n\t}\n\n\tprivate addNewId(\n\t\tclient: Client,\n\t\tid: SessionSpaceCompressedId,\n\t\toriginatingClient: OriginatingClient,\n\t\tsessionIdFrom: SessionId,\n\t\tisSequenced: boolean,\n\t): void {\n\t\tconst idData = {\n\t\t\tid,\n\t\t\toriginatingClient,\n\t\t\tsessionId: sessionIdFrom,\n\t\t\tisSequenced,\n\t\t};\n\t\tconst clientIds = this.idLogs.get(client);\n\t\tclientIds.push(idData);\n\t\tif (isSequenced) {\n\t\t\tconst sequencedIds = this.sequencedIdLogs.get(client);\n\t\t\tsequencedIds.push(idData);\n\t\t}\n\t}\n\n\t/**\n\t * Allocates a new range of local IDs and enqueues them for future delivery via a `testIdDelivery` action.\n\t * Calls to this method determine the total order of delivery, regardless of when `deliverOperations` is called.\n\t */\n\tpublic allocateAndSendIds(clientFrom: Client, numIds: number): OpSpaceCompressedId[] {\n\t\treturn this.allocateAndSendIdsFromRemoteClient(\n\t\t\tclientFrom,\n\t\t\tsessionIds.get(clientFrom),\n\t\t\tnumIds,\n\t\t);\n\t}\n\n\t/**\n\t * Same contract as `allocateAndSendIds`, but the originating client will be a client with the supplied sessionId.\n\t */\n\tpublic allocateAndSendIdsFromRemoteClient(\n\t\tclientFrom: OriginatingClient,\n\t\tsessionIdFrom: SessionId,\n\t\tnumIds: number,\n\t): OpSpaceCompressedId[] {\n\t\tassert(numIds > 0, \"Must allocate a non-zero number of IDs\");\n\t\tif (clientFrom === OriginatingClient.Remote) {\n\t\t\tconst range: IdCreationRange = {\n\t\t\t\tsessionId: sessionIdFrom,\n\t\t\t\tids: {\n\t\t\t\t\tfirstGenCount: 1,\n\t\t\t\t\tcount: numIds,\n\t\t\t\t\trequestedClusterSize: getClusterSize(this.getCompressor(Client.Client1)),\n\t\t\t\t\tlocalIdRanges: [], // remote session, can safely ignore in tests\n\t\t\t\t},\n\t\t\t};\n\t\t\tconst opSpaceIds: OpSpaceCompressedId[] = [];\n\t\t\tfor (let i = 0; i < numIds; i++) {\n\t\t\t\topSpaceIds.push(-(i + 1) as OpSpaceCompressedId);\n\t\t\t}\n\t\t\tthis.serverOperations.push([range, opSpaceIds, clientFrom, sessionIdFrom]);\n\t\t\treturn opSpaceIds;\n\t\t} else {\n\t\t\tassert(sessionIdFrom === sessionIds.get(clientFrom));\n\t\t\tconst compressor = this.compressors.get(clientFrom);\n\t\t\tconst sessionSpaceIds = generateCompressedIds(compressor, numIds);\n\t\t\tfor (let i = 0; i < numIds; i++) {\n\t\t\t\tthis.addNewId(clientFrom, sessionSpaceIds[i], clientFrom, sessionIdFrom, false);\n\t\t\t}\n\t\t\tconst opSpaceIds = sessionSpaceIds.map((id) => compressor.normalizeToOpSpace(id));\n\t\t\tconst creationRange = compressor.takeNextCreationRange();\n\t\t\tthis.serverOperations.push([creationRange, opSpaceIds, clientFrom, sessionIdFrom]);\n\t\t\treturn opSpaceIds;\n\t\t}\n\t}\n\n\t/**\n\t * Delivers all undelivered ID ranges from the server to the target clients.\n\t */\n\tpublic deliverOperations(clientTakingDelivery: Client, opsToDeliver?: number): void;\n\n\t/**\n\t * Delivers all undelivered ID ranges from the server to the target clients.\n\t */\n\tpublic deliverOperations(clientTakingDelivery: DestinationClient): void;\n\n\t/**\n\t * Delivers all undelivered ID ranges from the server to the target clients.\n\t */\n\tpublic deliverOperations(\n\t\tclientTakingDelivery: DestinationClient,\n\t\topsToDeliver?: number,\n\t): void {\n\t\tlet opIndexBound: number;\n\t\tif (clientTakingDelivery === DestinationClient.All) {\n\t\t\tassert(opsToDeliver === undefined);\n\t\t\topIndexBound = this.serverOperations.length;\n\t\t} else {\n\t\t\topIndexBound =\n\t\t\t\topsToDeliver === undefined\n\t\t\t\t\t? this.serverOperations.length\n\t\t\t\t\t: this.clientProgress.get(clientTakingDelivery) + opsToDeliver;\n\t\t}\n\t\tfor (const [clientTo, compressorTo] of this.getTargetCompressors(clientTakingDelivery)) {\n\t\t\tfor (let i = this.clientProgress.get(clientTo); i < opIndexBound; i++) {\n\t\t\t\tconst [range, opSpaceIds, clientFrom, sessionIdFrom] = this.serverOperations[i];\n\t\t\t\tcompressorTo.finalizeCreationRange(range);\n\n\t\t\t\tconst ids = range.ids;\n\t\t\t\tif (ids !== undefined) {\n\t\t\t\t\tfor (const id of opSpaceIds) {\n\t\t\t\t\t\tconst sessionSpaceId = compressorTo.normalizeToSessionSpace(id, range.sessionId);\n\t\t\t\t\t\tthis.addNewId(clientTo, sessionSpaceId, clientFrom, sessionIdFrom, true);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.clientProgress.set(clientTo, opIndexBound);\n\t\t}\n\t}\n\n\t/**\n\t * Simulate a client disconnecting (and serializing), then reconnecting (and deserializing)\n\t */\n\tpublic goOfflineThenResume(client: Client): void {\n\t\tconst compressor = this.compressors.get(client);\n\t\tconst [_, resumedCompressor] = roundtrip(compressor, true);\n\t\tthis.compressors.set(client, resumedCompressor);\n\t}\n\n\t/**\n\t * Ensure general validity of the network state. Useful for calling periodically or at the end of test scenarios.\n\t */\n\tpublic assertNetworkState(): void {\n\t\tconst sequencedLogs = Object.values(Client).map(\n\t\t\t(client) => [this.compressors.get(client), this.getSequencedIdLog(client)] as const,\n\t\t);\n\n\t\tconst getLocalIdsInRange = (\n\t\t\trange: IdCreationRange,\n\t\t\topSpaceIds?: OpSpaceCompressedId[],\n\t\t): Set<SessionSpaceCompressedId> => {\n\t\t\tconst localIdsInCreationRange = new Set<SessionSpaceCompressedId>();\n\t\t\tconst ids = range.ids;\n\t\t\tif (ids !== undefined) {\n\t\t\t\tconst { firstGenCount, localIdRanges } = ids;\n\t\t\t\tfor (const [genCount, count] of localIdRanges) {\n\t\t\t\t\tfor (let g = genCount; g < genCount + count; g++) {\n\t\t\t\t\t\tconst local = localIdFromGenCount(g);\n\t\t\t\t\t\tif (opSpaceIds) {\n\t\t\t\t\t\t\tassert.strictEqual(opSpaceIds[g - firstGenCount], local);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlocalIdsInCreationRange.add(local);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn localIdsInCreationRange;\n\t\t};\n\n\t\t// Ensure creation ranges for clients we track contain the correct local ID ranges\n\t\tfor (const [range, opSpaceIds, clientFrom] of this.serverOperations) {\n\t\t\tif (clientFrom !== OriginatingClient.Remote) {\n\t\t\t\tconst localIdsInCreationRange = getLocalIdsInRange(range, opSpaceIds);\n\t\t\t\tlet localCount = 0;\n\t\t\t\tfor (const id of opSpaceIds) {\n\t\t\t\t\tif (isLocalId(id)) {\n\t\t\t\t\t\tlocalCount++;\n\t\t\t\t\t\tassert(localIdsInCreationRange.has(id), \"Local ID not in creation range\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tassert.strictEqual(\n\t\t\t\t\tlocalCount,\n\t\t\t\t\tlocalIdsInCreationRange.size,\n\t\t\t\t\t\"Local ID count mismatch\",\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tconst undeliveredRanges = new Map<Client, IdCreationRange[]>();\n\t\tfor (const [client, progress] of this.clientProgress.entries()) {\n\t\t\tconst ranges = this.serverOperations\n\t\t\t\t.slice(progress)\n\t\t\t\t.filter((op) => op[2] === client)\n\t\t\t\t.map(([range]) => range);\n\t\t\tundeliveredRanges.set(client, ranges);\n\t\t}\n\t\tfor (const [client, ranges] of undeliveredRanges.entries()) {\n\t\t\tconst compressor = this.compressors.get(client);\n\t\t\tlet firstGenCount: number | undefined;\n\t\t\tlet totalCount = 0;\n\t\t\tconst unionedLocalRanges = new SessionSpaceNormalizer();\n\t\t\tfor (const range of ranges) {\n\t\t\t\tassert(range.sessionId === compressor.localSessionId);\n\t\t\t\tif (range.ids !== undefined) {\n\t\t\t\t\t// initialize firstGenCount if not set\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ??= could change behavior if value is falsy\n\t\t\t\t\tif (firstGenCount === undefined) {\n\t\t\t\t\t\tfirstGenCount = range.ids.firstGenCount;\n\t\t\t\t\t}\n\t\t\t\t\ttotalCount += range.ids.count;\n\t\t\t\t\tfor (const [genCount, count] of range.ids.localIdRanges) {\n\t\t\t\t\t\tunionedLocalRanges.addLocalRange(genCount, count);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst retakenRange = compressor.takeUnfinalizedCreationRange();\n\t\t\tif (retakenRange.ids === undefined) {\n\t\t\t\tassert.strictEqual(totalCount, 0);\n\t\t\t\tassert.strictEqual(unionedLocalRanges.idRanges.size, 0);\n\t\t\t} else {\n\t\t\t\tconst retakenLocalIds = new SessionSpaceNormalizer();\n\t\t\t\tfor (const [genCount, count] of retakenRange.ids.localIdRanges) {\n\t\t\t\t\tretakenLocalIds.addLocalRange(genCount, count);\n\t\t\t\t}\n\t\t\t\tassert.strictEqual(\n\t\t\t\t\tretakenLocalIds.equals(unionedLocalRanges),\n\t\t\t\t\ttrue,\n\t\t\t\t\t\"Local ID ranges mismatch\",\n\t\t\t\t);\n\t\t\t\tassert.strictEqual(retakenRange.ids.count, totalCount, \"Count mismatch\");\n\t\t\t\tassert.strictEqual(retakenRange.ids.firstGenCount, firstGenCount, \"Count mismatch\");\n\t\t\t}\n\t\t}\n\n\t\t// First, ensure all clients each generated a unique ID for each of their own calls to generate.\n\t\tfor (const [compressor, ids] of sequencedLogs) {\n\t\t\tconst allUuids = new Set<StableId | string>();\n\t\t\tfor (const idData of ids) {\n\t\t\t\tconst uuid = compressor.decompress(idData.id);\n\t\t\t\tassert.strictEqual(!allUuids.has(uuid), true, \"Duplicate UUID generated.\");\n\t\t\t\tallUuids.add(uuid);\n\t\t\t}\n\t\t}\n\n\t\tconst maxLogLength = sequencedLogs\n\t\t\t.map(([_, data]) => data.length)\n\t\t\t// eslint-disable-next-line unicorn/no-array-reduce\n\t\t\t.reduce((p, n) => Math.max(p, n));\n\n\t\tfunction getNextLogWithEntryAt(logsIndex: number, entryIndex: number): number | undefined {\n\t\t\tfor (let i = logsIndex; i < sequencedLogs.length; i++) {\n\t\t\t\tconst log = sequencedLogs[i];\n\t\t\t\tif (log[1].length > entryIndex) {\n\t\t\t\t\treturn i;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst uuids = new Set<StableId>();\n\t\tconst finalIds = new Set<FinalCompressedId>();\n\t\tconst idIndicesAggregator = new Map<SessionId, number>();\n\n\t\tfunction* getIdLogEntries(\n\t\t\tcolumnIndex: number,\n\t\t): Iterable<\n\t\t\t[\n\t\t\t\tcurrent: [compressor: IdCompressor, idData: TestIdData],\n\t\t\t\tnext?: [compressor: IdCompressor, idData: TestIdData],\n\t\t\t]\n\t\t> {\n\t\t\tlet current = getNextLogWithEntryAt(0, columnIndex);\n\t\t\twhile (current !== undefined) {\n\t\t\t\tconst next = getNextLogWithEntryAt(current + 1, columnIndex);\n\t\t\t\tconst [compressor, log] = sequencedLogs[current];\n\t\t\t\tif (next === undefined) {\n\t\t\t\t\tyield [[compressor, log[columnIndex]]];\n\t\t\t\t} else {\n\t\t\t\t\tconst [compressorNext, logNext] = sequencedLogs[next];\n\t\t\t\t\tyield [\n\t\t\t\t\t\t[compressor, log[columnIndex]],\n\t\t\t\t\t\t[compressorNext, logNext[columnIndex]],\n\t\t\t\t\t];\n\t\t\t\t}\n\t\t\t\tcurrent = next;\n\t\t\t}\n\t\t}\n\n\t\tfor (let i = 0; i < maxLogLength; i++) {\n\t\t\tlet idCreatorCount = 0;\n\t\t\tlet originatingSession: SessionId | undefined;\n\t\t\tfor (const [current, next] of getIdLogEntries(i)) {\n\t\t\t\tconst [compressorA, idDataA] = current;\n\t\t\t\tconst sessionSpaceIdA = idDataA.id;\n\t\t\t\tconst idIndex = getOrCreate(idIndicesAggregator, idDataA.sessionId, () => 0);\n\t\t\t\toriginatingSession ??= idDataA.sessionId;\n\t\t\t\tassert(\n\t\t\t\t\tidDataA.sessionId === originatingSession,\n\t\t\t\t\t\"Test infra gave wrong originating client to TestIdData\",\n\t\t\t\t);\n\n\t\t\t\t// Only one client should have this ID as local in its session space, as only one client could have created this ID\n\t\t\t\tif (isLocalId(sessionSpaceIdA)) {\n\t\t\t\t\tif (originatingSession !== OriginatingClient.Remote) {\n\t\t\t\t\t\tassert.strictEqual(\n\t\t\t\t\t\t\tidDataA.sessionId,\n\t\t\t\t\t\t\tthis.compressors.get(idDataA.originatingClient as Client).localSessionId,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tidCreatorCount++;\n\t\t\t\t}\n\n\t\t\t\tconst uuidASessionSpace = compressorA.decompress(sessionSpaceIdA);\n\t\t\t\tassert.strictEqual(uuidASessionSpace, incrementStableId(idDataA.sessionId, idIndex));\n\t\t\t\tassert.strictEqual(compressorA.recompress(uuidASessionSpace), sessionSpaceIdA);\n\t\t\t\tuuids.add(uuidASessionSpace);\n\t\t\t\tconst opSpaceIdA = compressorA.normalizeToOpSpace(sessionSpaceIdA);\n\t\t\t\tif (!isFinalId(opSpaceIdA)) {\n\t\t\t\t\tfail(\"IDs should have been finalized.\");\n\t\t\t\t}\n\t\t\t\tconst reNormalizedIdA = compressorA.normalizeToSessionSpace(\n\t\t\t\t\topSpaceIdA,\n\t\t\t\t\tcompressorA.localSessionId,\n\t\t\t\t);\n\t\t\t\tassert.strictEqual(reNormalizedIdA, sessionSpaceIdA);\n\t\t\t\tfinalIds.add(opSpaceIdA);\n\t\t\t\tconst uuidAOpSpace = compressorA.decompress(reNormalizedIdA);\n\n\t\t\t\tassert.strictEqual(uuidASessionSpace, uuidAOpSpace);\n\n\t\t\t\tif (next !== undefined) {\n\t\t\t\t\tconst [compressorB, idDataB] = next;\n\t\t\t\t\tconst sessionSpaceIdB = idDataB.id;\n\n\t\t\t\t\tconst uuidBSessionSpace = compressorB.decompress(sessionSpaceIdB);\n\t\t\t\t\tassert.strictEqual(uuidASessionSpace, uuidBSessionSpace);\n\t\t\t\t\tconst opSpaceIdB = compressorB.normalizeToOpSpace(sessionSpaceIdB);\n\t\t\t\t\tif (opSpaceIdA !== opSpaceIdB) {\n\t\t\t\t\t\tcompressorB.normalizeToOpSpace(sessionSpaceIdB);\n\t\t\t\t\t\tcompressorA.normalizeToOpSpace(sessionSpaceIdA);\n\t\t\t\t\t}\n\t\t\t\t\tassert.strictEqual(opSpaceIdA, opSpaceIdB);\n\t\t\t\t\tif (!isFinalId(opSpaceIdB)) {\n\t\t\t\t\t\tfail(\"IDs should have been finalized.\");\n\t\t\t\t\t}\n\t\t\t\t\tconst uuidBOpSpace = compressorB.decompress(\n\t\t\t\t\t\topSpaceIdB as unknown as SessionSpaceCompressedId,\n\t\t\t\t\t);\n\t\t\t\t\tassert.strictEqual(uuidAOpSpace, uuidBOpSpace);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tassert(idCreatorCount <= 1, \"Only one client can create an ID.\");\n\t\t\tassert.strictEqual(uuids.size, finalIds.size);\n\t\t\tassert(originatingSession !== undefined, \"Expected originating client to be defined\");\n\t\t\tidIndicesAggregator.set(\n\t\t\t\toriginatingSession,\n\n\t\t\t\t(idIndicesAggregator.get(originatingSession) ??\n\t\t\t\t\tfail(\"Expected pre-existing index for originating client\")) + 1,\n\t\t\t);\n\t\t}\n\n\t\tfor (const [compressor] of sequencedLogs) {\n\t\t\texpectSerializes(compressor);\n\t\t}\n\t}\n}\n\n/**\n * Roundtrips the supplied compressor through serialization and deserialization.\n */\nexport function roundtrip(\n\tcompressor: ReadonlyIdCompressor,\n\twithSession: true,\n): [SerializedIdCompressorWithOngoingSession, IdCompressor];\n\n/**\n * Roundtrips the supplied compressor through serialization and deserialization.\n */\nexport function roundtrip(\n\tcompressor: ReadonlyIdCompressor,\n\twithSession: false,\n): [SerializedIdCompressorWithNoSession, IdCompressor];\n\nexport function roundtrip(\n\tcompressor: ReadonlyIdCompressor,\n\twithSession: boolean,\n): [\n\tSerializedIdCompressorWithOngoingSession | SerializedIdCompressorWithNoSession,\n\tIdCompressor,\n] {\n\t// preserve the capacity request as this property is normally private and resets\n\t// to a default on construction (deserialization)\n\tconst capacity: number = getClusterSize(compressor);\n\tif (withSession) {\n\t\tconst serialized = compressor.serialize(withSession);\n\t\tconst roundtripped = IdCompressor.deserialize({ serialized });\n\t\tmodifyClusterSize(roundtripped, capacity);\n\t\treturn [serialized, roundtripped];\n\t} else {\n\t\tconst nonLocalSerialized = compressor.serialize(withSession);\n\t\tconst roundtripped = IdCompressor.deserialize({\n\t\t\tserialized: nonLocalSerialized,\n\t\t\tnewSessionId: createSessionId(),\n\t\t});\n\t\tmodifyClusterSize(roundtripped, capacity);\n\t\treturn [nonLocalSerialized, roundtripped];\n\t}\n}\n\n/**\n * Asserts that the supplied compressor correctly roundtrips through serialization/deserialization.\n */\nexport function expectSerializes(\n\tcompressor: ReadonlyIdCompressor,\n): [SerializedIdCompressorWithNoSession, SerializedIdCompressorWithOngoingSession] {\n\tfunction expectSerializesWithSession(\n\t\twithSession: boolean,\n\t): SerializedIdCompressorWithOngoingSession | SerializedIdCompressorWithNoSession {\n\t\tlet serialized:\n\t\t\t| SerializedIdCompressorWithOngoingSession\n\t\t\t| SerializedIdCompressorWithNoSession;\n\t\tlet deserialized: IdCompressor;\n\t\tif (withSession) {\n\t\t\t[serialized, deserialized] = roundtrip(compressor, true);\n\t\t} else {\n\t\t\t[serialized, deserialized] = roundtrip(compressor, false);\n\t\t}\n\t\tassert.strictEqual(compressor.equals(deserialized, withSession), true);\n\t\treturn serialized;\n\t}\n\n\treturn [\n\t\texpectSerializesWithSession(false) as SerializedIdCompressorWithNoSession,\n\t\texpectSerializesWithSession(true) as SerializedIdCompressorWithOngoingSession,\n\t];\n}\n\n/**\n * Merges 'from' into 'to', and returns 'to'.\n */\nexport function mergeArrayMaps<K, V>(\n\tto: Pick<Map<K, V[]>, \"get\" | \"set\">,\n\tfrom: ReadonlyMap<K, V[]>,\n): Pick<Map<K, V[]>, \"get\" | \"set\"> {\n\tfor (const [key, value] of from.entries()) {\n\t\tconst entry = to.get(key);\n\t\tif (entry === undefined) {\n\t\t\tto.set(key, [...value]);\n\t\t} else {\n\t\t\tentry.push(...value);\n\t\t}\n\t}\n\treturn to;\n}\n\ninterface AllocateIds {\n\ttype: \"allocateIds\";\n\tclient: Client;\n\tnumIds: number;\n}\n\ninterface AllocateOutsideIds {\n\ttype: \"allocateOutsideIds\";\n\tsessionId: SessionId;\n\tnumIds: number;\n}\n\ninterface DeliverAllOperations {\n\ttype: \"deliverAllOperations\";\n}\n\ninterface DeliverSomeOperations {\n\ttype: \"deliverSomeOperations\";\n\tclient: Client;\n\tcount: number;\n}\n\ninterface ChangeCapacity {\n\ttype: \"changeCapacity\";\n\tclient: Client;\n\tnewSize: number;\n}\n\n// Represents intent to go offline then resume.\ninterface Reconnect {\n\ttype: \"reconnect\";\n\tclient: Client;\n}\n\ninterface Validate {\n\ttype: \"validate\";\n}\n\ntype Operation =\n\t| AllocateIds\n\t| AllocateOutsideIds\n\t| DeliverSomeOperations\n\t| DeliverAllOperations\n\t| ChangeCapacity\n\t| Reconnect\n\t| Validate;\n\ninterface FuzzTestState extends BaseFuzzTestState {\n\tnetwork: IdCompressorTestNetwork;\n\tactiveClients: Client[];\n\tselectableClients: Client[];\n\tclusterSize: number;\n}\n\nexport interface OperationGenerationConfig {\n\t/**\n\t * maximum cluster size of the network. Default: 25\n\t */\n\tmaxClusterSize?: number;\n\t/**\n\t * Number of ops between validation ops. Default: 200\n\t */\n\tvalidateInterval?: number;\n\t/**\n\t * Fraction of ID allocations that are from an outside client (not Client1/2/3).\n\t */\n\toutsideAllocationFraction?: number;\n}\n\nconst defaultOptions = {\n\tmaxClusterSize: 25,\n\tvalidateInterval: 200,\n\toutsideAllocationFraction: 0.1,\n};\n\nexport function makeOpGenerator(\n\toptions: OperationGenerationConfig,\n): Generator<Operation, FuzzTestState> {\n\tconst { maxClusterSize, validateInterval, outsideAllocationFraction } = {\n\t\t...defaultOptions,\n\t\t...options,\n\t};\n\tassert(outsideAllocationFraction >= 0 && outsideAllocationFraction <= 1);\n\n\tfunction allocateIdsGenerator({\n\t\tactiveClients,\n\t\tclusterSize,\n\t\trandom,\n\t}: FuzzTestState): AllocateIds {\n\t\tconst client = random.pick(activeClients);\n\t\tconst maxIdsPerUsage = clusterSize * 2;\n\t\tconst numIds = Math.floor(random.real(0, 1) ** 3 * maxIdsPerUsage) + 1;\n\t\treturn {\n\t\t\ttype: \"allocateIds\",\n\t\t\tclient,\n\t\t\tnumIds,\n\t\t};\n\t}\n\n\tfunction allocateOutsideIdsGenerator({\n\t\tclusterSize,\n\t\trandom,\n\t}: FuzzTestState): AllocateOutsideIds {\n\t\tconst maxIdsPerUsage = clusterSize * 2;\n\t\tconst numIds = Math.floor(random.real(0, 1) ** 3 * maxIdsPerUsage) + 1;\n\t\treturn {\n\t\t\ttype: \"allocateOutsideIds\",\n\t\t\tsessionId: createSessionId(),\n\t\t\tnumIds,\n\t\t};\n\t}\n\n\tfunction changeCapacityGenerator({ random, activeClients }: FuzzTestState): ChangeCapacity {\n\t\treturn {\n\t\t\ttype: \"changeCapacity\",\n\t\t\tclient: random.pick(activeClients),\n\t\t\tnewSize: Math.min(\n\t\t\t\tMath.floor(random.real(0, 1) ** 2 * maxClusterSize) + 1,\n\t\t\t\tmaxClusterSize,\n\t\t\t),\n\t\t};\n\t}\n\n\tfunction deliverAllOperationsGenerator(): DeliverAllOperations {\n\t\treturn {\n\t\t\ttype: \"deliverAllOperations\",\n\t\t};\n\t}\n\n\tfunction deliverSomeOperationsGenerator({\n\t\trandom,\n\t\tselectableClients,\n\t\tnetwork,\n\t}: FuzzTestState): DeliverSomeOperations {\n\t\tconst pendingClients = selectableClients.filter(\n\t\t\t(c) => network.getPendingOperations(c) > 0,\n\t\t);\n\t\tif (pendingClients.length === 0) {\n\t\t\treturn {\n\t\t\t\ttype: \"deliverSomeOperations\",\n\t\t\t\tclient: random.pick(selectableClients),\n\t\t\t\tcount: 0,\n\t\t\t};\n\t\t}\n\t\tconst client = random.pick(pendingClients);\n\t\treturn {\n\t\t\ttype: \"deliverSomeOperations\",\n\t\t\tclient,\n\t\t\tcount: random.integer(1, network.getPendingOperations(client)),\n\t\t};\n\t}\n\n\tfunction reconnectGenerator({ activeClients, random }: FuzzTestState): Reconnect {\n\t\treturn { type: \"reconnect\", client: random.pick(activeClients) };\n\t}\n\n\tconst allocationWeight = 20;\n\treturn interleave(\n\t\tcreateWeightedGenerator<Operation, FuzzTestState>([\n\t\t\t[changeCapacityGenerator, 1],\n\t\t\t[allocateIdsGenerator, Math.round(allocationWeight * (1 - outsideAllocationFraction))],\n\t\t\t[allocateOutsideIdsGenerator, Math.round(allocationWeight * outsideAllocationFraction)],\n\t\t\t[deliverAllOperationsGenerator, 1],\n\t\t\t[deliverSomeOperationsGenerator, 6],\n\t\t\t[reconnectGenerator, 1],\n\t\t]),\n\t\ttake(1, repeat<Operation, FuzzTestState>({ type: \"validate\" })),\n\t\tvalidateInterval,\n\t);\n}\n\n/**\n * Performs random actions on a test network.\n * @param generator - the generator used to provide operations\n * @param network - the test network to test\n * @param seed - the seed for the random generation of the fuzz actions\n * @param observerClient - if provided, this client will never generate local ids\n * @param synchronizeAtEnd - if provided, all client will have all operations delivered from the server at the end of the test\n * @param validator - if provided, this callback will be invoked periodically during the fuzz test.\n */\nexport function performFuzzActions(\n\tgenerator: Generator<Operation, FuzzTestState>,\n\tnetwork: IdCompressorTestNetwork,\n\tseed: number,\n\tobserverClient?: Client,\n\tsynchronizeAtEnd: boolean = true,\n\tvalidator?: (network: IdCompressorTestNetwork) => void,\n\tsaveInfo?: SaveInfo,\n): void {\n\tconst random = makeRandom(seed);\n\tconst selectableClients: Client[] = network\n\t\t.getTargetCompressors(MetaClient.All)\n\t\t.map(([client]) => client);\n\n\tconst initialState: FuzzTestState = {\n\t\trandom,\n\t\tnetwork,\n\t\tactiveClients: selectableClients.filter((c) => c !== observerClient),\n\t\tselectableClients,\n\t\tclusterSize: network.initialClusterSize,\n\t};\n\n\tperformFuzzActionsBase(\n\t\tgenerator,\n\t\t{\n\t\t\tallocateIds: (state, { client, numIds }) => {\n\t\t\t\tnetwork.allocateAndSendIdsFromRemoteClient(client, sessionIds.get(client), numIds);\n\t\t\t\treturn state;\n\t\t\t},\n\t\t\tallocateOutsideIds: (state, { sessionId, numIds }) => {\n\t\t\t\tnetwork.allocateAndSendIdsFromRemoteClient(\n\t\t\t\t\tOriginatingClient.Remote,\n\t\t\t\t\tsessionId,\n\t\t\t\t\tnumIds,\n\t\t\t\t);\n\t\t\t\treturn state;\n\t\t\t},\n\t\t\tchangeCapacity: (state, op) => {\n\t\t\t\tnetwork.changeCapacity(op.client, op.newSize);\n\t\t\t\treturn { ...state, clusterSize: op.newSize };\n\t\t\t},\n\t\t\tdeliverSomeOperations: (state, op) => {\n\t\t\t\tnetwork.deliverOperations(op.client, op.count);\n\t\t\t\treturn state;\n\t\t\t},\n\t\t\tdeliverAllOperations: (state) => {\n\t\t\t\tnetwork.deliverOperations(DestinationClient.All);\n\t\t\t\treturn state;\n\t\t\t},\n\t\t\treconnect: (state, { client }) => {\n\t\t\t\tnetwork.goOfflineThenResume(client);\n\t\t\t\treturn state;\n\t\t\t},\n\t\t\tvalidate: (state) => {\n\t\t\t\tvalidator?.(network);\n\t\t\t\treturn state;\n\t\t\t},\n\t\t},\n\t\tinitialState,\n\t\tsaveInfo,\n\t);\n\n\tif (synchronizeAtEnd) {\n\t\tnetwork.deliverOperations(DestinationClient.All);\n\t\tvalidator?.(network);\n\t}\n}\n\n/**\n * Helper to generate a fixed number of IDs.\n */\nexport function generateCompressedIds(\n\tcompressor: IdCompressor,\n\tcount: number,\n): SessionSpaceCompressedId[] {\n\tconst ids: SessionSpaceCompressedId[] = [];\n\tfor (let i = 0; i < count; i++) {\n\t\tids.push(compressor.generateCompressedId());\n\t}\n\treturn ids;\n}\n\n/**\n * Creates a compressor that only produces final IDs.\n * It should only be used for testing purposes.\n */\nexport function createAlwaysFinalizedIdCompressor(\n\tlogger?: ITelemetryBaseLogger,\n): IIdCompressor & IIdCompressorCore;\n/**\n * Creates a compressor that only produces final IDs.\n * It should only be used for testing purposes.\n */\nexport function createAlwaysFinalizedIdCompressor(\n\tsessionId: SessionId,\n\tlogger?: ITelemetryBaseLogger,\n\tseed?: number,\n): IIdCompressor & IIdCompressorCore;\nexport function createAlwaysFinalizedIdCompressor(\n\tsessionIdOrLogger?: SessionId | ITelemetryBaseLogger,\n\tloggerOrUndefined?: ITelemetryBaseLogger,\n\tseed?: number,\n): IIdCompressor & IIdCompressorCore {\n\tconst random = seed === undefined ? makeRandom() : makeRandom(seed);\n\tconst sessionId =\n\t\ttypeof sessionIdOrLogger === \"string\" ? sessionIdOrLogger : (random.uuid4() as SessionId);\n\tconst logger =\n\t\t(loggerOrUndefined ?? typeof sessionIdOrLogger === \"object\")\n\t\t\t? (sessionIdOrLogger as ITelemetryBaseLogger)\n\t\t\t: undefined;\n\t// This local session is unused, but it needs to not collide with the GhostSession, so allocate a random one.\n\t// This causes the compressor to serialize non-deterministically even when provided an explicit SessionId.\n\t// This can be fixed in the future if needed.\n\tconst compressor = createIdCompressor(random.uuid4() as SessionId, logger);\n\t// Permanently put the compressor in a ghost session\n\t(compressor as IdCompressor).startGhostSession(sessionId);\n\treturn toIdCompressorWithCore(compressor);\n}\n"]}
1
+ {"version":3,"file":"idCompressorTestUtilities.js","sourceRoot":"","sources":["../../src/test/idCompressorTestUtilities.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AA6HH,8CAIC;AAOD,wCAIC;AAiBD,kDAgCC;AAkhBD,8BAwBC;AAKD,4CAuBC;AAKD,wCAaC;AA6ED,0CA8FC;AAWD,gDAkEC;AAKD,sD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AC;IACtB,CAAC;AACF,CAAC;AAED;;GAEG;AACH,SAAgB,qBAAqB,CACpC,UAAwB,EACxB,KAAa;IAEb,MAAM,GAAG,GAA+B,EAAE,CAAC;IAC3C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;QAChC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,oBAAoB,EAAE,CAAC,CAAC;IAC7C,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC;AAkBD,SAAgB,iCAAiC,CAChD,iBAAoD,EACpD,iBAAwC,EACxC,IAAa;IAEb,MAAM,MAAM,GAAG,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,IAAA,kCAAU,GAAE,CAAC,CAAC,CAAC,IAAA,kCAAU,EAAC,IAAI,CAAC,CAAC;IACpE,MAAM,SAAS,GACd,OAAO,iBAAiB,KAAK,QAAQ,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAE,MAAM,CAAC,KAAK,EAAgB,CAAC;IAC3F,MAAM,MAAM,GACX,CAAC,iBAAiB,IAAI,OAAO,iBAAiB,KAAK,QAAQ,CAAC;QAC3D,CAAC,CAAE,iBAA0C;QAC7C,CAAC,CAAC,SAAS,CAAC;IACd,6GAA6G;IAC7G,0GAA0G;IAC1G,6CAA6C;IAC7C,MAAM,UAAU,GAAG,IAAA,6BAAkB,EAAC,MAAM,CAAC,KAAK,EAAe,EAAE,MAAM,CAAC,CAAC;IAC3E,oDAAoD;IACnD,UAA2B,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;IAC1D,OAAO,IAAA,iCAAsB,EAAC,UAAU,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { strict as assert } from \"node:assert\";\n\nimport {\n\ttype BaseFuzzTestState,\n\ttype Generator,\n\ttype SaveInfo,\n\tcreateWeightedGenerator,\n\tinterleave,\n\tmakeRandom,\n\tperformFuzzActions as performFuzzActionsBase,\n\trepeat,\n\ttake,\n} from \"@fluid-private/stochastic-test-utils\";\nimport type { ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\n\nimport { IdCompressor } from \"../idCompressor.js\";\nimport {\n\ttype IIdCompressor,\n\ttype IIdCompressorCore,\n\ttype IdCreationRange,\n\ttype OpSpaceCompressedId,\n\ttype SerializedIdCompressorWithNoSession,\n\ttype SerializedIdCompressorWithOngoingSession,\n\ttype SessionId,\n\ttype SessionSpaceCompressedId,\n\ttype StableId,\n\tcreateIdCompressor,\n\ttoIdCompressorWithCore,\n} from \"../index.js\";\nimport { SessionSpaceNormalizer } from \"../sessionSpaceNormalizer.js\";\nimport { assertIsSessionId, createSessionId, localIdFromGenCount } from \"../utilities.js\";\n\nimport {\n\ttype FinalCompressedId,\n\ttype ReadonlyIdCompressor,\n\tfail,\n\tgetOrCreate,\n\tincrementStableId,\n\tisFinalId,\n\tisLocalId,\n} from \"./testCommon.js\";\n\n/**\n * A readonly `Map` which is known to contain a value for every possible key\n */\nexport interface ClosedMap<K, V> extends Omit<Map<K, V>, \"delete\" | \"clear\"> {\n\tget(key: K): V;\n}\n\n/**\n * Identifies a compressor in a network\n */\nexport enum Client {\n\tClient1 = \"Client1\",\n\tClient2 = \"Client2\",\n\tClient3 = \"Client3\",\n}\n\n/**\n * Identifies categories of compressors\n */\nexport enum MetaClient {\n\tAll = \"All\",\n}\n\n/**\n * Identifies a compressor inside the network but outside the three specially tracked clients.\n */\nexport enum OutsideClient {\n\tRemote = \"Remote\",\n}\n\n/**\n * Used to attribute actions to clients in a distributed collaboration session.\n * `Local` implies a local and unsequenced operation. All others imply sequenced operations.\n */\nexport type OriginatingClient = Client | OutsideClient;\nexport const OriginatingClient = { ...Client, ...OutsideClient };\n\n/**\n * Identifies a compressor to which to send an operation\n */\nexport type DestinationClient = Client | MetaClient;\nexport const DestinationClient = { ...Client, ...MetaClient };\n\n// eslint-disable-next-line @typescript-eslint/no-extraneous-class\nexport class CompressorFactory {\n\t/**\n\t * Creates a new compressor with the supplied cluster capacity.\n\t */\n\tpublic static createCompressor(\n\t\tclient: Client,\n\t\tclusterCapacity = 5,\n\t\tlogger?: ITelemetryBaseLogger,\n\t): IdCompressor {\n\t\treturn CompressorFactory.createCompressorWithSession(\n\t\t\tsessionIds.get(client),\n\t\t\tclusterCapacity,\n\t\t\tlogger,\n\t\t);\n\t}\n\n\t/**\n\t * Creates a new compressor with the supplied cluster capacity.\n\t */\n\tpublic static createCompressorWithSession(\n\t\tsessionId: SessionId,\n\t\tclusterCapacity = 5,\n\t\tlogger?: ITelemetryBaseLogger,\n\t): IdCompressor {\n\t\tconst compressor = createIdCompressor(sessionId, logger) as IdCompressor;\n\t\tmodifyClusterSize(compressor, clusterCapacity);\n\t\treturn compressor;\n\t}\n}\n\n/**\n * Modify the requested cluster size of the provided compressor.\n * @remarks\n * This is useful for testing purposes for a few reasons:\n * - Id compressor bugs are often related to edge cases that occur on cluster boundaries\n * - Smaller cluster sizes can enable writing tests without for loops generating \"ids until a new cluster is created\"\n */\nexport function modifyClusterSize(compressor: IIdCompressor, newClusterSize: number): void {\n\tverifyCompressorLike(compressor);\n\t// eslint-disable-next-line @typescript-eslint/dot-notation\n\tcompressor[\"nextRequestedClusterSize\"] = newClusterSize;\n}\n\n/**\n * Returns the current cluster size of the compressor.\n * @privateRemarks\n * This is useful in writing tests to avoid having to hardcode the (currently constant) cluster size.\n */\nexport function getClusterSize(compressor: ReadonlyIdCompressor): number {\n\tverifyCompressorLike(compressor);\n\t// eslint-disable-next-line @typescript-eslint/dot-notation\n\treturn compressor[\"nextRequestedClusterSize\"] as number;\n}\n\nfunction verifyCompressorLike(compressor: ReadonlyIdCompressor | IIdCompressor): void {\n\tassert(\n\t\t// Some IdCompressor tests wrap underlying compressors with proxies--allow this for now.\n\t\t// Because of id-compressor's dynamic import in container-runtime, instanceof checks for IdCompressor\n\t\t// also won't necessarily work nicely. Get a small amount of validation that this function should work\n\t\t// as intended by at least verifying the property name exists.\n\t\t// eslint-disable-next-line @typescript-eslint/dot-notation\n\t\ttypeof compressor[\"nextRequestedClusterSize\"] === \"number\",\n\t);\n}\n\n/**\n * Utility for building a huge compressor.\n * Build via the compressor factory.\n */\nexport function buildHugeCompressor(\n\tnumSessions = 10000,\n\tcapacity = 10,\n\tnumClustersPerSession = 3,\n): IdCompressor {\n\tconst compressor = CompressorFactory.createCompressorWithSession(\n\t\tcreateSessionId(),\n\t\tcapacity,\n\t);\n\tconst sessions: SessionId[] = [];\n\tfor (let i = 0; i < numSessions; i++) {\n\t\tsessions.push(createSessionId());\n\t}\n\tfor (let i = 0; i < numSessions * numClustersPerSession; i++) {\n\t\tconst sessionId = sessions[i % numSessions];\n\t\tif (Math.random() > 0.1) {\n\t\t\tfor (let j = 0; j < Math.round(capacity / 2); j++) {\n\t\t\t\tcompressor.generateCompressedId();\n\t\t\t}\n\t\t\tcompressor.finalizeCreationRange(compressor.takeNextCreationRange());\n\t\t}\n\t\tcompressor.finalizeCreationRange({\n\t\t\tsessionId,\n\t\t\tids: {\n\t\t\t\tfirstGenCount: Math.floor(i / numSessions) * capacity + 1,\n\t\t\t\tcount: capacity,\n\t\t\t\trequestedClusterSize: capacity,\n\t\t\t\tlocalIdRanges: [], // remote session, can safely ignore in tests\n\t\t\t},\n\t\t});\n\t}\n\treturn compressor;\n}\n\n/**\n * A closed map from NamedClient to T.\n */\nexport type ClientMap<T> = ClosedMap<Client, T>;\n\nfunction makeSessionIds(): ClientMap<SessionId> {\n\tconst stableIds = new Map<Client, SessionId>();\n\tconst clients = Object.values(Client);\n\tfor (let i = 0; i < clients.length; i++) {\n\t\t// Place session uuids roughly in the middle of uuid space to increase odds of encountering interesting\n\t\t// orderings in sorted collections\n\t\tconst sessionId = assertIsSessionId(`88888888-8888-4888-b${i}88-888888888888`);\n\t\tstableIds.set(clients[i], sessionId);\n\t}\n\treturn stableIds as ClientMap<SessionId>;\n}\n\n/**\n * An array of session ID strings corresponding to all non-local `Client` entries.\n */\nexport const sessionIds = makeSessionIds();\n\n/**\n * Information about a generated ID in a network to be validated by tests\n */\nexport interface TestIdData {\n\treadonly id: SessionSpaceCompressedId;\n\treadonly originatingClient: OriginatingClient;\n\treadonly sessionId: SessionId;\n\treadonly isSequenced: boolean;\n}\n\n/**\n * Simulates a network of ID compressors.\n * Not suitable for performance testing.\n */\nexport class IdCompressorTestNetwork {\n\t/**\n\t * The compressors used in this network\n\t */\n\tprivate readonly compressors: ClientMap<IdCompressor>;\n\t/**\n\t * The log of operations seen by the server so far. Append-only.\n\t */\n\tprivate readonly serverOperations: [\n\t\tcreationRange: IdCreationRange,\n\t\topSpaceIds: OpSpaceCompressedId[],\n\t\tclientFrom: OriginatingClient,\n\t\tsessionIdFrom: SessionId,\n\t][] = [];\n\t/**\n\t * An index into `serverOperations` for each client which represents how many operations have been delivered to that client\n\t */\n\tprivate readonly clientProgress: ClientMap<number>;\n\t/**\n\t * All ids (local and sequenced) that a client has created or received, in order.\n\t */\n\tprivate readonly idLogs: ClientMap<TestIdData[]>;\n\t/**\n\t * All ids that a client has received from the server, in order.\n\t */\n\tprivate readonly sequencedIdLogs: ClientMap<TestIdData[]>;\n\n\tpublic constructor(public readonly initialClusterSize = 5) {\n\t\tconst compressors = new Map<Client, IdCompressor>();\n\t\tconst clientProgress = new Map<Client, number>();\n\t\tconst clientIds = new Map<Client, TestIdData[]>();\n\t\tconst clientSequencedIds = new Map<Client, TestIdData[]>();\n\t\tfor (const client of Object.values(Client)) {\n\t\t\tconst compressor = CompressorFactory.createCompressor(client, initialClusterSize);\n\t\t\tcompressors.set(client, compressor);\n\t\t\tclientProgress.set(client, 0);\n\t\t\tclientIds.set(client, []);\n\t\t\tclientSequencedIds.set(client, []);\n\t\t}\n\t\tthis.compressors = compressors as ClientMap<IdCompressor>;\n\t\tthis.clientProgress = clientProgress as ClientMap<number>;\n\t\tthis.idLogs = clientIds as ClientMap<TestIdData[]>;\n\t\tthis.sequencedIdLogs = clientSequencedIds as ClientMap<TestIdData[]>;\n\t}\n\n\t/**\n\t * Returns the number of undelivered operations for the given client that are in flight in the network.\n\t */\n\tpublic getPendingOperations(destination: Client): number {\n\t\treturn this.serverOperations.length - this.clientProgress.get(destination);\n\t}\n\n\t/**\n\t * Returns an immutable handle to a compressor in the network.\n\t */\n\tpublic getCompressor(client: Client): ReadonlyIdCompressor {\n\t\tconst compressors = this.compressors;\n\t\tconst handler = {\n\t\t\tget<P extends keyof IdCompressor>(_: unknown, property: P): IdCompressor[P] {\n\t\t\t\treturn compressors.get(client)[property];\n\t\t\t},\n\t\t\tset<P extends keyof IdCompressor>(\n\t\t\t\t_: unknown,\n\t\t\t\tproperty: P,\n\t\t\t\tvalue: IdCompressor[P],\n\t\t\t): boolean {\n\t\t\t\tcompressors.get(client)[property] = value;\n\t\t\t\treturn true;\n\t\t\t},\n\t\t};\n\t\treturn new Proxy<IdCompressor>({} as unknown as IdCompressor, handler);\n\t}\n\n\t/**\n\t * Returns a mutable handle to a compressor in the network. Use of mutation methods will break the network invariants and\n\t * should only be used if the network will not be used again.\n\t */\n\tpublic getCompressorUnsafe(client: Client): IdCompressor {\n\t\treturn this.getCompressor(client) as IdCompressor;\n\t}\n\n\t/**\n\t * Returns a mutable handle to a compressor in the network. Use of mutation methods will break the network invariants and\n\t * should only be used if the network will not be used again. Additionally, the returned compressor will be invalidated/unusable\n\t * if any network operations cause it to be regenerated (serialization/deserialization, etc.).\n\t */\n\tpublic getCompressorUnsafeNoProxy(client: Client): IdCompressor {\n\t\treturn this.compressors.get(client);\n\t}\n\n\t/**\n\t * Returns data for all IDs created and received by this client, including ack's of their own (i.e. their own IDs will appear twice)\n\t */\n\tpublic getIdLog(client: Client): readonly TestIdData[] {\n\t\treturn this.idLogs.get(client);\n\t}\n\n\t/**\n\t * Returns data for all IDs received by this client, including ack's of their own.\n\t */\n\tpublic getSequencedIdLog(client: Client): readonly TestIdData[] {\n\t\treturn this.sequencedIdLogs.get(client);\n\t}\n\n\t/**\n\t * Get all compressors for the given destination\n\t */\n\tpublic getTargetCompressors(clientTo: DestinationClient): [Client, IdCompressor][] {\n\t\treturn clientTo === MetaClient.All\n\t\t\t? [...this.compressors.entries()]\n\t\t\t: ([[clientTo, this.getCompressor(clientTo)]] as [Client, IdCompressor][]);\n\t}\n\n\t/**\n\t * Changes the capacity request amount for a client. It will take effect immediately.\n\t */\n\tpublic changeCapacity(client: Client, newClusterCapacity: number): void {\n\t\tmodifyClusterSize(this.compressors.get(client), newClusterCapacity);\n\t}\n\n\tprivate addNewId(\n\t\tclient: Client,\n\t\tid: SessionSpaceCompressedId,\n\t\toriginatingClient: OriginatingClient,\n\t\tsessionIdFrom: SessionId,\n\t\tisSequenced: boolean,\n\t): void {\n\t\tconst idData = {\n\t\t\tid,\n\t\t\toriginatingClient,\n\t\t\tsessionId: sessionIdFrom,\n\t\t\tisSequenced,\n\t\t};\n\t\tconst clientIds = this.idLogs.get(client);\n\t\tclientIds.push(idData);\n\t\tif (isSequenced) {\n\t\t\tconst sequencedIds = this.sequencedIdLogs.get(client);\n\t\t\tsequencedIds.push(idData);\n\t\t}\n\t}\n\n\t/**\n\t * Allocates a new range of local IDs and enqueues them for future delivery via a `testIdDelivery` action.\n\t * Calls to this method determine the total order of delivery, regardless of when `deliverOperations` is called.\n\t */\n\tpublic allocateAndSendIds(clientFrom: Client, numIds: number): OpSpaceCompressedId[] {\n\t\treturn this.allocateAndSendIdsFromRemoteClient(\n\t\t\tclientFrom,\n\t\t\tsessionIds.get(clientFrom),\n\t\t\tnumIds,\n\t\t);\n\t}\n\n\t/**\n\t * Same contract as `allocateAndSendIds`, but the originating client will be a client with the supplied sessionId.\n\t */\n\tpublic allocateAndSendIdsFromRemoteClient(\n\t\tclientFrom: OriginatingClient,\n\t\tsessionIdFrom: SessionId,\n\t\tnumIds: number,\n\t): OpSpaceCompressedId[] {\n\t\tassert(numIds > 0, \"Must allocate a non-zero number of IDs\");\n\t\tif (clientFrom === OriginatingClient.Remote) {\n\t\t\tconst range: IdCreationRange = {\n\t\t\t\tsessionId: sessionIdFrom,\n\t\t\t\tids: {\n\t\t\t\t\tfirstGenCount: 1,\n\t\t\t\t\tcount: numIds,\n\t\t\t\t\trequestedClusterSize: getClusterSize(this.getCompressor(Client.Client1)),\n\t\t\t\t\tlocalIdRanges: [], // remote session, can safely ignore in tests\n\t\t\t\t},\n\t\t\t};\n\t\t\tconst opSpaceIds: OpSpaceCompressedId[] = [];\n\t\t\tfor (let i = 0; i < numIds; i++) {\n\t\t\t\topSpaceIds.push(-(i + 1) as OpSpaceCompressedId);\n\t\t\t}\n\t\t\tthis.serverOperations.push([range, opSpaceIds, clientFrom, sessionIdFrom]);\n\t\t\treturn opSpaceIds;\n\t\t} else {\n\t\t\tassert(sessionIdFrom === sessionIds.get(clientFrom));\n\t\t\tconst compressor = this.compressors.get(clientFrom);\n\t\t\tconst sessionSpaceIds = generateCompressedIds(compressor, numIds);\n\t\t\tfor (let i = 0; i < numIds; i++) {\n\t\t\t\tthis.addNewId(clientFrom, sessionSpaceIds[i], clientFrom, sessionIdFrom, false);\n\t\t\t}\n\t\t\tconst opSpaceIds = sessionSpaceIds.map((id) => compressor.normalizeToOpSpace(id));\n\t\t\tconst creationRange = compressor.takeNextCreationRange();\n\t\t\tthis.serverOperations.push([creationRange, opSpaceIds, clientFrom, sessionIdFrom]);\n\t\t\treturn opSpaceIds;\n\t\t}\n\t}\n\n\t/**\n\t * Delivers all undelivered ID ranges from the server to the target clients.\n\t */\n\tpublic deliverOperations(clientTakingDelivery: Client, opsToDeliver?: number): void;\n\n\t/**\n\t * Delivers all undelivered ID ranges from the server to the target clients.\n\t */\n\tpublic deliverOperations(clientTakingDelivery: DestinationClient): void;\n\n\t/**\n\t * Delivers all undelivered ID ranges from the server to the target clients.\n\t */\n\tpublic deliverOperations(\n\t\tclientTakingDelivery: DestinationClient,\n\t\topsToDeliver?: number,\n\t): void {\n\t\tlet opIndexBound: number;\n\t\tif (clientTakingDelivery === DestinationClient.All) {\n\t\t\tassert(opsToDeliver === undefined);\n\t\t\topIndexBound = this.serverOperations.length;\n\t\t} else {\n\t\t\topIndexBound =\n\t\t\t\topsToDeliver === undefined\n\t\t\t\t\t? this.serverOperations.length\n\t\t\t\t\t: this.clientProgress.get(clientTakingDelivery) + opsToDeliver;\n\t\t}\n\t\tfor (const [clientTo, compressorTo] of this.getTargetCompressors(clientTakingDelivery)) {\n\t\t\tfor (let i = this.clientProgress.get(clientTo); i < opIndexBound; i++) {\n\t\t\t\tconst [range, opSpaceIds, clientFrom, sessionIdFrom] = this.serverOperations[i];\n\t\t\t\tcompressorTo.finalizeCreationRange(range);\n\n\t\t\t\tconst ids = range.ids;\n\t\t\t\tif (ids !== undefined) {\n\t\t\t\t\tfor (const id of opSpaceIds) {\n\t\t\t\t\t\tconst sessionSpaceId = compressorTo.normalizeToSessionSpace(id, range.sessionId);\n\t\t\t\t\t\tthis.addNewId(clientTo, sessionSpaceId, clientFrom, sessionIdFrom, true);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.clientProgress.set(clientTo, opIndexBound);\n\t\t}\n\t}\n\n\t/**\n\t * Simulate a client disconnecting (and serializing), then reconnecting (and deserializing)\n\t */\n\tpublic goOfflineThenResume(client: Client): void {\n\t\tconst compressor = this.compressors.get(client);\n\t\tconst [_, resumedCompressor] = roundtrip(compressor, true);\n\t\tthis.compressors.set(client, resumedCompressor);\n\t}\n\n\t/**\n\t * Ensure general validity of the network state. Useful for calling periodically or at the end of test scenarios.\n\t */\n\tpublic assertNetworkState(): void {\n\t\tconst sequencedLogs = Object.values(Client).map(\n\t\t\t(client) => [this.compressors.get(client), this.getSequencedIdLog(client)] as const,\n\t\t);\n\n\t\tconst getLocalIdsInRange = (\n\t\t\trange: IdCreationRange,\n\t\t\topSpaceIds?: OpSpaceCompressedId[],\n\t\t): Set<SessionSpaceCompressedId> => {\n\t\t\tconst localIdsInCreationRange = new Set<SessionSpaceCompressedId>();\n\t\t\tconst ids = range.ids;\n\t\t\tif (ids !== undefined) {\n\t\t\t\tconst { firstGenCount, localIdRanges } = ids;\n\t\t\t\tfor (const [genCount, count] of localIdRanges) {\n\t\t\t\t\tfor (let g = genCount; g < genCount + count; g++) {\n\t\t\t\t\t\tconst local = localIdFromGenCount(g);\n\t\t\t\t\t\tif (opSpaceIds) {\n\t\t\t\t\t\t\tassert.strictEqual(opSpaceIds[g - firstGenCount], local);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlocalIdsInCreationRange.add(local);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn localIdsInCreationRange;\n\t\t};\n\n\t\t// Ensure creation ranges for clients we track contain the correct local ID ranges\n\t\tfor (const [range, opSpaceIds, clientFrom] of this.serverOperations) {\n\t\t\tif (clientFrom !== OriginatingClient.Remote) {\n\t\t\t\tconst localIdsInCreationRange = getLocalIdsInRange(range, opSpaceIds);\n\t\t\t\tlet localCount = 0;\n\t\t\t\tfor (const id of opSpaceIds) {\n\t\t\t\t\tif (isLocalId(id)) {\n\t\t\t\t\t\tlocalCount++;\n\t\t\t\t\t\tassert(localIdsInCreationRange.has(id), \"Local ID not in creation range\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tassert.strictEqual(\n\t\t\t\t\tlocalCount,\n\t\t\t\t\tlocalIdsInCreationRange.size,\n\t\t\t\t\t\"Local ID count mismatch\",\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tconst undeliveredRanges = new Map<Client, IdCreationRange[]>();\n\t\tfor (const [client, progress] of this.clientProgress.entries()) {\n\t\t\tconst ranges = this.serverOperations\n\t\t\t\t.slice(progress)\n\t\t\t\t.filter((op) => op[2] === client)\n\t\t\t\t.map(([range]) => range);\n\t\t\tundeliveredRanges.set(client, ranges);\n\t\t}\n\t\tfor (const [client, ranges] of undeliveredRanges.entries()) {\n\t\t\tconst compressor = this.compressors.get(client);\n\t\t\tlet firstGenCount: number | undefined;\n\t\t\tlet totalCount = 0;\n\t\t\tconst unionedLocalRanges = new SessionSpaceNormalizer();\n\t\t\tfor (const range of ranges) {\n\t\t\t\tassert(range.sessionId === compressor.localSessionId);\n\t\t\t\tif (range.ids !== undefined) {\n\t\t\t\t\t// initialize firstGenCount if not set\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ??= could change behavior if value is falsy\n\t\t\t\t\tif (firstGenCount === undefined) {\n\t\t\t\t\t\tfirstGenCount = range.ids.firstGenCount;\n\t\t\t\t\t}\n\t\t\t\t\ttotalCount += range.ids.count;\n\t\t\t\t\tfor (const [genCount, count] of range.ids.localIdRanges) {\n\t\t\t\t\t\tunionedLocalRanges.addLocalRange(genCount, count);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst retakenRange = compressor.takeUnfinalizedCreationRange();\n\t\t\tif (retakenRange.ids === undefined) {\n\t\t\t\tassert.strictEqual(totalCount, 0);\n\t\t\t\tassert.strictEqual(unionedLocalRanges.idRanges.size, 0);\n\t\t\t} else {\n\t\t\t\tconst retakenLocalIds = new SessionSpaceNormalizer();\n\t\t\t\tfor (const [genCount, count] of retakenRange.ids.localIdRanges) {\n\t\t\t\t\tretakenLocalIds.addLocalRange(genCount, count);\n\t\t\t\t}\n\t\t\t\tassert.strictEqual(\n\t\t\t\t\tretakenLocalIds.equals(unionedLocalRanges),\n\t\t\t\t\ttrue,\n\t\t\t\t\t\"Local ID ranges mismatch\",\n\t\t\t\t);\n\t\t\t\tassert.strictEqual(retakenRange.ids.count, totalCount, \"Count mismatch\");\n\t\t\t\tassert.strictEqual(retakenRange.ids.firstGenCount, firstGenCount, \"Count mismatch\");\n\t\t\t}\n\t\t}\n\n\t\t// First, ensure all clients each generated a unique ID for each of their own calls to generate.\n\t\tfor (const [compressor, ids] of sequencedLogs) {\n\t\t\tconst allUuids = new Set<StableId | string>();\n\t\t\tfor (const idData of ids) {\n\t\t\t\tconst uuid = compressor.decompress(idData.id);\n\t\t\t\tassert.strictEqual(!allUuids.has(uuid), true, \"Duplicate UUID generated.\");\n\t\t\t\tallUuids.add(uuid);\n\t\t\t}\n\t\t}\n\n\t\tconst maxLogLength = sequencedLogs\n\t\t\t.map(([_, data]) => data.length)\n\t\t\t// eslint-disable-next-line unicorn/no-array-reduce\n\t\t\t.reduce((p, n) => Math.max(p, n));\n\n\t\tfunction getNextLogWithEntryAt(logsIndex: number, entryIndex: number): number | undefined {\n\t\t\tfor (let i = logsIndex; i < sequencedLogs.length; i++) {\n\t\t\t\tconst log = sequencedLogs[i];\n\t\t\t\tif (log[1].length > entryIndex) {\n\t\t\t\t\treturn i;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst uuids = new Set<StableId>();\n\t\tconst finalIds = new Set<FinalCompressedId>();\n\t\tconst idIndicesAggregator = new Map<SessionId, number>();\n\n\t\tfunction* getIdLogEntries(\n\t\t\tcolumnIndex: number,\n\t\t): Iterable<\n\t\t\t[\n\t\t\t\tcurrent: [compressor: IdCompressor, idData: TestIdData],\n\t\t\t\tnext?: [compressor: IdCompressor, idData: TestIdData],\n\t\t\t]\n\t\t> {\n\t\t\tlet current = getNextLogWithEntryAt(0, columnIndex);\n\t\t\twhile (current !== undefined) {\n\t\t\t\tconst next = getNextLogWithEntryAt(current + 1, columnIndex);\n\t\t\t\tconst [compressor, log] = sequencedLogs[current];\n\t\t\t\tif (next === undefined) {\n\t\t\t\t\tyield [[compressor, log[columnIndex]]];\n\t\t\t\t} else {\n\t\t\t\t\tconst [compressorNext, logNext] = sequencedLogs[next];\n\t\t\t\t\tyield [\n\t\t\t\t\t\t[compressor, log[columnIndex]],\n\t\t\t\t\t\t[compressorNext, logNext[columnIndex]],\n\t\t\t\t\t];\n\t\t\t\t}\n\t\t\t\tcurrent = next;\n\t\t\t}\n\t\t}\n\n\t\tfor (let i = 0; i < maxLogLength; i++) {\n\t\t\tlet idCreatorCount = 0;\n\t\t\tlet originatingSession: SessionId | undefined;\n\t\t\tfor (const [current, next] of getIdLogEntries(i)) {\n\t\t\t\tconst [compressorA, idDataA] = current;\n\t\t\t\tconst sessionSpaceIdA = idDataA.id;\n\t\t\t\tconst idIndex = getOrCreate(idIndicesAggregator, idDataA.sessionId, () => 0);\n\t\t\t\toriginatingSession ??= idDataA.sessionId;\n\t\t\t\tassert(\n\t\t\t\t\tidDataA.sessionId === originatingSession,\n\t\t\t\t\t\"Test infra gave wrong originating client to TestIdData\",\n\t\t\t\t);\n\n\t\t\t\t// Only one client should have this ID as local in its session space, as only one client could have created this ID\n\t\t\t\tif (isLocalId(sessionSpaceIdA)) {\n\t\t\t\t\tif (originatingSession !== OriginatingClient.Remote) {\n\t\t\t\t\t\tassert.strictEqual(\n\t\t\t\t\t\t\tidDataA.sessionId,\n\t\t\t\t\t\t\tthis.compressors.get(idDataA.originatingClient as Client).localSessionId,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tidCreatorCount++;\n\t\t\t\t}\n\n\t\t\t\tconst uuidASessionSpace = compressorA.decompress(sessionSpaceIdA);\n\t\t\t\tassert.strictEqual(uuidASessionSpace, incrementStableId(idDataA.sessionId, idIndex));\n\t\t\t\tassert.strictEqual(compressorA.recompress(uuidASessionSpace), sessionSpaceIdA);\n\t\t\t\tuuids.add(uuidASessionSpace);\n\t\t\t\tconst opSpaceIdA = compressorA.normalizeToOpSpace(sessionSpaceIdA);\n\t\t\t\tif (!isFinalId(opSpaceIdA)) {\n\t\t\t\t\tfail(\"IDs should have been finalized.\");\n\t\t\t\t}\n\t\t\t\tconst reNormalizedIdA = compressorA.normalizeToSessionSpace(\n\t\t\t\t\topSpaceIdA,\n\t\t\t\t\tcompressorA.localSessionId,\n\t\t\t\t);\n\t\t\t\tassert.strictEqual(reNormalizedIdA, sessionSpaceIdA);\n\t\t\t\tfinalIds.add(opSpaceIdA);\n\t\t\t\tconst uuidAOpSpace = compressorA.decompress(reNormalizedIdA);\n\n\t\t\t\tassert.strictEqual(uuidASessionSpace, uuidAOpSpace);\n\n\t\t\t\tif (next !== undefined) {\n\t\t\t\t\tconst [compressorB, idDataB] = next;\n\t\t\t\t\tconst sessionSpaceIdB = idDataB.id;\n\n\t\t\t\t\tconst uuidBSessionSpace = compressorB.decompress(sessionSpaceIdB);\n\t\t\t\t\tassert.strictEqual(uuidASessionSpace, uuidBSessionSpace);\n\t\t\t\t\tconst opSpaceIdB = compressorB.normalizeToOpSpace(sessionSpaceIdB);\n\t\t\t\t\tif (opSpaceIdA !== opSpaceIdB) {\n\t\t\t\t\t\tcompressorB.normalizeToOpSpace(sessionSpaceIdB);\n\t\t\t\t\t\tcompressorA.normalizeToOpSpace(sessionSpaceIdA);\n\t\t\t\t\t}\n\t\t\t\t\tassert.strictEqual(opSpaceIdA, opSpaceIdB);\n\t\t\t\t\tif (!isFinalId(opSpaceIdB)) {\n\t\t\t\t\t\tfail(\"IDs should have been finalized.\");\n\t\t\t\t\t}\n\t\t\t\t\tconst uuidBOpSpace = compressorB.decompress(\n\t\t\t\t\t\topSpaceIdB as unknown as SessionSpaceCompressedId,\n\t\t\t\t\t);\n\t\t\t\t\tassert.strictEqual(uuidAOpSpace, uuidBOpSpace);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tassert(idCreatorCount <= 1, \"Only one client can create an ID.\");\n\t\t\tassert.strictEqual(uuids.size, finalIds.size);\n\t\t\tassert(originatingSession !== undefined, \"Expected originating client to be defined\");\n\t\t\tidIndicesAggregator.set(\n\t\t\t\toriginatingSession,\n\n\t\t\t\t(idIndicesAggregator.get(originatingSession) ??\n\t\t\t\t\tfail(\"Expected pre-existing index for originating client\")) + 1,\n\t\t\t);\n\t\t}\n\n\t\tfor (const [compressor] of sequencedLogs) {\n\t\t\texpectSerializes(compressor);\n\t\t}\n\t}\n}\n\n/**\n * Roundtrips the supplied compressor through serialization and deserialization.\n */\nexport function roundtrip(\n\tcompressor: ReadonlyIdCompressor,\n\twithSession: true,\n): [SerializedIdCompressorWithOngoingSession, IdCompressor];\n\n/**\n * Roundtrips the supplied compressor through serialization and deserialization.\n */\nexport function roundtrip(\n\tcompressor: ReadonlyIdCompressor,\n\twithSession: false,\n): [SerializedIdCompressorWithNoSession, IdCompressor];\n\nexport function roundtrip(\n\tcompressor: ReadonlyIdCompressor,\n\twithSession: boolean,\n): [\n\tSerializedIdCompressorWithOngoingSession | SerializedIdCompressorWithNoSession,\n\tIdCompressor,\n] {\n\t// preserve the capacity request as this property is normally private and resets\n\t// to a default on construction (deserialization)\n\tconst capacity: number = getClusterSize(compressor);\n\tif (withSession) {\n\t\tconst serialized = compressor.serialize(withSession);\n\t\tconst roundtripped = IdCompressor.deserialize({ serialized });\n\t\tmodifyClusterSize(roundtripped, capacity);\n\t\treturn [serialized, roundtripped];\n\t} else {\n\t\tconst nonLocalSerialized = compressor.serialize(withSession);\n\t\tconst roundtripped = IdCompressor.deserialize({\n\t\t\tserialized: nonLocalSerialized,\n\t\t\tnewSessionId: createSessionId(),\n\t\t});\n\t\tmodifyClusterSize(roundtripped, capacity);\n\t\treturn [nonLocalSerialized, roundtripped];\n\t}\n}\n\n/**\n * Asserts that the supplied compressor correctly roundtrips through serialization/deserialization.\n */\nexport function expectSerializes(\n\tcompressor: ReadonlyIdCompressor,\n): [SerializedIdCompressorWithNoSession, SerializedIdCompressorWithOngoingSession] {\n\tfunction expectSerializesWithSession(\n\t\twithSession: boolean,\n\t): SerializedIdCompressorWithOngoingSession | SerializedIdCompressorWithNoSession {\n\t\tlet serialized:\n\t\t\t| SerializedIdCompressorWithOngoingSession\n\t\t\t| SerializedIdCompressorWithNoSession;\n\t\tlet deserialized: IdCompressor;\n\t\tif (withSession) {\n\t\t\t[serialized, deserialized] = roundtrip(compressor, true);\n\t\t} else {\n\t\t\t[serialized, deserialized] = roundtrip(compressor, false);\n\t\t}\n\t\tassert.strictEqual(compressor.equals(deserialized, withSession), true);\n\t\treturn serialized;\n\t}\n\n\treturn [\n\t\texpectSerializesWithSession(false) as SerializedIdCompressorWithNoSession,\n\t\texpectSerializesWithSession(true) as SerializedIdCompressorWithOngoingSession,\n\t];\n}\n\n/**\n * Merges 'from' into 'to', and returns 'to'.\n */\nexport function mergeArrayMaps<K, V>(\n\tto: Pick<Map<K, V[]>, \"get\" | \"set\">,\n\tfrom: ReadonlyMap<K, V[]>,\n): Pick<Map<K, V[]>, \"get\" | \"set\"> {\n\tfor (const [key, value] of from.entries()) {\n\t\tconst entry = to.get(key);\n\t\tif (entry === undefined) {\n\t\t\tto.set(key, [...value]);\n\t\t} else {\n\t\t\tentry.push(...value);\n\t\t}\n\t}\n\treturn to;\n}\n\ninterface AllocateIds {\n\ttype: \"allocateIds\";\n\tclient: Client;\n\tnumIds: number;\n}\n\ninterface AllocateOutsideIds {\n\ttype: \"allocateOutsideIds\";\n\tsessionId: SessionId;\n\tnumIds: number;\n}\n\ninterface DeliverAllOperations {\n\ttype: \"deliverAllOperations\";\n}\n\ninterface DeliverSomeOperations {\n\ttype: \"deliverSomeOperations\";\n\tclient: Client;\n\tcount: number;\n}\n\ninterface ChangeCapacity {\n\ttype: \"changeCapacity\";\n\tclient: Client;\n\tnewSize: number;\n}\n\n// Represents intent to go offline then resume.\ninterface Reconnect {\n\ttype: \"reconnect\";\n\tclient: Client;\n}\n\ninterface Validate {\n\ttype: \"validate\";\n}\n\ntype Operation =\n\t| AllocateIds\n\t| AllocateOutsideIds\n\t| DeliverSomeOperations\n\t| DeliverAllOperations\n\t| ChangeCapacity\n\t| Reconnect\n\t| Validate;\n\ninterface FuzzTestState extends BaseFuzzTestState {\n\tnetwork: IdCompressorTestNetwork;\n\tactiveClients: Client[];\n\tselectableClients: Client[];\n\tclusterSize: number;\n}\n\nexport interface OperationGenerationConfig {\n\t/**\n\t * maximum cluster size of the network. Default: 25\n\t */\n\tmaxClusterSize?: number;\n\t/**\n\t * Number of ops between validation ops. Default: 200\n\t */\n\tvalidateInterval?: number;\n\t/**\n\t * Fraction of ID allocations that are from an outside client (not Client1/2/3).\n\t */\n\toutsideAllocationFraction?: number;\n}\n\nconst defaultOptions = {\n\tmaxClusterSize: 25,\n\tvalidateInterval: 200,\n\toutsideAllocationFraction: 0.1,\n};\n\nexport function makeOpGenerator(\n\toptions: OperationGenerationConfig,\n): Generator<Operation, FuzzTestState> {\n\tconst { maxClusterSize, validateInterval, outsideAllocationFraction } = {\n\t\t...defaultOptions,\n\t\t...options,\n\t};\n\tassert(outsideAllocationFraction >= 0 && outsideAllocationFraction <= 1);\n\n\tfunction allocateIdsGenerator({\n\t\tactiveClients,\n\t\tclusterSize,\n\t\trandom,\n\t}: FuzzTestState): AllocateIds {\n\t\tconst client = random.pick(activeClients);\n\t\tconst maxIdsPerUsage = clusterSize * 2;\n\t\tconst numIds = Math.floor(random.real(0, 1) ** 3 * maxIdsPerUsage) + 1;\n\t\treturn {\n\t\t\ttype: \"allocateIds\",\n\t\t\tclient,\n\t\t\tnumIds,\n\t\t};\n\t}\n\n\tfunction allocateOutsideIdsGenerator({\n\t\tclusterSize,\n\t\trandom,\n\t}: FuzzTestState): AllocateOutsideIds {\n\t\tconst maxIdsPerUsage = clusterSize * 2;\n\t\tconst numIds = Math.floor(random.real(0, 1) ** 3 * maxIdsPerUsage) + 1;\n\t\treturn {\n\t\t\ttype: \"allocateOutsideIds\",\n\t\t\tsessionId: createSessionId(),\n\t\t\tnumIds,\n\t\t};\n\t}\n\n\tfunction changeCapacityGenerator({ random, activeClients }: FuzzTestState): ChangeCapacity {\n\t\treturn {\n\t\t\ttype: \"changeCapacity\",\n\t\t\tclient: random.pick(activeClients),\n\t\t\tnewSize: Math.min(\n\t\t\t\tMath.floor(random.real(0, 1) ** 2 * maxClusterSize) + 1,\n\t\t\t\tmaxClusterSize,\n\t\t\t),\n\t\t};\n\t}\n\n\tfunction deliverAllOperationsGenerator(): DeliverAllOperations {\n\t\treturn {\n\t\t\ttype: \"deliverAllOperations\",\n\t\t};\n\t}\n\n\tfunction deliverSomeOperationsGenerator({\n\t\trandom,\n\t\tselectableClients,\n\t\tnetwork,\n\t}: FuzzTestState): DeliverSomeOperations {\n\t\tconst pendingClients = selectableClients.filter(\n\t\t\t(c) => network.getPendingOperations(c) > 0,\n\t\t);\n\t\tif (pendingClients.length === 0) {\n\t\t\treturn {\n\t\t\t\ttype: \"deliverSomeOperations\",\n\t\t\t\tclient: random.pick(selectableClients),\n\t\t\t\tcount: 0,\n\t\t\t};\n\t\t}\n\t\tconst client = random.pick(pendingClients);\n\t\treturn {\n\t\t\ttype: \"deliverSomeOperations\",\n\t\t\tclient,\n\t\t\tcount: random.integer(1, network.getPendingOperations(client)),\n\t\t};\n\t}\n\n\tfunction reconnectGenerator({ activeClients, random }: FuzzTestState): Reconnect {\n\t\treturn { type: \"reconnect\", client: random.pick(activeClients) };\n\t}\n\n\tconst allocationWeight = 20;\n\treturn interleave(\n\t\tcreateWeightedGenerator<Operation, FuzzTestState>([\n\t\t\t[changeCapacityGenerator, 1],\n\t\t\t[allocateIdsGenerator, Math.round(allocationWeight * (1 - outsideAllocationFraction))],\n\t\t\t[allocateOutsideIdsGenerator, Math.round(allocationWeight * outsideAllocationFraction)],\n\t\t\t[deliverAllOperationsGenerator, 1],\n\t\t\t[deliverSomeOperationsGenerator, 6],\n\t\t\t[reconnectGenerator, 1],\n\t\t]),\n\t\ttake(1, repeat<Operation, FuzzTestState>({ type: \"validate\" })),\n\t\tvalidateInterval,\n\t);\n}\n\n/**\n * Performs random actions on a test network.\n * @param generator - the generator used to provide operations\n * @param network - the test network to test\n * @param seed - the seed for the random generation of the fuzz actions\n * @param observerClient - if provided, this client will never generate local ids\n * @param synchronizeAtEnd - if provided, all client will have all operations delivered from the server at the end of the test\n * @param validator - if provided, this callback will be invoked periodically during the fuzz test.\n */\nexport function performFuzzActions(\n\tgenerator: Generator<Operation, FuzzTestState>,\n\tnetwork: IdCompressorTestNetwork,\n\tseed: number,\n\tobserverClient?: Client,\n\tsynchronizeAtEnd: boolean = true,\n\tvalidator?: (network: IdCompressorTestNetwork) => void,\n\tsaveInfo?: SaveInfo,\n): void {\n\tconst random = makeRandom(seed);\n\tconst selectableClients: Client[] = network\n\t\t.getTargetCompressors(MetaClient.All)\n\t\t.map(([client]) => client);\n\n\tconst initialState: FuzzTestState = {\n\t\trandom,\n\t\tnetwork,\n\t\tactiveClients: selectableClients.filter((c) => c !== observerClient),\n\t\tselectableClients,\n\t\tclusterSize: network.initialClusterSize,\n\t};\n\n\tperformFuzzActionsBase(\n\t\tgenerator,\n\t\t{\n\t\t\tallocateIds: (state, { client, numIds }) => {\n\t\t\t\tnetwork.allocateAndSendIdsFromRemoteClient(client, sessionIds.get(client), numIds);\n\t\t\t\treturn state;\n\t\t\t},\n\t\t\tallocateOutsideIds: (state, { sessionId, numIds }) => {\n\t\t\t\tnetwork.allocateAndSendIdsFromRemoteClient(\n\t\t\t\t\tOriginatingClient.Remote,\n\t\t\t\t\tsessionId,\n\t\t\t\t\tnumIds,\n\t\t\t\t);\n\t\t\t\treturn state;\n\t\t\t},\n\t\t\tchangeCapacity: (state, op) => {\n\t\t\t\tnetwork.changeCapacity(op.client, op.newSize);\n\t\t\t\treturn { ...state, clusterSize: op.newSize };\n\t\t\t},\n\t\t\tdeliverSomeOperations: (state, op) => {\n\t\t\t\tnetwork.deliverOperations(op.client, op.count);\n\t\t\t\treturn state;\n\t\t\t},\n\t\t\tdeliverAllOperations: (state) => {\n\t\t\t\tnetwork.deliverOperations(DestinationClient.All);\n\t\t\t\treturn state;\n\t\t\t},\n\t\t\treconnect: (state, { client }) => {\n\t\t\t\tnetwork.goOfflineThenResume(client);\n\t\t\t\treturn state;\n\t\t\t},\n\t\t\tvalidate: (state) => {\n\t\t\t\tvalidator?.(network);\n\t\t\t\treturn state;\n\t\t\t},\n\t\t},\n\t\tinitialState,\n\t\tsaveInfo,\n\t);\n\n\tif (synchronizeAtEnd) {\n\t\tnetwork.deliverOperations(DestinationClient.All);\n\t\tvalidator?.(network);\n\t}\n}\n\n/**\n * Helper to generate a fixed number of IDs.\n */\nexport function generateCompressedIds(\n\tcompressor: IdCompressor,\n\tcount: number,\n): SessionSpaceCompressedId[] {\n\tconst ids: SessionSpaceCompressedId[] = [];\n\tfor (let i = 0; i < count; i++) {\n\t\tids.push(compressor.generateCompressedId());\n\t}\n\treturn ids;\n}\n\n/**\n * Creates a compressor that only produces final IDs.\n * It should only be used for testing purposes.\n */\nexport function createAlwaysFinalizedIdCompressor(\n\tlogger?: ITelemetryBaseLogger,\n): IIdCompressor & IIdCompressorCore;\n/**\n * Creates a compressor that only produces final IDs.\n * It should only be used for testing purposes.\n */\nexport function createAlwaysFinalizedIdCompressor(\n\tsessionId: SessionId,\n\tlogger?: ITelemetryBaseLogger,\n\tseed?: number,\n): IIdCompressor & IIdCompressorCore;\nexport function createAlwaysFinalizedIdCompressor(\n\tsessionIdOrLogger?: SessionId | ITelemetryBaseLogger,\n\tloggerOrUndefined?: ITelemetryBaseLogger,\n\tseed?: number,\n): IIdCompressor & IIdCompressorCore {\n\tconst random = seed === undefined ? makeRandom() : makeRandom(seed);\n\tconst sessionId =\n\t\ttypeof sessionIdOrLogger === \"string\" ? sessionIdOrLogger : (random.uuid4() as SessionId);\n\tconst logger =\n\t\t(loggerOrUndefined ?? typeof sessionIdOrLogger === \"object\")\n\t\t\t? (sessionIdOrLogger as ITelemetryBaseLogger)\n\t\t\t: undefined;\n\t// This local session is unused, but it needs to not collide with the GhostSession, so allocate a random one.\n\t// This causes the compressor to serialize non-deterministically even when provided an explicit SessionId.\n\t// This can be fixed in the future if needed.\n\tconst compressor = createIdCompressor(random.uuid4() as SessionId, logger);\n\t// Permanently put the compressor in a ghost session\n\t(compressor as IdCompressor).startGhostSession(sessionId);\n\treturn toIdCompressorWithCore(compressor);\n}\n"]}
@@ -4,7 +4,13 @@
4
4
  * Licensed under the MIT License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.fail = exports.assertNotUndefined = exports.incrementStableId = exports.getOrCreate = exports.makeLocalId = exports.isLocalId = exports.isFinalId = void 0;
7
+ exports.isFinalId = isFinalId;
8
+ exports.isLocalId = isLocalId;
9
+ exports.makeLocalId = makeLocalId;
10
+ exports.getOrCreate = getOrCreate;
11
+ exports.incrementStableId = incrementStableId;
12
+ exports.assertNotUndefined = assertNotUndefined;
13
+ exports.fail = fail;
8
14
  const internal_1 = require("@fluidframework/core-utils/internal");
9
15
  const utilities_js_1 = require("../utilities.js");
10
16
  /**
@@ -14,7 +20,6 @@ const utilities_js_1 = require("../utilities.js");
14
20
  function isFinalId(id) {
15
21
  return id >= 0;
16
22
  }
17
- exports.isFinalId = isFinalId;
18
23
  /**
19
24
  * Returns true if the supplied ID is a local ID.
20
25
  * @returns true if the supplied ID is a local ID.
@@ -22,7 +27,6 @@ exports.isFinalId = isFinalId;
22
27
  function isLocalId(id) {
23
28
  return id < 0;
24
29
  }
25
- exports.isLocalId = isLocalId;
26
30
  /**
27
31
  * Turns a negative integer into a local compressed ID. For testing only.
28
32
  */
@@ -31,7 +35,6 @@ function makeLocalId(negativeInteger) {
31
35
  (0, internal_1.assert)(isLocalId(id), "Not a negative integer.");
32
36
  return id;
33
37
  }
34
- exports.makeLocalId = makeLocalId;
35
38
  /**
36
39
  * Retrieve a value from a map with the given key, or create a new entry if the key is not in the map.
37
40
  * @param map - The map to query/update
@@ -47,11 +50,9 @@ function getOrCreate(map, key, defaultValue) {
47
50
  }
48
51
  return value;
49
52
  }
50
- exports.getOrCreate = getOrCreate;
51
53
  function incrementStableId(stableId, offset) {
52
54
  return (0, utilities_js_1.stableIdFromNumericUuid)((0, utilities_js_1.offsetNumericUuid)((0, utilities_js_1.numericUuidFromStableId)(stableId), offset));
53
55
  }
54
- exports.incrementStableId = incrementStableId;
55
56
  /**
56
57
  * Asserts a value is not undefined, and returns the value.
57
58
  * Use when violations are logic errors in the program.
@@ -79,7 +80,6 @@ function assertNotUndefined(value, message = "value must not be undefined") {
79
80
  (0, internal_1.assert)(value !== undefined, message);
80
81
  return value;
81
82
  }
82
- exports.assertNotUndefined = assertNotUndefined;
83
83
  /**
84
84
  * Fails an assertion. Throws an Error that the assertion failed.
85
85
  * Use when violations are logic errors in the program.
@@ -88,5 +88,4 @@ exports.assertNotUndefined = assertNotUndefined;
88
88
  function fail(message) {
89
89
  (0, internal_1.fail)(message);
90
90
  }
91
- exports.fail = fail;
92
91
  //# sourceMappingURL=testCommon.js.map