#[tokio::test]
async fn test_server_actually_prints_route_registration() {
use std::process::{Command, Stdio};
use std::time::Duration;
let mut server = Command::new("cargo")
.args([
"run",
"--bin",
"ruchy",
"--features",
"notebook",
"--",
"notebook",
"--port",
"9004",
])
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.expect("Failed to start server");
tokio::time::sleep(Duration::from_secs(5)).await;
let _ = server.kill();
let output = server.wait_with_output().expect("Failed to get output");
let stdout = String::from_utf8_lossy(&output.stdout);
let stderr = String::from_utf8_lossy(&output.stderr);
let combined = format!("{stdout}{stderr}");
println!("CAPTURED OUTPUT:");
println!("STDOUT: {stdout}");
println!("STDERR: {stderr}");
assert!(
combined.contains("📋 Registering API routes"),
"BUG DETECTED: Server never prints route registration message!"
);
assert!(
combined.contains("POST /api/execute - Code execution"),
"BUG DETECTED: Server doesn't register /api/execute endpoint!"
);
}
#[tokio::test]
async fn test_api_endpoint_returns_404() {
use std::process::{Command, Stdio};
use std::time::Duration;
use tokio::time::timeout;
let mut server = Command::new("cargo")
.args([
"run",
"--bin",
"ruchy",
"--features",
"notebook",
"--",
"notebook",
"--port",
"9005",
])
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()
.expect("Failed to start server");
tokio::time::sleep(Duration::from_secs(4)).await;
let client = reqwest::Client::new();
let response = timeout(
Duration::from_secs(3),
client
.post("http://localhost:9005/api/execute")
.json(&serde_json::json!({
"code": "2 + 2",
"cell_id": "test-cell",
"session_id": "test-session"
}))
.send(),
)
.await;
let _ = server.kill();
match response {
Ok(Ok(resp)) => {
assert_eq!(
resp.status(),
404,
"BUG CONFIRMED: API endpoint returns 404 - routes not registered!"
);
println!("✅ BUG CONFIRMED: /api/execute returns 404 as expected");
}
Ok(Err(e)) => {
panic!("Network error: {e}");
}
Err(_) => {
panic!("Request timed out");
}
}
}
#[test]
fn test_notebook_feature_flag_enabled() {
#[cfg(feature = "notebook")]
{
println!("✅ Notebook feature is enabled");
}
#[cfg(not(feature = "notebook"))]
panic!("❌ BUG: Notebook feature not enabled during test!");
}