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.
This commit is contained in:
1 parent
0d11cabfc4
commit
3bbf48b1bf
4 files changed
+120
-1
No files matched your search
@@ -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:
|
||||
|
||||
Executable
+11
@@ -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 <dir>/<first-letter-of-name>/<name>,
|
||||
# so this writes termwiz/data/w/wezterm.
|
||||
tic -x -o "$repo_root/termwiz/data" "$repo_root/termwiz/data/wezterm.terminfo"
|
||||
@@ -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<Mutex<Vec<u8>>>,
|
||||
flushed: Sender<()>,
|
||||
}
|
||||
|
||||
impl Write for CaptureWriter {
|
||||
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
|
||||
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<Mutex<Vec<u8>>>) -> (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\\");
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Reference in new issue
Block a user