1 use std::fs;2 use std::path::PathBuf;3 use std::time::Duration;4 5 use inf3r_deploy::{Deploy, DeployError, Priority, bytes, duration};6 7 /// One valid node with one bind, sized to the smallest honest file.8 const BASE: &str = "\9 [[node]]10 host = \"host\"11 bin_dir = \"bin\"12 bundle_dirs = [\"bundles\"]13 blob_dir = \"/var/blobs\"14 blob_bound = \"200GB\"15 web = { unix = \"/run/inf3r/web.sock\" }16 auth_file = \"/etc/inf3r/token\"17 18 [[node.bind]]19 bundle = \"example/gpu\"20 models = [\"example\"]21 devices = [\"cuda:0\", \"cuda:1\"]22 vram = [1024, 1024]23 pin = true24 max_inflight = 825 ";26 27 fn scratch(name: &str) -> PathBuf {28 let path = PathBuf::from("/tmp").join(format!("inf3r-deploy-{}-{name}", std::process::id()));29 let _ = fs::remove_dir_all(&path);30 fs::create_dir_all(&path).expect("a scratch directory");31 path32 }33 34 #[test]35 fn the_spec_example_parses() {36 let deploy = Deploy::parse(BASE).expect("base is valid");37 assert_eq!(deploy.node.host, "host");38 assert_eq!(deploy.node.blob_bound, Some(200_000_000_000));39 assert_eq!(deploy.node.binds.len(), 1);40 let bind = &deploy.node.binds[0];41 assert_eq!(bind.bundle, "example/gpu");42 assert!(bind.pin);43 assert_eq!(bind.max_inflight, Some(8));44 assert_eq!(bind.priority, Priority::Interactive);45 }46 47 #[test]48 fn weights_parse_in_order_and_are_empty_when_absent() {49 let deploy = Deploy::parse(BASE).expect("base is valid");50 assert!(deploy.node.binds[0].weights.is_empty());51 52 let text = BASE.replace(53 "devices = [\"cuda:0\", \"cuda:1\"]",54 "devices = [\"cuda:0\", \"cuda:1\"]\nweights = [\"b.gguf\", \"/models/a.gguf\"]",55 );56 let deploy = Deploy::parse(&text).expect("weights are valid");57 assert_eq!(58 deploy.node.binds[0].weights,59 vec![PathBuf::from("b.gguf"), PathBuf::from("/models/a.gguf")]60 );61 }62 63 #[test]64 fn one_model_in_two_binds_is_duplicate() {65 let text = format!(66 "{BASE}\n[[node.bind]]\nbundle = \"other\"\nmodels = [\"example\"]\ndevices = [\"cuda:0\"]\n"67 );68 assert_eq!(69 Deploy::parse(&text).unwrap_err(),70 DeployError::DuplicateModel("example".to_string())71 );72 }73 74 #[test]75 fn settle_uses_a_duration_and_defaults_when_absent() {76 assert_eq!(77 Deploy::parse(BASE).expect("base is valid").node.settle,78 Duration::from_secs(2)79 );80 let text = BASE.replace(81 "blob_bound = \"200GB\"",82 "blob_bound = \"200GB\"\nsettle = \"2s\"",83 );84 assert_eq!(85 Deploy::parse(&text).expect("settle is valid").node.settle,86 Duration::from_secs(2)87 );88 }89 90 #[test]91 fn a_bad_settle_is_a_duration_error_with_its_line() {92 let text = BASE.replace(93 "blob_bound = \"200GB\"",94 "blob_bound = \"200GB\"\nsettle = \"2x\"",95 );96 let err = Deploy::parse(&text).expect_err("2x has no unit");97 assert!(matches!(err, DeployError::Duration(_)), "{err:?}");98 assert!(err.to_string().contains("line "), "{err}");99 }100 101 #[test]102 fn byte_sizes_are_decimal() {103 assert_eq!(bytes("200GB"), Some(200_000_000_000));104 assert_eq!(bytes("1KB"), Some(1_000));105 assert_eq!(bytes("12"), Some(12));106 assert_eq!(bytes("512MB"), Some(512_000_000));107 }108 109 #[test]110 fn durations_use_their_suffix() {111 assert_eq!(duration("5m"), Some(Duration::from_secs(300)));112 assert_eq!(duration("90s"), Some(Duration::from_secs(90)));113 assert_eq!(duration("2h"), Some(Duration::from_secs(7_200)));114 assert_eq!(duration("1500ms"), Some(Duration::from_millis(1_500)));115 }116 117 #[test]118 fn idle_unload_with_pin_conflicts() {119 let text = format!(120 "{BASE}\n[[node.bind]]\nbundle = \"flux\"\nmodels = [\"video\"]\ndevices = [\"cuda:1\"]\nidle_unload = \"5m\"\n"121 );122 let deploy = Deploy::parse(&text).expect("idle without pin is valid");123 assert_eq!(124 deploy.node.binds[1].idle_unload,125 Some(Duration::from_secs(300))126 );127 128 let text = format!(129 "{BASE}\n[[node.bind]]\nbundle = \"flux\"\nmodels = [\"video\"]\ndevices = [\"cuda:1\"]\npin = true\nidle_unload = \"5m\"\n"130 );131 assert!(matches!(132 Deploy::parse(&text),133 Err(DeployError::Conflicting { .. })134 ));135 }136 137 #[test]138 fn a_typo_is_unknown_with_its_line() {139 let text = "\140 [[node]]141 host = \"h\"142 bin_dir = \"b\"143 bundle_dirs = [\"p\"]144 blob_dir = \"/b\"145 web = { unix = \"/w\" }146 auth_file = \"/t\"147 148 [[node.bind]]149 bundle = \"p\"150 models = [\"m\"]151 devices = [\"d\"]152 max_inflght = 8153 ";154 assert_eq!(155 Deploy::parse(text).unwrap_err(),156 DeployError::Unknown {157 line: 13,158 key: "max_inflght".to_string()159 }160 );161 }162 163 #[test]164 fn an_unclosed_string_is_syntax_with_its_line() {165 let text = "[[node]]\nhost = \"oops\n";166 assert!(matches!(167 Deploy::parse(text),168 Err(DeployError::Syntax { line: 2, .. })169 ));170 }171 172 #[test]173 fn comments_obey_strings() {174 let text = format!(175 "{BASE}\n[[node.bind]]\nbundle = \"#not-a-comment\" # a trailing comment\nmodels = [\"m2\"] # another\ndevices = [\"cuda:1\"]\n"176 );177 let deploy = Deploy::parse(&text).expect("comments are stripped");178 assert_eq!(deploy.node.binds[1].bundle, "#not-a-comment");179 }180 181 #[test]182 fn no_node_is_missing() {183 assert_eq!(184 Deploy::parse("# only a comment\n").unwrap_err(),185 DeployError::Missing("[[node]]")186 );187 }188 189 #[test]190 fn a_second_node_is_refused() {191 assert_eq!(192 Deploy::parse("[[node]]\n[[node]]\n").unwrap_err(),193 DeployError::ManyNodes194 );195 }196 197 #[test]198 fn web_accepts_a_unix_socket_a_tcp_address_or_both() {199 let text = BASE.replace(200 "web = { unix = \"/run/inf3r/web.sock\" }",201 "web = { unix = \"/run/x.sock\" }",202 );203 let deploy = Deploy::parse(&text).expect("a single unix socket is valid");204 assert_eq!(205 deploy.node.web.unix.as_deref(),206 Some(std::path::Path::new("/run/x.sock"))207 );208 assert_eq!(deploy.node.web.tcp, None);209 210 let text = BASE.replace(211 "web = { unix = \"/run/inf3r/web.sock\" }",212 "web = { tcp = \"100.64.0.5:8080\" }",213 );214 let deploy = Deploy::parse(&text).expect("a single TCP address is valid");215 assert_eq!(deploy.node.web.unix, None);216 assert_eq!(deploy.node.web.tcp.as_deref(), Some("100.64.0.5:8080"));217 218 let text = BASE.replace(219 "web = { unix = \"/run/inf3r/web.sock\" }",220 "web = { unix = \"/run/x.sock\", tcp = \"100.64.0.5:8080\" }",221 );222 let deploy = Deploy::parse(&text).expect("both listeners are valid");223 assert_eq!(224 deploy.node.web.unix.as_deref(),225 Some(std::path::Path::new("/run/x.sock"))226 );227 assert_eq!(deploy.node.web.tcp.as_deref(), Some("100.64.0.5:8080"));228 assert_eq!(deploy.node.conflicts(), Vec::new());229 230 let text = BASE.replace("web = { unix = \"/run/inf3r/web.sock\" }", "web = {}");231 assert_eq!(Deploy::parse(&text).unwrap_err(), DeployError::Web);232 }233 234 #[test]235 fn zero_max_inflight_is_zero() {236 let text = BASE.replace("max_inflight = 8", "max_inflight = 0");237 assert_eq!(238 Deploy::parse(&text).unwrap_err(),239 DeployError::Zero("max_inflight")240 );241 }242 243 #[test]244 fn vram_must_match_devices() {245 let text = BASE.replace("vram = [1024, 1024]", "vram = [1024]");246 assert!(matches!(247 Deploy::parse(&text),248 Err(DeployError::Conflicting { .. })249 ));250 }251 252 #[test]253 fn a_bind_needs_a_model() {254 let text = BASE.replace("models = [\"example\"]", "models = []");255 assert_eq!(256 Deploy::parse(&text).unwrap_err(),257 DeployError::Missing("models")258 );259 }260 261 fn two_binds() -> inf3r_deploy::Node {262 inf3r_deploy::Deploy::parse(263 "\264 [[node]]265 host = \"t\"266 bin_dir = \"./bin\"267 bundle_dirs = [\"./bundles\"]268 blob_dir = \"./blobs\"269 web = { unix = \"/run/inf3r.sock\" }270 auth_file = \"./token\"271 272 [[node.bind]]273 bundle = \"mock/x64-cpu\"274 models = [\"mock\"]275 devices = [\"gpu0\"]276 277 [[node.bind]]278 bundle = \"toy/x64-cpu\"279 models = [\"toy\"]280 devices = [\"gpu0\"]281 ",282 )283 .unwrap()284 .node285 }286 287 #[test]288 fn a_bound_node_has_no_conflicts() {289 assert_eq!(two_binds().conflicts(), Vec::new());290 }291 292 #[test]293 fn a_model_in_two_binds_is_a_conflict() {294 let mut node = two_binds();295 node.binds[1].models = vec!["mock".to_string()];296 let found = node.conflicts();297 assert_eq!(found.len(), 1, "{found:?}");298 assert_eq!(found[0].bind, Some(1));299 assert!(found[0].message.contains("mock"));300 }301 302 #[test]303 fn a_bundle_bound_twice_is_a_conflict() {304 let mut node = two_binds();305 node.binds[1].bundle = "mock/x64-cpu".to_string();306 let found = node.conflicts();307 assert_eq!(found.len(), 1, "{found:?}");308 assert!(found[0].message.contains("bound twice"));309 }310 311 #[test]312 fn a_pinned_model_with_an_idle_time_is_a_conflict() {313 let mut node = two_binds();314 node.binds[0].pin = true;315 node.binds[0].idle_unload = Some(std::time::Duration::from_secs(60));316 let found = node.conflicts();317 assert_eq!(found.len(), 1, "{found:?}");318 assert!(found[0].message.contains("never unloaded"));319 }320 321 #[test]322 fn an_id_that_leaves_the_bundle_directory_is_refused() {323 for id in ["../escape", "/abs", "a//b", ""] {324 let mut node = two_binds();325 node.binds[0].bundle = id.to_string();326 let found = node.conflicts();327 assert!(328 found.iter().any(|c| c.message.contains("not a path below")),329 "{id:?} was accepted: {found:?}"330 );331 }332 }333 334 #[test]335 fn every_conflict_is_reported_not_only_the_first() {336 let mut node = two_binds();337 node.binds[1].models = vec!["mock".to_string()];338 node.binds[1].bundle = "mock/x64-cpu".to_string();339 node.binds[1].devices = vec!["gpu1".to_string(), "gpu1".to_string()];340 node.binds[1].vram = vec![1];341 let found = node.conflicts();342 assert_eq!(found.len(), 4, "{found:?}");343 }344 345 #[test]346 fn the_cache_is_host_policy_and_never_a_bind_quota() {347 let text = BASE.replace(348 "auth_file = \"/etc/inf3r/token\"\n",349 "auth_file = \"/etc/inf3r/token\"\n\n[node.cache]\nenabled = true\npin_bound = \"20GB\"\nflush_budget = \"5s\"\ndefault_ttl = \"7d\"\n\n[[node.cache.class]]\nname = \"standard\"\nttl = \"7d\"\n\n[[node.cache.tier]]\nname = \"nvme\"\ndir = \"/var/cache/inf3r\"\nbound = \"100GB\"\nheadroom = \"20GB\"\n",350 );351 let text = text.replace(352 "max_inflight = 8",353 "max_inflight = 8\ncache_class = \"standard\"\ncache_mode = \"read_only\"",354 );355 let deploy = Deploy::parse(&text).expect("cache is valid");356 let cache = deploy.node.cache.expect("a cache table");357 assert!(cache.enabled);358 assert_eq!(cache.pin_bound, 20_000_000_000);359 assert_eq!(cache.tiers.len(), 1);360 assert_eq!(cache.classes[0].name, "standard");361 assert_eq!(362 deploy.node.binds[0].cache_class.as_deref(),363 Some("standard")364 );365 assert_eq!(366 deploy.node.binds[0].cache_mode,367 inf3r_deploy::CacheMode::ReadOnly368 );369 }370 371 #[test]372 fn an_unknown_cache_class_is_a_conflict() {373 let text = BASE.replace(374 "max_inflight = 8",375 "max_inflight = 8\ncache_class = \"missing\"",376 );377 let deploy = Deploy::parse(&text).expect("the file parses");378 assert!(379 deploy380 .node381 .conflicts()382 .iter()383 .any(|conflict| conflict.message.contains("cache_class missing"))384 );385 }386 387 #[test]388 fn a_container_bind_parses_its_runtime_fields() {389 let assets = scratch("container");390 let license = assets.join("license");391 fs::write(&license, "a license").expect("an asset");392 let node = format!(393 "auth_file = \"/etc/inf3r/token\"\nasset_dirs = [\"{}\"]\nsocket_dir = \"/run/inf3r\"\nprobe_image = \"inf3r/probe@sha256:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\"",394 assets.display()395 );396 let bind = format!(397 "devices = [\"cuda:0\", \"cuda:1\"]\nruntime = \"container\"\nimage = \"inf3r/example@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"\ncommand = [\"/opt/inf3r/plugin\"]\nnetwork = \"none\"\nmounts = [\"{}:/license:ro\"]\n",398 license.display()399 );400 let text = BASE401 .replace("devices = [\"cuda:0\", \"cuda:1\"]", &bind)402 .replace("auth_file = \"/etc/inf3r/token\"", &node);403 let deploy = Deploy::parse(&text).expect("a container bind parses");404 let bind = &deploy.node.binds[0];405 assert_eq!(bind.runtime, inf3r_deploy::Runtime::Container);406 assert_eq!(407 bind.image.as_deref(),408 Some(409 "inf3r/example@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"410 )411 );412 assert_eq!(bind.command, vec!["/opt/inf3r/plugin"]);413 assert_eq!(bind.network, "none");414 assert_eq!(bind.mounts.len(), 1);415 assert_eq!(bind.mounts[0].target, PathBuf::from("/license"));416 assert_eq!(bind.mounts[0].source, license);417 assert!(bind.mounts[0].read_only);418 assert_eq!(deploy.node.socket_dir, Some(PathBuf::from("/run/inf3r")));419 assert_eq!(420 deploy.node.probe_image.as_deref(),421 Some("inf3r/probe@sha256:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")422 );423 assert_eq!(deploy.node.conflicts(), Vec::new());424 }425 426 #[test]427 fn a_control_container_can_name_a_different_host_socket_root() {428 let text = BASE.replace(429 "auth_file = \"/etc/inf3r/token\"",430 "auth_file = \"/etc/inf3r/token\"\nsocket_dir = \"/run/inf3r\"\nsocket_host_dir = \"/run/user/1000/inf3r\"",431 );432 let deploy = Deploy::parse(&text).expect("the host root parses");433 assert_eq!(434 deploy.node.socket_host_dir,435 Some(PathBuf::from("/run/user/1000/inf3r"))436 );437 assert_eq!(deploy.node.conflicts(), Vec::new());438 439 let relative = BASE.replace(440 "auth_file = \"/etc/inf3r/token\"",441 "auth_file = \"/etc/inf3r/token\"\nsocket_dir = \"/run/inf3r\"\nsocket_host_dir = \"run/inf3r\"",442 );443 let deploy = Deploy::parse(&relative).expect("the value parses");444 assert!(445 deploy446 .node447 .conflicts()448 .iter()449 .any(|conflict| conflict.message.contains("socket_host_dir"))450 );451 452 let orphan = BASE.replace(453 "auth_file = \"/etc/inf3r/token\"",454 "auth_file = \"/etc/inf3r/token\"\nsocket_host_dir = \"/run/user/1000/inf3r\"",455 );456 let deploy = Deploy::parse(&orphan).expect("the value parses");457 assert!(458 deploy459 .node460 .conflicts()461 .iter()462 .any(|conflict| conflict.message.contains("needs socket_dir"))463 );464 }465 466 #[test]467 fn a_container_bind_refuses_an_unpinned_image_and_a_host_network() {468 let text = BASE.replace(469 "devices = [\"cuda:0\", \"cuda:1\"]",470 "devices = [\"cuda:0\", \"cuda:1\"]\nruntime = \"container\"\nimage = \"inf3r/example:latest\"\nnetwork = \"host\"",471 );472 let deploy = Deploy::parse(&text).expect("the parser reads the values");473 let found = deploy.node.conflicts();474 assert!(475 found.iter().any(|c| c.message.contains("latest")),476 "{found:?}"477 );478 assert!(479 found.iter().any(|c| c.message.contains("not none")),480 "{found:?}"481 );482 assert!(483 found.iter().any(|c| c.message.contains("probe_image")),484 "{found:?}"485 );486 }487 488 #[test]489 fn container_resource_limits_parse_and_apply_only_to_containers() {490 let text = BASE491 .replace(492 "devices = [\"cuda:0\", \"cuda:1\"]",493 "devices = [\"cuda:0\", \"cuda:1\"]\nruntime = \"container\"\nimage = \"inf3r/example:1\"\npids_limit = 64\nmemory = \"128MB\"\nshm = \"256MB\"\nlog_max_size = \"4MB\"\nlog_max_files = 2",494 )495 .replace(496 "auth_file = \"/etc/inf3r/token\"",497 "auth_file = \"/etc/inf3r/token\"\nprobe_image = \"inf3r/probe:1\"",498 );499 let deploy = Deploy::parse(&text).expect("the limits parse");500 let bind = &deploy.node.binds[0];501 assert_eq!(bind.pids_limit, Some(64));502 assert_eq!(bind.memory_bytes, Some(128_000_000));503 assert_eq!(bind.shm_bytes, Some(256_000_000));504 assert_eq!(bind.log_max_bytes, Some(4_000_000));505 assert_eq!(bind.log_max_files, Some(2));506 assert_eq!(deploy.node.conflicts(), Vec::new());507 508 let process = text509 .replace("runtime = \"container\"\n", "")510 .replace("image = \"inf3r/example:1\"\n", "");511 let deploy = Deploy::parse(&process).expect("the process bind parses");512 assert!(513 deploy514 .node515 .conflicts()516 .iter()517 .any(|conflict| conflict.message.contains("container limits"))518 );519 }520 521 #[test]522 fn a_cpu_container_bind_also_needs_a_probe() {523 let text = BASE524 .replace(525 "devices = [\"cuda:0\", \"cuda:1\"]",526 "devices = [\"cpu:0\"]\nruntime = \"container\"\nimage = \"inf3r/example:1\"",527 )528 .replace("vram = [1024, 1024]", "vram = [1024]");529 let deploy = Deploy::parse(&text).expect("the parser reads the CPU bind");530 let found = deploy.node.conflicts();531 assert!(532 found533 .iter()534 .any(|conflict| conflict.message.contains("probe_image")),535 "{found:?}"536 );537 538 let with_probe = text.replace(539 "auth_file = \"/etc/inf3r/token\"",540 "auth_file = \"/etc/inf3r/token\"\nprobe_image = \"inf3r/probe@sha256:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\"",541 );542 let deploy = Deploy::parse(&with_probe).expect("the CPU bind with a probe parses");543 assert_eq!(deploy.node.conflicts(), Vec::new());544 }545 546 #[test]547 fn a_writable_or_docker_socket_mount_is_refused() {548 let assets = scratch("socket");549 let socket = assets.join("docker.sock");550 fs::create_dir_all(&socket).expect("a socket-named directory");551 let node = format!(552 "auth_file = \"/etc/inf3r/token\"\nasset_dirs = [\"{}\"]\nprobe_image = \"inf3r/probe:1\"",553 assets.display()554 );555 let bind = format!(556 "devices = [\"cuda:0\", \"cuda:1\"]\nruntime = \"container\"\nimage = \"inf3r/example:1\"\nmounts = [\"{}:/var/run/docker.sock:rw\"]",557 socket.display()558 );559 let text = BASE560 .replace("devices = [\"cuda:0\", \"cuda:1\"]", &bind)561 .replace("auth_file = \"/etc/inf3r/token\"", &node);562 let deploy = Deploy::parse(&text).expect("the parser reads the mount");563 let found = deploy.node.conflicts();564 assert!(565 found.iter().any(|c| c.message.contains("Docker socket")),566 "{found:?}"567 );568 assert!(569 found.iter().any(|c| c.message.contains("writable")),570 "{found:?}"571 );572 }573 574 #[test]575 fn a_bare_image_name_is_not_a_pin() {576 let text = BASE.replace(577 "devices = [\"cuda:0\", \"cuda:1\"]",578 "devices = [\"cuda:0\", \"cuda:1\"]\nruntime = \"container\"\nimage = \"inf3r/example\"",579 );580 let text = text.replace(581 "auth_file = \"/etc/inf3r/token\"",582 "auth_file = \"/etc/inf3r/token\"\nprobe_image = \"inf3r/probe:1\"",583 );584 let deploy = Deploy::parse(&text).expect("the parser reads the name");585 let found = deploy.node.conflicts();586 assert!(587 found588 .iter()589 .any(|conflict| conflict.message.contains("no tag or digest")),590 "{found:?}"591 );592 }593 594 #[test]595 fn an_empty_probe_image_is_refused() {596 let text = BASE.replace(597 "devices = [\"cuda:0\", \"cuda:1\"]",598 "devices = [\"cuda:0\", \"cuda:1\"]\nruntime = \"container\"\nimage = \"inf3r/example:1\"",599 );600 let text = text.replace(601 "auth_file = \"/etc/inf3r/token\"",602 "auth_file = \"/etc/inf3r/token\"\nprobe_image = \"\"",603 );604 let deploy = Deploy::parse(&text).expect("the parser reads the empty value");605 let found = deploy.node.conflicts();606 assert!(607 found608 .iter()609 .any(|conflict| conflict.message.contains("probe_image")610 && conflict.message.contains("empty")),611 "{found:?}"612 );613 }614 615 #[test]616 fn a_mount_source_must_be_a_real_asset_below_an_asset_dir() {617 let assets = scratch("missing");618 let text = BASE619 .replace(620 "devices = [\"cuda:0\", \"cuda:1\"]",621 "devices = [\"cuda:0\", \"cuda:1\"]\nruntime = \"container\"\nimage = \"inf3r/example:1\"\nmounts = [\"/license:/license:ro\"]",622 )623 .replace(624 "auth_file = \"/etc/inf3r/token\"",625 &format!(626 "auth_file = \"/etc/inf3r/token\"\nasset_dirs = [\"{}\"]\nprobe_image = \"inf3r/probe:1\"",627 assets.display()628 ),629 );630 let deploy = Deploy::parse(&text).expect("the parser reads the path");631 let found = deploy.node.conflicts();632 assert!(633 found.iter().any(|c| c.message.contains("does not exist")),634 "{found:?}"635 );636 }637 638 #[test]639 fn a_mount_outside_asset_dirs_is_refused() {640 let assets = scratch("allow");641 let outside = scratch("outside");642 let license = outside.join("license");643 fs::write(&license, "a license").expect("an asset");644 let text = BASE645 .replace(646 "devices = [\"cuda:0\", \"cuda:1\"]",647 &format!(648 "devices = [\"cuda:0\", \"cuda:1\"]\nruntime = \"container\"\nimage = \"inf3r/example:1\"\nmounts = [\"{}:/license:ro\"]",649 license.display()650 ),651 )652 .replace(653 "auth_file = \"/etc/inf3r/token\"",654 &format!(655 "auth_file = \"/etc/inf3r/token\"\nasset_dirs = [\"{}\"]\nprobe_image = \"inf3r/probe:1\"",656 assets.display()657 ),658 );659 let deploy = Deploy::parse(&text).expect("the parser reads the path");660 let found = deploy.node.conflicts();661 assert!(662 found663 .iter()664 .any(|c| c.message.contains("not below an asset_dirs entry")),665 "{found:?}"666 );667 }668 669 #[test]670 fn a_symlink_mount_is_refused() {671 let assets = scratch("symlink");672 let real = assets.join("license");673 let link = assets.join("license-link");674 fs::write(&real, "a license").expect("an asset");675 std::os::unix::fs::symlink(&real, &link).expect("a symlink");676 let text = BASE677 .replace(678 "devices = [\"cuda:0\", \"cuda:1\"]",679 &format!(680 "devices = [\"cuda:0\", \"cuda:1\"]\nruntime = \"container\"\nimage = \"inf3r/example:1\"\nmounts = [\"{}:/license:ro\"]",681 link.display()682 ),683 )684 .replace(685 "auth_file = \"/etc/inf3r/token\"",686 &format!(687 "auth_file = \"/etc/inf3r/token\"\nasset_dirs = [\"{}\"]\nprobe_image = \"inf3r/probe:1\"",688 assets.display()689 ),690 );691 let deploy = Deploy::parse(&text).expect("the parser reads the symlink");692 let found = deploy.node.conflicts();693 assert!(694 found.iter().any(|c| c.message.contains("symlink")),695 "{found:?}"696 );697 }698 699 #[test]700 fn a_socket_parent_or_trailing_slash_is_refused() {701 let assets = scratch("socket-parent");702 let run = assets.join("run");703 fs::create_dir_all(&run).expect("a run directory");704 fs::write(run.join("docker.sock"), "").expect("a socket file");705 let text = BASE706 .replace(707 "devices = [\"cuda:0\", \"cuda:1\"]",708 &format!(709 "devices = [\"cuda:0\", \"cuda:1\"]\nruntime = \"container\"\nimage = \"inf3r/example:1\"\nmounts = [\"{}:/license:ro\"]",710 run.display()711 ),712 )713 .replace(714 "auth_file = \"/etc/inf3r/token\"",715 &format!(716 "auth_file = \"/etc/inf3r/token\"\nasset_dirs = [\"{}\"]\nprobe_image = \"inf3r/probe:1\"",717 assets.display()718 ),719 );720 let deploy = Deploy::parse(&text).expect("the parser reads the parent");721 let found = deploy.node.conflicts();722 assert!(723 found.iter().any(|c| c.message.contains("Docker socket")),724 "{found:?}"725 );726 727 let socket = run.join("docker.sock");728 let trailing = format!("{}/", socket.display());729 let text = text.replace(&run.display().to_string(), &trailing);730 let deploy = Deploy::parse(&text).expect("the parser reads the trailing slash");731 let found = deploy.node.conflicts();732 assert!(733 found.iter().any(|c| c.message.contains("Docker socket")),734 "{found:?}"735 );736 }