projectRoundContext function
Joins workBead to its live session among stateBeads.
The live session is the one whose work_bead is EXACTLY the bead id.
Retired rounds carry <id>#r<N> and voided ones <id>#void-<session>
(grid_engine's src/domain/rework.dart), so both drop out of this join
by construction — the same predicate StationCommandHandler._rework uses.
The round number is maxReworkRound(...) + 1, rework.dart's own stated
rule ("The next round is maxReworkRound(...) + 1"), not a second
definition of it.
Implementation
RoundContext projectRoundContext({
required Bead workBead,
required Iterable<Bead> stateBeads,
}) {
final validationPlan = beadMetadataText(
workBead,
WorkBeadKeys.validationPlan,
);
final sessions = stateBeads
.where((bead) => bead.issueType == GridIssueTypes.session)
.toList(growable: false);
final keys = <String>[
for (final session in sessions)
if (beadMetadataText(session, SessionBeadKeys.workBead)
case final String key)
key,
];
final live = sessions
.where(
(session) =>
beadMetadataText(session, SessionBeadKeys.workBead) == workBead.id,
)
.toList(growable: false);
if (live.length != 1) {
return RoundContext.noRound(
beadId: workBead.id,
title: workBead.title,
status: workBead.status.wire,
validationPlan: validationPlan,
reason: live.isEmpty
? 'No session is linked to "${workBead.id}".'
: '${live.length} sessions are linked to "${workBead.id}".',
);
}
return RoundContext.round(
beadId: workBead.id,
title: workBead.title,
status: workBead.status.wire,
validationPlan: validationPlan,
sessionId: live.single.id,
round: maxReworkRound(workBead.id, keys) + 1,
);
}