11import type { Mock } from "vitest"
22import * as vscode from "vscode"
33import { ClineProvider } from "../../core/webview/ClineProvider"
4+ import * as RooImport from "../../services/roo-import/RooImport"
45
5- import { getVisibleProviderOrLog } from "../registerCommands"
6+ import { getVisibleProviderOrLog , handleImportRooHandoff } from "../registerCommands"
67
78vi . mock ( "execa" , ( ) => ( {
89 execa : vi . fn ( ) ,
@@ -29,6 +30,11 @@ vi.mock("vscode", () => ({
2930
3031vi . mock ( "../../core/webview/ClineProvider" )
3132
33+ vi . mock ( "../../services/roo-import/RooImport" , ( ) => ( {
34+ importRooHandoffFromPath : vi . fn ( ) ,
35+ promptAndImportRooHandoff : vi . fn ( ) ,
36+ } ) )
37+
3238describe ( "getVisibleProviderOrLog" , ( ) => {
3339 let mockOutputChannel : vscode . OutputChannel
3440
@@ -65,3 +71,68 @@ describe("getVisibleProviderOrLog", () => {
6571 expect ( mockOutputChannel . appendLine ) . toHaveBeenCalledWith ( "Cannot find any visible Roo Code instances." )
6672 } )
6773} )
74+
75+ describe ( "handleImportRooHandoff" , ( ) => {
76+ let mockOutputChannel : vscode . OutputChannel
77+ let mockContext : vscode . ExtensionContext
78+ let mockProvider : Partial < ClineProvider >
79+
80+ beforeEach ( ( ) => {
81+ mockOutputChannel = { appendLine : vi . fn ( ) } as any
82+ mockContext = { globalStorageUri : { fsPath : "/tmp/zoo" } } as any
83+ mockProvider = {
84+ providerSettingsManager : { } as any ,
85+ contextProxy : { } as any ,
86+ customModesManager : { } as any ,
87+ postStateToWebview : vi . fn ( ) . mockResolvedValue ( undefined ) ,
88+ }
89+ vi . clearAllMocks ( )
90+ ; ( ClineProvider . getInstance as Mock ) . mockResolvedValue ( mockProvider )
91+ } )
92+
93+ it ( "returns undefined when no provider is available" , async ( ) => {
94+ ; ( ClineProvider . getInstance as Mock ) . mockResolvedValue ( undefined )
95+
96+ const result = await handleImportRooHandoff ( undefined , mockContext , mockOutputChannel )
97+
98+ expect ( result ) . toBeUndefined ( )
99+ } )
100+
101+ it ( "calls importRooHandoffFromPath when a handoff path is given" , async ( ) => {
102+ const mockResult = { success : true , tasksCopied : 2 }
103+ vi . mocked ( RooImport . importRooHandoffFromPath ) . mockResolvedValue ( mockResult )
104+
105+ const result = await handleImportRooHandoff ( "/path/to/handoff.json" , mockContext , mockOutputChannel )
106+
107+ expect ( RooImport . importRooHandoffFromPath ) . toHaveBeenCalledWith ( "/path/to/handoff.json" , expect . any ( Object ) )
108+ expect ( mockProvider . postStateToWebview ) . toHaveBeenCalled ( )
109+ expect ( result ) . toBe ( mockResult )
110+ } )
111+
112+ it ( "calls promptAndImportRooHandoff when no path is given" , async ( ) => {
113+ const mockResult = { success : true , tasksCopied : 0 }
114+ vi . mocked ( RooImport . promptAndImportRooHandoff ) . mockResolvedValue ( mockResult )
115+
116+ const result = await handleImportRooHandoff ( undefined , mockContext , mockOutputChannel )
117+
118+ expect ( RooImport . promptAndImportRooHandoff ) . toHaveBeenCalled ( )
119+ expect ( result ) . toBe ( mockResult )
120+ } )
121+
122+ it ( "does not call postStateToWebview when import returns undefined" , async ( ) => {
123+ vi . mocked ( RooImport . promptAndImportRooHandoff ) . mockResolvedValue ( undefined )
124+
125+ await handleImportRooHandoff ( undefined , mockContext , mockOutputChannel )
126+
127+ expect ( mockProvider . postStateToWebview ) . not . toHaveBeenCalled ( )
128+ } )
129+
130+ it ( "logs and returns undefined when the import throws" , async ( ) => {
131+ vi . mocked ( RooImport . importRooHandoffFromPath ) . mockRejectedValue ( new Error ( "disk full" ) )
132+
133+ const result = await handleImportRooHandoff ( "/path/to/handoff.json" , mockContext , mockOutputChannel )
134+
135+ expect ( result ) . toBeUndefined ( )
136+ expect ( mockOutputChannel . appendLine ) . toHaveBeenCalledWith ( "[Roo Import] Failed: disk full" )
137+ } )
138+ } )
0 commit comments