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
25 changes: 18 additions & 7 deletions cli/cli/src/adopt/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,11 @@ mod tests {
std::fs::write(root.join("tools/dx"), text).expect("launcher");
}

fn write_patches(root: &Path) {
let plan = dx_adopt::plan_user_patches(root).expect("plan");
dx_adopt::user_patches::apply(root, &plan).expect("patches");
}

fn set_module_version(root: &Path, version: &str) {
std::fs::write(root.join("MODULE.bazel"), dep(version)).expect("module");
}
Expand Down Expand Up @@ -827,6 +832,7 @@ mod tests {
fn upgrade_moves_the_pin_and_refreshes_existing_files() {
let (_scratch, root) = pinned("dx-adopt-upgrade-hint-", OLD);
set_module_version(&root, OLD);
write_patches(&root);
std::fs::write(root.join("AGENTS.md"), STALE_AGENTS).expect("agents");
sh_launcher(&root, OLD);
let inv = invocation(&["upgrade", "--to", module(), "--apply"]);
Expand Down Expand Up @@ -1063,6 +1069,7 @@ mod tests {
let plan =
init_files::plan(&root, "refresh", false, &dx_plan::args::Agent::ALL).expect("plan");
std::fs::write(root.join("MODULE.bazel"), dep(module())).expect("module");
write_patches(&root);
dx_adopt::write_version_pin(&root, OLD).expect("pin");
sh_launcher(&root, OLD);
let ci = root.join(".github/workflows/ci.yml");
Expand Down Expand Up @@ -1182,6 +1189,7 @@ mod tests {
let (_scratch, root) = pinned("dx-adopt-upgrade-static-", OLD);
dx_adopt::write_launcher_files(&root, &mut dx_adopt::Applied::default())
.expect("launchers");
write_patches(&root);
let before = snapshot(&root);
let (code, out, err) = run(&upgrade(&["--apply"]), &root);
assert_eq!(code, 0, "{out}{err}");
Expand Down Expand Up @@ -1253,11 +1261,8 @@ mod tests {
fn a_handoff_drops_the_patch_include_and_the_same_version_writes_it() {
let (_scratch, root) = pinned("dx-adopt-upgrade-patches-", "1.2.3");
let include = "include(\"//third_party/rules_dx:rules_dx.MODULE.bazel\")\n";
std::fs::write(
root.join("MODULE.bazel"),
format!("{}{include}", dep(module())),
)
.expect("module");
write_patches(&root);
assert!(module_text(&root).contains(include));
let runner = Recorder::default();
let inv = invocation(&["upgrade", "--apply", "--to=2.0.0"]);
let (code, out, err) = run_with(&inv, &root, &runner);
Expand Down Expand Up @@ -1296,7 +1301,10 @@ mod tests {
let runner = Recorder::default();
let (code, out, err) = run_with(&upgrade(&["--apply"]), &root, &runner);
assert_eq!(code, 0, "{out}{err}");
assert_eq!(module_text(&root), dep(module()));
assert_eq!(
dx_adopt::user_patches::without_include(&module_text(&root)),
dep(module())
);
assert_eq!(read_pin(&root), module());
assert_eq!(runner.calls.borrow().len(), 1);
assert!(out.contains("wrote MODULE.bazel.lock"), "{out}");
Expand Down Expand Up @@ -1414,7 +1422,10 @@ mod tests {
let runner = Recorder::default();
let (code, out, err) = run_with(&upgrade(&["--apply"]), &root, &runner);
assert_eq!(code, 0, "{out}{err}");
assert_eq!(module_text(&root), dep(module()));
assert_eq!(
dx_adopt::user_patches::without_include(&module_text(&root)),
dep(module())
);
let calls = runner.calls.borrow();
assert_eq!(calls.len(), 1, "{calls:?}");
assert!(calls[0].ends_with(&["deps".to_owned(), "--lockfile_mode=off".to_owned()]));
Expand Down
3 changes: 3 additions & 0 deletions cli/cli/src/exec/error_boundary_launcher_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,9 @@ fn text_mode_failures_keep_stdout_empty() {
#[test]
fn check_keeps_every_phase_finding_when_the_report_cannot_be_written() {
let consumer = Consumer::new();
let workspace = consumer.workspace();
let plan = dx_adopt::plan_user_patches(&workspace).expect("plan");
dx_adopt::user_patches::apply(&workspace, &plan).expect("patches");
let (result, witness) = consumer.stage_findings();
fs::create_dir_all(consumer.workspace().join("rep.sarif")).expect("destination dir");
let outcome = consumer.run(
Expand Down
Loading