Merge main into feat/voice-bitcrusher

This commit is contained in:
dotCooCoo committed 2026-11-28 00:54:22 -08:00
commit 781b2fa5f8
10 files changed
+1198 -9

No files matched your search

Generated
+2
View File
@@ -4317,7 +4317,9 @@ dependencies = [
name = "craft-testkit"
version = "0.1.0"
dependencies = [
"libc",
"rustix 1.1.6",
"sha2 0.10.9",
"skrifa 0.47.0",
]
+2 -1
View File
@@ -424,7 +424,8 @@ See the [release notes](CHANGELOG.md) for included functionality and known limit
module holds two seeded generators for repeatable test input. Its `skip` module prints a `SKIPPED:`
line when a test lacks a program, a corpus or the craft-fonts faces, or fails the test when the
variable the caller names is `1`. Any other value of that variable except empty fails the test as a
configuration error. Not published.
configuration error. Its `corpus` module (the `corpus` feature) checks a corpus folder against a
pinned SHA-256 list. Not published.
- [`craft-text`](crates/text/README.md): text processing below the composer. Its `hyphen` module finds
hyphenation points, with a bundled US English dictionary and patterns and optional hypher patterns
for 47 more languages (one cargo feature each). With `ui`, the canvas text editor, Character and
+22
View File
@@ -875,6 +875,28 @@ mod tests {
}
}
#[test]
fn a_hop_periodic_startup_vowel_keeps_its_level_at_16_khz() {
let sr = 16_000.0;
let held = sr as usize * 3;
let mut speech = vec![0.0f32; held + sr as usize / 2];
for (i, v) in speech[..held].iter_mut().enumerate() {
let t = std::f64::consts::TAU * 250.0 * i as f64 / sr as f64;
*v = (1..8).map(|h| (0.15 * (h as f64 * t).sin() / h as f64) as f32).sum();
}
let mut s = NoiseSuppression::new(sr, 1);
assert!(s.set_param("reduction", 24.0));
s.reset();
assert_eq!(s.hop, sr as usize / 250);
let lat = s.latency();
let mut y = speech.clone();
s.process(&mut [&mut y]);
for range in [0..sr as usize * 2, sr as usize * 3 / 2..sr as usize * 2] {
let kept = db((energy(&y[range.start + lat..range.end + lat]) / energy(&speech[range.clone()])).sqrt());
assert!(kept.abs() < 3.0, "the 250 Hz startup vowel at 16 kHz changed by {kept:.2} dB over {range:?}");
}
}
/// Steady noise whose spectrum falls with frequency (white noise through a one-pole low-pass
/// at 500 Hz) is suppressed by at least 20 dB from 4 s on.
#[test]
+4
View File
@@ -9,15 +9,19 @@ description = "Source-level platform regression guards, test deadlines, hostile-
publish = false
[features]
# Pinned-corpus manifests and the `corpus::pinned` test gate (native only).
corpus = ["dep:sha2", "dep:libc"]
# `font-coverage`: `skip::craft_fonts_cover`, which parses font data with skrifa.
font-coverage = ["dep:skrifa"]
[dependencies]
sha2 = { version = "0.10", default-features = false, features = ["std"], optional = true }
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
skrifa = { workspace = true, optional = true }
[target.'cfg(unix)'.dependencies]
libc = { version = "0.2", optional = true }
rustix = { version = "1.1", default-features = false, features = ["std", "fs"] }
[lints]
+31
View File
@@ -237,6 +237,20 @@ Changes from `craft-media-testkit`'s `hammer`:
- `parse` is owned and runs on a worker thread. A closure that borrows from the test needs its data
moved or shared with an `Arc`.
## corpus
`craft_testkit::corpus` is behind the `corpus` feature and is native only. It parses a corpus manifest and checks a folder of files against it.
A manifest has one row per file, with tab-separated columns: the SHA-256 as 64 hexadecimal digits in either case, the path relative to the corpus folder with `/` between its parts, and optional license and URL columns. Blank lines and lines whose first character other than a space or a tab is `#` are skipped. LF and CRLF line endings are both read.
- `Manifest::parse(text)` returns a `ManifestError` naming the line for a row with fewer than 2 or more than 4 columns, a digest that is not 64 hexadecimal digits, a path that is empty, starts with `/`, has an empty, `.` or `..` part, or holds a `\`, a `:` or a control character (NUL included), and a path listed twice. An empty optional column is `None`. The parser does not check that a name is valid on a given file system: a name Windows reserves (`<`, `>`, `"`, `|`, `?`, `*`, a trailing `.` or space, a device name such as `NUL`) or two names that differ only in case are accepted, so a manifest must use names that every file system it is verified on supports.
- `Manifest::read(path, &limits)` reads a manifest file, stopping one byte past the size limit. A path that is not a regular file, such as a folder or a named pipe, returns `ManifestError::NotAFile` without being opened.
- `verify(dir, &manifest)` checks that each listed file resolves inside `dir` after symbolic links are followed, is a regular file within the size limit, and has the listed SHA-256. It returns a `VerifyError` naming the path. A manifest with no rows is an error.
- On Unix, `Manifest::read` and `verify` open each file with `O_NONBLOCK` and check the opened file's type again, so a path replaced by a named pipe after the first check fails at once. After the open, `verify` also checks that the opened file is inside `dir`: on Linux, Android and Apple platforms by the path the kernel reports for the open file, and on other Unix systems, or on Linux and Android when `/proc/self/fd` cannot be read, by resolving the listed path again and comparing its device and inode with the opened file's. On Apple platforms an error from the path query fails verification with `VerifyError::Read` instead of falling back to the second lookup. That second lookup goes through the path again, so a folder changed during it is not detected. On Windows the location of the opened file is not checked again, so a part of the path changed into a link out of `dir` between the check and the open is not detected. In every case the opened file must still have the listed SHA-256.
- `pinned(var, manifest)` is the gate a test calls. `var` names the folder variable, and `None` reads `CRAFT_CORPUS`. With the folder variable unset, it calls `skip::skip` with the reason `corpus not given: set <var> to its folder` and the required variable `<var>_REQUIRED` (by default `CRAFT_CORPUS_REQUIRED`), so the [skip](#skip) rule applies: unset or empty prints `SKIPPED: corpus not given: set <var> to its folder` to stderr and returns `None`, `1` fails the test, and any other value, `0` included, fails the test as a configuration error. With the folder variable set to an empty value, a manifest that does not parse or a folder that does not match, it fails the test. A `var` that is empty or holds `=` or a NUL character fails the test before the environment is read. Otherwise it returns the folder.
`Limits` sets the size limits: by default a manifest of at most 1 MiB and 10,000 rows, and files of at most 8 GiB each, read 64 KiB at a time. No function downloads a file or changes the process environment.
## skip
The `skip` module is not built for `wasm32`. A test that needs something a test environment may lack
@@ -354,6 +368,12 @@ PhotoCraft and DeckCraft. `holders_take_turns` waits on channels where the copie
|---|---|---|---|
| `Rng`, the edits of `mutations` and `hammer` | storytold/craft-libs | `crates/media-testkit/src/hostile.rs` | `75a654f4` |
### corpus
| Code | Repository | Path | SHA |
|---|---|---|---|
| The manifest rows and the digest check of `pinned` | storytold/craft-libs | `crates/affinity/tests/support/corpus.rs:18-35` | `75a654f4` |
### skip
| Code | Repository | Path | Commit |
@@ -414,6 +434,17 @@ An adoption keeps the variable name the app uses today.
CADCraft's and TextureCraft's loops make other edits than `mutations`. Their adoptions say which
cases change, and keep the test names.
### corpus
| Consumer | Code it replaces | State |
|---|---|---|
| craft-libs `affinity` | `tests/support/corpus.rs`, which parses `corpus.tsv` (four tab-separated columns) and checks the folder `AFFINITY_CORPUS` names | Pending |
| craft-libs `raw` | `tests/it/raf_corpus_manifest.rs`, which checks the rows of the tab-separated `docs/raf-corpus.sha256` but not the files | Pending |
| LightCraft | `crates/raw/tests/it/corpus.rs` checks the RAF list | Pending |
| PhotoCraft | `crates/io/tests/it/corpus.rs` and `xtask/*-corpus.sha256` (two-space lists, to be converted to tabs) | Pending |
| CADCraft | `crates/io/src/roundtrip/tests.rs` scans `CADCRAFT_CORPUS_DIR` without a checksum list | Pending: needs a pinned list first |
| VectorCraft | `crates/affinity/tests/support/corpus.rs` reads a two-space list, to be converted to tabs | Pending |
### skip
| Consumer | Code it replaces | State |
File diff suppressed because it is too large. Load diff
+8 -2
View File
@@ -32,12 +32,16 @@
//! for GPU tests. Every GPU test in a process must take this lock, because a test that takes a
//! different lock can run at the same time as one that takes this one.
//!
//! [`skip`] decides what a test does when something it needs is missing (a program, a corpus,
//! `skip` decides what a test does when something it needs is missing (a program, a corpus,
//! the craft-fonts faces): it prints one `SKIPPED:` line and returns, or fails the test when the
//! variable the caller names is `1`. A value other than unset, empty or `1` fails the test as a
//! configuration error. [`skip::required`] reads such a variable under this rule for any caller.
//! configuration error. `skip::required` reads such a variable under this rule for any caller.
//! It is not built for `wasm32`. `skip::craft_fonts_cover` needs the `font-coverage` feature.
//!
//! With the `corpus` feature, `corpus` (native only) parses pinned-corpus manifests and checks a
//! corpus folder against them: `corpus::Manifest`, `corpus::verify` and the test gate
//! `corpus::pinned`, which skips or fails under the rule of `skip`.
//!
//! ### Epistemic Scope: What Source Guards Establish vs What They Cannot
//!
//! Source-level guards provide deterministic syntactic evidence about codebase structure.
@@ -48,6 +52,8 @@
//! under foreign host environments. They are lightweight syntactic regression gates designed to complement,
//! rather than replace, platform integration tests and CI execution.
#[cfg(all(feature = "corpus", not(target_arch = "wasm32")))]
pub mod corpus;
#[cfg(not(target_arch = "wasm32"))]
pub mod deadline;
pub mod guards;
+17 -1
View File
@@ -115,7 +115,9 @@ fn skip_with(required: bool, reason: &str, required_var: &str) -> bool {
if required {
panic!("{reason}, and {required_var}=1 forbids skipping this test");
}
eprint!("{}", skip_line(reason));
// Written to the process's stderr directly: `eprint!` is captured by the test harness and
// would hide the line from a default run.
let _ = std::io::Write::write_all(&mut std::io::stderr().lock(), skip_line(reason).as_bytes());
false
}
@@ -385,6 +387,20 @@ mod tests {
assert!(!err.contains("ran on"), "{err}");
}
#[test]
fn the_skip_line_shows_in_a_run_that_captures_test_output() {
let exe = std::env::current_exe().expect("the test binary's path");
let out = Command::new(exe)
.args(["skip::tests::child", "--exact", "--test-threads=1"])
.env(CHILD_CASE, "skip")
.env_remove(REQUIRED_VAR)
.output()
.expect("run the test binary");
let err = stderr(&out);
assert!(out.status.success(), "{err}");
assert!(err.contains("SKIPPED: probe absent\n"), "{err}");
}
#[test]
fn skip_lines_from_parallel_threads_stay_whole() {
let out = run_child("threads", None);
@@ -203,7 +203,8 @@ fn preset_row(ui: &mut Ui, kit: &Kit<'_>, options: &mut SaveForWebOptions, live:
}
/// "Optimize to File Size…" and, once opened, its rows; OK, or Enter in the Desired File Size field, files the search.
/// While the rows are closed, the host's last answer shows as a line while the settings are the ones it found.
/// OK waits while the Desired File Size holds text that does not parse. While the rows are closed, the host's last
/// answer shows as a line while the settings are the ones it found.
fn optimize_rows(ui: &mut Ui, kit: &Kit<'_>, options: &SaveForWebOptions, live: &mut Live, asked: &mut Asked) {
let Kit { words, units, .. } = *kit;
if !live.optimize.open {
@@ -218,10 +219,19 @@ fn optimize_rows(ui: &mut Ui, kit: &Kit<'_>, options: &SaveForWebOptions, live:
}
return;
}
let mut unparsed = false;
row(ui, &words.optimize_size, "optimize-size", |ui| {
let edit = whole(units, words.optimize_size.clone(), live.optimize.desired_k(), DESIRED_K).submits().show(ui).edit;
if let Some(k) = edit.value().cloned().flatten() {
live.optimize.k = Some(k);
// An `f32` field takes no blank value, so empty text does not parse, as text that is not a number does not.
let edit = NumberField::named(words.optimize_size.clone(), Bind::given(live.optimize.desired_k() as f32))
.codec(NumberCodec::new(units.reader(None), 0))
.step(1.0)
.range(DESIRED_K)
.submits()
.show(ui)
.edit;
unparsed = edit.unparsed;
if let Some(k) = edit.value().copied() {
live.optimize.k = Some(f64::from(k));
}
if edit.submitted && edit.submit_mods == craft_keymap::Mods::NONE {
asked.optimize_request = Some(live.optimize.request(options));
@@ -247,7 +257,7 @@ fn optimize_rows(ui: &mut Ui, kit: &Kit<'_>, options: &SaveForWebOptions, live:
Text::new(reason.clone()).role(TypeRole::Caption).shade(Shade::Faint).id_salt("optimize-refused").show(ui);
}
Row::new().id_salt("optimize-buttons").show(ui, |ui, _| {
if clicked(&Button::new(words.optimize_ok.clone()).id_salt("optimize-ok").default_stop().show(ui)) {
if clicked(&Button::new(words.optimize_ok.clone()).id_salt("optimize-ok").enabled(!unparsed).default_stop().show(ui)) {
asked.optimize_request = Some(live.optimize.request(options));
}
if clicked(&Button::new(words.optimize_cancel.clone()).id_salt("optimize-cancel").show(ui)) {
@@ -320,6 +320,40 @@ fn enter_in_the_optimize_rows_files_the_search_and_never_saves() {
assert!(host.borrow_mut().get_mut::<HostedSaveForWeb>().and_then(HostedSaveForWeb::pick_path).is_some(), "with the rows closed Enter saves");
}
// While the Desired File Size holds text the field refuses (not a number, or empty), the Optimize rows' OK and Enter in
// the field file no search with the size the rows held before; once the text parses, OK files the typed size.
#[trial]
fn the_optimize_rows_file_nothing_while_the_size_text_is_refused() {
let (host, mut fixture) = open(HostedSaveForWeb::new("poster.psd", IMAGE, texture()).optimize());
let opener = fixture.by_label("Optimize to File Size…").expect("the Optimize button");
fixture.click(&opener).idle(4);
assert!(host.borrow_mut().get_mut::<HostedSaveForWeb>().expect("open").take_optimize_open(), "opening the rows asks for the opening size");
host.borrow_mut().get_mut::<HostedSaveForWeb>().expect("open").answer_optimize_start(Some(48 * 1024));
fixture.idle(4);
let request = |host: &Rc<RefCell<DialogHost>>| host.borrow_mut().get_mut::<HostedSaveForWeb>().and_then(HostedSaveForWeb::take_optimize_request);
for (text, what) in [("abc", "text that is not a number"), ("", "an empty field")] {
let field = fixture.by_label("Desired File Size (K)").expect("the Desired File Size field");
fixture.click(&field).settle();
fixture.key(Key::A, Modifiers::COMMAND).key(Key::Backspace, Modifiers::NONE).type_text(text);
fixture.idle(2);
fixture.key(Key::Enter, Modifiers::NONE).idle(4);
assert!(request(&host).is_none(), "Enter in the field files nothing while it holds {what}");
let ok = fixture.by_label("OK").expect("the rows' OK");
fixture.click(&ok).idle(4);
assert!(request(&host).is_none(), "OK files nothing while the field holds {what}");
}
let field = fixture.by_label("Desired File Size (K)").expect("the Desired File Size field");
fixture.click(&field).settle();
fixture.key(Key::A, Modifiers::COMMAND).type_text("20");
fixture.idle(2);
let ok = fixture.by_label("OK").expect("the rows' OK");
fixture.click(&ok).idle(4);
let filed = request(&host).expect("OK files the search once the text parses");
assert_eq!(filed.desired_k, 20.0, "the search asks for the typed size");
}
/// The frame the animation shows after the host's passes.
fn frame_of(host: &Rc<RefCell<DialogHost>>) -> u32 {
host.borrow_mut().get_mut::<HostedSaveForWeb>().map(|web| web.frame()).expect("the dialog is open")