@@ -19,6 +19,8 @@ const cursorSdkMock = vi.hoisted(() => ({
1919 send : vi . fn < ( prompt : string ) => Promise < unknown > > ( ) ,
2020 close : vi . fn ( ) ,
2121 cancel : vi . fn ( async ( ) => { } ) ,
22+ storeOpen : vi . fn < ( options : unknown ) => Promise < unknown > > ( ) ,
23+ storeDispose : vi . fn ( async ( ) => { } ) ,
2224 prompt : vi . fn < ( prompt : string , options : unknown ) => Promise < RunResult > > ( async ( ) => ( {
2325 id : "run-cursor-text-generation-test" ,
2426 status : "finished" ,
@@ -30,6 +32,7 @@ const cursorSdkMock = vi.hoisted(() => ({
3032vi . mock ( "./sdk.ts" , ( ) => ( {
3133 Agent : { create : cursorSdkMock . create } ,
3234 createAgentPlatform : vi . fn ( ) ,
35+ SqliteLocalAgentStore : { open : cursorSdkMock . storeOpen } ,
3336} ) ) ;
3437
3538let hasCustomPolicy = false ;
@@ -62,6 +65,9 @@ beforeEach(() => {
6265 } ) ;
6366 cursorSdkMock . close . mockClear ( ) ;
6467 cursorSdkMock . cancel . mockClear ( ) ;
68+ cursorSdkMock . storeDispose . mockClear ( ) ;
69+ cursorSdkMock . storeOpen . mockReset ( ) ;
70+ cursorSdkMock . storeOpen . mockResolvedValue ( { dispose : cursorSdkMock . storeDispose } ) ;
6571 cursorSdkMock . prompt . mockReset ( ) ;
6672 cursorSdkMock . prompt . mockResolvedValue ( {
6773 id : "run-cursor-text-generation-test" ,
@@ -139,6 +145,7 @@ describe("CursorTextGeneration", () => {
139145 } ,
140146 local : {
141147 cwd : "/isolated-text-generation" ,
148+ store : { dispose : cursorSdkMock . storeDispose } ,
142149 autoReview : false ,
143150 sandboxOptions : { enabled : true } ,
144151 settingSources : [ ] ,
@@ -148,6 +155,37 @@ describe("CursorTextGeneration", () => {
148155 } ) . pipe ( Effect . provide ( layerTest ) ) ,
149156 ) ;
150157
158+ it . effect ( "disposes the agent store after the agent, whether the run succeeds or fails" , ( ) =>
159+ Effect . gen ( function * ( ) {
160+ const textGeneration = yield * makeCursorTextGeneration ( cursorSettings , {
161+ CURSOR_API_KEY : "test-cursor-key" ,
162+ } ) ;
163+ const input = {
164+ cwd : process . cwd ( ) ,
165+ branch : "feature/cursor-store" ,
166+ stagedSummary : "M README.md" ,
167+ stagedPatch : "diff --git a/README.md b/README.md" ,
168+ modelSelection : createModelSelection ( ProviderInstanceId . make ( "cursor" ) , "composer-2" ) ,
169+ } ;
170+
171+ yield * textGeneration . generateCommitMessage ( input ) ;
172+ expect ( cursorSdkMock . storeOpen ) . toHaveBeenCalledWith (
173+ expect . objectContaining ( { workspaceRef : "/isolated-text-generation" } ) ,
174+ ) ;
175+ expect ( cursorSdkMock . storeDispose ) . toHaveBeenCalledTimes ( 1 ) ;
176+ expect ( cursorSdkMock . close . mock . invocationCallOrder [ 0 ] ) . toBeLessThan (
177+ cursorSdkMock . storeDispose . mock . invocationCallOrder [ 0 ] ! ,
178+ ) ;
179+
180+ cursorSdkMock . prompt . mockResolvedValueOnce ( {
181+ id : "run-cursor-text-generation-test" ,
182+ status : "error" ,
183+ } ) ;
184+ yield * Effect . flip ( textGeneration . generateCommitMessage ( input ) ) ;
185+ expect ( cursorSdkMock . storeDispose ) . toHaveBeenCalledTimes ( 2 ) ;
186+ } ) . pipe ( Effect . provide ( layerTest ) ) ,
187+ ) ;
188+
151189 it . effect ( "continues in the temp directory when the SDK cannot sandbox" , ( ) =>
152190 Effect . gen ( function * ( ) {
153191 cursorSdkMock . create . mockImplementationOnce ( async ( ) => {
@@ -175,6 +213,7 @@ describe("CursorTextGeneration", () => {
175213 expect ( cursorSdkMock . create . mock . calls [ 1 ] ?. [ 0 ] ) . toMatchObject ( {
176214 local : {
177215 cwd : "/isolated-text-generation" ,
216+ store : { dispose : cursorSdkMock . storeDispose } ,
178217 autoReview : false ,
179218 sandboxOptions : { enabled : false } ,
180219 settingSources : [ ] ,
0 commit comments