Skip to content

Commit 770bc04

Browse files
committed
fix: ignore disableCache in client
1 parent 8961354 commit 770bc04

2 files changed

Lines changed: 42 additions & 4 deletions

File tree

crates/vite_task_client/src/lib.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,24 @@ impl Client {
8484
self.send(&Request::IgnoreOutput(&ns))
8585
}
8686

87-
/// Fire-and-forget — see [`Self::ignore_input`].
87+
/// Temporary no-op.
88+
///
89+
/// `disableCache` currently causes too many false opt-outs because tools
90+
/// call it during configuration, before they know whether they will start
91+
/// an uncached operation such as listening on a port or watching the
92+
/// filesystem.
8893
///
8994
/// # Errors
9095
///
91-
/// Returns an error if the request fails to send.
96+
/// This temporary no-op does not currently return errors.
97+
#[expect(
98+
clippy::missing_const_for_fn,
99+
clippy::unnecessary_wraps,
100+
clippy::unused_self,
101+
reason = "temporary no-op preserves the public API until disableCache semantics are redesigned"
102+
)]
92103
pub fn disable_cache(&self) -> io::Result<()> {
93-
self.send(&Request::DisableCache)
104+
Ok(())
94105
}
95106

96107
/// Requests an env value from the runner. Returns `None` if the runner

crates/vite_task_server/tests/integration.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type RawStream = std::fs::File;
1414
use rustc_hash::FxHashMap;
1515
use tokio::runtime::Builder;
1616
use vite_task_client::{Client, GetEnvsQuery};
17-
use vite_task_ipc_shared::Request;
17+
use vite_task_ipc_shared::{GetEnvResponse, Request};
1818
use vite_task_server::{EnvQuery, Error, Recorder, Reports, ServerHandle, serve};
1919

2020
fn env_map(pairs: &[(&str, &str)]) -> FxHashMap<Arc<OsStr>, Arc<OsStr>> {
@@ -82,6 +82,15 @@ fn send_frame(stream: &mut RawStream, request: &Request<'_>) {
8282
stream.flush().expect("flush");
8383
}
8484

85+
fn recv_get_env_response(stream: &mut RawStream) -> GetEnvResponse {
86+
let mut len_bytes = [0u8; 4];
87+
stream.read_exact(&mut len_bytes).expect("read len");
88+
let len = u32::from_le_bytes(len_bytes) as usize;
89+
let mut buf = vec![0; len];
90+
stream.read_exact(&mut buf).expect("read body");
91+
wincode::deserialize_exact(&buf).expect("deserialize response")
92+
}
93+
8594
#[test]
8695
fn single_client_fire_and_forget() {
8796
#[cfg(unix)]
@@ -93,6 +102,9 @@ fn single_client_fire_and_forget() {
93102
let client = connect(&envs);
94103
client.ignore_input(OsStr::new(in_path)).unwrap();
95104
client.ignore_output(OsStr::new(out_path)).unwrap();
105+
// Temporary workaround: the client currently ignores disableCache so
106+
// tools cannot opt out at configuration time before they perform the
107+
// operation that actually makes a task uncacheable.
96108
client.disable_cache().unwrap();
97109
flush(&client);
98110
})
@@ -102,6 +114,21 @@ fn single_client_fire_and_forget() {
102114
let outputs: Vec<_> = reports.ignored_outputs.iter().map(|p| p.as_path().as_os_str()).collect();
103115
assert_eq!(inputs, vec![OsStr::new(in_path)]);
104116
assert_eq!(outputs, vec![OsStr::new(out_path)]);
117+
assert!(!reports.cache_disabled);
118+
}
119+
120+
#[test]
121+
fn raw_disable_cache_request_disables_cache() {
122+
let reports = run_with_server(env_map(&[]), |envs| {
123+
let name = &envs[0].1;
124+
let mut stream = connect_raw(name);
125+
send_frame(&mut stream, &Request::DisableCache);
126+
let flush_name: Box<NativeStr> = OsStr::new("__VP_TEST_FLUSH__").into();
127+
send_frame(&mut stream, &Request::GetEnv { name: &flush_name, tracked: false });
128+
let _ = recv_get_env_response(&mut stream);
129+
})
130+
.expect("driver returned error");
131+
105132
assert!(reports.cache_disabled);
106133
}
107134

0 commit comments

Comments
 (0)