Compare commits

..
Author SHA1 Message Date
Martin BallandClaude Opus 5.5 41172425d5 #7463: wait for the stubbed update check by wall-clock time, not a frame count
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FypgCZhHKRuRB5wZUiw6BE
2026-11-22 22:17:18 +00:00
Martin BallandClaude Opus 5.5 a4931ed447 #7463: wait for the update-check worker thread in the audit test
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FypgCZhHKRuRB5wZUiw6BE
2026-11-22 22:08:44 +00:00
Martin BallandClaude Opus 5.5 e652f6a4c6 #7463: i18n audit asserts the update check ran through the stub
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FypgCZhHKRuRB5wZUiw6BE
2026-11-22 22:02:49 +00:00
Martin BallandClaude Opus 5.5 802adcc02e #7463: i18n audit ignores clock data and URLs, and never calls GitHub
The audit compared the Date and Time preview with the clock at the moment of the
check, so a second ticking over between drawing and checking failed it. It now
accepts any preview from any second since the audit began, and any single-word
http(s) link. Check for Updates in the audit's apps answers from a stub, so the
GitHub rate limit's error text can't appear. A test pins that wording and
sentences with links are still reported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FypgCZhHKRuRB5wZUiw6BE
2026-11-22 19:52:46 +00:00
5 changed files with 98 additions and 10 deletions
+2 -1
View File
@@ -16,7 +16,8 @@ mod objects;
pub(crate) use header_footer::saved_copy;
use header_footer::{create_hf, edit_hf, header_footer, new_empty_headers, strip_headers};
pub use items::{
DropCapState, default_date_picture, drop_cap_state, format_date, format_date_at, format_date_in, format_date_parts, format_date_parts_in,
DropCapState, default_date_picture, drop_cap_state, format_date, format_date_at, format_date_at_in, format_date_in, format_date_parts,
format_date_parts_in,
};
use items::{cover_page, date_time, drop_cap, drop_cap_off, field, page_number, symbol};
use links::{bookmark, delete_bookmark, link, link_targets};
+1 -1
View File
@@ -26,7 +26,7 @@ pub(crate) mod symbol;
pub use columns::DropCapForm;
pub use date_time::DateTimeForm;
#[cfg(test)]
pub(crate) use date_time::date_time_preview_matches;
pub(crate) use date_time::date_time_previews_at;
pub use field::{DATE_FORMATS, FIELD_CATEGORIES, FIELDS, FieldForm, FieldKind, NUMBER_FORMATS, STYLEREF_SWITCHES, field_kind};
pub(crate) use symbol::SymbolDialog;
pub use symbol::{RECENT_SYMBOLS, RecentSymbol, SPECIAL, SUBSETS, SymbolForm, remember_symbol, subset_of};
@@ -35,14 +35,16 @@ const PT_DATE_FORMATS: &[&str] = &[
"HH:mm:ss",
];
/// The date preview list consists of document values (not interface strings).
/// The i18n audit recognizes these dynamic values instead of treating month names as UI labels.
/// What the Date and Time preview list shows at the instant `unix`: document values, not
/// interface strings. The i18n audit recognizes these instead of treating month names, dates and
/// times as labels.
#[cfg(test)]
pub(crate) fn date_time_preview_matches(value: &str) -> bool {
PT_DATE_FORMATS.iter().chain(DATE_FORMATS.iter()).any(|picture| {
wordcraft_engine::cmd::insert::format_date_in(picture, Some("pt-BR")) == value
|| wordcraft_engine::cmd::insert::format_date_in(picture, Some("en-US")) == value
})
pub(crate) fn date_time_previews_at(unix: u64) -> impl Iterator<Item = String> {
let offset = wordcraft_engine::cmd::local_offset_secs(unix);
PT_DATE_FORMATS
.iter()
.chain(DATE_FORMATS.iter())
.flat_map(move |picture| ["pt-BR", "en-US"].map(|lang| wordcraft_engine::cmd::insert::format_date_at_in(picture, Some(lang), unix, offset)))
}
/// State of the Word-like Insert > Date & Time dialog.
+67 -1
View File
@@ -28,7 +28,14 @@ fn unmarked(text: &str) -> String {
out
}
/// When the audit began: the Date and Time preview drawn at any moment since is clock data, not
/// interface text, whatever second the audit compares it in (#7463).
static CLOCK_START: std::sync::OnceLock<u64> = std::sync::OnceLock::new();
thread_local! {
// Every date/time the preview list could show since `CLOCK_START`, up to the second last
// looked at: (next second to add, strings).
static CLOCK_TEXTS: std::cell::RefCell<(u64, std::collections::HashSet<String>)> = std::cell::RefCell::new(Default::default());
// Input time, advanced every frame so tooltips and animations move on.
static TIME: Cell<f64> = const { Cell::new(0.0) };
// Process-wide names (font families, the custom dictionary) seen at any point of the run:
@@ -36,6 +43,19 @@ thread_local! {
static GLOBAL_NAMES: std::cell::RefCell<std::collections::HashSet<String>> = std::cell::RefCell::new(Default::default());
}
/// Whether `text` is something the Date and Time preview list showed at any second since the audit began.
fn clock_text(text: &str) -> bool {
let start = *CLOCK_START.get_or_init(wordcraft_engine::cmd::now_unix);
let now = wordcraft_engine::cmd::now_unix();
CLOCK_TEXTS.with_borrow_mut(|(next, set)| {
for unix in (*next).max(start)..=now {
set.extend(crate::dialogs_insert::date_time_previews_at(unix));
}
*next = now + 1;
set.contains(text)
})
}
/// Remember the process-wide names drawn this frame could have come from.
fn note_global_names() {
GLOBAL_NAMES.with_borrow_mut(|seen| {
@@ -124,11 +144,16 @@ fn pseudo_app(ctx: &egui::Context) -> WordApp {
}
fn fresh_app(ctx: &egui::Context) -> WordApp {
CLOCK_START.get_or_init(wordcraft_engine::cmd::now_unix);
ctx.all_styles_mut(|s| s.interaction.tooltip_delay = 0.0);
let mut app = WordApp::new(wordcraft_engine::Session::new(wordcraft_engine::sample::sample_document()), Default::default());
// Read Aloud holds each sentence instead of starting the system's speech engine: no sound on
// machines that have one, and no worker thread failing at its own pace on machines that don't.
app.session.read_aloud.backend = wordcraft_engine::speech::Backend::Hold;
// Help › Check for Updates answers "up to date" instead of asking GitHub, whose rate limit
// would otherwise put the updater's error text on screen.
#[cfg(not(target_arch = "wasm32"))]
app.stub_update_check();
// Fonts install over the first frames.
for _ in 0..2 {
frame(ctx, &mut app);
@@ -136,6 +161,11 @@ fn fresh_app(ctx: &egui::Context) -> WordApp {
app
}
/// A link: one `http(s)://` word.
fn is_url(text: &str) -> bool {
(text.starts_with("https://") || text.starts_with("http://")) && !text.contains(char::is_whitespace)
}
/// Words (two or more ASCII letters in a row) drawn outside translation marks.
fn english_words(text: &str) -> bool {
let plain = unmarked(text);
@@ -284,7 +314,8 @@ impl<'a> Exempt<'a> {
|| matches!(plain, "WordCraft" | "WordCraft User" | "Discord" | "https://" | "auto" | "I. II. III." | "i. ii. iii." | "I, II, III, …" | "i, ii, iii, …")
|| plain == "CONFIDENTIAL" // the watermark dialog's text: document content, kept as typed
|| plain == "Figure 1" // the caption dialog's sample: the label goes into the document as is
|| crate::dialogs_insert::date_time_preview_matches(plain)
|| clock_text(plain) // the Date and Time preview: formatted from the clock
|| is_url(plain) // a link is data, not wording
}
}
@@ -300,6 +331,41 @@ fn math_placeholders_are_exact_math_input_only() {
assert!(!set.contains("Translate"), "ordinary interface wording is not exempt");
}
/// Runtime data is exempt (links, the clock's dates and times), wording is not (#7463), and
/// Check for Updates never reaches the network.
#[test]
fn runtime_data_is_exempt_and_wording_is_not() {
let ctx = crate::test_harness::context();
let mut app = fresh_app(&ctx);
let none = std::collections::HashSet::new();
let exempt = Exempt::new(&app, &none);
let now = wordcraft_engine::cmd::now_unix();
let offset = wordcraft_engine::cmd::local_offset_secs(now);
for picture in ["M/d/yyyy h:mm:ss am/pm", "h:mm:ss am/pm", "dddd, MMMM d, yyyy"] {
let drawn = wordcraft_engine::cmd::insert::format_date_at_in(picture, None, now, offset);
assert!(exempt.allows(&app, &drawn), "{drawn:?} is the clock");
}
assert!(exempt.allows(&app, "https://github.com/storytold/wordcraft/releases"));
assert!(!exempt.allows(&app, "Download the newest release"), "an unwrapped sentence is reported");
assert!(!exempt.allows(&app, "See https://example.com now"), "a sentence with a link is not a link");
assert!(!exempt.allows(&app, "11/22/1999 5:28:50 PM"), "a time before the audit began is not the preview");
// A stubbed check finds no update and puts no updater error on screen.
app.run("help.checkForUpdates", json!({})).expect("Check for Updates runs");
let calls = app.updates_rt.stub_calls.clone();
// The check runs on a worker thread: draw at least 30 frames, then until it has run (a loaded
// runner can be slow to start the thread, so the cap is wall-clock time, not a frame count).
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(10);
for n in 0.. {
let drawn = frame(&ctx, &mut app);
assert!(drawn.iter().all(|t| !t.contains("request limit")), "{drawn:?}");
if n >= 30 && (calls.load(std::sync::atomic::Ordering::SeqCst) > 0 || std::time::Instant::now() > deadline) {
break;
}
std::thread::sleep(std::time::Duration::from_millis(2));
}
assert_eq!(calls.load(std::sync::atomic::Ordering::SeqCst), 1, "the check went through the stub, not GitHub");
}
/// Fails on interface text drawn without going through the catalog, listed per UI state, and
/// prints the missing-translation report (`report_catalog_gaps`). `cargo xtask i18n-report` runs it
/// with `--nocapture`; `cargo xtask test` and `ci` run it that way instead of in the main test run.
+19
View File
@@ -16,6 +16,9 @@ pub(crate) struct Runtime {
/// The desktop app turns the check at start on; tests and the web build leave it off.
#[cfg(not(target_arch = "wasm32"))]
startup_check: bool,
/// How many times the test stub answered a check (see `stub_update_check`).
#[cfg(all(test, not(target_arch = "wasm32")))]
pub(crate) stub_calls: std::sync::Arc<std::sync::atomic::AtomicUsize>,
}
impl Default for Runtime {
@@ -25,6 +28,8 @@ impl Default for Runtime {
updater: Updater::new(&crate::UPDATE_APP, env!("CARGO_PKG_VERSION")).with_translator(translate),
#[cfg(not(target_arch = "wasm32"))]
startup_check: false,
#[cfg(all(test, not(target_arch = "wasm32")))]
stub_calls: Default::default(),
}
}
}
@@ -53,6 +58,20 @@ impl WordApp {
rt.updater = Updater::new(&crate::UPDATE_APP, env!("CARGO_PKG_VERSION")).with_translator(translate).with_source(refused_check());
}
/// Answers every update check with "up to date" instead of asking GitHub, so a test's result
/// doesn't depend on the network or its rate limit (#7463).
#[cfg(all(test, not(target_arch = "wasm32")))]
pub(crate) fn stub_update_check(&mut self) {
let rt = &mut self.updates_rt;
rt.startup_check = false;
let calls = rt.stub_calls.clone();
rt.updater =
Updater::new(&crate::UPDATE_APP, env!("CARGO_PKG_VERSION")).with_translator(translate).with_source(std::sync::Arc::new(move || {
calls.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
Ok(None)
}));
}
/// Starts the helper of an update that is ready, so that it installs once the process has
/// ended. Call it once the exit is certain, before a path that ends the process without
/// dropping the app. Later calls do nothing.