test: Stabilize HITL abort fallback specs

This commit is contained in:
Danny Avila 2026-05-19 14:01:56 -04:00
parent 58c18e720e
commit 8dc4e2da57
2 changed files with 9 additions and 3 deletions

View file

@ -74,6 +74,10 @@ describe('Agent Abort Endpoint', () => {
beforeEach(() => {
jest.clearAllMocks();
mockGenerationJobManager.getJob.mockReset();
mockGenerationJobManager.abortJob.mockReset();
mockGenerationJobManager.getActiveJobIdsForUser.mockReset();
mockSaveMessage.mockReset();
});
describe('POST /chat/abort', () => {
@ -325,7 +329,6 @@ describe('Agent Abort Endpoint', () => {
describe('Job Not Found', () => {
it('should skip paused fallback jobs and abort the running job', async () => {
mockGenerationJobManager.getJob
.mockResolvedValueOnce(null)
.mockResolvedValueOnce({
status: 'requires_action',
metadata: { userId: 'test-user-123' },
@ -355,7 +358,7 @@ describe('Agent Abort Endpoint', () => {
});
it('should not abort paused fallback jobs', async () => {
mockGenerationJobManager.getJob.mockResolvedValueOnce(null).mockResolvedValueOnce({
mockGenerationJobManager.getJob.mockResolvedValueOnce({
status: 'requires_action',
metadata: { userId: 'test-user-123' },
});

View file

@ -231,7 +231,10 @@ router.post('/chat/abort', async (req, res) => {
// streamId === conversationId, so try any of the provided IDs
// Skip "new" as it's a placeholder for new conversations, not an actual ID
let jobStreamId =
streamId || (conversationId !== 'new' ? conversationId : null) || abortKey?.split(':')[0];
streamId ||
(conversationId !== 'new' ? conversationId : null) ||
abortKey?.split(':')[0] ||
null;
let job = jobStreamId ? await GenerationJobManager.getJob(jobStreamId) : null;
// Fallback: if job not found and we have a userId, look up active jobs for user