- The README's wordmark is an animated GIF with a transparent background, rendered from the dashboard's own art and lights, in light and dark variants for GitHub's two themes. - The README says Luxe is built with AI assistance, much of it Luxe working on itself, and CONTRIBUTING has an AI-assistance section: say what helped, understand the change, write to people in your own words. - The redaction table's Google-key example is joined at compile time, so secret scanning stops reading the invented value as a leaked key. - The MCP trust tests read Luxe's own report of what it started, so a slow runner can neither fail them nor pass them falsely.
132 lines
5.4 KiB
Rust
132 lines
5.4 KiB
Rust
//! 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();
|
|
}
|
|
|
|
/// Whether Luxe launched the project's server. The marker is the proof when the child gets that far,
|
|
/// but the child is this test binary starting up again, and on a slow runner Luxe can give up on the
|
|
/// closed connection before that startup reaches the write; its report of the attempt is the proof
|
|
/// then. A refused server is never launched, so neither can appear.
|
|
fn started(project: &Path, stdout: &str) -> bool {
|
|
project.join("mcp-ran").exists() || stdout.contains("project-marker: failed to connect")
|
|
}
|
|
|
|
/// Whether Luxe refused to start the project's server: it says so, naming it. Checked alongside the
|
|
/// absent marker, which alone would also pass for a server launched too slowly to have written it.
|
|
fn refused(project: &Path, stdout: &str) -> bool {
|
|
stdout.contains("Not starting project MCP servers: project-marker")
|
|
&& !project.join("mcp-ran").exists()
|
|
}
|
|
|
|
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!(refused(project.path(), &stdout), "the project command ran: {stdout}");
|
|
assert!(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!(started(project.path(), &stdout), "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!(started(project.path(), &stdout), "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!(refused(project.path(), &stdout), "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!(refused(project.path(), &stdout), "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!(started(project.path(), &stdout), "the user command never ran: {stdout}");
|
|
}
|