@@ -1063,12 +1063,19 @@ describe("link dialogs: a workspace that already has this project's name", () =>
10631063
10641064describe ( "/integrations" , ( ) => {
10651065 // The command opens the Status view directly, or says why it has nothing to
1066- // show. The link and Status dialogs are rendered and read; the install offer
1067- // is not (it needs the TUI's clipboard), so that case counts what reached it.
1066+ // show. The stand-in dialog stack closes the dialog it replaces, like the
1067+ // real one, and renders the first `render` dialogs; the install offer is not
1068+ // rendered (it needs the TUI's clipboard), so those cases count replacements.
10681069 const binding = { datamateId : 42 , datamateName : "analytics" }
1069- type Select = { title : string ; options : { title : string ; value : unknown ; description ?: string } [ ] ; current ?: unknown }
1070- function harness ( render = true ) {
1071- const h = { selects : [ ] as Select [ ] , replaced : 0 , toasts : [ ] as string [ ] }
1070+ type Select = { title : string ; options : { title : string ; value : unknown ; description ?: string } [ ] ; current ?: unknown ; onSelect : ( o : { value : unknown } ) => void }
1071+ function harness ( render = Number . POSITIVE_INFINITY ) {
1072+ const h = { selects : [ ] as Select [ ] , replaced : 0 , cleared : 0 , toasts : [ ] as string [ ] }
1073+ let onClose : ( ( ) => void ) | undefined
1074+ const close = ( ) => {
1075+ const previous = onClose
1076+ onClose = undefined
1077+ previous ?.( )
1078+ }
10721079 const tui = {
10731080 state : { path : { directory : os . tmpdir ( ) } } ,
10741081 kv : { ...makeKv ( ) , ready : true } ,
@@ -1081,11 +1088,16 @@ describe("/integrations", () => {
10811088 h . toasts . push ( t . message )
10821089 } ,
10831090 dialog : {
1084- replace : ( factory : ( ) => unknown ) => {
1091+ replace : ( factory : ( ) => unknown , closed ?: ( ) => void ) => {
1092+ close ( )
1093+ onClose = closed
10851094 h . replaced += 1
1086- if ( render ) createRoot ( ( ) => factory ( ) )
1095+ if ( h . replaced <= render ) createRoot ( ( ) => factory ( ) )
1096+ } ,
1097+ clear : ( ) => {
1098+ close ( )
1099+ h . cleared += 1
10871100 } ,
1088- clear : ( ) => { } ,
10891101 } ,
10901102 } ,
10911103 } as any
@@ -1122,9 +1134,31 @@ describe("/integrations", () => {
11221134 linked ( null )
11231135 const { tui, h } = harness ( )
11241136 await runIntegrations ( tui , os . tmpdir ( ) )
1125- expect ( h . selects ) . toHaveLength ( 1 )
1126- expect ( h . selects [ 0 ] ! . options . map ( ( o ) => o . value ) ) . toEqual ( [ "link" , "done" ] )
1127- expect ( h . selects [ 0 ] ! . current ) . toBe ( "link" )
1137+ expect ( h . selects . map ( ( s ) => s . title ) ) . toEqual ( [ "Integrations" , "Integrations come from a linked workspace" ] )
1138+ expect ( h . selects [ 1 ] ! . options . map ( ( o ) => o . value ) ) . toEqual ( [ "link" , "done" ] )
1139+ expect ( h . selects [ 1 ] ! . current ) . toBe ( "link" )
1140+ } )
1141+
1142+ test ( "Link closes the dialog before the picker starts, so a second Enter cannot start another" , async ( ) => {
1143+ linked ( null )
1144+ spies . push ( spyOn ( WorkspaceApi , "getBindingForProject" ) . mockResolvedValue ( null as any ) )
1145+ const { tui, h } = harness ( 2 )
1146+ await runIntegrations ( tui , os . tmpdir ( ) )
1147+ h . selects [ 1 ] ! . onSelect ( { value : "link" } )
1148+ expect ( h . cleared ) . toBe ( 1 )
1149+ } )
1150+
1151+ test ( "a dialog opened while the link is read is left alone" , async ( ) => {
1152+ const { tui, h } = harness ( )
1153+ spies . push (
1154+ spyOn ( Manage , "status" ) . mockImplementation ( async ( ) => {
1155+ tui . ui . dialog . replace ( ( ) => null ) // the user opens something else meanwhile
1156+ return { binding : null } as any
1157+ } ) ,
1158+ )
1159+ await runIntegrations ( tui , os . tmpdir ( ) )
1160+ expect ( h . replaced ) . toBe ( 2 )
1161+ expect ( h . selects . map ( ( s ) => s . title ) ) . toEqual ( [ "Integrations" ] )
11281162 } )
11291163
11301164 test . each ( [
@@ -1134,10 +1168,10 @@ describe("/integrations", () => {
11341168 linked ( binding )
11351169 engine ( version )
11361170 const read = statusRead ( )
1137- const { tui, h } = harness ( false )
1171+ const { tui, h } = harness ( 1 )
11381172 recordEngineSkip ( tui , "42" , { tenant : "acme" , apiUrl : "https://api.acme.example.com" } , Date . now ( ) )
11391173 await runIntegrations ( tui , os . tmpdir ( ) )
1140- expect ( h . replaced ) . toBe ( 1 )
1174+ expect ( h . replaced ) . toBe ( 2 )
11411175 expect ( engineOfferInternals . visible ) . toBe ( true )
11421176 expect ( read ) . not . toHaveBeenCalled ( )
11431177 } )
@@ -1146,37 +1180,58 @@ describe("/integrations", () => {
11461180 linked ( binding )
11471181 engine ( null )
11481182 statusRead ( )
1149- const { tui, h } = harness ( false )
1183+ const { tui, h } = harness ( 2 )
11501184 let ready = false
11511185 Object . defineProperty ( tui . kv , "ready" , { get : ( ) => ready } )
11521186 recordEngineSkip ( tui , "42" , { tenant : "acme" , apiUrl : "https://api.acme.example.com" } , Date . now ( ) )
1153- // The turn's raise holds the slot while the store hydrates; the request finds it taken.
1187+ // The turn's raise holds the slot while the store hydrates; the request finds it taken and
1188+ // shows Status meanwhile.
11541189 const automatic = showEngineInstallOffer ( tui )
11551190 await runIntegrations ( tui , os . tmpdir ( ) )
1156- expect ( h . replaced ) . toBe ( 0 )
1191+ expect ( h . selects . map ( ( s ) => s . title ) ) . toEqual ( [ "Integrations" , "Workspace status" ] )
11571192 ready = true
11581193 await automatic
1159- expect ( h . replaced ) . toBe ( 1 )
1194+ expect ( h . replaced ) . toBe ( 3 )
1195+ expect ( engineOfferInternals . visible ) . toBe ( true )
11601196 } )
11611197
1162- test ( "an install still running is reported, not offered again " , async ( ) => {
1198+ test ( "an install still running is reported, and the Status view shown, not a second offer " , async ( ) => {
11631199 linked ( binding )
11641200 engine ( null )
1201+ statusRead ( )
11651202 engineOfferInternals . set ( { inFlight : true } )
1166- const { tui, h } = harness ( false )
1203+ const { tui, h } = harness ( )
11671204 await runIntegrations ( tui , os . tmpdir ( ) )
1168- expect ( h . replaced ) . toBe ( 0 )
11691205 expect ( h . toasts . join ( " " ) ) . toContain ( "still installing" )
1206+ expect ( h . selects . map ( ( s ) => s . title ) ) . toEqual ( [ "Integrations" , "Workspace status" ] )
1207+ } )
1208+
1209+ test ( "an engine that turns usable before the offer opens gets the Status view, not nothing" , async ( ) => {
1210+ linked ( binding )
1211+ engine ( null )
1212+ statusRead ( )
1213+ // The first check finds no engine; by the offer's own check, another process has installed it.
1214+ let checks = 0
1215+ syncInternals . which = ( ) => ( ++ checks === 1 ? null : "/usr/local/bin/datamate" )
1216+ syncInternals . versionOf = async ( ) => "0.7.3"
1217+ const { tui, h } = harness ( )
1218+ await runIntegrations ( tui , os . tmpdir ( ) )
1219+ expect ( h . selects . map ( ( s ) => s . title ) ) . toEqual ( [ "Integrations" , "Workspace status" ] )
11701220 } )
11711221
11721222 test ( "a relink during the engine check shows the new link's attach, not the old one's" , async ( ) => {
1173- // The first read sees workspace 42; by the time the engine check is done the project is linked to 43.
1223+ // The project is relinked to workspace 43 while the version probe runs.
1224+ let relinked = false
11741225 spies . push (
1175- spyOn ( Manage , "status" )
1176- . mockResolvedValueOnce ( { binding } as any )
1177- . mockResolvedValue ( { binding : { datamateId : 43 , datamateName : "marketing" } } as any ) ,
1226+ spyOn ( Manage , "status" ) . mockImplementation (
1227+ async ( ) => ( { binding : relinked ? { datamateId : 43 , datamateName : "marketing" } : binding } ) as any ,
1228+ ) ,
11781229 )
11791230 engine ( "0.7.3" )
1231+ syncInternals . versionOf = async ( ) => {
1232+ relinked = true
1233+ return "0.7.3"
1234+ }
11801235 const read = statusRead ( )
11811236 const { tui } = harness ( )
11821237 await runIntegrations ( tui , os . tmpdir ( ) )
0 commit comments