fix: improve cross-level dependency test robustness
- Replace brittle array-index assertions with ID-based lookups - Add write path validation to ensure tests don't write to real files - Add assertion that no writes occur when dependency validation fails - Improve test reliability and address CodeRabbit review feedback Co-authored-by: Ralph Khreish <Crunchyman-ralph@users.noreply.github.com>
This commit is contained in:
committed by
Ralph Khreish
parent
63ef0d36ca
commit
fc57480948
@@ -992,13 +992,15 @@ describe('Dependency Manager Module', () => {
|
|||||||
// Test the specific scenario from Issue #542: subtask 2.2 depending on task 11
|
// Test the specific scenario from Issue #542: subtask 2.2 depending on task 11
|
||||||
await addDependency(TEST_TASKS_PATH, '2.2', 11, { projectRoot: '/test' });
|
await addDependency(TEST_TASKS_PATH, '2.2', 11, { projectRoot: '/test' });
|
||||||
|
|
||||||
// Verify mockWriteJSON was called (meaning the dependency was added)
|
// Verify we wrote to the test path (and not the real tasks.json)
|
||||||
expect(mockWriteJSON).toHaveBeenCalled();
|
expect(mockWriteJSON).toHaveBeenCalledWith(TEST_TASKS_PATH, expect.anything());
|
||||||
|
expect(mockWriteJSON).not.toHaveBeenCalledWith('tasks/tasks.json', expect.anything());
|
||||||
// Get the call arguments to verify the dependency was added
|
// Get the specific write call for TEST_TASKS_PATH
|
||||||
const writeCall = mockWriteJSON.mock.calls[0];
|
const writeCall = mockWriteJSON.mock.calls.find(([p]) => p === TEST_TASKS_PATH);
|
||||||
|
expect(writeCall).toBeDefined();
|
||||||
const savedData = writeCall[1];
|
const savedData = writeCall[1];
|
||||||
const subtask22 = savedData.tasks[0].subtasks[1];
|
const parent2 = savedData.tasks.find((t) => t.id === 2);
|
||||||
|
const subtask22 = parent2.subtasks.find((st) => st.id === 2);
|
||||||
|
|
||||||
// Verify the dependency was actually added to subtask 2.2
|
// Verify the dependency was actually added to subtask 2.2
|
||||||
expect(subtask22.dependencies).toContain(11);
|
expect(subtask22.dependencies).toContain(11);
|
||||||
@@ -1010,13 +1012,13 @@ describe('Dependency Manager Module', () => {
|
|||||||
// Test reverse scenario: task 11 depending on subtask 2.1
|
// Test reverse scenario: task 11 depending on subtask 2.1
|
||||||
await addDependency(TEST_TASKS_PATH, 11, '2.1', { projectRoot: '/test' });
|
await addDependency(TEST_TASKS_PATH, 11, '2.1', { projectRoot: '/test' });
|
||||||
|
|
||||||
// Verify mockWriteJSON was called
|
// Stronger assertions for writeJSON call and locating the correct task
|
||||||
expect(mockWriteJSON).toHaveBeenCalled();
|
expect(mockWriteJSON).toHaveBeenCalledWith(TEST_TASKS_PATH, expect.anything());
|
||||||
|
expect(mockWriteJSON).not.toHaveBeenCalledWith('tasks/tasks.json', expect.anything());
|
||||||
// Get the saved data and verify the dependency was added
|
const writeCall = mockWriteJSON.mock.calls.find(([p]) => p === TEST_TASKS_PATH);
|
||||||
const writeCall = mockWriteJSON.mock.calls[0];
|
expect(writeCall).toBeDefined();
|
||||||
const savedData = writeCall[1];
|
const savedData = writeCall[1];
|
||||||
const task11 = savedData.tasks[1];
|
const task11 = savedData.tasks.find((t) => t.id === 11);
|
||||||
|
|
||||||
// Verify the dependency was actually added to task 11
|
// Verify the dependency was actually added to task 11
|
||||||
expect(task11.dependencies).toContain('2.1');
|
expect(task11.dependencies).toContain('2.1');
|
||||||
@@ -1050,6 +1052,8 @@ describe('Dependency Manager Module', () => {
|
|||||||
|
|
||||||
// Verify that process.exit was called due to non-existent dependency target
|
// Verify that process.exit was called due to non-existent dependency target
|
||||||
expect(process.exit).toHaveBeenCalledWith(1);
|
expect(process.exit).toHaveBeenCalledWith(1);
|
||||||
|
// And that no writes were attempted
|
||||||
|
expect(mockWriteJSON).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user