Skip to content

Commit cae1141

Browse files
committed
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
1 parent 60410b6 commit cae1141

3 files changed

Lines changed: 44 additions & 45 deletions

File tree

rust/crates/runtime/src/config.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,6 @@ use crate::sandbox::{FilesystemIsolationMode, SandboxConfig};
99
/// Schema name advertised by generated settings files.
1010
pub const CLAW_SETTINGS_SCHEMA_NAME: &str = "SettingsSchema";
1111

12-
/// Top-level settings keys recognized by the runtime configuration loader.
13-
const KNOWN_TOP_LEVEL_KEYS: &[&str] = &[
14-
"$schema",
15-
"enabledPlugins",
16-
"env",
17-
"hooks",
18-
"mcpServers",
19-
"model",
20-
"oauth",
21-
"permissionMode",
22-
"permissions",
23-
"plugins",
24-
"sandbox",
25-
];
26-
27-
/// Deprecated top-level keys mapped to their replacement guidance.
28-
const DEPRECATED_TOP_LEVEL_KEYS: &[(&str, &str)] = &[
29-
("allowedTools", "permissions.allow"),
30-
("ignorePatterns", "permissions.deny"),
31-
];
32-
3312
/// Origin of a loaded settings file in the configuration precedence chain.
3413
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
3514
pub enum ConfigSource {

rust/crates/runtime/src/prompt.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -253,30 +253,6 @@ fn read_git_status(cwd: &Path) -> Option<String> {
253253
}
254254
}
255255

256-
fn read_git_recent_commits(cwd: &Path) -> Option<String> {
257-
let output = Command::new("git")
258-
.args([
259-
"--no-optional-locks",
260-
"log",
261-
"--oneline",
262-
"--no-decorate",
263-
"-n",
264-
"5",
265-
])
266-
.current_dir(cwd)
267-
.output()
268-
.ok()?;
269-
if !output.status.success() {
270-
return None;
271-
}
272-
let stdout = String::from_utf8(output.stdout).ok()?;
273-
let trimmed = stdout.trim();
274-
if trimmed.is_empty() {
275-
None
276-
} else {
277-
Some(trimmed.to_string())
278-
}
279-
}
280256

281257
fn read_git_diff(cwd: &Path) -> Option<String> {
282258
let mut sections = Vec::new();

rust/crates/runtime/src/session.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,8 +1438,52 @@ mod tests {
14381438
/// Per-worktree session isolation: returns a session directory namespaced
14391439
/// by the workspace fingerprint of the given working directory.
14401440
/// This prevents parallel `opencode serve` instances from colliding.
1441+
/// Called by external consumers (e.g. clawhip) to enumerate sessions for a CWD.
1442+
#[allow(dead_code)]
14411443
pub fn workspace_sessions_dir(cwd: &std::path::Path) -> Result<std::path::PathBuf, SessionError> {
14421444
let store = crate::session_control::SessionStore::from_cwd(cwd)
14431445
.map_err(|e| SessionError::Io(std::io::Error::new(std::io::ErrorKind::Other, e.to_string())))?;
14441446
Ok(store.sessions_dir().to_path_buf())
14451447
}
1448+
1449+
#[cfg(test)]
1450+
mod workspace_sessions_dir_tests {
1451+
use super::*;
1452+
use std::fs;
1453+
1454+
#[test]
1455+
fn workspace_sessions_dir_returns_fingerprinted_path_for_valid_cwd() {
1456+
let tmp = std::env::temp_dir().join("claw-session-dir-test");
1457+
fs::create_dir_all(&tmp).expect("create temp dir");
1458+
1459+
let result = workspace_sessions_dir(&tmp);
1460+
assert!(
1461+
result.is_ok(),
1462+
"workspace_sessions_dir should succeed for a valid CWD, got: {:?}",
1463+
result
1464+
);
1465+
let dir = result.unwrap();
1466+
// The returned path should be non-empty and end with a hash component
1467+
assert!(!dir.as_os_str().is_empty());
1468+
// Two calls with the same CWD should produce identical paths (deterministic)
1469+
let result2 = workspace_sessions_dir(&tmp).unwrap();
1470+
assert_eq!(dir, result2, "workspace_sessions_dir must be deterministic");
1471+
1472+
fs::remove_dir_all(&tmp).ok();
1473+
}
1474+
1475+
#[test]
1476+
fn workspace_sessions_dir_differs_for_different_cwds() {
1477+
let tmp_a = std::env::temp_dir().join("claw-session-dir-a");
1478+
let tmp_b = std::env::temp_dir().join("claw-session-dir-b");
1479+
fs::create_dir_all(&tmp_a).expect("create dir a");
1480+
fs::create_dir_all(&tmp_b).expect("create dir b");
1481+
1482+
let dir_a = workspace_sessions_dir(&tmp_a).expect("dir a");
1483+
let dir_b = workspace_sessions_dir(&tmp_b).expect("dir b");
1484+
assert_ne!(dir_a, dir_b, "different CWDs must produce different session dirs");
1485+
1486+
fs::remove_dir_all(&tmp_a).ok();
1487+
fs::remove_dir_all(&tmp_b).ok();
1488+
}
1489+
}

0 commit comments

Comments
 (0)