From 3bbf48b1bf0c9d0148f5f1a756f385f05be5a158 Mon Sep 17 00:00:00 2001 From: Benoit de Chezelles Date: Fri, 20 Nov 2026 09:00:05 +0100 Subject: [PATCH] termwiz: Add a CI guard+tests for the compiled terminfo entry (#8368) The compiled terminfo is reduced to a single artifact that CI checks against its text source, failing on any drift. Tests load the embedded entry and cover an XTGETTCAP response. --- .github/workflows/termwiz.yml | 27 +++++++++++ ci/regen-binary-terminfo.sh | 11 +++++ term/src/terminalstate/mod.rs | 83 +++++++++++++++++++++++++++++++++- termwiz/data/wezterm | Bin 2852 -> 0 bytes 4 files changed, 120 insertions(+), 1 deletion(-) create mode 100755 ci/regen-binary-terminfo.sh delete mode 100644 termwiz/data/wezterm diff --git a/.github/workflows/termwiz.yml b/.github/workflows/termwiz.yml index 10c44f62b..eb595e024 100644 --- a/.github/workflows/termwiz.yml +++ b/.github/workflows/termwiz.yml @@ -12,6 +12,7 @@ on: - "filedescriptor/**" - "vtparse/**" - ".github/workflows/termwiz.yml" + - "ci/regen-binary-terminfo.sh" push: branches: - main @@ -23,8 +24,34 @@ on: - "filedescriptor/**" - "vtparse/**" - ".github/workflows/termwiz.yml" + - "ci/regen-binary-terminfo.sh" jobs: + check-terminfo: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v6 + + - name: "Install tic" + run: | + sudo apt-get update + sudo apt-get install -y ncurses-bin + + - name: "Check compiled terminfo is up to date" + run: | + bash ci/regen-binary-terminfo.sh + if git diff --exit-code -- termwiz/data/w/wezterm; then + echo "✅ termwiz/data/w/wezterm is up to date with termwiz/data/wezterm.terminfo" + else + echo "❌ termwiz/data/w/wezterm is out of date with termwiz/data/wezterm.terminfo" + echo # blank line + echo "Regenerate it with:" + echo " ci/regen-binary-terminfo.sh" + echo # blank line + exit 1 + fi + build-termwiz-all-features: runs-on: ubuntu-latest steps: diff --git a/ci/regen-binary-terminfo.sh b/ci/regen-binary-terminfo.sh new file mode 100755 index 000000000..eefb4dacb --- /dev/null +++ b/ci/regen-binary-terminfo.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +# Regenerate the compiled terminfo database from its text source. + +set -euo pipefail + +repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" + +# tic lays entries out as //, +# so this writes termwiz/data/w/wezterm. +tic -x -o "$repo_root/termwiz/data" "$repo_root/termwiz/data/wezterm.terminfo" diff --git a/term/src/terminalstate/mod.rs b/term/src/terminalstate/mod.rs index f2ad3a514..13f29b337 100644 --- a/term/src/terminalstate/mod.rs +++ b/term/src/terminalstate/mod.rs @@ -38,7 +38,7 @@ use crate::terminalstate::kitty::*; lazy_static::lazy_static! { static ref DB: Database = { - let data = include_bytes!("../../../termwiz/data/wezterm"); + let data = include_bytes!("../../../termwiz/data/w/wezterm"); Database::from_buffer(&data[..]).unwrap() }; } @@ -2890,3 +2890,84 @@ impl TerminalState { .unwrap_or(self.keyboard_encoding) } } + +#[cfg(test)] +mod test { + use super::*; + use std::sync::mpsc::Receiver; + use std::sync::Mutex; + use std::time::Duration; + use wezterm_escape_parser::Action; + + #[derive(Debug)] + struct TestConfig; + + impl crate::TerminalConfiguration for TestConfig { + fn color_palette(&self) -> ColorPalette { + ColorPalette::default() + } + } + + /// Captures everything the terminal writes and signals on flush, so a test + /// can wait for the writer thread to emit the response before reading it. + struct CaptureWriter { + buffer: Arc>>, + flushed: Sender<()>, + } + + impl Write for CaptureWriter { + fn write(&mut self, buf: &[u8]) -> std::io::Result { + self.buffer.lock().unwrap().extend_from_slice(buf); + Ok(buf.len()) + } + + fn flush(&mut self) -> std::io::Result<()> { + let _ = self.flushed.send(()); + Ok(()) + } + } + + /// Builds a terminal whose output is captured into `buffer`. + fn capture_terminal(buffer: &Arc>>) -> (TerminalState, Receiver<()>) { + let (flushed, flushed_rx) = channel(); + let writer = Box::new(CaptureWriter { + buffer: Arc::clone(buffer), + flushed, + }); + let state = TerminalState::new( + TerminalSize::default(), + Arc::new(TestConfig), + "WezTerm", + "O_o", + writer, + ); + (state, flushed_rx) + } + + #[test] + fn embedded_terminfo_is_valid() { + // Initializing the lazy_static database panics if the embedded + // terminfo file is missing or malformed. + assert!(DB.raw("Tc").is_some()); + } + + #[test] + fn xt_get_tcap_responds_from_embedded_terminfo() { + let buffer = Arc::new(Mutex::new(Vec::new())); + let (mut state, flushed_rx) = capture_terminal(&buffer); + + { + let mut performer = performer::Performer::new(&mut state); + performer.perform(Action::XtGetTcap(vec!["sitm".to_string()])); + } + + // Wait for the writer thread to write and flush the response. + flushed_rx + .recv_timeout(Duration::from_secs(5)) + .expect("terminal did not flush its response"); + + let response = String::from_utf8(buffer.lock().unwrap().clone()).unwrap(); + // 7369746D is hex for "sitm"; 1B5B336D is hex for the SGR italics sequence. + assert_eq!(response, "\x1bP1+r7369746D=1B5B336D\x1b\\"); + } +} diff --git a/termwiz/data/wezterm b/termwiz/data/wezterm deleted file mode 100644 index e402d3d9f32d8e32ce37ff35e521e5afb70731dd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2852 zcmb_eeTY<56hHUfyKCkbDu_8*D|yw_-1qK#Z$9>|j;Yn6yN$Vm+fG~V$LyCgyW`BP z&VG!V5K2WwQGXOg6cmI61^GvTeNa|N7D0g!{ZSBs5J4gRQBCLE`(|Wmm;UK7_nhDP z-E+>n@7(k5yfv%|*1|G)ku7gLo|!6T3b~m>nW>G%CW0elz1gNrZX(-T8ZQ7a{R4*D z2-Jo|YCqfntD!o_1+01!KtLmU+yuA42G|VS&@%yhp&jE6A-*35QI5hGlwk%=AwC0- z!Bg-oqSxUZyoLHayayk^CvX|QhAU`agTMyeRuzk~ zR<@JvVQuVQc93_N4S~SycrL1nN$9l->v))JMBkSYPll(ug<1Y|doVZ55 zSZl(wuN8dNJTtTXW?O4?%({ByCf>}W+S-nCPss19&sVDlco%<=XLyzu`4m6RALUQ; z=lLuA4gNNNmw(7V<6rV``S<)M{tLgx|K^QisaPe}iuGcPP@+Zb5_`n~(JlJKs3?d@ zaY~#K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