@@ -29,24 +29,18 @@ import {
29
29
} from "@fluidframework/test-runtime-utils/internal" ;
30
30
31
31
import {
32
- AllowedUpdateType ,
33
32
type ChangeFamily ,
34
33
type ChangeFamilyEditor ,
35
34
type GraphCommit ,
36
35
rootFieldKey ,
37
36
} from "../../core/index.js" ;
38
- import { leaf } from "../../domains/index.js" ;
39
37
import {
40
38
type DefaultChangeset ,
41
39
type DefaultEditBuilder ,
42
- FieldKinds ,
43
- FlexFieldSchema ,
44
40
type ModularChangeset ,
45
- SchemaBuilderBase ,
46
41
cursorForJsonableTreeNode ,
47
- typeNameSymbol ,
48
42
} from "../../feature-libraries/index.js" ;
49
- import type { InitializeAndSchematizeConfiguration } from "../../shared-tree/index.js" ;
43
+ import { Tree } from "../../shared-tree/index.js" ;
50
44
import type {
51
45
ChangeEnricherReadonlyCheckout ,
52
46
EditManager ,
@@ -57,14 +51,12 @@ import type {
57
51
SummaryElementStringifier ,
58
52
} from "../../shared-tree-core/index.js" ;
59
53
import { brand , disposeSymbol } from "../../util/index.js" ;
60
- import {
61
- SharedTreeTestFactory ,
62
- TestTreeProviderLite ,
63
- schematizeFlexTree ,
64
- stringSequenceRootSchema ,
65
- } from "../utils.js" ;
54
+ import { SharedTreeTestFactory , StringArray , TestTreeProviderLite } from "../utils.js" ;
66
55
67
56
import { TestSharedTreeCore } from "./utils.js" ;
57
+ import { SchemaFactory } from "../../simple-tree/index.js" ;
58
+
59
+ const enableSchemaValidation = true ;
68
60
69
61
describe ( "SharedTreeCore" , ( ) => {
70
62
it ( "summarizes without indexes" , async ( ) => {
@@ -301,14 +293,10 @@ describe("SharedTreeCore", () => {
301
293
objectStorage : new MockStorage ( ) ,
302
294
} ) ;
303
295
304
- const b = new SchemaBuilderBase ( FieldKinds . optional , {
305
- scope : "0x4a6 repro" ,
306
- libraries : [ leaf . library ] ,
296
+ const sf = new SchemaFactory ( "0x4a6 repro" ) ;
297
+ const TestNode = sf . objectRecursive ( "test node" , {
298
+ child : sf . optionalRecursive ( [ ( ) => TestNode , sf . number ] ) ,
307
299
} ) ;
308
- const node = b . objectRecursive ( "test node" , {
309
- child : FlexFieldSchema . createUnsafe ( FieldKinds . optional , [ ( ) => node , leaf . number ] ) ,
310
- } ) ;
311
- const schema = b . intoSchema ( node ) ;
312
300
313
301
const tree2 = await factory . load (
314
302
dataStoreRuntime2 ,
@@ -320,107 +308,95 @@ describe("SharedTreeCore", () => {
320
308
factory . attributes ,
321
309
) ;
322
310
323
- const config = {
324
- schema,
325
- initialTree : undefined ,
326
- allowedSchemaModifications : AllowedUpdateType . Initialize ,
327
- } satisfies InitializeAndSchematizeConfiguration ;
328
-
329
- const view1 = schematizeFlexTree ( tree1 , config ) ;
311
+ const view1 = tree1 . viewWith ( { schema : TestNode , enableSchemaValidation } ) ;
312
+ view1 . initialize ( new TestNode ( { } ) ) ;
330
313
containerRuntimeFactory . processAllMessages ( ) ;
331
- const view2 = schematizeFlexTree ( tree2 , config ) ;
332
- const editable1 = view1 . flexTree ;
333
- const editable2 = view2 . flexTree ;
334
-
335
- editable2 . content = { [ typeNameSymbol ] : node . name , child : undefined } ;
336
- editable1 . content = { [ typeNameSymbol ] : node . name , child : undefined } ;
337
- const rootNode = editable2 . content ;
338
- assert ( rootNode ?. is ( node ) , "Expected set operation to set root node" ) ;
339
- rootNode . boxedChild . content = 42 ;
340
- editable1 . content = { [ typeNameSymbol ] : node . name , child : undefined } ;
341
- rootNode . boxedChild . content = 43 ;
314
+ const view2 = tree2 . viewWith ( { schema : TestNode , enableSchemaValidation } ) ;
315
+
316
+ view2 . root = new TestNode ( { } ) ;
317
+ view1 . root = new TestNode ( { } ) ;
318
+ assert ( Tree . is ( view2 . root , TestNode ) , "Expected set operation to set root node" ) ;
319
+ view2 . root . child = 42 ;
320
+ view1 . root = new TestNode ( { } ) ;
321
+ view2 . root . child = 43 ;
342
322
containerRuntimeFactory . processAllMessages ( ) ;
343
323
assert . deepEqual ( tree1 . contentSnapshot ( ) . tree , [
344
324
{
345
- type : node . name ,
325
+ type : TestNode . identifier ,
346
326
} ,
347
327
] ) ;
348
328
assert . deepEqual ( tree2 . contentSnapshot ( ) . tree , [
349
329
{
350
- type : node . name ,
330
+ type : TestNode . identifier ,
351
331
} ,
352
332
] ) ;
353
333
} ) ;
354
334
355
335
it ( "Does not submit changes that were aborted in an outer transaction" , async ( ) => {
356
336
const provider = new TestTreeProviderLite ( 2 ) ;
357
- const content = {
358
- schema : stringSequenceRootSchema ,
359
- allowedSchemaModifications : AllowedUpdateType . Initialize ,
360
- initialTree : [ "A" , "B" ] ,
361
- } satisfies InitializeAndSchematizeConfiguration ;
362
- const tree1 = schematizeFlexTree ( provider . trees [ 0 ] , content ) ;
337
+ const view1 = provider . trees [ 0 ] . viewWith ( {
338
+ schema : StringArray ,
339
+ enableSchemaValidation,
340
+ } ) ;
341
+ view1 . initialize ( [ "A" , "B" ] ) ;
363
342
provider . processMessages ( ) ;
364
- const tree2 = schematizeFlexTree ( provider . trees [ 1 ] , content ) ;
343
+ const view2 = provider . trees [ 1 ] . viewWith ( {
344
+ schema : StringArray ,
345
+ enableSchemaValidation,
346
+ } ) ;
365
347
366
- const root1 = tree1 . flexTree ;
367
- const root2 = tree2 . flexTree ;
348
+ const root1 = view1 . root ;
349
+ const root2 = view2 . root ;
368
350
369
- tree1 . checkout . transaction . start ( ) ;
370
- {
351
+ Tree . runTransaction ( root1 , ( ) => {
371
352
// Remove A as part of the aborted transaction
372
353
root1 . removeAt ( 0 ) ;
373
- tree1 . checkout . transaction . start ( ) ;
374
- {
354
+ Tree . runTransaction ( root1 , ( ) => {
375
355
// Remove B as part of the committed inner transaction
376
356
root1 . removeAt ( 0 ) ;
377
- }
378
- tree1 . checkout . transaction . commit ( ) ;
379
- }
380
- tree1 . checkout . transaction . abort ( ) ;
357
+ } ) ;
358
+ return Tree . runTransaction . rollback ;
359
+ } ) ;
381
360
382
361
provider . processMessages ( ) ;
383
- assert . deepEqual ( [ ...root2 ] , [ "A" , "B" ] ) ;
362
+ assert . deepEqual ( [ ...root1 ] , [ "A" , "B" ] ) ;
384
363
assert . deepEqual ( [ ...root2 ] , [ "A" , "B" ] ) ;
385
364
386
365
// Make an additional change to ensure that all changes from the previous transactions were flushed
387
- tree1 . checkout . transaction . start ( ) ;
388
- {
366
+ Tree . runTransaction ( root1 , ( ) => {
389
367
root1 . insertAtEnd ( "C" ) ;
390
- }
391
- tree1 . checkout . transaction . commit ( ) ;
368
+ } ) ;
369
+
392
370
provider . processMessages ( ) ;
393
- assert . deepEqual ( [ ...root2 ] , [ "A" , "B" , "C" ] ) ;
371
+ assert . deepEqual ( [ ...root1 ] , [ "A" , "B" , "C" ] ) ;
394
372
assert . deepEqual ( [ ...root2 ] , [ "A" , "B" , "C" ] ) ;
395
373
} ) ;
396
374
397
375
it ( "Does not submit changes that were aborted in an inner transaction" , async ( ) => {
398
376
const provider = new TestTreeProviderLite ( 2 ) ;
399
- const content = {
400
- schema : stringSequenceRootSchema ,
401
- allowedSchemaModifications : AllowedUpdateType . Initialize ,
402
- initialTree : [ "A" , "B" ] ,
403
- } satisfies InitializeAndSchematizeConfiguration ;
404
- const tree1 = schematizeFlexTree ( provider . trees [ 0 ] , content ) ;
405
-
377
+ const view1 = provider . trees [ 0 ] . viewWith ( {
378
+ schema : StringArray ,
379
+ enableSchemaValidation,
380
+ } ) ;
381
+ view1 . initialize ( [ "A" , "B" ] ) ;
406
382
provider . processMessages ( ) ;
407
- const tree2 = schematizeFlexTree ( provider . trees [ 1 ] , content ) ;
383
+ const view2 = provider . trees [ 1 ] . viewWith ( {
384
+ schema : StringArray ,
385
+ enableSchemaValidation,
386
+ } ) ;
408
387
409
- const root1 = tree1 . flexTree ;
410
- const root2 = tree2 . flexTree ;
388
+ const root1 = view1 . root ;
389
+ const root2 = view2 . root ;
411
390
412
- tree1 . checkout . transaction . start ( ) ;
413
- {
391
+ Tree . runTransaction ( root1 , ( ) => {
414
392
// Remove A as part of the committed transaction
415
393
root1 . removeAt ( 0 ) ;
416
- tree1 . checkout . transaction . start ( ) ;
417
- {
394
+ Tree . runTransaction ( root1 , ( ) => {
418
395
// Remove B as part of the aborted transaction
419
396
root1 . removeAt ( 0 ) ;
420
- }
421
- tree1 . checkout . transaction . abort ( ) ;
422
- }
423
- tree1 . checkout . transaction . commit ( ) ;
397
+ return Tree . runTransaction . rollback ;
398
+ } ) ;
399
+ } ) ;
424
400
425
401
assert . deepEqual ( [ ...root1 ] , [ "B" ] ) ;
426
402
assert . deepEqual ( [ ...root2 ] , [ "A" , "B" ] ) ;
@@ -431,11 +407,10 @@ describe("SharedTreeCore", () => {
431
407
assert . deepEqual ( [ ...root2 ] , [ "B" ] ) ;
432
408
433
409
// Make an additional change to ensure that all changes from the previous transactions were flushed
434
- tree1 . checkout . transaction . start ( ) ;
435
- {
410
+ Tree . runTransaction ( root1 , ( ) => {
436
411
root1 . insertAtEnd ( "C" ) ;
437
- }
438
- tree1 . checkout . transaction . commit ( ) ;
412
+ } ) ;
413
+
439
414
provider . processMessages ( ) ;
440
415
assert . deepEqual ( [ ...root2 ] , [ "B" , "C" ] ) ;
441
416
assert . deepEqual ( [ ...root2 ] , [ "B" , "C" ] ) ;
0 commit comments