Rimosso il sistema di aggiornamento upstream: nessun update verso terzi (B)

Parte "sicurezza" di 9494b768 (senza il nuovo `akode update`, che e' una funzione di aKode):
- via il sottocomando `update`, il prompt di aggiornamento, il riquadro "Update available",
  la cache delle versioni e le azioni npm/pnpm/bun/brew/installer che eseguivano
  curl https://chatgpt.com/codex/install.sh (e il .ps1) o installavano @openai/codex;
- UpdateAction resta con la sola sostituzione del pacchetto del daemon locale;
- test rimossi solo perche' il codice che verificavano non c'e' piu'
  (risoluzione Windows del comando di update, parsing di `update`, update dei pacchetti
  fuori dal progetto).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
andrea.difonzo
2026-11-17 12:45:54 +01:00
parent ea3dee91e1
commit f29b17c288
22 changed files with 15 additions and 1175 deletions

View File

@@ -5,36 +5,6 @@ use akode_tui::DaemonUpdateSource;
use pretty_assertions::assert_eq;
use std::os::unix::fs::PermissionsExt;
#[test]
fn package_update_runs_outside_the_project() -> anyhow::Result<()> {
const CHILD: &str = "AKODE_TEST_PACKAGE_UPDATE_CHILD";
if std::env::var_os(CHILD).is_some() {
return run_update_action(UpdateAction::PnpmGlobalLatest, /*cli_executable*/ None);
}
let project = tempfile::tempdir()?;
let bin = tempfile::tempdir()?;
akode_utils_cargo_bin::write_executable(
&bin.path().join("pnpm"),
"#!/bin/sh\npwd -P > \"$0.cwd\"\n",
)?;
assert_cmd::Command::new(std::env::current_exe()?)
.args([
"--exact",
"daemon_update_tests::package_update_runs_outside_the_project",
])
.current_dir(project.path())
.env("TMPDIR", project.path())
.env("PATH", bin.path())
.env(CHILD, "1")
.assert()
.success();
let cwd = std::fs::read_to_string(bin.path().join("pnpm.cwd"))?;
assert!(!std::path::Path::new(cwd.trim_end()).starts_with(project.path().canonicalize()?));
Ok(())
}
#[test]
fn daemon_handoff_uses_selected_executable_and_propagates_failure() -> anyhow::Result<()> {
let dir = tempfile::tempdir()?;

View File

@@ -60,7 +60,6 @@ mod sandbox_setup;
mod sandbox_uninstall;
mod state_db_recovery;
#[cfg(not(windows))]
mod wsl_paths;
use crate::mcp_cmd::McpCli;
use crate::plugin_cmd::PluginCli;
@@ -155,9 +154,6 @@ enum Subcommand {
/// Generate shell completion scripts.
Completion(CompletionCommand),
/// Update aKode to the latest version.
Update,
/// Diagnose local aKode installation, config, auth, and runtime health.
Doctor(DoctorCommand),
@@ -714,106 +710,21 @@ fn run_update_action(
action: UpdateAction,
cli_executable: Option<&std::path::Path>,
) -> anyhow::Result<()> {
if let UpdateAction::Daemon(source) = action {
let executable = cli_executable
.ok_or_else(|| anyhow::anyhow!("Cannot locate the launching aKode CLI"))?;
println!("Updating the local background server...");
let status = std::process::Command::new(executable)
.args(source.command_args())
.status()?;
anyhow::ensure!(
status.success(),
"Daemon update failed with status {status}"
);
println!("Relaunch aKode to reconnect.");
return Ok(());
}
println!();
let cmd_str = action.command_str();
println!("Updating aKode via `{cmd_str}`...");
let status = {
#[cfg(windows)]
{
let (cmd, args) = action.command_args();
let cmd = if action == UpdateAction::StandaloneWindows {
// These args contain PowerShell metacharacters, so do not let
// PATHEXT select a batch shim for this action.
"powershell.exe"
} else {
cmd
};
let path_env =
std::env::var_os("PATH").ok_or_else(|| anyhow::anyhow!("PATH is not set"))?;
let command_path = resolve_windows_update_command_from_path(cmd, &path_env)?;
// Do not let a project-local command or package-manager config
// influence the updater after the user accepts the update prompt.
let update_cwd = tempfile::tempdir()?;
// Resolve through PATH without consulting the project cwd. When
// this returns a .cmd/.bat shim, std::process::Command routes the
// absolute path through the system command processor.
std::process::Command::new(command_path)
.args(args)
.current_dir(update_cwd.path())
.status()?
}
#[cfg(not(windows))]
{
let (cmd, args) = action.command_args();
let command_path = crate::wsl_paths::normalize_for_wsl(cmd);
let normalized_args: Vec<String> = args
.iter()
.map(crate::wsl_paths::normalize_for_wsl)
.collect();
std::process::Command::new(&command_path)
.args(&normalized_args)
// Package managers search parent directories for project config and hooks.
.current_dir("/")
.status()?
}
};
if !status.success() {
anyhow::bail!("`{cmd_str}` failed with status {status}");
}
println!("\n🎉 Update ran successfully! Please restart aKode.");
let UpdateAction::Daemon(source) = action;
let executable =
cli_executable.ok_or_else(|| anyhow::anyhow!("Cannot locate the launching aKode CLI"))?;
println!("Updating the local background server...");
let status = std::process::Command::new(executable)
.args(source.command_args())
.status()?;
anyhow::ensure!(
status.success(),
"Daemon update failed with status {status}"
);
println!("Relaunch aKode to reconnect.");
Ok(())
}
#[cfg(windows)]
fn resolve_windows_update_command_from_path(
command: &str,
path_env: &std::ffi::OsStr,
) -> anyhow::Result<PathBuf> {
let path_env =
std::env::join_paths(std::env::split_paths(path_env).filter(|path| path.is_absolute()))?;
if path_env.is_empty() {
anyhow::bail!(
"Could not find an absolute update command `{command}` on PATH. Please update manually: https://developers.openai.com/akode/cli/"
);
}
which::which_in_global(command, Some(&path_env))?
.next()
.ok_or_else(|| anyhow::anyhow!("could not find update command `{command}` on PATH"))
}
fn run_update_command() -> anyhow::Result<()> {
#[cfg(debug_assertions)]
{
anyhow::bail!(
"`akode update` is not available in debug builds. Install a release build of aKode to use this command."
);
}
#[cfg(not(debug_assertions))]
{
let Some(action) = akode_tui::get_update_action() else {
anyhow::bail!(
"Could not detect the aKode installation method. Please update manually: https://developers.openai.com/akode/cli/"
);
};
run_update_action(action, /*cli_executable*/ None)
}
}
fn run_execpolicycheck(cmd: ExecPolicyCheckCommand) -> anyhow::Result<()> {
cmd.run()
}
@@ -1550,14 +1461,6 @@ async fn dispatch_cli(
)?;
print_completion(completion_cli);
}
Some(Subcommand::Update) => {
reject_remote_mode_for_subcommand(
root_remote.as_deref(),
root_remote_auth_token_env.as_deref(),
"update",
)?;
run_update_command()?;
}
Some(Subcommand::Doctor(doctor_cli)) => {
reject_remote_mode_for_subcommand(
root_remote.as_deref(),
@@ -2166,7 +2069,6 @@ fn unsupported_subcommand_name_for_strict_config(
Some(Subcommand::Login(_)) => Some("login"),
Some(Subcommand::Logout(_)) => Some("logout"),
Some(Subcommand::Completion(_)) => Some("completion"),
Some(Subcommand::Update) => Some("update"),
Some(Subcommand::Sandbox(_)) => Some("sandbox"),
Some(Subcommand::Debug(_)) => Some("debug"),
Some(Subcommand::Execpolicy(_)) => Some("execpolicy"),
@@ -2588,52 +2490,6 @@ mod tests {
assert!(size < 64 * 1024, "interactive TUI future is {size} bytes");
}
#[cfg(windows)]
#[test]
fn windows_update_command_resolution_ignores_relative_path_entries() {
let cwd = std::env::current_dir().expect("current directory");
let decoy_dir = tempfile::tempdir_in(&cwd).expect("relative decoy directory");
let trusted_dir = tempfile::tempdir().expect("trusted PATH directory");
let relative_decoy_dir = decoy_dir
.path()
.strip_prefix(&cwd)
.expect("decoy directory should be relative to cwd");
for command in ["npm.cmd", "pnpm.cmd", "bun.exe"] {
std::fs::write(decoy_dir.path().join(command), "decoy")
.expect("write cwd-relative decoy");
std::fs::write(trusted_dir.path().join(command), "trusted")
.expect("write trusted PATH command");
let path_env = std::env::join_paths([relative_decoy_dir, trusted_dir.path()])
.expect("join synthetic PATH");
let resolved = resolve_windows_update_command_from_path(command, &path_env)
.expect("resolve update command");
assert_eq!(resolved, trusted_dir.path().join(command));
}
let cwd_decoy = tempfile::Builder::new()
.suffix(".cmd")
.tempfile_in(&cwd)
.expect("cwd-local decoy");
let command = cwd_decoy
.path()
.file_name()
.and_then(|name| name.to_str())
.expect("decoy filename");
let relative_only_path_env = std::env::join_paths(["."]).expect("join relative-only PATH");
let err = resolve_windows_update_command_from_path(command, &relative_only_path_env)
.expect_err("relative-only PATH should not resolve a cwd command");
assert_eq!(
err.to_string(),
format!(
"Could not find an absolute update command `{command}` on PATH. Please update manually: https://developers.openai.com/akode/cli/"
)
);
}
#[tokio::test]
async fn updater_http_client_factory_honors_respect_system_proxy() {
let akode_home = tempfile::tempdir().expect("temporary aKode home");
@@ -3373,12 +3229,6 @@ enabled = true
assert!(matches!(cli.subcommand, Some(Subcommand::Plugin(_))));
}
#[test]
fn update_parses_as_update_subcommand() {
let cli = MultitoolCli::try_parse_from(["akode", "update"]).expect("parse");
assert!(matches!(cli.subcommand, Some(Subcommand::Update)));
}
#[test]
fn archive_merges_scoped_tui_flags() {
let (target, interactive, remote) = finalize_archive_from_args(

View File

@@ -1,59 +0,0 @@
use std::ffi::OsStr;
/// Returns true if the current process is running under WSL.
pub use akode_utils_path::is_wsl;
/// Convert a Windows absolute path (`C:\foo\bar` or `C:/foo/bar`) to a WSL mount path (`/mnt/c/foo/bar`).
/// Returns `None` if the input does not look like a Windows drive path.
pub fn win_path_to_wsl(path: &str) -> Option<String> {
let bytes = path.as_bytes();
if bytes.len() < 3
|| bytes[1] != b':'
|| !(bytes[2] == b'\\' || bytes[2] == b'/')
|| !bytes[0].is_ascii_alphabetic()
{
return None;
}
let drive = (bytes[0] as char).to_ascii_lowercase();
let tail = path[3..].replace('\\', "/");
if tail.is_empty() {
return Some(format!("/mnt/{drive}"));
}
Some(format!("/mnt/{drive}/{tail}"))
}
/// If under WSL and given a Windows-style path, return the equivalent `/mnt/<drive>/…` path.
/// Otherwise returns the input unchanged.
pub fn normalize_for_wsl<P: AsRef<OsStr>>(path: P) -> String {
let value = path.as_ref().to_string_lossy().to_string();
if !is_wsl() {
return value;
}
if let Some(mapped) = win_path_to_wsl(&value) {
return mapped;
}
value
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn win_to_wsl_basic() {
assert_eq!(
win_path_to_wsl(r"C:\Temp\codex.zip").as_deref(),
Some("/mnt/c/Temp/codex.zip")
);
assert_eq!(
win_path_to_wsl("D:/Work/codex.tgz").as_deref(),
Some("/mnt/d/Work/codex.tgz")
);
assert!(win_path_to_wsl("/home/user/codex").is_none());
}
#[test]
fn normalize_is_noop_on_unix_paths() {
assert_eq!(normalize_for_wsl("/home/u/x"), "/home/u/x");
}
}