claude-scriptorium 0.1.3

Render Claude Code sessions as self-contained HTML
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
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
use std::path::Path;

use claude_scriptorium::{
    render::{Colophon, Scribe},
    transcript::{Content, Folio, Role},
};
use comrak::plugins::syntect::{SyntectAdapter, SyntectAdapterBuilder};
use jiff::{Timestamp, tz::TimeZone};

fn fixture() -> Folio {
    Folio::read(Path::new("tests/fixtures/session.jsonl")).expect("fixture parses")
}

fn highlighter() -> SyntectAdapter {
    SyntectAdapterBuilder::new()
        .css_with_class_prefix("ink-")
        .build()
}

fn render(folio: &Folio, highlighter: &SyntectAdapter) -> String {
    let scribe = Scribe::new(highlighter, TimeZone::UTC);
    let colophon = Colophon {
        generated: "2026-03-12T09:15:00Z".parse::<Timestamp>().unwrap(),
        tool: "claude-scriptorium",
        version: "0.1.0",
        home: "https://example.invalid/scriptorium",
    };
    scribe.folio(folio, &colophon).into_string()
}

#[test]
fn bookkeeping_lines_are_not_turns() {
    let folio = fixture();

    assert_eq!(folio.turns.len(), 5);
}

#[test]
fn turn_roles_come_from_the_entry_tag() {
    let folio = fixture();

    let roles: Vec<Role> = folio.turns.iter().map(|turn| turn.role).collect();
    assert_eq!(
        roles,
        [
            Role::User,
            Role::Assistant,
            Role::User,
            Role::User,
            Role::Assistant
        ]
    );
}

#[test]
fn string_content_is_kept_whole() {
    let folio = fixture();

    let Content::Text(text) = &folio.turns[0].content else {
        panic!("expected the opening turn to carry plain string content");
    };
    assert_eq!(text, "Explain the **quire** layout, please.");
}

#[test]
fn subagent_turns_are_marked() {
    let folio = fixture();

    let sidechains: Vec<bool> = folio.turns.iter().map(|turn| turn.is_sidechain).collect();
    assert_eq!(sidechains, [false, false, false, true, false]);
}

#[test]
fn session_id_comes_from_the_file_name() {
    assert_eq!(fixture().session_id(), "session");
}

#[test]
fn the_effort_level_refines_the_model_name() {
    let html = render(&fixture(), &highlighter());

    assert!(html.contains(
        r#"<span class="turn__model">claude-opus-4-8 <span class="turn__effort">(high)</span></span>"#
    ));
    // The turn the harness recorded no effort for names the model alone.
    assert!(html.contains(r#"<span class="turn__model">claude-opus-4-8</span>"#));
}

fn metered() -> Folio {
    Folio::read(Path::new("tests/fixtures/usage.jsonl")).expect("fixture parses")
}

#[test]
fn a_response_written_as_several_lines_is_counted_once() {
    let folio = metered();

    // Both lines of msg_quire report the response's usage; only the first
    // keeps it, so the second contributes nothing to the total.
    let counted: Vec<u64> = folio
        .turns
        .iter()
        .filter_map(|turn| turn.usage)
        .map(|usage| usage.output_tokens)
        .collect();
    assert_eq!(counted, [214, 31]);
}

#[test]
fn a_session_totals_its_output_but_takes_its_largest_input() {
    let folio = metered();

    assert_eq!(folio.output(), Some(245));
    assert_eq!(folio.largest_input(), Some(48_207));
}

#[test]
fn a_session_without_usage_reports_none() {
    assert!(fixture().output().is_none());
    assert!(fixture().largest_input().is_none());
}

#[test]
fn a_turn_shows_the_input_it_added_and_the_output_it_drew() {
    let html = render(&metered(), &highlighter());

    assert!(html.contains(
        r#"<span class="turn__usage" title="32,403 input this turn · 214 output this turn">↑ 32.4k ↓ 214</span>"#
    ));
}

#[test]
fn the_plaque_shows_the_largest_input_and_the_total_output() {
    let html = render(&metered(), &highlighter());

    assert!(html.contains(
        r#"<dd title="48,207 input at its largest · 245 output in all">↑ 48.2k ↓ 245</dd>"#
    ));
}

#[test]
fn unrecognized_block_types_render_as_json_instead_of_failing() {
    let html = render(&fixture(), &highlighter());

    assert!(html.contains("block--unknown"));
    assert!(html.contains("<summary>illumination</summary>"));
    assert!(html.contains("lapis lazuli"));
}

#[test]
fn unrecognized_blocks_nested_in_tool_results_survive_too() {
    let html = render(&fixture(), &highlighter());

    assert!(html.contains("<summary>tool_reference</summary>"));
    assert!(html.contains("Scriptorium"));
}

#[test]
fn markdown_becomes_html() {
    let html = render(&fixture(), &highlighter());

    assert!(html.contains("<strong>quire</strong>"));
}

#[test]
fn fenced_code_is_highlighted_into_classed_spans() {
    let html = render(&fixture(), &highlighter());

    assert!(html.contains(r#"class="ink-source ink-rust""#));
}

#[test]
fn tool_calls_carry_a_gist_of_their_subject() {
    let html = render(&fixture(), &highlighter());

    assert!(html.contains(r#"<span class="marginalia__tool">Read</span>"#));
    assert!(html.contains("/scriptorium/quire.rs"));
}

fn tools() -> Folio {
    Folio::read(Path::new("tests/fixtures/tools.jsonl")).expect("fixture parses")
}

#[test]
fn bash_calls_show_their_description_and_highlighted_command() {
    let html = render(&tools(), &highlighter());

    // The description labels the fold; the command fills its body.
    assert!(html.contains(r#"<span class="marginalia__gist">Scaffold the crate</span>"#));
    // The command is a highlighted shell block, not raw JSON.
    assert!(html.contains("ink-shell"));
    assert!(html.contains("cargo"));
}

#[test]
fn write_calls_highlight_content_by_file_extension() {
    let html = render(&tools(), &highlighter());

    // main.rs resolves to the Rust lexer via the bare extension.
    assert!(html.contains("ink-rust"));
    assert!(html.contains("scriptorium"));
}

#[test]
fn edit_calls_render_before_and_after_as_a_diff() {
    let html = render(&tools(), &highlighter());

    assert!(html.contains(r#"<span class="marginalia__note">replace all</span>"#));
    // The old line is a deletion and the new line an insertion in the diff.
    assert!(html.contains("ink-deleted"));
    assert!(html.contains("ink-inserted"));
}

#[test]
fn todo_writes_render_as_a_status_marked_checklist() {
    let html = render(&tools(), &highlighter());

    assert!(
        html.contains(r#"<li class="tool__todo" data-status="completed">Scaffold the crate</li>"#)
    );
    assert!(html.contains(r#"data-status="in_progress">Wire the CLI</li>"#));
    assert!(html.contains(r#"data-status="pending">Add coverage</li>"#));
}

fn playground() -> Folio {
    Folio::read(Path::new("tests/fixtures/playground.jsonl")).expect("fixture parses")
}

#[test]
fn a_call_its_summary_states_in_full_has_no_fold_to_open() {
    let html = render(&playground(), &highlighter());

    // A read names a file and the lines it took, and both fit on the line, so
    // there is no subject left for a body to hold.
    assert!(html.contains(r#"<div class="marginalia marginalia--use marginalia--flat">"#));
    assert!(html.contains(r#"<span class="marginalia__note">lines 105–108</span>"#));
}

#[test]
fn a_reads_result_is_set_as_the_language_of_the_file_it_read() {
    let html = render(&playground(), &highlighter());

    // The harness numbers the lines it returns; those come off, and what is
    // left is highlighted as the Rust the file holds.
    assert!(!html.contains("1\t//! Parsing of Claude Code"));
    assert!(html.contains(r#"class="ink-source ink-rust""#));
}

#[test]
fn a_plan_is_set_as_the_markdown_document_it_is() {
    let html = render(&playground(), &highlighter());

    assert!(
        html.contains(r#"<span class="marginalia__gist">Pretty-print every built-in tool</span>"#)
    );
    assert!(html.contains("<h1>Pretty-print every built-in tool</h1>"));
    // The prompts the plan asks to be pre-approved sit under it, not in it.
    assert!(html.contains(r#"<li class="tool__prompt">"#));
}

#[test]
fn a_question_shows_every_option_it_offered() {
    let html = render(&playground(), &highlighter());

    assert!(html.contains(r#"<span class="tool__header">Read result</span>"#));
    assert!(html.contains(r#"<span class="tool__label">Highlight by extension</span>"#));
    assert!(html.contains("Keep the numbers"));
    // Every question a call asked is laid out at once, rather than one screen
    // at a time behind a control the reader has to work through.
    assert_eq!(
        html.matches(r#"<section class="tool__question">"#).count(),
        2
    );
    assert!(html.contains(r#"<span class="tool__header">Scope</span>"#));
}

#[test]
fn a_web_search_sets_the_links_it_found_as_links() {
    let html = render(&playground(), &highlighter());

    assert!(
        html.contains(r#"<a href="https://openfontlicense.org/">SIL Open Font License 1.1</a>"#)
    );
}

#[test]
fn a_background_tasks_answer_splits_into_its_facts_and_its_output() {
    let html = render(&playground(), &highlighter());

    assert!(html.contains(r#"<dl class="tool tool--facts">"#));
    assert!(html.contains("<dt>status</dt><dd>completed</dd>"));
    // The output is prose, so it is set as prose rather than as a terminal's.
    assert!(html.contains("<li>164 sessions</li>"));
}

fn answers() -> Folio {
    Folio::read(Path::new("tests/fixtures/answers.jsonl")).expect("fixture parses")
}

#[test]
fn an_answer_is_recovered_from_the_sentence_the_harness_buries_it_in() {
    let html = render(&answers(), &highlighter());

    assert!(html.contains(r#"<p class="tool__chosen">All projects, two-stage</p>"#));
    assert!(html.contains(r#"<p class="tool__chosen">Time + first prompt</p>"#));
    // Nothing of the framing sentence survives into the folio.
    assert!(!html.contains("Your questions have been answered"));
    assert!(!html.contains("You can now continue with these answers in mind"));
}

#[test]
fn a_question_quoting_code_does_not_break_the_pairs_apart() {
    let html = render(&answers(), &highlighter());

    // The question carries `raise ValueError("...")`, so the quotes the
    // sentence delimits its values with also appear inside one.
    assert!(html.contains(r#"<p class="tool__chosen">Leave it</p>"#));
}

#[test]
fn a_chosen_options_preview_is_shown_against_the_option_not_the_answer() {
    let html = render(&answers(), &highlighter());

    // The mockup is what the reader compared, so it belongs to the option in
    // the call; the answer names the option and no more.
    assert!(html.contains(r#"<p class="tool__chosen">In the meta line</p>"#));
    assert!(!html.contains("selected preview"));
    assert_eq!(html.matches("┌───────────────┐").count(), 1);
}

#[test]
fn several_selections_arrive_as_the_one_answer_they_were_given_as() {
    let html = render(&answers(), &highlighter());

    assert!(html.contains(
        r#"<p class="tool__chosen">Default policy by role, Valid-optional vs malformed, Derive, don't restate</p>"#
    ));
}

#[test]
fn an_answer_the_reader_typed_is_kept_whole() {
    let html = render(&answers(), &highlighter());

    // Typed instead of chosen, so it arrives unquoted under the other opening
    // and with no closing sentence.
    // The harness's own framing around it goes; that it was typed rather than
    // chosen is kept, as a mark on the answer.
    assert!(html.contains(
        r#"<p class="tool__chosen" data-typed>I want copy buttons, jump, and fancy collapse."#
    ));
    assert!(!html.contains("The user answered:"));
    assert!(!html.contains("no option selected"));
    // And a typed answer may quote something of its own.
    assert!(html.contains("it keeps matching items instead of dropping them"));
}

#[test]
fn a_question_that_was_never_answered_stands_as_the_note_it_is() {
    let html = render(&answers(), &highlighter());

    // A timeout is not an answer, so there is no pair to find and the harness's
    // own words are shown rather than forced into the shape of one.
    assert!(html.contains("No response after 60s"));
}

#[test]
fn a_result_that_only_says_the_call_worked_is_dropped() {
    let html = render(&playground(), &highlighter());

    // The write and the edit above them already show the file and the change;
    // an acknowledgement per file touched would crowd out the conversation.
    assert!(!html.contains("src/render.rs has been updated successfully"));
    assert!(!html.contains("File created successfully at"));
    assert!(!html.contains("Todos have been modified"));
    assert!(!html.contains("Launching skill"));
    // Entering plan mode answers with instructions meant for the model, so the
    // call stands alone as the one line it is.
    assert!(html.contains(r#"<span class="marginalia__tool">EnterPlanMode</span>"#));
    assert!(!html.contains("Entered plan mode"));
}

#[test]
fn a_result_written_down_as_text_blocks_is_weighed_like_a_plain_one() {
    let html = render(&playground(), &highlighter());

    // The harness records a background agent's launch as text blocks rather
    // than as a plain string, but that is how it was written down and not a
    // difference in what came back: the id and output file it names are for the
    // model to reach the agent again, and the call above it already shows what
    // the agent was sent.
    assert!(!html.contains("Async agent launched successfully"));
    assert!(html.contains("Survey the drollery bestiary"));
}

#[test]
fn a_result_that_warns_alongside_the_acknowledgement_is_kept() {
    let html = render(&playground(), &highlighter());

    // The match is on the acknowledgement itself, not on the tool, so an edit
    // that also reports the file changed underneath it still reaches a reader.
    assert!(html.contains("the file had been modified on disk"));
}

#[test]
fn a_terminals_colour_survives_into_the_folio() {
    let html = render(&playground(), &highlighter());

    // The named colours are the folio's to grind, so they arrive as classes the
    // stylesheet resolves against the parchment.
    assert!(html.contains(r#"<span class="ansi ansi--green">ok</span>"#));
    assert!(html.contains(r#"<span class="ansi ansi--red ansi--bold">FAILED</span>"#));
    assert!(html.contains(r#"<span class="ansi ansi--bright-black">"#));
    // No escape reaches the page, whether it carried colour or drove the
    // terminal.
    assert!(!html.contains('\u{1b}'));
}

#[test]
fn a_colour_a_tool_states_outright_is_carried_as_its_own_value() {
    let html = render(&playground(), &highlighter());

    // No palette token can stand for a 256-colour index or a 24-bit colour, so
    // these are the one place a pigment is set on the element itself.
    assert!(html.contains(r#"style="color:#ff8700""#));
    assert!(html.contains(r#"style="color:#785ac8""#));
}

#[test]
fn a_bodys_trailing_newline_is_not_set_as_a_line() {
    let html = render(&playground(), &highlighter());

    // A file's own trailing newline would otherwise leave an empty line against
    // the bottom edge of the fold, reading as content that isn't there.
    assert!(!html.contains("\n</code></pre>"));
}

#[test]
fn a_failure_sheds_the_tag_the_harness_wraps_it_in() {
    let html = render(&playground(), &highlighter());

    assert!(html.contains("String to replace not found in file."));
    assert!(!html.contains("tool_use_error"));
}

#[test]
fn an_answer_that_is_json_is_pretty_printed() {
    let html = render(&playground(), &highlighter());

    // Several tools answer with a JSON object on a single line.
    assert!(html.contains(r#"class="ink-source ink-json""#));
}

#[test]
fn a_tool_search_lists_the_tools_it_found() {
    let html = render(&playground(), &highlighter());

    assert!(html.contains(r#"<li class="tool__reference">WebSearch</li>"#));
    assert!(html.contains(r#"<li class="tool__reference">WebFetch</li>"#));
}

#[test]
fn a_tool_with_no_view_of_its_own_falls_back_to_json() {
    let html = render(&playground(), &highlighter());

    // An MCP tool is named by its server, and its input has whatever shape that
    // server gave it: no view can know it, so the call shows what it was sent.
    assert!(
        html.contains(r#"<span class="marginalia__tool">mcp__scriptorium__list_quires</span>"#)
    );
    assert!(html.contains("newest_first"));
}

#[test]
fn failed_tool_results_are_flagged() {
    let html = render(&fixture(), &highlighter());

    assert!(html.contains("data-error"));
    assert!(html.contains("vellum not found"));
}

#[test]
fn images_are_inlined_as_data_urls() {
    let html = render(&fixture(), &highlighter());

    assert!(html.contains(r#"src="data:image/png;base64,iVBORw0KGgo=""#));
}

#[test]
fn transcript_html_is_escaped_rather_than_executed() {
    let folio = Folio::read(Path::new("tests/fixtures/injection.jsonl")).expect("fixture parses");

    let html = render(&folio, &highlighter());

    // The folio carries its own trusted app script, so "no <script> at all" is
    // no longer the invariant. What must hold is that transcript-provided
    // markup is inert: every <script> the session mentions is escaped to text,
    // and none survives as an executable tag.
    assert!(html.contains("&lt;script&gt;"));
    assert!(!html.contains("<script>alert"));
}

#[test]
fn the_folio_carries_its_trusted_app_script() {
    let html = render(&fixture(), &highlighter());

    // The app script is inlined in <head> (theme applies before first paint).
    assert!(html.contains("<script>"));
    assert!(html.contains("scriptorium-theme"));
}

#[test]
fn the_folio_carries_a_search_widget() {
    let html = render(&fixture(), &highlighter());

    assert!(html.contains(r#"class="search""#));
    assert!(html.contains(r#"class="search__input""#));
    assert!(html.contains(r#"data-search-nav="next""#));
}

#[test]
fn the_header_offers_a_light_dark_system_theme_toggle() {
    let html = render(&fixture(), &highlighter());

    assert!(html.contains(r#"class="theme-toggle""#));
    assert!(html.contains(r#"data-theme-choice="light""#));
    assert!(html.contains(r#"data-theme-choice="system""#));
    assert!(html.contains(r#"data-theme-choice="dark""#));
}

#[test]
fn a_turns_role_is_one_class_attribute_not_two() {
    let html = render(&fixture(), &highlighter());

    assert!(html.contains(r#"class="turn turn--assistant""#));
    assert!(!html.contains(r#"class="turn" class="#));
}

#[test]
fn thinking_blocks_render_their_markdown() {
    let html = render(&fixture(), &highlighter());

    assert!(html.contains(r#"<section class="block block--thinking">"#));
    assert!(html.contains("The gathering is four folded sheets."));
}

#[test]
fn redacted_thinking_blocks_are_marked_not_shown_as_an_empty_box() {
    let folio =
        Folio::read(Path::new("tests/fixtures/redacted_thinking.jsonl")).expect("fixture parses");

    let html = render(&folio, &highlighter());

    assert!(!html.contains(r#"<section class="block block--thinking">"#));
    assert!(html.contains("block--redacted"));
    assert!(html.contains("The reasoning was redacted."));
}

#[test]
fn tool_result_turns_fold_into_the_assistant_panel() {
    let html = render(&fixture(), &highlighter());

    // The opening user turn, the assistant panel that absorbs the tool
    // results, and the closing assistant panel: three articles, one "user".
    assert_eq!(html.matches("<article").count(), 3);
    assert_eq!(html.matches(r#"turn__role">user"#).count(), 1);
    // The read's result is set as the Rust the file holds, so the type it
    // declares arrives wrapped in the highlighter's spans rather than bare.
    assert!(html.contains("Quire"));
    assert!(html.contains("ink-storage"));
}

#[test]
fn panels_are_labelled_by_their_content_kind() {
    let folio = Folio::read(Path::new("tests/fixtures/kinds.jsonl")).expect("fixture parses");

    let html = render(&folio, &highlighter());

    // A tool call plus its folded result reads as tool; bare reasoning as
    // thinking; prose keeps the speaker's name.
    assert!(html.contains(r#"turn__role">tool<"#));
    assert!(html.contains(r#"turn__role">thinking<"#));
    assert!(html.contains(r#"turn__role">assistant<"#));
}

#[test]
fn only_speech_panels_open_with_a_versal() {
    let folio = Folio::read(Path::new("tests/fixtures/kinds.jsonl")).expect("fixture parses");

    let html = render(&folio, &highlighter());

    // Three panels: a tool exchange, bare reasoning, and one line of prose.
    // Only the prose panel earns a versal; tool and thinking panels get none.
    // (Match the emitted attribute, not the `[data-versal]` selectors the
    // inlined stylesheet also carries.)
    assert_eq!(html.matches("data-versal>").count(), 1);
    assert!(html.contains(r#"<div class="block block--text" data-versal>"#));
}

#[test]
fn a_versal_marks_only_the_opening_paragraph_of_a_panel() {
    // The assistant panel opens with a thinking block, then prose, then a tool
    // call and its folded result: the versal lands on the leading text and
    // nowhere else, so the session's two speaking panels carry exactly two.
    let html = render(&fixture(), &highlighter());

    assert_eq!(html.matches("data-versal>").count(), 2);
}

#[test]
fn each_panel_is_numbered_by_its_leading_turn() {
    let html = render(&fixture(), &highlighter());

    // Turns 1, 2, and 5 lead panels; turns 3 and 4 fold into turn 2's panel,
    // so their numbers never appear as labels.
    assert!(html.contains(r##"href="#turn-1">#1</a>"##));
    assert!(html.contains(r##"href="#turn-2">#2</a>"##));
    assert!(html.contains(r##"href="#turn-5">#5</a>"##));
    assert!(!html.contains(r##"href="#turn-3">#3</a>"##));
}

#[test]
fn each_panel_is_a_deep_link_target_its_number_points_to() {
    let html = render(&fixture(), &highlighter());

    // The panel carries an id its own number links to, so #turn-N in the URL
    // lands on the panel and the number is a shareable permalink to it.
    assert!(html.contains(r#"<article id="turn-1""#));
    assert!(html.contains(r#"<article id="turn-2""#));
    assert!(html.contains(r##"<a class="turn__index" href="#turn-1">#1</a>"##));
}

#[test]
fn meta_turns_are_marked_and_hidden_with_no_reveal_control() {
    let folio = Folio::read(Path::new("tests/fixtures/meta.jsonl")).expect("fixture parses");

    let html = render(&folio, &highlighter());

    // Harness notes stay in the folio, marked and hidden by the stylesheet, but
    // carry no reader-facing control to reveal them.
    assert!(html.contains("data-meta"));
    assert!(html.contains("Base directory for this skill"));
    assert!(!html.contains(r#"id="show-meta""#));
}

#[test]
fn clear_command_turns_are_dropped() {
    let folio = Folio::read(Path::new("tests/fixtures/clear.jsonl")).expect("fixture parses");

    let html = render(&folio, &highlighter());

    assert!(!html.contains("command-name"));
    assert!(!html.contains("command-message"));
    assert!(html.contains("Explain the quire layout."));
    assert_eq!(html.matches("<article").count(), 1);
}

#[test]
fn a_message_queued_mid_response_becomes_a_user_turn() {
    let folio = Folio::read(Path::new("tests/fixtures/queued.jsonl")).expect("fixture parses");

    // The prompt the user typed while the assistant was working is recorded as
    // a `queued_command` attachment, not a `user` line, so it would vanish if
    // attachments were all dropped as bookkeeping.
    let queued = folio
        .turns
        .iter()
        .find(|turn| {
            turn.role == Role::User
                && matches!(&turn.content, Content::Text(text) if text.contains("above and below"))
        })
        .expect("the queued message is lifted into a user turn");
    assert!(!queued.is_meta);
    assert!(!queued.is_sidechain);
}

#[test]
fn a_queued_message_renders_as_its_own_user_panel() {
    let folio = Folio::read(Path::new("tests/fixtures/queued.jsonl")).expect("fixture parses");

    let html = render(&folio, &highlighter());

    assert!(html.contains("put the drolleries above and below the vine"));
    // Opening prompt and the mid-response interjection are two user panels; the
    // tool result folds into the assistant that called it rather than standing
    // between them.
    assert_eq!(html.matches(r#"turn__role">user"#).count(), 2);
}

#[test]
fn non_queued_attachments_stay_dropped() {
    let folio = Folio::read(Path::new("tests/fixtures/queued.jsonl")).expect("fixture parses");

    let html = render(&folio, &highlighter());

    // A `task_reminder` attachment is scaffolding, not conversation: it must not
    // leak into the render the way the queued command does.
    assert!(!html.contains("You have not used the task tools"));
}

#[test]
fn search_offers_per_kind_scope_toggles() {
    let html = render(&fixture(), &highlighter());

    // The reader can restrict the search to chosen kinds of message; every
    // scope starts enabled.
    assert!(html.contains(r#"data-scope="user" aria-pressed="true""#));
    assert!(html.contains(r#"data-scope="assistant" aria-pressed="true""#));
    assert!(html.contains(r#"data-scope="tool" aria-pressed="true""#));
    assert!(html.contains(r#"data-scope="thinking" aria-pressed="true""#));
}

#[test]
fn panels_carry_their_turn_number_for_stable_fold_memory() {
    let html = render(&fixture(), &highlighter());

    // The per-message fold memory keys on this: a panel's turn number is stable
    // across live re-renders because the raw stream only ever appends.
    assert!(html.contains(r#"data-turn="1""#));
    assert!(html.contains(r#"data-turn="2""#));
}

#[test]
fn the_dock_offers_role_scoped_message_navigation() {
    let html = render(&fixture(), &highlighter());

    // The middle column steps between all messages; the flanking columns seek
    // one speaker, tagged so the app script and stylesheet can scope them.
    assert!(html.contains(r#"data-nav="prev" data-role="user""#));
    assert!(html.contains(r#"data-nav="next" data-role="assistant""#));
    assert!(html.contains(r#"class="dock__btn dock__btn--user""#));
    assert!(html.contains(r#"class="dock__btn dock__btn--assistant""#));
}

#[test]
fn the_dock_leaps_to_either_end_of_the_folio() {
    let html = render(&fixture(), &highlighter());

    assert!(html.contains(r#"data-nav="top" aria-label="jump to top""#));
    assert!(html.contains(r#"data-nav="end" aria-label="jump to end""#));
}

#[test]
fn the_stylesheet_is_inlined_not_linked() {
    let html = render(&fixture(), &highlighter());

    assert!(html.contains("<style>"));
    assert!(html.contains(".ink-keyword"));
    assert!(!html.contains("<link"));
}

#[test]
fn fonts_are_embedded_not_linked() {
    let html = render(&fixture(), &highlighter());

    // Every face is inlined as a woff2 data URI, so the folio stays
    // self-contained: Junicode (roman + italic), UnifrakturCook, Fira Code.
    assert_eq!(html.matches("data:font/woff2;base64,").count(), 4);
    assert!(html.contains(r#"font-family:"Junicode""#));
    assert!(html.contains(r#"font-family:"UnifrakturCook""#));
    assert!(html.contains(r#"font-family:"Fira Code""#));
    assert!(!html.contains("fonts.googleapis.com"));
    assert!(!html.contains("fonts.gstatic.com"));
}

#[test]
fn embedded_fonts_carry_their_open_font_license_notice() {
    let html = render(&fixture(), &highlighter());

    // The SIL OFL requires every copy to carry the copyright and license; the
    // notice comment and colophon credit put both in every generated folio.
    assert!(html.contains("Copyright 2010 j. 'mach' wust"));
    assert!(html.contains("SIL Open Font License"));
}

#[test]
fn the_colophon_stamps_the_run() {
    let html = render(&fixture(), &highlighter());

    assert!(html.contains("claude-scriptorium"));
    assert!(html.contains("2026-03-12 09:15:00 UTC"));
}

#[test]
fn the_colophon_links_the_tool_to_its_home() {
    let html = render(&fixture(), &highlighter());

    assert!(html.contains(
        r#"Written by <a href="https://example.invalid/scriptorium">claude-scriptorium</a> 0.1.0"#
    ));
}