mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
Windows and Linux asked "Open Hex when your Mac starts?" and had Hex napping "in your menu bar". The ask's copy now follows `Home`: macOS keeps its Mac and menu bar, Windows says computer and system tray, Linux says computer and in the background. The new strings are translated in every language, and a headless test checks all three platforms.
543 lines
20 KiB
Rust
543 lines
20 KiB
Rust
//! The onboarding check (`scripts/check-onboarding.sh`, run before every
|
||
//! stable release): every onboarding scene against its approved golden in
|
||
//! both appearances, and a first run walked through the real onboarding in
|
||
//! a clean data folder. Like every golden, these render on Linux only: the
|
||
//! macOS and Windows scenes are the same window drawn from fixtures.
|
||
|
||
use super::super::onboarding_kit::live::Page;
|
||
use super::*;
|
||
use crate::desktop::onboarding::Step;
|
||
|
||
/// Every onboarding state a person can see, on macOS and on Linux and
|
||
/// Windows. An intentional change refreshes these goldens in the same PR
|
||
/// (`HEX_UPDATE_GOLDENS=1`).
|
||
pub(super) const SCENES: &[&str] = &[
|
||
// A fresh install: setting up Hex, the recommended model downloading.
|
||
"onboarding",
|
||
"mac-onboarding",
|
||
// The download stopped; Continue without a model, then Settings.
|
||
"onboarding-download-failed",
|
||
"onboarding-no-model",
|
||
// The model step: models on this computer; the recommended one among
|
||
// them; ours picked and downloading; Back to the list from the next page.
|
||
"onboarding-model-found",
|
||
"onboarding-model-found-recommended",
|
||
"onboarding-model-found-downloading",
|
||
"onboarding-model-found-back",
|
||
// The demo while the model downloads.
|
||
"onboarding-demo",
|
||
// Permissions (macOS): to do, refused, stale entry, waiting for a
|
||
// restart; Windows' microphone privacy switch.
|
||
"mac-onboarding-permissions",
|
||
"mac-onboarding-denied",
|
||
"mac-onboarding-stale",
|
||
"mac-onboarding-restart",
|
||
"windows-onboarding-microphone",
|
||
// GNOME and KDE on Wayland: the desktop's paste permission, explained.
|
||
"onboarding-paste",
|
||
// Almost ready: the model still downloads, and a sketch from "Watch
|
||
// another one" while it does.
|
||
"onboarding-waiting",
|
||
"onboarding-sketch",
|
||
// Your turn: the practice game, and the shortcut that didn't start.
|
||
"onboarding-try",
|
||
"mac-onboarding-try",
|
||
"mac-onboarding-reopen",
|
||
// Hex is ready.
|
||
"onboarding-ready",
|
||
"mac-onboarding-ready",
|
||
];
|
||
|
||
/// The optional pages: the demo and the practice.
|
||
const OPTIONAL: &[&str] = &[
|
||
"onboarding-model-found-back",
|
||
"onboarding-demo",
|
||
"onboarding-try",
|
||
"mac-onboarding-try",
|
||
"mac-onboarding-reopen",
|
||
];
|
||
|
||
/// Skip shows only on the optional pages, the demo and the practice, and
|
||
/// passes over them to the next step setup still needs: permissions, then
|
||
/// the model, else Hex is ready. It never closes onboarding.
|
||
#[test]
|
||
fn onboarding_skip() {
|
||
for scene in SCENES {
|
||
let rt = runtime(scene, true, PANE_SIZE);
|
||
assert_eq!(
|
||
rt.find("skip").is_some(),
|
||
OPTIONAL.contains(scene),
|
||
"{scene}: Skip"
|
||
);
|
||
}
|
||
let page = |rt: &Runtime<Ui>| super::super::onboarding_kit::live::page(&rt.state);
|
||
let skip = |rt: &mut Runtime<Ui>, scene: &str, next: Page| {
|
||
tap(rt, "skip");
|
||
settle(rt);
|
||
assert_eq!(page(rt), Some(next), "{scene}: Skip lands here");
|
||
assert!(rt.state.tour.is_some(), "{scene}: onboarding stays open");
|
||
assert_eq!(
|
||
rt.find("skip").is_some(),
|
||
next == Page::Try,
|
||
"{scene}: no Skip on {next:?}"
|
||
);
|
||
};
|
||
|
||
// macOS, permissions still to grant: the demo skips to them.
|
||
let mut rt = runtime("mac-onboarding", true, PANE_SIZE);
|
||
rt.update(|ui, _| super::super::onboarding_kit::live::fixture_resume(ui, Page::Demo));
|
||
settle(&mut rt);
|
||
assert_eq!(page(&rt), Some(Page::Demo));
|
||
skip(&mut rt, "mac demo", Page::Permissions);
|
||
|
||
// Nothing to grant, the model still downloading: on to Almost ready.
|
||
let mut rt = runtime("onboarding-demo", true, PANE_SIZE);
|
||
skip(&mut rt, "onboarding-demo", Page::Waiting);
|
||
|
||
// Nothing left to set up: the demo and the practice skip to Hex is ready.
|
||
let mut rt = runtime("onboarding-demo", true, PANE_SIZE);
|
||
rt.update(|ui, tx| {
|
||
ui.picker.installed = Some(vec![ui.settings.transcription.model]);
|
||
if let Some(view) = &mut ui.view {
|
||
view.transcription.preparing = None;
|
||
}
|
||
super::super::onboarding_kit::live::poll(ui, tx);
|
||
});
|
||
skip(&mut rt, "onboarding-demo, model ready", Page::Ready);
|
||
for scene in ["onboarding-try", "mac-onboarding-try"] {
|
||
let mut rt = runtime(scene, true, PANE_SIZE);
|
||
skip(&mut rt, scene, Page::Ready);
|
||
}
|
||
}
|
||
|
||
/// Continue without a model (#894): only on the download step, only once
|
||
/// the download failed or stalled. It finishes onboarding, and Settings ›
|
||
/// General then says no model is installed, with Download and Add model
|
||
/// file….
|
||
#[test]
|
||
fn onboarding_continue_without_model() {
|
||
for scene in SCENES {
|
||
let rt = runtime(scene, true, PANE_SIZE);
|
||
assert_eq!(
|
||
rt.find("continue-without-model").is_some(),
|
||
*scene == "onboarding-download-failed",
|
||
"{scene}: Continue without a model"
|
||
);
|
||
}
|
||
|
||
let mut rt = runtime("onboarding-download-failed", true, PANE_SIZE);
|
||
tap(&mut rt, "continue-without-model");
|
||
settle(&mut rt);
|
||
assert!(rt.state.first_run.is_none(), "onboarding closed");
|
||
assert!(rt.state.tour.is_none(), "and its tour");
|
||
assert!(
|
||
texts(&rt).contains(&"No speech model installed: The connection was reset.".to_owned()),
|
||
"{:?}",
|
||
texts(&rt)
|
||
);
|
||
assert!(rt.find("transcription-download").is_some(), "Download");
|
||
assert!(
|
||
rt.find("transcription-add-file").is_some(),
|
||
"Add model file…"
|
||
);
|
||
assert!(
|
||
texts(&rt).contains(&"Hex can't dictate until a speech model is installed".to_owned()),
|
||
"the status says so too"
|
||
);
|
||
|
||
// A download that gains nothing for a while offers it too.
|
||
let mut rt = runtime("onboarding-waiting", true, PANE_SIZE);
|
||
assert!(rt.find("continue-without-model").is_none());
|
||
rt.update(|ui, tx| {
|
||
if let Some(s) = ui.first_run.as_mut() {
|
||
s.now += 31.0;
|
||
}
|
||
super::super::onboarding_kit::live::poll(ui, tx);
|
||
});
|
||
settle(&mut rt);
|
||
assert!(rt.find("continue-without-model").is_some(), "stalled");
|
||
tap(&mut rt, "continue-without-model");
|
||
assert!(rt.state.first_run.is_none(), "onboarding closed");
|
||
}
|
||
|
||
/// The mic note follows the shortcut: Hold says hold, Toggle says tap,
|
||
/// and a mic released while idle has nothing to explain.
|
||
#[test]
|
||
fn the_mic_note_follows_the_shortcut() {
|
||
let note = |toggle: bool, release: bool| {
|
||
let mut ui = Ui::with(AppSettings::default(), Service::Fixture(Vec::new()));
|
||
super::super::onboarding_kit::scenes::mac_first_run(
|
||
&mut ui,
|
||
crate::rune_ui::onboarding::MacStep::TryIt,
|
||
Page::Try,
|
||
);
|
||
// Each poll reads both from settings again.
|
||
if toggle {
|
||
ui.settings.shortcut_mode = crate::dictation::ShortcutMode::Toggle;
|
||
}
|
||
ui.settings.release_microphone_while_idle = release;
|
||
let s = ui.first_run.as_mut().expect("the first run is open");
|
||
s.toggle = toggle;
|
||
if let Some(live) = s.live.as_mut() {
|
||
live.release_microphone = release;
|
||
}
|
||
texts(&runtime_for(ui, true, PANE_SIZE))
|
||
.into_iter()
|
||
.find(|t| t.starts_with("It only records"))
|
||
};
|
||
let hold = note(false, false).expect("the note shows");
|
||
assert!(
|
||
hold.starts_with("It only records while you hold "),
|
||
"{hold}"
|
||
);
|
||
let tap = note(true, false).expect("the note shows");
|
||
assert!(tap.starts_with("It only records after you tap "), "{tap}");
|
||
assert_eq!(note(false, true), None, "no note once the mic is released");
|
||
}
|
||
|
||
/// The language capsule on the download page: English systems have no
|
||
/// other language, and a later setup replaces the earlier setup's label.
|
||
/// A test's own preferred language keeps both cases independent of the
|
||
/// host locale.
|
||
#[test]
|
||
fn the_language_capsule_switches_only_between_different_languages() {
|
||
let setup = |model: TranscriptionModelId, language: &str| {
|
||
let mut ui = portal_fixture();
|
||
ui.settings.transcription = TranscriptionSelection {
|
||
model,
|
||
language: language.into(),
|
||
};
|
||
ui.preferred_language = Some("en".into());
|
||
super::super::onboarding::fixture(&mut ui, Step::Setup, true);
|
||
super::super::onboarding_kit::live::fixture(&mut ui, Page::Download);
|
||
runtime_for(ui, false, PANE_SIZE)
|
||
};
|
||
|
||
// An English system has no other language to offer.
|
||
let mut rt = setup(TranscriptionModelId::ParakeetUnifiedEnglish, "en");
|
||
let before = sent(&rt).len();
|
||
tap(&mut rt, "language-capsule");
|
||
assert_eq!(sent(&rt).len(), before, "nothing downloads");
|
||
|
||
// Neither has another English model, such as a Cohere English pick.
|
||
let mut rt = setup(TranscriptionModelId::CohereTranscribe, "en");
|
||
let before = sent(&rt).len();
|
||
tap(&mut rt, "language-capsule");
|
||
assert_eq!(sent(&rt).len(), before, "English to English is no switch");
|
||
|
||
// A French setup switches to the recommended English model and back.
|
||
let mut rt = setup(TranscriptionModelId::ParakeetV3, "fr");
|
||
assert!(
|
||
matches!(
|
||
sent(&rt),
|
||
[Request::ChooseModel { model: TranscriptionModelId::ParakeetV3, language }] if language == "fr"
|
||
),
|
||
"{:?}",
|
||
sent(&rt)
|
||
);
|
||
tap(&mut rt, "language-capsule");
|
||
assert!(matches!(
|
||
sent(&rt),
|
||
[
|
||
Request::ChooseModel { model: TranscriptionModelId::ParakeetV3, language: started },
|
||
Request::ChooseModel { model: TranscriptionModelId::ParakeetUnifiedEnglish, language },
|
||
] if started == "fr" && language == "en"
|
||
));
|
||
tap(&mut rt, "language-capsule");
|
||
assert!(
|
||
matches!(
|
||
sent(&rt).last(),
|
||
Some(Request::ChooseModel { model: TranscriptionModelId::ParakeetV3, language }) if language == "fr"
|
||
),
|
||
"the toggle swaps back to the saved selection"
|
||
);
|
||
|
||
// Running setup again for Japanese replaces the earlier French label.
|
||
let rt = setup(
|
||
crate::transcription::models::recommended_selection("ja").model,
|
||
"ja",
|
||
);
|
||
let shown = texts(&rt);
|
||
assert!(shown.contains(&"Japanese".to_owned()), "{shown:?}");
|
||
assert!(
|
||
!shown.contains(&"French".to_owned()),
|
||
"the previous setup's label is gone: {shown:?}"
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn onboarding_goldens() {
|
||
let _goldens = Goldens::collect();
|
||
for scene in SCENES {
|
||
for dark in [true, false] {
|
||
check_golden(scene, dark, PANE_SIZE);
|
||
}
|
||
}
|
||
}
|
||
|
||
/// A first run on Linux or Windows, in the clean data folder
|
||
/// `HEX_APPLICATION_SUPPORT_DIR` names (no settings, no models, an empty
|
||
/// Hugging Face cache): the real settings load, the real decision to open
|
||
/// onboarding, the real download and verification of the model it picks,
|
||
/// and every page to Hex is ready. Downloads the recommended model, so only
|
||
/// scripts/check-onboarding.sh runs it. The window here is a fixture, not
|
||
/// connected to a service: the test does the service's download itself,
|
||
/// plays the story on its own clock, and nothing writes the completion
|
||
/// marker.
|
||
#[test]
|
||
#[ignore = "downloads a speech model; run by scripts/check-onboarding.sh"]
|
||
fn onboarding_walkthrough() {
|
||
let support = crate::app_paths::support_dir().unwrap();
|
||
assert!(
|
||
std::env::var_os("HEX_APPLICATION_SUPPORT_DIR").is_some(),
|
||
"set HEX_APPLICATION_SUPPORT_DIR to a clean folder"
|
||
);
|
||
assert!(
|
||
std::fs::read_dir(&support).map_or(true, |mut entries| entries.next().is_none()),
|
||
"{} must start empty",
|
||
support.display()
|
||
);
|
||
assert!(
|
||
crate::transcription::found_models::scan().is_empty(),
|
||
"the Hugging Face cache must be empty"
|
||
);
|
||
|
||
// A new install: default settings from an empty folder, nothing installed.
|
||
let settings = AppSettings::load().unwrap();
|
||
let mut ui = portal_fixture();
|
||
ui.platform.caps = platform::Capabilities::LINUX;
|
||
ui.settings = settings;
|
||
let installed = |ui: &Ui| {
|
||
let selection = &ui.settings.transcription;
|
||
crate::transcription::models::is_installed(
|
||
crate::transcription::models::definition(selection.model),
|
||
&selection.language,
|
||
)
|
||
};
|
||
assert!(!installed(&ui), "no model is installed yet");
|
||
ui.picker.installed = Some(Vec::new());
|
||
// As the window opens at launch.
|
||
ui.tour = Some(
|
||
super::super::onboarding::Tour::start(&ui.settings, &ui.platform)
|
||
.expect("a new install opens onboarding"),
|
||
);
|
||
super::super::onboarding_kit::live::open(&mut ui);
|
||
assert!(ui.first_run.is_some(), "the first run shows");
|
||
let mut rt = runtime_for(ui, true, PANE_SIZE);
|
||
let step = |rt: &Runtime<Ui>| rt.state.tour.as_ref().map(|tour| tour.flow.step());
|
||
let shown = texts(&rt);
|
||
assert!(shown.contains(&"Setting up Hex".to_owned()), "{shown:?}");
|
||
assert!(
|
||
!shown.contains(&"Choose a speech model".to_owned()),
|
||
"nothing found, so no model step"
|
||
);
|
||
|
||
// Setting up Hex asks the service for the recommended model at once.
|
||
assert_eq!(step(&rt), Some(Step::Setup));
|
||
let (model, language) = match sent(&rt) {
|
||
[Request::ChooseModel { model, language }] => (*model, language.clone()),
|
||
other => panic!("setup should choose a model, sent {other:?}"),
|
||
};
|
||
assert_eq!(model, rt.state.settings.transcription.model);
|
||
|
||
// The service's work, for real: download and verify into the clean folder.
|
||
let definition = crate::transcription::models::definition(model);
|
||
let downloaded = std::sync::atomic::AtomicU64::new(0);
|
||
let path = crate::transcription::models::download_with_progress(
|
||
definition,
|
||
&std::sync::atomic::AtomicBool::new(false),
|
||
&downloaded,
|
||
)
|
||
.unwrap_or_else(|error| panic!("downloading {} failed: {error:#}", definition.name));
|
||
assert!(
|
||
path.starts_with(&support),
|
||
"{} is outside the data folder",
|
||
path.display()
|
||
);
|
||
rt.state.settings.transcription = TranscriptionSelection { model, language };
|
||
assert!(installed(&rt.state), "{} is installed", definition.name);
|
||
assert!(
|
||
crate::transcription::models::is_verified(definition),
|
||
"{} is verified against its pin",
|
||
definition.name
|
||
);
|
||
rt.state.picker.installed = Some(vec![model]);
|
||
|
||
// The story plays on: the demo, then the practice game ("With Hex")
|
||
// once the model is ready, then Hex is ready.
|
||
settle(&mut rt);
|
||
rt.update(|ui, _| super::super::onboarding_kit::live::fixture_resume(ui, Page::Try));
|
||
settle(&mut rt);
|
||
assert_eq!(step(&rt), Some(Step::TryIt));
|
||
assert!(texts(&rt).contains(&"With Hex".to_owned()));
|
||
assert!(rt.find("skip").is_some(), "Skip shows on the practice too");
|
||
tap(&mut rt, "done");
|
||
assert!(texts(&rt).contains(&"Hex is ready".to_owned()));
|
||
tap(&mut rt, "start-using-hex");
|
||
assert!(rt.state.tour.is_none(), "Start using Hex closes onboarding");
|
||
assert!(rt.state.first_run.is_none());
|
||
println!(
|
||
"onboarding walkthrough: Setting up Hex -> {} downloaded ({} bytes) -> Your turn -> Hex is ready",
|
||
definition.name,
|
||
downloaded.load(std::sync::atomic::Ordering::Relaxed)
|
||
);
|
||
}
|
||
|
||
/// The practice and Hex is ready speak the interface language, the
|
||
/// shortcut's keycaps sitting where the translation puts `{keys}`.
|
||
#[test]
|
||
fn the_practice_and_ready_pages_are_translated() {
|
||
let shown = |scene: &str| {
|
||
let mut rt = runtime(scene, true, PANE_SIZE);
|
||
crate::desktop::i18n::apply(Some("zh"));
|
||
settle(&mut rt);
|
||
texts(&rt)
|
||
};
|
||
let english = [
|
||
"Hold",
|
||
"Tap",
|
||
"Not recording",
|
||
"and answer the one that's lit.",
|
||
"anywhere, then talk.",
|
||
"to answer",
|
||
"Keyboard mode",
|
||
"Hex is ready",
|
||
];
|
||
for (scene, expected) in [
|
||
(
|
||
"mac-onboarding-try",
|
||
&["按住", ",回复亮起的那条。", "未在录音", "回复"][..],
|
||
),
|
||
(
|
||
"mac-onboarding-ready",
|
||
&["在任何地方按住", ",然后开口说。"][..],
|
||
),
|
||
] {
|
||
let shown = shown(scene);
|
||
for text in expected {
|
||
assert!(
|
||
shown.iter().any(|t| t == text),
|
||
"{scene}: {text}: {shown:?}"
|
||
);
|
||
}
|
||
for text in english {
|
||
assert!(
|
||
!shown.iter().any(|t| t == text),
|
||
"{scene}: {text}: {shown:?}"
|
||
);
|
||
}
|
||
}
|
||
}
|
||
|
||
/// A shortcut that didn't start leaves only the way out: no hold prompt or
|
||
/// idle pill inviting a press that does nothing, and one Reopen Hex.
|
||
#[test]
|
||
fn a_shortcut_that_did_not_start_shows_only_reopen() {
|
||
let rt = runtime("mac-onboarding-reopen", true, PANE_SIZE);
|
||
let shown = texts(&rt);
|
||
assert!(
|
||
!shown
|
||
.iter()
|
||
.any(|t| t == "and answer the one that's lit." || t == "and say anything."),
|
||
"{shown:?}"
|
||
);
|
||
assert!(rt.find("idle-pill").is_none(), "no idle pill");
|
||
assert_eq!(
|
||
rt.elements()
|
||
.iter()
|
||
.filter(|e| !e.exiting && e.path.ends_with("/reopen-hex"))
|
||
.count(),
|
||
1,
|
||
"one Reopen Hex"
|
||
);
|
||
assert!(
|
||
shown.iter().any(|t| t == "Hex's shortcut didn't start."),
|
||
"{shown:?}"
|
||
);
|
||
}
|
||
|
||
/// A ready page on `caps` with its login item as `login`, so the ask shows,
|
||
/// and a shortcut that `tap`s to start or holds.
|
||
fn ready_with_login(
|
||
caps: platform::Capabilities,
|
||
login: crate::desktop::login_item::LoginItemStatus,
|
||
tap: bool,
|
||
) -> Ui {
|
||
let mut ui = portal_fixture();
|
||
ui.platform.caps = caps;
|
||
ui.platform.login_item = Some(login);
|
||
ui.settings.shortcut_mode = if tap {
|
||
crate::dictation::ShortcutMode::Toggle
|
||
} else {
|
||
crate::dictation::ShortcutMode::Hold
|
||
};
|
||
super::super::onboarding::fixture(&mut ui, Step::Setup, true);
|
||
ui.picker.installed = Some(vec![ui.settings.transcription.model]);
|
||
if let Some(view) = &mut ui.view {
|
||
view.transcription.preparing = None;
|
||
}
|
||
super::super::onboarding::poll(&mut ui);
|
||
super::super::onboarding_kit::live::fixture(&mut ui, Page::Ready);
|
||
ui
|
||
}
|
||
|
||
/// The launch-at-login ask in the platform's own words: a Mac and its menu
|
||
/// bar, a Windows computer and its system tray, a Linux computer in the
|
||
/// background.
|
||
#[test]
|
||
fn the_login_ask_speaks_each_platforms_wording() {
|
||
use crate::desktop::login_item::LoginItemStatus;
|
||
|
||
let mac = texts(&runtime("mac-onboarding-ready", true, PANE_SIZE));
|
||
assert!(
|
||
mac.contains(&"Open Hex when your Mac starts?".to_owned()),
|
||
"{mac:?}"
|
||
);
|
||
assert!(
|
||
mac.contains(&"It's tiny. It naps in your menu bar until you hold the key.".to_owned()),
|
||
"{mac:?}"
|
||
);
|
||
|
||
for (caps, place) in [
|
||
(platform::Capabilities::WINDOWS, "your system tray"),
|
||
(platform::Capabilities::LINUX, "the background"),
|
||
] {
|
||
for (tap, start) in [(false, "hold"), (true, "tap")] {
|
||
let off = texts(&runtime_for(
|
||
ready_with_login(caps, LoginItemStatus::Disabled, tap),
|
||
true,
|
||
PANE_SIZE,
|
||
));
|
||
assert!(
|
||
off.contains(&"Open Hex when your computer starts?".to_owned()),
|
||
"{caps:?}: {off:?}"
|
||
);
|
||
assert!(
|
||
off.contains(&format!(
|
||
"It's tiny. It naps in {place} until you {start} the key."
|
||
)),
|
||
"{caps:?}: {off:?}"
|
||
);
|
||
assert!(
|
||
!off.iter()
|
||
.any(|text| text.contains("Mac") || text.contains("menu bar")),
|
||
"{caps:?}: {off:?}"
|
||
);
|
||
}
|
||
|
||
let on = texts(&runtime_for(
|
||
ready_with_login(caps, LoginItemStatus::Enabled, false),
|
||
true,
|
||
PANE_SIZE,
|
||
));
|
||
assert!(
|
||
on.contains(&"Hex opens when your computer starts.".to_owned()),
|
||
"{caps:?}: {on:?}"
|
||
);
|
||
assert!(
|
||
!on.iter()
|
||
.any(|text| text.contains("Mac") || text.contains("menu bar")),
|
||
"{caps:?}: {on:?}"
|
||
);
|
||
}
|
||
}
|