fix: am start <agent> passait le token run en argument (binaire enregistre existant) — picoclaw rejetait son propre nom, aichat recevait 'aichat' en prompt

This commit is contained in:
2026-08-21 10:32:26 -04:00
parent 7fb65c257d
commit e71cffb3c0
7 changed files with 798 additions and 2 deletions
+50
View File
@@ -319,6 +319,12 @@ pub fn resolve_exec(
Some(e) if !e.bins.is_empty() => {
let p = std::path::PathBuf::from(&e.bins[0]);
if p.exists() || app.dry_run() {
// The recorded bin replaces the run command's first token
// (e.g. "picoclaw"): consume it so it is not appended to
// the argument list. Regression: am start <agent géré>
// lançait "<bin> <token-run>" — picoclaw rejetait son propre
// nom comme sous-commande inconnue.
tokens.remove(0);
p.display().to_string()
} else {
tokens.remove(0)
@@ -473,6 +479,7 @@ pub fn select_method<'a>(
#[cfg(test)]
mod tests {
use super::*;
use clap::Parser;
#[test]
fn routes_cmd_scripts_through_comspec() {
@@ -498,4 +505,47 @@ mod tests {
assert_eq!(program, "node");
assert_eq!(args, vec!["-v".to_string()]);
}
#[test]
fn resolve_exec_installed_agent_does_not_leak_run_token() {
let guard = tempfile::tempdir().unwrap();
let dir = guard.path().to_path_buf();
std::mem::forget(guard);
let cfg = dir.join("config.yaml");
std::fs::write(
&cfg,
"version: \"1.0\"\nsettings:\n auto_install_deps: false\n confirm_before_run: false\nagents:\n - name: x\n run: x\n installable: false\n",
)
.unwrap();
let cli = crate::cli::Cli::parse_from(["am", "--config", cfg.to_str().unwrap()]);
let mut app = crate::app::App::from_cli(cli).unwrap();
app.paths.state_file = dir.join("state.json");
app.state = crate::state::StateStore::new(app.paths.state_file.clone());
// A recorded installed bin that exists: the run token "x" must be
// consumed, not appended to the argument list.
let bin = dir.join("x.exe");
std::fs::write(&bin, b"x").unwrap();
app.state
.set(&crate::state::InstalledEntry {
name: "x".to_string(),
version: Some("1.0".to_string()),
method: "binary".to_string(),
install_dir: dir.display().to_string(),
bins: vec![bin.display().to_string()],
run: "x".to_string(),
installed_at: "2026-01-01T00:00:00Z".to_string(),
updated_at: None,
pid: None,
started_at: None,
})
.unwrap();
let agent = app.catalog.resolve("x").unwrap();
let exec = resolve_exec(&app, agent, &[], &BTreeMap::new()).unwrap();
assert_eq!(exec.program, bin.display().to_string());
assert!(
exec.args.is_empty(),
"run token leaked into args: {:?}",
exec.args
);
}
}