Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 138 additions & 12 deletions rust/execution/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2680,6 +2680,15 @@ impl Boundary {
let s = name.to_string_lossy();
s.ends_with(".sln") || s.ends_with(".csproj")
});
let is_java_repo = self.root.join("pom.xml").is_file()
|| self.root.join("build.gradle").is_file()
|| self.root.join("build.gradle.kts").is_file()
|| self.written.iter().any(|file| file.ends_with(".java"))
|| self
.document
.files_allowed
.iter()
.any(|file| file.ends_with(".java"));
let mut queue = vec![self.root.clone()];
let mut audit = BTreeMap::new();
let mut visited = 0;
Expand All @@ -2706,6 +2715,10 @@ impl Boundary {
.split('/')
.any(|part| matches!(part, "__pycache__" | ".pytest_cache"))
|| (is_dotnet_repo && file.split('/').any(|part| matches!(part, "bin" | "obj")))
|| (is_java_repo
&& file
.split('/')
.any(|part| matches!(part, "target" | "build")))
|| file.ends_with(".pyc")
|| [".roster/locks", ".roster/checkpoints"]
.iter()
Expand All @@ -2718,8 +2731,8 @@ impl Boundary {
continue;
}
visited += 1;
if visited > 8192 {
return Err(denied("Verification worktree audit exceeds 8192 entries"));
if visited > MAX_TREE_ENTRIES {
return Err(denied("Verification worktree audit exceeds 32768 entries"));
}
let metadata = fs::symlink_metadata(&target)
.map_err(|error| secure::io_error("Inspect audit entry", &target, error))?;
Expand Down Expand Up @@ -3312,14 +3325,100 @@ impl Boundary {
)
.await?;
} else {
result.output = pytest_out;
let pytest_combined = format!(
"{}\n{}",
String::from_utf8_lossy(&pytest_out.stdout),
String::from_utf8_lossy(&pytest_out.stderr)
);
if pytest_out.exit != 0 && Self::is_pytest_missing_fixture_only(&pytest_combined) {
let changed_tests = self.changed_python_tests(&test_files).await;
if !changed_tests.is_empty() {
let expr = changed_tests.join(" or ");
let mut scoped_args = vec![
"-B".to_owned(),
"-m".to_owned(),
"pytest".to_owned(),
"-p".to_owned(),
"no:cacheprovider".to_owned(),
];
scoped_args.extend(test_files.clone());
scoped_args.push("-k".to_owned());
scoped_args.push(expr.clone());
result.commands.push(format!(
"python3 -B -m pytest {} -k \"{}\"",
test_files.join(" "),
expr
));
result.output = self
.process(
&python,
&scoped_args,
&environment,
policy::FULL_TEST_TIMEOUT_MS,
4 * 1024 * 1024,
)
.await?;
} else {
result.output = pytest_out;
}
} else {
result.output = pytest_out;
}
}
} else {
result.output.stdout = b"python3 -m py_compile passed".to_vec();
}
Ok(result)
}

pub(crate) fn is_pytest_missing_fixture_only(output: &str) -> bool {
let has_missing_fixture = (output.contains("fixture '") && output.contains("' not found"))
|| output.contains("recursive dependency involving fixture '");
if !has_missing_fixture {
return false;
}
let summary = output
.lines()
.rev()
.find(|line| line.contains(" in ") && line.contains("===="))
.unwrap_or_default();
(summary.contains(" error") || output.contains("ERROR ")) && !summary.contains(" failed")
}

async fn changed_python_tests(&self, test_files: &[String]) -> Vec<String> {
let mut diff_args = vec![
"diff".to_owned(),
"-U0".to_owned(),
"HEAD".to_owned(),
"--".to_owned(),
];
diff_args.extend(test_files.iter().cloned());
let Ok(raw) = self.git(&diff_args, &BTreeMap::new()).await else {
return Vec::new();
};
let text = String::from_utf8_lossy(&raw);
let mut names = Vec::new();
for line in text.lines() {
if let Some(rest) = line.strip_prefix('+') {
let trimmed = rest.trim_start();
if let Some(after) = trimmed.strip_prefix("def ")
&& let Some(name) = after.split('(').next()
{
let name = name.trim();
if name.starts_with("test_")
&& name
.chars()
.all(|ch| ch.is_ascii_alphanumeric() || ch == '_')
&& !names.iter().any(|existing: &String| existing == name)
{
names.push(name.to_owned());
}
}
}
}
names
}

async fn dotnet_checks(&self, scope: &[String]) -> Result<NodeChecks, Error> {
let bin_name = if cfg!(windows) {
"dotnet.exe"
Expand Down Expand Up @@ -3652,21 +3751,33 @@ impl Boundary {
unsupported("Java verification requires Maven (mvnw/mvn); no Maven tool was found")
})?;
let mut filters = Vec::new();
let mut modules = Vec::new();
for file in scope.iter().chain(self.written.iter()) {
if file.ends_with(".java")
&& file.contains("Test")
&& let Some(stem) = Path::new(file).file_stem().and_then(|s| s.to_str())
&& !filters.iter().any(|existing: &String| existing == stem)
{
filters.push(stem.to_owned());
if file.ends_with(".java") {
if let Some(module) = self.maven_module_for_path(file)
&& !modules.iter().any(|existing: &String| existing == &module)
{
modules.push(module);
}
if file.contains("Test")
&& let Some(stem) = Path::new(file).file_stem().and_then(|s| s.to_str())
&& !filters.iter().any(|existing: &String| existing == stem)
{
filters.push(stem.to_owned());
}
}
}
let mut online_args = vec![
"-B".to_owned(),
let mut online_args = vec!["-B".to_owned()];
if !modules.is_empty() {
online_args.push("-pl".to_owned());
online_args.push(modules.join(","));
online_args.push("-am".to_owned());
}
online_args.extend([
"test".to_owned(),
"-DfailIfNoTests=false".to_owned(),
"-Drat.skip=true".to_owned(),
];
]);
if !filters.is_empty() {
online_args.push(format!("-Dtest={}", filters.join(",")));
}
Expand Down Expand Up @@ -3744,6 +3855,21 @@ impl Boundary {
|| (output.contains("PluginResolutionException") && output.contains("offline"))
}

fn maven_module_for_path(&self, file: &str) -> Option<String> {
let mut current = Path::new(file).parent();
while let Some(dir) = current {
let rel = dir.to_string_lossy().replace('\\', "/");
if rel.is_empty() || rel == "." {
break;
}
if self.root.join(dir).join("pom.xml").is_file() {
return Some(rel);
}
current = dir.parent();
}
None
}

pub(crate) fn is_maven_resolution_error(output: &str) -> bool {
output.contains("PluginResolutionException")
|| output.contains("DependencyResolutionException")
Expand Down
Loading
Loading