diff --git a/src/__tests__/index.test.ts b/src/__tests__/index.test.ts index 5be673e..5865e66 100755 --- a/src/__tests__/index.test.ts +++ b/src/__tests__/index.test.ts @@ -397,6 +397,28 @@ describe('Wedged-dispatch timeout backstop', () => { expect(op.getSummary().failedTasks).toBe(1); }); + it('mission completion stops the command loop so status/timer do not stay active', async () => { + const mod = await import('../index.js'); + const command = new mod.TempestCommand({ + name: 'Lifecycle Op', + llm: { provider: 'mock', model: 'mock-model' }, + }); + + let stopped = false; + command.on('command:stopped', () => { stopped = true; }); + command.start(); + + const mission = command.mission.getActiveMission(); + expect(mission).toBeDefined(); + expect(command.getStatus().running).toBe(true); + + command.mission.completeMission(mission!.id); + + expect(command.getStatus().running).toBe(false); + expect(command.mission.getActiveMission()).toBeUndefined(); + expect(stopped).toBe(true); + }); + it('a wedged mission reaches phase advancement once the per-dispatch backstop fires', async () => { // Tiny backstop so the test is fast and deterministic. const prev = process.env.T3MP3ST_TASK_TIMEOUT_MS; diff --git a/src/index.ts b/src/index.ts index 26cd162..ee8bf98 100755 --- a/src/index.ts +++ b/src/index.ts @@ -496,8 +496,12 @@ export class TempestCommand extends EventEmitter { }); // Forward mission events - this.mission.on('mission:completed', (_mission) => { - // Could trigger reporting here + this.mission.on('mission:completed', () => { + this.stop(); + }); + + this.mission.on('mission:aborted', () => { + this.stop(); }); this.mission.on('mission:phase_changed', ({ mission, newPhase }) => {