Discover this machine's providers instead of asserting them
A fresh install wrote a `claude-cli` provider into the local setup unconditionally. Nothing looked for `claude`; the list was hardcoded in `Config::seed`, so on any machine without it -- which is every machine but the dev VM -- the phone was offered a provider that cannot spawn, stated with exactly the confidence of one that had been checked. Discovery already existed and was already right: `setups::discover` probes with `command -v` over the transport, includes echo for the local one because it runs in-process, and records the resolved path rather than the bare name. Only the local setup skipped it, which is the one place the answer felt obvious enough not to ask. So `seed` now takes the providers it is given, and seeding asks this machine the same question it asks any other. It moved out of `SessionManager::new` into an awaited step in main, because asking is I/O and a constructor that quietly spawns a subprocess surprises every caller. A discovery that fails seeds `echo` alone and says so, since echo is true wherever this server runs -- falling back to the hardcoded list would be the same bug with an extra step. The test that covered this agreed with the bug, because both were written from the same assumption: it asserted the seed contains `claude-cli`. It now asserts the opposite -- that the seed invents nothing -- and the session tests seed echo explicitly rather than relying on a constructor that would make them pass or fail on whether `claude` happens to be installed on whoever runs them. Verified by running a server on a PATH holding only `sh`: it seeds `echo` alone. With claude and llama-server present it finds both. 34 tests.
This commit is contained in:
1 parent
3cf6925d90
commit
4370c467ca
3 files changed
+126
-44
No files matched your search
+56
-12
@@ -241,29 +241,54 @@ impl SessionManager {
|
||||
models_dir,
|
||||
inner: RwLock::new(Inner { config, live }),
|
||||
};
|
||||
manager.seed_setup()?;
|
||||
Ok(manager)
|
||||
}
|
||||
|
||||
/// Writes a starting `claude-cli` provider into a config that has none,
|
||||
/// so a fresh install has something to spawn and a worked example of
|
||||
/// the schema to edit. Runs local by default -- a session is given a
|
||||
/// host when the CLI lives elsewhere, which is a per-session choice.
|
||||
/// Gives a fresh install something to spawn. Only ever fires when
|
||||
/// there are no setups at all -- deleting the last one is a choice,
|
||||
/// not a state to be repaired.
|
||||
fn seed_setup(&self) -> Result<()> {
|
||||
/// Writes this machine into a config that has no setups, with the
|
||||
/// providers actually found on it.
|
||||
///
|
||||
/// Discovered rather than assumed. Until 2026-08-28 this wrote a
|
||||
/// `claude-cli` provider unconditionally, so a fresh install on a
|
||||
/// machine without `claude` -- which is every machine but the dev VM
|
||||
/// -- offered a spawn option that could not work, and said so with the
|
||||
/// same confidence as a provider that had been checked for. Providers
|
||||
/// are discovered by asking the machine, and the local machine is not
|
||||
/// an exception to that.
|
||||
///
|
||||
/// A discovery that fails seeds only `echo`, which is true wherever
|
||||
/// this server runs, and says so in the log. Seeding the hardcoded
|
||||
/// list on failure would be the original bug with an extra step, and
|
||||
/// seeding nothing would leave a fresh install with nothing to prove
|
||||
/// the pipe with.
|
||||
pub async fn seed_setup(&self) -> Result<()> {
|
||||
if !self.inner.read().unwrap().config.setups.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
let providers = match crate::setups::discover(&transport::Transport::Here).await {
|
||||
Ok(found) => found,
|
||||
Err(err) => {
|
||||
tracing::warn!(
|
||||
"couldn't ask this machine what it has ({err}); seeding {} only -- \
|
||||
re-probe the setup from the app once that is fixed",
|
||||
crate::config::ECHO_PROVIDER
|
||||
);
|
||||
vec![Config::echo_provider()]
|
||||
}
|
||||
};
|
||||
let names: Vec<&str> = providers.iter().map(|p| p.name.as_str()).collect();
|
||||
|
||||
let mut inner = self.inner.write().unwrap();
|
||||
if !inner.config.setups.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
let mut candidate = inner.config.clone();
|
||||
candidate.setups.push(Config::seed());
|
||||
candidate.setups.push(Config::seed(providers.clone()));
|
||||
candidate.save(&self.config_path)?;
|
||||
inner.config = candidate;
|
||||
tracing::info!(
|
||||
"no setups configured -- added \"{}\"",
|
||||
crate::config::LOCAL_SETUP
|
||||
"no setups configured -- added \"{}\" with: {}",
|
||||
crate::config::LOCAL_SETUP,
|
||||
names.join(", ")
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
@@ -763,11 +788,28 @@ mod tests {
|
||||
.await
|
||||
}
|
||||
|
||||
/// Writes this machine into `config_path` with echo and nothing else.
|
||||
///
|
||||
/// Explicit rather than letting the manager seed itself: seeding now
|
||||
/// asks the machine what it has, so a test that relied on it would
|
||||
/// pass or fail depending on whether `claude` happens to be installed
|
||||
/// on whoever is running it. Echo is the only provider that is true
|
||||
/// everywhere, and the only one these tests need.
|
||||
fn seed_echo_only(config_path: &std::path::Path) {
|
||||
Config {
|
||||
setups: vec![Config::seed(vec![Config::echo_provider()])],
|
||||
..Config::default()
|
||||
}
|
||||
.save(config_path)
|
||||
.expect("seed config");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn spawn_message_and_delete_round_trip() {
|
||||
let dir = tempfile::tempdir().expect("tempdir");
|
||||
let config_path = dir.path().join("config.ron");
|
||||
let data_dir = dir.path().join("sessions");
|
||||
seed_echo_only(&config_path);
|
||||
let manager = SessionManager::new(
|
||||
config_path.clone(),
|
||||
data_dir.clone(),
|
||||
@@ -828,6 +870,7 @@ mod tests {
|
||||
#[tokio::test]
|
||||
async fn questions_round_trip_through_answer() {
|
||||
let dir = tempfile::tempdir().expect("tempdir");
|
||||
seed_echo_only(&dir.path().join("config.ron"));
|
||||
let manager = SessionManager::new(
|
||||
dir.path().join("config.ron"),
|
||||
dir.path().join("sessions"),
|
||||
@@ -869,6 +912,7 @@ mod tests {
|
||||
let dir = tempfile::tempdir().expect("tempdir");
|
||||
let config_path = dir.path().join("config.ron");
|
||||
let data_dir = dir.path().join("sessions");
|
||||
seed_echo_only(&config_path);
|
||||
|
||||
let manager = SessionManager::new(
|
||||
config_path.clone(),
|
||||
|
||||
Reference in new issue
Block a user