1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
// ready-subtasks.test.mjs — subtask rollup visibility for READY tasks
//
// Run with: node --test web/test/ready-subtasks.test.mjs
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
// ── Logic under test ──────────────────────────────────────────────────────────
//
// READY tasks (awaiting user approval) that have subtasks should display a
// subtask rollup identical to BLOCKED tasks. The rollup fetches from:
// GET /api/tasks/{id}/subtasks
//
// States that show the subtask rollup:
// - BLOCKED (when task.question is absent)
// - READY (always — mirrors BLOCKED without question)
function shouldShowSubtaskRollup(state, hasQuestion) {
if (state === 'BLOCKED' && !hasQuestion) return true;
if (state === 'READY') return true;
return false;
}
function getSubtasksEndpoint(taskId) {
return `/api/tasks/${taskId}/subtasks`;
}
// ── Tests ─────────────────────────────────────────────────────────────────────
describe('subtask rollup visibility', () => {
it('READY tasks show subtask rollup', () => {
assert.equal(shouldShowSubtaskRollup('READY', false), true);
});
it('READY tasks show subtask rollup even when question is absent', () => {
assert.equal(shouldShowSubtaskRollup('READY', true), true);
});
it('BLOCKED tasks without a question show subtask rollup', () => {
assert.equal(shouldShowSubtaskRollup('BLOCKED', false), true);
});
it('BLOCKED tasks with a question do NOT show subtask rollup', () => {
assert.equal(shouldShowSubtaskRollup('BLOCKED', true), false);
});
it('RUNNING tasks do not show subtask rollup', () => {
assert.equal(shouldShowSubtaskRollup('RUNNING', false), false);
});
it('PENDING tasks do not show subtask rollup', () => {
assert.equal(shouldShowSubtaskRollup('PENDING', false), false);
});
it('COMPLETED tasks do not show subtask rollup', () => {
assert.equal(shouldShowSubtaskRollup('COMPLETED', false), false);
});
it('FAILED tasks do not show subtask rollup', () => {
assert.equal(shouldShowSubtaskRollup('FAILED', false), false);
});
});
describe('subtask rollup API endpoint', () => {
it('uses correct subtasks endpoint for a READY task', () => {
assert.equal(getSubtasksEndpoint('task-abc'), '/api/tasks/task-abc/subtasks');
});
it('uses correct subtasks endpoint for a BLOCKED task', () => {
assert.equal(getSubtasksEndpoint('task-xyz'), '/api/tasks/task-xyz/subtasks');
});
});
|