这是indexloc提供的服务,不要输入任何密码
Skip to content

fix(cache): no longer let remoteCache.enable override force #9684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 51 additions & 6 deletions crates/turborepo-lib/src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ impl<'a> TryFrom<OptsInputs<'a>> for CacheOpts {
return Err(Error::OverlappingCacheOptions);
}

// defaults to fully enabled cache
let mut cache = cache.unwrap_or_default();

if inputs.config.remote_only() {
Expand All @@ -482,11 +483,10 @@ impl<'a> TryFrom<OptsInputs<'a>> 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() {
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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(())
}
}
Loading