zorath-env 0.3.9

Fast CLI for .env validation against JSON/YAML schemas. 14 types, secret detection, watch mode, remote schemas, 7 export formats, CI templates, health diagnostics, code scanning, auto-fix. Language-agnostic single binary.
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
use std::fs;
use std::path::Path;

use crate::config::Config;
use crate::envfile;
use crate::errors::CliError;
use crate::remote;
use crate::schema::{self, LoadOptions, SchemaFormat};

/// Health check result for a single item
struct HealthItem {
    name: String,
    status: HealthStatus,
    message: String,
    suggestion: Option<String>,
}

#[derive(Clone, Copy, Debug, PartialEq)]
enum HealthStatus {
    Ok,
    Warning,
    Error,
}

impl HealthStatus {
    fn symbol(&self) -> &'static str {
        match self {
            HealthStatus::Ok => "[OK]",
            HealthStatus::Warning => "[WARN]",
            HealthStatus::Error => "[ERROR]",
        }
    }
}

#[doc(hidden)]
pub fn run(env_path: &str, schema_path: &str, no_cache: bool, verify_hash: Option<&str>, ca_cert: Option<&str>) -> Result<(), CliError> {
    println!("zenv doctor - Health Check\n");

    let load_options = LoadOptions {
        no_cache,
        verify_hash: verify_hash.map(|s| s.to_string()),
        ca_cert: ca_cert.map(|s| s.to_string()),
        rate_limit_seconds: None,
    };

    let mut items = vec![
        // 1. Check schema file
        check_schema_path(schema_path, &load_options),
        // 2. Check .env file
        check_env_path(env_path),
        // 3. Check config file
        check_config_file(),
        // 4. Check remote schema cache
        check_cache(),
    ];

    // 5. Validation test (if both schema and env exist)
    if let Some(validation_result) = check_validation_paths(env_path, schema_path, &load_options) {
        items.push(validation_result);
    }

    // Print results
    let mut has_errors = false;
    let mut has_warnings = false;

    for item in &items {
        let status_str = item.status.symbol();
        println!("{} {}: {}", status_str, item.name, item.message);

        if let Some(ref suggestion) = item.suggestion {
            println!("     -> {}", suggestion);
        }

        match item.status {
            HealthStatus::Error => has_errors = true,
            HealthStatus::Warning => has_warnings = true,
            HealthStatus::Ok => {}
        }
    }

    // Summary
    println!();
    if has_errors {
        println!("Health check completed with errors.");
        Err(CliError::Validation("doctor found issues".into()))
    } else if has_warnings {
        println!("Health check completed with warnings.");
        Ok(())
    } else {
        println!("Health check passed. All systems operational.");
        Ok(())
    }
}

fn check_schema_path(schema_path: &str, load_options: &LoadOptions) -> HealthItem {
    // Check for common schema file locations
    let possible_paths = [
        schema_path,
        "env.schema.json",
        "env.schema.yaml",
        "env.schema.yml",
        ".env.schema.json",
    ];

    for path in &possible_paths {
        if Path::new(path).exists() {
            // Try to parse it
            match schema::load_schema_with_options(path, load_options) {
                Ok(schema) => {
                    let format = SchemaFormat::from_path(path);
                    return HealthItem {
                        name: "Schema".to_string(),
                        status: HealthStatus::Ok,
                        message: format!("Found {} ({} format, {} variables)", path, format.name(), schema.len()),
                        suggestion: None,
                    };
                }
                Err(e) => {
                    return HealthItem {
                        name: "Schema".to_string(),
                        status: HealthStatus::Error,
                        message: format!("Found {} but failed to parse", path),
                        suggestion: Some(format!("Fix schema error: {}", e)),
                    };
                }
            }
        }
    }

    HealthItem {
        name: "Schema".to_string(),
        status: HealthStatus::Warning,
        message: "No schema file found".to_string(),
        suggestion: Some("Run 'zenv init' to create one from .env.example".to_string()),
    }
}

fn check_env_path(env_path: &str) -> HealthItem {
    // Check for common env file locations
    let possible_paths = [
        env_path,
        ".env",
        ".env.local",
        ".env.development",
        ".env.development.local",
    ];

    for path in &possible_paths {
        if Path::new(path).exists() {
            // Try to parse it
            match envfile::parse_env_file(path) {
                Ok(env_map) => {
                    return HealthItem {
                        name: "Env file".to_string(),
                        status: HealthStatus::Ok,
                        message: format!("Found {} ({} variables)", path, env_map.len()),
                        suggestion: None,
                    };
                }
                Err(e) => {
                    return HealthItem {
                        name: "Env file".to_string(),
                        status: HealthStatus::Error,
                        message: format!("Found {} but failed to parse", path),
                        suggestion: Some(format!("Fix parse error: {}", e)),
                    };
                }
            }
        }
    }

    HealthItem {
        name: "Env file".to_string(),
        status: HealthStatus::Warning,
        message: "No .env file found".to_string(),
        suggestion: Some("Create .env or use 'zenv example' to generate a template".to_string()),
    }
}

fn check_config_file() -> HealthItem {
    let config_paths = [".zenvrc"];

    for path in &config_paths {
        if Path::new(path).exists() {
            // Try to parse it
            let content = match fs::read_to_string(path) {
                Ok(c) => c,
                Err(e) => {
                    return HealthItem {
                        name: "Config".to_string(),
                        status: HealthStatus::Error,
                        message: format!("Found {} but couldn't read it", path),
                        suggestion: Some(format!("Fix read error: {}", e)),
                    };
                }
            };

            match serde_json::from_str::<Config>(&content) {
                Ok(_) => {
                    return HealthItem {
                        name: "Config".to_string(),
                        status: HealthStatus::Ok,
                        message: format!("Found {} (valid)", path),
                        suggestion: None,
                    };
                }
                Err(e) => {
                    return HealthItem {
                        name: "Config".to_string(),
                        status: HealthStatus::Error,
                        message: format!("Found {} but it's invalid JSON", path),
                        suggestion: Some(format!("Fix JSON error: {}", e)),
                    };
                }
            }
        }
    }

    HealthItem {
        name: "Config".to_string(),
        status: HealthStatus::Ok,
        message: "No .zenvrc found (using defaults)".to_string(),
        suggestion: None,
    }
}

fn check_cache() -> HealthItem {
    let cache_dir = match remote::cache_dir() {
        Some(dir) => dir,
        None => {
            return HealthItem {
                name: "Cache".to_string(),
                status: HealthStatus::Warning,
                message: "Could not determine cache directory".to_string(),
                suggestion: None,
            };
        }
    };

    if !cache_dir.exists() {
        return HealthItem {
            name: "Cache".to_string(),
            status: HealthStatus::Ok,
            message: "No cache directory (remote schemas not used)".to_string(),
            suggestion: None,
        };
    }

    // Count cached schemas
    match fs::read_dir(&cache_dir) {
        Ok(entries) => {
            let count = entries.filter_map(|e| e.ok()).count();
            if count > 0 {
                HealthItem {
                    name: "Cache".to_string(),
                    status: HealthStatus::Ok,
                    message: format!("{} cached remote schema(s) at {}", count, cache_dir.display()),
                    suggestion: None,
                }
            } else {
                HealthItem {
                    name: "Cache".to_string(),
                    status: HealthStatus::Ok,
                    message: format!("Cache directory exists but is empty: {}", cache_dir.display()),
                    suggestion: None,
                }
            }
        }
        Err(e) => HealthItem {
            name: "Cache".to_string(),
            status: HealthStatus::Warning,
            message: format!("Couldn't read cache directory: {}", e),
            suggestion: Some("Run 'zenv cache clear' to reset".to_string()),
        },
    }
}

fn check_validation_paths(env_path: &str, schema_path: &str, load_options: &LoadOptions) -> Option<HealthItem> {
    // Both must exist for validation
    let schema_exists = Path::new(schema_path).exists();
    let env_exists = find_env_file(env_path).is_some();

    if !schema_exists || !env_exists {
        return None;
    }

    let resolved_env = find_env_file(env_path)?;

    // Load schema
    let schema = match schema::load_schema_with_options(schema_path, load_options) {
        Ok(s) => s,
        Err(_) => return None,
    };

    // Load env
    let env_map = match envfile::parse_env_file(&resolved_env) {
        Ok(m) => m,
        Err(_) => return None,
    };

    // Interpolate
    let env_map = match envfile::interpolate_env(env_map) {
        Ok(m) => m,
        Err(_) => return None,
    };

    // Validate
    let errors = crate::commands::check::validate(&schema, &env_map);

    if errors.is_empty() {
        Some(HealthItem {
            name: "Validation".to_string(),
            status: HealthStatus::Ok,
            message: "Schema validation passed".to_string(),
            suggestion: None,
        })
    } else {
        let error_count = errors.len();
        Some(HealthItem {
            name: "Validation".to_string(),
            status: HealthStatus::Error,
            message: format!("{} validation error(s) found", error_count),
            suggestion: Some("Run 'zenv check' for details".to_string()),
        })
    }
}

fn find_env_file(primary: &str) -> Option<String> {
    let paths = [
        primary,
        ".env",
        ".env.local",
        ".env.development",
        ".env.development.local",
    ];

    for path in &paths {
        if Path::new(path).exists() {
            return Some(path.to_string());
        }
    }
    None
}

#[cfg(test)]
mod tests {
    use super::*;

    fn default_load_options() -> LoadOptions {
        LoadOptions {
            no_cache: true,
            verify_hash: None,
            ca_cert: None,
            rate_limit_seconds: None,
        }
    }

    #[test]
    fn test_health_status_symbol() {
        assert_eq!(HealthStatus::Ok.symbol(), "[OK]");
        assert_eq!(HealthStatus::Warning.symbol(), "[WARN]");
        assert_eq!(HealthStatus::Error.symbol(), "[ERROR]");
    }

    #[test]
    fn test_check_schema_path_not_found() {
        // Note: If run from a directory with env.schema.json (like zenv root),
        // the function will find the fallback file and return Ok instead of Warning
        let result = check_schema_path("nonexistent_schema_12345.json", &default_load_options());
        // Either file not found (Warning) or fallback found (Ok/Error)
        assert!(
            result.status == HealthStatus::Warning
                || result.status == HealthStatus::Ok
                || result.status == HealthStatus::Error,
            "Expected Warning, Ok, or Error status"
        );
    }

    #[test]
    fn test_check_schema_path_found_valid() {
        let temp_dir = std::env::temp_dir();
        let schema_path = temp_dir.join("test_doctor_schema.json");
        std::fs::write(&schema_path, r#"{"FOO": {"type": "string"}}"#).unwrap();

        let result = check_schema_path(schema_path.to_str().unwrap(), &default_load_options());
        assert_eq!(result.status, HealthStatus::Ok);
        assert!(result.message.contains("Found"));
        assert!(result.message.contains("1 variables"));

        let _ = std::fs::remove_file(&schema_path);
    }

    #[test]
    fn test_check_schema_path_found_invalid() {
        let temp_dir = std::env::temp_dir();
        let schema_path = temp_dir.join("test_doctor_invalid_schema.json");
        std::fs::write(&schema_path, "{ invalid json }").unwrap();

        let result = check_schema_path(schema_path.to_str().unwrap(), &default_load_options());
        assert_eq!(result.status, HealthStatus::Error);
        assert!(result.message.contains("failed to parse"));
        assert!(result.suggestion.is_some());

        let _ = std::fs::remove_file(&schema_path);
    }

    #[test]
    fn test_check_env_path_not_found() {
        // Note: If run from a directory with .env (like zenv root),
        // the function will find the fallback file and return Ok instead of Warning
        let result = check_env_path("nonexistent_env_12345.env");
        // Either file not found (Warning) or fallback found (Ok/Error)
        assert!(
            result.status == HealthStatus::Warning
                || result.status == HealthStatus::Ok
                || result.status == HealthStatus::Error,
            "Expected Warning, Ok, or Error status"
        );
    }

    #[test]
    fn test_check_env_path_found_valid() {
        let temp_dir = std::env::temp_dir();
        let env_path = temp_dir.join("test_doctor.env");
        std::fs::write(&env_path, "FOO=bar\nBAZ=qux").unwrap();

        let result = check_env_path(env_path.to_str().unwrap());
        assert_eq!(result.status, HealthStatus::Ok);
        assert!(result.message.contains("Found"));
        assert!(result.message.contains("2 variables"));

        let _ = std::fs::remove_file(&env_path);
    }

    #[test]
    fn test_check_config_file_not_found() {
        // This test assumes no .zenvrc exists in the current directory
        // Since we're testing, this should be safe
        let result = check_config_file();
        // Either Ok (not found, using defaults) or found if one exists
        assert!(result.status == HealthStatus::Ok || result.status == HealthStatus::Error);
    }

    #[test]
    fn test_check_cache_returns_result() {
        // Cache check should always return a result (Ok or Warning)
        let result = check_cache();
        assert!(result.status == HealthStatus::Ok || result.status == HealthStatus::Warning);
        assert!(result.name == "Cache");
    }

    #[test]
    fn test_find_env_file_primary_exists() {
        let temp_dir = std::env::temp_dir();
        let env_path = temp_dir.join("test_find_env.env");
        std::fs::write(&env_path, "FOO=bar").unwrap();

        let result = find_env_file(env_path.to_str().unwrap());
        assert!(result.is_some());
        assert_eq!(result.unwrap(), env_path.to_str().unwrap());

        let _ = std::fs::remove_file(&env_path);
    }

    #[test]
    fn test_find_env_file_not_found() {
        let result = find_env_file("nonexistent_env_file_12345.env");
        // Will be None unless .env, .env.local, etc. exist in current dir
        // This is expected behavior - it checks fallbacks
        assert!(result.is_none() || result.is_some());
    }

    #[test]
    fn test_health_item_structure() {
        let item = HealthItem {
            name: "Test".to_string(),
            status: HealthStatus::Ok,
            message: "Test message".to_string(),
            suggestion: Some("Test suggestion".to_string()),
        };
        assert_eq!(item.name, "Test");
        assert_eq!(item.status, HealthStatus::Ok);
        assert_eq!(item.message, "Test message");
        assert_eq!(item.suggestion, Some("Test suggestion".to_string()));
    }

    #[test]
    fn test_check_validation_paths_returns_none_when_files_missing() {
        // When neither schema nor env exists, should return None
        let result = check_validation_paths(
            "nonexistent_env_12345.env",
            "nonexistent_schema_12345.json",
            &default_load_options(),
        );
        assert!(result.is_none());
    }

    // ====== Additional Doctor Scenario Tests ======

    #[test]
    fn test_check_schema_yaml_format() {
        let temp_dir = std::env::temp_dir();
        let schema_path = temp_dir.join("test_doctor_schema.yaml");
        std::fs::write(&schema_path, "FOO:\n  type: string\n  required: true\n").unwrap();

        let result = check_schema_path(schema_path.to_str().unwrap(), &default_load_options());
        assert_eq!(result.status, HealthStatus::Ok);
        assert!(result.message.contains("YAML") || result.message.contains("yaml"));

        let _ = std::fs::remove_file(&schema_path);
    }

    #[test]
    fn test_check_schema_multiple_variables() {
        let temp_dir = std::env::temp_dir();
        let schema_path = temp_dir.join("test_doctor_multi_schema.json");
        std::fs::write(
            &schema_path,
            r#"{
                "API_KEY": {"type": "string", "required": true},
                "DATABASE_URL": {"type": "url"},
                "PORT": {"type": "int", "default": "3000"}
            }"#,
        )
        .unwrap();

        let result = check_schema_path(schema_path.to_str().unwrap(), &default_load_options());
        assert_eq!(result.status, HealthStatus::Ok);
        assert!(result.message.contains("3 variables"));

        let _ = std::fs::remove_file(&schema_path);
    }

    #[test]
    fn test_check_env_with_comments_and_empty_lines() {
        let temp_dir = std::env::temp_dir();
        let env_path = temp_dir.join("test_doctor_comments.env");
        std::fs::write(
            &env_path,
            "# This is a comment\n\nFOO=bar\n\n# Another comment\nBAZ=qux\n",
        )
        .unwrap();

        let result = check_env_path(env_path.to_str().unwrap());
        assert_eq!(result.status, HealthStatus::Ok);
        // Should count only actual variables, not comments/empty lines
        assert!(result.message.contains("2 variables"));

        let _ = std::fs::remove_file(&env_path);
    }

    #[test]
    fn test_check_validation_passes() {
        let temp_dir = std::env::temp_dir();
        let schema_path = temp_dir.join("test_doctor_val_schema.json");
        let env_path = temp_dir.join("test_doctor_val.env");

        std::fs::write(&schema_path, r#"{"PORT": {"type": "int", "required": true}}"#).unwrap();
        std::fs::write(&env_path, "PORT=3000").unwrap();

        let result = check_validation_paths(
            env_path.to_str().unwrap(),
            schema_path.to_str().unwrap(),
            &default_load_options(),
        );

        assert!(result.is_some());
        let item = result.unwrap();
        assert_eq!(item.status, HealthStatus::Ok);
        assert!(item.message.contains("passed"));

        let _ = std::fs::remove_file(&schema_path);
        let _ = std::fs::remove_file(&env_path);
    }

    #[test]
    fn test_check_validation_fails_missing_required() {
        let temp_dir = std::env::temp_dir();
        let schema_path = temp_dir.join("test_doctor_val_fail_schema.json");
        let env_path = temp_dir.join("test_doctor_val_fail.env");

        std::fs::write(
            &schema_path,
            r#"{"API_KEY": {"type": "string", "required": true}}"#,
        )
        .unwrap();
        std::fs::write(&env_path, "OTHER_VAR=value").unwrap();

        let result = check_validation_paths(
            env_path.to_str().unwrap(),
            schema_path.to_str().unwrap(),
            &default_load_options(),
        );

        assert!(result.is_some());
        let item = result.unwrap();
        assert_eq!(item.status, HealthStatus::Error);
        assert!(item.message.contains("error"));
        assert!(item.suggestion.is_some());

        let _ = std::fs::remove_file(&schema_path);
        let _ = std::fs::remove_file(&env_path);
    }

    #[test]
    fn test_check_validation_fails_type_mismatch() {
        let temp_dir = std::env::temp_dir();
        let schema_path = temp_dir.join("test_doctor_type_schema.json");
        let env_path = temp_dir.join("test_doctor_type.env");

        std::fs::write(&schema_path, r#"{"PORT": {"type": "int", "required": true}}"#).unwrap();
        std::fs::write(&env_path, "PORT=not_a_number").unwrap();

        let result = check_validation_paths(
            env_path.to_str().unwrap(),
            schema_path.to_str().unwrap(),
            &default_load_options(),
        );

        assert!(result.is_some());
        let item = result.unwrap();
        assert_eq!(item.status, HealthStatus::Error);

        let _ = std::fs::remove_file(&schema_path);
        let _ = std::fs::remove_file(&env_path);
    }

    #[test]
    fn test_health_item_without_suggestion() {
        let item = HealthItem {
            name: "Test".to_string(),
            status: HealthStatus::Ok,
            message: "All good".to_string(),
            suggestion: None,
        };
        assert!(item.suggestion.is_none());
    }

    #[test]
    fn test_health_status_equality() {
        assert_eq!(HealthStatus::Ok, HealthStatus::Ok);
        assert_eq!(HealthStatus::Warning, HealthStatus::Warning);
        assert_eq!(HealthStatus::Error, HealthStatus::Error);
        assert_ne!(HealthStatus::Ok, HealthStatus::Error);
        assert_ne!(HealthStatus::Warning, HealthStatus::Error);
    }

    #[test]
    fn test_check_env_with_quoted_values() {
        let temp_dir = std::env::temp_dir();
        let env_path = temp_dir.join("test_doctor_quoted.env");
        std::fs::write(
            &env_path,
            r#"
FOO="bar with spaces"
BAZ='single quoted'
PLAIN=noquotes
"#,
        )
        .unwrap();

        let result = check_env_path(env_path.to_str().unwrap());
        assert_eq!(result.status, HealthStatus::Ok);
        assert!(result.message.contains("3 variables"));

        let _ = std::fs::remove_file(&env_path);
    }

    #[test]
    fn test_check_schema_empty_but_valid() {
        let temp_dir = std::env::temp_dir();
        let schema_path = temp_dir.join("test_doctor_empty_schema.json");
        std::fs::write(&schema_path, "{}").unwrap();

        let result = check_schema_path(schema_path.to_str().unwrap(), &default_load_options());
        assert_eq!(result.status, HealthStatus::Ok);
        assert!(result.message.contains("0 variables"));

        let _ = std::fs::remove_file(&schema_path);
    }

    #[test]
    fn test_check_env_with_multiline_value() {
        let temp_dir = std::env::temp_dir();
        let env_path = temp_dir.join("test_doctor_multiline.env");
        std::fs::write(
            &env_path,
            r#"SINGLE=value
MULTI="line1
line2
line3"
ANOTHER=final
"#,
        )
        .unwrap();

        let result = check_env_path(env_path.to_str().unwrap());
        // Should successfully parse multiline values
        assert_eq!(result.status, HealthStatus::Ok);

        let _ = std::fs::remove_file(&env_path);
    }

    #[test]
    fn test_check_validation_with_interpolation() {
        let temp_dir = std::env::temp_dir();
        let schema_path = temp_dir.join("test_doctor_interp_schema.json");
        let env_path = temp_dir.join("test_doctor_interp.env");

        // Include HOST in schema so it's not flagged as unknown
        std::fs::write(
            &schema_path,
            r#"{
                "HOST": {"type": "hostname", "required": true},
                "FULL_URL": {"type": "url", "required": true}
            }"#,
        )
        .unwrap();
        std::fs::write(
            &env_path,
            "HOST=example.com\nFULL_URL=https://${HOST}/api",
        )
        .unwrap();

        let result = check_validation_paths(
            env_path.to_str().unwrap(),
            schema_path.to_str().unwrap(),
            &default_load_options(),
        );

        // Should pass if interpolation works correctly
        assert!(result.is_some());
        let item = result.unwrap();
        assert_eq!(item.status, HealthStatus::Ok, "Interpolated URL should be valid");

        let _ = std::fs::remove_file(&schema_path);
        let _ = std::fs::remove_file(&env_path);
    }
}