1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
//! Deterministic sealed-shadow boundary examples.
use super::*;
#[test]
fn test_the_shadow_restores_the_swept_anchor_bucket_order() {
// S213 falsifier one: two records sharing a swept `After` bucket reverse
// under every anchor-identity map. The shadow judges them on the old
// shoulder, so their mutual order survives in both arrival orders (the
// second order takes the pure fast path, the first forces a rebuild).
let (state, movements) = anchor_case(false, [2, 1]);
for window in [
[Delta::Move(movements[0]), Delta::Move(movements[1])],
[Delta::Move(movements[1]), Delta::Move(movements[0])],
] {
let result = cross_boundary_shadow(&state, &[], &window);
assert_eq!(result.fold_then_refound, ['a', 'x', 'y', 'b']);
assert_eq!(result.shadow_projection, ['a', 'x', 'y', 'b']);
assert!(result.commutes());
}
}
#[test]
fn test_the_shadow_preserves_the_old_world_move_verdict() {
// S213 falsifier two: re-chaining turns a lawful in-flight move into a
// refused cycle-former. The shadow judges it against the old root-sibling
// relation, where it applies, and the outcome crosses.
let mut state = State::new();
let a = Dot::old(1);
let b = Dot::old(2);
state.insert(
a,
Node {
label: 'a',
locus: Locus {
anchor: Anchor::Origin,
rank: 2,
},
visible: true,
},
);
state.insert(
b,
Node {
label: 'b',
locus: Locus {
anchor: Anchor::Origin,
rank: 1,
},
visible: true,
},
);
let movement = Movement {
testimony: Testimony(1),
target: a,
to: Locus {
anchor: Anchor::After(b),
rank: 1,
},
};
let result = cross_boundary_shadow(&state, &[], &[Delta::Move(movement)]);
assert_eq!(
result.shadow_decisions,
[Decision {
testimony: Testimony(1),
verdict: Verdict::Applied,
}]
);
assert_eq!(result.fold_then_refound, ['b', 'a']);
assert_eq!(result.shadow_projection, ['b', 'a']);
assert!(result.commutes());
}
#[test]
fn test_the_shadow_carries_equal_rank_rechaining() {
// The equal-rank arm that defeated both S213 supports: the shadow keeps
// the old sibling context, so the dot tie-break resolves identically on
// both squares.
let (state, movements) = anchor_case(true, [0, 0]);
let window = [Delta::Move(movements[0]), Delta::Move(movements[1])];
let result = cross_boundary_shadow(&state, &[], &window);
assert_eq!(result.fold_then_refound, ['a', 't', 'x', 'y', 'b']);
assert_eq!(result.shadow_projection, ['a', 't', 'x', 'y', 'b']);
assert!(result.commutes());
}
#[test]
fn test_a_window_arrival_re_decides_a_record_move() {
// Why the shadow carries the movement record and not just the effective
// state: the replay is order-fixed over the whole record, so a window
// move keyed below a record move re-decides it. Here the record's
// "a after b" stands alone at declaration, then the window's lower-keyed
// "b after a" replays first and turns the record move into the
// cycle-former, retroactively and deterministically.
let mut state = State::new();
for (index, label, rank) in [(1, 'a', 3), (2, 'b', 2), (3, 'c', 1)] {
state.insert(
Dot::old(index),
Node {
label,
locus: Locus {
anchor: Anchor::Origin,
rank,
},
visible: true,
},
);
}
let record = [Movement {
testimony: Testimony(2),
target: Dot::old(1),
to: Locus {
anchor: Anchor::After(Dot::old(2)),
rank: 2,
},
}];
let window_move = Movement {
testimony: Testimony(1),
target: Dot::old(2),
to: Locus {
anchor: Anchor::After(Dot::old(1)),
rank: 1,
},
};
let mut shadow = Shadow::declare(&state, &record);
assert_eq!(
shadow.decisions,
[Decision {
testimony: Testimony(2),
verdict: Verdict::Applied,
}]
);
assert_eq!(shadow.projected_reading(), ['b', 'a', 'c']);
shadow.deliver(Delta::Move(window_move));
assert_eq!(
shadow.decisions,
[
Decision {
testimony: Testimony(1),
verdict: Verdict::Applied,
},
Decision {
testimony: Testimony(2),
verdict: Verdict::RefusedCycle,
},
]
);
assert_eq!(shadow.projected_reading(), ['a', 'b', 'c']);
let result = cross_boundary_shadow(&state, &record, &[Delta::Move(window_move)]);
assert!(result.commutes());
}
#[test]
fn test_an_unwitnessed_cut_lets_a_delayed_tombstone_shift_the_identity_plane() {
// The R1 seal falsifier: admit a declaration whose cut the watermark
// never witnessed, and a delayed at-or-below-cut tombstone from a
// non-contributing replica splits the fold. The hasty member and the
// informed member compact different live sets, so their maps diverge;
// delivering the tombstone later converges the reading but can never
// converge the identities. With identical sealed strata the fold is a
// pure function and the map cannot shift, which is what the refusal
// `EpochUnwitnessed` protects.
let mut stratum = State::new();
for (index, label, rank) in [(1, 'a', 3), (2, 'b', 2), (3, 'c', 1)] {
stratum.insert(
Dot::old(index),
Node {
label,
locus: Locus {
anchor: Anchor::Origin,
rank,
},
visible: true,
},
);
}
let delayed = Delta::Delete {
target: Dot::old(2),
};
let mut informed_stratum = stratum.clone();
informed_stratum
.nodes
.get_mut(&Dot::old(2))
.expect("the tombstone target is woven")
.visible = false;
let mut hasty = Shadow::declare(&stratum, &[]);
let informed = Shadow::declare(&informed_stratum, &[]);
assert_ne!(hasty.map, informed.map);
assert_ne!(hasty.projected_reading(), informed.projected_reading());
hasty.deliver(delayed);
assert_eq!(hasty.projected_reading(), informed.projected_reading());
assert_ne!(
hasty.projected_identities(),
informed.projected_identities()
);
let twin = Shadow::declare(&informed_stratum, &[]);
assert_eq!(informed.map, twin.map);
assert_eq!(informed.projected_identities(), twin.projected_identities());
}
#[test]
fn test_window_born_chains_survive_the_affine_shift() {
// One live element and one tombstone at the cut: ceiling 2, one
// compacted slot. Three consecutive window-born dots translate to three
// consecutive new indices above the compacted range, and the map frozen
// at declaration never shifts under the arrivals.
let mut state = State::new();
state.insert(
Dot::old(1),
Node {
label: 'a',
locus: Locus {
anchor: Anchor::Origin,
rank: 1,
},
visible: true,
},
);
state.insert(
Dot::old(2),
Node {
label: 't',
locus: Locus {
anchor: Anchor::After(Dot::old(1)),
rank: 1,
},
visible: false,
},
);
let mut shadow = Shadow::declare(&state, &[]);
let frozen = shadow.map.clone();
let mut anchor = Dot::old(2);
for (index, label) in [(3, 'x'), (4, 'y'), (5, 'z')] {
shadow.deliver(Delta::Birth {
dot: Dot::old(index),
label,
locus: Locus {
anchor: Anchor::After(anchor),
rank: 1,
},
});
anchor = Dot::old(index);
}
assert_eq!(shadow.map, frozen);
let identities = shadow.projected_identities();
let translated: Vec<Dot> = identities.iter().map(|(dot, _)| *dot).collect();
assert_eq!(
translated,
[
Dot {
epoch: Epoch(1),
index: 1,
},
Dot {
epoch: Epoch(1),
index: 2,
},
Dot {
epoch: Epoch(1),
index: 3,
},
Dot {
epoch: Epoch(1),
index: 4,
},
]
);
assert_eq!(
identities
.iter()
.map(|(_, label)| *label)
.collect::<Vec<_>>(),
['a', 'x', 'y', 'z']
);
}