diff --git a/crates/turborepo-lib/src/opts.rs b/crates/turborepo-lib/src/opts.rs index 70ad5dda35acf..5fc5646aca353 100644 --- a/crates/turborepo-lib/src/opts.rs +++ b/crates/turborepo-lib/src/opts.rs @@ -462,6 +462,7 @@ impl<'a> TryFrom> for CacheOpts { return Err(Error::OverlappingCacheOptions); } + // defaults to fully enabled cache let mut cache = cache.unwrap_or_default(); if inputs.config.remote_only() { @@ -482,11 +483,10 @@ impl<'a> TryFrom> for CacheOpts { if !is_linked { cache.remote.read = false; cache.remote.write = false; - } else if let Some(enabled) = inputs.config.enabled { - // We're linked, but if the user has explicitly enabled or disabled, use that - // value - cache.remote.read = enabled; - cache.remote.write = enabled; + } else if let Some(false) = inputs.config.enabled { + // We're linked, but if the user has explicitly disabled remote cache + cache.remote.read = false; + cache.remote.write = false; }; if inputs.config.remote_cache_read_only() { @@ -529,9 +529,10 @@ impl ScopeOpts { #[cfg(test)] mod test { + use tempfile::TempDir; use test_case::test_case; use turbopath::AbsoluteSystemPathBuf; - use turborepo_cache::CacheOpts; + use turborepo_cache::{CacheActions, CacheConfig, CacheOpts}; use turborepo_ui::ColorConfig; use super::{APIClientOpts, RepoOpts, RunOpts}; @@ -773,4 +774,48 @@ mod test { Ok(()) } + + #[test] + fn test_cache_config_force_remote_enable() -> Result<(), anyhow::Error> { + let tmpdir = TempDir::new()?; + let repo_root = AbsoluteSystemPathBuf::try_from(tmpdir.path())?; + + repo_root + .join_component("turbo.json") + .create_with_contents(serde_json::to_string_pretty(&serde_json::json!({ + "remoteCache": { "enabled": true } + }))?)?; + + let mut args = Args::default(); + args.command = Some(Command::Run { + execution_args: Box::default(), + run_args: Box::new(RunArgs { + force: Some(Some(true)), + ..Default::default() + }), + }); + + // set token and team to simulate a logged in/linked user + args.token = Some("token".to_string()); + args.team = Some("team".to_string()); + + let base = CommandBase::new(args, repo_root, "1.0.0", ColorConfig::new(false))?; + let actual = base.opts().cache_opts.cache; + + assert_eq!( + actual, + CacheConfig { + remote: CacheActions { + read: false, + write: true + }, + local: CacheActions { + read: false, + write: true + } + } + ); + + Ok(()) + } }