use std::path::Path;
use tempfile::TempDir;
use tinyharness_lib::context::WorkspaceContext;
#[test]
fn context_detects_rust_project() {
let tmp = TempDir::new().unwrap();
std::fs::write(
tmp.path().join("Cargo.toml"),
"[package]\nname = \"test\"\nversion = \"0.1.0\"\n",
)
.unwrap();
std::fs::create_dir_all(tmp.path().join("src")).unwrap();
std::fs::write(tmp.path().join("src/main.rs"), "fn main() {}").unwrap();
let ctx = WorkspaceContext::collect();
assert!(!ctx.project_name.is_empty());
}
#[test]
fn context_detects_node_project() {
let tmp = TempDir::new().unwrap();
std::fs::write(
tmp.path().join("package.json"),
r#"{"name": "my-node-project", "version": "1.0.0"}"#,
)
.unwrap();
assert!(tmp.path().join("package.json").exists());
}
#[test]
fn context_empty_directory() {
let _tmp = TempDir::new().unwrap();
let ctx = WorkspaceContext::collect();
let _ = ctx;
}
#[test]
fn context_with_git_directory() {
let tmp = TempDir::new().unwrap();
std::fs::create_dir_all(tmp.path().join(".git")).unwrap();
std::fs::write(
tmp.path().join("Cargo.toml"),
"[package]\nname = \"test\"\n",
)
.unwrap();
assert!(tmp.path().join(".git").exists());
}
#[test]
fn context_monorepo_detection() {
let tmp = TempDir::new().unwrap();
std::fs::write(
tmp.path().join("Cargo.toml"),
"[package]\nname = \"test\"\n",
)
.unwrap();
std::fs::write(
tmp.path().join("package.json"),
r#"{"name": "frontend", "version": "1.0.0"}"#,
)
.unwrap();
assert!(tmp.path().join("Cargo.toml").exists());
assert!(tmp.path().join("package.json").exists());
}
#[test]
fn context_instruction_file_tinyharness() {
let tmp = TempDir::new().unwrap();
std::fs::write(
tmp.path().join("TINYHARNESS.md"),
"# Test Project\nInstructions here.",
)
.unwrap();
assert!(Path::new(&tmp.path().join("TINYHARNESS.md")).exists());
}
#[test]
fn context_instruction_file_agents() {
let tmp = TempDir::new().unwrap();
std::fs::write(
tmp.path().join("AGENTS.md"),
"# Agents\nAgent instructions.",
)
.unwrap();
assert!(Path::new(&tmp.path().join("AGENTS.md")).exists());
}