@@ -78,23 +78,30 @@ import { rollbackFork } from '@/ee/workspace-forking/lib/promote/rollback'
7878
7979const EDGE = { childWorkspaceId : 'child-ws' , parentWorkspaceId : 'parent-ws' }
8080
81- /** A fake transaction whose existence query returns the given undeploy ids. */
82- function makeTx ( existingUndeployIds : string [ ] = [ ] ) {
81+ /** A fake transaction whose existence/update queries return the supplied workflow ids. */
82+ function makeTx ( existingUndeployIds : string [ ] = [ ] , unarchivedWorkflowIds : string [ ] = [ ] ) {
8383 return {
8484 select : vi . fn ( ( ) => ( {
8585 from : vi . fn ( ( ) => ( {
8686 where : vi . fn ( ( ) => Promise . resolve ( existingUndeployIds . map ( ( id ) => ( { id } ) ) ) ) ,
8787 } ) ) ,
8888 } ) ) ,
8989 update : vi . fn ( ( ) => ( {
90- set : vi . fn ( ( ) => ( { where : vi . fn ( ( ) => Promise . resolve ( undefined ) ) } ) ) ,
90+ set : vi . fn ( ( ) => ( {
91+ where : vi . fn ( ( ) =>
92+ Object . assign ( Promise . resolve ( undefined ) , {
93+ returning : vi . fn ( ) . mockResolvedValue ( unarchivedWorkflowIds . map ( ( id ) => ( { id } ) ) ) ,
94+ } )
95+ ) ,
96+ } ) ) ,
9197 } ) ) ,
9298 }
9399}
94100
95- function setTx ( existingUndeployIds : string [ ] = [ ] ) {
101+ function setTx ( existingUndeployIds : string [ ] = [ ] , unarchivedWorkflowIds : string [ ] = [ ] ) {
96102 vi . mocked ( db . transaction ) . mockImplementation (
97- async ( cb : ( tx : unknown ) => unknown ) => cb ( makeTx ( existingUndeployIds ) ) as never
103+ async ( cb : ( tx : unknown ) => unknown ) =>
104+ cb ( makeTx ( existingUndeployIds , unarchivedWorkflowIds ) ) as never
98105 )
99106}
100107
@@ -165,6 +172,7 @@ describe('rollbackFork', () => {
165172 } )
166173
167174 it ( 'un-archives and reactivates an archived orphan (prior version restored)' , async ( ) => {
175+ setTx ( [ ] , [ 'wf-x' ] )
168176 const run = makeRun ( {
169177 snapshot : { updated : [ ] , created : [ ] , archived : [ { workflowId : 'wf-x' , priorVersion : 2 } ] } ,
170178 } )
@@ -187,6 +195,30 @@ describe('rollbackFork', () => {
187195 expect ( mockNotify ) . toHaveBeenCalledWith ( 'wf-x' )
188196 } )
189197
198+ it ( 'refreshes workspace lists when an archived orphan had no prior deployment' , async ( ) => {
199+ setTx ( [ ] , [ 'wf-x' ] )
200+ mockGetLatestRun . mockResolvedValue (
201+ makeRun ( {
202+ snapshot : {
203+ updated : [ ] ,
204+ created : [ ] ,
205+ archived : [ { workflowId : 'wf-x' , priorVersion : null } ] ,
206+ } ,
207+ } )
208+ )
209+
210+ const result = await rollbackFork ( {
211+ targetWorkspaceId : 'target-ws' ,
212+ otherWorkspaceId : 'other-ws' ,
213+ userId : 'user-1' ,
214+ } )
215+
216+ expect ( result . unarchived ) . toBe ( 1 )
217+ expect ( mockReactivate ) . not . toHaveBeenCalled ( )
218+ expect ( mockNotifyWorkspace ) . toHaveBeenCalledOnce ( )
219+ expect ( mockNotifyWorkspace ) . toHaveBeenCalledWith ( 'target-ws' )
220+ } )
221+
190222 it ( 'aborts with 409 and writes nothing when a newer sync supersedes it mid-flight' , async ( ) => {
191223 const run = makeRun ( {
192224 snapshot : { updated : [ { workflowId : 'wf-a' , priorVersion : 3 } ] , created : [ ] , archived : [ ] } ,
0 commit comments