mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
Taskwarrior's task export / task import JSON is the task format of the Taskwarrior command line tool, and WeKan read and wrote neither. It now imports from the import picker, as a JSON array or one task per line as versions before 2.4 write it, and exports from the board's export menu. A completed task goes to Done, a waiting one to Waiting and a started one to In Progress; project and priority become labels, tags become labels, entry, due, scheduled and end become dates, annotations become comments and depends becomes blocked-by dependencies resolved by uuid. WeKan's wekanlist and wekandescription attributes, which Taskwarrior keeps as orphaned UDAs, carry list names and descriptions across a round trip. Deleted tasks, recurring templates, bad dates and unmapped attributes are reported in the loss report instead of guessed. tests/taskwarrior.test.cjs covers the mapping, both input shapes, the round trip and the negatives; the format guards learn the new format and a Playwright case imports a Taskwarrior export through the page. The new instruction text is in English, pending translation. Thanks to xet7 !
114 lines
7.9 KiB
JavaScript
114 lines
7.9 KiB
JavaScript
'use strict';
|
|
|
|
// Taskwarrior import/export (models/lib/taskwarriorFormat.js), following
|
|
// https://taskwarrior.org/docs/design/task/. Run: node tests/taskwarrior.test.cjs
|
|
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const read = file => fs.readFileSync(path.join(__dirname, '..', file), 'utf8');
|
|
|
|
async function main() {
|
|
const { parseTaskwarrior, formatTaskwarrior, taskwarriorDate, taskwarriorUuid, MAX_TASKWARRIOR_TASKS } =
|
|
await import('../models/lib/taskwarriorFormat.js');
|
|
const { EXTERNAL_PARSERS } = await import('../models/lib/externalParsers.js');
|
|
const { formatters } = await import('../models/lib/externalExportFormatters.js');
|
|
const { validateImportSourceShape } = await import('../models/lib/importSourceShape.js');
|
|
const { planImportedTask, planImportedLinks } = await import('../models/lib/importedTaskPlan.js');
|
|
let passed = 0;
|
|
const test = (name, fn) => { fn(); passed += 1; console.log(' ok -', name); };
|
|
|
|
test('a task export maps to cards: status, project, priority, tags, dates, annotations, depends', () => {
|
|
const { tasks, columns, unsupported } = parseTaskwarrior(JSON.stringify([
|
|
{ id: 1, uuid: 'u1', status: 'pending', entry: '20260901T120000Z', description: 'Order valves', project: 'Plant.Pumps',
|
|
priority: 'H', tags: ['shop', 'urgent'], due: '20261010T000000Z', scheduled: '20261001T000000Z', urgency: 9.1,
|
|
annotations: [{ entry: '20260902T080000Z', description: 'Call the vendor' }] },
|
|
{ uuid: 'u2', status: 'completed', entry: '20260901T120000Z', end: '20261009T120000Z', description: 'Replace pump',
|
|
depends: ['u1'] },
|
|
{ uuid: 'u3', status: 'pending', start: '20261002T090000Z', description: 'Fit seals', depends: 'u1,u2' },
|
|
{ uuid: 'u4', status: 'waiting', wait: '20261101T000000Z', description: 'Inspect' },
|
|
]));
|
|
assert.deepEqual(tasks.map(task => task.column_name), ['To Do', 'Done', 'In Progress', 'Waiting']);
|
|
assert.deepEqual(columns.map(column => column.title), ['To Do', 'Done', 'In Progress', 'Waiting']);
|
|
assert.deepEqual(tasks[0].tags, ['project:Plant.Pumps', 'priority:H', 'shop', 'urgent']);
|
|
assert.deepEqual([tasks[0].date_creation, tasks[0].date_due, tasks[0].date_started],
|
|
['2026-09-01T12:00:00.000Z', '2026-10-10T00:00:00.000Z', '2026-10-01T00:00:00.000Z']);
|
|
assert.deepEqual(tasks[0].comments, [{ text: 'Call the vendor', date: '2026-09-02T08:00:00.000Z' }]);
|
|
assert.equal(tasks[1].date_end, '2026-10-09T12:00:00.000Z');
|
|
assert.deepEqual(tasks[2].dependencies, [{ ref: 'u1', type: 'is-blocked-by' }, { ref: 'u2', type: 'is-blocked-by' }],
|
|
'the older comma-separated form too');
|
|
assert.deepEqual(unsupported, [{ path: '/3/wait', reason: 'Taskwarrior attribute wait has no WeKan field' }],
|
|
'computed attributes (id, urgency, start) are not losses; wait is');
|
|
const links = planImportedLinks(tasks);
|
|
assert.deepEqual(links.dependencies.map(row => [row.index, row.deps.map(dep => dep.target)]), [[1, [0]], [2, [0, 1]]]);
|
|
assert.equal(planImportedTask(tasks[1]).card.endAt.toISOString(), '2026-10-09T12:00:00.000Z');
|
|
});
|
|
|
|
test('one task object per line, as versions before 2.4 export', () => {
|
|
const { tasks } = parseTaskwarrior('{"uuid":"a","status":"pending","description":"One"},\n{"uuid":"b","status":"pending","description":"Two"}\n');
|
|
assert.deepEqual(tasks.map(task => task.title), ['One', 'Two']);
|
|
});
|
|
|
|
test('a board exports to Taskwarrior and imports back with lists, descriptions, dates, labels and comments', () => {
|
|
const collected = { board: { title: 'Plant' }, items: [
|
|
{ cardId: 'card-1', title: 'Order valves', listTitle: 'Doing', description: 'Two of them\nDN50',
|
|
labels: ['priority:H', 'project:Plant', 'shop floor'], dueAt: '2026-10-10T00:00:00.000Z',
|
|
startAt: '2026-10-01T00:00:00.000Z', createdAt: '2026-09-01T12:00:00.000Z',
|
|
comments: [{ text: 'Call the vendor', author: 'alice', date: '2026-09-02T08:00:00.000Z' }] },
|
|
{ cardId: 'card-2', title: 'Replace pump', listTitle: 'Done', labels: [], createdAt: '2026-09-02T00:00:00.000Z',
|
|
endAt: '2026-10-09T12:00:00.000Z' },
|
|
] };
|
|
assert.equal(formatters.taskwarrior, formatTaskwarrior);
|
|
const text = formatters.taskwarrior(collected);
|
|
const exported = JSON.parse(text);
|
|
assert.deepEqual(exported[0], { uuid: taskwarriorUuid('card-1'), status: 'pending', description: 'Order valves',
|
|
entry: '20260901T120000Z', due: '20261010T000000Z', scheduled: '20261001T000000Z', project: 'Plant', priority: 'H',
|
|
tags: ['shop_floor'], annotations: [{ entry: '20260902T080000Z', description: 'alice: Call the vendor' }],
|
|
wekanlist: 'Doing', wekandescription: 'Two of them\nDN50' });
|
|
assert.deepEqual([exported[1].status, exported[1].end, exported[1].description], ['completed', '20261009T120000Z', 'Replace pump']);
|
|
const [a, b] = EXTERNAL_PARSERS.taskwarrior(text).tasks;
|
|
assert.deepEqual([a.title, a.column_name, a.description, a.tags, a.date_due],
|
|
['Order valves', 'Doing', 'Two of them\nDN50', ['project:Plant', 'priority:H', 'shop_floor'], '2026-10-10T00:00:00.000Z']);
|
|
assert.deepEqual([b.column_name, b.date_end], ['Done', '2026-10-09T12:00:00.000Z']);
|
|
// A uuid is an RFC 4122 version-4 shape, and the same card always gets the same one.
|
|
assert.match(taskwarriorUuid('card-1'), /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/);
|
|
assert.equal(taskwarriorUuid('card-1'), taskwarriorUuid('card-1'));
|
|
assert.notEqual(taskwarriorUuid('card-1'), taskwarriorUuid('card-2'));
|
|
});
|
|
|
|
test('negative: deleted tasks, recurring templates, bad dates and malformed input', () => {
|
|
const { tasks, unsupported } = parseTaskwarrior(JSON.stringify([
|
|
{ uuid: 'd', status: 'deleted', description: 'Gone' },
|
|
{ uuid: 'r', status: 'recurring', recur: 'weekly', description: 'Template' },
|
|
{ uuid: 'p', status: 'pending', description: 'Bad date', due: 'tomorrow', myuda: 'x' },
|
|
'not a task',
|
|
]));
|
|
assert.deepEqual(tasks.map(task => task.title), ['Bad date']);
|
|
assert.equal(tasks[0].date_due, undefined, 'a bad date is reported, not guessed');
|
|
assert.deepEqual(unsupported.map(row => row.path), ['/0/status', '/1/status', '/2/myuda', '/2/due', '/3']);
|
|
assert.throws(() => parseTaskwarrior('{"description": "x"'), /line 1 is not a JSON object/);
|
|
assert.throws(() => parseTaskwarrior(JSON.stringify(Array.from({ length: MAX_TASKWARRIOR_TASKS + 1 }, () => ({})))),
|
|
/more than/);
|
|
assert.equal(taskwarriorDate('2026-13-45T00:00:00Z'), undefined);
|
|
assert.equal(taskwarriorDate(20260901), undefined);
|
|
assert.deepEqual(parseTaskwarrior('').tasks, []);
|
|
});
|
|
|
|
test('wiring: parser, formatter, page, method, export type and shape check know the format', () => {
|
|
assert.equal(EXTERNAL_PARSERS.taskwarrior, parseTaskwarrior);
|
|
assert.equal(validateImportSourceShape('taskwarrior', '[]'), undefined);
|
|
assert.throws(() => validateImportSourceShape('taskwarrior', { tasks: [] }));
|
|
assert.match(read('client/components/import/import.js'), /\{ key: 'taskwarrior', name: 'Taskwarrior' \}/);
|
|
assert.match(read('client/components/import/import.js'), /dataSource === 'todotxt' \|\| dataSource === 'taskwarrior'/);
|
|
assert.match(read('models/import.js'), /case 'taskwarrior':[\s\S]*?check\(board, String\);[\s\S]*?new KanboardCreator\(data, 'taskwarrior'\)/);
|
|
assert.match(read('models/export.js'), /taskwarrior: 'application\/json'/);
|
|
assert.match(read('client/components/boards/exportScope.js'), /key: 'taskwarrior'.*path: 'export\/taskwarrior', ext: 'json'/);
|
|
assert.match(read('docs/Features/ImportExport/Format-Coverage.md'), /\| Taskwarrior \|/);
|
|
const en = JSON.parse(read('imports/i18n/data/en.i18n.json'));
|
|
assert.match(en['import-board-instruction-taskwarrior'], /task export/);
|
|
});
|
|
|
|
console.log(`\ntaskwarrior: ${passed} passed`);
|
|
}
|
|
main().catch(error => { console.error(error); process.exit(1); });
|