From b5947952381ccbc15bbe341c48c77e3a331bb476 Mon Sep 17 00:00:00 2001 From: Ralph Khreish <35776126+Crunchyman-ralph@users.noreply.github.com> Date: Thu, 31 Jul 2025 23:41:24 +0300 Subject: [PATCH] chore: run format to resolve CI issues --- scripts/modules/utils.js | 17 +++++++++------ tests/unit/task-finder.test.js | 40 ++++++++++++++++++++-------------- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/scripts/modules/utils.js b/scripts/modules/utils.js index aab7fd0f..fa6cdc26 100644 --- a/scripts/modules/utils.js +++ b/scripts/modules/utils.js @@ -268,8 +268,8 @@ function hasTaggedStructure(data) { */ function normalizeTaskIds(tasks) { if (!Array.isArray(tasks)) return; - - tasks.forEach(task => { + + tasks.forEach((task) => { // Convert task ID to number with validation if (task.id !== undefined) { const parsedId = parseInt(task.id, 10); @@ -277,10 +277,10 @@ function normalizeTaskIds(tasks) { task.id = parsedId; } } - + // Convert subtask IDs to numbers with validation if (Array.isArray(task.subtasks)) { - task.subtasks.forEach(subtask => { + task.subtasks.forEach((subtask) => { if (subtask.id !== undefined) { // Check for dot notation (which shouldn't exist in storage) if (typeof subtask.id === 'string' && subtask.id.includes('.')) { @@ -439,10 +439,13 @@ function readJSON(filepath, projectRoot = null, tag = null) { // Store reference to the raw tagged data for functions that need it const originalTaggedData = JSON.parse(JSON.stringify(data)); - + // Normalize IDs in all tags before storing as originalTaggedData for (const tagName in originalTaggedData) { - if (originalTaggedData[tagName] && Array.isArray(originalTaggedData[tagName].tasks)) { + if ( + originalTaggedData[tagName] && + Array.isArray(originalTaggedData[tagName].tasks) + ) { normalizeTaskIds(originalTaggedData[tagName].tasks); } } @@ -1465,4 +1468,4 @@ export { flattenTasksWithSubtasks, ensureTagMetadata, normalizeTaskIds -}; \ No newline at end of file +}; diff --git a/tests/unit/task-finder.test.js b/tests/unit/task-finder.test.js index 78348d8f..92e24c26 100644 --- a/tests/unit/task-finder.test.js +++ b/tests/unit/task-finder.test.js @@ -26,23 +26,31 @@ describe('Task Finder', () => { test('should find tasks when JSON contains string IDs (normalized to numbers)', () => { // Simulate tasks loaded from JSON with string IDs and mixed subtask notations const tasksWithStringIds = [ - { id: "1", title: 'First Task' }, - { id: "2", title: 'Second Task', subtasks: [ - { id: "1", title: 'Subtask One' }, - { id: "2.2", title: 'Subtask Two (with dotted notation)' } // Testing dotted notation - ]}, - { id: "5", title: 'Fifth Task', subtasks: [ - { id: "5.1", title: 'Subtask with dotted ID' }, // Should normalize to 1 - { id: "3", title: 'Subtask with simple ID' } // Should stay as 3 - ]} + { id: '1', title: 'First Task' }, + { + id: '2', + title: 'Second Task', + subtasks: [ + { id: '1', title: 'Subtask One' }, + { id: '2.2', title: 'Subtask Two (with dotted notation)' } // Testing dotted notation + ] + }, + { + id: '5', + title: 'Fifth Task', + subtasks: [ + { id: '5.1', title: 'Subtask with dotted ID' }, // Should normalize to 1 + { id: '3', title: 'Subtask with simple ID' } // Should stay as 3 + ] + } ]; - + // The readJSON function should normalize these IDs to numbers // For this test, we'll manually normalize them to simulate what happens - tasksWithStringIds.forEach(task => { + tasksWithStringIds.forEach((task) => { task.id = parseInt(task.id, 10); if (task.subtasks) { - task.subtasks.forEach(subtask => { + task.subtasks.forEach((subtask) => { // Handle dotted notation like "5.1" -> extract the subtask part if (typeof subtask.id === 'string' && subtask.id.includes('.')) { const parts = subtask.id.split('.'); @@ -60,7 +68,7 @@ describe('Task Finder', () => { expect(result1.task.id).toBe(5); expect(result1.task.title).toBe('Fifth Task'); - // Test finding tasks by string ID + // Test finding tasks by string ID const result2 = findTaskById(tasksWithStringIds, '5'); expect(result2.task).toBeDefined(); expect(result2.task.id).toBe(5); @@ -71,19 +79,19 @@ describe('Task Finder', () => { expect(result3.task.id).toBe(1); expect(result3.task.title).toBe('Subtask One'); expect(result3.task.isSubtask).toBe(true); - + // Test subtask that was originally "2.2" (should be normalized to 2) const result4 = findTaskById(tasksWithStringIds, '2.2'); expect(result4.task).toBeDefined(); expect(result4.task.id).toBe(2); expect(result4.task.title).toBe('Subtask Two (with dotted notation)'); - + // Test subtask that was originally "5.1" (should be normalized to 1) const result5 = findTaskById(tasksWithStringIds, '5.1'); expect(result5.task).toBeDefined(); expect(result5.task.id).toBe(1); expect(result5.task.title).toBe('Subtask with dotted ID'); - + // Test subtask that was originally "3" (should stay as 3) const result6 = findTaskById(tasksWithStringIds, '5.3'); expect(result6.task).toBeDefined();