refactor(dynamic): ensure unique workdir names to avoid conflicts, improve Java sibling stub handling, and enhance comments

This commit is contained in:
elipeter 2026-05-22 11:31:17 -05:00
parent 32211079a0
commit fd50549582
4 changed files with 157 additions and 24 deletions

View file

@ -497,22 +497,11 @@ pub fn run_shape_fixture_lang(
// Phase 14: Java shape fixtures bundle annotation / type stubs as
// sibling `*.java` files alongside `Vuln.java` / `Benign.java`.
// The harness builder owns `/tmp/nyx-harness/<spec_hash>/` and only
// copies the entry file + extra_files — it never walks the entry
// file's parent dir. Pre-create the workdir and stage every
// sibling stub there so the build sandbox's `javac *.java` step
// resolves the annotation / type references without pulling in any
// Maven deps. Skip the alternate Vuln/Benign file to keep public
// class declarations from colliding with the running variant.
// Stage those sidecars next to the temp-copied entry file so the
// harness builder can copy them into its per-run workdir. Skip the
// alternate Vuln/Benign file to keep public class declarations from
// colliding with the running variant.
if matches!(lang, nyx_scanner::symbol::Lang::Java) {
let workdir = std::path::PathBuf::from("/tmp/nyx-harness").join(&spec.spec_hash);
// Wipe any prior contents so stale `.java` / `.class` files
// from previous emitter revisions cannot bleed into this run.
// `prepare_java` globs every `*.java` in the workdir — leaving
// an obsolete `Entry.java` next to the new `Vuln.java` produces
// a duplicate-class compile error.
let _ = std::fs::remove_dir_all(&workdir);
let _ = std::fs::create_dir_all(&workdir);
let alt_file = if file == "Vuln.java" {
"Benign.java"
} else if file == "Benign.java" {
@ -531,7 +520,7 @@ pub fn run_shape_fixture_lang(
continue;
}
if p.extension().map(|e| e == "java").unwrap_or(false) {
let _ = std::fs::copy(&p, workdir.join(&name));
let _ = std::fs::copy(&p, tmp.path().join(&name));
}
}
}