Commit Graph
20 Commits
Author SHA1 Message Date
BFlat 5a77c51821 Merge pull request #1405 from dotCooCoo/feat/craft-testkit-rng
craft-testkit: add seeded xorshift64 and xorshift64* generators for test input
2026-11-26 10:08:27 +07:00
dotCooCoo d791d9c893 testkit: describe below's modulo bias over the nonzero draw range
A draw from either generator is never 0, so below(n) reduces one of the
2^64 - 1 values from 1 to 2^64 - 1. The README and the module doc now say
that below(n) is unbiased when n divides 2^64 - 1 (below(3) is), that
otherwise the results from 1 to (2^64 - 1) mod n come from one more state
than the others, and that the bias can be large: on a 64-bit target,
below(2^63 + 1) returns 1 twice as often as 0.
2026-11-24 16:14:37 -08:00
dotCooCoo da52b002d2 Merge main into feat/craft-testkit-rng 2026-11-17 18:17:00 -08:00
dotCooCoo 5c5b529480 Merge main into feat/craft-testkit-serial 2026-11-17 18:09:17 -08:00
aiongg ff502fb75f ci: run a fraction of the fuzz-style tests on pull requests, all of them nightly
craft-testkit's hostile hammer reads CRAFT_HOSTILE_DIVISOR=N: the unmodified
seed, every N-th truncation and 1/N of the rounds. hostile::divisor() gives the
same value to sweeps written without the hammer; craft-image-codecs' TIFF zoo
and malformed-header sweeps use it, with a different offset per input so the
inputs together still reach every position. Proptests without their own case
count read proptest's PROPTEST_CASES.

The Workspace gate and the media, audio, video and PDF workflows set
CRAFT_HOSTILE_DIVISOR=8 and PROPTEST_CASES=64. The longest of these tests
(craft-media's MXF hostile input, 1,310 s on Windows; craft-pdf's crypt
proptests, up to 257 s; the image-codecs sweeps, 140-162 s) drop to about an
eighth or a quarter. nightly.yml runs the whole workspace on Linux without
either variable, so every case still runs once a day.

The gate's test-input setup moves to scripts/ci-test-inputs.sh, shared by both
workflows; it uses a corpus that is already present.
2026-11-17 19:09:17 +00:00
dotCooCoo d837d459ef Merge main into feat/craft-testkit-rng 2026-11-16 19:39:25 -08:00
dotCooCoo c9c4e4da65 Merge main into feat/craft-testkit-serial 2026-11-16 19:36:54 -08:00
.CooCoo c91e32eb67 craft-media-testkit: run hostile and with_deadline on craft-testkit (#1462) 2026-11-16 21:34:35 -05:00
dotCooCoo f390dcf3cb Merge feat/craft-testkit-guards into feat/craft-testkit-rng 2026-11-14 17:07:53 -08:00
dotCooCoo e1b53c6b44 craft-testkit: guards end a native cfg if let at its body and read only muda's qualified type
- A native-only `if`, `while`, `match` or `for` now ends at its body's
  closing brace, or at the last block of an `else` chain. A `{` in the
  pattern of a `let` (also after `&&` in a chain) or a `for` opens a
  struct pattern, so `#[cfg(unix)] if let State::Ready { .. } = s { .. }`
  no longer ends at the pattern's brace and leaves its body checked.
- A raw identifier spelled like a keyword (`r#let`, `r#in`, `r#match`)
  is read as a name. `mod r#match;` still names `match.rs`.
- predefined_quit reports a qualified path only as
  `muda::PredefinedMenuItem` (or `::muda::...`), so
  `other_crate::PredefinedMenuItem::quit` is not reported. The plain
  name and a `use muda::PredefinedMenuItem as X` rename still are.
2026-11-14 17:01:49 -08:00
dotCooCoo c0a5bb8b5c Merge feat/craft-testkit-guards into feat/craft-testkit-rng 2026-11-14 15:38:23 -08:00
dotCooCoo 4739754009 craft-testkit: guards read cfg literals, escapes and deep nesting, and bound use-path copies
- A cfg predicate nested more than 64 levels deep is unknown, so its
  item is checked instead of skipped.
- cfg(true) and cfg(false) are read as their values; r#true and
  r#false stay option names.
- String values in cfg predicates have their escapes decoded; a string
  with an invalid escape is unknown.
- The `:` after a field's name starts its type, so a native-only
  `callback: fn(),` field ends at its comma and later fields are checked.
- use<...> is read as a capturing bound, not a declaration, and the
  guards keep use paths of at most eight segments of at most 32 bytes,
  so a long prefix or name shared by many leaves is not copied into each.
- std_instant finds the modules of a file that a #[path] attribute names
  next to that file, separately from a plain load of the same file.
- predefined_quit reports <muda::PredefinedMenuItem>::quit.
- wgsl_float_literals ends line comments and counts lines at every WGSL
  line break, and skips digits inside Unicode identifiers.
2026-11-14 15:34:50 -08:00
dotCooCoo a7b24b109a Testkit: std_instant keeps a native cfg on the whole statement it covers
A native-only `let`, `return` or other statement whose value holds an
`if` or `match` block is now exempt up to its `;`, instead of only to the
nested block's closing brace. A match arm whose value holds a block runs
to its comma. Const blocks and labeled blocks at the head of a statement
or arm end at their closing brace, so the next statement is checked.

A `use` split over lines is reported once, on the line where its path
starts.

Adds tests for paths split by line breaks and comments (CRLF included),
cfg attributes with code before and after them on one line, other time
modules and longer names, literals and labels, and a large source.
2026-11-14 14:58:16 -08:00
dotCooCoo 19b98454a9 craft-testkit: seeded xorshift64 and xorshift64* generators for test input
Add craft_testkit::rng with XorShift64 (shifts 13, 7, 17) and
XorShift64Star (shifts 12, 25, 27, output multiplied by
0x2545_F491_4F6C_DD1D, state kept unmultiplied). Each has new, next,
below, byte and fill.

- new returns SeedError::ZeroSeed for a seed of 0, which would make
  either recurrence return 0 forever.
- below takes one draw modulo the bound; a bound of 0 returns 0 after
  one draw, as the DNx and JPEG suites do today.
- byte is the low 8 bits of one draw; fill takes one byte() per output
  byte in index order, and an empty slice takes no draw.

The module uses no std-only items and builds for wasm32-unknown-unknown.
Its tests pin the first outputs of both generators for the DNx and JPEG
seeds and compare draws with the generators those suites define. The
README gains the module's description and rows for it in the Origin and
Migration tables.
2026-11-14 13:54:32 -08:00
dotCooCoo 836433ccb9 craft-testkit: wgsl_float_literals docs say the limit check uses the value rounded to f64
README item 2, the wgsl_float_literals rustdoc and the boundary test comment now say the
scanner compares each literal's value rounded to f64, so a literal that exceeds the maximum
by less than f64 precision, such as 0x1.fffffe000000001p+127f, is not reported. They also say
0x1.fffffep+127f equals f32::MAX and 3.4028234663852886e38 rounds to it.
2026-11-14 12:01:40 -08:00
dotCooCoo b89076646d craft-testkit: rust_sources docs name the CACHEDIR.TAG signature it checks
rust_sources skips a folder only when its CACHEDIR.TAG starts with the line
Signature: 8a477f597d28d172789f06886806bc55. The doc comment and the crate
README now say so instead of naming any CACHEDIR.TAG file.
2026-11-14 11:55:02 -08:00
dotCooCoo b9d451674e craft-testkit: std_instant skips module files a native-only mod declares
std_instant read each file on its own, so `#[cfg(not(target_arch =
"wasm32"))] mod native;` in lib.rs did not stop it from reporting
std::time::Instant in native.rs when both came from one rust_sources
call.

std_instant now first collects every `mod name;` declaration and treats
the file it names as native-only when the declaration is inside an item
whose cfg is false on wasm32-unknown-unknown, along with the files that
file declares. A file that a declaration outside such items also reaches
from a crate root is still checked. Module files are found by rustc's
rules: next to lib.rs, main.rs and mod.rs, in the stem folder of any
other file, below enclosing inline modules, and through #[path] on the
declaration or on an enclosing inline module. Declarations inside more
than 64 inline modules are not followed, so their files are checked.
2026-11-14 11:40:45 -08:00
dotCooCoo d378335722 craft-testkit: add the serial module with a reentrant test lock
TestLock is a lock a static can hold (TestLock::new is const). The
thread that holds it can take it again, and it is released when the
last of that thread's guards is dropped, in any order. A panic while
it is held does not block the next holder, and a poisoned internal
mutex is recovered. Guards are not Send.

gpu_lock() is the one lock of the process for GPU tests, and
hold_gpu_lock() keeps it until the calling thread ends; a second call
on the same thread does nothing more. The module is native only and
reads no environment variables.

The lock comes from PhotoCraft's crates/testkit/src/gpu.rs and
DeckCraft's crates/ui-egui/src/gpu_lock.rs, with the thread-held form
from EffectCraft's crates/gpu/src/tests.rs.
a_panicked_holder_does_not_block_the_next_test and holders_take_turns
keep their names; holders_take_turns now waits on channels instead of
sleeping 2 ms.
2026-11-14 11:17:12 -08:00
dotCooCoo 52b917fce5 craft-testkit: guards read Rust tokens, check hex and f16 floats, and bound rust_sources
predefined_quit and std_instant now run on a small Rust lexer instead of
a masked line search:

- Character and byte literals such as '"' no longer open a phantom
  string that hides the code after them.
- A Quit call split by tabs or a line break around :: is reported, a
  different name such as MyPredefinedMenuItem or quitter is not, and a
  use muda::PredefinedMenuItem as X rename is followed.
- std_instant reports std::time::Instant, <m>::Instant where a use binds
  m to std::time, and each use that imports std::time::Instant or
  std::time::*. A line that also names web_time is still reported, and
  an unrelated time::Instant is not.
- cfg attributes are read from code, not from strings or comments, and
  evaluated for wasm32-unknown-unknown (all, any, not, unix, windows,
  target_* keys). An outer attribute covers the item after it, an inner
  one the rest of its module. A predicate that depends on a feature or
  test is checked.

wgsl_float_literals skips integer literals, reports hexadecimal floats
above f32::MAX, and checks an h-suffixed float against 65504.

rust_sources does not follow symbolic links, skips folders that hold a
CACHEDIR.TAG file, no longer drops every file when the root itself is
under a folder named tests, and returns an error for a file over 8 MiB,
more than 256 MiB in all or more than 50,000 files.
rust_sources_with_limits takes other limits.

The tests use a scratch folder that is never reused and is removed when
a test panics. The crate is not published, and the root README lists
it.
2026-11-14 11:16:07 -08:00
Zach Shallbetter 87bbc1c711 craft-testkit: add source-level platform regression guards (closes #139)
Add craft-testkit with source guards for platform rules that broke before:
- predefined_quit: flags calls of muda PredefinedMenuItem::quit that bypass dirty document save prompts and window teardown on macOS.
- wgsl_float_literals: scans WGSL shaders using PhotoCraft's decimal float scanner and flags literals exceeding f32 finite range that fail on WebGPU compilers (Tint).
- std_instant: flags lines naming std::time::Instant without web_time in code running on the web, preventing wasm32 runtime panics.
- rust_sources: directory crawler discovering a crate's .rs sources while excluding test files and test directories.
2026-11-14 10:53:15 -08:00