diff options
| author | Claudomator Agent <agent@claudomator> | 2026-03-12 01:48:15 +0000 |
|---|---|---|
| committer | Claudomator Agent <agent@claudomator> | 2026-03-12 01:48:15 +0000 |
| commit | f28c22352aa1a8ede7552ee0277f7d60552d9094 (patch) | |
| tree | 02e9085809462e09b7d2a68ebb754e247eaecd22 /web/test | |
| parent | 4f83d35fa47bc71b31e0f92a0927bea8910c01b6 (diff) | |
feat: add Resume support for CANCELLED, FAILED, and BUDGET_EXCEEDED tasks
Interrupted tasks (CANCELLED, FAILED, BUDGET_EXCEEDED) now support session
resume in addition to restart. Both buttons are shown on the task card.
- executor: extend resumablePoolStates to include CANCELLED, FAILED, BUDGET_EXCEEDED
- api: extend handleResumeTimedOutTask to accept all resumable states with
state-specific resume messages; replace hard-coded TIMED_OUT check with a
resumableStates map
- web: add RESUME_STATES set; render Resume + Restart buttons for interrupted
states; TIMED_OUT keeps Resume only
- tests: 5 new Go tests (TestResumeInterrupted_*); updated task-actions.test.mjs
with 17 tests covering dual-button behaviour
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'web/test')
| -rw-r--r-- | web/test/task-actions.test.mjs | 89 |
1 files changed, 56 insertions, 33 deletions
diff --git a/web/test/task-actions.test.mjs b/web/test/task-actions.test.mjs index c7d666b..a1790fa 100644 --- a/web/test/task-actions.test.mjs +++ b/web/test/task-actions.test.mjs @@ -6,78 +6,101 @@ import { describe, it } from 'node:test'; import assert from 'node:assert/strict'; // ── Logic under test ────────────────────────────────────────────────────────── +// +// Interrupted states (CANCELLED, FAILED, BUDGET_EXCEEDED) get BOTH a Resume +// button and a Restart button. TIMED_OUT gets Resume only. + +const RESUME_STATES = new Set(['TIMED_OUT', 'CANCELLED', 'FAILED', 'BUDGET_EXCEEDED']); +const RESTART_STATES = new Set(['CANCELLED', 'FAILED', 'BUDGET_EXCEEDED']); + +function getCardActions(state) { + const actions = []; + if (state === 'PENDING') return ['run']; + if (state === 'RUNNING') return ['cancel']; + if (state === 'READY') return ['approve']; + if (RESUME_STATES.has(state)) actions.push('resume'); + if (RESTART_STATES.has(state)) actions.push('restart'); + return actions.length ? actions : [null]; +} -const RESTART_STATES = new Set(['FAILED', 'CANCELLED', 'BUDGET_EXCEEDED']); - -function getCardAction(state) { - if (state === 'PENDING') return 'run'; - if (state === 'RUNNING') return 'cancel'; - if (state === 'READY') return 'approve'; - if (state === 'TIMED_OUT') return 'resume'; - if (RESTART_STATES.has(state)) return 'restart'; - return null; +function getResumeEndpoint(state) { + return RESUME_STATES.has(state) ? '/resume' : null; } -function getApiEndpoint(state) { - if (state === 'TIMED_OUT') return '/resume'; - if (RESTART_STATES.has(state)) return '/run'; - return null; +function getRestartEndpoint(state) { + return RESTART_STATES.has(state) ? '/run' : null; } // ── Tests ───────────────────────────────────────────────────────────────────── describe('task card action buttons', () => { it('shows Run button for PENDING', () => { - assert.equal(getCardAction('PENDING'), 'run'); + assert.deepEqual(getCardActions('PENDING'), ['run']); }); it('shows Cancel button for RUNNING', () => { - assert.equal(getCardAction('RUNNING'), 'cancel'); + assert.deepEqual(getCardActions('RUNNING'), ['cancel']); }); - it('shows Restart button for FAILED', () => { - assert.equal(getCardAction('FAILED'), 'restart'); + it('shows Resume AND Restart buttons for FAILED', () => { + assert.deepEqual(getCardActions('FAILED'), ['resume', 'restart']); }); - it('shows Resume button for TIMED_OUT', () => { - assert.equal(getCardAction('TIMED_OUT'), 'resume'); + it('shows Resume AND Restart buttons for CANCELLED', () => { + assert.deepEqual(getCardActions('CANCELLED'), ['resume', 'restart']); }); - it('shows Restart button for CANCELLED', () => { - assert.equal(getCardAction('CANCELLED'), 'restart'); + it('shows Resume AND Restart buttons for BUDGET_EXCEEDED', () => { + assert.deepEqual(getCardActions('BUDGET_EXCEEDED'), ['resume', 'restart']); }); - it('shows Restart button for BUDGET_EXCEEDED', () => { - assert.equal(getCardAction('BUDGET_EXCEEDED'), 'restart'); + it('shows Resume button only for TIMED_OUT (no restart)', () => { + assert.deepEqual(getCardActions('TIMED_OUT'), ['resume']); }); it('shows approve buttons for READY', () => { - assert.equal(getCardAction('READY'), 'approve'); + assert.deepEqual(getCardActions('READY'), ['approve']); }); it('shows no button for COMPLETED', () => { - assert.equal(getCardAction('COMPLETED'), null); + assert.deepEqual(getCardActions('COMPLETED'), [null]); }); it('shows no button for QUEUED', () => { - assert.equal(getCardAction('QUEUED'), null); + assert.deepEqual(getCardActions('QUEUED'), [null]); }); }); describe('task action API endpoints', () => { it('TIMED_OUT uses /resume endpoint', () => { - assert.equal(getApiEndpoint('TIMED_OUT'), '/resume'); + assert.equal(getResumeEndpoint('TIMED_OUT'), '/resume'); + }); + + it('CANCELLED uses /resume endpoint for resume', () => { + assert.equal(getResumeEndpoint('CANCELLED'), '/resume'); + }); + + it('FAILED uses /resume endpoint for resume', () => { + assert.equal(getResumeEndpoint('FAILED'), '/resume'); + }); + + it('BUDGET_EXCEEDED uses /resume endpoint for resume', () => { + assert.equal(getResumeEndpoint('BUDGET_EXCEEDED'), '/resume'); + }); + + it('CANCELLED uses /run endpoint for restart', () => { + assert.equal(getRestartEndpoint('CANCELLED'), '/run'); }); - it('FAILED uses /run endpoint', () => { - assert.equal(getApiEndpoint('FAILED'), '/run'); + it('FAILED uses /run endpoint for restart', () => { + assert.equal(getRestartEndpoint('FAILED'), '/run'); }); - it('CANCELLED uses /run endpoint', () => { - assert.equal(getApiEndpoint('CANCELLED'), '/run'); + it('BUDGET_EXCEEDED uses /run endpoint for restart', () => { + assert.equal(getRestartEndpoint('BUDGET_EXCEEDED'), '/run'); }); - it('BUDGET_EXCEEDED uses /run endpoint', () => { - assert.equal(getApiEndpoint('BUDGET_EXCEEDED'), '/run'); + it('TIMED_OUT has no /run restart endpoint', () => { + assert.equal(getRestartEndpoint('TIMED_OUT'), null); }); }); |
