-
Notifications
You must be signed in to change notification settings - Fork 2.5k
fix: ensure consistent task ID serialization as numbers (#1583) #1618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
SiriusA7
wants to merge
5
commits into
eyaltoledano:next
from
SiriusA7:fix/task-id-numeric-consistency
Closed
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
592534c
fix: ensure consistent task ID serialization as numbers (#1583)
SiriusA7 44b84ec
fix(tm-core): resolve task ID type handling and normalization issues
SiriusA7 4f8256a
fix(task-id): prevent invalid ID coercion and negative ID bypass in n…
SiriusA7 983b850
fix(tm-core): ensure numeric task IDs are serialized as numbers in ta…
SiriusA7 6bb6bfa
fix(tm-core): enforce string-canonical task IDs across codebase
Crunchyman-ralph File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| "task-master-ai": patch | ||
| --- | ||
|
|
||
| Fix inconsistent task ID serialization in tasks.json (#1583) | ||
|
|
||
| Task IDs were inconsistently saved as strings or numbers depending on which command was used (e.g., `set-status` vs `update-task`), causing unnecessary git diffs. The tm-core file storage adapter was incorrectly converting IDs to strings when file storage should use numbers. Task and subtask IDs are now consistently saved as numbers in tasks.json. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,239 @@ | ||
| /** | ||
| * @fileoverview Tests for core type definitions and type guards | ||
| */ | ||
|
|
||
| import { describe, it, expect } from 'vitest'; | ||
| import { | ||
| isTaskStatus, | ||
| isTaskPriority, | ||
| isTaskComplexity, | ||
| isValidTaskIdType, | ||
| isTask, | ||
| isSubtask | ||
| } from './index.js'; | ||
| import type { Task, Subtask, TaskStatus, TaskPriority } from './index.js'; | ||
|
|
||
| describe('Type Guards', () => { | ||
| describe('isTaskStatus', () => { | ||
| it('returns true for valid status values', () => { | ||
| expect(isTaskStatus('pending')).toBe(true); | ||
| expect(isTaskStatus('in-progress')).toBe(true); | ||
| expect(isTaskStatus('done')).toBe(true); | ||
| expect(isTaskStatus('deferred')).toBe(true); | ||
| expect(isTaskStatus('cancelled')).toBe(true); | ||
| expect(isTaskStatus('blocked')).toBe(true); | ||
| expect(isTaskStatus('review')).toBe(true); | ||
| }); | ||
|
|
||
| it('returns false for invalid values', () => { | ||
| expect(isTaskStatus('invalid')).toBe(false); | ||
| expect(isTaskStatus('')).toBe(false); | ||
| expect(isTaskStatus(123)).toBe(false); | ||
| expect(isTaskStatus(null)).toBe(false); | ||
| expect(isTaskStatus(undefined)).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('isTaskPriority', () => { | ||
| it('returns true for valid priority values', () => { | ||
| expect(isTaskPriority('low')).toBe(true); | ||
| expect(isTaskPriority('medium')).toBe(true); | ||
| expect(isTaskPriority('high')).toBe(true); | ||
| expect(isTaskPriority('critical')).toBe(true); | ||
| }); | ||
|
|
||
| it('returns false for invalid values', () => { | ||
| expect(isTaskPriority('invalid')).toBe(false); | ||
| expect(isTaskPriority('')).toBe(false); | ||
| expect(isTaskPriority(1)).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('isTaskComplexity', () => { | ||
| it('returns true for valid complexity values', () => { | ||
| expect(isTaskComplexity('simple')).toBe(true); | ||
| expect(isTaskComplexity('moderate')).toBe(true); | ||
| expect(isTaskComplexity('complex')).toBe(true); | ||
| expect(isTaskComplexity('very-complex')).toBe(true); | ||
| }); | ||
|
|
||
| it('returns false for invalid values', () => { | ||
| expect(isTaskComplexity('invalid')).toBe(false); | ||
| expect(isTaskComplexity(5)).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('isValidTaskIdType', () => { | ||
| it('returns true for number IDs', () => { | ||
| expect(isValidTaskIdType(1)).toBe(true); | ||
| expect(isValidTaskIdType(42)).toBe(true); | ||
| expect(isValidTaskIdType(0)).toBe(true); | ||
| expect(isValidTaskIdType(-1)).toBe(true); // Still a number | ||
| }); | ||
|
|
||
| it('returns true for string IDs', () => { | ||
| expect(isValidTaskIdType('1')).toBe(true); | ||
| expect(isValidTaskIdType('HAM-123')).toBe(true); | ||
| expect(isValidTaskIdType('1.2')).toBe(true); | ||
| expect(isValidTaskIdType('')).toBe(true); // Empty string is still a string | ||
| }); | ||
|
|
||
| it('returns false for non-number/string values', () => { | ||
| expect(isValidTaskIdType(null)).toBe(false); | ||
| expect(isValidTaskIdType(undefined)).toBe(false); | ||
| expect(isValidTaskIdType({})).toBe(false); | ||
| expect(isValidTaskIdType([])).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('isTask', () => { | ||
| const createValidTask = (overrides: Partial<Task> = {}): Task => ({ | ||
| id: 1, | ||
| title: 'Test Task', | ||
| description: 'Test description', | ||
| status: 'pending' as TaskStatus, | ||
| priority: 'medium' as TaskPriority, | ||
| dependencies: [], | ||
| details: 'Test details', | ||
| testStrategy: 'Test strategy', | ||
| subtasks: [], | ||
| ...overrides | ||
| }); | ||
|
|
||
| it('returns true for valid task with numeric ID', () => { | ||
| const task = createValidTask({ id: 1 }); | ||
| expect(isTask(task)).toBe(true); | ||
| }); | ||
|
|
||
| it('returns true for valid task with string ID', () => { | ||
| const task = createValidTask({ id: 'HAM-123' }); | ||
| expect(isTask(task)).toBe(true); | ||
| }); | ||
|
|
||
| it('returns true for valid task with string numeric ID', () => { | ||
| const task = createValidTask({ id: '42' }); | ||
| expect(isTask(task)).toBe(true); | ||
| }); | ||
|
|
||
| it('returns false for null/undefined', () => { | ||
| expect(isTask(null)).toBe(false); | ||
| expect(isTask(undefined)).toBe(false); | ||
| }); | ||
|
|
||
| it('returns false for non-object', () => { | ||
| expect(isTask('string')).toBe(false); | ||
| expect(isTask(123)).toBe(false); | ||
| }); | ||
|
|
||
| it('returns false for invalid id type', () => { | ||
| const task = createValidTask(); | ||
| (task as any).id = {}; // Invalid type | ||
| expect(isTask(task)).toBe(false); | ||
| }); | ||
|
|
||
| it('returns false for missing required fields', () => { | ||
| const task = createValidTask(); | ||
| delete (task as any).title; | ||
| expect(isTask(task)).toBe(false); | ||
| }); | ||
|
|
||
| it('returns false for invalid status', () => { | ||
| const task = createValidTask(); | ||
| (task as any).status = 'invalid-status'; | ||
| expect(isTask(task)).toBe(false); | ||
| }); | ||
|
|
||
| it('returns false for invalid priority', () => { | ||
| const task = createValidTask(); | ||
| (task as any).priority = 'invalid-priority'; | ||
| expect(isTask(task)).toBe(false); | ||
| }); | ||
|
|
||
| it('returns false for non-array dependencies', () => { | ||
| const task = createValidTask(); | ||
| (task as any).dependencies = 'not-array'; | ||
| expect(isTask(task)).toBe(false); | ||
| }); | ||
|
|
||
| it('returns false for non-array subtasks', () => { | ||
| const task = createValidTask(); | ||
| (task as any).subtasks = 'not-array'; | ||
| expect(isTask(task)).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('isSubtask', () => { | ||
| const createValidSubtask = (overrides: Partial<Subtask> = {}): Subtask => ({ | ||
| id: 1, | ||
| parentId: 5, | ||
| title: 'Test Subtask', | ||
| description: 'Test description', | ||
| status: 'pending' as TaskStatus, | ||
| priority: 'medium' as TaskPriority, | ||
| dependencies: [], | ||
| details: 'Test details', | ||
| testStrategy: 'Test strategy', | ||
| ...overrides | ||
| }); | ||
|
|
||
| it('returns true for valid subtask with numeric ID and parentId', () => { | ||
| const subtask = createValidSubtask({ id: 1, parentId: 5 }); | ||
| expect(isSubtask(subtask)).toBe(true); | ||
| }); | ||
|
|
||
| it('returns true for valid subtask with string ID and parentId', () => { | ||
| const subtask = createValidSubtask({ id: '1', parentId: '5' }); | ||
| expect(isSubtask(subtask)).toBe(true); | ||
| }); | ||
|
|
||
| it('returns true for valid subtask with mixed ID types', () => { | ||
| // Numeric ID, string parentId | ||
| const subtask1 = createValidSubtask({ id: 1, parentId: '5' }); | ||
| expect(isSubtask(subtask1)).toBe(true); | ||
|
|
||
| // String ID, numeric parentId | ||
| const subtask2 = createValidSubtask({ id: '1', parentId: 5 }); | ||
| expect(isSubtask(subtask2)).toBe(true); | ||
| }); | ||
|
|
||
| it('returns false for null/undefined', () => { | ||
| expect(isSubtask(null)).toBe(false); | ||
| expect(isSubtask(undefined)).toBe(false); | ||
| }); | ||
|
|
||
| it('returns false for non-object', () => { | ||
| expect(isSubtask('string')).toBe(false); | ||
| expect(isSubtask(123)).toBe(false); | ||
| }); | ||
|
|
||
| it('returns false for invalid id type', () => { | ||
| const subtask = createValidSubtask(); | ||
| (subtask as any).id = {}; // Invalid type | ||
| expect(isSubtask(subtask)).toBe(false); | ||
| }); | ||
|
|
||
| it('returns false for invalid parentId type', () => { | ||
| const subtask = createValidSubtask(); | ||
| (subtask as any).parentId = {}; // Invalid type | ||
| expect(isSubtask(subtask)).toBe(false); | ||
| }); | ||
|
|
||
| it('returns false if subtasks property exists', () => { | ||
| const subtask = createValidSubtask(); | ||
| (subtask as any).subtasks = []; // Subtasks cannot have subtasks | ||
| expect(isSubtask(subtask)).toBe(false); | ||
| }); | ||
|
|
||
| it('returns false for invalid status', () => { | ||
| const subtask = createValidSubtask(); | ||
| (subtask as any).status = 'invalid-status'; | ||
| expect(isSubtask(subtask)).toBe(false); | ||
| }); | ||
|
|
||
| it('returns false for invalid priority', () => { | ||
| const subtask = createValidSubtask(); | ||
| (subtask as any).priority = 'invalid-priority'; | ||
| expect(isSubtask(subtask)).toBe(false); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.