@@ -59,6 +59,13 @@ func createTestWorkflow(name string, transformations []types.Transformation) typ
5959 }
6060}
6161
62+ // createTestWorkflowWithDeprecation creates a test workflow with deprecation tracking enabled
63+ func createTestWorkflowWithDeprecation (name string , transformations []types.Transformation ) types.Workflow {
64+ wf := createTestWorkflow (name , transformations )
65+ wf .DeprecationCheck = & types.DeprecationConfig {Enabled : true }
66+ return wf
67+ }
68+
6269func createMoveTransformation (from , to string ) types.Transformation {
6370 return types.Transformation {
6471 Move : & types.MoveTransform {From : from , To : to },
@@ -159,7 +166,7 @@ func TestWorkflowProcessor_MoveTransformation(t *testing.T) {
159166 test .TestConfig (),
160167 )
161168
162- workflow := createTestWorkflow ("test-workflow" , []types.Transformation {
169+ workflow := createTestWorkflowWithDeprecation ("test-workflow" , []types.Transformation {
163170 createMoveTransformation (tt .from , tt .to ),
164171 })
165172
@@ -229,7 +236,7 @@ func TestWorkflowProcessor_CopyTransformation(t *testing.T) {
229236 test .TestConfig (),
230237 )
231238
232- workflow := createTestWorkflow ("test-workflow" , []types.Transformation {
239+ workflow := createTestWorkflowWithDeprecation ("test-workflow" , []types.Transformation {
233240 createCopyTransformation (tt .from , tt .to ),
234241 })
235242
@@ -304,7 +311,7 @@ func TestWorkflowProcessor_GlobTransformation(t *testing.T) {
304311 test .TestConfig (),
305312 )
306313
307- workflow := createTestWorkflow ("test-workflow" , []types.Transformation {
314+ workflow := createTestWorkflowWithDeprecation ("test-workflow" , []types.Transformation {
308315 createGlobTransformation (tt .pattern , tt .transform ),
309316 })
310317
@@ -372,7 +379,7 @@ func TestWorkflowProcessor_RegexTransformation(t *testing.T) {
372379 test .TestConfig (),
373380 )
374381
375- workflow := createTestWorkflow ("test-workflow" , []types.Transformation {
382+ workflow := createTestWorkflowWithDeprecation ("test-workflow" , []types.Transformation {
376383 createRegexTransformation (tt .pattern , tt .transform ),
377384 })
378385
@@ -493,7 +500,8 @@ func TestWorkflowProcessor_ExcludePatterns(t *testing.T) {
493500 createMoveTransformation ("src" , "dest" ),
494501 createMoveTransformation ("vendor" , "vendor" ),
495502 },
496- Exclude : tt .exclude ,
503+ Exclude : tt .exclude ,
504+ DeprecationCheck : & types.DeprecationConfig {Enabled : true },
497505 }
498506
499507 changedFiles := []types.ChangedFile {
@@ -546,6 +554,7 @@ func TestWorkflowProcessor_MultipleTransformations(t *testing.T) {
546554 createMoveTransformation ("docs" , "documentation" ),
547555 createCopyTransformation ("README.md" , "docs/README.md" ),
548556 },
557+ DeprecationCheck : & types.DeprecationConfig {Enabled : true },
549558 }
550559
551560 changedFiles := []types.ChangedFile {
@@ -659,7 +668,8 @@ func TestWorkflowProcessor_InvalidExcludePattern(t *testing.T) {
659668 createMoveTransformation ("src" , "dest" ),
660669 },
661670 // Invalid glob pattern - should be handled gracefully
662- Exclude : []string {"[invalid" },
671+ Exclude : []string {"[invalid" },
672+ DeprecationCheck : & types.DeprecationConfig {Enabled : true },
663673 }
664674
665675 changedFiles := []types.ChangedFile {
@@ -704,7 +714,8 @@ func TestWorkflowProcessor_CustomDeprecationFile(t *testing.T) {
704714 createMoveTransformation ("src" , "dest" ),
705715 },
706716 DeprecationCheck : & types.DeprecationConfig {
707- File : "custom_deprecation.json" ,
717+ Enabled : true ,
718+ File : "custom_deprecation.json" ,
708719 },
709720 }
710721
@@ -720,6 +731,8 @@ func TestWorkflowProcessor_CustomDeprecationFile(t *testing.T) {
720731 assert .True (t , exists , "expected custom deprecation file to be used" )
721732 require .Len (t , entries , 1 , "expected one entry in custom deprecation file" )
722733 assert .Equal (t , "dest/main.go" , entries [0 ].FileName )
734+ assert .Equal (t , "src/main.go" , entries [0 ].SourcePath , "expected source path to be recorded" )
735+ assert .Equal (t , 1 , entries [0 ].PRNumber , "expected PR number to be recorded" )
723736}
724737
725738// ============================================================================
@@ -769,6 +782,8 @@ func TestWorkflowProcessor_FileStatusHandling(t *testing.T) {
769782 workflow := createTestWorkflow ("test-workflow" , []types.Transformation {
770783 createMoveTransformation ("src" , "dest" ),
771784 })
785+ // Enable deprecation tracking for this test
786+ workflow .DeprecationCheck = & types.DeprecationConfig {Enabled : true }
772787
773788 changedFiles := []types.ChangedFile {
774789 {Path : "src/main.go" , Status : tt .status },
@@ -790,6 +805,45 @@ func TestWorkflowProcessor_FileStatusHandling(t *testing.T) {
790805 }
791806}
792807
808+ func TestWorkflowProcessor_DeprecationDisabledByDefault (t * testing.T ) {
809+ // Test that deprecation tracking does NOT happen when DeprecationCheck.Enabled is false/unset
810+ fileStateService := services .NewFileStateService ()
811+ processor := services .NewWorkflowProcessor (
812+ services .NewPatternMatcher (),
813+ services .NewPathTransformer (),
814+ fileStateService ,
815+ nil ,
816+ & mockMessageTemplater {},
817+ test .TestConfig (),
818+ )
819+
820+ // Create workflow WITHOUT deprecation enabled
821+ workflow := createTestWorkflow ("test-workflow" , []types.Transformation {
822+ createMoveTransformation ("src" , "dest" ),
823+ })
824+ // DeprecationCheck is nil - should not track deprecations
825+
826+ changedFiles := []types.ChangedFile {
827+ {Path : "src/main.go" , Status : "removed" },
828+ }
829+
830+ err := processor .ProcessWorkflow (context .Background (), workflow , changedFiles , 1 , "abc123" )
831+ require .NoError (t , err )
832+
833+ deprecated := fileStateService .GetFilesToDeprecate ()
834+ assert .Empty (t , deprecated , "expected NO deprecation tracking when DeprecationCheck is nil" )
835+
836+ // Also test when DeprecationCheck exists but Enabled is false
837+ workflow .DeprecationCheck = & types.DeprecationConfig {Enabled : false , File : "test.json" }
838+ fileStateService .ClearFilesToDeprecate ()
839+
840+ err = processor .ProcessWorkflow (context .Background (), workflow , changedFiles , 1 , "abc123" )
841+ require .NoError (t , err )
842+
843+ deprecated = fileStateService .GetFilesToDeprecate ()
844+ assert .Empty (t , deprecated , "expected NO deprecation tracking when DeprecationCheck.Enabled is false" )
845+ }
846+
793847// ============================================================================
794848// Tests for Path Transformation Edge Cases
795849// ============================================================================
@@ -845,7 +899,7 @@ func TestWorkflowProcessor_PathTransformationEdgeCases(t *testing.T) {
845899 test .TestConfig (),
846900 )
847901
848- workflow := createTestWorkflow ("test-workflow" , []types.Transformation {tt .transform })
902+ workflow := createTestWorkflowWithDeprecation ("test-workflow" , []types.Transformation {tt .transform })
849903
850904 changedFiles := []types.ChangedFile {
851905 {Path : tt .sourcePath , Status : "removed" },
@@ -863,3 +917,59 @@ func TestWorkflowProcessor_PathTransformationEdgeCases(t *testing.T) {
863917 })
864918 }
865919}
920+
921+ // ============================================================================
922+ // Tests for Auto-Merge Batching Behavior
923+ // ============================================================================
924+
925+ // TestFileStateService_AutoMergeBatching_AllTrue tests that when all entries
926+ // in a batch have auto_merge: true, the batch retains auto_merge: true.
927+ func TestFileStateService_AutoMergeBatching_AllTrue (t * testing.T ) {
928+ fileStateService := services .NewFileStateService ()
929+
930+ key := types.UploadKey {
931+ RepoName : "test-org/dest-repo" ,
932+ BranchPath : "main" ,
933+ CommitStrategy : "pull_request" ,
934+ }
935+
936+ // First upload with auto_merge: true
937+ fileStateService .AddFileToUpload (key , types.UploadFileContent {
938+ TargetBranch : "main" ,
939+ CommitStrategy : "pull_request" ,
940+ AutoMergePR : true ,
941+ })
942+
943+ uploads := fileStateService .GetFilesToUpload ()
944+ require .Len (t , uploads , 1 , "expected one upload entry" )
945+ assert .True (t , uploads [key ].AutoMergePR , "expected auto_merge to be true" )
946+ }
947+
948+ // TestFileStateService_AutoMergeBatching_AllFalse tests that when all entries
949+ // in a batch have auto_merge: false, the batch has auto_merge: false.
950+ func TestFileStateService_AutoMergeBatching_AllFalse (t * testing.T ) {
951+ fileStateService := services .NewFileStateService ()
952+
953+ key := types.UploadKey {
954+ RepoName : "test-org/dest-repo" ,
955+ BranchPath : "main" ,
956+ CommitStrategy : "pull_request" ,
957+ }
958+
959+ // Upload with auto_merge: false
960+ fileStateService .AddFileToUpload (key , types.UploadFileContent {
961+ TargetBranch : "main" ,
962+ CommitStrategy : "pull_request" ,
963+ AutoMergePR : false ,
964+ })
965+
966+ uploads := fileStateService .GetFilesToUpload ()
967+ require .Len (t , uploads , 1 , "expected one upload entry" )
968+ assert .False (t , uploads [key ].AutoMergePR , "expected auto_merge to be false" )
969+ }
970+
971+ // Note: The actual conflict detection and AND logic happens in workflow_processor.go's
972+ // queueUpload function when adding files to an existing batch. Testing this requires
973+ // either mocking GitHub API calls or testing at the integration level.
974+ // The conflict warning is logged when workflows with different auto_merge settings
975+ // target the same repo, and AND logic is applied (any false results in false).
0 commit comments