|
| 1 | +#[path = "execute/loading.rs"] |
| 2 | +mod loading; |
| 3 | +#[path = "execute/result.rs"] |
| 4 | +mod result; |
| 5 | + |
1 | 6 | use anyhow::Result; |
2 | | -use std::path::{Path, PathBuf}; |
3 | 7 |
|
4 | 8 | use crate::config; |
5 | | -use crate::core::eval_benchmarks::FixtureResult as BenchmarkFixtureResult; |
6 | 9 | use crate::review::review_diff_content_raw; |
7 | 10 |
|
| 11 | +use self::loading::prepare_fixture_execution; |
| 12 | +use self::result::{append_total_comment_failures, build_benchmark_metrics, build_fixture_result}; |
8 | 13 | use super::super::{EvalFixtureResult, LoadedEvalFixture}; |
9 | 14 | use super::matching::evaluate_fixture_expectations; |
10 | 15 |
|
11 | 16 | pub(in super::super) async fn run_eval_fixture( |
12 | 17 | config: &config::Config, |
13 | 18 | loaded_fixture: LoadedEvalFixture, |
14 | 19 | ) -> Result<EvalFixtureResult> { |
15 | | - let LoadedEvalFixture { |
16 | | - fixture_path, |
17 | | - fixture, |
18 | | - suite_name, |
19 | | - suite_thresholds, |
20 | | - difficulty, |
21 | | - } = loaded_fixture; |
22 | | - let fixture_name = fixture.name.clone().unwrap_or_else(|| { |
23 | | - fixture_path |
24 | | - .file_name() |
25 | | - .and_then(|value| value.to_str()) |
26 | | - .unwrap_or("fixture") |
27 | | - .to_string() |
28 | | - }); |
29 | | - let fixture_dir = fixture_path |
30 | | - .parent() |
31 | | - .map(Path::to_path_buf) |
32 | | - .unwrap_or_else(|| PathBuf::from(".")); |
33 | | - |
34 | | - let diff_content = match (fixture.diff.clone(), fixture.diff_file.clone()) { |
35 | | - (Some(diff), _) => diff, |
36 | | - (None, Some(diff_file)) => { |
37 | | - let path = if diff_file.is_absolute() { |
38 | | - diff_file |
39 | | - } else { |
40 | | - fixture_dir.join(diff_file) |
41 | | - }; |
42 | | - std::fs::read_to_string(path)? |
43 | | - } |
44 | | - (None, None) => anyhow::bail!( |
45 | | - "Fixture '{}' must define either diff or diff_file", |
46 | | - fixture_name |
47 | | - ), |
48 | | - }; |
49 | | - |
50 | | - let repo_path = fixture |
51 | | - .repo_path |
52 | | - .clone() |
53 | | - .map(|path| { |
54 | | - if path.is_absolute() { |
55 | | - path |
56 | | - } else { |
57 | | - fixture_dir.join(path) |
58 | | - } |
59 | | - }) |
60 | | - .unwrap_or_else(|| PathBuf::from(".")); |
61 | | - |
62 | | - let review_result = review_diff_content_raw(&diff_content, config.clone(), &repo_path).await?; |
| 20 | + let prepared = prepare_fixture_execution(loaded_fixture)?; |
| 21 | + let review_result = |
| 22 | + review_diff_content_raw(&prepared.diff_content, config.clone(), &prepared.repo_path) |
| 23 | + .await?; |
63 | 24 | let comments = review_result.comments; |
64 | 25 | let total_comments = comments.len(); |
65 | | - let match_summary = evaluate_fixture_expectations(&fixture.expect, &comments); |
66 | | - let mut failures = match_summary.failures; |
67 | | - |
68 | | - if let Some(min_total) = fixture.expect.min_total { |
69 | | - if total_comments < min_total { |
70 | | - failures.push(format!( |
71 | | - "Expected at least {} comments, got {}", |
72 | | - min_total, total_comments |
73 | | - )); |
74 | | - } |
75 | | - } |
76 | | - if let Some(max_total) = fixture.expect.max_total { |
77 | | - if total_comments > max_total { |
78 | | - failures.push(format!( |
79 | | - "Expected at most {} comments, got {}", |
80 | | - max_total, total_comments |
81 | | - )); |
82 | | - } |
83 | | - } |
| 26 | + let match_summary = evaluate_fixture_expectations(&prepared.fixture.expect, &comments); |
| 27 | + let mut failures = match_summary.failures.clone(); |
84 | 28 |
|
85 | | - let benchmark_metrics = suite_name.as_ref().map(|_| { |
86 | | - let accounted_for = match_summary |
87 | | - .used_comment_indices |
88 | | - .union(&match_summary.unexpected_comment_indices) |
89 | | - .count(); |
90 | | - let extra_findings = total_comments.saturating_sub(accounted_for); |
91 | | - let mut result = BenchmarkFixtureResult::compute( |
92 | | - &fixture_name, |
93 | | - fixture.expect.must_find.len(), |
94 | | - fixture.expect.must_not_find.len(), |
95 | | - match_summary.required_matches, |
96 | | - match_summary.unexpected_comment_indices.len(), |
97 | | - extra_findings, |
98 | | - ); |
99 | | - result.details = failures.clone(); |
100 | | - result |
101 | | - }); |
| 29 | + append_total_comment_failures(&mut failures, total_comments, &prepared.fixture.expect); |
| 30 | + let benchmark_metrics = |
| 31 | + build_benchmark_metrics(&prepared, total_comments, &match_summary, &failures); |
102 | 32 |
|
103 | | - Ok(EvalFixtureResult { |
104 | | - fixture: fixture_name, |
105 | | - suite: suite_name, |
106 | | - passed: failures.is_empty(), |
| 33 | + Ok(build_fixture_result( |
| 34 | + prepared, |
107 | 35 | total_comments, |
108 | | - required_matches: match_summary.required_matches, |
109 | | - required_total: match_summary.required_total, |
| 36 | + match_summary, |
110 | 37 | benchmark_metrics, |
111 | | - suite_thresholds, |
112 | | - difficulty, |
113 | | - rule_metrics: match_summary.rule_metrics, |
114 | | - rule_summary: match_summary.rule_summary, |
115 | 38 | failures, |
116 | | - }) |
| 39 | + )) |
117 | 40 | } |
0 commit comments