Skip to content

Commit 92434dc

Browse files
authored
test(windows): repair the Windows MSVC test suite (NVIDIA#4862)
* fix(isolation): validate Unix socket paths the same way on every host Prior to this change, SandboxTransport::validate checked Unix socket paths with Path::is_absolute(). On Windows that requires a drive or UNC prefix, so a POSIX path such as /run/backend.sock was rejected as "invalid boundary control transport endpoint". The isolation backend registration work in NVIDIA#3898 added tests that register Unix endpoints in the core registration types, gateway config, gateway config preflight, and supervisor backend setup; all of them failed on the Windows MSVC runners. The Windows test job only runs on PRs labeled test:windows, so the break went unnoticed on main. Unix transport is refused at runtime on non-Unix hosts, so these paths are always POSIX paths regardless of where they are validated. Now, both the core registration validator and the sandbox backend protocol validator use a new openshell_core::paths::is_posix_absolute helper, which applies the POSIX rule (the path starts with '/') on every host. On Unix this matches is_absolute() exactly. Signed-off-by: Kris Hicks <[email protected]> * test(supervisor): run baseline write-back cases only on Unix hosts The startup policy write-refusal tests from NVIDIA#3785 rely on enrich_proto_baseline_paths adding the proxy baseline paths (/usr, /tmp, /dev/null, ...) to a policy, which triggers a write-back that the fake gateway then refuses. Enrichment only adds paths that exist on the host. Prior to this change, the tests assumed those paths exist, so on Windows enrichment added nothing, the precondition assertions failed, and the baseline case of permanent_codes_still_exit never saw a write to refuse. Now, the four baseline write-back tests are gated to Unix, and permanent_codes_still_exit checks the image policy upload case on every host and the baseline write-back case only on Unix. Signed-off-by: Kris Hicks <[email protected]> * test(server): scale the SQLite concurrent-write test for Windows fsync sqlite_concurrent_writes_return_their_own_resource_version (NVIDIA#4408) runs 8 writers that each make 25 unconditional and 25 version-checked writes against one row of an on-disk WAL database with synchronous=FULL. Writers serialize on the SQLite write lock and wait out sqlx's default 5s busy_timeout. Prior to this change, the per-commit fsync cost on the Windows runners was high enough that a waiting writer starved past that timeout and failed with "database is locked" after about 7s. Now, each writer makes 5 writes on Windows and 25 elsewhere. The test still races every writer on the same row, which is what it checks. Signed-off-by: Kris Hicks <[email protected]> * test(server): hold scope-mix locks for wall-clock time, not timer ticks random_scope_mix_never_deadlocks (NVIDIA#4147) runs 64 tasks of 50 random lock operations and holds each operation's locks for 0-2 ms, failing if the mix does not finish within 20s. Prior to this change, the hold was a tokio::time::sleep. Windows timers round a 1 ms sleep up to about 16 ms, and a quarter of the operations take the exclusive global lock, so the serialized holds alone took several seconds and the full mix exceeded the 20s deadline on the Windows runners. Now, occupy yields until a std::time::Instant deadline, so holds last 0-2 ms of wall-clock time on every platform and the deadline means the same thing everywhere. Signed-off-by: Kris Hicks <[email protected]> * test(supervisor): run sandbox instance host tests only on Unix hosts The sandbox_instance_host tests added with per-instance supervisor state (NVIDIA#4701) admit hosted instances through SandboxInstanceHost::new, which prepares a private directory per instance. Hosted sandbox instances are Unix-only: on other hosts prepare_private_dir returns "hosted sandbox instances require a Unix host". Prior to this change, the test module still compiled and ran on Windows, so all three tests failed while creating their host. Now, the test module is gated to Unix, and the Unix-only permission check inside one test no longer needs its own cfg attribute. Signed-off-by: Kris Hicks <[email protected]> --------- Signed-off-by: Kris Hicks <[email protected]>
1 parent 72e4eaa commit 92434dc

7 files changed

Lines changed: 46 additions & 18 deletions

File tree

‎crates/openshell-core/src/isolation_registration.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ pub enum SandboxTransport {
3434
impl SandboxTransport {
3535
pub fn validate(&self) -> Result<(), &'static str> {
3636
let valid = match self {
37-
Self::Unix { socket_path } => socket_path.is_absolute(),
37+
// Unix transport only runs on Unix hosts, but validation may not.
38+
Self::Unix { socket_path } => crate::paths::is_posix_absolute(socket_path),
3839
Self::Tcp {
3940
authority,
4041
addresses,

‎crates/openshell-core/src/paths.rs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ pub fn is_file_permissions_too_open(path: &Path) -> bool {
167167
std::fs::metadata(path).is_ok_and(|m| m.permissions().mode() & 0o077 != 0)
168168
}
169169

170+
/// Whether `path` is absolute under POSIX rules, whatever the host platform.
171+
pub fn is_posix_absolute(path: &Path) -> bool {
172+
path.to_str().is_some_and(|path| path.starts_with('/'))
173+
}
174+
170175
/// Compatibility re-export; authored policy path normalization is owned by
171176
/// `openshell-policy-schema`.
172177
pub use openshell_policy_schema::normalize_path;
@@ -175,6 +180,15 @@ pub use openshell_policy_schema::normalize_path;
175180
mod tests {
176181
use super::*;
177182

183+
#[test]
184+
fn is_posix_absolute_ignores_host_path_syntax() {
185+
assert!(is_posix_absolute(Path::new("/run/backend.sock")));
186+
assert!(is_posix_absolute(Path::new("/")));
187+
for path in ["", "relative", "./run", r"\run", r"C:\run", "C:/run"] {
188+
assert!(!is_posix_absolute(Path::new(path)), "{path}");
189+
}
190+
}
191+
178192
#[test]
179193
fn xdg_config_dir_respects_env() {
180194
// This test checks the logic — actual env var mutation is unsafe so

‎crates/openshell-sandbox-backend/src/boundary_protocol.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ impl SandboxTransport {
283283
pub fn validate(&self) -> Result<(), &'static str> {
284284
let valid = match self {
285285
Self::Unix { socket_path } | Self::RuntimeInitiatedUnix { socket_path } => {
286-
socket_path.is_absolute()
286+
openshell_core::paths::is_posix_absolute(socket_path)
287287
}
288288
Self::Tcp {
289289
authority,

‎crates/openshell-server/src/compute/mutation_guard.rs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,11 @@ mod tests {
11691169
if op.is_distributed() {
11701170
fleet.enter(op);
11711171
}
1172-
tokio::time::sleep(hold).await;
1172+
// Windows timers round a 1 ms sleep up to ~16 ms, so yield instead.
1173+
let until = std::time::Instant::now() + hold;
1174+
while std::time::Instant::now() < until {
1175+
tokio::task::yield_now().await;
1176+
}
11731177
if op.is_distributed() {
11741178
fleet.leave(op);
11751179
}

‎crates/openshell-server/src/persistence/tests.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2379,7 +2379,8 @@ async fn sqlite_concurrent_writes_return_their_own_resource_version() {
23792379
use std::sync::Arc;
23802380

23812381
const WRITERS: u64 = 8;
2382-
const WRITES: u64 = 25;
2382+
// Slow Windows fsync can starve a writer past the SQLite busy timeout.
2383+
const WRITES: u64 = if cfg!(windows) { 5 } else { 25 };
23832384

23842385
let tmp = tempfile::tempdir().expect("tempdir");
23852386
let url = on_disk_store_url(&tmp.path().join("openshell.db"));

‎crates/openshell-supervisor/src/lib.rs‎

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5620,6 +5620,8 @@ network_policies:
56205620
.await;
56215621
}
56225622

5623+
// Baseline enrichment adds host paths that only exist on Unix.
5624+
#[cfg(unix)]
56235625
#[tokio::test(start_paused = true)]
56245626
async fn startup_policy_write_refusal_baseline_write_back_waits_for_repair() {
56255627
// The gateway policy has network rules but lacks the proxy baseline
@@ -5749,6 +5751,8 @@ network_policies:
57495751
.await;
57505752
}
57515753

5754+
// Baseline enrichment adds host paths that only exist on Unix.
5755+
#[cfg(unix)]
57525756
#[tokio::test(start_paused = true)]
57535757
async fn startup_policy_write_refusal_baseline_repair_before_report_refetches() {
57545758
let mut repaired = proto_tcp_policy_fixture();
@@ -5892,6 +5896,8 @@ network_policies:
58925896
.await;
58935897
}
58945898

5899+
// Baseline enrichment adds host paths that only exist on Unix.
5900+
#[cfg(unix)]
58955901
#[tokio::test(start_paused = true)]
58965902
async fn startup_policy_write_refusal_write_back_outlasts_the_attempt_limit() {
58975903
// The same limit applies to a refused baseline-path write-back.
@@ -5979,6 +5985,8 @@ network_policies:
59795985
);
59805986
}
59815987

5988+
// Baseline enrichment adds host paths that only exist on Unix.
5989+
#[cfg(unix)]
59825990
#[tokio::test(start_paused = true)]
59835991
async fn startup_policy_write_refusal_global_policy_skips_baseline_write_back() {
59845992
use openshell_core::proto::{ConfigurationAdmissionState, PolicySource};
@@ -6067,18 +6075,18 @@ network_policies:
60676075
// Both writes are checked: the image policy upload to a gateway with
60686076
// no policy, and the write-back of a stored policy that lacks the
60696077
// proxy baseline paths.
6070-
let writes = [
6071-
(
6072-
"image policy upload",
6073-
unset_policy_snapshot(),
6074-
ImagePolicyDiscovery::Policy(Box::new(proto_tcp_policy_fixture())),
6075-
),
6076-
(
6077-
"baseline write-back",
6078-
settings_poll_result(Some(proto_tcp_policy_fixture()), 1, PolicySource::Sandbox),
6079-
ImagePolicyDiscovery::Missing,
6080-
),
6081-
];
6078+
let image_upload = (
6079+
"image policy upload",
6080+
unset_policy_snapshot(),
6081+
ImagePolicyDiscovery::Policy(Box::new(proto_tcp_policy_fixture())),
6082+
);
6083+
let baseline_write_back = (
6084+
"baseline write-back",
6085+
settings_poll_result(Some(proto_tcp_policy_fixture()), 1, PolicySource::Sandbox),
6086+
ImagePolicyDiscovery::Missing,
6087+
);
6088+
// Baseline enrichment adds host paths that only exist on Unix.
6089+
let writes = std::iter::once(image_upload).chain(cfg!(unix).then_some(baseline_write_back));
60826090
for (write, initial, discovery) in writes {
60836091
for code in [
60846092
tonic::Code::PermissionDenied,

‎crates/openshell-supervisor/src/sandbox_instance_host.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,8 @@ pub(crate) fn prepare_private_dir(_path: &Path) -> Result<()> {
745745
))
746746
}
747747

748-
#[cfg(test)]
748+
// Hosted sandbox instances require a Unix host.
749+
#[cfg(all(test, unix))]
749750
mod tests {
750751
use super::*;
751752
use http_body_util::BodyExt as _;
@@ -1050,7 +1051,6 @@ mod tests {
10501051

10511052
// Files that cannot be deleted keep the key reserved until a later
10521053
// removal deletes them. Root ignores the permission this relies on.
1053-
#[cfg(unix)]
10541054
if !nix::unistd::geteuid().is_root() {
10551055
use std::os::unix::fs::PermissionsExt as _;
10561056

0 commit comments

Comments
 (0)