supercode-harness 0.4.13

The optional native Supercode agent and tool harness
Documentation
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
//! Acceptance tests for TR-7 (`.volter/tracker/markdown/TR-7.md`, T20): LLM-
//! written summary placeholders over an A10 `TurnsCleared` span, gated by
//! `ReductionPolicy::summarize_cleared_turns` (default off) and driven by the
//! injectable `reduce::summarize::SpanSummarizer` side-call
//! (`reduce::prepare_cleared_turns_summary`, always run OUTSIDE
//! `project_messages` — mirrors A8's `probe_read_freshness` split).
//!
//! No test here ever performs a real network/model call: every summarizer
//! below is a small deterministic (or deliberately failing) in-process fake.
//!
//! ACs covered (dev/01-05; dev/06 is the separate archived demo artifact in
//! `reduce_summaries_demo.rs`, and the disk-reload guarantor lives in
//! `tr7_summary_guarantor.rs`):
//! - dev/01: summaries on -> banner + summary + reduction_id; summaries off
//!   (default) -> byte-identical to the pre-TR-7 deterministic stub.
//! - dev/02: invert/export purity — zero summary text, byte-exact restore,
//!   regardless of summaries on/off.
//! - dev/03: summarizer failure/empty output falls back to the deterministic
//!   stub, never blocking/failing the pass.
//! - dev/04: audit trail — model id, prompt version, summary hash recorded;
//!   `verify_log` passes (sidecar-bytes-anchored).
//! - dev/05: cost guard — a span below the floor never even calls the
//!   summarizer (tested at the boundary).

use std::sync::atomic::{AtomicUsize, Ordering};

use supercode_harness::reduce::summarize::{SpanSummarizer, PROMPT_VERSION};
use supercode_harness::reduce::{
    content_hash, export_session, invert, prepare_cleared_turns_summary, project_messages,
    verify_log, ReductionError, ReductionKind, ReductionLog, ReductionPolicy, ReductionResult,
};
use supercode_harness::session::SessionFormat;
use supercode_harness::{ChatMessage, Session};

/// A deterministic all-ASCII filler string of exactly `len` bytes.
fn filler(len: usize) -> String {
    (0..len).map(|i| (b'a' + (i % 26) as u8) as char).collect()
}

fn empty_session() -> Session {
    Session::from_claude_code_str("").unwrap()
}

/// Append `n` (user, assistant) turn pairs with enough padding that the
/// resulting cleared span comfortably clears `ReductionPolicy::default()`'s
/// cost-guard floor (400 * 4 = 1600 bytes) without needing to fiddle with
/// those knobs in every test. Deliberately duplicated from
/// `reduce_projection.rs::append_synthetic_turns` (padded) rather than
/// shared — each integration test binary stands on its own, matching this
/// crate's established convention (see e.g. `export_sidecar.rs`'s `msg_eq`).
fn append_padded_turns(session: &mut Session, n: usize) {
    let pad = filler(120);
    for i in 0..n {
        session
            .messages
            .push(ChatMessage::user(format!("user turn {i}: {pad}")));
        session.messages.push(ChatMessage::assistant(format!(
            "assistant reply {i}: {pad}"
        )));
    }
}

/// Every message's serialized wire bytes for `assert_identity`-style
/// byte-exact comparison (mirrors `reduce_projection.rs::messages_identical`,
/// duplicated for the same standalone-test-binary reason).
fn messages_identical(a: &[ChatMessage], b: &[ChatMessage]) -> bool {
    a.len() == b.len()
        && a.iter().zip(b).all(|(x, y)| {
            x.role == y.role
                && x.content == y.content
                && x.content_parts == y.content_parts
                && x.tool_call_id == y.tool_call_id
                && x.name == y.name
                && x.metadata == y.metadata
        })
}

/// A canned, deterministic summarizer: always succeeds with a fixed string.
/// Never calls out to a real model — this is exactly the "injected
/// deterministic fake" TR-7 requires every test to use instead.
struct FakeSummarizer {
    text: &'static str,
    model: &'static str,
}
impl SpanSummarizer for FakeSummarizer {
    fn summarize(&self, _span_text: &str) -> ReductionResult<String> {
        Ok(self.text.to_string())
    }
    fn model_id(&self) -> &str {
        self.model
    }
}

/// A summarizer that always errors — models a provider failure or a
/// caller-enforced timeout (dev/03's fault-injection fixture).
struct FailingSummarizer;
impl SpanSummarizer for FailingSummarizer {
    fn summarize(&self, _span_text: &str) -> ReductionResult<String> {
        Err(ReductionError::new("simulated summarization timeout"))
    }
    fn model_id(&self) -> &str {
        "unreachable-model"
    }
}

/// A summarizer that always succeeds but counts how many times it was
/// actually invoked — dev/05 needs to prove the cost-guard floor skips the
/// side-call ENTIRELY for a too-small span, not merely discards its result.
struct CountingSummarizer {
    calls: AtomicUsize,
    text: &'static str,
}
impl SpanSummarizer for CountingSummarizer {
    fn summarize(&self, _span_text: &str) -> ReductionResult<String> {
        self.calls.fetch_add(1, Ordering::SeqCst);
        Ok(self.text.to_string())
    }
    fn model_id(&self) -> &str {
        "counting-model"
    }
}

/// Extract the singleton `TurnsCleared` reduction's `(first, last)` from a
/// log, panicking with a useful message if it isn't there.
fn find_cleared(log: &ReductionLog) -> (usize, usize) {
    log.reductions
        .iter()
        .find_map(|r| match r.kind {
            ReductionKind::TurnsCleared { first, last, .. } => Some((first, last)),
            _ => None,
        })
        .expect("expected exactly one TurnsCleared reduction")
}

// ---- dev/01: off by default is byte-identical; on renders the summary -----

#[test]
fn dev01_summaries_off_by_default_matches_the_pre_tr7_deterministic_stub() {
    let mut session = empty_session();
    append_padded_turns(&mut session, 10); // 20 messages
    let msgs = session.messages.clone();

    // `ReductionPolicy::default()` leaves `summarize_cleared_turns` off —
    // this IS the "default" dev/01 cares about, not a hand-picked value.
    let policy = ReductionPolicy {
        clear_turns_older_than: Some(8),
        ..ReductionPolicy::default()
    };
    assert!(
        !policy.summarize_cleared_turns,
        "summaries must default to OFF"
    );
    let prior = ReductionLog::default();

    let (view, log) = project_messages(&msgs, &policy, &prior);
    let (first, last) = find_cleared(&log);
    let r = log
        .reductions
        .iter()
        .find(|r| matches!(r.kind, ReductionKind::TurnsCleared { .. }))
        .unwrap();

    // The exact pre-TR-7 grammar: `[sc-reduced turns-cleared <id>: turns
    // <first>..<last+1> cleared (<n> messages: ...) — full turns in session
    // sidecar]` — the deterministic stub, unchanged. Pin the structural
    // pieces (never a hand-computed byte count, which is a derived,
    // formatting-sensitive figure) so a future change to TR-7's summarized
    // branch can never silently alter the off-by-default path.
    assert_eq!(first, 0);
    assert_eq!(last, 15);
    assert!(
        r.placeholder.starts_with(&format!(
            "[sc-reduced turns-cleared {}: turns {first}..{} cleared (16 messages: 8 user, 8 \
             assistant, 0 tool; ",
            r.id,
            last + 1,
        )),
        "{}",
        r.placeholder
    );
    assert!(
        !r.placeholder.contains("sc-summary"),
        "off by default must never carry a summary banner: {}",
        r.placeholder
    );
    assert!(
        r.placeholder.starts_with("[sc-reduced turns-cleared "),
        "{}",
        r.placeholder
    );
    assert!(
        r.placeholder.contains("full turns in session sidecar"),
        "{}",
        r.placeholder
    );
    assert!(matches!(
        r.kind,
        ReductionKind::TurnsCleared { summary: None, .. }
    ));

    // Defense in depth: even if a caller mistakenly populated
    // `cleared_turns_summary` while `summarize_cleared_turns` stays off, the
    // rendered placeholder must be UNCHANGED — the policy gate alone decides
    // this, not merely "was a prepared summary present."
    let mut policy_with_stray_data = policy.clone();
    let fake = FakeSummarizer {
        text: "should never be used",
        model: "never-called-model",
    };
    policy_with_stray_data.cleared_turns_summary = prepare_cleared_turns_summary(
        &msgs,
        &{
            let mut p = policy.clone();
            p.summarize_cleared_turns = true;
            p
        },
        &prior,
        &fake,
    );
    let (_, log_stray) = project_messages(&msgs, &policy_with_stray_data, &prior);
    let r_stray = log_stray
        .reductions
        .iter()
        .find(|r| matches!(r.kind, ReductionKind::TurnsCleared { .. }))
        .unwrap();
    assert_eq!(
        r_stray.placeholder, r.placeholder,
        "policy gate off must win even with a prepared summary sitting in the policy"
    );

    let _ = view;
}

#[test]
fn dev01_summaries_on_projects_banner_llm_summary_and_reduction_id() {
    let mut session = empty_session();
    append_padded_turns(&mut session, 10);
    let msgs = session.messages.clone();

    let mut policy = ReductionPolicy {
        clear_turns_older_than: Some(8),
        summarize_cleared_turns: true,
        ..ReductionPolicy::default()
    };
    let prior = ReductionLog::default();

    let fake = FakeSummarizer {
        text: "The user asked about widgets; the assistant explained the API.",
        model: "fake-summary-model-v1",
    };
    let prepared = prepare_cleared_turns_summary(&msgs, &policy, &prior, &fake)
        .expect("a large-enough span above the cost floor must be prepared");
    policy.cleared_turns_summary = Some(prepared);

    let (view, log) = project_messages(&msgs, &policy, &prior);
    let (first, last) = find_cleared(&log);
    let r = log
        .reductions
        .iter()
        .find(|r| matches!(r.kind, ReductionKind::TurnsCleared { .. }))
        .unwrap();

    assert!(
        r.placeholder.contains("widgets"),
        "the LLM summary text must appear in the placeholder: {}",
        r.placeholder
    );
    assert!(
        r.placeholder.contains(&format!("sc-summary of {}", r.id)),
        "{}",
        r.placeholder
    );
    assert!(
        r.placeholder
            .contains(&format!("expand_reduction(\"{}\")", r.id)),
        "the honesty banner must spell out the exact escape hatch: {}",
        r.placeholder
    );
    assert!(
        r.placeholder.contains("original 16 messages in sidecar"),
        "{}",
        r.placeholder
    );
    assert!(matches!(
        r.kind,
        ReductionKind::TurnsCleared {
            summary: Some(_),
            ..
        }
    ));

    let placeholder_msg = &view[first];
    assert_eq!(
        supercode_harness::reduce::reduction_id(placeholder_msg),
        Some(r.id.as_str())
    );
    let _ = last;
}

// ---- dev/02: invert/export purity, both on and off -------------------------

#[test]
fn dev02_invert_restores_original_byte_exact_and_never_carries_summary_text() {
    for summaries_on in [false, true] {
        let mut session = empty_session();
        append_padded_turns(&mut session, 10);
        let msgs = session.messages.clone();

        let mut policy = ReductionPolicy {
            clear_turns_older_than: Some(8),
            summarize_cleared_turns: summaries_on,
            ..ReductionPolicy::default()
        };
        let prior = ReductionLog::default();
        if summaries_on {
            let fake = FakeSummarizer {
                text: "UNIQUE-SUMMARY-MARKER-9f3c should never survive invert or export",
                model: "fake-model",
            };
            policy.cleared_turns_summary =
                prepare_cleared_turns_summary(&msgs, &policy, &prior, &fake);
            assert!(policy.cleared_turns_summary.is_some());
        }

        let (view, log) = project_messages(&msgs, &policy, &prior);
        if summaries_on {
            let r = log
                .reductions
                .iter()
                .find(|r| matches!(r.kind, ReductionKind::TurnsCleared { .. }))
                .unwrap();
            assert!(r.placeholder.contains("UNIQUE-SUMMARY-MARKER-9f3c"));
        }

        // B10 conformance: verify_log is anchored on sidecar bytes alone —
        // passes identically whether summaries are on or off.
        verify_log(&log, &session)
            .unwrap_or_else(|e| panic!("verify_log must pass (summaries_on={summaries_on}): {e}"));

        let inverted = invert(&view, &log, &session)
            .unwrap_or_else(|e| panic!("invert must pass (summaries_on={summaries_on}): {e}"));
        assert!(
            messages_identical(&inverted, &msgs),
            "invert must restore the original byte-exact (summaries_on={summaries_on})"
        );
        for m in &inverted {
            let content = m.content.as_deref().unwrap_or("");
            assert!(
                !content.contains("UNIQUE-SUMMARY-MARKER-9f3c"),
                "invert leaked summary text into a restored original (summaries_on={summaries_on})"
            );
        }

        // A11 export purity: export_session reads ONLY the sidecar, never
        // the view/log — so the summary marker can never appear in it,
        // regardless of whether a summary was ever minted for this session.
        let sidecar_jsonl = empty_session().to_native_jsonl_v2(&msgs);
        let exported = export_session(&sidecar_jsonl, SessionFormat::ClaudeCode)
            .unwrap_or_else(|e| panic!("export_session failed (summaries_on={summaries_on}): {e}"));
        assert!(
            !exported.contains("UNIQUE-SUMMARY-MARKER-9f3c"),
            "export leaked summary text (summaries_on={summaries_on}):\n{exported}"
        );
        assert!(!exported.contains(supercode_harness::reduce::REDUCTION_SENTINEL));
    }
}

// ---- dev/03: failure/empty fallback ----------------------------------------

#[test]
fn dev03_erroring_summarizer_falls_back_to_the_deterministic_stub() {
    let mut session = empty_session();
    append_padded_turns(&mut session, 10);
    let msgs = session.messages.clone();

    let mut policy = ReductionPolicy {
        clear_turns_older_than: Some(8),
        summarize_cleared_turns: true,
        ..ReductionPolicy::default()
    };
    let prior = ReductionLog::default();

    // The side-call itself must never panic or propagate an error: it simply
    // yields `None`.
    let prepared = prepare_cleared_turns_summary(&msgs, &policy, &prior, &FailingSummarizer);
    assert!(
        prepared.is_none(),
        "an erroring summarizer must never be treated as prepared"
    );
    policy.cleared_turns_summary = prepared;

    let (_, log) = project_messages(&msgs, &policy, &prior);
    let r = log
        .reductions
        .iter()
        .find(|r| matches!(r.kind, ReductionKind::TurnsCleared { .. }))
        .unwrap();
    assert!(
        !r.placeholder.contains("sc-summary"),
        "failure must fall back to the deterministic stub, never a partial/blocked one: {}",
        r.placeholder
    );
    assert!(matches!(
        r.kind,
        ReductionKind::TurnsCleared { summary: None, .. }
    ));

    // Same fallback for a summarizer that "succeeds" with nothing usable.
    struct BlankSummarizer;
    impl SpanSummarizer for BlankSummarizer {
        fn summarize(&self, _: &str) -> ReductionResult<String> {
            Ok("   \n  ".to_string())
        }
        fn model_id(&self) -> &str {
            "blank-model"
        }
    }
    let prepared_blank = prepare_cleared_turns_summary(&msgs, &policy, &prior, &BlankSummarizer);
    assert!(
        prepared_blank.is_none(),
        "a blank/whitespace-only summary must also fall back to the deterministic stub"
    );
}

// ---- dev/04: audit trail ----------------------------------------------------

#[test]
fn dev04_audit_trail_records_model_id_prompt_version_and_summary_hash() {
    let mut session = empty_session();
    append_padded_turns(&mut session, 10);
    let msgs = session.messages.clone();

    let mut policy = ReductionPolicy {
        clear_turns_older_than: Some(8),
        summarize_cleared_turns: true,
        ..ReductionPolicy::default()
    };
    let prior = ReductionLog::default();
    let fake = FakeSummarizer {
        text: "audit-trail summary text",
        model: "audit-model-42",
    };
    policy.cleared_turns_summary = prepare_cleared_turns_summary(&msgs, &policy, &prior, &fake);
    assert!(policy.cleared_turns_summary.is_some());

    let (_, log) = project_messages(&msgs, &policy, &prior);
    let r = log
        .reductions
        .iter()
        .find(|r| matches!(r.kind, ReductionKind::TurnsCleared { .. }))
        .unwrap();
    let audit = match &r.kind {
        ReductionKind::TurnsCleared { summary, .. } => summary
            .as_ref()
            .expect("a summarized span must carry audit metadata"),
        _ => unreachable!(),
    };
    assert_eq!(audit.model_id, "audit-model-42");
    assert_eq!(audit.prompt_version, PROMPT_VERSION);
    assert_eq!(
        audit.summary_hash,
        content_hash("audit-trail summary text".as_bytes()),
        "summary_hash must hash the summarizer's own text, independent of the placeholder's \
         surrounding banner/id punctuation"
    );

    // Persisted-log shape: this all rides `Reduction`/`ReductionLog`'s normal
    // `Serialize`, so it's already covered by the sidecar-family round trip
    // elsewhere (`sidecar_family_reduction_resolve.rs`) — reconfirm here that
    // a log carrying this field still round-trips through JSON verbatim.
    let json = serde_json::to_string(&log).unwrap();
    let reloaded: ReductionLog = serde_json::from_str(&json).unwrap();
    assert_eq!(reloaded, log);

    verify_log(&log, &session).expect("verify_log must pass — anchored on sidecar bytes only");
}

// ---- dev/05: cost guard floor -----------------------------------------------

#[test]
fn dev05_spans_at_or_below_the_floor_are_never_summarized_no_side_call_at_all() {
    // A small session whose cleared span is intentionally tiny, with a
    // policy whose floor is set explicitly so the boundary is exact rather
    // than dependent on serialization-format incidentals.
    let mut session = empty_session();
    // 10 pairs -> 20 messages, threshold 8 -> clears messages [0..=15]
    // (16 messages), same shape as every other test above.
    append_padded_turns(&mut session, 10);
    let msgs = session.messages.clone();

    let prior = ReductionLog::default();

    // Point 1: an unreachably high floor -> even a large span must be
    // skipped, and the summarizer must NEVER be called.
    let counting = CountingSummarizer {
        calls: AtomicUsize::new(0),
        text: "should not be produced",
    };
    let policy_above_floor = ReductionPolicy {
        clear_turns_older_than: Some(8),
        summarize_cleared_turns: true,
        expected_summary_bytes: 1_000_000,
        summary_cost_floor_multiple: 1,
        ..ReductionPolicy::default()
    };
    let prepared = prepare_cleared_turns_summary(&msgs, &policy_above_floor, &prior, &counting);
    assert!(
        prepared.is_none(),
        "a span below the cost-guard floor must never be prepared"
    );
    assert_eq!(
        counting.calls.load(Ordering::SeqCst),
        0,
        "the summarizer must never be CALLED for a below-floor span — not just have its result discarded"
    );

    // Point 2: a floor of 0 (trivially satisfied by any non-empty span) ->
    // the same span (same messages, same threshold) is now prepared, and the
    // summarizer WAS called exactly once.
    let counting2 = CountingSummarizer {
        calls: AtomicUsize::new(0),
        text: "now above the floor",
    };
    let policy_below_floor = ReductionPolicy {
        clear_turns_older_than: Some(8),
        summarize_cleared_turns: true,
        expected_summary_bytes: 1,
        summary_cost_floor_multiple: 1,
        ..ReductionPolicy::default()
    };
    let prepared2 = prepare_cleared_turns_summary(&msgs, &policy_below_floor, &prior, &counting2);
    assert!(
        prepared2.is_some(),
        "the identical span must be prepared once it clears the floor"
    );
    assert_eq!(counting2.calls.load(Ordering::SeqCst), 1);

    // Exact boundary: floor == range_bytes must skip (strictly-greater-than
    // required, never greater-or-equal) — derive the true range_bytes first
    // via a policy definitely below it, then pin the boundary exactly.
    let probe = CountingSummarizer {
        calls: AtomicUsize::new(0),
        text: "probe",
    };
    let policy_probe = ReductionPolicy {
        clear_turns_older_than: Some(8),
        summarize_cleared_turns: true,
        expected_summary_bytes: 1,
        summary_cost_floor_multiple: 1,
        ..ReductionPolicy::default()
    };
    let _ = prepare_cleared_turns_summary(&msgs, &policy_probe, &prior, &probe);
    // Reconstruct the exact byte figure `hash_turns_range` would report,
    // through the one place it's observable on the public surface: the
    // deterministic stub's own summary clause (`; <N>B) — full turns`).
    let policy_off = ReductionPolicy {
        clear_turns_older_than: Some(8),
        ..ReductionPolicy::default()
    };
    let (_, log_off) = project_messages(&msgs, &policy_off, &prior);
    let r = log_off
        .reductions
        .iter()
        .find(|r| matches!(r.kind, ReductionKind::TurnsCleared { .. }))
        .unwrap();
    // The stub's byte figure is comma-grouped (`format_commas`, e.g.
    // `3,296B)`) — strip the grouping commas before parsing.
    let n_bytes: usize = r
        .placeholder
        .split(';')
        .nth(1)
        .and_then(|s| s.split("B)").next())
        .map(|s| s.trim().replace(',', ""))
        .and_then(|s| s.parse().ok())
        .expect("deterministic stub must carry a parseable `; <N>B)` clause");

    let counting_at_floor = CountingSummarizer {
        calls: AtomicUsize::new(0),
        text: "at floor",
    };
    let policy_at_floor = ReductionPolicy {
        clear_turns_older_than: Some(8),
        summarize_cleared_turns: true,
        expected_summary_bytes: n_bytes,
        summary_cost_floor_multiple: 1, // floor == n_bytes exactly
        ..ReductionPolicy::default()
    };
    let prepared_at_floor =
        prepare_cleared_turns_summary(&msgs, &policy_at_floor, &prior, &counting_at_floor);
    assert!(
        prepared_at_floor.is_none(),
        "a span exactly AT the floor (not strictly above) must still be skipped"
    );
    assert_eq!(counting_at_floor.calls.load(Ordering::SeqCst), 0);

    let counting_above_floor = CountingSummarizer {
        calls: AtomicUsize::new(0),
        text: "one byte above the floor",
    };
    let policy_one_above = ReductionPolicy {
        clear_turns_older_than: Some(8),
        summarize_cleared_turns: true,
        expected_summary_bytes: n_bytes - 1,
        summary_cost_floor_multiple: 1, // floor == n_bytes - 1, span == n_bytes -> above
        ..ReductionPolicy::default()
    };
    let prepared_one_above =
        prepare_cleared_turns_summary(&msgs, &policy_one_above, &prior, &counting_above_floor);
    assert!(
        prepared_one_above.is_some(),
        "a span one byte above the floor must be summarized"
    );
    assert_eq!(counting_above_floor.calls.load(Ordering::SeqCst), 1);
}