Skip to content
Closed
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
33 changes: 32 additions & 1 deletion crates/vite_task/src/session/cache/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ use std::collections::HashSet;
use vite_task_plan::cache_metadata::SpawnFingerprint;

use super::{CacheMiss, FingerprintMismatch};
use crate::session::event::{CacheDisabledReason, CacheStatus};
use crate::session::event::{
CacheDisabledReason, CacheNotUpdatedReason, CacheStatus, CacheUpdateStatus,
};

/// Describes a single atomic change between two spawn fingerprints
enum SpawnFingerprintChange {
Expand Down Expand Up @@ -283,3 +285,32 @@ pub fn format_cache_status_summary(cache_status: &CacheStatus) -> String {
}
}
}

/// Format cache update status for summary display (post-execution).
///
/// Returns Some(formatted_string) only when the reason is not already clear from CacheStatus.
/// - Updated: No message needed (success is implied)
/// - CacheHit: No message needed (already shown in CacheStatus::Hit)
/// - CacheDisabled: No message needed (already shown in CacheStatus::Disabled)
/// - BuiltInCommand: No message needed (already shown in CacheStatus::Disabled(InProcessExecution))
/// - NonZeroExitStatus: Shows message that cache wasn't updated due to failure
///
/// Note: Returns plain text without styling. The reporter applies colors.
pub fn format_cache_update_status(status: &CacheUpdateStatus) -> Option<String> {
match status {
CacheUpdateStatus::Updated => None,
CacheUpdateStatus::NotUpdated(reason) => match reason {
// These are already clear from CacheStatus in the Start event
CacheNotUpdatedReason::CacheHit => None,
CacheNotUpdatedReason::CacheDisabled => None,
CacheNotUpdatedReason::BuiltInCommand => None,
// These need to be shown - they explain why cache wasn't updated
CacheNotUpdatedReason::NonZeroExitStatus => {
Some("→ Cache not updated: task failed".to_string())
}
CacheNotUpdatedReason::StdinDataExists => {
Some("→ Cache not updated: stdin had data".to_string())
}
},
}
}
4 changes: 3 additions & 1 deletion crates/vite_task/src/session/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use std::{fmt::Display, fs::File, io::Write, sync::Arc, time::Duration};

use bincode::{Decode, Encode, decode_from_slice, encode_to_vec};
// Re-export display functions for convenience
pub use display::{format_cache_status_inline, format_cache_status_summary};
pub use display::{
format_cache_status_inline, format_cache_status_summary, format_cache_update_status,
};
use rusqlite::{Connection, OptionalExtension as _, config::DbConfig};
use serde::{Deserialize, Serialize};
use tokio::sync::Mutex;
Expand Down
4 changes: 4 additions & 0 deletions crates/vite_task/src/session/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ pub enum CacheNotUpdatedReason {
CacheDisabled,
/// Execution exited with non-zero status
NonZeroExitStatus,
/// Built-in command doesn't support caching
BuiltInCommand,
/// Stdin had data - output may depend on input, unsafe to cache
StdinDataExists,
}

#[derive(Debug)]
Expand Down
18 changes: 11 additions & 7 deletions crates/vite_task/src/session/execute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@ impl ExecutionContext<'_> {
},
});

// Emit Finish with CacheDisabled status (in-process executions don't cache)
// Emit Finish with BuiltInCommand status (built-in commands don't cache)
self.event_handler.handle_event(ExecutionEvent {
execution_id,
kind: ExecutionEventKind::Finish {
status: Some(0),
cache_update_status: CacheUpdateStatus::NotUpdated(
CacheNotUpdatedReason::CacheDisabled,
CacheNotUpdatedReason::BuiltInCommand,
),
},
});
Expand Down Expand Up @@ -287,11 +287,18 @@ impl ExecutionContext<'_> {
};

// 5. Update cache if successful and determine cache update status
// Priority: NonZeroExitStatus > StdinDataExists > Success
let cache_update_status = if let Some((track_result, cache_metadata)) =
track_result_with_cache_metadata
{
if result.exit_status.success() {
// Execution succeeded, attempt cache update
if !result.exit_status.success() {
// Priority 1: Non-zero exit status - don't update cache
CacheUpdateStatus::NotUpdated(CacheNotUpdatedReason::NonZeroExitStatus)
} else if result.stdin_had_data {
// Priority 2: Stdin had data - output may depend on input, unsafe to cache
CacheUpdateStatus::NotUpdated(CacheNotUpdatedReason::StdinDataExists)
} else {
// Success: attempt cache update
let fingerprint_ignores =
cache_metadata.spawn_fingerprint.fingerprint_ignores().map(|v| v.as_slice());
match PostRunFingerprint::create(
Expand Down Expand Up @@ -326,9 +333,6 @@ impl ExecutionContext<'_> {
return Err(ExecutionAborted);
}
}
} else {
// Execution failed with non-zero exit status, don't update cache
CacheUpdateStatus::NotUpdated(CacheNotUpdatedReason::NonZeroExitStatus)
}
} else {
// Caching was disabled for this task
Expand Down
Loading