From 68854a10d61e4667bf43ba5461f87c5d1f44051d Mon Sep 17 00:00:00 2001 From: Alexander Kiselev Date: Thu, 5 Feb 2026 14:02:31 -0800 Subject: [PATCH] fix: inject --project/--program after subcommand in GhidraCommand helper The GhidraCommand builder was adding --project before the subcommand args (e.g., `ghidra --project X function list`), but --project is a per-subcommand arg, not a global one. Now stores project/program as builder state and injects them after all other args in run(). Co-Authored-By: Claude Opus 4.6 --- tests/common/helpers.rs | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/tests/common/helpers.rs b/tests/common/helpers.rs index 9cb6100..acfb89c 100644 --- a/tests/common/helpers.rs +++ b/tests/common/helpers.rs @@ -129,6 +129,8 @@ impl GhidraResult { /// Builder for running ghidra CLI commands with proper configuration. pub struct GhidraCommand { args: Vec, + project: Option, + program: Option, env_vars: Vec<(String, String)>, timeout_secs: u64, } @@ -138,6 +140,8 @@ impl GhidraCommand { pub fn new() -> Self { Self { args: Vec::new(), + project: None, + program: None, env_vars: Vec::new(), timeout_secs: 120, } @@ -168,16 +172,16 @@ impl GhidraCommand { } /// Configure for bridge connection. - pub fn with_daemon(self, harness: &DaemonTestHarness) -> Self { - self.arg("--project").arg(harness.project()) + pub fn with_daemon(mut self, harness: &DaemonTestHarness) -> Self { + self.project = Some(harness.project().to_string()); + self } /// Set project and program arguments. - pub fn with_project(self, project: &str, program: &str) -> Self { - self.arg("--project") - .arg(project) - .arg("--program") - .arg(program) + pub fn with_project(mut self, project: &str, program: &str) -> Self { + self.project = Some(project.to_string()); + self.program = Some(program.to_string()); + self } /// Request JSON output format. @@ -203,6 +207,14 @@ impl GhidraCommand { cmd.arg(arg); } + // Add --project and --program after the subcommand and its args + if let Some(ref project) = self.project { + cmd.arg("--project").arg(project); + } + if let Some(ref program) = self.program { + cmd.arg("--program").arg(program); + } + cmd.timeout(std::time::Duration::from_secs(self.timeout_secs)); let output = cmd.output().expect("Failed to run ghidra command");