mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-17 14:21:22 +01:00
test(config): rule matching tests for the Windows input shape
Adds four tests to crates/komorebi-config/tests/rule_matching.rs next to the KDE/macOS ones moved there: a Windows exe rule names the program with its extension (mirrors rules_exe, where platform.exe_id adds `.exe` on Windows) and the id without it does not match; a regex id is looked up as written on Windows and with `.exe` removed elsewhere; the whole grid of kinds x strategies x ids agrees between RuleQuirks::WINDOWS and UNIX for a window with one class (mirrors rules_class); a negated class rule for a window of another class and for one with no class. Each names the e2e check it mirrors. docs/dev/e2e-to-unit.md points at the shared file. Verified: cargo test -p komorebi-config --test rule_matching (16 passed); bare cargo clippy --locked --all-targets -D warnings clean.
This commit is contained in:
1 parent
008b5145fa
commit
a1e59871c1
2 files changed
+173
-1
No files matched your search
@@ -479,3 +479,175 @@ fn a_rule_by_title_follows_the_title_it_is_asked_about() {
|
||||
assert!(ask("a secret window").is_some());
|
||||
assert!(ask("a renamed window").is_none());
|
||||
}
|
||||
|
||||
// The Windows input shape: one class, and an executable that carries its `.exe`
|
||||
// (`RuleQuirks::WINDOWS`: a rule id is compared as written).
|
||||
|
||||
const WIN_EXE: &str = "e2e-exe-sent.exe";
|
||||
|
||||
fn windows_matches(rule: &IdWithIdentifier, regex: &HashMap<String, Regex>) -> bool {
|
||||
komorebi_config::rules::should_act_individual(
|
||||
&RuleSubject {
|
||||
title: TITLE,
|
||||
exe_name: WIN_EXE,
|
||||
classes: &[CLASS],
|
||||
path: PATH,
|
||||
},
|
||||
RuleQuirks::WINDOWS,
|
||||
rule,
|
||||
regex,
|
||||
)
|
||||
}
|
||||
|
||||
// mirrors: rules_exe / a window an exe rule matches goes to the workspace the rule names
|
||||
// mirrors: rules_exe / a window of another program stays on the first workspace
|
||||
// (on Windows the rule id is `platform.exe_id(program)`, which is `e2e-exe-sent.exe`)
|
||||
#[test]
|
||||
fn on_windows_an_exe_rule_names_the_program_with_its_extension() {
|
||||
for strategy in [None, Some(MatchingStrategy::Equals)] {
|
||||
assert!(windows_matches(
|
||||
&id(ApplicationIdentifier::Exe, WIN_EXE, strategy.clone()),
|
||||
&no_regex()
|
||||
));
|
||||
// not stripped: the id without the extension is another program
|
||||
assert!(!windows_matches(
|
||||
&id(ApplicationIdentifier::Exe, "e2e-exe-sent", strategy.clone()),
|
||||
&no_regex()
|
||||
));
|
||||
assert!(!windows_matches(
|
||||
&id(ApplicationIdentifier::Exe, "e2e-exe-other.exe", strategy),
|
||||
&no_regex()
|
||||
));
|
||||
}
|
||||
// the same ids on the KDE/macOS shape: the suffix of the id is ignored, so both name the
|
||||
// program `e2e-exe-sent`
|
||||
for written in ["e2e-exe-sent", "e2e-exe-sent.exe"] {
|
||||
assert!(should_act_individual(
|
||||
TITLE,
|
||||
"e2e-exe-sent",
|
||||
&[CLASS],
|
||||
PATH,
|
||||
&id(
|
||||
ApplicationIdentifier::Exe,
|
||||
written,
|
||||
Some(MatchingStrategy::Equals)
|
||||
),
|
||||
&no_regex()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_regex_id_is_looked_up_as_written_on_windows_and_without_exe_elsewhere() {
|
||||
let written = "^e2e-exe-.*\\.exe$";
|
||||
let rule = id(
|
||||
ApplicationIdentifier::Exe,
|
||||
written,
|
||||
Some(MatchingStrategy::Regex),
|
||||
);
|
||||
let mut compiled = HashMap::new();
|
||||
compiled.insert(written.to_string(), Regex::new(written).unwrap());
|
||||
assert!(windows_matches(&rule, &compiled));
|
||||
// KDE/macOS look the cache up with `.exe` removed from the id (`^e2e-exe-.*\$`), which is
|
||||
// not a key there: no match, whatever the executable is
|
||||
assert!(!should_act_individual(
|
||||
TITLE,
|
||||
WIN_EXE,
|
||||
&[CLASS],
|
||||
PATH,
|
||||
&rule,
|
||||
&compiled
|
||||
));
|
||||
}
|
||||
|
||||
// mirrors: rules_class / a window a class rule matches goes to the workspace the rule names
|
||||
// mirrors: rules_class / a window of another class stays on the first workspace
|
||||
#[test]
|
||||
fn a_window_with_one_class_is_decided_the_same_way_on_every_platform() {
|
||||
// With ids that hold no `.exe` the two input shapes are the same function: the whole grid of
|
||||
// kinds and strategies agrees, for ids that match and ids that do not.
|
||||
let no_regex = no_regex();
|
||||
for kind in kinds() {
|
||||
let text = text_of(kind);
|
||||
let probes = [
|
||||
text.to_string(),
|
||||
text[..4].to_string(),
|
||||
text[text.len() - 4..].to_string(),
|
||||
"zzzz-not-there".to_string(),
|
||||
];
|
||||
for strategy in [
|
||||
None,
|
||||
Some(MatchingStrategy::Legacy),
|
||||
Some(MatchingStrategy::Equals),
|
||||
Some(MatchingStrategy::DoesNotEqual),
|
||||
Some(MatchingStrategy::StartsWith),
|
||||
Some(MatchingStrategy::DoesNotStartWith),
|
||||
Some(MatchingStrategy::EndsWith),
|
||||
Some(MatchingStrategy::DoesNotEndWith),
|
||||
Some(MatchingStrategy::Contains),
|
||||
Some(MatchingStrategy::DoesNotContain),
|
||||
] {
|
||||
for probe in &probes {
|
||||
let rule = id(kind, probe, strategy.clone());
|
||||
let subject = RuleSubject {
|
||||
title: TITLE,
|
||||
exe_name: EXE,
|
||||
classes: &[CLASS],
|
||||
path: PATH,
|
||||
};
|
||||
assert_eq!(
|
||||
komorebi_config::rules::should_act_individual(
|
||||
&subject,
|
||||
RuleQuirks::WINDOWS,
|
||||
&rule,
|
||||
&no_regex
|
||||
),
|
||||
komorebi_config::rules::should_act_individual(
|
||||
&subject,
|
||||
RuleQuirks::UNIX,
|
||||
&rule,
|
||||
&no_regex
|
||||
),
|
||||
"{kind:?} {strategy:?} {probe:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// mirrors: rules_class / a window of another class stays on the first workspace
|
||||
#[test]
|
||||
fn a_negated_class_rule_holds_for_a_window_of_another_class_and_for_none_without_a_class() {
|
||||
let rule = id(
|
||||
ApplicationIdentifier::Class,
|
||||
CLASS,
|
||||
Some(MatchingStrategy::DoesNotEqual),
|
||||
);
|
||||
// one class that is not the id: holds
|
||||
assert!(should_act_individual(
|
||||
TITLE,
|
||||
EXE,
|
||||
&["another"],
|
||||
PATH,
|
||||
&rule,
|
||||
&no_regex()
|
||||
));
|
||||
// the class the id names: does not
|
||||
assert!(!should_act_individual(
|
||||
TITLE,
|
||||
EXE,
|
||||
&[CLASS],
|
||||
PATH,
|
||||
&rule,
|
||||
&no_regex()
|
||||
));
|
||||
// a window with no class has none to hold for (KDE/macOS only; Windows always has one)
|
||||
assert!(!should_act_individual(
|
||||
TITLE,
|
||||
EXE,
|
||||
&[],
|
||||
PATH,
|
||||
&rule,
|
||||
&no_regex()
|
||||
));
|
||||
}
|
||||
@@ -45,7 +45,7 @@ times (Windows `komorebi/src/window.rs:1178`, KDE `window.rs:661`, macOS `window
|
||||
| workspaces (8), workspace_moves (8) | send/move/focus workspace, last-workspace | A: `monitor_workspaces.rs` (focus, last focused, ensure, remove); the OS hide/show is C | - | - | med |
|
||||
| commands (265, 7.6 min) | every komorebic command leaves the daemon alive, answers state, manages every window | A now for command line (`crates/komorebic-core/tests/e2e_sweep.rs`: every SWEEP/PRINTED line is a Windows command; macOS lacks exactly 8) and for the KDE model (`komorebi-for-kde/komorebi/tests/command_sweep.rs`, about 185 messages, 0.2 s); B: same sweep for the Windows and macOS daemons (needs seam, below); C: stall-family (daemon busy 8 s), socket answering | S done / L for Win+mac | highest: biggest, flakiest scenario |
|
||||
| unknown_monitor (12) | a window sent to a monitor that does not exist stays managed | B: shared `Monitor`/`Workspace::add_container` errors are covered (`monitor_workspaces.rs` `adding_a_container_to_a_workspace_that_is_not_there_is_an_error`); the daemon handler is per platform: needs seam | M | med (known flaky marker) |
|
||||
| rules (12), rules_class (5), rules_exe (5), manage_rules (4), title_rule (5), startup_rules (5) | which window a rule catches (kind, strategy, composite, last wins, manage over ignore); the workspace it goes to | A now for matching, KDE copy only: `komorebi-for-kde/komorebi/tests/rule_matching.rs` (13 tests). Windows and macOS copies of `should_act_individual` untested natively (windows crate does not build on Linux; macOS needs the Mini). Workspace of a rule: A in core: `workspace_containers.rs` `initial_placement_rules_choose_where_a_new_window_goes`. When-evaluated (open vs rename), hide/show: C | M to move the function into `komorebi-config` and test once for three daemons (recommended seam) | high |
|
||||
| rules (12), rules_class (5), rules_exe (5), manage_rules (4), title_rule (5), startup_rules (5) | which window a rule catches (kind, strategy, composite, last wins, manage over ignore); the workspace it goes to | A now for matching, once for all three daemons: `crates/komorebi-config/tests/rule_matching.rs` (16 tests, KDE/macOS and Windows input shapes; the matching moved to `komorebi_config::rules`, see `docs/dev/rule-matching.md`); KDE keeps the manage-rule rescue test. Workspace of a rule: A in core: `workspace_containers.rs` `initial_placement_rules_choose_where_a_new_window_goes`. When-evaluated (open vs rename), hide/show: C | M to move the function into `komorebi-config` and test once for three daemons (recommended seam) | high |
|
||||
| state_fidelity (5) | state names title/exe/class/path as opened | A: `state_roundtrip.rs` (kfw/kfde fixtures, `the_fixtures_are_the_ones_the_e2e_library_has`, `a_windows_tiled_state_is_written_as_it_was_read`); what the OS reports C | - | - | low |
|
||||
| queries (3) | `komorebic query X` answers from the state, resize save/load round trip | B: state answers per query are `StateQuery` handling in the daemon; resize round trip needs `process_command` (KDE: `resize.rs` `sizes_saved_to_a_file_are_loaded_back_from_it` A) | M | low |
|
||||
| config_reload (8) | file change reloads names, layout, rules | A for the merge/reset semantics: `crates/komorebi-settings/tests/reload.rs` (`a_reload_merges_what_the_file_gives_and_resets_what_it_resets`), `src/handle.rs`; C: the file watch and the reload message dropped while the lock is held (the NEW failing check in gate5 is that mechanism) | - | - | med |
|
||||
|
||||
Reference in new issue
Block a user