Initial public release
Luxe 0.1.0: a coding agent harness for the terminal. See README.md to get started and CHANGELOG.md for releases.
This commit is contained in:
79
crates/luxe-cli/tests/mcp_commands/list.rs
Normal file
79
crates/luxe-cli/tests/mcp_commands/list.rs
Normal file
@@ -0,0 +1,79 @@
|
||||
use std::path::Path;
|
||||
|
||||
use super::{project_server, run_mcp};
|
||||
|
||||
fn user_server(home: &Path, id: &str) {
|
||||
let config = serde_json::json!({"mcpServers": {id: {
|
||||
"command": luxe_core::paths::display(&std::env::current_exe().unwrap()),
|
||||
"args": ["--exact", "mcp_marker_child", "--ignored"]
|
||||
}}});
|
||||
std::fs::create_dir_all(home.join("luxe")).unwrap();
|
||||
std::fs::write(home.join("luxe/mcp.json"), config.to_string()).unwrap();
|
||||
}
|
||||
|
||||
/// Filtering the list would hide project entries; omitting the label would hide their origin.
|
||||
#[test]
|
||||
fn list_keeps_and_marks_an_untrusted_project_server() {
|
||||
let project = tempfile::tempdir().unwrap();
|
||||
let home = tempfile::tempdir().unwrap();
|
||||
project_server(project.path());
|
||||
let stdout = run_mcp(project.path(), home.path(), false, "list");
|
||||
assert!(stdout.contains("project-marker"), "{stdout}");
|
||||
assert!(stdout.contains("enabled not started (project)"), "{stdout}");
|
||||
assert!(!project.path().join("mcp-ran").exists(), "listing must never start a server");
|
||||
}
|
||||
|
||||
/// The project label must not be attached to entries supplied by the user.
|
||||
#[test]
|
||||
fn list_does_not_mark_a_user_server_as_project_supplied() {
|
||||
let project = tempfile::tempdir().unwrap();
|
||||
let home = tempfile::tempdir().unwrap();
|
||||
user_server(home.path(), "user-marker");
|
||||
let stdout = run_mcp(project.path(), home.path(), false, "list");
|
||||
assert!(stdout.contains("user-marker") && stdout.contains("enabled"), "{stdout}");
|
||||
assert!(!stdout.contains("(project)"), "{stdout}");
|
||||
assert!(!project.path().join("mcp-ran").exists(), "listing must never start a server");
|
||||
}
|
||||
|
||||
/// Trust changes which commands may run, not who declared an entry or what a listing executes.
|
||||
#[test]
|
||||
fn list_still_marks_and_does_not_start_a_trusted_project_server() {
|
||||
let project = tempfile::tempdir().unwrap();
|
||||
let home = tempfile::tempdir().unwrap();
|
||||
project_server(project.path());
|
||||
let stdout = run_mcp(project.path(), home.path(), true, "list");
|
||||
assert!(
|
||||
stdout.contains("project-marker") && stdout.contains("not started (project)"),
|
||||
"{stdout}"
|
||||
);
|
||||
assert!(!project.path().join("mcp-ran").exists(), "trusted listing must not execute a server");
|
||||
}
|
||||
|
||||
/// Disabled entries must retain both their state and their project attribution.
|
||||
#[test]
|
||||
fn list_keeps_disabled_project_entries() {
|
||||
let project = tempfile::tempdir().unwrap();
|
||||
let home = tempfile::tempdir().unwrap();
|
||||
let config = serde_json::json!({"mcpServers": {"disabled-project": {
|
||||
"command": "unused-disabled-command", "enabled": false
|
||||
}}});
|
||||
std::fs::write(project.path().join(".mcp.json"), config.to_string()).unwrap();
|
||||
let stdout = run_mcp(project.path(), home.path(), false, "list");
|
||||
assert!(stdout.contains("disabled-project"), "{stdout}");
|
||||
assert!(stdout.contains("disabled not started (project)"), "{stdout}");
|
||||
}
|
||||
|
||||
/// A project override must not inherit the user's attribution from the shadowed entry.
|
||||
#[test]
|
||||
fn list_marks_a_project_override_of_a_user_server() {
|
||||
let project = tempfile::tempdir().unwrap();
|
||||
let home = tempfile::tempdir().unwrap();
|
||||
user_server(home.path(), "project-marker");
|
||||
project_server(project.path());
|
||||
let stdout = run_mcp(project.path(), home.path(), false, "list");
|
||||
assert!(stdout.contains("Configured MCP servers (1)"), "{stdout}");
|
||||
assert!(
|
||||
stdout.contains("project-marker") && stdout.contains("not started (project)"),
|
||||
"{stdout}"
|
||||
);
|
||||
}
|
||||
106
crates/luxe-cli/tests/mcp_commands/login.rs
Normal file
106
crates/luxe-cli/tests/mcp_commands/login.rs
Normal file
@@ -0,0 +1,106 @@
|
||||
use std::path::Path;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
use tokio::net::TcpListener;
|
||||
use tokio::process::Command;
|
||||
|
||||
async fn discovery_probe(listener: TcpListener, requests: Arc<AtomicUsize>) {
|
||||
// A mismatched resource ends discovery before any browser prompt or token exchange
|
||||
let body = r#"{"resource":"https://wrong.example/mcp","authorization_servers":["https://wrong.example"]}"#;
|
||||
let response = format!(
|
||||
"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}",
|
||||
body.len()
|
||||
);
|
||||
loop {
|
||||
let (mut socket, _) = listener.accept().await.unwrap();
|
||||
let mut request = [0; 4096];
|
||||
assert!(socket.read(&mut request).await.unwrap() > 0, "client sent no request");
|
||||
requests.fetch_add(1, Ordering::SeqCst);
|
||||
socket.write_all(response.as_bytes()).await.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
fn oauth_server(path: &Path, url: &str) {
|
||||
let config = serde_json::json!({"mcpServers": {"project-oauth": {
|
||||
"url": url, "auth": {"kind": "oauth"}
|
||||
}}});
|
||||
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
|
||||
std::fs::write(path, config.to_string()).unwrap();
|
||||
}
|
||||
|
||||
fn login_command(project: &Path, home: &Path, trust: bool) -> Command {
|
||||
let mut command = Command::new(env!("CARGO_BIN_EXE_luxe"));
|
||||
if trust {
|
||||
command.arg("--trust-project");
|
||||
}
|
||||
command
|
||||
.args(["mcp", "login", "--id", "project-oauth"])
|
||||
.current_dir(project)
|
||||
.env("XDG_CONFIG_HOME", home)
|
||||
.env("XDG_STATE_HOME", home.join("state"))
|
||||
.env("XDG_CACHE_HOME", home.join("cache"))
|
||||
.env_remove("LUXE_CONFIG_DIR")
|
||||
.env_remove("LUXE_STATE_DIR")
|
||||
.env("LUXE_MODELS_DEV_REFRESH", "0")
|
||||
.env("NO_PROXY", "127.0.0.1")
|
||||
.kill_on_drop(true);
|
||||
command
|
||||
}
|
||||
|
||||
async fn probe_login(trust: bool, user_server: bool) -> (String, String, usize) {
|
||||
let project = tempfile::tempdir().unwrap();
|
||||
let home = tempfile::tempdir().unwrap();
|
||||
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
|
||||
let url = format!("http://{}/mcp", listener.local_addr().unwrap());
|
||||
let path = if user_server {
|
||||
home.path().join("luxe/mcp.json")
|
||||
} else {
|
||||
project.path().join(".mcp.json")
|
||||
};
|
||||
oauth_server(&path, &url);
|
||||
run_probed_login(login_command(project.path(), home.path(), trust), listener).await
|
||||
}
|
||||
|
||||
async fn run_probed_login(mut command: Command, listener: TcpListener) -> (String, String, usize) {
|
||||
let requests = Arc::new(AtomicUsize::new(0));
|
||||
let probe = tokio::spawn(discovery_probe(listener, requests.clone()));
|
||||
let outcome = tokio::time::timeout(Duration::from_secs(10), command.output()).await;
|
||||
probe.abort();
|
||||
let stopped = probe.await.unwrap_err();
|
||||
assert!(stopped.is_cancelled(), "discovery probe failed: {stopped}");
|
||||
let output = outcome.expect("login must finish without a browser").unwrap();
|
||||
assert!(!output.status.success(), "the probe must stop login: {output:?}");
|
||||
(
|
||||
String::from_utf8(output.stdout).unwrap(),
|
||||
String::from_utf8(output.stderr).unwrap(),
|
||||
requests.load(Ordering::SeqCst),
|
||||
)
|
||||
}
|
||||
|
||||
/// Unfiltered login used to contact an OAuth endpoint chosen by an untrusted repository.
|
||||
#[tokio::test]
|
||||
async fn login_does_not_contact_an_untrusted_project_server() {
|
||||
let (stdout, stderr, requests) = probe_login(false, false).await;
|
||||
assert_eq!(requests, 0, "untrusted OAuth discovery ran: {stdout}\n{stderr}");
|
||||
assert!(stdout.contains("project-oauth") && stdout.contains("--trust-project"), "{stdout}");
|
||||
assert!(stderr.contains("not an OAuth-configured HTTP MCP server"), "{stderr}");
|
||||
}
|
||||
|
||||
/// Filtering login must not discard explicit project trust before OAuth discovery.
|
||||
#[tokio::test]
|
||||
async fn login_contacts_a_project_server_with_explicit_trust() {
|
||||
let (stdout, stderr, requests) = probe_login(true, false).await;
|
||||
assert!(requests > 0, "the trusted server was not contacted: {stdout}\n{stderr}");
|
||||
assert!(stderr.contains("refusing to send a token"), "{stderr}");
|
||||
}
|
||||
|
||||
/// A user's own OAuth server must remain available without granting the repository trust.
|
||||
#[tokio::test]
|
||||
async fn login_contacts_a_user_server_without_project_trust() {
|
||||
let (stdout, stderr, requests) = probe_login(false, true).await;
|
||||
assert!(requests > 0, "the user's server was not contacted: {stdout}\n{stderr}");
|
||||
assert!(stderr.contains("refusing to send a token"), "{stderr}");
|
||||
}
|
||||
116
crates/luxe-cli/tests/mcp_commands/main.rs
Normal file
116
crates/luxe-cli/tests/mcp_commands/main.rs
Normal file
@@ -0,0 +1,116 @@
|
||||
//! MCP commands — project servers must not start without the shared tooling trust grant.
|
||||
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
mod list;
|
||||
mod login;
|
||||
|
||||
fn project_server(project: &Path) {
|
||||
let config = serde_json::json!({"mcpServers": {"project-marker": {
|
||||
"command": luxe_core::paths::display(&std::env::current_exe().unwrap()),
|
||||
"args": ["--exact", "mcp_marker_child", "--ignored"],
|
||||
"enabled": true
|
||||
}}});
|
||||
std::fs::write(project.join(".mcp.json"), config.to_string()).unwrap();
|
||||
}
|
||||
|
||||
fn tools(project: &Path, home: &Path, trust: bool) -> String {
|
||||
run_mcp(project, home, trust, "tools")
|
||||
}
|
||||
|
||||
fn run_mcp(project: &Path, home: &Path, trust: bool, subcommand: &str) -> String {
|
||||
let mut command = Command::new(env!("CARGO_BIN_EXE_luxe"));
|
||||
if trust {
|
||||
command.arg("--trust-project");
|
||||
}
|
||||
let output = command
|
||||
.args(["mcp", subcommand])
|
||||
.current_dir(project)
|
||||
.env("XDG_CONFIG_HOME", home)
|
||||
.env("XDG_STATE_HOME", home.join("state"))
|
||||
.env("XDG_CACHE_HOME", home.join("cache"))
|
||||
.env("LUXE_MODELS_DEV_REFRESH", "0")
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(output.status.success(), "{output:?}");
|
||||
String::from_utf8(output.stdout).unwrap()
|
||||
}
|
||||
|
||||
fn tooling_preference(directory: &Path, preference: &str) {
|
||||
std::fs::create_dir_all(directory).unwrap();
|
||||
let config = serde_json::json!({"lsp": {"project_servers": preference}});
|
||||
std::fs::write(directory.join("config.json"), config.to_string()).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "subprocess fixture explicitly run by the MCP trust tests"]
|
||||
fn mcp_marker_child() {
|
||||
std::fs::write("mcp-ran", "started").unwrap();
|
||||
}
|
||||
|
||||
/// Unfiltered CLI discovery used to execute a command from an untrusted project's `.mcp.json`.
|
||||
#[test]
|
||||
fn tools_does_not_start_an_untrusted_project_server() {
|
||||
let project = tempfile::tempdir().unwrap();
|
||||
let home = tempfile::tempdir().unwrap();
|
||||
project_server(project.path());
|
||||
let stdout = tools(project.path(), home.path(), false);
|
||||
assert!(!project.path().join("mcp-ran").exists(), "the project command ran: {stdout}");
|
||||
assert!(stdout.contains("project-marker") && stdout.contains("--trust-project"), "{stdout}");
|
||||
}
|
||||
|
||||
/// Refusing every project server would silently discard the CLI's explicit trust grant.
|
||||
#[test]
|
||||
fn tools_starts_a_project_server_with_explicit_trust() {
|
||||
let project = tempfile::tempdir().unwrap();
|
||||
let home = tempfile::tempdir().unwrap();
|
||||
project_server(project.path());
|
||||
let stdout = tools(project.path(), home.path(), true);
|
||||
assert!(project.path().join("mcp-ran").exists(), "the trusted command never ran: {stdout}");
|
||||
}
|
||||
|
||||
/// CLI tools must honor the same global opt-in the engine uses.
|
||||
#[test]
|
||||
fn tools_honors_the_user_always_preference() {
|
||||
let project = tempfile::tempdir().unwrap();
|
||||
let home = tempfile::tempdir().unwrap();
|
||||
project_server(project.path());
|
||||
tooling_preference(&home.path().join("luxe"), "always");
|
||||
let stdout = tools(project.path(), home.path(), false);
|
||||
assert!(project.path().join("mcp-ran").exists(), "the user opt-in was ignored: {stdout}");
|
||||
}
|
||||
|
||||
/// Explicit trust must not override the user's global refusal to start project tooling.
|
||||
#[test]
|
||||
fn tools_honors_the_user_never_preference_even_with_trust() {
|
||||
let project = tempfile::tempdir().unwrap();
|
||||
let home = tempfile::tempdir().unwrap();
|
||||
project_server(project.path());
|
||||
tooling_preference(&home.path().join("luxe"), "never");
|
||||
let stdout = tools(project.path(), home.path(), true);
|
||||
assert!(!project.path().join("mcp-ran").exists(), "the user refusal was ignored: {stdout}");
|
||||
}
|
||||
|
||||
/// A repository must not grant itself permission by setting the global-only tooling preference.
|
||||
#[test]
|
||||
fn tools_ignores_a_project_always_preference() {
|
||||
let project = tempfile::tempdir().unwrap();
|
||||
let home = tempfile::tempdir().unwrap();
|
||||
project_server(project.path());
|
||||
tooling_preference(&project.path().join(".luxe"), "always");
|
||||
let stdout = tools(project.path(), home.path(), false);
|
||||
assert!(!project.path().join("mcp-ran").exists(), "the project granted itself trust: {stdout}");
|
||||
}
|
||||
|
||||
/// The trust filter must not block a server declared by the user, outside the project.
|
||||
#[test]
|
||||
fn tools_starts_a_user_server_without_project_trust() {
|
||||
let project = tempfile::tempdir().unwrap();
|
||||
let home = tempfile::tempdir().unwrap();
|
||||
project_server(project.path());
|
||||
std::fs::create_dir_all(home.path().join("luxe")).unwrap();
|
||||
std::fs::rename(project.path().join(".mcp.json"), home.path().join("luxe/mcp.json")).unwrap();
|
||||
let stdout = tools(project.path(), home.path(), false);
|
||||
assert!(project.path().join("mcp-ran").exists(), "the user command never ran: {stdout}");
|
||||
}
|
||||
Reference in New Issue
Block a user