Skip to content

Commit f819b10

Browse files
committed
Unit test works and covers the changes to SharedObjectFromKernel.
1 parent b33574b commit f819b10

File tree

5 files changed

+145
-7
lines changed

5 files changed

+145
-7
lines changed

packages/dds/shared-object-base/src/test/createSharedObjectKind.spec.ts

Lines changed: 132 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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";
1825
import { MockFluidDataStoreRuntime } from "@fluidframework/test-runtime-utils/internal";
1926

27+
import type { IFluidSerializer } from "../serializer.js";
2028
import { 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

2238
interface IFoo {
2339
foo: string;
24-
minVersionForCollab: MinimumVersionForCollab;
40+
minVersionForCollab: MinimumVersionForCollab | undefined;
2541
}
2642
class 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+
91166
describe("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
});

packages/runtime/test-runtime-utils/api-report/test-runtime-utils.legacy.beta.api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,8 @@ export class MockFluidDataStoreRuntime extends EventEmitter implements IFluidDat
470470
// (undocumented)
471471
makeVisibleAndAttachGraph(): void;
472472
// (undocumented)
473+
readonly minVersionForCollab: MinimumVersionForCollab | undefined;
474+
// (undocumented)
473475
notifyReadOnlyState(readonly: boolean): void;
474476
// (undocumented)
475477
get objectsRoutingContext(): IFluidHandleContext;

packages/runtime/test-runtime-utils/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@
156156
"broken": {
157157
"Class_MockFluidDataStoreContext": {
158158
"forwardCompat": false
159+
},
160+
"Class_MockFluidDataStoreRuntime": {
161+
"forwardCompat": false
159162
}
160163
},
161164
"entrypoint": "legacy"

packages/runtime/test-runtime-utils/src/mocks.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,13 +880,20 @@ export class MockFluidDataStoreRuntime
880880
if (registry) {
881881
this.registry = new Map(registry.map((factory) => [factory.type, factory]));
882882
}
883+
884+
this.minVersionForCollab = overrides?.minVersionForCollab;
883885
}
884886

885887
private readonly: boolean = false;
886888
public readonly isReadOnly = () => this.readonly;
887889

888890
public readonly entryPoint: IFluidHandleInternal<FluidObject>;
889891

892+
/**
893+
* @see IFluidDataStoreRuntimeInternalConfig.minVersionForCollab
894+
*/
895+
public readonly minVersionForCollab: MinimumVersionForCollab | undefined;
896+
890897
public get IFluidHandleContext(): IFluidHandleContext {
891898
return this;
892899
}

packages/runtime/test-runtime-utils/src/test/types/validateTestRuntimeUtilsPrevious.generated.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ declare type current_as_old_for_Class_MockFluidDataStoreContext = requireAssigna
185185
* typeValidation.broken:
186186
* "Class_MockFluidDataStoreRuntime": {"forwardCompat": false}
187187
*/
188+
// @ts-expect-error compatibility expected to be broken
188189
declare type old_as_current_for_Class_MockFluidDataStoreRuntime = requireAssignableTo<TypeOnly<old.MockFluidDataStoreRuntime>, TypeOnly<current.MockFluidDataStoreRuntime>>
189190

190191
/*

0 commit comments

Comments
 (0)