@@ -767,13 +767,16 @@ public async Task ImportsSplitSourceFiles(
767767 }
768768
769769 // Create split source files simulating a previous patcher's output
770- // Note: When Mutagen splits a mod, records keep FormKeys pointing to the merged mod key
771- var sourceModKey = ModKey . FromFileName ( "PreviousPatch .esp" ) ;
770+ // In real usage, source and output share the same mod name but live in different directories
771+ var patchModKey = ModKey . FromFileName ( "Patch .esp" ) ;
772772 var expectedFormLists = new List < ( string EditorID , List < FormKey > Items ) > ( ) ;
773773
774+ // Create a source directory (simulating a previous run's working directory)
775+ var sourceDir = Path . Combine ( dataFolder , "Previous" ) ;
776+ fileSystem . Directory . CreateDirectory ( sourceDir ) ;
777+
774778 // Create first split file with first 128 masters
775- // Use merged mod key for the mod, then write with NoModKeySync to preserve FormKeys
776- var splitMod1 = new SkyrimMod ( sourceModKey , SkyrimRelease . SkyrimSE ) ;
779+ var splitMod1 = new SkyrimMod ( patchModKey , SkyrimRelease . SkyrimSE ) ;
777780 var formList1 = splitMod1 . FormLists . AddNew ( ) ;
778781 formList1 . EditorID = "NpcFormList_0" ;
779782 var items1 = new List < FormKey > ( ) ;
@@ -785,7 +788,7 @@ public async Task ImportsSplitSourceFiles(
785788 expectedFormLists . Add ( ( formList1 . EditorID , items1 ) ) ;
786789
787790 // First split file uses the base name (no suffix)
788- var splitFile1Path = Path . Combine ( dataFolder , sourceModKey . FileName ) ;
791+ var splitFile1Path = Path . Combine ( sourceDir , patchModKey . FileName ) ;
789792 splitMod1 . BeginWrite
790793 . ToPath ( splitFile1Path )
791794 . WithNoLoadOrder ( )
@@ -794,9 +797,9 @@ public async Task ImportsSplitSourceFiles(
794797 . Write ( ) ;
795798
796799 // Create second split file with remaining masters
797- var splitMod2 = new SkyrimMod ( sourceModKey , SkyrimRelease . SkyrimSE ) ;
800+ var splitMod2 = new SkyrimMod ( patchModKey , SkyrimRelease . SkyrimSE ) ;
798801 // Use RecordWith to create a record with a specific FormKey to avoid conflicts
799- var formList2 = new Mutagen . Bethesda . Skyrim . FormList ( new FormKey ( sourceModKey , 0x900 ) , SkyrimRelease . SkyrimSE ) ;
802+ var formList2 = new Mutagen . Bethesda . Skyrim . FormList ( new FormKey ( patchModKey , 0x900 ) , SkyrimRelease . SkyrimSE ) ;
800803 formList2 . EditorID = "NpcFormList_1" ;
801804 splitMod2 . FormLists . RecordCache . Set ( formList2 ) ;
802805 var items2 = new List < FormKey > ( ) ;
@@ -808,7 +811,7 @@ public async Task ImportsSplitSourceFiles(
808811 expectedFormLists . Add ( ( formList2 . EditorID , items2 ) ) ;
809812
810813 // Second split file uses _2 suffix
811- var splitFile2Path = Path . Combine ( dataFolder , $ "{ sourceModKey . Name } _2{ Path . GetExtension ( sourceModKey . FileName ) } ") ;
814+ var splitFile2Path = Path . Combine ( sourceDir , $ "{ patchModKey . Name } _2{ Path . GetExtension ( patchModKey . FileName ) } ") ;
812815 splitMod2 . BeginWrite
813816 . ToPath ( splitFile2Path )
814817 . WithNoLoadOrder ( )
@@ -819,20 +822,19 @@ public async Task ImportsSplitSourceFiles(
819822 // Create plugins.txt with all masters AND the split files
820823 var pluginPath = Path . Combine ( dataFolder , "Plugins.txt" ) ;
821824 var pluginLines = masterModKeys . Select ( k => $ "*{ k . FileName } ") . ToList ( ) ;
822- pluginLines . Add ( $ "*{ sourceModKey . FileName } ") ;
823- pluginLines . Add ( $ "*{ sourceModKey . Name } _2{ Path . GetExtension ( sourceModKey . FileName ) } ") ;
825+ pluginLines . Add ( $ "*{ patchModKey . FileName } ") ;
826+ pluginLines . Add ( $ "*{ patchModKey . Name } _2{ Path . GetExtension ( patchModKey . FileName ) } ") ;
824827 fileSystem . File . WriteAllLines ( pluginPath , pluginLines ) ;
825828
826- // Setup run arguments - SourcePath points to base name that doesn't exist
827- var outputModKey = ModKey . FromFileName ( "Output.esp" ) ;
829+ // Setup run arguments - SourcePath is in a different directory than output
828830 var runArgs = new RunSynthesisMutagenPatcher
829831 {
830- ModKey = outputModKey . FileName ,
832+ ModKey = patchModKey . FileName ,
831833 DataFolderPath = dataFolder ,
832834 LoadOrderFilePath = pluginPath ,
833835 GameRelease = GameRelease . SkyrimSE ,
834- SourcePath = Path . Combine ( dataFolder , sourceModKey . FileName ) , // Base name (first split file)
835- OutputPath = Path . Combine ( outputPath , outputModKey . FileName ) ,
836+ SourcePath = splitFile1Path , // Source in Previous/ directory
837+ OutputPath = Path . Combine ( outputPath , patchModKey . FileName ) ,
836838 LoadOrderIncludesCreationClub = true ,
837839 SplitIfMaxMastersExceeded = true // Enable split file detection
838840 } ;
@@ -874,15 +876,15 @@ await SynthesisPipeline.Instance
874876 // Verify load order was modified correctly
875877 capturedLoadOrder . ShouldNotBeNull ( ) ;
876878
877- // The load order should contain the output mod key (patchMod) , not the split files
879+ // The load order should contain the patch mod key, not the split files
878880 var loadOrderKeys = capturedLoadOrder ! . ListedOrder . Select ( x => x . ModKey ) . ToList ( ) ;
879881
880- // Should contain the output mod key (the patchMod)
881- loadOrderKeys . ShouldContain ( outputModKey ,
882- $ "Load order should contain output ModKey { outputModKey } ") ;
882+ // Should contain the patch mod key
883+ loadOrderKeys . ShouldContain ( patchModKey ,
884+ $ "Load order should contain patch ModKey { patchModKey } ") ;
883885
884886 // Should NOT contain the split sibling file key
885- var splitKey2 = new ModKey ( $ "{ sourceModKey . Name } _2", sourceModKey . Type ) ;
887+ var splitKey2 = new ModKey ( $ "{ patchModKey . Name } _2", patchModKey . Type ) ;
886888 loadOrderKeys . ShouldNotContain ( splitKey2 ,
887889 $ "Load order should not contain split file { splitKey2 } ") ;
888890 }
0 commit comments