use std::{path::PathBuf, process::Command};
fn clawgallery_bin() -> PathBuf {
PathBuf::from(env!("CARGO_BIN_EXE_clawgallery"))
}
#[test]
fn vdr_serve_mlx_help_is_packaged_for_installed_cli() {
let temp = tempfile::tempdir().expect("tempdir");
let output = Command::new(clawgallery_bin())
.env("CLAWGALLERY_CONFIG_DIR", temp.path().join("state"))
.env("CLAWGALLERY_VDR_MLX_FAKE", "1")
.args(["vdr", "serve", "--backend", "mlx", "--help"])
.output()
.expect("clawgallery command should run");
assert!(
output.status.success(),
"serve help should succeed\nstdout:\n{}\nstderr:\n{}",
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)
);
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(stdout.contains("--dimensions"), "got: {stdout}");
assert!(stdout.contains("mlx"), "got: {stdout}");
}
#[test]
fn vdr_serve_help_lists_jina_mlx_backend() {
let temp = tempfile::tempdir().expect("tempdir");
let output = Command::new(clawgallery_bin())
.env("CLAWGALLERY_CONFIG_DIR", temp.path().join("state"))
.args(["vdr", "serve", "--help"])
.output()
.expect("clawgallery command should run");
assert!(output.status.success(), "serve help should succeed");
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(stdout.contains("jina-mlx"), "got: {stdout}");
}
#[test]
fn vdr_serve_help_lists_vsplade_backend() {
let temp = tempfile::tempdir().expect("tempdir");
let output = Command::new(clawgallery_bin())
.env("CLAWGALLERY_CONFIG_DIR", temp.path().join("state"))
.args(["vdr", "serve", "--help"])
.output()
.expect("clawgallery command should run");
assert!(output.status.success(), "serve help should succeed");
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(stdout.contains("vsplade"), "got: {stdout}");
}
#[test]
fn vdr_serve_help_lists_colqwen_backend() {
let temp = tempfile::tempdir().expect("tempdir");
let output = Command::new(clawgallery_bin())
.env("CLAWGALLERY_CONFIG_DIR", temp.path().join("state"))
.args(["vdr", "serve", "--help"])
.output()
.expect("clawgallery command should run");
assert!(output.status.success(), "serve help should succeed");
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(stdout.contains("colqwen"), "got: {stdout}");
}
#[test]
fn vdr_serve_jina_mlx_rejects_incompatible_dimensions() {
let temp = tempfile::tempdir().expect("tempdir");
let output = Command::new(clawgallery_bin())
.env("CLAWGALLERY_CONFIG_DIR", temp.path().join("state"))
.env("CLAWGALLERY_VDR_JINA_MLX_FAKE", "1")
.args([
"vdr",
"serve",
"--backend",
"jina-mlx",
"--dimensions",
"128",
])
.output()
.expect("clawgallery command should run");
assert!(!output.status.success(), "invalid dimensions should fail");
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(stderr.contains("requires 1024 dimensions"), "got: {stderr}");
}
#[test]
fn vdr_serve_mlx_rejects_remote_bind_without_allow_remote() {
let temp = tempfile::tempdir().expect("tempdir");
let output = Command::new(clawgallery_bin())
.env("CLAWGALLERY_CONFIG_DIR", temp.path().join("state"))
.env("CLAWGALLERY_VDR_MLX_FAKE", "1")
.args([
"vdr",
"serve",
"--backend",
"mlx",
"--host",
"0.0.0.0",
"--port",
"8877",
])
.output()
.expect("clawgallery command should run");
assert!(
!output.status.success(),
"remote bind should fail\nstdout:\n{}\nstderr:\n{}",
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)
);
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
stderr.contains("refusing to bind") && stderr.contains("non-loopback"),
"expected non-loopback refusal, got: {stderr}"
);
}
#[test]
fn vdr_serve_mlx_accepts_allow_remote_flag_for_python_launcher() {
let temp = tempfile::tempdir().expect("tempdir");
let output = Command::new(clawgallery_bin())
.env("CLAWGALLERY_CONFIG_DIR", temp.path().join("state"))
.env("CLAWGALLERY_VDR_MLX_FAKE", "1")
.args([
"vdr",
"serve",
"--backend",
"mlx",
"--allow-remote",
"--help",
])
.output()
.expect("clawgallery command should run");
assert!(
output.status.success(),
"serve help with --allow-remote should succeed\nstdout:\n{}\nstderr:\n{}",
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)
);
}
#[test]
fn vdr_serve_colqwen_rejects_remote_bind_without_allow_remote() {
let temp = tempfile::tempdir().expect("tempdir");
let output = Command::new(clawgallery_bin())
.env("CLAWGALLERY_CONFIG_DIR", temp.path().join("state"))
.env("CLAWGALLERY_VDR_COLQWEN_FAKE", "1")
.args([
"vdr",
"serve",
"--backend",
"colqwen",
"--host",
"0.0.0.0",
"--port",
"8878",
])
.output()
.expect("clawgallery command should run");
assert!(
!output.status.success(),
"remote bind should fail\nstdout:\n{}\nstderr:\n{}",
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)
);
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
stderr.contains("refusing to bind") && stderr.contains("non-loopback"),
"expected non-loopback refusal, got: {stderr}"
);
}
#[cfg(windows)]
#[test]
fn vdr_serve_mlx_on_windows_points_at_colqwen() {
let temp = tempfile::tempdir().expect("tempdir");
let output = Command::new(clawgallery_bin())
.env("CLAWGALLERY_CONFIG_DIR", temp.path().join("state"))
.env_remove("CLAWGALLERY_VDR_MLX_FAKE")
.args([
"vdr",
"serve",
"--backend",
"mlx",
"--host",
"127.0.0.1",
"--port",
"0",
])
.output()
.expect("clawgallery command should run");
assert!(!output.status.success(), "mlx on Windows should fail");
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(stderr.contains("colqwen"), "got: {stderr}");
assert!(stderr.contains("Apple Silicon"), "got: {stderr}");
assert!(
!stderr.contains("mlx_embeddings"),
"should not reach the Apple-only import, got: {stderr}"
);
}