phenotyper 0.3.0

Core compiler library for the Phenotyper structural artifact definition language
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
// SPDX-License-Identifier: Apache-2.0
//! End-to-end integration tests — validate the full pipeline from `.pht` source
//! through code generation and verify the generated code structure.

use phenotyper::diagnostic;

/// Helper: compile a .pht source and return the generated Rust code.
fn compile_ok(source: &str) -> String {
    match phenotyper::compile_source(source, "test.pht", None) {
        Ok(output) => {
            assert!(
                output.warnings.is_empty(),
                "unexpected warnings: {:?}",
                output.warnings
            );
            output.code
        }
        Err(errors) => {
            for e in &errors {
                eprintln!("{}", diagnostic::format_human(e));
            }
            panic!("compilation failed with {} error(s)", errors.len());
        }
    }
}

/// Helper: compile and expect errors.
fn compile_err(source: &str) -> Vec<phenotyper::diagnostic::Diagnostic> {
    match phenotyper::compile_source(source, "test.pht", None) {
        Ok(_) => panic!("expected compilation to fail"),
        Err(errors) => errors,
    }
}

// ═══════════════════════════════════════════════════════════════════════════
// T-113: CSV end-to-end
// ═══════════════════════════════════════════════════════════════════════════

#[test]
fn e2e_csv_fixture_compiles() {
    let source = include_str!("../../../tests/fixtures/valid/csv_basic.pht");
    let code = compile_ok(source);

    // Core structures
    assert!(
        code.contains("pub struct CsvFieldValue"),
        "missing CsvFieldValue struct"
    );
    assert!(
        code.contains("pub struct CsvFieldValues"),
        "missing CsvFieldValues struct"
    );
    assert!(
        code.contains("pub struct CsvLine"),
        "missing CsvLine struct"
    );
    assert!(
        code.contains("pub struct CsvLines"),
        "missing CsvLines struct"
    );
    assert!(
        code.contains("pub struct CsvFile"),
        "missing CsvFile struct"
    );

    // Union type
    assert!(
        code.contains("pub enum ScalarValue"),
        "missing ScalarValue enum"
    );
    assert!(code.contains("Int64(i64)"), "missing Int64 variant");
    assert!(code.contains("String(String)"), "missing String variant");

    // Builders
    assert!(
        code.contains("pub struct CsvFieldValueBuilder"),
        "missing builder"
    );
    assert!(
        code.contains("pub struct CsvLineBuilder"),
        "missing builder"
    );
    assert!(
        code.contains("pub struct CsvFileBuilder"),
        "missing builder"
    );

    // Plural builders
    assert!(
        code.contains("pub struct CsvFieldValuesBuilder"),
        "missing plural builder"
    );
    assert!(
        code.contains("pub struct CsvLinesBuilder"),
        "missing plural builder"
    );

    // Render implementations
    assert!(
        code.contains("impl Render for CsvFieldValue"),
        "missing Render impl"
    );
    assert!(
        code.contains("impl Render for CsvLine"),
        "missing Render impl"
    );
    assert!(
        code.contains("impl Render for CsvFile"),
        "missing Render impl"
    );
    assert!(
        code.contains("impl Render for CsvFieldValues"),
        "missing plural Render impl"
    );
    assert!(
        code.contains("impl Render for CsvLines"),
        "missing plural Render impl"
    );

    // Render trait
    assert!(code.contains("pub trait Render"), "missing Render trait");
    assert!(
        code.contains("fn render_into(&self, out: &mut String)"),
        "missing render_into"
    );

    // BuildError
    assert!(code.contains("pub enum BuildError"), "missing BuildError");
    assert!(
        code.contains("MissingField"),
        "missing MissingField variant"
    );
}

#[test]
fn e2e_csv_namespace() {
    let source = include_str!("../../../tests/fixtures/valid/csv_basic.pht");
    let output = phenotyper::compile_source(source, "test.pht", None).unwrap();
    assert_eq!(output.namespace, "aivolution/format/csv");
}

#[test]
fn e2e_csv_join_separator() {
    let source = include_str!("../../../tests/fixtures/valid/csv_basic.pht");
    let code = compile_ok(source);

    // CsvLine uses @join(fields, separator) — field-based separator
    assert!(
        code.contains("out.push_str(&self.separator)"),
        "missing field separator in join"
    );
}

// ═══════════════════════════════════════════════════════════════════════════
// T-114: Markdown container end-to-end
// ═══════════════════════════════════════════════════════════════════════════

#[test]
fn e2e_md_container_compiles() {
    // Compile the csv.md example (markdown with embedded ```pht blocks)
    let md_source = include_str!("../../../docs/examples/csv.md");
    let output = phenotyper::compile_source(md_source, "csv.md", None).unwrap();

    assert_eq!(output.namespace, "aivolution/format/csv");
    assert!(output.code.contains("pub struct CsvFieldValue"));
    assert!(output.code.contains("pub struct CsvLine"));
    assert!(output.code.contains("pub struct CsvFile"));
    assert!(output.code.contains("pub enum ScalarValue"));
    assert!(output.code.contains("pub trait Render"));
}

#[test]
fn e2e_md_all_examples_compile() {
    let examples = [
        ("csv.md", include_str!("../../../docs/examples/csv.md")),
        (
            "prompt.md",
            include_str!("../../../docs/examples/prompt.md"),
        ),
        (
            "config.md",
            include_str!("../../../docs/examples/config.md"),
        ),
        (
            "report.md",
            include_str!("../../../docs/examples/report.md"),
        ),
    ];

    for (name, source) in &examples {
        let result = phenotyper::compile_source(source, name, None);
        assert!(result.is_ok(), "{name} failed: {:?}", result.err());
    }
}

#[test]
fn e2e_md_no_pht_blocks_error() {
    // A markdown file with no ```pht blocks should produce an error
    let md = "# Just a regular markdown file\n\nNo phenotyper here.\n";
    let result = phenotyper::compile_source(md, "empty.md", None);
    assert!(result.is_err());
    let errors = result.unwrap_err();
    assert!(errors.iter().any(|e| e.summary.contains("no")));
}

// ═══════════════════════════════════════════════════════════════════════════
// T-115: Structured prompt end-to-end
// ═══════════════════════════════════════════════════════════════════════════

#[test]
fn e2e_prompt_compiles() {
    let source = include_str!("../../../tests/fixtures/valid/prompt.pht");
    let code = compile_ok(source);

    // Structs
    assert!(
        code.contains("pub struct PromptSection"),
        "missing PromptSection"
    );
    assert!(
        code.contains("pub struct PromptSections"),
        "missing PromptSections"
    );
    assert!(
        code.contains("pub struct SystemPrompt"),
        "missing SystemPrompt"
    );

    // Optional field
    assert!(
        code.contains("pub context: Option<String>"),
        "missing optional context"
    );

    // Text literals in render
    assert!(code.contains("# System Prompt"), "missing title literal");
    assert!(code.contains("You are "), "missing role prefix");

    // @ifset for optional context
    assert!(
        code.contains("if let Some(ref val) = self.context"),
        "missing @ifset codegen"
    );
}

#[test]
fn e2e_prompt_namespace() {
    let source = include_str!("../../../tests/fixtures/valid/prompt.pht");
    let output = phenotyper::compile_source(source, "test.pht", None).unwrap();
    assert_eq!(output.namespace, "aivolution/ai/prompt");
}

// ═══════════════════════════════════════════════════════════════════════════
// T-116: Union-heavy (config) end-to-end
// ═══════════════════════════════════════════════════════════════════════════

#[test]
fn e2e_config_compiles() {
    let source = include_str!("../../../tests/fixtures/valid/config.pht");
    let code = compile_ok(source);

    // Enum type
    assert!(
        code.contains("pub enum Visibility"),
        "missing Visibility enum"
    );
    assert!(code.contains("Public,"), "missing Public variant");
    assert!(code.contains("Private,"), "missing Private variant");
    assert!(code.contains("Internal,"), "missing Internal variant");

    // Enum renders original spelling
    assert!(
        code.contains("out.push_str(\"public\")"),
        "missing original-spelling render"
    );

    // Union type alias
    assert!(
        code.contains("pub enum ConfigValue"),
        "missing ConfigValue union"
    );
    assert!(code.contains("Int64(i64)"), "missing Int64 in union");
    assert!(code.contains("Bool(bool)"), "missing Bool in union");

    // Nested structures
    assert!(
        code.contains("pub struct ConfigEntry"),
        "missing ConfigEntry"
    );
    assert!(
        code.contains("pub struct ConfigEntries"),
        "missing ConfigEntries"
    );
    assert!(
        code.contains("pub struct ConfigSection"),
        "missing ConfigSection"
    );
    assert!(
        code.contains("pub struct ConfigSections"),
        "missing ConfigSections"
    );
    assert!(code.contains("pub struct ConfigFile"), "missing ConfigFile");

    // Text literals
    assert!(
        code.contains("out.push_str(\" = \")"),
        "missing ' = ' separator"
    );
    assert!(code.contains("out.push_str(\" [\")"), "missing ' [' prefix");
}

// ═══════════════════════════════════════════════════════════════════════════
// T-118: Optional-field (report) end-to-end
// ═══════════════════════════════════════════════════════════════════════════

#[test]
fn e2e_report_compiles() {
    let source = include_str!("../../../tests/fixtures/valid/report.pht");
    let code = compile_ok(source);

    // Structs
    assert!(code.contains("pub struct Report"), "missing Report");
    assert!(code.contains("pub struct ReportLine"), "missing ReportLine");
    assert!(code.contains("pub struct Tag"), "missing Tag");

    // Optional fields
    assert!(
        code.contains("pub subtitle: Option<String>"),
        "missing optional subtitle"
    );
    assert!(
        code.contains("pub footer: Option<String>"),
        "missing optional footer"
    );

    // Collection field (plural wrapper type)
    assert!(code.contains("pub tags: Tags"), "missing tags field");

    // @ifset for subtitle
    assert!(
        code.contains("if let Some(ref val) = self.subtitle"),
        "missing @ifset for subtitle"
    );

    // @ifset for footer
    assert!(
        code.contains("if let Some(ref val) = self.footer"),
        "missing @ifset for footer"
    );

    // @ifnotempty for tags (plural wrapper uses as_slice().is_empty())
    assert!(
        code.contains("if !self.tags.as_slice().is_empty()"),
        "missing @ifnotempty for tags"
    );
}

#[test]
fn e2e_report_join_tags() {
    let source = include_str!("../../../tests/fixtures/valid/report.pht");
    let code = compile_ok(source);

    // Tags joined with ", "
    assert!(
        code.contains("out.push_str(\", \")"),
        "missing tag join separator"
    );
}

// ═══════════════════════════════════════════════════════════════════════════
// T-108: CLI integration — error handling
// ═══════════════════════════════════════════════════════════════════════════

#[test]
fn e2e_compile_error_on_invalid_source() {
    let errors = compile_err("this is not valid phenotyper source");
    assert!(!errors.is_empty(), "expected parse errors");
}

#[test]
fn e2e_compile_error_on_missing_required_type() {
    let errors = compile_err(
        r#"
        test/types:
        Record:
            name: required UnknownType,
            @(name)
        ;
    .
    "#,
    );
    assert!(!errors.is_empty(), "expected symbol errors");
    assert!(
        errors.iter().any(|e| e.summary.contains("unknown type")),
        "expected 'unknown type' in error"
    );
}

// ═══════════════════════════════════════════════════════════════════════════
// File output (T-113 complement)
// ═══════════════════════════════════════════════════════════════════════════

#[test]
fn e2e_compile_writes_output() {
    let source = include_str!("../../../tests/fixtures/valid/csv_basic.pht");
    let out_dir = std::env::temp_dir().join("phenotyper-e2e-test");
    let _ = std::fs::remove_dir_all(&out_dir);

    let output = phenotyper::compile_source(source, "test.pht", Some(&out_dir)).unwrap();

    let expected_file = out_dir.join("aivolution/format/csv/mod.rs");
    assert!(expected_file.exists(), "output file not created");

    let written = std::fs::read_to_string(&expected_file).unwrap();
    assert_eq!(
        written, output.code,
        "written file doesn't match returned code"
    );

    // Cleanup
    let _ = std::fs::remove_dir_all(&out_dir);
}

// ═══════════════════════════════════════════════════════════════════════════
// Generated code quality checks
// ═══════════════════════════════════════════════════════════════════════════

#[test]
fn e2e_generated_code_has_header() {
    let source = include_str!("../../../tests/fixtures/valid/csv_basic.pht");
    let code = compile_ok(source);
    assert!(
        code.starts_with("// This file is @generated"),
        "missing @generated header"
    );
}

#[test]
fn e2e_generated_code_has_allow_attributes() {
    let source = include_str!("../../../tests/fixtures/valid/csv_basic.pht");
    let code = compile_ok(source);
    assert!(
        code.contains("#![allow(dead_code"),
        "missing #![allow] attribute"
    );
}

#[test]
fn e2e_all_fixtures_compile() {
    let fixtures = [
        include_str!("../../../tests/fixtures/valid/csv_basic.pht"),
        include_str!("../../../tests/fixtures/valid/prompt.pht"),
        include_str!("../../../tests/fixtures/valid/config.pht"),
        include_str!("../../../tests/fixtures/valid/report.pht"),
    ];

    for (i, source) in fixtures.iter().enumerate() {
        let result = phenotyper::compile_source(source, &format!("fixture_{i}.pht"), None);
        assert!(result.is_ok(), "fixture {i} failed: {:?}", result.err());
    }
}

// ═══════════════════════════════════════════════════════════════════════════
// T-095: Codegen compile tests — verify generated Rust compiles with rustc
// ═══════════════════════════════════════════════════════════════════════════

/// Helper: compile generated Rust code with `rustc` and check it passes.
fn assert_rustc_compiles(code: &str, label: &str) {
    use std::io::Write;

    let tmp_dir = std::env::temp_dir().join(format!("phenotyper-compile-test-{label}"));
    let _ = std::fs::remove_dir_all(&tmp_dir);
    std::fs::create_dir_all(&tmp_dir).unwrap();

    let src_file = tmp_dir.join("generated.rs");

    // The generated code already has #![allow(...)] — use it as-is with a main()
    let wrapped = format!("{code}\nfn main() {{}}\n");

    let mut file = std::fs::File::create(&src_file).unwrap();
    file.write_all(wrapped.as_bytes()).unwrap();

    let output = std::process::Command::new("rustc")
        .arg("--edition=2021")
        .arg("--crate-type=bin")
        .arg("-o")
        .arg(tmp_dir.join("test_binary").to_str().unwrap())
        .arg(src_file.to_str().unwrap())
        .output()
        .expect("rustc not found");

    let stderr = String::from_utf8_lossy(&output.stderr);
    assert!(
        output.status.success(),
        "generated Rust for '{label}' does not compile:\n{stderr}"
    );

    let _ = std::fs::remove_dir_all(&tmp_dir);
}

#[test]
fn t095_csv_generated_code_compiles() {
    let code = compile_ok(include_str!("../../../tests/fixtures/valid/csv_basic.pht"));
    assert_rustc_compiles(&code, "csv");
}

#[test]
fn t095_prompt_generated_code_compiles() {
    let code = compile_ok(include_str!("../../../tests/fixtures/valid/prompt.pht"));
    assert_rustc_compiles(&code, "prompt");
}

#[test]
fn t095_config_generated_code_compiles() {
    let code = compile_ok(include_str!("../../../tests/fixtures/valid/config.pht"));
    assert_rustc_compiles(&code, "config");
}

#[test]
fn t095_report_generated_code_compiles() {
    let code = compile_ok(include_str!("../../../tests/fixtures/valid/report.pht"));
    assert_rustc_compiles(&code, "report");
}

// ═══════════════════════════════════════════════════════════════════════════
// T-096: Codegen runtime tests — compile, run, and verify rendered output
// ═══════════════════════════════════════════════════════════════════════════

/// Helper: compile and run generated Rust code, returning stdout.
fn compile_and_run(code: &str, main_code: &str, label: &str) -> String {
    use std::io::Write;

    let tmp_dir = std::env::temp_dir().join(format!("phenotyper-runtime-test-{label}"));
    let _ = std::fs::remove_dir_all(&tmp_dir);
    std::fs::create_dir_all(&tmp_dir).unwrap();

    let src_file = tmp_dir.join("generated.rs");
    let binary = tmp_dir.join("test_binary");

    let wrapped = format!("{code}\nfn main() {{\n{main_code}\n}}\n");

    let mut file = std::fs::File::create(&src_file).unwrap();
    file.write_all(wrapped.as_bytes()).unwrap();

    let compile_output = std::process::Command::new("rustc")
        .arg("--edition=2021")
        .arg("-o")
        .arg(binary.to_str().unwrap())
        .arg(src_file.to_str().unwrap())
        .output()
        .expect("rustc not found");

    let compile_stderr = String::from_utf8_lossy(&compile_output.stderr);
    assert!(
        compile_output.status.success(),
        "compile failed for '{label}':\n{compile_stderr}"
    );

    let run_output = std::process::Command::new(&binary)
        .output()
        .expect("failed to run binary");

    assert!(run_output.status.success(), "runtime failed for '{label}'");

    let _ = std::fs::remove_dir_all(&tmp_dir);
    String::from_utf8(run_output.stdout).unwrap()
}

#[test]
fn t096_config_render_produces_correct_output() {
    let code = compile_ok(include_str!("../../../tests/fixtures/valid/config.pht"));

    let main_code = r#"
        let entry = ConfigEntry {
            key: "host".to_string(),
            value: ConfigValue::String("localhost".to_string()),
            visibility: Visibility::Public,
        };
        let rendered = entry.render();
        print!("{}", rendered);
    "#;

    let output = compile_and_run(&code, main_code, "config-render");
    assert_eq!(output, "host = localhost [public]");
}

#[test]
fn t096_prompt_render_produces_correct_output() {
    let code = compile_ok(include_str!("../../../tests/fixtures/valid/prompt.pht"));

    let main_code = r#"
        let section = PromptSection {
            heading: "Rules".to_string(),
            body: "Be concise.".to_string(),
        };
        let rendered = section.render();
        print!("{}", rendered);
    "#;

    let output = compile_and_run(&code, main_code, "prompt-render");
    assert_eq!(output, "## Rules\n\nBe concise.");
}

#[test]
fn t096_report_optional_fields_render() {
    let code = compile_ok(include_str!("../../../tests/fixtures/valid/report.pht"));

    // Test with subtitle present, tags empty, no footer
    let main_code = r#"
        let report = Report {
            title: "My Report".to_string(),
            subtitle: Some("Draft".to_string()),
            lines: ReportLines::from_vec(vec![
                ReportLine { content: "Line 1".to_string() },
                ReportLine { content: "Line 2".to_string() },
            ]),
            tags: Tags::new(),
            footer: None,
        };
        print!("{}", report.render());
    "#;

    let output = compile_and_run(&code, main_code, "report-optional");
    assert!(output.contains("# My Report\n"), "missing title");
    assert!(output.contains("## Draft\n"), "missing subtitle");
    assert!(output.contains("Line 1\nLine 2"), "missing lines");
    // Tags empty → @ifnotempty block should be absent
    assert!(
        !output.contains("Tags:"),
        "tags should be absent when empty"
    );
    // No footer
    assert!(!output.contains("---\n"), "footer should be absent");
}

// ═══════════════════════════════════════════════════════════════════════════
// T-268: Nested phenotypes end-to-end
// ═══════════════════════════════════════════════════════════════════════════

#[test]
fn e2e_nested_basic_compiles() {
    let source = include_str!("../../../tests/fixtures/valid/nested_basic.pht");
    let code = compile_ok(source);

    // Both Parent and Child should be generated as flat types
    assert!(code.contains("pub struct Parent"), "missing Parent struct");
    assert!(code.contains("pub struct Child"), "missing Child struct");

    // Both should have builders
    assert!(
        code.contains("pub struct ParentBuilder"),
        "missing ParentBuilder"
    );
    assert!(
        code.contains("pub struct ChildBuilder"),
        "missing ChildBuilder"
    );

    // Both get Render impls
    assert!(
        code.contains("impl Render for Parent"),
        "missing Parent Render"
    );
    assert!(
        code.contains("impl Render for Child"),
        "missing Child Render"
    );
}

#[test]
fn e2e_javaclass_compiles() {
    let source = include_str!("../../../tests/fixtures/valid/javaclass.pht");
    let code = compile_ok(source);

    // Enum type
    assert!(
        code.contains("pub enum Visibility"),
        "missing Visibility enum"
    );

    // Parent type structures
    assert!(
        code.contains("pub struct JavaClass"),
        "missing JavaClass struct"
    );
    assert!(
        code.contains("pub struct JavaClasses"),
        "missing JavaClasses struct"
    );

    // Nested type structures (flattened)
    assert!(
        code.contains("pub struct Constructor"),
        "missing Constructor struct"
    );
    assert!(
        code.contains("pub struct Constructors"),
        "missing Constructors struct"
    );
}

#[test]
fn e2e_javaclass_has_render_with_parent() {
    let source = include_str!("../../../tests/fixtures/valid/javaclass.pht");
    let code = compile_ok(source);

    // Constructor references @(JavaClass/name) → generates render_with_parent
    assert!(
        code.contains("render_with_parent"),
        "missing render_with_parent method"
    );
    assert!(
        code.contains("parent: &JavaClass"),
        "missing parent parameter type"
    );
    // The parent field access
    assert!(code.contains("parent.name"), "missing parent.name access");
}

#[test]
fn e2e_nested_basic_no_parent_context() {
    let source = include_str!("../../../tests/fixtures/valid/nested_basic.pht");
    let code = compile_ok(source);

    // nested_basic has no parent-scoped refs, so no render_with_parent
    assert!(
        !code.contains("render_with_parent"),
        "unexpected render_with_parent — nested_basic has no parent refs"
    );
}