mirror of
https://github.com/instructkr/claw-code.git
synced 2026-04-08 17:14:49 +08:00
fix(dead-code): remove stale constants + dead function; add workspace_sessions_dir tests
Three dead-code warnings eliminated from cargo check: 1. KNOWN_TOP_LEVEL_KEYS / DEPRECATED_TOP_LEVEL_KEYS in config.rs - Superseded by config_validate::TOP_LEVEL_FIELDS and DEPRECATED_FIELDS - Were out of date (missing aliases, providerFallbacks, trustedRoots) - Removed 2. read_git_recent_commits in prompt.rs - Private function, never called anywhere in the codebase - Removed 3. workspace_sessions_dir in session.rs - Public API scaffolded for session isolation (#41) - Genuinely useful for external consumers (clawhip enumerating sessions) - Added 2 tests: deterministic path for same CWD, different path for different CWDs - Annotated with #[allow(dead_code)] since it is external-facing API cargo check --workspace: 0 warnings remaining 430 runtime tests passing, 0 failing
This commit is contained in:
@@ -9,27 +9,6 @@ use crate::sandbox::{FilesystemIsolationMode, SandboxConfig};
|
|||||||
/// Schema name advertised by generated settings files.
|
/// Schema name advertised by generated settings files.
|
||||||
pub const CLAW_SETTINGS_SCHEMA_NAME: &str = "SettingsSchema";
|
pub const CLAW_SETTINGS_SCHEMA_NAME: &str = "SettingsSchema";
|
||||||
|
|
||||||
/// Top-level settings keys recognized by the runtime configuration loader.
|
|
||||||
const KNOWN_TOP_LEVEL_KEYS: &[&str] = &[
|
|
||||||
"$schema",
|
|
||||||
"enabledPlugins",
|
|
||||||
"env",
|
|
||||||
"hooks",
|
|
||||||
"mcpServers",
|
|
||||||
"model",
|
|
||||||
"oauth",
|
|
||||||
"permissionMode",
|
|
||||||
"permissions",
|
|
||||||
"plugins",
|
|
||||||
"sandbox",
|
|
||||||
];
|
|
||||||
|
|
||||||
/// Deprecated top-level keys mapped to their replacement guidance.
|
|
||||||
const DEPRECATED_TOP_LEVEL_KEYS: &[(&str, &str)] = &[
|
|
||||||
("allowedTools", "permissions.allow"),
|
|
||||||
("ignorePatterns", "permissions.deny"),
|
|
||||||
];
|
|
||||||
|
|
||||||
/// Origin of a loaded settings file in the configuration precedence chain.
|
/// Origin of a loaded settings file in the configuration precedence chain.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub enum ConfigSource {
|
pub enum ConfigSource {
|
||||||
|
|||||||
@@ -253,30 +253,6 @@ fn read_git_status(cwd: &Path) -> Option<String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_git_recent_commits(cwd: &Path) -> Option<String> {
|
|
||||||
let output = Command::new("git")
|
|
||||||
.args([
|
|
||||||
"--no-optional-locks",
|
|
||||||
"log",
|
|
||||||
"--oneline",
|
|
||||||
"--no-decorate",
|
|
||||||
"-n",
|
|
||||||
"5",
|
|
||||||
])
|
|
||||||
.current_dir(cwd)
|
|
||||||
.output()
|
|
||||||
.ok()?;
|
|
||||||
if !output.status.success() {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
let stdout = String::from_utf8(output.stdout).ok()?;
|
|
||||||
let trimmed = stdout.trim();
|
|
||||||
if trimmed.is_empty() {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(trimmed.to_string())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn read_git_diff(cwd: &Path) -> Option<String> {
|
fn read_git_diff(cwd: &Path) -> Option<String> {
|
||||||
let mut sections = Vec::new();
|
let mut sections = Vec::new();
|
||||||
|
|||||||
@@ -1438,8 +1438,52 @@ mod tests {
|
|||||||
/// Per-worktree session isolation: returns a session directory namespaced
|
/// Per-worktree session isolation: returns a session directory namespaced
|
||||||
/// by the workspace fingerprint of the given working directory.
|
/// by the workspace fingerprint of the given working directory.
|
||||||
/// This prevents parallel `opencode serve` instances from colliding.
|
/// This prevents parallel `opencode serve` instances from colliding.
|
||||||
|
/// Called by external consumers (e.g. clawhip) to enumerate sessions for a CWD.
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn workspace_sessions_dir(cwd: &std::path::Path) -> Result<std::path::PathBuf, SessionError> {
|
pub fn workspace_sessions_dir(cwd: &std::path::Path) -> Result<std::path::PathBuf, SessionError> {
|
||||||
let store = crate::session_control::SessionStore::from_cwd(cwd)
|
let store = crate::session_control::SessionStore::from_cwd(cwd)
|
||||||
.map_err(|e| SessionError::Io(std::io::Error::new(std::io::ErrorKind::Other, e.to_string())))?;
|
.map_err(|e| SessionError::Io(std::io::Error::new(std::io::ErrorKind::Other, e.to_string())))?;
|
||||||
Ok(store.sessions_dir().to_path_buf())
|
Ok(store.sessions_dir().to_path_buf())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod workspace_sessions_dir_tests {
|
||||||
|
use super::*;
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn workspace_sessions_dir_returns_fingerprinted_path_for_valid_cwd() {
|
||||||
|
let tmp = std::env::temp_dir().join("claw-session-dir-test");
|
||||||
|
fs::create_dir_all(&tmp).expect("create temp dir");
|
||||||
|
|
||||||
|
let result = workspace_sessions_dir(&tmp);
|
||||||
|
assert!(
|
||||||
|
result.is_ok(),
|
||||||
|
"workspace_sessions_dir should succeed for a valid CWD, got: {:?}",
|
||||||
|
result
|
||||||
|
);
|
||||||
|
let dir = result.unwrap();
|
||||||
|
// The returned path should be non-empty and end with a hash component
|
||||||
|
assert!(!dir.as_os_str().is_empty());
|
||||||
|
// Two calls with the same CWD should produce identical paths (deterministic)
|
||||||
|
let result2 = workspace_sessions_dir(&tmp).unwrap();
|
||||||
|
assert_eq!(dir, result2, "workspace_sessions_dir must be deterministic");
|
||||||
|
|
||||||
|
fs::remove_dir_all(&tmp).ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn workspace_sessions_dir_differs_for_different_cwds() {
|
||||||
|
let tmp_a = std::env::temp_dir().join("claw-session-dir-a");
|
||||||
|
let tmp_b = std::env::temp_dir().join("claw-session-dir-b");
|
||||||
|
fs::create_dir_all(&tmp_a).expect("create dir a");
|
||||||
|
fs::create_dir_all(&tmp_b).expect("create dir b");
|
||||||
|
|
||||||
|
let dir_a = workspace_sessions_dir(&tmp_a).expect("dir a");
|
||||||
|
let dir_b = workspace_sessions_dir(&tmp_b).expect("dir b");
|
||||||
|
assert_ne!(dir_a, dir_b, "different CWDs must produce different session dirs");
|
||||||
|
|
||||||
|
fs::remove_dir_all(&tmp_a).ok();
|
||||||
|
fs::remove_dir_all(&tmp_b).ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user