diff --git a/services/worker/src/passes/dep_fix.rs b/services/worker/src/passes/dep_fix.rs index 89667f13..325db7e8 100644 --- a/services/worker/src/passes/dep_fix.rs +++ b/services/worker/src/passes/dep_fix.rs @@ -294,11 +294,21 @@ struct Probe<'a> { families: Vec, } +/// What a probe's build wrote: the manifests and lockfiles, and which of +/// them it left executable (committed as such when new). +#[derive(Default)] +struct Written { + files: Vec<(String, String)>, + executable: Vec, +} + /// One probe's result and the manifests and lockfiles it wrote. #[derive(Default)] struct Probed { result: ProbeResult, files: Vec<(String, String)>, + /// The paths of `files` the build left executable. + executable: Vec, /// Packages whose parent was raised instead of an override, and that /// the lockfile the probe wrote still installs below the fixed version. parent_unmoved: Vec, @@ -389,6 +399,11 @@ impl Probe<'_> { .into_iter() .filter(|(p, _)| df::commit_path(p)) .collect(); + let executable: Vec = o + .executable + .into_iter() + .filter(|p| files.iter().any(|(f, _)| f == p)) + .collect(); let tail = common::tail_str(&o.output, 3000).to_string(); let mut result = ProbeResult { ran, @@ -419,6 +434,7 @@ impl Probe<'_> { Probed { result, files, + executable, parent_unmoved, } } @@ -903,7 +919,7 @@ pub async fn drive( if run.base_failing.is_none() && run.applied.is_empty() { clean_slate(w).await; } - let mut files: HashMap> = HashMap::new(); + let mut files: HashMap = HashMap::new(); loop { crate::passes::check_cancelled(state, &msg.team_id, w.run_id).await?; let action = run.next_action(); @@ -965,7 +981,7 @@ pub async fn drive( ) .await; let mut results = vec![]; - let mut keyed: HashMap, Vec<(String, String)>> = HashMap::new(); + let mut keyed: HashMap, Written> = HashMap::new(); // A parent raised instead of an override that did not move // its package: the override is written after all, and the // set is probed again with it. @@ -975,7 +991,13 @@ pub async fn drive( unmoved.extend(o.parent_unmoved); continue; } - keyed.insert(ids, o.files); + keyed.insert( + ids, + Written { + files: o.files, + executable: o.executable, + }, + ); results.push((*g, o.result)); } for b in run.plan.bumps.iter_mut() { @@ -1016,14 +1038,17 @@ pub async fn drive( .map(|&i| run.plan.bumps[i].package.clone()) .collect(); let captured = files.remove(&g).unwrap_or_default(); - if captured.is_empty() { + if captured.files.is_empty() { // Green and nothing to write: the manifests and the // lockfile already say these versions. let head = run.head.clone(); run.on_commit(g, &head); continue; } + // A new file the build left executable is committed executable. + let sources = crate::clients::git_mode::archive_sources(&captured.executable); let ops: Vec = captured + .files .into_iter() .map(|(path, content)| FileOp::Write { path, content }) .collect(); @@ -1040,7 +1065,7 @@ pub async fn drive( .await; match w .github - .batch_write(owner, name, w.branch, &message, &ops) + .batch_write_from(owner, name, w.branch, &message, &ops, &sources) .await { Ok(_) => { @@ -1459,9 +1484,10 @@ async fn code_fix( &format!("fix(deps): {} {} to {}", b.package, b.from, b.to), ) .await; + let sources = crate::clients::git_mode::archive_sources(&applied.executable); if let Err(e) = w .github - .batch_write(owner, name, w.branch, &message, &ops) + .batch_write_from(owner, name, w.branch, &message, &ops, &sources) .await { return CodeFixed::Failed { diff --git a/services/worker/src/passes/incidents/xl_file_modes_kept.rs b/services/worker/src/passes/incidents/xl_file_modes_kept.rs index f530d761..eafbe071 100644 --- a/services/worker/src/passes/incidents/xl_file_modes_kept.rs +++ b/services/worker/src/passes/incidents/xl_file_modes_kept.rs @@ -531,6 +531,54 @@ fn a_new_file_a_build_left_executable_is_committed_executable() { 2 ); assert_eq!(generators.matches(".batch_write_from(").count(), 2); + // Every pass that runs a build commits its output with the archive's + // modes: each caller of `run_codegen` is named here with how many + // commits of build output it makes, each through `batch_write_from` + // with `archive_sources`. A new caller fails until it is wired. + let callers: [(&str, &str, usize); 3] = [ + ("implement.rs", implement, 1), + ("generators.rs", generators, 2), + ("dep_fix.rs", include_str!("../dep_fix.rs"), 2), + ]; + for (name, src, commits) in callers { + assert!(src.contains(".run_codegen("), "{name}"); + assert_eq!( + src.matches("git_mode::archive_sources(").count(), + commits, + "{name}" + ); + assert_eq!(src.matches(".batch_write_from(").count(), commits, "{name}"); + } + let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("src"); + let mut stack = vec![dir]; + let mut running = Vec::new(); + while let Some(d) = stack.pop() { + for e in std::fs::read_dir(&d).unwrap().flatten() { + let p = e.path(); + if p.is_dir() { + if !p.ends_with("incidents") { + stack.push(p); + } + continue; + } + if p.extension().and_then(|x| x.to_str()) != Some("rs") + || p.ends_with("clients/sandbox.rs") + { + continue; + } + let src = std::fs::read_to_string(&p).unwrap(); + if src.contains(".run_codegen(") { + running.push(p.file_name().unwrap().to_string_lossy().to_string()); + } + } + } + running.sort(); + let mut named: Vec = callers.iter().map(|(n, _, _)| n.to_string()).collect(); + named.sort(); + assert_eq!( + running, named, + "a pass runs a build without committing its modes" + ); let sandbox_src = include_str!("../../clients/sandbox.rs"); assert!(sandbox_src.contains("executable: captured.executable,")); assert!(sandbox_src.contains("executable: retry.executable,"));