fix(agent-jobs): add heartbeat cancel and stale recovery
This commit is contained in:
@@ -107,3 +107,35 @@ describe('updateStatus terminal guard', () => {
|
||||
expect(job?.status).toBe('checks_running');
|
||||
});
|
||||
});
|
||||
|
||||
describe('heartbeatWorkspace cancellation propagation', () => {
|
||||
test('reports cancellation while refreshing the workspace heartbeat', async () => {
|
||||
const t = convexTest(schema, modules);
|
||||
const jobId = await seedJob(t, 'cancelled');
|
||||
|
||||
const result = await t.mutation(api.agentJobs.heartbeatWorkspace, {
|
||||
workerToken: 'test-worker-token',
|
||||
workerId: 'worker-1',
|
||||
jobId,
|
||||
});
|
||||
|
||||
expect(result).toEqual({ success: true, cancelRequested: true });
|
||||
const job = await t.run(async (ctx) => await ctx.db.get(jobId));
|
||||
expect(job?.status).toBe('cancelled');
|
||||
expect(job?.workspaceStatus).toBe('active');
|
||||
expect(job?.lastHeartbeatAt).toBeTypeOf('number');
|
||||
});
|
||||
|
||||
test('reports no cancellation for an active job', async () => {
|
||||
const t = convexTest(schema, modules);
|
||||
const jobId = await seedJob(t, 'running');
|
||||
|
||||
const result = await t.mutation(api.agentJobs.heartbeatWorkspace, {
|
||||
workerToken: 'test-worker-token',
|
||||
workerId: 'worker-1',
|
||||
jobId,
|
||||
});
|
||||
|
||||
expect(result).toEqual({ success: true, cancelRequested: false });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user