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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
// tab-filters.test.mjs — TDD tests for new tab filter functions
//
// Run with: node --test web/test/tab-filters.test.mjs
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { filterQueueTasks, filterReadyTasks, filterAllDoneTasks } from '../app.js';
// ── Helpers ────────────────────────────────────────────────────────────────────
function makeTask(state, created_at = null) {
return { id: state, name: `task-${state}`, state, created_at };
}
const ALL_STATES = [
'PENDING', 'QUEUED', 'RUNNING', 'READY', 'BLOCKED',
'COMPLETED', 'FAILED', 'TIMED_OUT', 'CANCELLED', 'BUDGET_EXCEEDED',
];
// ── filterQueueTasks ──────────────────────────────────────────────────────────
describe('filterQueueTasks', () => {
it('includes QUEUED tasks', () => {
const tasks = ALL_STATES.map(s => makeTask(s));
const result = filterQueueTasks(tasks);
assert.ok(result.some(t => t.state === 'QUEUED'), 'QUEUED should be included');
});
it('includes PENDING tasks', () => {
const tasks = ALL_STATES.map(s => makeTask(s));
const result = filterQueueTasks(tasks);
assert.ok(result.some(t => t.state === 'PENDING'), 'PENDING should be included');
});
it('excludes all other states', () => {
const tasks = ALL_STATES.map(s => makeTask(s));
const result = filterQueueTasks(tasks);
for (const state of ['RUNNING', 'READY', 'BLOCKED', 'COMPLETED', 'FAILED', 'TIMED_OUT', 'CANCELLED', 'BUDGET_EXCEEDED']) {
assert.ok(!result.some(t => t.state === state), `${state} should be excluded`);
}
});
it('returns only QUEUED and PENDING (length 2 from all states)', () => {
const tasks = ALL_STATES.map(s => makeTask(s));
const result = filterQueueTasks(tasks);
assert.equal(result.length, 2);
});
it('returns empty array for empty input', () => {
assert.deepEqual(filterQueueTasks([]), []);
});
});
// ── filterReadyTasks ──────────────────────────────────────────────────────────
describe('filterReadyTasks', () => {
it('includes READY tasks', () => {
const tasks = ALL_STATES.map(s => makeTask(s));
const result = filterReadyTasks(tasks);
assert.ok(result.some(t => t.state === 'READY'), 'READY should be included');
});
it('excludes all non-READY states', () => {
const tasks = ALL_STATES.map(s => makeTask(s));
const result = filterReadyTasks(tasks);
for (const state of ['PENDING', 'QUEUED', 'RUNNING', 'BLOCKED', 'COMPLETED', 'FAILED', 'TIMED_OUT', 'CANCELLED', 'BUDGET_EXCEEDED']) {
assert.ok(!result.some(t => t.state === state), `${state} should be excluded`);
}
});
it('returns only READY tasks (length 1 from all states)', () => {
const tasks = ALL_STATES.map(s => makeTask(s));
const result = filterReadyTasks(tasks);
assert.equal(result.length, 1);
});
it('returns empty array for empty input', () => {
assert.deepEqual(filterReadyTasks([]), []);
});
});
// ── filterAllDoneTasks ────────────────────────────────────────────────────────
describe('filterAllDoneTasks', () => {
it('includes COMPLETED tasks within 24h', () => {
const now = new Date().toISOString();
const result = filterAllDoneTasks([makeTask('COMPLETED', now)]);
assert.equal(result.length, 1);
});
it('includes TIMED_OUT tasks within 24h', () => {
const now = new Date().toISOString();
const result = filterAllDoneTasks([makeTask('TIMED_OUT', now)]);
assert.equal(result.length, 1);
});
it('includes BUDGET_EXCEEDED tasks within 24h', () => {
const now = new Date().toISOString();
const result = filterAllDoneTasks([makeTask('BUDGET_EXCEEDED', now)]);
assert.equal(result.length, 1);
});
it('excludes non-done states', () => {
const now = new Date().toISOString();
const tasks = ALL_STATES.map(s => makeTask(s, now));
const result = filterAllDoneTasks(tasks);
for (const state of ['PENDING', 'QUEUED', 'RUNNING', 'READY', 'BLOCKED', 'FAILED', 'CANCELLED']) {
assert.ok(!result.some(t => t.state === state), `${state} should be excluded`);
}
});
it('excludes COMPLETED tasks older than 24h by default', () => {
const longAgo = new Date(Date.now() - 25 * 60 * 60 * 1000).toISOString();
const result = filterAllDoneTasks([makeTask('COMPLETED', longAgo)]);
assert.equal(result.length, 0, 'should hide tasks older than 24h');
});
it('includes tasks with null created_at by default (defensive)', () => {
const result = filterAllDoneTasks([makeTask('COMPLETED', null)]);
assert.equal(result.length, 1);
});
it('returns empty array for empty input', () => {
assert.deepEqual(filterAllDoneTasks([]), []);
});
});
|