@@ -14,6 +14,19 @@ import (
1414 "github.com/authzed/spicedb/pkg/schema/v2"
1515)
1616
17+ // buildIterator is a test helper that builds a CanonicalOutline from the schema
18+ // and compiles it into an Iterator. It mirrors the old BuildIteratorFromSchema
19+ // convenience function which has been removed in favour of the explicit
20+ // BuildOutlineFromSchema → Compile() pipeline.
21+ func buildIterator (t * testing.T , fullSchema * schema.Schema , defName , relName string ) (Iterator , error ) {
22+ t .Helper ()
23+ co , err := BuildOutlineFromSchema (fullSchema , defName , relName )
24+ if err != nil {
25+ return nil , err
26+ }
27+ return co .Compile ()
28+ }
29+
1730func TestBuildTree (t * testing.T ) {
1831 t .Parallel ()
1932
@@ -28,7 +41,7 @@ func TestBuildTree(t *testing.T) {
2841 dsSchema , err := schema .BuildSchemaFromDefinitions (objectDefs , nil )
2942 require .NoError (err )
3043
31- it , err := BuildIteratorFromSchema ( dsSchema , "document" , "edit" )
44+ it , err := buildIterator ( t , dsSchema , "document" , "edit" )
3245 require .NoError (err )
3346
3447 ctx := NewLocalContext (t .Context (),
@@ -55,7 +68,7 @@ func TestBuildTreeMultipleRelations(t *testing.T) {
5568 require .NoError (err )
5669
5770 // Test building iterator for edit permission which creates a union
58- it , err := BuildIteratorFromSchema ( dsSchema , "document" , "edit" )
71+ it , err := buildIterator ( t , dsSchema , "document" , "edit" )
5972 require .NoError (err )
6073
6174 explain := it .Explain ()
@@ -81,12 +94,12 @@ func TestBuildTreeInvalidDefinition(t *testing.T) {
8194 require .NoError (err )
8295
8396 // Test with invalid definition name
84- _ , err = BuildIteratorFromSchema ( dsSchema , "nonexistent" , "edit" )
97+ _ , err = buildIterator ( t , dsSchema , "nonexistent" , "edit" )
8598 require .Error (err )
8699 require .Contains (err .Error (), "couldn't find a schema definition named `nonexistent`" )
87100
88101 // Test with invalid relation/permission name
89- _ , err = BuildIteratorFromSchema ( dsSchema , "document" , "nonexistent" )
102+ _ , err = buildIterator ( t , dsSchema , "document" , "nonexistent" )
90103 require .Error (err )
91104 require .Contains (err .Error (), "couldn't find a relation or permission named `nonexistent`" )
92105}
@@ -105,7 +118,7 @@ func TestBuildTreeSubRelations(t *testing.T) {
105118 require .NoError (err )
106119
107120 // Test building iterator for a relation with subrelations
108- it , err := BuildIteratorFromSchema ( dsSchema , "document" , "parent" )
121+ it , err := buildIterator ( t , dsSchema , "document" , "parent" )
109122 require .NoError (err )
110123
111124 // Should have created a relation iterator
@@ -152,7 +165,7 @@ func TestBuildTreeRecursion(t *testing.T) {
152165
153166 // This should detect recursion and create a RecursiveIterator
154167 // The arrow operation parent->member creates recursion: group->parent->member->parent->member...
155- it , err := BuildIteratorFromSchema ( dsSchema , "group" , "member" )
168+ it , err := buildIterator ( t , dsSchema , "group" , "member" )
156169 require .NoError (err )
157170 require .NotNil (it )
158171
@@ -203,7 +216,7 @@ func TestBuildTreeIntersectionOperation(t *testing.T) {
203216 require .NoError (err )
204217
205218 // Test building iterator for view_and_edit permission which uses intersection operations
206- it , err := BuildIteratorFromSchema ( dsSchema , "document" , "view_and_edit" )
219+ it , err := buildIterator ( t , dsSchema , "document" , "view_and_edit" )
207220 require .NoError (err )
208221
209222 // Should create an intersection iterator
@@ -245,7 +258,7 @@ func TestBuildTreeExclusionOperation(t *testing.T) {
245258 require .NoError (err )
246259
247260 // Test building iterator for exclusion permission - should succeed
248- it , err := BuildIteratorFromSchema ( dsSchema , "document" , "excluded_perm" )
261+ it , err := buildIterator ( t , dsSchema , "document" , "excluded_perm" )
249262 require .NoError (err )
250263 require .NotNil (it )
251264 // Should be wrapped in an Alias
@@ -297,7 +310,7 @@ func TestBuildTreeExclusionEdgeCases(t *testing.T) {
297310 dsSchema , err := schema .BuildSchemaFromDefinitions (objectDefs , nil )
298311 require .NoError (err )
299312
300- it , err := BuildIteratorFromSchema ( dsSchema , "document" , "can_view" )
313+ it , err := buildIterator ( t , dsSchema , "document" , "can_view" )
301314 require .NoError (err )
302315 require .NotNil (it )
303316 // Should be wrapped in an Alias
@@ -336,7 +349,7 @@ func TestBuildTreeExclusionEdgeCases(t *testing.T) {
336349 dsSchema , err := schema .BuildSchemaFromDefinitions (objectDefs , nil )
337350 require .NoError (err )
338351
339- it , err := BuildIteratorFromSchema ( dsSchema , "document" , "restricted_viewers" )
352+ it , err := buildIterator ( t , dsSchema , "document" , "restricted_viewers" )
340353 require .NoError (err )
341354 require .NotNil (it )
342355 // Should be wrapped in an Alias
@@ -377,7 +390,7 @@ func TestBuildTreeExclusionEdgeCases(t *testing.T) {
377390 dsSchema , err := schema .BuildSchemaFromDefinitions (objectDefs , nil )
378391 require .NoError (err )
379392
380- it , err := BuildIteratorFromSchema ( dsSchema , "document" , "restricted_view" )
393+ it , err := buildIterator ( t , dsSchema , "document" , "restricted_view" )
381394 require .NoError (err )
382395 require .NotNil (it )
383396 // Should be wrapped in an Alias
@@ -419,7 +432,7 @@ func TestBuildTreeExclusionEdgeCases(t *testing.T) {
419432 dsSchema , err := schema .BuildSchemaFromDefinitions (objectDefs , nil )
420433 require .NoError (err )
421434
422- it , err := BuildIteratorFromSchema ( dsSchema , "document" , "allowed_users" )
435+ it , err := buildIterator ( t , dsSchema , "document" , "allowed_users" )
423436 require .NoError (err )
424437 require .NotNil (it )
425438 // Should be wrapped in an Alias
@@ -457,7 +470,7 @@ func TestBuildTreeExclusionEdgeCases(t *testing.T) {
457470 require .NoError (err )
458471
459472 // Building iterator should fail due to missing relation
460- _ , err = BuildIteratorFromSchema ( dsSchema , "document" , "bad_exclusion" )
473+ _ , err = buildIterator ( t , dsSchema , "document" , "bad_exclusion" )
461474 require .Error (err )
462475 require .Contains (err .Error (), "couldn't find a relation or permission named `nonexistent_relation`" )
463476 })
@@ -480,7 +493,7 @@ func TestBuildTreeExclusionEdgeCases(t *testing.T) {
480493 require .NoError (err )
481494
482495 // Building iterator should fail due to missing relation
483- _ , err = BuildIteratorFromSchema ( dsSchema , "document" , "bad_exclusion" )
496+ _ , err = buildIterator ( t , dsSchema , "document" , "bad_exclusion" )
484497 require .Error (err )
485498 require .Contains (err .Error (), "couldn't find a relation or permission named `nonexistent_relation`" )
486499 })
@@ -507,7 +520,7 @@ func TestBuildTreeArrowMissingLeftRelation(t *testing.T) {
507520 require .NoError (err )
508521
509522 // Test building iterator for arrow with missing left relation
510- _ , err = BuildIteratorFromSchema ( dsSchema , "document" , "bad_arrow" )
523+ _ , err = buildIterator ( t , dsSchema , "document" , "bad_arrow" )
511524 require .Error (err )
512525 require .Contains (err .Error (), "couldn't find left-hand relation for arrow" )
513526}
@@ -526,7 +539,7 @@ func TestBuildTreeSingleRelationOptimization(t *testing.T) {
526539 require .NoError (err )
527540
528541 // Test building iterator for a simple relation - should not create unnecessary unions
529- it , err := BuildIteratorFromSchema ( dsSchema , "document" , "owner" )
542+ it , err := buildIterator ( t , dsSchema , "document" , "owner" )
530543 require .NoError (err )
531544
532545 // Should create a simple relation iterator without extra union wrappers
@@ -580,7 +593,7 @@ func TestBuildTreeSubrelationHandling(t *testing.T) {
580593 require .NoError (err )
581594
582595 // Should create an alias wrapping union with arrow
583- it , err := BuildIteratorFromSchema ( dsSchema , "document" , "viewer" )
596+ it , err := buildIterator ( t , dsSchema , "document" , "viewer" )
584597 require .NoError (err )
585598 require .NotNil (it )
586599
@@ -617,7 +630,7 @@ func TestBuildTreeSubrelationHandling(t *testing.T) {
617630 dsSchema , err := schema .BuildSchemaFromDefinitions (objectDefs , nil )
618631 require .NoError (err )
619632
620- it , err := BuildIteratorFromSchema ( dsSchema , "document" , "viewer" )
633+ it , err := buildIterator ( t , dsSchema , "document" , "viewer" )
621634 require .NoError (err )
622635 require .NotNil (it )
623636
@@ -649,7 +662,7 @@ func TestBuildTreeSubrelationHandling(t *testing.T) {
649662 require .NoError (err )
650663
651664 // Should create RecursiveIterator for arrow recursion
652- it , err := BuildIteratorFromSchema ( dsSchema , "document" , "viewer" )
665+ it , err := buildIterator ( t , dsSchema , "document" , "viewer" )
653666 require .NoError (err )
654667 require .NotNil (it )
655668
@@ -680,7 +693,7 @@ func TestBuildTreeSubrelationHandling(t *testing.T) {
680693 require .NoError (err )
681694
682695 // Should fail when trying to build iterator due to missing subrelation
683- _ , err = BuildIteratorFromSchema ( dsSchema , "document" , "viewer" )
696+ _ , err = buildIterator ( t , dsSchema , "document" , "viewer" )
684697 require .Error (err )
685698 require .Contains (err .Error (), "couldn't find a relation or permission named `nonexistent`" )
686699 })
@@ -708,7 +721,7 @@ func TestBuildTreeSubrelationHandling(t *testing.T) {
708721 dsSchema , err := schema .BuildSchemaFromDefinitions (objectDefs , nil )
709722 require .NoError (err )
710723
711- it , err := BuildIteratorFromSchema ( dsSchema , "document" , "viewer" )
724+ it , err := buildIterator ( t , dsSchema , "document" , "viewer" )
712725 require .NoError (err )
713726 require .NotNil (it )
714727
@@ -770,7 +783,7 @@ func TestBuildTreeWildcardIterator(t *testing.T) {
770783
771784 t .Run ("Schema with wildcard creates WildcardIterator" , func (t * testing.T ) {
772785 t .Parallel ()
773- it , err := BuildIteratorFromSchema ( dsSchema , "document" , "viewer" )
786+ it , err := buildIterator ( t , dsSchema , "document" , "viewer" )
774787 require .NoError (err )
775788 require .NotNil (it )
776789
@@ -801,7 +814,7 @@ func TestBuildTreeWildcardIterator(t *testing.T) {
801814 mixedSchema , err := schema .BuildSchemaFromDefinitions (mixedObjectDefs , nil )
802815 require .NoError (err )
803816
804- it , err := BuildIteratorFromSchema ( mixedSchema , "document" , "viewer" )
817+ it , err := buildIterator ( t , mixedSchema , "document" , "viewer" )
805818 require .NoError (err )
806819 require .NotNil (it )
807820
@@ -859,7 +872,7 @@ func TestBuildTreeMutualRecursionSentinelFiltering(t *testing.T) {
859872 t .Run ("document viewer builds successfully with mutual recursion" , func (t * testing.T ) {
860873 t .Parallel ()
861874 // Build iterator for document#viewer - should detect recursion and wrap properly
862- it , err := BuildIteratorFromSchema ( dsSchema , "document" , "viewer" )
875+ it , err := buildIterator ( t , dsSchema , "document" , "viewer" )
863876 require .NoError (err )
864877 require .NotNil (it )
865878
@@ -872,7 +885,7 @@ func TestBuildTreeMutualRecursionSentinelFiltering(t *testing.T) {
872885 t .Run ("otherdocument viewer builds successfully with mutual recursion" , func (t * testing.T ) {
873886 t .Parallel ()
874887 // Build iterator for otherdocument#viewer - should also handle mutual recursion
875- it , err := BuildIteratorFromSchema ( dsSchema , "otherdocument" , "viewer" )
888+ it , err := buildIterator ( t , dsSchema , "otherdocument" , "viewer" )
876889 require .NoError (err )
877890 require .NotNil (it )
878891
@@ -890,7 +903,7 @@ func TestBuildTreeMutualRecursionSentinelFiltering(t *testing.T) {
890903 // its own sentinels.
891904
892905 // Build the tree
893- it , err := BuildIteratorFromSchema ( dsSchema , "document" , "viewer" )
906+ it , err := buildIterator ( t , dsSchema , "document" , "viewer" )
894907 require .NoError (err )
895908 require .NotNil (it )
896909
0 commit comments