xtask: test-lint fails on weak tests in the lines a change touches

`cargo xtask test-lint` reads the Rust files changed since a base and
fails on tests that a wrong result can pass: `.all()` with no length or
emptiness check, only is_ok/is_some/non-empty checks, `assert_eq!(x, x)`,
a process test that checks only the exit status, no assertion and no
asserting helper, a silent early return on a value from the code under
test, `#[ignore]` without a reason, an environment variable that no CI
leg sets, `thread::sleep` in test code, and test code that reads Rust
source outside the listed source audits.

Only hits on changed lines, or in a test with a changed line for the
rules about a whole test, fail it; older hits in the same files are
counted. The base is --base or TEST_LINT_BASE, the first parent of the
checked-out commit in CI (a shallow checkout fetches it), else the merge
base with upstream/main or origin/main. `// test-lint: allow <rule>
<reason>` exempts a line. `--all` lists every hit by crate and rule and
does not fail. `cargo xtask ci` runs it after cursors, so it runs in the
checks shard.
This commit is contained in:
dotCooCoo committed 2026-11-30 03:12:48 -08:00
1 parent ad642cb34c
commit f553ddfa67
3 files changed
+2586 -1

No files matched your search

+4
View File
@@ -349,6 +349,10 @@ The app decides which cursors exist; whoever draws them works from the list. For
`cargo xtask brands` (part of `cargo xtask ci`) fails when user-visible text names another vendor's products or company: string literals in Rust sources (command labels and params docs, menus, panels, MCP tool definitions), `Cargo.toml` descriptions and packaging files. Comments, test files and `#[cfg(test)]` modules are not checked. Say "the reference app" or name the feature itself. A line that must keep an old name, such as an alias that files or preferences from earlier versions still use, or a name another project defines, such as a shared MIME type, carries a `brand-ok` comment. In the Linux desktop entry, whose comments take whole lines, the comment goes on the `#` line just above it; `MARK_ABOVE` in `xtask/src/brands.rs` lists the files that accept a mark there.
## Test lint
`cargo xtask test-lint` (part of `cargo xtask ci`) fails on tests that a wrong result can pass, in the lines and tests changed since a base: `assert!(….all(…))` with no length or emptiness check, a test whose only checks are `is_ok`, `is_some` or `!is_empty`, `assert_eq!(x, x)`, a process test that checks only the exit status, a test with no assertion and no asserting helper, a silent early `return` on a value from the code under test, `#[ignore]` without a reason, an environment variable that no CI leg sets, `thread::sleep` in test code, and test code that reads Rust source outside the audits listed in `SOURCE_AUDITS`. The base is `--base <rev>` or `TEST_LINT_BASE`; in CI it is the first parent of the checked-out commit, and elsewhere the merge base with `upstream/main` or `origin/main`. Hits on unchanged lines are counted but do not fail it. A `// test-lint: allow <rule> <reason>` comment exempts its own line and the line below it; `xtask/src/test_lint.rs` lists the rules and their ids. `cargo xtask test-lint --all` lists every hit in the workspace by crate and rule, and does not fail.
## Tests
- `cargo xtask test` runs the workspace's unit and integration tests with
+8 -1
View File
@@ -18,6 +18,7 @@ mod sha256;
mod shards;
mod stats;
mod test262;
mod test_lint;
mod ui_commands;
mod version;
mod web_fonts;
@@ -32,6 +33,10 @@ commands:
assets check that every icon/image/font/asset is attributed in ASSETS.md
brands check that user-visible text (labels, params docs, MCP, docs, packaging) names no other vendor's products
cursors warn about Cursor values with no entry in crates/tools/src/cursors.toml (never fails)
test-lint [--base <rev>] [--all]
fail on weak tests (unguarded .all(), only is_ok/is_some checks, no assertion, early
returns, unset env gates, sleeps...) in the lines changed since the base
(xtask/src/test_lint.rs); --all lists every hit by crate and never fails
i18n-report list the strings each language's catalog lacks, shown in English (fails only on a
broken scan; ci runs it too)
ui-commands regenerate crates/mcp/src/ui_catalog.rs from desktop UI_COMMANDS; --check fails on drift
@@ -39,7 +44,7 @@ commands:
layers enforce the crate dependency layering (plan/architecture.md §3)
wasm cargo check --target wasm32-unknown-unknown for the wasm-safe crates, the web app and its plug-in worker
test the workspace tests (cargo nextest when installed, else cargo test), then the doctests
ci fmt --check, clippy -D warnings, test, doctests, no-bundled-fonts, pdf-deps, assets, brands, cursors (warnings only), ui-commands --check, layers, wasm (stops at first failure)
ci fmt --check, clippy -D warnings, test, doctests, no-bundled-fonts, pdf-deps, assets, brands, cursors (warnings only), test-lint, ui-commands --check, layers, wasm (stops at first failure)
ci shard shard $GATE_SHARD of $GATE_SHARDS of ci (xtask/src/shards.rs): a test shard runs
the tests and doctests of its crates, the last shard the other steps
ci warm build what every shard builds, without running it (fills the gate's cache); with
@@ -74,6 +79,7 @@ fn main() -> ExitCode {
Some("assets") => assets::run(&root()),
Some("brands") => brands::run(&root()),
Some("cursors") => cursors::run(&root()),
Some("test-lint") => test_lint::run(&root(), &rest),
Some("i18n-report") => cmd_i18n_report(),
Some("ui-commands") => ui_commands::run(&root(), rest.contains(&"--check")),
Some("layers") => cmd_layers(),
@@ -515,6 +521,7 @@ fn ci_steps() -> Vec<Step> {
("assets", Box::new(|| assets::run(&root()))),
("brands", Box::new(|| brands::run(&root()))),
("cursors", Box::new(|| cursors::run(&root()))),
("test-lint", Box::new(|| test_lint::run(&root(), &[]))),
("i18n-report", Box::new(cmd_ci_i18n_report)),
("ui-commands", Box::new(|| ui_commands::run(&root(), true))),
("layers", Box::new(cmd_layers)),
File diff suppressed because it is too large. Load diff