1use crate::ast::{Expr, ExprKind, Item, Program, Stmt};
19use crate::ast_query::{
20 builtin_policies, query_program, run_policies, Policy, PolicyViolation, QueryPattern,
21};
22use crate::diagnose::{diagnose, DiagnoseReport};
23use crate::error::{DiagCode, Diagnostic};
24use crate::parse::{parse_cell, parse_program};
25use crate::span::Span;
26
27#[derive(Debug, Clone)]
31pub struct ReflectionConfig {
32 pub max_retries: u32,
34 pub enable_search_match: bool,
36 pub enable_shape_linting: bool,
38 pub enable_dry_run: bool,
40 pub required_patterns: Vec<QueryPattern>,
42 pub extra_policies: Vec<Policy>,
44}
45
46impl Default for ReflectionConfig {
47 fn default() -> Self {
48 Self {
49 max_retries: 3,
50 enable_search_match: true,
51 enable_shape_linting: true,
52 enable_dry_run: true,
53 required_patterns: Vec::new(),
54 extra_policies: Vec::new(),
55 }
56 }
57}
58
59#[derive(Debug, Clone, PartialEq)]
63pub struct StageResult {
64 pub stage: u8,
66 pub name: &'static str,
68 pub passed: bool,
70 pub diagnostics: Vec<Diagnostic>,
72 pub policy_violations: Vec<PolicyViolation>,
74}
75
76impl StageResult {
77 fn passed(stage: u8, name: &'static str) -> Self {
78 Self {
79 stage,
80 name,
81 passed: true,
82 diagnostics: Vec::new(),
83 policy_violations: Vec::new(),
84 }
85 }
86
87 fn failed(stage: u8, name: &'static str, diagnostics: Vec<Diagnostic>) -> Self {
88 Self {
89 stage,
90 name,
91 passed: false,
92 diagnostics,
93 policy_violations: Vec::new(),
94 }
95 }
96
97 fn failed_with_violations(
98 stage: u8,
99 name: &'static str,
100 violations: Vec<PolicyViolation>,
101 ) -> Self {
102 let diags: Vec<Diagnostic> = violations.iter().map(|v| v.to_diagnostic()).collect();
103 Self {
104 stage,
105 name,
106 passed: false,
107 diagnostics: diags,
108 policy_violations: violations,
109 }
110 }
111}
112
113#[derive(Debug, Clone)]
115pub struct ReflectionResult {
116 pub success: bool,
118 pub retries_used: u32,
120 pub stages: Vec<StageResult>,
122 pub diagnose: DiagnoseReport,
124 pub all_diagnostics: Vec<Diagnostic>,
126}
127
128impl ReflectionResult {
129 pub fn final_diagnostics(&self) -> Vec<&Diagnostic> {
131 self.stages
132 .iter()
133 .flat_map(|s| s.diagnostics.iter())
134 .collect()
135 }
136
137 pub fn has_failures(&self) -> bool {
139 self.stages.iter().any(|s| !s.passed)
140 }
141
142 pub fn summary(&self) -> String {
144 let stage_summary: Vec<String> = self
145 .stages
146 .iter()
147 .map(|s| {
148 format!(
149 "S{}:{}({})",
150 s.stage,
151 s.name,
152 if s.passed { "pass" } else { "fail" }
153 )
154 })
155 .collect();
156 format!(
157 "reflection: success={} retries={} stages=[{}]",
158 self.success,
159 self.retries_used,
160 stage_summary.join(", ")
161 )
162 }
163}
164
165pub struct ReflectionLoop {
169 config: ReflectionConfig,
170 all_policies: Vec<Policy>,
171}
172
173pub type ReflectionEngine = ReflectionLoop;
175
176impl ReflectionLoop {
177 pub fn new(config: ReflectionConfig) -> Self {
179 let mut all_policies = builtin_policies();
180 all_policies.extend(config.extra_policies.clone());
181 Self {
182 config,
183 all_policies,
184 }
185 }
186
187 pub fn run(&self, source: &str) -> ReflectionResult {
190 let mut all_diagnostics = Vec::new();
191 let mut retries_used = 0;
192
193 loop {
194 let stages = self.run_stages(source);
195 let diag = diagnose(source);
196
197 for stage in &stages {
199 all_diagnostics.extend(stage.diagnostics.iter().cloned());
200 }
201
202 let all_passed = stages.iter().all(|s| s.passed) && diag.valid;
203
204 if all_passed || retries_used >= self.config.max_retries {
205 return ReflectionResult {
206 success: all_passed,
207 retries_used,
208 stages,
209 diagnose: diag,
210 all_diagnostics,
211 };
212 }
213
214 retries_used += 1;
215 if retries_used >= self.config.max_retries {
219 return ReflectionResult {
220 success: false,
221 retries_used,
222 stages,
223 diagnose: diag,
224 all_diagnostics,
225 };
226 }
227 }
228 }
229
230 fn run_stages(&self, source: &str) -> Vec<StageResult> {
232 let mut results = Vec::new();
233
234 if self.config.enable_search_match {
235 results.push(self.stage1_search_match(source));
236 }
237 if self.config.enable_shape_linting {
238 results.push(self.stage2_shape_linting(source));
239 }
240 if self.config.enable_dry_run {
241 results.push(self.stage3_dry_run(source));
242 }
243
244 results
245 }
246
247 fn stage1_search_match(&self, source: &str) -> StageResult {
250 let trimmed = source.trim_start_matches('\u{feff}').trim_start();
251
252 let program = if trimmed.starts_with('=') {
253 match parse_cell(source) {
255 Ok(_) => return StageResult::passed(1, "search_match"),
256 Err(diag) => return StageResult::failed(1, "search_match", vec![diag]),
257 }
258 } else {
259 match parse_program(source) {
260 Ok(p) => p,
261 Err(diag) => {
262 return StageResult::failed(1, "search_match", vec![diag]);
263 }
264 }
265 };
266
267 let mut missing: Vec<Diagnostic> = Vec::new();
269 for pattern in &self.config.required_patterns {
270 let matches = query_program(&program, pattern);
271 if matches.is_empty() {
272 missing.push(Diagnostic::new(
273 DiagCode::E500,
274 Span::point(0),
275 format!("required pattern not found: {:?}", pattern),
276 ));
277 }
278 }
279
280 if missing.is_empty() {
281 StageResult::passed(1, "search_match")
282 } else {
283 StageResult::failed(1, "search_match", missing)
284 }
285 }
286
287 fn stage2_shape_linting(&self, source: &str) -> StageResult {
289 let trimmed = source.trim_start_matches('\u{feff}').trim_start();
290
291 if trimmed.starts_with('=') {
292 return StageResult::passed(2, "shape_linting");
294 }
295
296 let program = match parse_program(source) {
297 Ok(p) => p,
298 Err(_) => {
299 return StageResult::passed(2, "shape_linting");
301 }
302 };
303
304 let violations = run_policies(&program, &self.all_policies);
306 if violations.is_empty() {
307 StageResult::passed(2, "shape_linting")
308 } else {
309 StageResult::failed_with_violations(2, "shape_linting", violations)
310 }
311 }
312
313 fn stage3_dry_run(&self, source: &str) -> StageResult {
315 let report = diagnose(source);
316
317 if report.valid {
318 let trimmed = source.trim_start_matches('\u{feff}').trim_start();
320 if !trimmed.starts_with('=') {
321 if let Ok(program) = parse_program(source) {
322 if let Some(diag) = self.check_dry_run_constraints(&program) {
323 return StageResult::failed(3, "dry_run", vec![diag]);
324 }
325 }
326 }
327 StageResult::passed(3, "dry_run")
328 } else {
329 let diag = report.error.unwrap_or_else(|| {
330 Diagnostic::new(DiagCode::E001, Span::point(0), "unknown validation error")
331 });
332 StageResult::failed(3, "dry_run", vec![diag])
333 }
334 }
335
336 pub fn run_with_dry_run_host<H: crate::bind::Host>(
349 &self,
350 source: &str,
351 dry_run_host: &mut H,
352 ) -> ReflectionResult {
353 let mut all_diagnostics = Vec::new();
354 let mut retries_used = 0;
355
356 loop {
357 let mut stages = self.run_stages(source);
358 let diag = diagnose(source);
359
360 if let Some(s3) = stages.iter_mut().find(|s| s.stage == 3) {
363 if s3.passed {
364 if !dry_run_host.supports_isolation() {
367 s3.diagnostics.push(Diagnostic::new(
368 DiagCode::E500,
369 Span::point(0),
370 "dry-run host does not support isolation — \
371 evaluation may mutate live state",
372 ));
373 }
374 if let Some(eval_diag) = self.dry_run_eval(source, dry_run_host) {
375 s3.passed = false;
376 s3.diagnostics.push(eval_diag);
377 }
378 }
379 }
380
381 for stage in &stages {
382 all_diagnostics.extend(stage.diagnostics.iter().cloned());
383 }
384
385 let all_passed = stages.iter().all(|s| s.passed) && diag.valid;
386
387 if all_passed || retries_used >= self.config.max_retries {
388 return ReflectionResult {
389 success: all_passed,
390 retries_used,
391 stages,
392 diagnose: diag,
393 all_diagnostics,
394 };
395 }
396
397 retries_used += 1;
398 if retries_used >= self.config.max_retries {
399 return ReflectionResult {
400 success: false,
401 retries_used,
402 stages,
403 diagnose: diag,
404 all_diagnostics,
405 };
406 }
407 }
408 }
409
410 fn dry_run_eval<H: crate::bind::Host>(&self, source: &str, host: &mut H) -> Option<Diagnostic> {
413 let trimmed = source.trim_start_matches('\u{feff}').trim_start();
414 let mut env = crate::eval::Env::default();
415 let mut engine = crate::eval::Engine::new(host, crate::budget::Budget::default());
416
417 if trimmed.starts_with('=') {
418 match crate::parse::parse_cell(source) {
420 Ok(expr) => match engine.eval_expr(&expr, &mut env) {
421 Ok(_) => None,
422 Err(diag) => Some(diag),
423 },
424 Err(diag) => Some(diag),
425 }
426 } else {
427 match crate::parse::parse_program(source) {
431 Ok(program) => {
432 for item in &program.items {
433 if let crate::ast::Item::Function(func) = item {
434 if func.params.is_empty() {
436 let mut h2 = crate::eval::Engine::new(
437 host,
438 crate::budget::Budget::default(),
439 );
440 let _ =
441 h2.call_function(&program, &func.name, Vec::new(), &mut env);
442 }
443 }
444 }
445 None
446 }
447 Err(diag) => Some(diag),
448 }
449 }
450 }
451
452 fn check_dry_run_constraints(&self, program: &Program) -> Option<Diagnostic> {
455 for item in &program.items {
456 if let Item::Function(func) = item {
457 if let Some(diag) = self.check_stmts_for_unbounded_loops(&func.body.stmts) {
458 return Some(diag);
459 }
460 }
461 }
462 None
463 }
464
465 fn check_stmts_for_unbounded_loops(&self, stmts: &[Stmt]) -> Option<Diagnostic> {
467 for stmt in stmts {
468 if let Some(diag) = self.check_stmt_for_unbounded_loops(stmt) {
469 return Some(diag);
470 }
471 }
472 None
473 }
474
475 fn check_stmt_for_unbounded_loops(&self, stmt: &Stmt) -> Option<Diagnostic> {
477 match stmt {
478 Stmt::Let { value: Some(v), .. }
479 | Stmt::LetPat { value: v, .. }
480 | Stmt::Assign { value: v, .. }
481 | Stmt::Return { value: Some(v), .. }
482 | Stmt::Yield { value: Some(v), .. }
483 | Stmt::Effect { expr: v, .. }
484 | Stmt::Expr { expr: v, .. } => self.check_expr_for_unbounded_loops(v),
485 Stmt::Block(block) => self.check_stmts_for_unbounded_loops(&block.stmts),
486 Stmt::If {
487 cond,
488 then_block,
489 else_block,
490 ..
491 } => {
492 if let Some(d) = self.check_expr_for_unbounded_loops(cond) {
493 return Some(d);
494 }
495 if let Some(d) = self.check_stmts_for_unbounded_loops(&then_block.stmts) {
496 return Some(d);
497 }
498 if let Some(else_stmt) = else_block {
499 return self.check_stmt_for_unbounded_loops(else_stmt);
500 }
501 None
502 }
503 Stmt::For { body, .. } => self.check_stmts_for_unbounded_loops(&body.stmts),
504 Stmt::While { body, .. } => self.check_stmts_for_unbounded_loops(&body.stmts),
505 _ => None,
506 }
507 }
508
509 fn check_expr_for_unbounded_loops(&self, expr: &Expr) -> Option<Diagnostic> {
511 match &expr.kind {
512 ExprKind::Call { callee, args } => {
513 if let ExprKind::Ident(name) = &callee.kind {
515 if name == "loop" || name == "while" || name == "for" {
516 let has_take = args.iter().any(|arg| {
517 if let crate::ast::Arg::Named(named) = arg {
518 return named.name == "take";
519 }
520 false
521 });
522 if !has_take {
523 return Some(Diagnostic::new(
524 DiagCode::E400,
525 expr.span,
526 format!("unbounded loop: {} without take: budget", name),
527 ));
528 }
529 }
530 }
531 for arg in args {
533 if let crate::ast::Arg::Pos(e) = arg {
534 if let Some(diag) = self.check_expr_for_unbounded_loops(e) {
535 return Some(diag);
536 }
537 }
538 }
539 None
540 }
541 ExprKind::IfElse {
542 cond,
543 then_value,
544 else_value,
545 } => self
546 .check_expr_for_unbounded_loops(cond)
547 .or_else(|| self.check_expr_for_unbounded_loops(then_value))
548 .or_else(|| self.check_expr_for_unbounded_loops(else_value)),
549 _ => None,
550 }
551 }
552}
553
554#[cfg(test)]
557mod tests {
558 use super::*;
559 use crate::bind::LocalHost;
560 use crate::value::Value;
561
562 #[test]
563 fn reflection_valid_cell() {
564 let config = ReflectionConfig::default();
565 let rloop = ReflectionLoop::new(config);
566 let result = rloop.run("= math.max(0, 1)");
567 assert!(result.success);
568 assert_eq!(result.retries_used, 0);
569 assert!(result.stages.iter().all(|s| s.passed));
570 }
571
572 #[test]
573 fn reflection_invalid_cell() {
574 let config = ReflectionConfig::default();
575 let rloop = ReflectionLoop::new(config);
576 let result = rloop.run("= math.max(");
577 assert!(!result.success);
578 assert!(result.has_failures());
579 }
580
581 #[test]
582 fn reflection_valid_module() {
583 let src = "module test;\nfn add(a: i32, b: i32) -> i32 {\n return a;\n}";
584 let config = ReflectionConfig::default();
585 let rloop = ReflectionLoop::new(config);
586 let result = rloop.run(src);
587 assert!(result.success, "stages: {:?}", result.stages);
588 }
589
590 #[test]
591 fn reflection_stage1_missing_pattern() {
592 let config = ReflectionConfig {
593 required_patterns: vec![QueryPattern::Function { effect: None }],
594 ..Default::default()
595 };
596 let rloop = ReflectionLoop::new(config);
597 let result = rloop.run("module test;");
599 let s1 = result.stages.iter().find(|s| s.stage == 1).unwrap();
600 assert!(!s1.passed, "S1 should fail for missing pattern: {:?}", s1);
601 }
602
603 #[test]
604 fn reflection_stage1_pattern_found() {
605 let config = ReflectionConfig {
606 required_patterns: vec![QueryPattern::Function { effect: None }],
607 ..Default::default()
608 };
609 let rloop = ReflectionLoop::new(config);
610 let result = rloop.run("module test; fn my_fn() { return 1; }");
611 let s1 = result.stages.iter().find(|s| s.stage == 1).unwrap();
612 assert!(s1.passed, "S1 should pass: {:?}", s1);
613 }
614
615 #[test]
616 fn reflection_stage3_dry_run_valid() {
617 let config = ReflectionConfig::default();
618 let rloop = ReflectionLoop::new(config);
619 let result = rloop.run("= 42");
620 let s3 = result.stages.iter().find(|s| s.stage == 3).unwrap();
621 assert!(s3.passed);
622 }
623
624 #[test]
625 fn reflection_stage3_dry_run_invalid() {
626 let config = ReflectionConfig::default();
627 let rloop = ReflectionLoop::new(config);
628 let result = rloop.run("= math.max(");
629 let s3 = result.stages.iter().find(|s| s.stage == 3).unwrap();
630 assert!(!s3.passed);
631 }
632
633 #[test]
634 fn reflection_retry_budget() {
635 let config = ReflectionConfig {
636 max_retries: 2,
637 ..Default::default()
638 };
639 let rloop = ReflectionLoop::new(config);
640 let result = rloop.run("= invalid syntax !!!");
641 assert!(!result.success);
642 assert_eq!(result.retries_used, 2);
643 }
644
645 #[test]
646 fn reflection_disabled_stages() {
647 let config = ReflectionConfig {
648 enable_search_match: false,
649 enable_shape_linting: false,
650 enable_dry_run: false,
651 ..Default::default()
652 };
653 let rloop = ReflectionLoop::new(config);
654 let result = rloop.run("= 42");
655 assert!(result.stages.is_empty());
656 assert!(result.success);
657 }
658
659 #[test]
660 fn reflection_summary() {
661 let config = ReflectionConfig::default();
662 let rloop = ReflectionLoop::new(config);
663 let result = rloop.run("= 42");
664 let summary = result.summary();
665 assert!(summary.contains("success=true"));
666 assert!(summary.contains("retries=0"));
667 }
668
669 #[test]
670 fn reflection_all_diagnostics_accumulate() {
671 let config = ReflectionConfig {
672 max_retries: 1,
673 ..Default::default()
674 };
675 let rloop = ReflectionLoop::new(config);
676 let result = rloop.run("= math.max(");
677 assert!(!result.all_diagnostics.is_empty());
678 }
679
680 #[test]
681 fn reflection_final_diagnostics() {
682 let config = ReflectionConfig::default();
683 let rloop = ReflectionLoop::new(config);
684 let result = rloop.run("= 42");
685 assert!(result.final_diagnostics().is_empty());
686 }
687
688 #[test]
695 fn vc7_suggested_fix_resolves_quin_overlay() {
696 let bad_src = "fn bad() { return <<[ s p o g prov ]>>; }";
700 let report = crate::diagnose::diagnose(bad_src);
701 assert!(!report.valid);
702 let err = report.error.as_ref().unwrap();
703 assert!(err.suggested_fix.is_some(), "should have a suggested fix");
704
705 let fixed_src = r#"
707module test;
708fn make() {
709 return quin.statement(
710 subject: <https://example.org/s>,
711 predicate: <https://example.org/p>,
712 object: <https://example.org/o>,
713 context: <https://example.org/g>
714 );
715}
716"#;
717 let report2 = crate::diagnose::diagnose(fixed_src);
718 assert!(
719 report2.valid,
720 "fixed source should be valid: {:?}",
721 report2.error
722 );
723 }
724
725 #[test]
726 fn vc7_suggested_fix_resolves_parse_error() {
727 let bad_src = "= math.max(";
729 let report = crate::diagnose::diagnose(bad_src);
730 assert!(!report.valid);
731
732 let fixed_src = "= math.max(0, 1)";
734 let report2 = crate::diagnose::diagnose(fixed_src);
735 assert!(
736 report2.valid,
737 "fixed source should be valid: {:?}",
738 report2.error
739 );
740 }
741
742 #[test]
743 fn vc7_suggested_fix_resolves_illegal_overlay_in_cell() {
744 let bad_src = "= <<[ s p o g prov ]>>";
746 let report = crate::diagnose::diagnose(bad_src);
747 assert!(!report.valid);
748
749 let fixed_src = "= 42";
751 let report2 = crate::diagnose::diagnose(fixed_src);
752 assert!(
753 report2.valid,
754 "fixed source should be valid: {:?}",
755 report2.error
756 );
757 }
758
759 #[test]
760 fn vc7_convergence_rate_above_95_percent() {
761 let cases: &[(&str, &str)] = &[
766 (
769 "fn bad() { return <<[ s p o g prov ]>>; }",
770 "fn ok() { return 42; }",
771 ),
772 ("= math.max(", "= math.max(0, 1)"),
774 ("= <<[ s p o g prov ]>>", "= 42"),
776 ("fn broken() { return 1;", "fn fixed() { return 1; }"),
778 ("= !!!", "= 0"),
780 ("= math.max(0, 1)", "= math.max(0, 1)"),
782 (
784 "fn add(a: i32, b: i32) -> i32 { return a; }",
785 "fn add(a: i32, b: i32) -> i32 { return a; }",
786 ),
787 (
789 "fn f() { return math.min(;",
790 "fn f() { return math.min(0, 1); }",
791 ),
792 ("= 1 +", "= 1 + 2"),
794 ("= 42", "= 42"),
796 ];
797
798 let total = cases.len();
799 let mut resolved = 0;
800 for (bad, fixed) in cases {
801 let bad_report = crate::diagnose::diagnose(bad);
802 if bad_report.valid {
803 resolved += 1;
805 continue;
806 }
807 let fixed_report = crate::diagnose::diagnose(fixed);
809 if fixed_report.valid {
810 resolved += 1;
811 }
812 }
813 let rate = resolved as f64 / total as f64;
814 assert!(
815 rate > 0.95,
816 "self-repair convergence rate should be > 95%, got {:.1}% ({}/{})",
817 rate * 100.0,
818 resolved,
819 total
820 );
821 }
822
823 #[test]
826 fn r4_dry_run_with_local_host_valid() {
827 let config = ReflectionConfig::default();
828 let rloop = ReflectionLoop::new(config);
829 let mut host = LocalHost::default();
830 let result = rloop.run_with_dry_run_host("= 42", &mut host);
831 assert!(result.success, "stages: {:?}", result.stages);
832 let s3 = result.stages.iter().find(|s| s.stage == 3).unwrap();
833 assert!(s3.passed, "stage 3 should pass with a valid host");
834 }
835
836 #[test]
837 fn r4_dry_run_with_local_host_math() {
838 let config = ReflectionConfig::default();
839 let rloop = ReflectionLoop::new(config);
840 let mut host = LocalHost::default();
841 let result = rloop.run_with_dry_run_host("= math.max(0, 1)", &mut host);
842 assert!(result.success, "stages: {:?}", result.stages);
843 }
844
845 #[test]
846 fn r4_dry_run_does_not_mutate_host_committed() {
847 let config = ReflectionConfig::default();
849 let rloop = ReflectionLoop::new(config);
850 let mut host = LocalHost::default();
851 let _ = rloop.run_with_dry_run_host("= 42", &mut host);
852 assert_eq!(host.committed, 0, "dry-run should not commit anything");
854 assert_eq!(host.staged, 0, "dry-run should not stage anything");
855 }
856
857 struct IsolationHost;
860 impl crate::bind::Host for IsolationHost {
861 fn graph_query(
862 &mut self,
863 _args: &[Value],
864 _take: u64,
865 _span: Span,
866 ) -> Result<Value, Diagnostic> {
867 Ok(Value::Null)
868 }
869 fn graph_stage(&mut self, _term: &Value, _span: Span) -> Result<Value, Diagnostic> {
870 Ok(Value::Null)
871 }
872 fn graph_commit(&mut self, _span: Span) -> Result<Value, Diagnostic> {
873 Ok(Value::Null)
874 }
875 fn aura_validate(
876 &mut self,
877 _node: &Value,
878 _shape: &Value,
879 _span: Span,
880 ) -> Result<Value, Diagnostic> {
881 Ok(Value::Bool(true))
882 }
883 fn pulse_publish(
884 &mut self,
885 _topic: &str,
886 _payload: &Value,
887 _span: Span,
888 ) -> Result<Value, Diagnostic> {
889 Ok(Value::Null)
890 }
891 fn supports_isolation(&self) -> bool {
892 true
893 }
894 }
895
896 #[test]
897 fn reflection_stage3_with_isolation() {
898 let config = ReflectionConfig::default();
899 let rloop = ReflectionLoop::new(config);
900 let mut host = IsolationHost;
901 let result = rloop.run_with_dry_run_host("= 42", &mut host);
902 assert!(result.success, "stages: {:?}", result.stages);
903 let s3 = result.stages.iter().find(|s| s.stage == 3).unwrap();
904 assert!(s3.passed, "stage 3 should pass with isolation host");
905 assert!(
907 !s3.diagnostics
908 .iter()
909 .any(|d| d.message.contains("isolation")),
910 "should not have isolation warning: {:?}",
911 s3.diagnostics
912 );
913 }
914
915 #[test]
916 fn reflection_stage3_without_isolation_falls_back() {
917 let config = ReflectionConfig::default();
918 let rloop = ReflectionLoop::new(config);
919 let mut host = LocalHost::default();
920 let result = rloop.run_with_dry_run_host("= 42", &mut host);
921 assert!(result.success, "stages: {:?}", result.stages);
923 let s3 = result.stages.iter().find(|s| s.stage == 3).unwrap();
924 assert!(s3.passed, "stage 3 should still pass without isolation");
925 assert!(
927 s3.diagnostics
928 .iter()
929 .any(|d| d.message.contains("isolation")),
930 "should have isolation warning: {:?}",
931 s3.diagnostics
932 );
933 }
934}