Whether `change`'s own FileOps key `leaf`'s id when applied (review D2: a registered NodeId is not proof of a writer — the leaf must come from the writer's own per-apply counter over the Insert/Modify content it recorded for this trunk and branch). The replay mirrors the apply's leaf-id contract exactly: one counter per change spanning every file entry in order, advanced by every recorded leaf op.
(
change: &Change,
trunk: atomic_core::crdt::TrunkId,
branch: atomic_core::crdt::BranchId,
leaf: atomic_core::crdt::LeafId,
)
| 1248 | /// leaf-id contract exactly: one counter per change spanning every file |
| 1249 | /// entry in order, advanced by every recorded leaf op. |
| 1250 | fn change_wrote_leaf( |
| 1251 | change: &Change, |
| 1252 | trunk: atomic_core::crdt::TrunkId, |
| 1253 | branch: atomic_core::crdt::BranchId, |
| 1254 | leaf: atomic_core::crdt::LeafId, |
| 1255 | ) -> bool { |
| 1256 | let owner = leaf.change_id(); |
| 1257 | let mut counter = 0u32; |
| 1258 | for ops in change.file_ops() { |
| 1259 | let is_target = file_ops_target_trunk(ops, owner, trunk); |
| 1260 | for line_op in ops.line_ops() { |
| 1261 | let raw_branch = line_op.branch_id(); |
| 1262 | let resolved = if raw_branch.change_id().is_root() { |
| 1263 | atomic_core::crdt::BranchId::new(owner, raw_branch.branch_idx()) |
| 1264 | } else { |
| 1265 | raw_branch |
| 1266 | }; |
| 1267 | let content: &[atomic_core::crdt::LeafOp] = match line_op.operation() { |
| 1268 | atomic_core::crdt::BranchOp::Insert { content, .. } => content, |
| 1269 | atomic_core::crdt::BranchOp::Modify { new_content, .. } => new_content, |
| 1270 | _ => continue, |
| 1271 | }; |
| 1272 | for leaf_op in content { |
| 1273 | let is_writer_leaf = matches!(leaf_op, atomic_core::crdt::LeafOp::Insert { .. }) |
| 1274 | && is_target |
| 1275 | && resolved == branch |
| 1276 | && atomic_core::crdt::LeafId::new(owner, counter) == leaf; |
| 1277 | if is_writer_leaf { |
| 1278 | return true; |
| 1279 | } |
| 1280 | counter += 1; |
| 1281 | } |
| 1282 | } |
| 1283 | } |
| 1284 | false |
| 1285 | } |
| 1286 | |
| 1287 | impl Repository { |
| 1288 | /// Ensure every named change (with its dependency closure) is a member |
no test coverage detected