@@ -381,6 +381,16 @@ class Project extends Specification {
381381 this . #currentStageWorkspace = null ;
382382 }
383383
384+ _resetStages ( ) {
385+ this . #stages = [ ] ;
386+ this . #currentStage = null ;
387+ this . #currentStageName = "<source>" ;
388+ this . #currentStageReadIndex = - 1 ;
389+ this . #currentStageReaders = new Map ( ) ;
390+ this . #currentStageWorkspace = null ;
391+ this . #workspaceVersion = 0 ;
392+ }
393+
384394 #getReaderForStage( stage , style = "buildtime" , includeCache = true ) {
385395 const writers = stage . getAllWriters ( includeCache ) ;
386396 const readers = [ ] ;
@@ -406,23 +416,7 @@ class Project extends Specification {
406416 }
407417
408418 setStages ( stageIds , cacheReaders ) {
409- if ( this . #stages. length > 0 ) {
410- // Stages have already been set. Compare existing stages with new ones and throw on mismatch
411- for ( let i = 0 ; i < stageIds . length ; i ++ ) {
412- const stageId = stageIds [ i ] ;
413- if ( this . #stages[ i ] . getId ( ) !== stageId ) {
414- throw new Error (
415- `Unable to set stages for project ${ this . getName ( ) } : Stage mismatch at position ${ i } ` +
416- `(existing: ${ this . #stages[ i ] . getId ( ) } , new: ${ stageId } )` ) ;
417- }
418- }
419- if ( cacheReaders ?. length ) {
420- throw new Error (
421- `Unable to set stages for project ${ this . getName ( ) } : Cache readers can only be set ` +
422- `when stages are created for the first time` ) ;
423- }
424- return ; // Stages already set and matching, no further processing needed
425- }
419+ this . _resetStages ( ) ; // Reset current stages and metadata
426420 for ( let i = 0 ; i < stageIds . length ; i ++ ) {
427421 const stageId = stageIds [ i ] ;
428422 const newStage = new Stage ( stageId , cacheReaders ?. [ i ] ) ;
0 commit comments