@@ -9,10 +9,13 @@ import path from 'node:path';
99import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest' ;
1010import {
1111 executePendingPostTurnAction ,
12+ resolveActiveGoalContinuation ,
1213 unpackQueuedAgentInstruction ,
14+ type ActiveGoalContinuationHost ,
1315 type PostTurnActionHost ,
1416 type PostTurnEnvironment ,
1517} from '../../../src/core/agent/PostTurnActionCoordinator.js' ;
18+ import { GoalManager } from '../../../src/goals/GoalManager.js' ;
1619
1720const interactiveEnvironment : PostTurnEnvironment = {
1821 stdinIsTTY : true ,
@@ -147,3 +150,46 @@ describe('post-turn research publication', () => {
147150 expect ( requestResearchPublication ) . not . toHaveBeenCalled ( ) ;
148151 } ) ;
149152} ) ;
153+
154+ describe ( 'post-turn active goal continuation' , ( ) => {
155+ let workspaceRoot : string ;
156+ let host : ActiveGoalContinuationHost ;
157+
158+ beforeEach ( async ( ) => {
159+ workspaceRoot = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , 'autohand-goal-continuation-' ) ) ;
160+ await new GoalManager ( workspaceRoot ) . createGoal ( { objective : 'Finish the browser game' } ) ;
161+ host = {
162+ runtime : { workspaceRoot } ,
163+ shouldExit : false ,
164+ interactiveAutomodeEnabled : true ,
165+ } ;
166+ } ) ;
167+
168+ afterEach ( async ( ) => {
169+ await fs . remove ( workspaceRoot ) ;
170+ } ) ;
171+
172+ it ( 'continues a successful auto-mode turn while the goal remains active' , async ( ) => {
173+ const continuation = await resolveActiveGoalContinuation ( host , true ) ;
174+
175+ expect ( continuation ) . toContain ( 'Active goal: Finish the browser game' ) ;
176+ expect ( continuation ) . toContain ( 'until it is complete, blocked, paused, cleared, or budget-limited' ) ;
177+ } ) ;
178+
179+ it . each ( [
180+ [ 'the turn failed' , false , true , false ] ,
181+ [ 'auto mode is disabled' , true , false , false ] ,
182+ [ 'the session is exiting' , true , true , true ] ,
183+ ] ) ( 'does not continue when %s' , async ( _label , turnSucceeded , autoMode , shouldExit ) => {
184+ host . interactiveAutomodeEnabled = autoMode ;
185+ host . shouldExit = shouldExit ;
186+
187+ await expect ( resolveActiveGoalContinuation ( host , turnSucceeded ) ) . resolves . toBeNull ( ) ;
188+ } ) ;
189+
190+ it ( 'stops scheduling after the goal reaches a terminal state' , async ( ) => {
191+ await new GoalManager ( workspaceRoot ) . updateGoal ( { status : 'complete' } ) ;
192+
193+ await expect ( resolveActiveGoalContinuation ( host , true ) ) . resolves . toBeNull ( ) ;
194+ } ) ;
195+ } ) ;
0 commit comments