From fd42a54d96fcd3342941caaeb61a4b0d5d3f1b4f Mon Sep 17 00:00:00 2001 From: Peter Stone Date: Fri, 6 Mar 2026 23:55:07 +0000 Subject: recover: restore untracked work from recovery branch (no Gemini changes) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Recovered files with no Claude→Agent contamination: - docs/adr/002-task-state-machine.md - internal/api/logs.go/logs_test.go: task-level log streaming endpoint - internal/api/validate.go/validate_test.go: POST /api/tasks/validate - internal/api/server_test.go, storage/db_test.go: expanded test coverage - scripts/reset-failed-tasks, reset-running-tasks - web/app.js, index.html, style.css: frontend improvements - web/test/: active-tasks-tab, delete-button, filter-tabs, sort-tasks tests Manually applied from server.go diff (skipping Claude→Agent rename): - taskLogStore field + validateCmdPath field - DELETE /api/tasks/{id} route + handleDeleteTask - GET /api/tasks/{id}/logs/stream route - POST /api/tasks/{id}/resume route + handleResumeTimedOutTask - handleCancelTask: allow cancelling PENDING/QUEUED tasks directly Co-Authored-By: Claude Sonnet 4.6 --- web/test/filter-tabs.test.mjs | 90 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 web/test/filter-tabs.test.mjs (limited to 'web/test/filter-tabs.test.mjs') diff --git a/web/test/filter-tabs.test.mjs b/web/test/filter-tabs.test.mjs new file mode 100644 index 0000000..44cfaf6 --- /dev/null +++ b/web/test/filter-tabs.test.mjs @@ -0,0 +1,90 @@ +// filter-tabs.test.mjs — TDD contract tests for filterTasksByTab +// +// filterTasksByTab is defined inline here to establish expected behaviour. +// Once filterTasksByTab is exported from web/app.js, remove the inline +// definition and import it instead. +// +// Run with: node --test web/test/filter-tabs.test.mjs + +import { describe, it } from 'node:test'; +import assert from 'node:assert/strict'; +import { filterTasksByTab } from '../app.js'; + +// ── Helpers ──────────────────────────────────────────────────────────────────── + +function makeTask(state) { + return { id: state, name: `task-${state}`, state }; +} + +const ALL_STATES = [ + 'PENDING', 'QUEUED', 'RUNNING', 'READY', 'BLOCKED', + 'COMPLETED', 'FAILED', 'TIMED_OUT', 'CANCELLED', 'BUDGET_EXCEEDED', +]; + +// ── Tests ────────────────────────────────────────────────────────────────────── + +describe('filterTasksByTab — active tab', () => { + it('includes PENDING, QUEUED, RUNNING, READY, BLOCKED', () => { + const tasks = ALL_STATES.map(makeTask); + const result = filterTasksByTab(tasks, 'active'); + for (const state of ['PENDING', 'QUEUED', 'RUNNING', 'READY', 'BLOCKED']) { + assert.ok(result.some(t => t.state === state), `${state} should be included`); + } + }); + + it('excludes COMPLETED, FAILED, TIMED_OUT, CANCELLED, BUDGET_EXCEEDED', () => { + const tasks = ALL_STATES.map(makeTask); + const result = filterTasksByTab(tasks, 'active'); + for (const state of ['COMPLETED', 'FAILED', 'TIMED_OUT', 'CANCELLED', 'BUDGET_EXCEEDED']) { + assert.ok(!result.some(t => t.state === state), `${state} should be excluded`); + } + }); + + it('returns empty array for empty input', () => { + assert.deepEqual(filterTasksByTab([], 'active'), []); + }); +}); + +describe('filterTasksByTab — done tab', () => { + it('includes COMPLETED, FAILED, TIMED_OUT, CANCELLED, BUDGET_EXCEEDED', () => { + const tasks = ALL_STATES.map(makeTask); + const result = filterTasksByTab(tasks, 'done'); + for (const state of ['COMPLETED', 'FAILED', 'TIMED_OUT', 'CANCELLED', 'BUDGET_EXCEEDED']) { + assert.ok(result.some(t => t.state === state), `${state} should be included`); + } + }); + + it('excludes PENDING, QUEUED, RUNNING, READY, BLOCKED', () => { + const tasks = ALL_STATES.map(makeTask); + const result = filterTasksByTab(tasks, 'done'); + for (const state of ['PENDING', 'QUEUED', 'RUNNING', 'READY', 'BLOCKED']) { + assert.ok(!result.some(t => t.state === state), `${state} should be excluded`); + } + }); + + it('returns empty array for empty input', () => { + assert.deepEqual(filterTasksByTab([], 'done'), []); + }); +}); + +describe('filterTasksByTab — all tab', () => { + it('returns all tasks unchanged', () => { + const tasks = ALL_STATES.map(makeTask); + const result = filterTasksByTab(tasks, 'all'); + assert.equal(result.length, ALL_STATES.length); + assert.strictEqual(result, tasks, 'should return the same array reference'); + }); + + it('returns empty array for empty input', () => { + assert.deepEqual(filterTasksByTab([], 'all'), []); + }); +}); + +describe('filterTasksByTab — unknown tab', () => { + it('returns all tasks as defensive fallback', () => { + const tasks = ALL_STATES.map(makeTask); + const result = filterTasksByTab(tasks, 'unknown-tab'); + assert.equal(result.length, ALL_STATES.length); + assert.strictEqual(result, tasks, 'should return the same array reference'); + }); +}); -- cgit v1.2.3