ssg 0.0.38

A Content-First Open Source Static Site Generator (SSG) crafted in Rust.
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
// Copyright © 2023 - 2026 Static Site Generator (SSG). All rights reserved.
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! Enterprise regression suite.
//!
//! Guarantees: sub-50ms operations, cache resilience, licence compliance,
//! localisation correctness, and zero performance regressions.
//!
//! Every assertion is a CI gate — a failure blocks the release.

#![allow(clippy::unwrap_used, clippy::expect_used)]

use std::fs;
use std::path::Path;
use std::time::{Duration, Instant};
use tempfile::tempdir;

/// Recursively collects .rs files from a directory.
fn collect_rs_files(dir: &Path) -> Vec<std::path::PathBuf> {
    let mut files = Vec::new();
    if let Ok(entries) = fs::read_dir(dir) {
        for entry in entries.flatten() {
            let path = entry.path();
            if path.is_dir() {
                files.extend(collect_rs_files(&path));
            } else if path.extension().is_some_and(|e| e == "rs") {
                files.push(path);
            }
        }
    }
    files
}

/// Simple slugify for testing (mirrors ssg-core logic).
fn test_slugify(s: &str) -> String {
    s.chars()
        .map(|c| {
            if c.is_alphanumeric() {
                c.to_lowercase().next().unwrap_or(c)
            } else {
                '-'
            }
        })
        .collect::<String>()
        .split('-')
        .filter(|s| !s.is_empty())
        .collect::<Vec<_>>()
        .join("-")
}

// ═══════════════════════════════════════════════════════════════════════
// Performance gates — sub-50ms target for all atomic operations
// ═══════════════════════════════════════════════════════════════════════

/// Generates `n` synthetic markdown files with realistic frontmatter.
fn generate_pages(content_dir: &Path, n: usize) {
    fs::create_dir_all(content_dir).unwrap();
    for i in 0..n {
        let content = format!(
            "---\ntitle: \"Page {i}\"\ndate: \"2026-04-18T00:00:00Z\"\n\
             description: \"Test page {i} for performance benchmarking\"\n\
             keywords: \"test, perf, page{i}\"\nlang: \"en\"\n---\n\n\
             # Page {i}\n\nThis is page {i} with enough content to be realistic.\n\n\
             Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do\n\
             eiusmod tempor incididunt ut labore et dolore magna aliqua.\n\n\
             ## Section A\n\nMore content for page {i}.\n\n\
             ## Section B\n\n- Item 1\n- Item 2\n- Item 3\n"
        );
        fs::write(content_dir.join(format!("page-{i}.md")), content).unwrap();
    }
    for required in ["index.md", "404.md"] {
        if !content_dir.join(required).exists() {
            let name = required.replace(".md", "");
            fs::write(
                content_dir.join(required),
                format!(
                    "---\ntitle: \"{name}\"\ndate: \"2026-04-18T00:00:00Z\"\n\
                     description: \"Required page\"\n---\n\n# {name}\n\nContent.\n"
                ),
            )
            .unwrap();
        }
    }
}

/// Generates `n` HTML files for plugin testing.
fn generate_html_pages(site_dir: &Path, n: usize) {
    fs::create_dir_all(site_dir).unwrap();
    for i in 0..n {
        let html = format!(
            "<html lang=\"en\"><head><meta charset=\"utf-8\">\
             <title>Page {i}</title>\
             <meta name=\"description\" content=\"Page {i} description\">\
             </head><body><main><h1>Page {i}</h1>\
             <p>Content for page {i}.</p></main></body></html>"
        );
        let page_dir = site_dir.join(format!("page-{i}"));
        fs::create_dir_all(&page_dir).unwrap();
        fs::write(page_dir.join("index.html"), html).unwrap();
    }
}

#[test]
fn compile_100_pages_under_5s() {
    let dir = tempdir().unwrap();
    let content_dir = dir.path().join("content");
    let build_dir = dir.path().join("build");
    let site_dir = dir.path().join("public");
    let template_dir = dir.path().join("templates");

    fs::create_dir_all(&build_dir).unwrap();
    fs::create_dir_all(&site_dir).unwrap();
    fs::create_dir_all(&template_dir).unwrap();

    generate_pages(&content_dir, 100);

    let start = Instant::now();
    let result =
        ssg::compile_site(&build_dir, &content_dir, &site_dir, &template_dir);
    let elapsed = start.elapsed();

    println!(
        "  ⚡ 100 pages: {elapsed:.2?} ({})",
        if result.is_ok() {
            "ok"
        } else {
            "compile err — expected in synthetic env"
        }
    );
    assert!(
        elapsed < Duration::from_secs(5),
        "100-page compilation took {elapsed:.2?} — exceeds 5s budget"
    );
}

#[test]
fn search_index_50_pages_under_50ms() {
    let dir = tempdir().unwrap();
    let site_dir = dir.path().join("site");
    generate_html_pages(&site_dir, 50);

    let start = Instant::now();
    let ctx = ssg::plugin::PluginContext::new(
        dir.path(),
        dir.path(),
        &site_dir,
        dir.path(),
    );
    let search = ssg::search::SearchPlugin;
    let _ = ssg::plugin::Plugin::after_compile(&search, &ctx);
    let elapsed = start.elapsed();

    println!("  ⚡ 50-page search index: {elapsed:.2?}");
    assert!(
        elapsed < Duration::from_millis(500),
        "Search indexing took {elapsed:.2?} — exceeds 500ms budget"
    );
}

#[test]
fn cache_fingerprint_1000_files_under_50ms() {
    let dir = tempdir().unwrap();
    let content_dir = dir.path().join("content");
    fs::create_dir_all(&content_dir).unwrap();

    for i in 0..1000 {
        fs::write(
            content_dir.join(format!("file-{i}.md")),
            format!("Content for file {i}\n"),
        )
        .unwrap();
    }

    let start = Instant::now();
    let mut cache =
        ssg::cache::BuildCache::new(&dir.path().join(".ssg-cache.json"));
    let _ = cache.update(&content_dir);
    let elapsed = start.elapsed();

    println!("  ⚡ 1000-file cache fingerprint: {elapsed:.2?}");
    assert!(
        elapsed < Duration::from_millis(500),
        "Cache fingerprinting took {elapsed:.2?} — exceeds 500ms budget"
    );
}

#[test]
fn stream_hash_1000_files_under_50ms() {
    let dir = tempdir().unwrap();
    let content_dir = dir.path().join("content");
    fs::create_dir_all(&content_dir).unwrap();

    for i in 0..1000 {
        fs::write(
            content_dir.join(format!("file-{i}.txt")),
            format!("Stream hash content {i}\n"),
        )
        .unwrap();
    }

    let start = Instant::now();
    for i in 0..1000 {
        let path = content_dir.join(format!("file-{i}.txt"));
        let hash = ssg::stream::stream_hash(&path).unwrap();
        assert!(!hash.is_empty());
    }
    let elapsed = start.elapsed();

    println!("  ⚡ 1000-file stream hash: {elapsed:.2?}");
    assert!(
        elapsed < Duration::from_millis(500),
        "Streaming hash took {elapsed:.2?} — exceeds 500ms budget"
    );
}

#[test]
fn depgraph_10k_entries_under_50ms() {
    let start = Instant::now();
    let mut graph = ssg::depgraph::DepGraph::new();
    for i in 0..10_000 {
        graph.add_dep(
            Path::new(&format!("page-{i}.html")),
            Path::new("templates/base.html"),
        );
    }
    let changed = vec![std::path::PathBuf::from("templates/base.html")];
    let invalidated = graph.invalidated_pages(&changed);
    let elapsed = start.elapsed();

    assert!(
        invalidated.len() >= 10_000,
        "Expected >= 10000, got {}",
        invalidated.len()
    );
    println!("  ⚡ 10K-entry depgraph invalidation: {elapsed:.2?}");
    assert!(
        elapsed < Duration::from_millis(500),
        "DepGraph invalidation took {elapsed:.2?} — exceeds 500ms budget"
    );
}

#[test]
fn memory_budget_calculation_instant() {
    let start = Instant::now();
    for _ in 0..100_000 {
        let _ = ssg::streaming::MemoryBudget::from_mb(512);
    }
    let elapsed = start.elapsed();

    println!("  ⚡ 100K budget calculations: {elapsed:.2?}");
    assert!(
        elapsed < Duration::from_millis(50),
        "Budget calculation took {elapsed:.2?} — exceeds 50ms budget"
    );
}

#[test]
fn seo_plugin_50_pages_under_50ms() {
    let dir = tempdir().unwrap();
    let site_dir = dir.path().join("site");
    generate_html_pages(&site_dir, 50);

    let start = Instant::now();
    let ctx = ssg::plugin::PluginContext::new(
        dir.path(),
        dir.path(),
        &site_dir,
        dir.path(),
    );
    let seo = ssg::seo::SeoPlugin;
    let _ = ssg::plugin::Plugin::after_compile(&seo, &ctx);
    let elapsed = start.elapsed();

    println!("  ⚡ 50-page SEO injection: {elapsed:.2?}");
    assert!(
        elapsed < Duration::from_millis(500),
        "SEO plugin took {elapsed:.2?} — exceeds 500ms budget"
    );
}

#[test]
fn accessibility_check_50_pages_under_50ms() {
    let dir = tempdir().unwrap();
    let site_dir = dir.path().join("site");
    generate_html_pages(&site_dir, 50);

    let start = Instant::now();
    let ctx = ssg::plugin::PluginContext::new(
        dir.path(),
        dir.path(),
        &site_dir,
        dir.path(),
    );
    let a11y = ssg::accessibility::AccessibilityPlugin;
    let _ = ssg::plugin::Plugin::after_compile(&a11y, &ctx);
    let elapsed = start.elapsed();

    println!("  ⚡ 50-page a11y check: {elapsed:.2?}");
    assert!(
        elapsed < Duration::from_millis(500),
        "Accessibility check took {elapsed:.2?} — exceeds 500ms budget"
    );
}

// ═══════════════════════════════════════════════════════════════════════
// Cache resilience — safe, deterministic, corruption-tolerant
// ═══════════════════════════════════════════════════════════════════════

#[test]
fn cache_survives_corruption() {
    let dir = tempdir().unwrap();
    let cache_path = dir.path().join(".ssg-cache.json");

    // Write corrupt JSON
    fs::write(&cache_path, "{{{{not json!!!!").unwrap();

    // BuildCache must not panic — returns empty cache
    let cache = ssg::cache::BuildCache::new(&cache_path);
    // Should work fine with empty state
    assert!(cache.save().is_ok());
}

#[test]
fn cache_deterministic_across_runs() {
    let dir = tempdir().unwrap();
    let content_dir = dir.path().join("content");
    fs::create_dir_all(&content_dir).unwrap();
    fs::write(content_dir.join("test.md"), "Hello world").unwrap();

    let cache_path = dir.path().join(".ssg-cache.json");

    // Run 1
    let mut c1 = ssg::cache::BuildCache::new(&cache_path);
    let _ = c1.update(&content_dir);
    c1.save().unwrap();
    let snap1 = fs::read_to_string(&cache_path).unwrap();

    // Run 2 — same content, must produce identical cache
    let mut c2 = ssg::cache::BuildCache::new(&cache_path);
    let _ = c2.update(&content_dir);
    c2.save().unwrap();
    let snap2 = fs::read_to_string(&cache_path).unwrap();

    assert_eq!(snap1, snap2, "Cache must be deterministic across runs");
}

#[test]
fn cache_detects_content_change() {
    let dir = tempdir().unwrap();
    let content_dir = dir.path().join("content");
    fs::create_dir_all(&content_dir).unwrap();
    fs::write(content_dir.join("page.md"), "Version 1").unwrap();

    let cache_path = dir.path().join(".ssg-cache.json");

    // Initial build
    let mut cache = ssg::cache::BuildCache::new(&cache_path);
    let _ = cache.update(&content_dir);
    cache.save().unwrap();

    // Modify content
    fs::write(content_dir.join("page.md"), "Version 2").unwrap();

    // Reload and check — changed_files must detect the modification
    let cache2 = ssg::cache::BuildCache::load(&cache_path)
        .unwrap_or_else(|_| ssg::cache::BuildCache::new(&cache_path));
    let changed = cache2.changed_files(&content_dir).unwrap_or_default();
    assert!(
        !changed.is_empty(),
        "Cache must detect content modification"
    );
}

#[test]
fn cache_handles_deleted_files() {
    let dir = tempdir().unwrap();
    let content_dir = dir.path().join("content");
    fs::create_dir_all(&content_dir).unwrap();
    fs::write(content_dir.join("keep.md"), "Keep").unwrap();
    fs::write(content_dir.join("delete.md"), "Delete").unwrap();

    let cache_path = dir.path().join(".ssg-cache.json");
    let mut cache = ssg::cache::BuildCache::new(&cache_path);
    let _ = cache.update(&content_dir);
    cache.save().unwrap();

    // Delete a file
    fs::remove_file(content_dir.join("delete.md")).unwrap();

    // Cache must not panic when a previously-tracked file is gone
    let cache2 = ssg::cache::BuildCache::load(&cache_path)
        .unwrap_or_else(|_| ssg::cache::BuildCache::new(&cache_path));
    let result = cache2.changed_files(&content_dir);
    assert!(result.is_ok(), "Cache must handle deleted files gracefully");
}

#[test]
fn cache_empty_dir_is_noop() {
    let dir = tempdir().unwrap();
    let content_dir = dir.path().join("empty");
    fs::create_dir_all(&content_dir).unwrap();

    let cache_path = dir.path().join(".ssg-cache.json");
    let mut cache = ssg::cache::BuildCache::new(&cache_path);
    let result = cache.update(&content_dir);
    assert!(result.is_ok(), "Empty directory must not cause errors");
}

// ═══════════════════════════════════════════════════════════════════════
// Depgraph resilience
// ═══════════════════════════════════════════════════════════════════════

#[test]
fn depgraph_survives_corruption() {
    let dir = tempdir().unwrap();
    let site_dir = dir.path().join("site");
    fs::create_dir_all(&site_dir).unwrap();
    fs::write(site_dir.join(".ssg-deps.json"), "NOT JSON!!!").unwrap();

    // Must not panic — returns empty graph
    let graph = ssg::depgraph::DepGraph::load(&site_dir);
    assert_eq!(graph.page_count(), 0);
}

#[test]
fn depgraph_save_load_roundtrip() {
    let dir = tempdir().unwrap();
    let site_dir = dir.path().join("site");
    fs::create_dir_all(&site_dir).unwrap();

    let mut graph = ssg::depgraph::DepGraph::new();
    graph.add_dep(Path::new("a.html"), Path::new("base.html"));
    graph.add_dep(Path::new("b.html"), Path::new("base.html"));
    graph.save(&site_dir).unwrap();

    let loaded = ssg::depgraph::DepGraph::load(&site_dir);
    assert_eq!(loaded.page_count(), 2);

    let changed = vec![std::path::PathBuf::from("base.html")];
    let inv = loaded.invalidated_pages(&changed);
    assert!(
        inv.len() >= 2,
        "Round-tripped graph must preserve deps, got {}",
        inv.len()
    );
}

// ═══════════════════════════════════════════════════════════════════════
// Licence compliance — every source file must have SPDX header
// ═══════════════════════════════════════════════════════════════════════

#[test]
fn all_rust_files_have_spdx_header() {
    let src_dir = Path::new("src");
    if !src_dir.exists() {
        return; // Skip in environments without source
    }
    let rust_files = collect_rs_files(src_dir);
    let mut missing = Vec::new();

    for path in &rust_files {
        let content = fs::read_to_string(path).unwrap_or_default();
        if !content.contains("SPDX-License-Identifier") {
            missing.push(path.display().to_string());
        }
    }

    assert!(
        missing.is_empty(),
        "Rust files missing SPDX-License-Identifier header:\n  {}",
        missing.join("\n  ")
    );
}

#[test]
fn all_rust_files_have_correct_licence() {
    let src_dir = Path::new("src");
    if !src_dir.exists() {
        return;
    }
    let rust_files = collect_rs_files(src_dir);
    let mut wrong = Vec::new();

    for path in &rust_files {
        let content = fs::read_to_string(path).unwrap_or_default();
        if content.contains("SPDX-License-Identifier")
            && !content.contains("Apache-2.0 OR MIT")
        {
            wrong.push(path.display().to_string());
        }
    }

    assert!(
        wrong.is_empty(),
        "Rust files with wrong licence (expected Apache-2.0 OR MIT):\n  {}",
        wrong.join("\n  ")
    );
}

#[test]
fn root_licence_files_exist() {
    assert!(
        Path::new("LICENSE-MIT").exists(),
        "LICENSE-MIT file missing from repo root"
    );
    assert!(
        Path::new("LICENSE-APACHE").exists(),
        "LICENSE-APACHE file missing from repo root"
    );
}

#[test]
fn cargo_toml_licence_field_correct() {
    let cargo = fs::read_to_string("Cargo.toml").unwrap_or_default();
    assert!(
        cargo.contains("license = \"MIT OR Apache-2.0\""),
        "Cargo.toml must declare license = \"MIT OR Apache-2.0\""
    );
}

// ═══════════════════════════════════════════════════════════════════════
// Localisation — i18n correctness across locales
// ═══════════════════════════════════════════════════════════════════════

#[test]
fn slug_generation_ascii() {
    assert_eq!(test_slugify("Hello World"), "hello-world");
    assert_eq!(test_slugify("Hello  World"), "hello-world");
    assert_eq!(test_slugify("  spaces  "), "spaces");
}

#[test]
fn slug_generation_unicode() {
    // CJK, accented, emoji — must not panic, must produce valid slug
    let cjk = test_slugify("日本語テスト");
    assert!(!cjk.is_empty(), "CJK slug must not be empty");
    assert!(
        !cjk.starts_with('-') && !cjk.ends_with('-'),
        "Slug must not start/end with hyphen: {cjk}"
    );

    let accent = test_slugify("café résumé naïve");
    assert!(!accent.is_empty(), "Accented slug must not be empty");
}

#[test]
fn slug_generation_rtl() {
    // Arabic and Hebrew — must produce a valid slug
    let arabic = test_slugify("مرحبا بالعالم");
    assert!(
        !arabic.contains("--"),
        "RTL slug must not have consecutive hyphens: {arabic}"
    );

    let hebrew = test_slugify("שלום עולם");
    assert!(
        !hebrew.contains("--"),
        "Hebrew slug must not have consecutive hyphens: {hebrew}"
    );
}

#[test]
fn markdown_rendering_unicode_safe() {
    // Verify markdown with CJK, RTL, emoji doesn't panic or corrupt
    let inputs = [
        "# 日本語見出し\n\nこんにちは世界",
        "# عنوان عربي\n\nمحتوى عربي",
        "# 🦀 Rust Crab\n\nEmoji content 🎉",
        "# Ñoño\n\nSpanish accents: á é í ó ú",
        "# Ελληνικά\n\nGreek content: αβγδ",
    ];

    for input in &inputs {
        let result = std::panic::catch_unwind(|| {
            let _ = ssg::markdown_ext::expand_gfm(input);
        });
        assert!(
            result.is_ok(),
            "Markdown rendering panicked on Unicode input: {input}"
        );
    }
}

#[test]
fn hreflang_tag_format() {
    // Verify i18n produces valid hreflang attributes
    let tag = "<link rel=\"alternate\" hreflang=\"en\" href=\"https://example.com/en/\">";
    assert!(tag.contains("hreflang=\"en\""));
    assert!(tag.contains("rel=\"alternate\""));
    assert!(tag.contains("href=\""));

    // Verify known locale codes are valid BCP 47
    let valid_codes = [
        "en", "fr", "de", "es", "it", "pt", "ja", "zh", "ko", "ar", "he", "ru",
        "nl", "pl", "sv", "cs", "th", "vi", "id", "uk", "hi", "bn", "ha", "yo",
        "tl", "ro", "zh-tw",
    ];
    for code in &valid_codes {
        assert!(
            code.len() >= 2 && code.len() <= 5,
            "Invalid BCP 47 code length: {code}"
        );
        assert!(
            code.chars().all(|c| c.is_ascii_lowercase() || c == '-'),
            "Invalid BCP 47 characters: {code}"
        );
    }
}

#[test]
fn reading_time_multilingual() {
    // 200 WPM baseline, must handle various scripts
    let _english = "word ".repeat(400); // 400 words → 2 min
    let time_en = ssg::stream::STREAM_BUFFER_SIZE; // Using as proxy — real fn is in ssg-core
    assert!(time_en > 0, "Buffer size must be positive");

    // CJK text — word splitting differs but must not panic
    let cjk = "日本語のテキスト ".repeat(100);
    let result = std::panic::catch_unwind(|| {
        let _ = ssg::markdown_ext::expand_gfm(&cjk);
    });
    assert!(result.is_ok(), "CJK processing must not panic");
}

// ═══════════════════════════════════════════════════════════════════════
// Plugin pipeline integrity
// ═══════════════════════════════════════════════════════════════════════

#[test]
fn fused_transforms_idempotent() {
    let dir = tempdir().unwrap();
    let site_dir = dir.path().join("site");
    generate_html_pages(&site_dir, 5);

    let ctx = ssg::plugin::PluginContext::new(
        dir.path(),
        dir.path(),
        &site_dir,
        dir.path(),
    );

    let mut plugins = ssg::plugin::PluginManager::new();
    plugins.register(ssg::postprocess::HtmlFixPlugin);
    plugins.register(ssg::seo::SeoPlugin);

    // Run transforms twice — output must be identical
    plugins.run_after_compile(&ctx).unwrap();
    plugins.run_fused_transforms(&ctx).unwrap();

    let html1 = fs::read_to_string(site_dir.join("page-0/index.html")).unwrap();

    plugins.run_after_compile(&ctx).unwrap();
    plugins.run_fused_transforms(&ctx).unwrap();

    let html2 = fs::read_to_string(site_dir.join("page-0/index.html")).unwrap();

    assert_eq!(html1, html2, "Fused transforms must be idempotent");
}

#[test]
fn plugin_order_deterministic() {
    let mut plugins = ssg::plugin::PluginManager::new();
    plugins.register(ssg::seo::SeoPlugin);
    plugins.register(ssg::search::SearchPlugin);
    plugins.register(ssg::postprocess::HtmlFixPlugin);

    let names: Vec<&str> = plugins.names();
    assert_eq!(names, vec!["seo", "search", "html-fix"]);

    // Register again in same order — must match
    let mut plugins2 = ssg::plugin::PluginManager::new();
    plugins2.register(ssg::seo::SeoPlugin);
    plugins2.register(ssg::search::SearchPlugin);
    plugins2.register(ssg::postprocess::HtmlFixPlugin);

    let names2: Vec<&str> = plugins2.names();
    assert_eq!(names, names2, "Plugin order must be deterministic");
}