Files
yvgude--lean-ctx/rust/tests/claude_config_dir.rs
T
wehub-resource-sync 26382a7ac6
CI / Clippy (push) Failing after 15m13s
CI / Test (ubuntu-latest) (push) Failing after 16m1s
CI / Test (macos-latest) (push) Has been cancelled
CI / Test (windows-latest) (push) Has been cancelled
CI / Build (no embeddings / no ORT) (push) Has been cancelled
CI / Format (push) Has been cancelled
CI / Cookbook (Node) (push) Has been cancelled
CI / Pi Extension (Node) (push) Has been cancelled
CI / Rust SDK (lean-ctx-client) (push) Has been cancelled
CI / Embed SDK (lean-ctx-sdk) (push) Has been cancelled
CI / Python SDK (leanctx) (push) Has been cancelled
CI / Hermes Plugin (Python) (push) Has been cancelled
CI / SDK Conformance Matrix (push) Has been cancelled
CI / Coverage (push) Has been cancelled
CI / cargo-deny (push) Has been cancelled
CI / Adversarial Safety (push) Has been cancelled
CI / Benchmarks (push) Has been cancelled
CI / Output-Quality Gate (eval A/B) (push) Has been cancelled
CI / Documentation (push) Has been cancelled
CI / CI Green (push) Has been cancelled
JetBrains Plugin / Actionlint (push) Has been cancelled
CodeQL / Analyze (actions) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
CodeQL / Analyze (rust) (push) Has been cancelled
JetBrains Plugin / Validation (push) Has been cancelled
JetBrains Plugin / Build (push) Has been cancelled
JetBrains Plugin / Test (push) Has been cancelled
Security Check / Security Scan (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:35:30 +08:00

86 lines
2.7 KiB
Rust

//! Tests for `CLAUDE_CONFIG_DIR` support in instructions and compiler output.
//!
//! These tests modify process-global env vars — must run serialized.
use serial_test::serial;
#[test]
#[serial]
fn claude_code_instructions_default_path() {
// Ensure CLAUDE_CONFIG_DIR is unset so we get the default.
let prev = std::env::var("CLAUDE_CONFIG_DIR").ok();
unsafe { std::env::remove_var("CLAUDE_CONFIG_DIR") };
let instr = lean_ctx::instructions::claude_code_instructions();
assert!(
instr.contains("Full instructions at ~/.claude/CLAUDE.md"),
"Default instructions should reference ~/.claude/CLAUDE.md, got:\n{instr}"
);
// Restore.
if let Some(v) = prev {
unsafe { std::env::set_var("CLAUDE_CONFIG_DIR", v) };
}
}
#[test]
#[serial]
fn claude_code_instructions_custom_config_dir() {
let prev = std::env::var("CLAUDE_CONFIG_DIR").ok();
unsafe { std::env::set_var("CLAUDE_CONFIG_DIR", "~/.arc/claude") };
let instr = lean_ctx::instructions::claude_code_instructions();
assert!(
instr.contains("Full instructions at ~/.arc/claude/CLAUDE.md"),
"Custom CLAUDE_CONFIG_DIR should appear in instructions, got:\n{instr}"
);
assert!(
!instr.contains("Full instructions at ~/.claude/CLAUDE.md"),
"Default path should NOT appear when CLAUDE_CONFIG_DIR is set"
);
// Restore.
match prev {
Some(v) => unsafe { std::env::set_var("CLAUDE_CONFIG_DIR", v) },
None => unsafe { std::env::remove_var("CLAUDE_CONFIG_DIR") },
}
}
#[test]
#[serial]
fn claude_config_dir_display_resolves_home() {
let prev = std::env::var("CLAUDE_CONFIG_DIR").ok();
let home = dirs::home_dir().expect("need home dir for test");
let custom = format!("{}/.arc/claude", home.display());
unsafe { std::env::set_var("CLAUDE_CONFIG_DIR", &custom) };
let display = lean_ctx::instructions::claude_config_dir_display();
assert_eq!(
display, "~/.arc/claude",
"Absolute path under $HOME should be collapsed to tilde form"
);
// Restore.
match prev {
Some(v) => unsafe { std::env::set_var("CLAUDE_CONFIG_DIR", v) },
None => unsafe { std::env::remove_var("CLAUDE_CONFIG_DIR") },
}
}
#[test]
#[serial]
fn claude_config_dir_display_tilde_passthrough() {
let prev = std::env::var("CLAUDE_CONFIG_DIR").ok();
unsafe { std::env::set_var("CLAUDE_CONFIG_DIR", "~/.custom/claude") };
let display = lean_ctx::instructions::claude_config_dir_display();
assert_eq!(display, "~/.custom/claude");
// Restore.
match prev {
Some(v) => unsafe { std::env::set_var("CLAUDE_CONFIG_DIR", v) },
None => unsafe { std::env::remove_var("CLAUDE_CONFIG_DIR") },
}
}