@@ -11,17 +11,33 @@ import type {
1111 IChannelAttributes ,
1212 IChannelFactory ,
1313 IChannelServices ,
14+ IChannelStorageService ,
1415 IFluidDataStoreRuntime ,
1516 IFluidDataStoreRuntimeInternalConfig ,
1617} from "@fluidframework/datastore-definitions/internal" ;
17- import type { MinimumVersionForCollab } from "@fluidframework/runtime-definitions/internal" ;
18+ import type {
19+ IExperimentalIncrementalSummaryContext ,
20+ IRuntimeMessageCollection ,
21+ ISummaryTreeWithStats ,
22+ ITelemetryContext ,
23+ MinimumVersionForCollab ,
24+ } from "@fluidframework/runtime-definitions/internal" ;
1825import { MockFluidDataStoreRuntime } from "@fluidframework/test-runtime-utils/internal" ;
1926
27+ import type { IFluidSerializer } from "../serializer.js" ;
2028import { createSharedObjectKind } from "../sharedObject.js" ;
29+ import {
30+ makeSharedObjectKind ,
31+ type FactoryOut ,
32+ type KernelArgs ,
33+ type SharedKernel ,
34+ type SharedKernelFactory ,
35+ type SharedObjectOptions ,
36+ } from "../sharedObjectKernel.js" ;
2137
2238interface IFoo {
2339 foo : string ;
24- minVersionForCollab : MinimumVersionForCollab ;
40+ minVersionForCollab : MinimumVersionForCollab | undefined ;
2541}
2642class SharedFooFactory implements IChannelFactory < IFoo > {
2743 public static readonly Type : string = "SharedFoo" ;
@@ -88,11 +104,120 @@ describe("createSharedObjectKind's return type", () => {
88104 } ) ;
89105} ) ;
90106
107+ /**
108+ * The options used to construct a `FooKernelFactory`.
109+ */
110+ interface FooOptionsInternal {
111+ readonly minVersionForCollab : MinimumVersionForCollab ;
112+ }
113+
114+ /**
115+ * A minimal implementation of a `KernelView` based on `SharedTreeKernelView` in the \@fluidframework/tree package.
116+ */
117+ interface FooKernelView extends IFoo {
118+ readonly kernel : FooKernel ;
119+ readonly minVersionForCollab : MinimumVersionForCollab | undefined ;
120+ readonly foo : string ;
121+ }
122+
123+ /**
124+ * A minimal implementation of a `SharedKernel` that builds a view containing the `minVersionForCollab` it was
125+ * constructed with. Does not provide any method implementations beyond the constructor.
126+ */
127+ class FooKernel implements SharedKernel {
128+ public readonly view : FooKernelView ;
129+
130+ constructor ( minVersionForCollab : MinimumVersionForCollab | undefined ) {
131+ this . view = {
132+ kernel : this ,
133+ minVersionForCollab,
134+ foo : "foo" ,
135+ } ;
136+ }
137+
138+ summarizeCore (
139+ serializer : IFluidSerializer ,
140+ telemetryContext : ITelemetryContext | undefined ,
141+ incrementalSummaryContext : IExperimentalIncrementalSummaryContext | undefined ,
142+ fullTree ?: boolean ,
143+ ) : ISummaryTreeWithStats {
144+ throw new Error ( "Method not implemented." ) ;
145+ }
146+ onDisconnect ( ) : void {
147+ throw new Error ( "Method not implemented." ) ;
148+ }
149+ reSubmitCore ( content : unknown , localOpMetadata : unknown ) : void {
150+ throw new Error ( "Method not implemented." ) ;
151+ }
152+ applyStashedOp ( content : unknown ) : void {
153+ throw new Error ( "Method not implemented." ) ;
154+ }
155+ processMessagesCore ( messagesCollection : IRuntimeMessageCollection ) : void {
156+ throw new Error ( "Method not implemented." ) ;
157+ }
158+ rollback ?( content : unknown , localOpMetadata : unknown ) : void {
159+ throw new Error ( "Method not implemented." ) ;
160+ }
161+ didAttach ?( ) : void {
162+ throw new Error ( "Method not implemented." ) ;
163+ }
164+ }
165+
91166describe ( "createSharedObjectKind with minVersionForCollab" , ( ) => {
92- it ( "SharedObject can read minVersionForCollab from the runtime" , ( ) => {
93- const factory = SharedFoo . getFactory ( ) ;
94- const runtime = new MockFluidDataStoreRuntime ( { minVersionForCollab : "1.2.3" } ) ;
95- const sharedObject = factory . create ( runtime , "test-id" ) ;
96- assert . strictEqual ( sharedObject . minVersionForCollab , "1.2.3" ) ;
167+ /**
168+ * A simple KernelFactory that creates a `FooKernel` with the `minVersionForCollab` from its constructor arguments.
169+ * @param options - The options for the factory.
170+ * @returns A `SharedKernelFactory` that creates `FooKernelView` instances.
171+ */
172+ function fooKernelFactory ( options : FooOptionsInternal ) : SharedKernelFactory < FooKernelView > {
173+ function fooFromKernelArgs ( args : KernelArgs ) : FooKernel {
174+ return new FooKernel ( args . minVersionForCollab ) ;
175+ }
176+
177+ return {
178+ create ( args : KernelArgs ) : FactoryOut < FooKernelView > {
179+ const kernel = fooFromKernelArgs ( args ) ;
180+ return { kernel, view : kernel . view } ;
181+ } ,
182+ async loadCore (
183+ args : KernelArgs ,
184+ storage : IChannelStorageService ,
185+ ) : Promise < FactoryOut < FooKernelView > > {
186+ const kernel = fooFromKernelArgs ( args ) ;
187+ // There is no differentiation between load and create for the purposes of this test.
188+ return { kernel, view : kernel . view } ;
189+ } ,
190+ } ;
191+ }
192+
193+ it ( "SharedObject can be constructed with a minVersionForCollab from the runtime" , ( ) => {
194+ const minVersionForCollab = "1.2.3" ;
195+ const type = "Foo" ;
196+
197+ const attributes : IChannelAttributes = {
198+ type,
199+ snapshotFormatVersion : "0.1" ,
200+ packageVersion : "2.0.0" ,
201+ } ;
202+
203+ const options : FooOptionsInternal = {
204+ minVersionForCollab,
205+ } ;
206+
207+ const sharedObjectOptions : SharedObjectOptions < IFoo > = {
208+ type : "" ,
209+ attributes,
210+ telemetryContextPrefix : "foo_" ,
211+ factory : fooKernelFactory ( options ) ,
212+ } ;
213+
214+ const LocalSharedFoo = makeSharedObjectKind ( sharedObjectOptions ) ;
215+ const runtime = new MockFluidDataStoreRuntime ( {
216+ registry : [ LocalSharedFoo . getFactory ( ) ] ,
217+ minVersionForCollab,
218+ } ) ;
219+ const foo = LocalSharedFoo . create ( runtime , "test-id" ) ;
220+
221+ assert . strictEqual ( foo . minVersionForCollab , "1.2.3" ) ;
97222 } ) ;
98223} ) ;
0 commit comments