import { strict as assert } from "assert" ; import { IFluidDataStoreChannel , IFluidDataStoreContext , IFluidDataStoreFactory , IFluidDataStoreRegistry , FluidDataStoreRegistryEntry , NamedFluidDataStoreRegistryEntries , SummarizeInternalFn , CreateChildSummarizerNodeFn , CreateSummarizerNodeSource , } from "@fluidframework/runtime-definitions" ; import { FluidObject } from "@fluidframework/core-interfaces" ; import { IDocumentStorageService } from "@fluidframework/driver-definitions" ; import { MockFluidDataStoreRuntime } from "@fluidframework/test-runtime-utils" ; import { createRootSummarizerNodeWithGC } from "@fluidframework/runtime-utils" ; import { TelemetryNullLogger } from "@fluidframework/common-utils" ; import { LocalFluidDataStoreContext } from "../dataStoreContext" ; import { ContainerRuntime } from "../containerRuntime" ; describe ( "Data Store Creation Tests" , ( ) => { describe ( "Store creation via local context creation and realize" , ( ) => { /**
         * These tests simulate dataStore and subDataStore creation by creating local contexts and realizing them.
         * The dataStore tree for these tests is as follows:
         *
         *                  Default
         *                     |
         *                     |
         *                DataStore A
         *                   /   \
         *                  /     \
         *        DataStore B     DataStore C
         */ let storage ; let scope ; const attachCb = ( mR ) => { } ; let containerRuntime ; const defaultName = "default" ; const dataStoreAName = "dataStoreA" ; const dataStoreBName = "dataStoreB" ; const dataStoreCName = "dataStoreC" ; let getCreateSummarizerNodeFn ; function createDataStoreRegistryEntry ( entries ) { const registryEntries = new Map ( entries ) ; const factory = { type : "store-type" , get IFluidDataStoreFactory ( ) { return factory ; } , instantiateDataStore : async ( context ) => new MockFluidDataStoreRuntime ( ) } ; const registry = { get IFluidDataStoreRegistry ( ) { return registry ; } , get : async ( pkg ) => registryEntries . get ( pkg ) } ; const entry = { get IFluidDataStoreFactory ( ) { return factory ; } , get IFluidDataStoreRegistry ( ) { return registry ; } } ; return entry ; } beforeEach ( async ( ) => { const entryB = createDataStoreRegistryEntry ( [ ] ) ; const entryC = createDataStoreRegistryEntry ( [ ] ) ; const entryA = createDataStoreRegistryEntry ( [ [ dataStoreBName , Promise . resolve ( entryB ) ] , [ dataStoreCName , Promise . resolve ( entryC ) ] , ] ) ; const entryDefault = createDataStoreRegistryEntry ( [ [ dataStoreAName , Promise . resolve ( entryA ) ] ] ) ; const globalRegistryEntries = new Map ( [ [ defaultName , Promise . resolve ( entryDefault ) ] ] ) ; const globalRegistry = { get IFluidDataStoreRegistry ( ) { return globalRegistry ; } , get : async ( pkg ) => globalRegistryEntries . get ( pkg ) } ; containerRuntime = { IFluidDataStoreRegistry : globalRegistry , on : ( event , listener ) => { } , logger : new TelemetryNullLogger ( ) } as ContainerRuntime ; const summarizerNode = createRootSummarizerNodeWithGC ( new TelemetryNullLogger ( ) , ( ( ) => { } ) as unknown as SummarizeInternalFn , 0 , 0 ) ; getCreateSummarizerNodeFn = ( id ) => ( si ) => summarizerNode . createChild ( si , id , { type : CreateSummarizerNodeSource . Local } ) ; } ) ; it ( "Valid global dataStore" , async ( ) => { let success = true ; const dataStoreId = "default-Id" ; const context = new LocalFluidDataStoreContext ( dataStoreId , [ defaultName ] , containerRuntime , storage , scope , getCreateSummarizerNodeFn ( dataStoreId ) , attachCb , undefined , false ) ; try { await context . realize ( ) ; } catch ( error ) { success = false ; } assert . strictEqual ( success , true ) ; } ) ; it ( "Invalid global dataStore" , async ( ) => { let success = true ; const dataStoreId = "A-Id" ; const context = new LocalFluidDataStoreContext ( dataStoreId , [ dataStoreAName ] , containerRuntime , storage , scope , getCreateSummarizerNodeFn ( dataStoreId ) , attachCb , undefined , false ) ; try { await context . realize ( ) ; } catch ( error ) { success = false ; } assert . strictEqual ( success , false ) ; } ) ; it ( "Valid subDataStore from the global dataStore" , async ( ) => { let success = true ; const dataStoreId = "A-Id" ; const contextA = new LocalFluidDataStoreContext ( dataStoreId , [ defaultName , dataStoreAName ] , containerRuntime , storage , scope , getCreateSummarizerNodeFn ( dataStoreId ) , attachCb , undefined , false ) ; try { await contextA . realize ( ) ; } catch ( error ) { success = false ; } assert . strictEqual ( success , true ) ; } ) ; it ( "Invalid subDataStore from the global dataStore" , async ( ) => { let success = true ; const dataStoreId = "B-Id" ; const contextB = new LocalFluidDataStoreContext ( dataStoreId , [ defaultName , dataStoreBName ] , containerRuntime , storage , scope , getCreateSummarizerNodeFn ( dataStoreId ) , attachCb , undefined , false ) ; try { await contextB . realize ( ) ; } catch ( error ) { success = false ; } assert . strictEqual ( success , false ) ; } ) ; it ( "Valid subDataStore at depth 2" , async ( ) => { let success = true ; const dataStoreBId = "B-Id" ; const contextB = new LocalFluidDataStoreContext ( dataStoreBId , [ defaultName , dataStoreAName , dataStoreBName ] , containerRuntime , storage , scope , getCreateSummarizerNodeFn ( dataStoreBId ) , attachCb , undefined , false ) ; try { await contextB . realize ( ) ; } catch ( error ) { success = false ; } assert . strictEqual ( success , true ) ; const dataStoreCId = "C-Id" ; const contextC = new LocalFluidDataStoreContext ( dataStoreCId , [ defaultName , dataStoreAName , dataStoreCName ] , containerRuntime , storage , scope , getCreateSummarizerNodeFn ( dataStoreCId ) , attachCb , undefined , false ) ; try { await contextC . realize ( ) ; } catch ( error ) { success = false ; } assert . strictEqual ( success , true ) ; } ) ; it ( "Invalid subDataStore at depth 2" , async ( ) => { let success = true ; const dataStoreId = "fake-Id" ; const contextFake = new LocalFluidDataStoreContext ( dataStoreId , [ defaultName , dataStoreAName , "fake" ] , containerRuntime , storage , scope , getCreateSummarizerNodeFn ( dataStoreId ) , attachCb , undefined , false ) ; try { await contextFake . realize ( ) ; } catch ( error ) { success = false ; } assert . strictEqual ( success , false ) ; } ) ; it ( "Invalid subDataStore at depth 3" , async ( ) => { let success = true ; const dataStoreId = "fake-Id" ; const contextFake = new LocalFluidDataStoreContext ( dataStoreId , [ defaultName , dataStoreAName , dataStoreBName , "fake" ] , containerRuntime , storage , scope , getCreateSummarizerNodeFn ( dataStoreId ) , attachCb , undefined , false ) ; try { await contextFake . realize ( ) ; } catch ( error ) { success = false ; } assert . strictEqual ( success , false ) ; } ) ; it ( "SubDataStore which is in the registry of the parent dataStore" , async ( ) => { let success = true ; const dataStoreId = "C-Id" ; const contextC = new LocalFluidDataStoreContext ( dataStoreId , [ defaultName , dataStoreAName , dataStoreBName , dataStoreCName ] , containerRuntime , storage , scope , getCreateSummarizerNodeFn ( dataStoreId ) , attachCb , undefined , false ) ; try { await contextC . realize ( ) ; } catch ( error ) { success = false ; } assert . strictEqual ( success , false ) ; } ) ; } ) ; } ) ;