Skip to content

Commit 10cbe90

Browse files
committed
fix: add cross-platform symlink_dir helper for Windows compatibility
Uses std::os::unix::fs::symlink on Unix and std::os::windows::fs::symlink_dir on Windows, allowing tests to run on both platforms.
1 parent 593d2a3 commit 10cbe90

2 files changed

Lines changed: 50 additions & 8 deletions

File tree

code-rs/core/src/skills/loader.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,19 @@ fn extract_frontmatter(contents: &str) -> Option<String> {
322322
#[cfg(test)]
323323
mod tests {
324324
use super::*;
325-
use std::os::unix::fs::symlink;
326325
use tempfile::TempDir;
327326

327+
/// Cross-platform directory symlink helper.
328+
#[cfg(unix)]
329+
fn symlink_dir(src: &Path, dst: &Path) -> std::io::Result<()> {
330+
std::os::unix::fs::symlink(src, dst)
331+
}
332+
333+
#[cfg(windows)]
334+
fn symlink_dir(src: &Path, dst: &Path) -> std::io::Result<()> {
335+
std::os::windows::fs::symlink_dir(src, dst)
336+
}
337+
328338
fn write_skill(dir: &Path, name: &str, description: &str) -> PathBuf {
329339
let skill_dir = dir.join(name);
330340
fs::create_dir_all(&skill_dir).unwrap();
@@ -348,7 +358,7 @@ mod tests {
348358
write_skill(shared.path(), "shared-skill", "A shared skill");
349359

350360
// Symlink the shared directory into skills root
351-
symlink(shared.path(), skills_root.join("shared")).unwrap();
361+
symlink_dir(shared.path(), &skills_root.join("shared")).unwrap();
352362

353363
let mut outcome = SkillLoadOutcome::default();
354364
discover_skills_under_root(&skills_root, SkillScope::User, &mut outcome);
@@ -368,7 +378,7 @@ mod tests {
368378
write_skill(shared.path(), "shared-skill", "A shared skill");
369379

370380
// Symlink the shared directory into skills root
371-
symlink(shared.path(), skills_root.join("shared")).unwrap();
381+
symlink_dir(shared.path(), &skills_root.join("shared")).unwrap();
372382

373383
let mut outcome = SkillLoadOutcome::default();
374384
discover_skills_under_root(&skills_root, SkillScope::System, &mut outcome);
@@ -384,7 +394,7 @@ mod tests {
384394
fs::create_dir_all(&cycle_dir).unwrap();
385395

386396
// Create a circular symlink
387-
symlink(&cycle_dir, cycle_dir.join("loop")).unwrap();
397+
symlink_dir(&cycle_dir, &cycle_dir.join("loop")).unwrap();
388398

389399
// Also add a real skill to verify we still find it
390400
write_skill(&cycle_dir, "real-skill", "A real skill");

code-rs/tui/src/tui.rs

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,16 @@ pub fn stdout_ready_for_writes() -> bool {
345345
}
346346

347347
fn should_enable_alternate_scroll_mode() -> bool {
348-
// macOS Terminal hijacks scrolling when 1007h is set without also enabling
349-
// mouse reporting, so skip the escape in that environment.
350-
!matches!(env::var("TERM_PROGRAM"), Ok(value) if value.eq_ignore_ascii_case("Apple_Terminal"))
348+
// Hard overrides first.
349+
if env::var("CODE_DISABLE_ALT_SCROLL").map(|v| v == "1").unwrap_or(false) {
350+
return false;
351+
}
352+
if env::var("CODE_ENABLE_ALT_SCROLL").map(|v| v == "1").unwrap_or(false) {
353+
return true;
354+
}
355+
356+
// Default off to preserve native terminal scrollback + selection behavior.
357+
false
351358
}
352359

353360
/// Clear the current screen (normal buffer) with the theme background and reset cursor.
@@ -428,7 +435,7 @@ pub(crate) fn should_enable_keyboard_enhancement() -> bool {
428435

429436
#[cfg(test)]
430437
mod tests {
431-
use super::should_enable_keyboard_enhancement;
438+
use super::{should_enable_alternate_scroll_mode, should_enable_keyboard_enhancement};
432439

433440
#[test]
434441
fn keyboard_enhancement_respects_env_overrides() {
@@ -458,6 +465,31 @@ mod tests {
458465
restore_env("CODE_DISABLE_KBD_ENHANCEMENT", prev_disable);
459466
}
460467

468+
#[test]
469+
fn alternate_scroll_mode_respects_env_overrides() {
470+
let prev_enable = std::env::var("CODE_ENABLE_ALT_SCROLL").ok();
471+
let prev_disable = std::env::var("CODE_DISABLE_ALT_SCROLL").ok();
472+
473+
unsafe {
474+
std::env::remove_var("CODE_ENABLE_ALT_SCROLL");
475+
std::env::remove_var("CODE_DISABLE_ALT_SCROLL");
476+
}
477+
assert!(!should_enable_alternate_scroll_mode());
478+
479+
unsafe {
480+
std::env::set_var("CODE_ENABLE_ALT_SCROLL", "1");
481+
}
482+
assert!(should_enable_alternate_scroll_mode());
483+
484+
unsafe {
485+
std::env::set_var("CODE_DISABLE_ALT_SCROLL", "1");
486+
}
487+
assert!(!should_enable_alternate_scroll_mode());
488+
489+
restore_env("CODE_ENABLE_ALT_SCROLL", prev_enable);
490+
restore_env("CODE_DISABLE_ALT_SCROLL", prev_disable);
491+
}
492+
461493
fn restore_env(key: &str, value: Option<String>) {
462494
match value {
463495
Some(value) => unsafe { std::env::set_var(key, value) },

0 commit comments

Comments
 (0)