11import { describe , expect , it , vi } from "vitest" ;
2- import { createCuaComputerCommands } from "./commands.js" ;
2+ import { createCuaComputerProvider } from "./commands.js" ;
33import {
44 ClickButton ,
55 ScrollDirection ,
@@ -68,25 +68,25 @@ function driver() {
6868 } ;
6969}
7070
71- function commands ( session : CuaDriverSession ) {
72- return createCuaComputerCommands ( {
71+ async function execution ( session : CuaDriverSession ) {
72+ return await createCuaComputerProvider ( {
7373 platform : "linux" ,
7474 driver : session ,
7575 imageProcessor : {
7676 encode : vi . fn ( async ( ) => ( { data : Buffer . from ( "jpeg" ) , width : 100 , height : 50 } ) ) ,
7777 } ,
78- } ) ;
78+ } ) . openExecution ( { } ) ;
7979}
8080
81- describe ( "cua-computer direct SDK commands " , ( ) => {
81+ describe ( "cua-computer provider " , ( ) => {
8282 it ( "uses one typed session for snapshot and frame-authorized click" , async ( ) => {
8383 const { session, getDesktopState, getScreenSize, click } = driver ( ) ;
84- const [ snapshot , act ] = commands ( session ) ;
85- const screen = JSON . parse ( await snapshot ! . handle ( '{"format":"png","maxWidth":100}' ) ) as {
84+ const computer = await execution ( session ) ;
85+ const screen = JSON . parse ( await computer . snapshot ( '{"format":"png","maxWidth":100}' ) ) as {
8686 displayFrameId : string ;
8787 width : number ;
8888 } ;
89- await act ! . handle (
89+ await computer . act (
9090 JSON . stringify ( {
9191 action : "left_click" ,
9292 displayFrameId : screen . displayFrameId ,
@@ -110,24 +110,24 @@ describe("cua-computer direct SDK commands", () => {
110110
111111 it ( "maps scroll and key through typed SDK enums" , async ( ) => {
112112 const { session, typeText, pressKey } = driver ( ) ;
113- const [ , act ] = commands ( session ) ;
114- await act ! . handle ( '{"action":"type","text":"hello"}' ) ;
115- await act ! . handle ( '{"action":"key","keys":"ctrl+enter"}' ) ;
113+ const computer = await execution ( session ) ;
114+ await computer . act ( '{"action":"type","text":"hello"}' ) ;
115+ await computer . act ( '{"action":"key","keys":"ctrl+enter"}' ) ;
116116 expect ( typeText ) . toHaveBeenCalledWith ( "hello" , undefined ) ;
117117 expect ( pressKey ) . toHaveBeenCalledWith ( { key : "enter" , modifiers : [ "ctrl" ] } , undefined ) ;
118118 expect ( ScrollDirection . Down ) . toBeTypeOf ( "number" ) ;
119119 } ) ;
120120
121121 it ( "maps all remaining projected desktop actions through direct SDK methods" , async ( ) => {
122122 const { session, scroll, moveCursor, drag } = driver ( ) ;
123- const [ snapshot , act ] = commands ( session ) ;
124- const screen = JSON . parse ( await snapshot ! . handle ( '{"format":"png","maxWidth":100}' ) ) as {
123+ const computer = await execution ( session ) ;
124+ const screen = JSON . parse ( await computer . snapshot ( '{"format":"png","maxWidth":100}' ) ) as {
125125 displayFrameId : string ;
126126 width : number ;
127127 } ;
128128 const frame = { displayFrameId : screen . displayFrameId , refWidth : screen . width } ;
129129
130- await act ! . handle (
130+ await computer . act (
131131 JSON . stringify ( {
132132 action : "scroll" ,
133133 ...frame ,
@@ -137,8 +137,8 @@ describe("cua-computer direct SDK commands", () => {
137137 scrollAmount : 4 ,
138138 } ) ,
139139 ) ;
140- await act ! . handle ( JSON . stringify ( { action : "mouse_move" , ...frame , x : 11 , y : 21 } ) ) ;
141- await act ! . handle (
140+ await computer . act ( JSON . stringify ( { action : "mouse_move" , ...frame , x : 11 , y : 21 } ) ) ;
141+ await computer . act (
142142 JSON . stringify ( {
143143 action : "left_click_drag" ,
144144 ...frame ,
@@ -169,13 +169,13 @@ describe("cua-computer direct SDK commands", () => {
169169 errorCode : "desktop_unavailable" ,
170170 text : "desktop input is unavailable" ,
171171 } ) ;
172- const [ snapshot , act ] = commands ( session ) ;
173- const screen = JSON . parse ( await snapshot ! . handle ( '{"format":"png","maxWidth":100}' ) ) as {
172+ const computer = await execution ( session ) ;
173+ const screen = JSON . parse ( await computer . snapshot ( '{"format":"png","maxWidth":100}' ) ) as {
174174 displayFrameId : string ;
175175 width : number ;
176176 } ;
177177 await expect (
178- act ! . handle (
178+ computer . act (
179179 JSON . stringify ( {
180180 action : "left_click" ,
181181 displayFrameId : screen . displayFrameId ,
@@ -189,14 +189,14 @@ describe("cua-computer direct SDK commands", () => {
189189
190190 it ( "rejects a mismatched reference width before desktop input" , async ( ) => {
191191 const { session, click } = driver ( ) ;
192- const [ snapshot , act ] = commands ( session ) ;
193- const screen = JSON . parse ( await snapshot ! . handle ( '{"format":"png","maxWidth":100}' ) ) as {
192+ const computer = await execution ( session ) ;
193+ const screen = JSON . parse ( await computer . snapshot ( '{"format":"png","maxWidth":100}' ) ) as {
194194 displayFrameId : string ;
195195 width : number ;
196196 } ;
197197
198198 await expect (
199- act ! . handle (
199+ computer . act (
200200 JSON . stringify ( {
201201 action : "left_click" ,
202202 displayFrameId : screen . displayFrameId ,
@@ -213,7 +213,7 @@ describe("cua-computer direct SDK commands", () => {
213213 const { session, dispose } = driver ( ) ;
214214 const createDriver = vi . fn ( ( ) => session ) ;
215215 const clearInterval = vi . fn ( ) ;
216- const [ snapshot ] = createCuaComputerCommands ( {
216+ const provider = createCuaComputerProvider ( {
217217 platform : "linux" ,
218218 createDriver,
219219 imageProcessor : {
@@ -224,10 +224,11 @@ describe("cua-computer direct SDK commands", () => {
224224 } ) ;
225225 expect ( createDriver ) . not . toHaveBeenCalled ( ) ;
226226
227- await snapshot ! . handle ( '{"format":"png","maxWidth":100}' ) ;
227+ const computer = await provider . openExecution ( { } ) ;
228+ await computer . snapshot ( '{"format":"png","maxWidth":100}' ) ;
228229 expect ( createDriver ) . toHaveBeenCalledOnce ( ) ;
229230
230- const stop = snapshot ! . watchAvailability ?.( { config : { } as never , env : { } } , vi . fn ( ) ) ;
231+ const stop = provider . watchAvailability ?.( { config : { } as never , env : { } } , vi . fn ( ) ) ;
231232 stop ?.( ) ;
232233 await Promise . resolve ( ) ;
233234 expect ( clearInterval ) . toHaveBeenCalledOnce ( ) ;
@@ -236,12 +237,9 @@ describe("cua-computer direct SDK commands", () => {
236237
237238 it ( "passes node invocation cancellation to the direct SDK" , async ( ) => {
238239 const { session, getDesktopState } = driver ( ) ;
239- const [ snapshot ] = commands ( session ) ;
240+ const computer = await execution ( session ) ;
240241 const signal = AbortSignal . abort ( ) ;
241- await snapshot ! . handle ( '{"format":"png","maxWidth":100}' , undefined , {
242- sendNodeEvent : vi . fn ( ) ,
243- signal,
244- } ) ;
242+ await computer . snapshot ( '{"format":"png","maxWidth":100}' , signal ) ;
245243 expect ( getDesktopState ) . toHaveBeenCalledWith ( signal ) ;
246244 } ) ;
247245} ) ;
0 commit comments