star-toml 26.6.30

Framework for loading, layering, and validating any *.toml configuration file
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
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
//! Release verifier binary for checking the 19 release gate counterexamples.
//!
//! Exits non-zero if any counterexample is active or if git status is dirty (unless overridden).

#![allow(clippy::all, clippy::pedantic, unused_imports, dead_code)]

use std::{
    fs,
    path::{Path, PathBuf},
    process::Command,
};

struct Check {
    name: &'static str,
    passed: bool,
    note: String,
}

macro_rules! check {
    ($name:expr, $body:block) => {{
        let mut note = String::new();
        let passed = (|| -> bool {
            let res = $body;
            note = res.1;
            res.0
        })();
        Check { name: $name, passed, note }
    }};
}

fn strip_comments_and_strings(content: &str) -> String {
    let mut clean = String::new();
    let mut in_string = false;
    let mut chars = content.chars().peekable();
    while let Some(ch) = chars.next() {
        if in_string {
            if ch == '"' {
                in_string = false;
            } else if ch == '\\' {
                chars.next(); // skip escaped char
            }
        } else if ch == '"' {
            in_string = true;
        } else if ch == '/' && chars.peek() == Some(&'/') {
            // skip line comment
            while let Some(&c) = chars.peek() {
                if c == '\n' {
                    break;
                }
                chars.next();
            }
        } else {
            clean.push(ch);
        }
    }
    clean
}

fn parse_package_version(cargo_toml_path: &Path) -> Result<String, String> {
    let content = fs::read_to_string(cargo_toml_path)
        .map_err(|e| format!("Failed to read Cargo.toml: {}", e))?;
    let mut in_package = false;
    for line in content.lines() {
        let trimmed = line.trim();
        if trimmed.starts_with('[') {
            in_package = trimmed == "[package]";
        }
        if in_package && trimmed.starts_with("version") {
            let parts: Vec<&str> = trimmed.split('=').collect();
            if parts.len() == 2 {
                let ver = parts[1].trim().trim_matches('"').trim();
                return Ok(ver.to_string());
            }
        }
    }
    Err("version key not found under [package] section".to_string())
}

fn main() {
    let args: Vec<String> = std::env::args().collect();
    let dev_mode = args.iter().any(|a| a == "--dev")
        || std::env::var("STAR_TOML_DEV").map_or(false, |v| v == "1");

    println!("# star-toml v26.6.29 — Full ST-JSON Admission Release\n");
    if dev_mode {
        println!("(--dev mode: git-clean check bypassed)\n");
    }

    let results = run_release_checks(dev_mode);
    let mut failed = 0;

    println!("## Counterexample Gate\n");
    println!("| # | Check | Status | Note |");
    println!("|---|---|---|---|");
    for (i, c) in results.iter().enumerate() {
        let status = if c.passed {
            "PASS"
        } else {
            failed += 1;
            "FAIL"
        };
        println!("| {} | {} | **{}** | {} |", i + 1, c.name, status, c.note);
    }

    println!(
        "\nTotal: {}  Passed: {}  Failed: {}\n",
        results.len(),
        results.len() - failed,
        failed
    );

    // ── 10-Section DoD Standing Report ─────────────────────────────────────
    let pass = |checks: &[&str]| -> &'static str {
        let ok = checks
            .iter()
            .all(|name| results.iter().find(|c| c.name == *name).map_or(false, |c| c.passed));
        if ok {
            "PASS"
        } else {
            "FAIL"
        }
    };

    let s1 = pass(&["json_schema_bridge_standing"]);
    let s2 = pass(&["version_alignment_drift", "dependency_order_not_publishable"]);
    let s3 = pass(&["raw_parse_treated_as_trusted", "example_uses_non_admitted_path"]);
    let s4 = pass(&["docs_integrity_and_freshness"]);
    let s5 = pass(&["witness_claim_without_hash_input"]);
    let s6 = pass(&["deferred_feature_marked_complete", "doc_claim_not_backed_by_test"]);
    let s7 = pass(&["docs_integrity_and_freshness"]);
    let s8 = pass(&["json_schema_bridge_standing"]);
    let s9 = pass(&[
        "variant_axis_without_fixture",
        "detector_without_negative_fixture",
        "config_test_crate_present",
        "config_test_suite_passes",
    ]);
    let s10 = pass(&["wasm_pack_web_build", "wasm_pack_nodejs_build"]);

    let sections_all_pass =
        [s1, s2, s3, s4, s5, s6, s7, s8, s9, s10].iter().all(|&s| s == "PASS") && failed == 0;
    let final_standing = if sections_all_pass { "ADMITTED" } else { "REFUSED" };

    println!("## v26.6.29 Full ST-JSON Admission Release — Standing\n");
    println!("| # | Section | Status |");
    println!("|---|---|---|");
    println!("| 1 | JSON Schema Bridge Standing | **{}** |", s1);
    println!("| 2 | Schema Admission            | **{}** |", s2);
    println!("| 3 | Config Admission            | **{}** |", s3);
    println!("| 4 | Generated Docs Standing     | **{}** |", s4);
    println!("| 5 | Receipt Binding             | **{}** |", s5);
    println!("| 6 | Projection Freshness        | **{}** |", s6);
    println!("| 7 | DOC Diagnostics             | **{}** |", s7);
    println!("| 8 | SCH-JSON Diagnostics        | **{}** |", s8);
    println!("| 9 | DfCM Fixture Coverage       | **{}** |", s9);
    println!("|10 | star-toml-wasm              | **{}** |", s10);
    println!("|11 | Final Standing              | **{}** |", final_standing);

    println!("\n## Final: {}", final_standing);

    if final_standing == "REFUSED" {
        std::process::exit(1);
    }
}

fn run_release_checks(dev_mode: bool) -> Vec<Check> {
    let mut results = Vec::new();
    let root = Path::new(".");
    let _dev_mode = dev_mode;

    // 1. architecture_claim_without_invariant
    results.push(check!("architecture_claim_without_invariant", {
        let mut ok = true;
        let mut note = "Verified: star-toml-lsp does not bypass loader internals.".to_string();
        if let Ok(entries) = fs::read_dir(root.join("star-toml-lsp/src")) {
            for entry in entries.filter_map(Result::ok) {
                if let Ok(content) = fs::read_to_string(entry.path()) {
                    let clean = strip_comments_and_strings(&content);
                    if clean.contains("AdmittedConfig {") {
                        ok = false;
                        note = format!(
                            "LSP constructs AdmittedConfig directly in {:?}",
                            entry.file_name()
                        );
                        break;
                    }
                }
            }
        }
        (ok, note)
    }));

    // 2. public_api_without_example
    results.push(check!("public_api_without_example", {
        let mut ok = true;
        let mut note =
            "Verified: all core public API surface elements have matching examples.".to_string();
        let api_elements = vec![
            "TrustedLoader",
            "load_admitted",
            "load_admitted_exploratory",
            "ConfigWitness",
            "save_canonical",
        ];

        let mut examples_content = String::new();
        if let Ok(entries) = fs::read_dir(root.join("examples")) {
            for entry in entries.filter_map(Result::ok) {
                if entry.path().extension().map_or(false, |ext| ext == "rs") {
                    if let Ok(c) = fs::read_to_string(entry.path()) {
                        examples_content.push_str(&c);
                    }
                }
            }
        }

        for element in api_elements {
            if !examples_content.contains(element) {
                ok = false;
                note = format!("Public API item `{}` lacks example coverage.", element);
                break;
            }
        }
        (ok, note)
    }));

    // 3. public_api_without_lifecycle_position
    results.push(check!("public_api_without_lifecycle_position", {
        let mut ok = true;
        let mut note =
            "Verified: all public items are lifecycle-mapped in ST-102 or ST-112.".to_string();
        if let Ok(spec) =
            fs::read_to_string(root.join("docs/jira/v26.6.29/ST-112_release_standing.md"))
        {
            let api_elements = vec![
                "TrustedLoader",
                "load_admitted",
                "load_admitted_exploratory",
                "Validate",
                "Validator",
                "ConfigWitness",
                "AdmittedConfig",
                "save_canonical",
            ];
            for element in api_elements {
                if !spec.contains(element) {
                    ok = false;
                    note = format!(
                        "Public API item `{}` is not mapped in ST-112 specification.",
                        element
                    );
                    break;
                }
            }
        } else {
            ok = false;
            note = "ST-112 specification file is missing.".to_string();
        }
        (ok, note)
    }));

    // 4. doc_claim_not_backed_by_test
    results.push(check!("doc_claim_not_backed_by_test", {
        let mut ok = true;
        let mut note = "Verified: doc claims are backed by active tests.".to_string();
        let tests_content = fs::read_to_string(root.join("tests/brce.rs")).unwrap_or_default();
        let claims = vec![
            "test_forbidden_path_fails",
            "test_path_absolute_rejected_under_relative_only",
            "test_path_relative_traversal_rejected",
            "test_path_win_backslash_traversal_rejected",
        ];
        for claim in claims {
            if !tests_content.contains(claim) {
                ok = false;
                note = format!("Doc claim check `{}` is missing from tests/brce.rs.", claim);
                break;
            }
        }
        (ok, note)
    }));

    // 5. deferred_feature_marked_complete
    results.push(check!("deferred_feature_marked_complete", {
        let mut ok = true;
        let mut note = "Verified: no deferred features are marked complete.".to_string();
        if let Ok(spec) =
            fs::read_to_string(root.join("docs/jira/v26.6.28/ST-110_error_topology_lsp.md"))
        {
            if spec.contains("[x] Custom LSP Extension") || spec.contains("[x] Document Formatting")
            {
                ok = false;
                note =
                    "Deferred LSP features (formatting/extensions) are marked complete in ST-110."
                        .to_string();
            }
        }
        (ok, note)
    }));

    // 6. implemented_claim_without_gate
    results.push(check!("implemented_claim_without_gate", {
        let mut ok = true;
        let mut note =
            "Verified: implemented validation checkers have active test gates.".to_string();
        let test_methods =
            vec!["test_check_ip_or_domain", "test_check_size_format", "test_check_semver"];
        let validation_tests =
            fs::read_to_string(root.join("src/validation.rs")).unwrap_or_default();
        for test in test_methods {
            if !validation_tests.contains(test) {
                ok = false;
                note = format!(
                    "Validation checker test `{}` is missing from validation.rs unit tests.",
                    test
                );
                break;
            }
        }
        (ok, note)
    }));

    // 7. lsp_feature_claim_without_handler
    results.push(check!("lsp_feature_claim_without_handler", {
        let mut ok = true;
        let mut note = "Verified: all claimed LSP features have active handlers.".to_string();
        let server_content =
            fs::read_to_string(root.join("star-toml-lsp/src/server.rs")).unwrap_or_default();
        let claimed_features = vec![
            "completion_provider",
            "hover_provider",
            "document_symbol_provider",
            "code_action_provider",
        ];
        for feature in claimed_features {
            if !server_content.contains(feature) {
                ok = false;
                note = format!("LSP handler for `{}` is missing from server.rs.", feature);
                break;
            }
        }
        (ok, note)
    }));

    // 8. lsp_authority_boundary_violation
    results.push(check!("lsp_authority_boundary_violation", {
        let mut ok = true;
        let mut note =
            "Verified: star-toml-lsp has zero imports of core authority loader builders."
                .to_string();
        if let Ok(entries) = fs::read_dir(root.join("star-toml-lsp/src")) {
            for entry in entries.filter_map(Result::ok) {
                if let Ok(content) = fs::read_to_string(entry.path()) {
                    let clean = strip_comments_and_strings(&content);
                    if clean.contains("TrustedLoader::")
                        || clean.contains("load_admitted::<")
                        || clean.contains("use crate::TrustedLoader")
                    {
                        ok = false;
                        note = format!(
                            "LSP violates boundary by importing authority builders in {:?}",
                            entry.file_name()
                        );
                        break;
                    }
                }
            }
        }
        (ok, note)
    }));

    // 9. ocel_treated_as_standing_authority
    results.push(check!("ocel_treated_as_standing_authority", {
        let mut ok = true;
        let mut note =
            "Verified: OCEL history tracking is decoupled from authority / witness checks."
                .to_string();
        if let Ok(content) = fs::read_to_string(root.join("src/ocel.rs")) {
            let clean = strip_comments_and_strings(&content);
            if clean.contains("ConfigWitness")
                || clean.contains("witness")
                || clean.contains("q_config")
            {
                ok = false;
                note = "OCEL module references ConfigWitness or witness authority in code."
                    .to_string();
            }
        }
        (ok, note)
    }));

    // 10. raw_parse_treated_as_trusted
    results.push(check!("raw_parse_treated_as_trusted", {
        let mut ok = true;
        let mut note =
            "Verified: examples do not treat raw TOML parse as admitted config.".to_string();
        if let Ok(entries) = fs::read_dir(root.join("examples")) {
            for entry in entries.filter_map(Result::ok) {
                if entry.path().extension().map_or(false, |ext| ext == "rs") {
                    if let Ok(content) = fs::read_to_string(entry.path()) {
                        let clean = strip_comments_and_strings(&content);
                        if clean.contains("toml::from_str")
                            && !clean.contains("TrustedLoader")
                            && !clean.contains("load_admitted")
                        {
                            ok = false;
                            note = format!(
                                "Example {:?} treats raw parsing as trusted configuration.",
                                entry.file_name()
                            );
                            break;
                        }
                    }
                }
            }
        }
        (ok, note)
    }));

    // 11. example_uses_non_admitted_path
    results.push(check!("example_uses_non_admitted_path", {
        let mut ok = true;
        let mut note = "Verified: examples use admitted or frozen wrappers or standalone validators to access config state.".to_string();
        if let Ok(entries) = fs::read_dir(root.join("examples")) {
            for entry in entries.filter_map(Result::ok) {
                if entry.path().extension().map_or(false, |ext| ext == "rs") {
                    if let Ok(content) = fs::read_to_string(entry.path()) {
                        let clean = strip_comments_and_strings(&content);
                        if clean.contains("fn main") 
                           && !clean.contains("AdmittedConfig") 
                           && !clean.contains("load_admitted")
                           && !clean.contains("load_frozen")
                           && !clean.contains("load_admitted_exploratory")
                           && !clean.contains("resolve_and_validate")
                           && !clean.contains("export_events_to_ocel")
                           && !clean.contains(".check()")
                           && entry.file_name() != "dfcm_axes_matrix.rs" 
                           && entry.file_name() != "dfcm_common_patterns.rs"
                           && entry.file_name() != "red_team_counterexamples.rs" {
                            ok = false;
                            note = format!("Example {:?} lacks AdmittedConfig/Frozen/Standalone envelope usage.", entry.file_name());
                            break;
                        }
                    }
                }
            }
        }
        (ok, note)
    }));

    // 12. variant_axis_without_fixture
    results.push(check!("variant_axis_without_fixture", {
        let mut ok = true;
        let mut note = "Verified: all variant axes are covered by matching examples.".to_string();
        let examples_dir = root.join("examples");
        let required_examples = vec![
            "layered_profiles.rs",
            "env_overrides.rs",
            "strict_unknown_fields.rs",
            "exploratory_unknown_fields.rs",
            "path_policy_sandbox.rs",
            "witness_and_q_config.rs",
            "ocel_lifecycle_export.rs",
        ];
        for ex in required_examples {
            if !examples_dir.join(ex).exists() {
                ok = false;
                note = format!("Axis example file `{}` is missing.", ex);
                break;
            }
        }
        (ok, note)
    }));

    // 13. detector_without_negative_fixture
    results.push(check!("detector_without_negative_fixture", {
        let mut ok = true;
        let mut note = "Verified: verifier checks are covered by negative test gates.".to_string();
        if let Ok(content) = fs::read_to_string(root.join("tests/brce.rs")) {
            let required_tests = vec![
                "test_forbidden_path_fails",
                "test_missing_required_file_fails",
                "test_path_relative_traversal_rejected",
                "test_null_byte_fails",
            ];
            for t in required_tests {
                if !content.contains(t) {
                    ok = false;
                    note = format!("Verifier negative test `{}` is missing from tests/brce.rs.", t);
                    break;
                }
            }
        }
        (ok, note)
    }));

    // 14. witness_claim_without_hash_input
    results.push(check!("witness_claim_without_hash_input", {
        let mut ok = true;
        let mut note = "Verified: ConfigWitness correctly hashes sources, layers, envs, validation, and canonical TOML.".to_string();
        if let Ok(content) = fs::read_to_string(root.join("src/loader.rs")) {
            let required_hash_components = vec![
                "source_entries",
                "last_lod",
                "env_entries",
                "validation_fitness",
                "canonical_bytes",
            ];
            for component in required_hash_components {
                if !content.contains(component) {
                    ok = false;
                    note = format!("Witness hash input is missing required component: `{}`.", component);
                    break;
                }
            }
        }
        (ok, note)
    }));

    // 15. cargo_package_without_clean_git
    //
    // DfCM invariant: a release-standing gate cannot pass while the working
    // tree is dirty.  Any modified, staged, or untracked file is a FAIL.
    // There are no allowlisted exceptions — a clean release requires a clean
    // tree, full stop.
    results.push(check!("cargo_package_without_clean_git", {
        if _dev_mode {
            (true, "skipped in --dev mode".to_string())
        } else {
            let mut ok = true;
            let mut note = "Verified: git working tree is clean.".to_string();

            match Command::new("git").args(&["status", "--porcelain"]).output() {
                Err(e) => {
                    ok = false;
                    note = format!("Could not run git status: {}", e);
                }
                Ok(output) => {
                    let stdout = String::from_utf8_lossy(&output.stdout);
                    let dirty: Vec<&str> =
                        stdout.lines().map(|l| l.trim()).filter(|l| !l.is_empty()).collect();
                    if !dirty.is_empty() {
                        ok = false;
                        note = format!(
                            "Working tree is not clean — {} file(s) dirty/untracked: {:?}",
                            dirty.len(),
                            dirty
                        );
                    }
                }
            }
            (ok, note)
        }
    }));

    // 16. dependency_order_not_publishable
    results.push(check!("dependency_order_not_publishable", {
        let mut ok = true;
        let mut note =
            "Verified: workspace dependency hierarchy is valid and publishable.".to_string();
        if let Ok(content) = fs::read_to_string(root.join("star-toml-lsp/Cargo.toml")) {
            if !content.contains("path = \"..\"") {
                ok = false;
                note = "star-toml-lsp dependency configuration is invalid.".to_string();
            }
        }
        (ok, note)
    }));

    // 17. version_alignment_drift
    results.push(check!("version_alignment_drift", {
        let mut ok = true;
        let mut note = "Verified: workspace package versions and dependency specifications are fully aligned.".to_string();

        let root_ver = parse_package_version(&root.join("Cargo.toml"));
        let derive_ver = parse_package_version(&root.join("star-toml-derive/Cargo.toml"));
        let lsp_ver = parse_package_version(&root.join("star-toml-lsp/Cargo.toml"));

        match (root_ver, derive_ver, lsp_ver) {
            (Ok(rv), Ok(dv), Ok(lv)) => {
                if rv != dv {
                    ok = false;
                    note = format!("Version mismatch: star-toml ({}) vs star-toml-derive ({})", rv, dv);
                } else if rv != lv {
                    ok = false;
                    note = format!("Version mismatch: star-toml ({}) vs star-toml-lsp ({})", rv, lv);
                } else {
                    let root_content = fs::read_to_string(root.join("Cargo.toml")).unwrap_or_default();
                    let expected_version_str = format!("\"{}\"", rv);

                    let mut found_derive_dep = false;
                    for line in root_content.lines() {
                        let trimmed = line.trim();
                        if trimmed.starts_with("star-toml-derive") {
                            if trimmed.contains(&expected_version_str) {
                                found_derive_dep = true;
                                break;
                            }
                        }
                    }
                    if !found_derive_dep {
                        ok = false;
                        note = format!("Root Cargo.toml dependency on star-toml-derive does not specify version {}", rv);
                    }

                    let lsp_content = fs::read_to_string(root.join("star-toml-lsp/Cargo.toml")).unwrap_or_default();
                    let mut found_lsp_dep = false;
                    for line in lsp_content.lines() {
                        let trimmed = line.trim();
                        if trimmed.starts_with("star-toml") && !trimmed.starts_with("star-toml-lsp") {
                            if trimmed.contains(&expected_version_str) {
                                found_lsp_dep = true;
                                break;
                            }
                        }
                    }
                    if !found_lsp_dep {
                        ok = false;
                        note = format!("star-toml-lsp dependency on star-toml does not specify version {}", rv);
                    }
                }
            }
            (Err(e), _, _) => {
                ok = false;
                note = format!("Root Cargo.toml version error: {}", e);
            }
            (_, Err(e), _) => {
                ok = false;
                note = format!("star-toml-derive Cargo.toml version error: {}", e);
            }
            (_, _, Err(e)) => {
                ok = false;
                note = format!("star-toml-lsp Cargo.toml version error: {}", e);
            }
        }
        (ok, note)
    }));

    // 18. git_release_tag_missing
    results.push(check!("git_release_tag_missing", {
        let mut ok = true;
        let mut note = "Verified: a git tag matching the package version exists.".to_string();

        match parse_package_version(&root.join("Cargo.toml")) {
            Err(e) => {
                ok = false;
                note = format!("Root Cargo.toml version error: {}", e);
            }
            Ok(root_ver) => {
                let tag_name = format!("v{}", root_ver);
                match Command::new("git").args(&["tag"]).output() {
                    Err(e) => {
                        ok = false;
                        note = format!("Failed to run git tag: {}", e);
                    }
                    Ok(output) => {
                        let stdout = String::from_utf8_lossy(&output.stdout);
                        let mut found = false;
                        for line in stdout.lines() {
                            if line.trim() == tag_name {
                                found = true;
                                break;
                            }
                        }
                        if !found {
                            ok = false;
                            note = format!(
                                "Git tag `{}` matching version `{}` is missing.",
                                tag_name, root_ver
                            );
                        }
                    }
                }
            }
        }
        (ok, note)
    }));

    // 19. example_runtime_panic
    results.push(check!("example_runtime_panic", {
        let mut ok = true;
        let mut note =
            "Verified: all examples compile and run to completion (exit 0) successfully."
                .to_string();

        let mut failed_examples = Vec::new();
        if let Ok(entries) = fs::read_dir(root.join("examples")) {
            for entry in entries.filter_map(Result::ok) {
                if entry.path().extension().map_or(false, |ext| ext == "rs") {
                    let file_stem =
                        entry.path().file_stem().unwrap().to_string_lossy().into_owned();
                    let run_res = Command::new("cargo")
                        .args(&["run", "--quiet", "--example", &file_stem])
                        .output();
                    match run_res {
                        Err(e) => {
                            ok = false;
                            failed_examples
                                .push(format!("{} (failed to execute: {})", file_stem, e));
                        }
                        Ok(output) => {
                            if !output.status.success() {
                                ok = false;
                                let stderr = String::from_utf8_lossy(&output.stderr);
                                failed_examples.push(format!(
                                    "{} (exit code: {:?}, stderr: {})",
                                    file_stem,
                                    output.status.code(),
                                    stderr.trim()
                                ));
                            }
                        }
                    }
                }
            }
        }
        if !ok {
            note = format!("Examples failed to run successfully: {:?}", failed_examples);
        }
        (ok, note)
    }));

    // 20. docs_integrity_and_freshness
    results.push(check!("docs_integrity_and_freshness", {
        let mut ok = true;
        let mut note = "Verified: generated documentation is fresh and complete.".to_string();

        let run_res = Command::new("cargo")
            .args(&["run", "--quiet", "--bin", "star_toml_docs", "verify"])
            .output();

        match run_res {
            Err(e) => {
                ok = false;
                note = format!("Failed to execute star_toml_docs: {}", e);
            }
            Ok(output) => {
                if !output.status.success() {
                    ok = false;
                    let stderr = String::from_utf8_lossy(&output.stderr);
                    let stdout = String::from_utf8_lossy(&output.stdout);
                    note =
                        format!("Docs verification failed:\n{}\n{}", stdout.trim(), stderr.trim());
                }
            }
        }
        (ok, note)
    }));

    // 22. config_test_crate_present
    results.push(check!("config_test_crate_present", {
        let lib_path = root.join("star-toml-config-test/src/lib.rs");
        if lib_path.exists() {
            (true, "Verified: star-toml-config-test crate is present.".to_string())
        } else {
            (false, "star-toml-config-test/src/lib.rs is missing.".to_string())
        }
    }));

    // 23. config_test_suite_passes
    results.push(check!("config_test_suite_passes", {
        let mut ok = true;
        let mut note = "Verified: star-toml-config-test conformance suite passes.".to_string();
        match Command::new("cargo")
            .args(&["test", "--quiet", "-p", "star-toml-config-test"])
            .output()
        {
            Err(e) => {
                ok = false;
                note = format!("Failed to run config-test suite: {}", e);
            }
            Ok(output) => {
                if !output.status.success() {
                    ok = false;
                    let stderr = String::from_utf8_lossy(&output.stderr);
                    note = format!("Config-test suite failed: {}", stderr.trim());
                }
            }
        }
        (ok, note)
    }));

    // 21. json_schema_bridge_standing
    results.push(check!("json_schema_bridge_standing", {
        let mut ok = true;
        let mut note =
            "Verified: star-toml-json-schema bridge tests pass (SCH-JSON-001..016).".to_string();

        let run_res = Command::new("cargo")
            .args(&["test", "--quiet", "-p", "star-toml-json-schema", "--test", "bridge_tests"])
            .output();

        match run_res {
            Err(e) => {
                ok = false;
                note = format!("Failed to run bridge tests: {}", e);
            }
            Ok(output) => {
                if !output.status.success() {
                    ok = false;
                    let stderr = String::from_utf8_lossy(&output.stderr);
                    note = format!("JSON Schema bridge tests failed: {}", stderr.trim());
                }
            }
        }
        (ok, note)
    }));

    // 24. wasm_pack_web_build
    results.push(check!("wasm_pack_web_build", {
        let mut ok = true;
        let mut note = "Verified: wasm-pack build --target web succeeds.".to_string();
        match Command::new("wasm-pack")
            .args(&["build", "--target", "web", "--quiet"])
            .current_dir(root.join("../star-toml-wasm"))
            .output()
        {
            Err(e) => {
                ok = false;
                note = format!("Failed to invoke wasm-pack: {}", e);
            }
            Ok(output) => {
                if !output.status.success() {
                    ok = false;
                    let stderr = String::from_utf8_lossy(&output.stderr);
                    note = format!("wasm-pack web build failed: {}", stderr.trim());
                }
            }
        }
        (ok, note)
    }));

    // 25. wasm_pack_nodejs_build
    results.push(check!("wasm_pack_nodejs_build", {
        let mut ok = true;
        let mut note = "Verified: wasm-pack build --target nodejs succeeds.".to_string();
        match Command::new("wasm-pack")
            .args(&["build", "--target", "nodejs", "--quiet"])
            .current_dir(root.join("../star-toml-wasm"))
            .output()
        {
            Err(e) => {
                ok = false;
                note = format!("Failed to invoke wasm-pack: {}", e);
            }
            Ok(output) => {
                if !output.status.success() {
                    ok = false;
                    let stderr = String::from_utf8_lossy(&output.stderr);
                    note = format!("wasm-pack nodejs build failed: {}", stderr.trim());
                }
            }
        }
        (ok, note)
    }));

    results
}