8000 test: close 126 surviving mutants from the untangle run by aorumbayev · Pull Request #111 · kagan-sh/kagan · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0d82f20
test(domain): pin browser input edges, paste text-or-file, thread liv…
aorumbayev Nov 9, 2026
b019bff
test(store): cover listing every environment
aorumbayev Nov 9, 2026
ae6e126
test(process): cover the login shell PATH, warm-up, and tree kills; e…
aorumbayev Nov 9, 2026
a526dc2
test(kg): pin the paste size cap at its edge and in the reported size
aorumbayev Nov 9, 2026
1745d03
test(terminal): cover the snapshot bound, kept lines, paste, and stop
aorumbayev Nov 9, 2026
adc3103
fix(plugins): count the first whole line of a log tail
aorumbayev Nov 9, 2026
9583626
test(plugins): pin the caps, index limits, staging, host pause, and t…
aorumbayev Nov 10, 2026
c428ad7
fix(core): a blank last line is not a cut in the shown script
aorumbayev Nov 10, 2026
2116360
test(core): pin plugin folders, the cache, preview caps, settings kin…
aorumbayev Nov 10, 2026
87a15f2
test(core): pin the plugin persona and tools, the requester rename lo…
aorumbayev Nov 10, 2026
5cfb259
test(ui): pin each install kind's update action and label; exclude th…
aorumbayev Nov 10, 2026
fcaa197
refactor(core): move two test modules into their own files
aorumbayev Nov 10, 2026
4e7d067
test(core): pin the settle time, a busy parent's silence, and the bus…
aorumbayev Nov 10, 2026
1aa6608
refactor(ui): move the Windows capture into its own file and exclude …
aorumbayev Nov 10, 2026
c2e6cd9
test(ui): pin the start folder, summary dot, archived list, attention…
aorumbayev Nov 10, 2026
66b1279
test(terminal): import Finished for the restore tests on every platform
aorumbayev Nov 10, 2026
be28c08
test(core): put the unix cfg back on the executable-bit test
aorumbayev Nov 10, 2026
35102da
test(plugins): run the git index cap test on unix only
aorumbayev Nov 10, 2026
f34babf
build(mutants): name whole-function excludes instead of pinning lines
aorumbayev Nov 10, 2026
28e6efa
test(core): make the settle test kill the sign flip
aorumbayev Nov 10, 2026
82a6625
test(ui): drop the busy-dot helper and exclude its paint comparisons
aorumbayev Nov 10, 2026
c521fa1
test(ui): cover the removal of a page whose view is gone, and drop th…
aorumbayev Nov 10, 2026
91d0c6f
test(core): set HOME to a fixed path in the user home test
aorumbayev Nov 10, 2026
fdf3b45
test(core): keep the requester alive in the rename lock test
aorumbayev Nov 10, 2026
5208f89
test(terminal): assert the literal transcript and tail of a restored …
aorumbayev Nov 10, 2026
4a7fa2f
fix(core): keep the newline of a blank first line in the shown script
aorumbayev Nov 10, 2026
3f2ad58
merge origin/main into the PR branch
aorumbayev Nov 10, 2026
1e6560c
refactor(core): move the script and settings test modules into their …
aorumbayev Nov 10, 2026
58780b4
test(core): answer the commands request in the persona test
aorumbayev Nov 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .cargo/mutants.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ exclude_globs = [
"crates/*/tests/**",
"**/tests.rs",
"**/*_test.rs",
# The Windows screen capture. It is platform-only, and CI's mutants run on Linux, which does not compile it.
"crates/ui/src/ui_driver/windows.rs",
]

exclude_re = [
Expand All @@ -15,4 +17,30 @@ exclude_re = [
# `highlight` returns early for "text" or an empty source. Without it, `highlight_cached` gives
# the same empty result for "text", so the early return only saves a parse.
'syntax\.rs:\d+:\d+: replace \|\| with && in highlight\b',
# The limit compares two clock readings; > and >= differ only within the same nanosecond.
'process\.rs:\d+:\d+: replace > with >= in Process::wait_within',
# The Windows and macOS clipboard write. CI's mutants run on Linux, which compiles the other write_png.
'clipboard\.rs:25:5: replace write_png -> Result<HostValue, HostError> with Ok\(Default::default\(\)\)',
# The production stub is compiled only outside tests; the test build has its own hold.
'runtime/host/mod\.rs:\d+:\d+: replace hold -> bool with true',
# The keychain module is compiled out of every test build, and it talks to the OS keychain.
'keychain\.rs:\d+:\d+: replace use_keychain with \(\)',
'keychain\.rs:\d+:\d+: replace <impl keyring_core::api::CredentialStoreApi for Keychain>::vendor',
# The macOS screen capture. CI's mutants run on Linux, which does not compile it.
'ui/src/ui_driver\.rs:\d+:\d+: replace macos::run',
# Painting pixels. A test can only see the grid, not the glyphs drawn from it.
'ui/src/terminal\.rs:\d+:\d+: replace paint_glyphs',
'ui/src/terminal\.rs:580:36: replace \+ with - in paint_glyphs',
'ui/src/terminal\.rs:580:64: replace \* with / in paint_glyphs',
# The busy colour of the activity dot is paint. No test reads an element's colour.
'ui/src/kagan/activity/summary\.rs:\d+:\d+: replace > with (<|==|>=) in Kagan::strip_summary',
# Loading the font files into the app. Its effect is pixels on screen.
'ui/src/theme/mod\.rs:\d+:\d+: replace load_fonts',
# The macOS-only website data store branch of `place`. Linux does not compile it.
'ui/src/components/webview/mod\.rs:228:12: delete ! in place',
'ui/src/components/webview/mod\.rs:231:43: replace < with (<=|==|>) in place',
# These need a live WebView, which needs a display, so CI's runner cannot run them.
'ui/src/web_page\.rs:\d+:\d+: replace open_windows',
'ui/src/web_page\.rs:\d+:\d+: replace restrain',
'ui/src/web_page\.rs:\d+:\d+: replace WebPage::eval',
]
16 changes: 16 additions & 0 deletions crates/core/src/diff/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,19 @@ fn the_cache_holds_a_bounded_number_of_scopes() {
}
assert!(cache.len() <= MAX_ENTRIES, "{} scopes kept", cache.len());
}

#[test]
fn a_cache_keeps_its_scopes_until_it_is_full() {
let cache = Cache::new();
for index in 0..3 {
cached(&cache, &format!("scope-{index}"), "left", "right", |_| ());
}
assert_eq!(cache.len(), 3);
for index in 3..MAX_ENTRIES {
cached(&cache, &format!("scope-{index}"), "left", "right", |_| ());
}
cached(&cache, "scope-0", "left", "right", |_| ());
assert_eq!(cache.len(), MAX_ENTRIES);
cached(&cache, "scope-new", "left", "right", |_| ());
assert_eq!(cache.len(), 1);
}
4 changes: 4 additions & 0 deletions crates/core/src/dispatch/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,7 @@ fn write_new(path: &Path, text: &str) -> std::result::Result<(), OpError> {
}
Ok(())
}

#[cfg(test)]
#[path = "diagnostics_test.rs"]
mod tests;
40 changes: 40 additions & 0 deletions crates/core/src/dispatch/diagnostics_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use std::path::Path;

use kg_domain::{LogCounts, Plugin, PluginId, PluginLog};

use super::{Facts, render};

fn plugin(id: &str) -> Plugin {
Plugin {
id: PluginId(id.into()),
source: "/plugins/x".into(),
approved: serde_json::json!({"powers": {}, "downloads": {}}),
root: Path::new("/plugins/x").into(),
commit: None,
enabled: true,
skills: Vec::new(),
error: None,
}
}

#[test]
fn each_plugin_shows_its_own_log_counts() {
let facts = Facts {
schema: 1,
threads: Vec::new(),
endings: Vec::new(),
screens: Vec::new(),
plugins: vec![plugin("a"), plugin("b")],
};
let logs = [PluginLog {
id: PluginId("b".into()),
counts: LogCounts::Counted { warn: 2, error: 1 },
}];
let text = render(&facts, Path::new("/data"), &logs);
let shown: Vec<&str> = text.lines().filter(|line| line.contains("log:")).collect();
assert_eq!(
shown,
[" log: not read, no plugin host", " log: 2 warn, 1 error"],
"{text}"
);
}
97 changes: 4 additions & 93 deletions crates/core/src/environment/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,16 @@ fn shown_text(raw: &str) -> (String, bool) {
if short.chars().count() < line.chars().count() {
truncated = true;
}
let gap = usize::from(!out.is_empty());
let gap = usize::from(index > 0);
if out.len() + gap + short.len() > SHOWN_CHARS {
truncated = true;
break;
}
if !out.is_empty() {
if index > 0 {
out.push('\n');
}
out.push_str(&short);
}
if !truncated && raw.lines().nth(out.lines().count()).is_some() {
truncated = true;
}
(out, truncated)
}
const TEARDOWN: &str = ".kagan/teardown";
Expand Down Expand Up @@ -426,91 +423,5 @@ impl Drop for StderrFile {
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn only_a_full_sha_is_a_commit_id() {
assert!(commit_id(&"a".repeat(40)));
assert!(commit_id(&"b".repeat(64)));
assert!(!commit_id(&"a".repeat(39)));
assert!(!commit_id(&"a".repeat(41)));
assert!(!commit_id(&"z".repeat(40)));
}

#[test]
fn a_setup_file_matches_only_the_same_blob_and_mode() {
let file = Object {
mode: "100644".into(),
blob: "one".into(),
};
assert!(same(
&file,
&Object {
mode: "100644".into(),
blob: "one".into()
}
));
assert!(!same(
&file,
&Object {
mode: "100644".into(),
blob: "two".into()
}
));
#[cfg(unix)]
assert!(!same(
&file,
&Object {
mode: "100755".into(),
blob: "one".into()
}
));
}

#[test]
fn the_timeout_message_names_the_ten_minute_limit_only_for_it() {
assert_eq!(
timeout_message(SETUP, SCRIPT_LIMIT),
".kagan/setup ran longer than 10 minutes."
);
assert_eq!(
timeout_message(TEARDOWN, Duration::from_secs(1)),
".kagan/teardown timed out."
);
}

#[test]
fn a_failed_setup_names_its_exit_code_and_stderr() {
let status = std::process::Command::new("sh")
.args(["-c", "exit 7"])
.status()
.unwrap();
assert_eq!(
script_error(SETUP, status, "").to_string(),
".kagan/setup failed (exit 7)."
);
let status = std::process::Command::new("sh")
.args(["-c", "echo why >&2; exit 7"])
.status()
.unwrap();
assert_eq!(
script_error(SETUP, status, "why").to_string(),
".kagan/setup failed (exit 7). why"
);
}

#[cfg(unix)]
#[test]
fn file_mode_keeps_the_executable_bit() {
use std::os::unix::fs::PermissionsExt as _;
let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("setup");
std::fs::write(&path, "").unwrap();
let meta = std::fs::metadata(&path).unwrap();
assert_eq!(file_mode(&meta), "100644");
std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o755)).unwrap();
let meta = std::fs::metadata(&path).unwrap();
assert_eq!(file_mode(&meta), "100755");
}
}
#[path = "script_test.rs"]
mod tests;
121 changes: 121 additions & 0 deletions crates/core/src/environment/script_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
use super::*;

#[test]
fn only_a_full_sha_is_a_commit_id() {
assert!(commit_id(&"a".repeat(40)));
assert!(commit_id(&"b".repeat(64)));
assert!(!commit_id(&"a".repeat(39)));
assert!(!commit_id(&"a".repeat(41)));
assert!(!commit_id(&"z".repeat(40)));
}

#[test]
fn a_setup_file_matches_only_the_same_blob_and_mode() {
let file = Object {
mode: "100644".into(),
blob: "one".into(),
};
assert!(same(
&file,
&Object {
mode: "100644".into(),
blob: "one".into()
}
));
assert!(!same(
&file,
&Object {
mode: "100644".into(),
blob: "two".into()
}
));
#[cfg(unix)]
assert!(!same(
&file,
&Object {
mode: "100755".into(),
blob: "one".into()
}
));
}

#[test]
fn the_timeout_message_names_the_ten_minute_limit_only_for_it() {
assert_eq!(
timeout_message(SETUP, SCRIPT_LIMIT),
".kagan/setup ran longer than 10 minutes."
);
assert_eq!(
timeout_message(TEARDOWN, Duration::from_secs(1)),
".kagan/teardown timed out."
);
}

#[test]
fn a_failed_setup_names_its_exit_code_and_stderr() {
let status = std::process::Command::new("sh")
.args(["-c", "exit 7"])
.status()
.unwrap();
assert_eq!(
script_error(SETUP, status, "").to_string(),
".kagan/setup failed (exit 7)."
);
let status = std::process::Command::new("sh")
.args(["-c", "echo why >&2; exit 7"])
.status()
.unwrap();
assert_eq!(
script_error(SETUP, status, "why").to_string(),
".kagan/setup failed (exit 7). why"
);
}

#[test]
fn a_long_line_is_cut_and_marked() {
let (shown, truncated) = shown_text(&"x".repeat(201));
assert_eq!(shown, "x".repeat(200));
assert!(truncated);
}

#[test]
fn shown_text_stops_at_its_character_cap() {
let lines: Vec<String> = [199, 199, 199, 199, 199, 199, 199, 199, 200, 200]
.iter()
.map(|n| "y".repeat(*n))
.collect();
let (shown, truncated) = shown_text(&lines.join("\n"));
assert!(truncated);
assert_eq!(shown.lines().count(), 9);
let fits: Vec<String> = [199, 199, 199, 199, 199, 199, 199, 199, 199, 200]
.iter()
.map(|n| "y".repeat(*n))
.collect();
let (shown, truncated) = shown_text(&fits.join("\n"));
assert!(!truncated);
assert_eq!(shown.lines().count(), 10);
}

#[test]
fn a_blank_first_line_keeps_its_newline() {
assert_eq!(shown_text("\na"), ("\na".to_owned(), false));
}

#[test]
fn a_blank_last_line_is_not_a_cut() {
assert_eq!(shown_text("a\n\n"), ("a\n".to_owned(), false));
}

#[cfg(unix)]
#[test]
fn file_mode_keeps_the_executable_bit() {
use std::os::unix::fs::PermissionsExt as _;
let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("setup");
std::fs::write(&path, "").unwrap();
let meta = std::fs::metadata(&path).unwrap();
assert_eq!(file_mode(&meta), "100644");
std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o755)).unwrap();
let meta = std::fs::metadata(&path).unwrap();
assert_eq!(file_mode(&meta), "100755");
}
4 changes: 4 additions & 0 deletions crates/core/src/host/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,7 @@ impl Workspace {
.or_else(|| user_home().map(|home| home.join(folder)))
}
}

#[cfg(all(test, unix))]
#[path = "program_test.rs"]
mod tests;
27 changes: 27 additions & 0 deletions crates/core/src/host/program_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use std::ffi::OsString;
use std::path::PathBuf;

use super::{ProgramEnvironment, read_environment, user_home};

#[test]
fn a_program_environment_names_its_path_and_shell() {
let environment = ProgramEnvironment {
path: "/work/bin".into(),
shell: "/bin/zsh".into(),
};
assert_eq!(
read_environment(Some(environment)),
(
Some(OsString::from("/work/bin")),
None,
Some(OsString::from("/bin/zsh"))
)
);
}

#[test]
fn the_home_folder_is_the_home_variable() {
// SAFETY: nextest runs each test in its own process, so no other thread reads HOME here.
unsafe { std::env::set_var("HOME", "/kg/test/home") };
assert_eq!(user_home(), Some(PathBuf::from("/kg/test/home")));
}
Loading
Loading
0