test(core): add headless end-to-end tests and fix bugs they found
Adds crates/ghostty-core/tests/e2e_*.rs: 81 tests that drive the real core Surface, termio, pty and child processes through a fake runtime (recording apprt actions, in-memory clipboard) with a headless renderer (ghostty-renderer/src/headless.rs). They cover keys (legacy, DECCKM, kitty, modifyOtherKeys), keybinding actions and sequences, mouse selection/reporting/scrolling/links, clipboard incl. OSC 52 and paste safety, resize, focus, titles/pwd/bell/notifications/progress, child exit, and IME preedit. Fixes for issues found by the tests and by the Codex audit (docs/rewrite/notes/review-core-codex.md, all 9 items): - replacing a selection with copy-on-select panicked (stale tracked handles); global new_window no longer inherits a parent; the child environment uses the runtime's env wholesale so GTK's removals stick; Flatpak host resources path; locale recovery (ensureLocale) in apprt-gtk before GTK init and for CLI actions; failed screen-file opens propagate errors; OSC 52 base64 rules, CSI/ESC binding length limits and GHOSTTY_LOG parsing match Zig. - Also includes V2's termio cleanups (tmux viewer wiring in the stream handler, Pty slave semantics docs, shared cgroup wait loop). apprt-gtk gains a debug input replay hook (GHOSTTY_DEBUG_INPUT_SCRIPT) exercising the real GTK key path. With it, the real app was verified on Wayland: typing and output, new tab, splits, select-all/copy/paste and font size all work (docs/rewrite/notes/verification-V1.md). Not yet exercised at GTK level: mouse, real IM-context IME, clipboard dialogs. Test Plan: - cargo test --workspace (2983 passed) - cargo test -p ghostty-core --tests (81 e2e tests)
This commit is contained in:
1 parent
d650e5171b
commit
be6d706ba5
33 files changed
+3016
-222
No files matched your search
@@ -192,16 +192,63 @@ fn set_gtk_env(config: &CoreConfig) {
|
||||
set_env("GDK_DISABLE", &gdk_disable);
|
||||
}
|
||||
|
||||
/// Call `setlocale(LC_ALL, "")` like Ghostty's `global.zig` does at startup
|
||||
/// (see docs/rewrite/INTEGRATION_TODO.md). Idempotent.
|
||||
/// Port of Ghostty's `os/locale.zig` `ensureLocale` (called from
|
||||
/// `global.zig` at startup): set the process locale from the environment and,
|
||||
/// if that fails (usually an invalid `LANG`), retry with `LANG` unset, then fall
|
||||
/// back to `en_US.UTF-8` (updating `LANG` on success). Idempotent. This must
|
||||
/// run before GTK initializes and before the child environment is captured.
|
||||
#[allow(unsafe_code)]
|
||||
pub fn init_locale() {
|
||||
static ONCE: std::sync::Once = std::sync::Once::new();
|
||||
ONCE.call_once(|| {
|
||||
// SAFETY: called with a valid NUL-terminated empty string at startup
|
||||
// before other threads depend on the locale.
|
||||
// SAFETY: all strings are valid NUL-terminated C strings; this runs at
|
||||
// startup before other threads read the environment or locale.
|
||||
unsafe {
|
||||
libc::setlocale(libc::LC_ALL, c"".as_ptr());
|
||||
fn show(p: *const libc::c_char) -> String {
|
||||
// SAFETY: setlocale returns a valid C string when non-null.
|
||||
unsafe { std::ffi::CStr::from_ptr(p) }
|
||||
.to_string_lossy()
|
||||
.into_owned()
|
||||
}
|
||||
|
||||
// Set the locale to whatever is set in env vars.
|
||||
let r = libc::setlocale(libc::LC_ALL, c"".as_ptr());
|
||||
if !r.is_null() {
|
||||
log::info!("setlocale from env result={}", show(r));
|
||||
return;
|
||||
}
|
||||
|
||||
// setlocale failed, probably because LANG is invalid. Try again
|
||||
// without LANG to use the system default.
|
||||
if std::env::var_os("LANG").is_some_and(|v| !v.is_empty()) {
|
||||
// Both so that LANG is either empty or unset completely.
|
||||
libc::setenv(c"LANG".as_ptr(), c"".as_ptr(), 1);
|
||||
libc::unsetenv(c"LANG".as_ptr());
|
||||
|
||||
let r = libc::setlocale(libc::LC_ALL, c"".as_ptr());
|
||||
if !r.is_null() {
|
||||
let v = show(r);
|
||||
log::info!("setlocale after unset lang result={v}");
|
||||
|
||||
// An unsupported locale yields the "C" fallback; we
|
||||
// prefer moving on to en_US.UTF-8 in that case.
|
||||
if v != "C" {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Failure again... fallback to en_US.UTF-8
|
||||
log::warn!(
|
||||
"setlocale failed with LANG and system default. Falling back to en_US.UTF-8"
|
||||
);
|
||||
let r = libc::setlocale(libc::LC_ALL, c"en_US.UTF-8".as_ptr());
|
||||
if r.is_null() {
|
||||
log::warn!("setlocale failed even with the fallback, uncertain results");
|
||||
} else {
|
||||
libc::setenv(c"LANG".as_ptr(), c"en_US.UTF-8".as_ptr(), 1);
|
||||
log::info!("setlocale default result={}", show(r));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -605,6 +652,9 @@ impl Application {
|
||||
// Tell systemd that we are ready.
|
||||
ghostty_os::systemd::notify::ready();
|
||||
|
||||
// Developer aid: replay synthesized input (GHOSTTY_DEBUG_INPUT_SCRIPT).
|
||||
crate::debug_input::start(self);
|
||||
|
||||
log::debug!("entering runloop");
|
||||
let imp = self.imp();
|
||||
imp.running.set(true);
|
||||
|
||||
Reference in new issue
Block a user