fix(team): preserve cached task nested fields

This commit is contained in:
777genius 2026-05-31 18:30:14 +03:00
parent b9cfdb9323
commit 961691f477
2 changed files with 17 additions and 4 deletions

View file

@ -774,9 +774,9 @@ function restorePersistentTaskProjectionShape(
owner: typeof task.owner === 'string' ? task.owner : undefined, owner: typeof task.owner === 'string' ? task.owner : undefined,
createdBy: typeof task.createdBy === 'string' ? task.createdBy : undefined, createdBy: typeof task.createdBy === 'string' ? task.createdBy : undefined,
status, status,
workIntervals: Array.isArray(task.workIntervals) ? task.workIntervals : undefined, workIntervals: normalizeWorkIntervals(task),
reviewIntervals: Array.isArray(task.reviewIntervals) ? task.reviewIntervals : undefined, reviewIntervals: normalizeReviewIntervals(task),
historyEvents: Array.isArray(task.historyEvents) ? task.historyEvents : undefined, historyEvents: normalizeHistoryEvents(task),
blocks: Array.isArray(task.blocks) ? task.blocks : undefined, blocks: Array.isArray(task.blocks) ? task.blocks : undefined,
blockedBy: Array.isArray(task.blockedBy) ? task.blockedBy : undefined, blockedBy: Array.isArray(task.blockedBy) ? task.blockedBy : undefined,
related: Array.isArray(task.related) related: Array.isArray(task.related)
@ -785,7 +785,7 @@ function restorePersistentTaskProjectionShape(
createdAt: typeof task.createdAt === 'string' ? task.createdAt : undefined, createdAt: typeof task.createdAt === 'string' ? task.createdAt : undefined,
updatedAt: typeof task.updatedAt === 'string' ? task.updatedAt : undefined, updatedAt: typeof task.updatedAt === 'string' ? task.updatedAt : undefined,
projectPath: typeof task.projectPath === 'string' ? task.projectPath : undefined, projectPath: typeof task.projectPath === 'string' ? task.projectPath : undefined,
comments: Array.isArray(task.comments) ? task.comments : undefined, comments: normalizeComments(task),
needsClarification: needsClarification:
task.needsClarification === 'lead' || task.needsClarification === 'user' task.needsClarification === 'lead' || task.needsClarification === 'user'
? task.needsClarification ? task.needsClarification

View file

@ -593,15 +593,27 @@ describe('team-fs-worker integration', () => {
subject: 'Persisted subject', subject: 'Persisted subject',
status: 'pending', status: 'pending',
createdAt: '2026-05-02T12:00:00.000Z', createdAt: '2026-05-02T12:00:00.000Z',
workIntervals: [{ startedAt: '2026-05-02T12:00:00.000Z' }],
reviewIntervals: [{ reviewer: 'alice', startedAt: '2026-05-02T12:30:00.000Z' }],
comments: [
{
id: 'comment-1',
author: 'alice',
text: 'Looks good',
createdAt: '2026-05-02T12:45:00.000Z',
},
],
}), }),
'utf8' 'utf8'
); );
const firstWorker = createWorker(workerPath); const firstWorker = createWorker(workerPath);
let firstTasks: unknown[] = [];
let firstTaskKeys: string[] = []; let firstTaskKeys: string[] = [];
try { try {
const first = await callGetAllTasks(firstWorker, tasksBase, projectionCacheBase); const first = await callGetAllTasks(firstWorker, tasksBase, projectionCacheBase);
expect(first.tasks[0]).toMatchObject({ teamName, subject: 'Persisted subject' }); expect(first.tasks[0]).toMatchObject({ teamName, subject: 'Persisted subject' });
firstTasks = first.tasks;
firstTaskKeys = Object.keys(first.tasks[0] as Record<string, unknown>); firstTaskKeys = Object.keys(first.tasks[0] as Record<string, unknown>);
expect(first.diag?.cacheMisses).toBe(1); expect(first.diag?.cacheMisses).toBe(1);
expect(first.diag?.persistentCacheWrites).toBe(1); expect(first.diag?.persistentCacheWrites).toBe(1);
@ -616,6 +628,7 @@ describe('team-fs-worker integration', () => {
expect(Object.keys(second.tasks[0] as Record<string, unknown>)).toEqual( expect(Object.keys(second.tasks[0] as Record<string, unknown>)).toEqual(
firstTaskKeys firstTaskKeys
); );
expect(second.tasks).toEqual(firstTasks);
expect(second.diag?.cacheHits).toBe(0); expect(second.diag?.cacheHits).toBe(0);
expect(second.diag?.cacheMisses).toBe(0); expect(second.diag?.cacheMisses).toBe(0);
expect(second.diag?.persistentCacheLoads).toBe(1); expect(second.diag?.persistentCacheLoads).toBe(1);