Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Changelog

- **Fixed** A `!` pattern in `cache.env` or `cache.untrackedEnv` now excludes variables only from its own list. To keep a default pass-through variable such as `NPM_TOKEN` out of a task's environment, exclude it in `cache.untrackedEnv`, and in `cache.env` if that list also matches it ([#1010](https://github.com/voidzero-dev/vite-task/pull/1010)).
- **Fixed** Remote cache operations now cap concurrent uploads to 4 per endpoint, use pooled HTTP/1.1 connections instead of multiplexing all reads and uploads over one HTTP/2 connection, retry transient `5xx`/`429`/`408` and network failures with jittered backoff, and back off briefly during sustained endpoint outages, preventing `503` upload bursts and Windows connection-reset drops ([#1016](https://github.com/voidzero-dev/vite-task/pull/1016)).
- **Fixed** Tasks that list `node_modules`, the workspace root, or `node_modules/.vite` no longer miss the cache when pnpm's `node_modules/.pnpm-workspace-state-*.json`, Vite's `node_modules/.vite-temp`, the workspace root's `.git`, or the task cache directory appear or disappear. Direct accesses to `node_modules/.vite-temp` and `.DS_Store` are now skipped as well, so they are neither tracked as inputs nor archived as outputs ([#1014](https://github.com/voidzero-dev/vite-task/pull/1014)).
- **Fixed** When a command handler sets a working directory for a command it generates, `vp run` now runs that command in the selected directory and includes the directory in its cache fingerprint ([#1005](https://github.com/voidzero-dev/vite-task/pull/1005)).
Expand Down
2 changes: 1 addition & 1 deletion crates/vt/src/session/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ pub fn split_path(path: &str) -> (Option<&str>, &str) {
/// its own cache warm across branch switches, and a cache from a different
/// version is simply ignored (it lives in a directory this build never looks
/// at) rather than aborting the run. Bumping the version starts a fresh cache.
const CACHE_SCHEMA_VERSION: u32 = 24;
const CACHE_SCHEMA_VERSION: u32 = 25;

/// Name of the per-version subdirectory (e.g. `v14`) under the task-cache
/// directory that holds the database and output archives for the current
Expand Down
153 changes: 127 additions & 26 deletions crates/vt_plan/src/envs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,17 @@ impl EnvFingerprints {
envs: &mut FxHashMap<EnvName<Arc<OsStr>>, Arc<OsStr>>,
env_config: &EnvConfig,
) -> Result<Self, ResolveEnvError> {
// Collect all envs matching fingerprinted or untracked envs in env_config
*envs = resolve_envs_with_patterns(
envs.iter(),
&env_config
.untracked_env
.iter()
.map(std::convert::AsRef::as_ref)
.chain(env_config.fingerprinted_envs.iter().map(std::convert::AsRef::as_ref))
.collect::<Vec<&str>>(),
)?;
// Match each list on its own, so a `!` pattern only excludes names from
// the list it's in. Compile both before modifying `envs`.
let untracked_patterns = EnvGlobSet::new(env_config.untracked_env.iter())?;
let fingerprinted_patterns = EnvGlobSet::new(env_config.fingerprinted_envs.iter())?;

// Keep envs matching either list
envs.retain(|name, _| {
name.inner().to_str().is_some_and(|name_str| {
untracked_patterns.is_match(name_str) || fingerprinted_patterns.is_match(name_str)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Bump the cache version for the changed environment semantics

When upgrading an existing cache for a task configured with env: ['VITE_*', '!VITE_DEBUG'] and untrackedEnv: ['VITE_DEBUG'], with inherited VITE_DEBUG set, the old implementation omitted that variable whereas this implementation passes it through. However, both fingerprinted_envs and untracked_env_config remain identical, so the cache key does not change. Because CACHE_SCHEMA_VERSION is still 23 in crates/vt/src/session/cache/mod.rs:471, local and remote lookups can replay output produced without VITE_DEBUG instead of rerunning the task with its newly allowed environment. Bump the cache schema version or otherwise distinguish the new matching semantics in the fingerprint.

Useful? React with 👍 / 👎.

})
});

// Ensure cached output is colored by default. Skipped if the user
// opted into passing `FORCE_COLOR` through (via `env` / `untrackedEnv`)
Expand All @@ -129,12 +130,11 @@ impl EnvFingerprints {
// Resolve fingerprinted envs
let mut fingerprinted_envs = BTreeMap::<Str, EnvValueHash>::new();
if !env_config.fingerprinted_envs.is_empty() {
let fingerprinted_env_patterns = EnvGlobSet::new(env_config.fingerprinted_envs.iter())?;
for (name, value) in envs.iter() {
let Some(name) = name.inner().to_str() else {
continue;
};
if !fingerprinted_env_patterns.is_match(name) {
if !fingerprinted_patterns.is_match(name) {
continue;
}
let Some(value) = value.to_str() else {
Expand All @@ -159,20 +159,6 @@ impl EnvFingerprints {
}
}

fn resolve_envs_with_patterns<'a>(
env_vars: impl Iterator<Item = (&'a EnvName<Arc<OsStr>>, &'a Arc<OsStr>)>,
patterns: &[&str],
) -> Result<FxHashMap<EnvName<Arc<OsStr>>, Arc<OsStr>>, vt_glob::env::EnvGlobError> {
let patterns = EnvGlobSet::new(patterns.iter())?;
let envs: FxHashMap<EnvName<Arc<OsStr>>, Arc<OsStr>> = env_vars
.filter_map(|(name, value)| {
let name_str = name.inner().to_str()?;
if patterns.is_match(name_str) { Some((name.clone(), Arc::clone(value))) } else { None }
})
.collect();
Ok(envs)
}

#[cfg(test)]
mod tests {
use vt_graph::config::DEFAULT_UNTRACKED_ENV;
Expand All @@ -197,6 +183,12 @@ mod tests {
EnvValueHash::new(value)
}

fn env_pairs(envs: &FxHashMap<EnvName<Arc<OsStr>>, Arc<OsStr>>) -> BTreeMap<&str, &str> {
envs.iter()
.map(|(name, value)| (name.inner().to_str().unwrap(), value.to_str().unwrap()))
.collect()
}

#[test]
fn test_force_color_defaults_to_one_when_user_does_not_opt_in() {
// The user did not list `FORCE_COLOR` in `env` or `untrackedEnv`, so
Expand Down Expand Up @@ -301,6 +293,115 @@ mod tests {
assert_eq!(result.fingerprinted_envs.get("FORCE_COLOR").copied(), Some(hash("1")));
}

#[test]
fn test_untracked_negation_does_not_cancel_env() {
let untracked = [DEFAULT_UNTRACKED_ENV, &["!CI"]].concat();
let env_config = create_env_config(&["CI"], &untracked);
let mut envs = create_test_envs(vec![("CI", "true"), ("PATH", "bin")]);

let result = EnvFingerprints::resolve(&mut envs, &env_config).unwrap();

assert_eq!(
env_pairs(&envs),
BTreeMap::from([("CI", "true"), ("FORCE_COLOR", "1"), ("PATH", "bin")])
);
assert_eq!(result.fingerprinted_envs, BTreeMap::from([("CI".into(), hash("true"))]));
}

#[test]
fn test_env_negation_does_not_cancel_untracked() {
let env_config = create_env_config(&["VITE_*", "!VITE_DEBUG"], &["VITE_DEBUG"]);
let mut envs = create_test_envs(vec![("VITE_API_URL", "api"), ("VITE_DEBUG", "true")]);

let result = EnvFingerprints::resolve(&mut envs, &env_config).unwrap();

assert_eq!(
env_pairs(&envs),
BTreeMap::from([("FORCE_COLOR", "1"), ("VITE_API_URL", "api"), ("VITE_DEBUG", "true")])
);
assert_eq!(
result.fingerprinted_envs,
BTreeMap::from([("VITE_API_URL".into(), hash("api"))])
);
}

#[test]
fn test_untracked_exclude_all_keeps_only_explicit_env() {
let untracked = [DEFAULT_UNTRACKED_ENV, &["!*"]].concat();
let env_config = create_env_config(&["PATH", "CI"], &untracked);
let mut envs = create_test_envs(vec![("CI", "true"), ("HOME", "home"), ("PATH", "bin")]);

let result = EnvFingerprints::resolve(&mut envs, &env_config).unwrap();

assert_eq!(
env_pairs(&envs),
BTreeMap::from([("CI", "true"), ("FORCE_COLOR", "1"), ("PATH", "bin")])
);
assert_eq!(
result.fingerprinted_envs,
BTreeMap::from([("CI".into(), hash("true")), ("PATH".into(), hash("bin"))])
);
}

#[test]
fn test_env_negation_does_not_suppress_default_untracked_passthrough() {
// `*_TOKEN` is in `DEFAULT_UNTRACKED_ENV`, so negating `NPM_TOKEN` only in
// `env` still lets it pass through untracked; keeping it out of the
// spawned process environment requires negating it in `untrackedEnv`.
let env_config = create_env_config(&["!NPM_TOKEN"], DEFAULT_UNTRACKED_ENV);
let mut envs = create_test_envs(vec![("NPM_TOKEN", "secret"), ("PATH", "bin")]);

let result = EnvFingerprints::resolve(&mut envs, &env_config).unwrap();

assert_eq!(
env_pairs(&envs),
BTreeMap::from([("FORCE_COLOR", "1"), ("NPM_TOKEN", "secret"), ("PATH", "bin")])
);
assert!(result.fingerprinted_envs.is_empty());

let untracked = [DEFAULT_UNTRACKED_ENV, &["!NPM_TOKEN"]].concat();
let env_config = create_env_config(&["!NPM_TOKEN"], &untracked);
let mut envs = create_test_envs(vec![("NPM_TOKEN", "secret"), ("PATH", "bin")]);

let result = EnvFingerprints::resolve(&mut envs, &env_config).unwrap();

assert_eq!(env_pairs(&envs), BTreeMap::from([("FORCE_COLOR", "1"), ("PATH", "bin")]));
assert!(result.fingerprinted_envs.is_empty());
}

#[test]
fn test_force_color_opt_in_survives_negation_in_other_list() {
// A negation in the other list must not trigger the `FORCE_COLOR=1` fallback.
let env_config = create_env_config(&["FORCE_COLOR"], &["!FORCE_COLOR"]);
let mut envs = create_test_envs(vec![("FORCE_COLOR", "3")]);

let result = EnvFingerprints::resolve(&mut envs, &env_config).unwrap();

assert_eq!(env_pairs(&envs), BTreeMap::from([("FORCE_COLOR", "3")]));
assert_eq!(result.fingerprinted_envs, BTreeMap::from([("FORCE_COLOR".into(), hash("3"))]));

let env_config = create_env_config(&["*", "!FORCE_COLOR"], &["FORCE_COLOR"]);
let mut envs = create_test_envs(vec![("FORCE_COLOR", "0")]);

let result = EnvFingerprints::resolve(&mut envs, &env_config).unwrap();

assert_eq!(env_pairs(&envs), BTreeMap::from([("FORCE_COLOR", "0")]));
assert!(result.fingerprinted_envs.is_empty());
}

#[test]
fn test_invalid_glob_in_either_list_leaves_envs_unmodified() {
for env_config in [create_env_config(&["["], &[]), create_env_config(&[], &["["])] {
let original = create_test_envs(vec![("UNLISTED", "value")]);
let mut envs = original.clone();

let result = EnvFingerprints::resolve(&mut envs, &env_config);

assert!(matches!(result, Err(ResolveEnvError::GlobError { .. })));
assert_eq!(envs, original);
}
}

#[test]
#[cfg(unix)]
fn test_task_envs_stable_ordering() {
Expand Down