@@ -97,12 +97,165 @@ describe("onboard recommendations command", () => {
9797 matches : [ ] ,
9898 } ) ) ;
9999
100- acknowledgeOnboardRecommendationsCommand ( runtime , { acknowledge } ) ;
100+ acknowledgeOnboardRecommendationsCommand ( { } , runtime , { acknowledge } ) ;
101101
102102 expect ( acknowledge ) . toHaveBeenCalledOnce ( ) ;
103103 expect ( runtime . log ) . toHaveBeenCalledWith ( "Onboarding recommendations acknowledged." ) ;
104104 } ) ;
105105
106+ it ( "leaves failed bootstrap installs pending and consumes the other matches" , ( ) => {
107+ const runtime = makeRuntime ( ) ;
108+ const updatePending = vi . fn ( ( ) => ( {
109+ inventoryHash : "hash" ,
110+ offeredAt : 1 ,
111+ acceptedAt : null ,
112+ updatedAt : 2 ,
113+ matches : [ ] ,
114+ } ) ) ;
115+ const matches = [
116+ {
117+ appLabel : "Chat" ,
118+ candidateId : "chat-plugin" ,
119+ tier : "recommended" as const ,
120+ reason : "Connects conversations" ,
121+ candidate : {
122+ id : "chat-plugin" ,
123+ displayName : "Chat plugin" ,
124+ summary : "Chat" ,
125+ source : "official-channel" as const ,
126+ } ,
127+ } ,
128+ {
129+ appLabel : "Notes" ,
130+ candidateId : "@demo-owner/notes" ,
131+ tier : "optional" as const ,
132+ reason : "Connects notes" ,
133+ candidate : {
134+ id : "@demo-owner/notes" ,
135+ displayName : "Notes skill" ,
136+ summary : "Notes" ,
137+ source : "clawhub-skill" as const ,
138+ } ,
139+ } ,
140+ ] ;
141+
142+ acknowledgeOnboardRecommendationsCommand ( { retry : [ "@demo-owner/notes" ] } , runtime , {
143+ read : ( ) => ( {
144+ inventoryHash : "hash" ,
145+ offeredAt : 1 ,
146+ acceptedAt : null ,
147+ updatedAt : 1 ,
148+ matches,
149+ } ) ,
150+ updatePending,
151+ } ) ;
152+
153+ expect ( updatePending ) . toHaveBeenCalledWith ( {
154+ matches : [ matches [ 1 ] ] ,
155+ expected : {
156+ inventoryHash : "hash" ,
157+ offeredAt : 1 ,
158+ acceptedAt : null ,
159+ updatedAt : 1 ,
160+ matches,
161+ } ,
162+ } ) ;
163+ expect ( runtime . log ) . toHaveBeenCalledWith (
164+ "Onboarding recommendations updated; 1 left pending for retry." ,
165+ ) ;
166+ } ) ;
167+
168+ it ( "rejects unknown bootstrap retry ids without consuming the offer" , ( ) => {
169+ const runtime = makeRuntime ( ) ;
170+ const acknowledge = vi . fn ( ) ;
171+ const updatePending = vi . fn ( ) ;
172+
173+ acknowledgeOnboardRecommendationsCommand ( { retry : [ "missing-skill" ] } , runtime , {
174+ read : ( ) => ( {
175+ inventoryHash : "hash" ,
176+ offeredAt : 1 ,
177+ acceptedAt : null ,
178+ updatedAt : 1 ,
179+ matches : [ ] ,
180+ } ) ,
181+ acknowledge,
182+ updatePending,
183+ } ) ;
184+
185+ expect ( runtime . error ) . toHaveBeenCalledWith ( "Unknown pending recommendation id: missing-skill" ) ;
186+ expect ( runtime . exit ) . toHaveBeenCalledWith ( 1 ) ;
187+ expect ( acknowledge ) . not . toHaveBeenCalled ( ) ;
188+ expect ( updatePending ) . not . toHaveBeenCalled ( ) ;
189+ } ) ;
190+
191+ it ( "fails closed when the pending offer changes before retry persistence" , ( ) => {
192+ const runtime = makeRuntime ( ) ;
193+ const updatePending = vi . fn ( ( ) => null ) ;
194+ const match = {
195+ appLabel : "Notes" ,
196+ candidateId : "@demo-owner/notes" ,
197+ tier : "optional" as const ,
198+ reason : "Connects notes" ,
199+ candidate : {
200+ id : "@demo-owner/notes" ,
201+ displayName : "Notes skill" ,
202+ summary : "Notes" ,
203+ source : "clawhub-skill" as const ,
204+ } ,
205+ } ;
206+
207+ acknowledgeOnboardRecommendationsCommand ( { retry : [ match . candidateId ] } , runtime , {
208+ read : ( ) => ( {
209+ inventoryHash : "hash" ,
210+ offeredAt : 1 ,
211+ acceptedAt : null ,
212+ updatedAt : 1 ,
213+ matches : [ match ] ,
214+ } ) ,
215+ updatePending,
216+ } ) ;
217+
218+ expect ( runtime . error ) . toHaveBeenCalledWith (
219+ "Stored recommendations changed; read them again before recording retries." ,
220+ ) ;
221+ expect ( runtime . exit ) . toHaveBeenCalledWith ( 1 ) ;
222+ expect ( runtime . log ) . not . toHaveBeenCalled ( ) ;
223+ } ) ;
224+
225+ it ( "clears pending bootstrap offers with legacy bare ClawHub ids" , ( ) => {
226+ const runtime = makeRuntime ( ) ;
227+ const clearPending = vi . fn ( ( ) => true ) ;
228+
229+ onboardRecommendationsCommand ( { json : true } , runtime , {
230+ read : ( ) => ( {
231+ inventoryHash : "hash" ,
232+ offeredAt : 1 ,
233+ acceptedAt : null ,
234+ updatedAt : 1 ,
235+ matches : [
236+ {
237+ appLabel : "Notes" ,
238+ candidateId : "notes" ,
239+ tier : "optional" ,
240+ reason : "Connects notes" ,
241+ candidate : {
242+ id : "notes" ,
243+ displayName : "Notes skill" ,
244+ summary : "Notes" ,
245+ source : "clawhub-skill" ,
246+ } ,
247+ } ,
248+ ] ,
249+ } ) ,
250+ clearPending,
251+ } ) ;
252+
253+ expect ( clearPending ) . toHaveBeenCalledWith ( {
254+ expected : expect . objectContaining ( { inventoryHash : "hash" , updatedAt : 1 } ) ,
255+ } ) ;
256+ expect ( runtime . log ) . toHaveBeenCalledWith ( "[]" ) ;
257+ } ) ;
258+
106259 it ( "clears a stored offer for the next onboarding scan" , ( ) => {
107260 const runtime = makeRuntime ( ) ;
108261 const clear = vi . fn ( ( ) => true ) ;
0 commit comments