C1: alpha dry run fixes (Ctrl+C in terminal, ignored colour, find singular)
- Terminal: undo an inherited "ignore Ctrl+C" flag before starting a ConPTY shell (lutra_proc::enable_ctrl_c). Lutra started by the lutra CLI (CREATE_NEW_PROCESS_GROUP) passed it to every shell, so Ctrl+C stopped nothing. Test reruns itself with that flag. - Engine: an edited .gitignore/.ignore reports TreeChanged for its folder, so the tree greys newly ignored files (Add to .gitignore). - Find: "1 match", "1 file" instead of "1 files". - docs/alpha-checklist.md: steps corrected after the Windows dry run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
30de747ad6
commit
e228d11ef9
11 changed files with 173 additions and 20 deletions
|
|
@ -234,9 +234,18 @@ pub fn sync_buffer_dirs(state: &mut State) {
|
|||
workspace.pin_dirs(dirs);
|
||||
}
|
||||
|
||||
/// Whether `path` is an ignore file (`.gitignore`, `.ignore`) whose rules
|
||||
/// decide the `ignored` flag of the entries listed next to it.
|
||||
fn is_ignore_file(path: &Path) -> bool {
|
||||
path.file_name()
|
||||
.is_some_and(|name| name == ".gitignore" || name == ".ignore")
|
||||
}
|
||||
|
||||
/// Applies pending changes on disk to the state: hands them to the symbol
|
||||
/// index ([`crate::cmd::goto::note_disk_changes`]), queues
|
||||
/// [`Event::TreeChanged`] for affected directories, reloads clean buffers
|
||||
/// [`Event::TreeChanged`] for affected directories (also for the directory
|
||||
/// of an edited ignore file, whose entries may change their `ignored`
|
||||
/// flag), reloads clean buffers
|
||||
/// whose file changed, and queues [`Event::FileChangedOnDisk`] for dirty
|
||||
/// buffers and for buffers whose file disappeared.
|
||||
pub fn pump(state: &mut State) {
|
||||
|
|
@ -268,7 +277,12 @@ pub fn pump(state: &mut State) {
|
|||
add_dir(&to);
|
||||
gone.push(from);
|
||||
}
|
||||
VfsEvent::Modified { path } => modified.push(path),
|
||||
VfsEvent::Modified { path } => {
|
||||
if is_ignore_file(&path) {
|
||||
add_dir(&path);
|
||||
}
|
||||
modified.push(path);
|
||||
}
|
||||
VfsEvent::Failed(_) => {}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -381,6 +381,29 @@ fn tree_changes_are_reported_for_listed_directories() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn editing_gitignore_reports_its_directory_with_the_new_ignored_flag() {
|
||||
let (dir, mut engine, _) = open_project(&[(".gitignore", b"/var/\n"), ("notes.txt", b"note")]);
|
||||
let ignored = |engine: &mut Engine| {
|
||||
let listing = run(engine, "project.children", json!({"dir": ""})).value;
|
||||
listing["entries"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.find(|e| e["name"] == "notes.txt")
|
||||
.unwrap()["ignored"]
|
||||
.as_bool()
|
||||
.unwrap()
|
||||
};
|
||||
assert!(!ignored(&mut engine));
|
||||
fs::write(dir.path().join(".gitignore"), "/var/\n/notes.txt\n").unwrap();
|
||||
wait_for(
|
||||
&mut engine,
|
||||
|e| matches!(e, Event::TreeChanged { dir } if dir.is_empty()),
|
||||
);
|
||||
assert!(ignored(&mut engine));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn watched_directories_are_capped_least_recently_listed_first() {
|
||||
let (dir, mut engine, _) = open_project(&[]);
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ doc = false
|
|||
windows-sys = { version = "0.61.2", features = [
|
||||
"Win32_Foundation",
|
||||
"Win32_Security",
|
||||
"Win32_System_Console",
|
||||
"Win32_System_Diagnostics_ToolHelp",
|
||||
"Win32_System_JobObjects",
|
||||
"Win32_System_Threading",
|
||||
|
|
|
|||
|
|
@ -35,7 +35,8 @@
|
|||
//!
|
||||
//! [`adopt`] (Windows) puts a process started by someone else, the
|
||||
//! integrated terminal's ConPTY shell, into a kill-on-close job and returns
|
||||
//! a [`Guard`] that holds it.
|
||||
//! a [`Guard`] that holds it. [`enable_ctrl_c`] (Windows) undoes an
|
||||
//! inherited "ignore Ctrl+C" flag before that shell starts.
|
||||
|
||||
use std::io;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
|
@ -169,6 +170,18 @@ pub fn adopt(process: std::os::windows::io::RawHandle) -> io::Result<Guard> {
|
|||
Group::adopt(process).map(|group| Guard { group })
|
||||
}
|
||||
|
||||
/// Undoes an inherited "ignore Ctrl+C" flag (Windows only), so console
|
||||
/// programs started from now on, such as the integrated terminal's shell
|
||||
/// and what it runs, get Ctrl+C. Lutra inherits that flag when it is
|
||||
/// started with `CREATE_NEW_PROCESS_GROUP`, as the `lutra` CLI does.
|
||||
///
|
||||
/// # Errors
|
||||
/// The OS error of `SetConsoleCtrlHandler`.
|
||||
#[cfg(windows)]
|
||||
pub fn enable_ctrl_c() -> io::Result<()> {
|
||||
windows::enable_ctrl_c()
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
impl Guard {
|
||||
/// Terminates every process in the job.
|
||||
|
|
|
|||
|
|
@ -15,8 +15,12 @@
|
|||
//! [`Group::adopt`] puts a process someone else started (the terminal's
|
||||
//! ConPTY shell) into a new job by its handle.
|
||||
//!
|
||||
//! [`enable_ctrl_c`] undoes an inherited "ignore Ctrl+C" flag
|
||||
//! (`SetConsoleCtrlHandler(NULL, FALSE)`), so the terminal's shells pass
|
||||
//! Ctrl+C on to the programs they run.
|
||||
//!
|
||||
//! This is the one module in Lutra that allows `unsafe`: the job object,
|
||||
//! Tool Help and thread APIs are only reachable through FFI. Every call gets
|
||||
//! Tool Help, thread and console APIs are only reachable through FFI. Every call gets
|
||||
//! valid arguments by construction: handles come from `CreateJobObjectW`,
|
||||
//! `CreateToolhelp32Snapshot` or `OpenThread` (owned by an [`OwnedHandle`]
|
||||
//! right away) or from a live [`std::process::Child`], and the limit and
|
||||
|
|
@ -30,6 +34,7 @@ use std::os::windows::process::CommandExt;
|
|||
use std::process::Command;
|
||||
|
||||
use windows_sys::Win32::Foundation::INVALID_HANDLE_VALUE;
|
||||
use windows_sys::Win32::System::Console::SetConsoleCtrlHandler;
|
||||
use windows_sys::Win32::System::Diagnostics::ToolHelp::{
|
||||
CreateToolhelp32Snapshot, TH32CS_SNAPTHREAD, THREADENTRY32, Thread32First, Thread32Next,
|
||||
};
|
||||
|
|
@ -45,6 +50,22 @@ use windows_sys::Win32::System::Threading::{
|
|||
/// The exit code a process killed with its job reports.
|
||||
const KILLED_EXIT_CODE: u32 = 1;
|
||||
|
||||
/// Lets this process, and the console programs it starts from now on,
|
||||
/// handle Ctrl+C again: `SetConsoleCtrlHandler(NULL, FALSE)`.
|
||||
///
|
||||
/// A process started with `CREATE_NEW_PROCESS_GROUP` (the `lutra` CLI
|
||||
/// starts Lutra that way) ignores Ctrl+C, and its children inherit that.
|
||||
///
|
||||
/// # Errors
|
||||
/// The OS error of `SetConsoleCtrlHandler`.
|
||||
pub(crate) fn enable_ctrl_c() -> io::Result<()> {
|
||||
let ok = unsafe { SetConsoleCtrlHandler(None, 0) };
|
||||
if ok == 0 {
|
||||
return Err(io::Error::last_os_error());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The job a child runs in. Lutra holds the only handle; closing it (on
|
||||
/// drop, or when Lutra's process ends) kills every process in the job.
|
||||
pub(crate) struct Group {
|
||||
|
|
|
|||
|
|
@ -184,6 +184,11 @@ fn spawn_error(e: impl std::fmt::Display) -> TerminalError {
|
|||
impl Session {
|
||||
/// Starts a shell in a new pseudo terminal.
|
||||
///
|
||||
/// On Windows it first undoes an "ignore Ctrl+C" flag Lutra may have
|
||||
/// inherited ([`lutra_proc::enable_ctrl_c`]), because the shell and the
|
||||
/// programs it runs inherit it in turn and Ctrl+C would stop nothing. A
|
||||
/// failure there is ignored: the shell works without it.
|
||||
///
|
||||
/// # Errors
|
||||
/// [`TerminalError::InvalidSize`] for a size outside `1..=MAX_SIZE`,
|
||||
/// [`TerminalError::Spawn`] if the pty cannot be created, the program
|
||||
|
|
@ -210,6 +215,8 @@ impl Session {
|
|||
for (key, value) in &options.env {
|
||||
cmd.env(key, value);
|
||||
}
|
||||
#[cfg(windows)]
|
||||
let _ = lutra_proc::enable_ctrl_c();
|
||||
let mut child = pair.slave.spawn_command(cmd).map_err(spawn_error)?;
|
||||
drop(pair.slave);
|
||||
#[cfg(windows)]
|
||||
|
|
|
|||
|
|
@ -261,3 +261,50 @@ fn spawn_errors() {
|
|||
Err(TerminalError::InvalidSize { cols: 0, rows: 24 })
|
||||
));
|
||||
}
|
||||
|
||||
/// Set for the copy of this test binary that
|
||||
/// [`ctrl_c_stops_a_program_when_lutra_ignores_ctrl_c`] starts.
|
||||
#[cfg(windows)]
|
||||
const CTRL_C_CHILD: &str = "LUTRA_TERMINAL_CTRL_C_CHILD";
|
||||
|
||||
/// Ctrl+C in the terminal stops a running program even when Lutra was
|
||||
/// started with `CREATE_NEW_PROCESS_GROUP` (as `lutra` starts it), which
|
||||
/// makes a process and its children ignore Ctrl+C. Runs
|
||||
/// [`ctrl_c_child`] in a copy of this test binary started that way.
|
||||
#[cfg(windows)]
|
||||
#[test]
|
||||
fn ctrl_c_stops_a_program_when_lutra_ignores_ctrl_c() {
|
||||
use std::os::windows::process::CommandExt;
|
||||
const CREATE_NEW_PROCESS_GROUP: u32 = 0x0000_0200;
|
||||
let out = std::process::Command::new(std::env::current_exe().unwrap())
|
||||
.args(["--exact", "ctrl_c_child", "--nocapture", "--test-threads=1"])
|
||||
.env(CTRL_C_CHILD, "1")
|
||||
.creation_flags(CREATE_NEW_PROCESS_GROUP)
|
||||
.output()
|
||||
.unwrap();
|
||||
let text =
|
||||
String::from_utf8_lossy(&out.stdout).into_owned() + &String::from_utf8_lossy(&out.stderr);
|
||||
assert!(out.status.success(), "{text}");
|
||||
assert!(text.contains("1 passed"), "{text}");
|
||||
}
|
||||
|
||||
/// The part of [`ctrl_c_stops_a_program_when_lutra_ignores_ctrl_c`] that
|
||||
/// runs in the copy; does nothing in a normal test run.
|
||||
#[cfg(windows)]
|
||||
#[test]
|
||||
fn ctrl_c_child() {
|
||||
if std::env::var_os(CTRL_C_CHILD).is_none() {
|
||||
return;
|
||||
}
|
||||
let s = spawn(interactive(), 120);
|
||||
s.write(b"ping -n 60 127.0.0.1\r").unwrap();
|
||||
let (out, exit) = drive(&s, |out| out.matches("127.0.0.1").count() >= 3);
|
||||
assert!(exit.is_none(), "{out:?}");
|
||||
s.write(b"\x03").unwrap();
|
||||
s.write(b"echo lutra-after-%OS%\r").unwrap();
|
||||
let started = Instant::now();
|
||||
let (out, exit) = drive(&s, |out| out.contains("lutra-after-Windows"));
|
||||
assert!(exit.is_none(), "{out:?}");
|
||||
assert!(out.contains("lutra-after-Windows"), "{out:?}");
|
||||
assert!(started.elapsed() < Duration::from_secs(20), "{out:?}");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue