fix(programmer): reassignment while paused must not open new segment

Capture whether segment was running before reassignment, and only reopen
for new assignee if it was. A paused task that gets reassigned should not
start accruing time for the new assignee until explicitly resumed.

Also add test: reassignment while paused does not open segment.

Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
2026-09-27 20:57:55 +08:00
parent 6beb92d3c6
commit f071cc722d
2 changed files with 35 additions and 2 deletions
+5 -1
View File
@@ -88,6 +88,7 @@ List<WorkedInterval> workedIntervals({
break;
case 'reassigned':
final wasRunning = segmentStart != null;
if (segmentStart != null) {
// Close segment for old assignee
intervals.add((
@@ -95,12 +96,15 @@ List<WorkedInterval> workedIntervals({
start: segmentStart,
end: log.createdAt,
));
segmentStart = null;
}
// Update assignee and reopen segment
// Update assignee and reopen segment only if it was running
if (log.meta?['assignee_id'] != null) {
currentAssignee = log.meta!['assignee_id'] as String;
if (wasRunning) {
segmentStart = log.createdAt;
}
}
break;
}
}
+29
View File
@@ -235,4 +235,33 @@ void main() {
final result = dailySecondsByAssignee(task: task, logs: logs, now: now);
expect(result['a']![DateTime.utc(2026, 9, 27)], 3600); // not 6 hours
});
test('reassignment while paused does not open a new segment for the new assignee', () {
// task: started 09:00, paused 10:00, reassigned {assignee_id:'b'} 11:00, completed 12:00 (all Sep 27)
// expected: a -> 3600s (09-10), b -> 0 (no interval opened after paused reassignment)
final task = _task(
status: ProgrammerTaskStatus.completed,
creatorId: 'a',
assigneeId: 'b',
startedAt: AppTime.fromComponents(year: 2026, month: 9, day: 27, hour: 9),
completedAt:
AppTime.fromComponents(year: 2026, month: 9, day: 27, hour: 12),
);
final logs = [
_ev('started', 27, 9),
_ev('paused', 27, 10),
_ev('reassigned', 27, 11, 0, {'assignee_id': 'b'}),
_ev('completed', 27, 12),
];
final now =
AppTime.fromComponents(year: 2026, month: 9, day: 27, hour: 20);
final result = dailySecondsByAssignee(task: task, logs: logs, now: now);
expect(result['a']![DateTime.utc(2026, 9, 27)], 3600); // a worked 09-10
// b should have no time, or null entry
expect(
result['b']?[DateTime.utc(2026, 9, 27)] ?? 0,
0,
);
});
}