@@ -485,6 +485,188 @@ void mutuallyRecursiveRecipesDetectedAsCycle() {
485485 .hasMessageContaining ("RecipeB" );
486486 }
487487
488+ @ Issue ("https://github.com/openrewrite/rewrite/issues/6698" )
489+ @ Test
490+ void nestedScanningRecipeInOrPrecondition () {
491+ rewriteRun (
492+ spec -> spec .recipeFromYaml (
493+ """
494+ type: specs.openrewrite.org/v1beta/recipe
495+ name: org.sample.AddJacksonAnnotations
496+ description: Test.
497+ preconditions:
498+ - org.sample.ProjectUsesJackson
499+ recipeList:
500+ - org.openrewrite.text.ChangeText:
501+ toText: changed
502+ ---
503+ type: specs.openrewrite.org/v1beta/recipe
504+ name: org.sample.ProjectUsesJackson
505+ description: OR precondition - matches if ANY condition is true
506+ recipeList:
507+ - org.openrewrite.search.RepositoryContainsFile:
508+ filePattern: "**/jackson-config.json"
509+ - org.openrewrite.search.RepositoryContainsFile:
510+ filePattern: "**/jackson.properties"
511+ """ ,
512+ "org.sample.AddJacksonAnnotations"
513+ ),
514+ // jackson-config.json triggers the precondition, so all files get changed
515+ text ("config" , "changed" , spec -> spec .path ("jackson-config.json" )),
516+ text ("original" , "changed" )
517+ );
518+ }
519+
520+ @ Issue ("https://github.com/openrewrite/rewrite/issues/6698" )
521+ @ Test
522+ void nestedScanningRecipeInOrPreconditionNotMet () {
523+ rewriteRun (
524+ spec -> spec .recipeFromYaml (
525+ """
526+ type: specs.openrewrite.org/v1beta/recipe
527+ name: org.sample.AddJacksonAnnotations
528+ description: Test.
529+ preconditions:
530+ - org.sample.ProjectUsesJackson
531+ recipeList:
532+ - org.openrewrite.text.ChangeText:
533+ toText: changed
534+ ---
535+ type: specs.openrewrite.org/v1beta/recipe
536+ name: org.sample.ProjectUsesJackson
537+ description: OR precondition - matches if ANY condition is true
538+ recipeList:
539+ - org.openrewrite.search.RepositoryContainsFile:
540+ filePattern: "**/jackson-config.json"
541+ - org.openrewrite.search.RepositoryContainsFile:
542+ filePattern: "**/jackson.properties"
543+ """ ,
544+ "org.sample.AddJacksonAnnotations"
545+ ),
546+ text ("config" , spec -> spec .path ("some-other-file.txt" )),
547+ text ("original" )
548+ );
549+ }
550+
551+ @ Issue ("https://github.com/openrewrite/rewrite/issues/6698" )
552+ @ Test
553+ void sameScanningRecipeWithDifferentParametersInOrPrecondition () {
554+ rewriteRun (
555+ spec -> spec .recipeFromYaml (
556+ """
557+ type: specs.openrewrite.org/v1beta/recipe
558+ name: org.sample.MultiFileCheck
559+ description: Test.
560+ preconditions:
561+ - org.sample.HasAnyConfigFile
562+ recipeList:
563+ - org.openrewrite.text.ChangeText:
564+ toText: changed
565+ ---
566+ type: specs.openrewrite.org/v1beta/recipe
567+ name: org.sample.HasAnyConfigFile
568+ description: OR precondition with same recipe type but different params
569+ recipeList:
570+ - org.openrewrite.search.RepositoryContainsFile:
571+ filePattern: "**/config-a.json"
572+ - org.openrewrite.search.RepositoryContainsFile:
573+ filePattern: "**/config-b.json"
574+ - org.openrewrite.search.RepositoryContainsFile:
575+ filePattern: "**/config-c.json"
576+ """ ,
577+ "org.sample.MultiFileCheck"
578+ ),
579+ // Only config-b.json exists, so should still match due to OR logic
580+ // When matched, all files are changed
581+ text ("config b" , "changed" , spec -> spec .path ("config-b.json" )),
582+ text ("original" , "changed" )
583+ );
584+ }
585+
586+ @ Issue ("https://github.com/openrewrite/rewrite/issues/6698" )
587+ @ Test
588+ void deeplyNestedOrPreconditionsWithScanningRecipe () {
589+ rewriteRun (
590+ spec -> spec .recipeFromYaml (
591+ """
592+ type: specs.openrewrite.org/v1beta/recipe
593+ name: org.sample.TopLevel
594+ description: Test.
595+ preconditions:
596+ - org.sample.MiddleLevel
597+ recipeList:
598+ - org.openrewrite.text.ChangeText:
599+ toText: changed
600+ ---
601+ type: specs.openrewrite.org/v1beta/recipe
602+ name: org.sample.MiddleLevel
603+ description: Middle level precondition
604+ recipeList:
605+ - org.sample.BottomLevel
606+ - org.openrewrite.search.RepositoryContainsFile:
607+ filePattern: "**/middle.json"
608+ ---
609+ type: specs.openrewrite.org/v1beta/recipe
610+ name: org.sample.BottomLevel
611+ description: Bottom level with scanning recipes
612+ recipeList:
613+ - org.openrewrite.search.RepositoryContainsFile:
614+ filePattern: "**/bottom-a.json"
615+ - org.openrewrite.search.RepositoryContainsFile:
616+ filePattern: "**/bottom-b.json"
617+ """ ,
618+ "org.sample.TopLevel"
619+ ),
620+ // Only bottom-b.json exists, which should match through the nested OR chain
621+ // When matched, all files are changed
622+ text ("bottom b config" , "changed" , spec -> spec .path ("bottom-b.json" )),
623+ text ("original" , "changed" )
624+ );
625+ }
626+
627+ @ Issue ("https://github.com/openrewrite/rewrite/issues/6698" )
628+ @ Test
629+ void multipleNestedOrPreconditionsWithSameScanningRecipe () {
630+ rewriteRun (
631+ spec -> spec .recipeFromYaml (
632+ """
633+ type: specs.openrewrite.org/v1beta/recipe
634+ name: org.sample.TopLevel
635+ description: Test.
636+ preconditions:
637+ - org.sample.BranchA
638+ - org.sample.BranchB
639+ recipeList:
640+ - org.openrewrite.text.ChangeText:
641+ toText: changed
642+ ---
643+ type: specs.openrewrite.org/v1beta/recipe
644+ name: org.sample.BranchA
645+ description: First branch
646+ recipeList:
647+ - org.openrewrite.search.RepositoryContainsFile:
648+ filePattern: "**/branch-a-1.json"
649+ - org.openrewrite.search.RepositoryContainsFile:
650+ filePattern: "**/shared.json"
651+ ---
652+ type: specs.openrewrite.org/v1beta/recipe
653+ name: org.sample.BranchB
654+ description: Second branch
655+ recipeList:
656+ - org.openrewrite.search.RepositoryContainsFile:
657+ filePattern: "**/branch-b-1.json"
658+ - org.openrewrite.search.RepositoryContainsFile:
659+ filePattern: "**/shared.json"
660+ """ ,
661+ "org.sample.TopLevel"
662+ ),
663+ // shared.json exists, which should satisfy both branches (AND of two ORs)
664+ // When matched, all files are changed
665+ text ("shared config" , "changed" , spec -> spec .path ("shared.json" )),
666+ text ("original" , "changed" )
667+ );
668+ }
669+
488670 @ Test
489671 void deeperCyclicReferencesDetectedAsCycle () {
490672 // Test that deeper cyclic references (A -> B -> C -> A) are detected as a cycle
0 commit comments