diff --git a/.agents/skills/which-tier/SKILL.md b/.agents/skills/which-tier/SKILL.md index 752c288b1e..b49b6ba989 100644 --- a/.agents/skills/which-tier/SKILL.md +++ b/.agents/skills/which-tier/SKILL.md @@ -94,9 +94,11 @@ cargo can see a python file). everybody quotes is `cargo test --lib` alone, and that part is itself tens of seconds now (the per-crate test binaries, `UNIT_SUITE` in the Makefile, run side by side through `tools/cargo-test-parallel.py`; `make test-crate C=` runs just the one you touched); end to end the gate runs in MINUTES warm. The bulk of it is `python3 tests/test_harness.py`, which shells out to -`ci/check-deps.sh` (11 s a run) once or more per self-test to prove each structure gate still -catches a planted violation — 661 s of a 1100 s run, measured 2026-10-01 on a cold lane at load -~5, before those self-tests moved to private tree copies and a thread pool (175 s after). The lab selftest's **~7 s is mostly two DELIBERATE rate-limit waits** — so +`ci/check-deps.sh` to prove each structure gate still catches a planted violation: each DepGates +self-test runs only the rule or rules it plants for (`--only `), and only the whole-script +tests, with the one shared run over the real tree, run every rule. That was 661 s of a 1100 s run, +measured 2026-10-01 on a cold lane at load ~5, before those self-tests moved to private tree +copies and a thread pool (175 s after). The lab selftest's **~7 s is mostly two DELIBERATE rate-limit waits** — so a ten-second-plus pause there is the target working, not a hang. (That step also SSDP-probes the LAN to report whether a UPnP gateway is present; still no television, still no lock.) Do not write a new number here: measure it if you need one — this file has already carried a diff --git a/ci/check-deps.sh b/ci/check-deps.sh index 1576294f36..e0b4389980 100755 --- a/ci/check-deps.sh +++ b/ci/check-deps.sh @@ -155,6 +155,88 @@ fails=0 fail() { echo "::error::check-deps: $*"; fails=$((fails+1)); } ok() { echo " ok — $*"; } +# ---- selecting rules --------------------------------------------------------------------------- +# `ci/check-deps.sh` with no argument runs EVERY rule: that is what `make check`, CI and +# ci/check-python-steps.txt run, and nothing but an argument changes it (an environment variable left +# exported in a shell would quietly shrink the gate; an argument cannot be inherited). The gate +# self-tests of tests/test_harness.py prove each rule still catches a planted violation, and each +# used to run the whole script for that, ~25 s of CPU a run and ~70 runs. So: +# ci/check-deps.sh --only blocking,workers run just those rules, the code the full run runs for +# them: their verdict lines, a summary, exit 0 or 1 +# ci/check-deps.sh --list-rules the rule names (RULES below), one a line, no rule run +# A name that is no rule, an empty list, a second --only or any other argument exits 2 before any +# rule runs, so a misspelt selector is an error and never "ran nothing (or less than asked), green". A rule's NAME is what its verdict +# line starts with (`ok — ` / `check-deps: : ...`); `allowlist-counts` is the one rule that +# prints nothing when green. +# +# A rule is a block `if want ; then ... fi # ` (or `want && gate ...`) whose body +# is left at the margin, not indented, so the diff and blame of the rules stay what they were. Inside +# a block, use only what the block itself computes, a shared definition (a function, a constant, a +# pattern) outside every block, or one of the three PRELUDES below, which are computed only when a +# rule that reads them is selected (`any_wanted`; a rule that reads one is named in its list). Under +# `set -u` an unset prelude read inside `$( ... )` kills just that subshell and the rule reads +# green, so a rule that reads a prelude it was not named for is loud, not quiet: `is_wholly_test` +# exits 2 and the others print `unbound variable` on stderr (tests/test_harness.py fails on both). +# RULES must name the `want` calls in order; every run ends by checking that, whatever it selected. +RULES=(browse-owner viewstate-owner person-owner search-owner hubs-owner metadata-owner libm ticks wall + fpflags present effect mutators mutators-visibility nav ui-owner-legacy ui-owner-files owned-damage + owned-wake cards layer sessionwrite uistorage legacypage sibling textmeasure dt ladder hittest frame + sink route fnlen testmod threads blocking workers globals forks fxlanes tmppath paging allowlist-counts) +deps_usage() { + echo "check-deps: $*" >&2 + echo "usage: ci/check-deps.sh [--only RULE[,RULE...] | --list-rules]" >&2 + exit 2 +} +known_rule() { + local r + for r in "${RULES[@]}"; do [ "$r" = "$1" ] && return 0; done + return 1 +} +only="" # ",rule,rule," once --only was given, else empty: every rule +have_only=0 +only_arg="" +while [ $# -gt 0 ]; do + case "$1" in + --list-rules) printf '%s\n' "${RULES[@]}"; exit 0 ;; + --only|--only=*) + # one way to say it: a second --only would overwrite the first and run a smaller set, green + [ "$have_only" -eq 0 ] || deps_usage "--only is given once; join the rules with commas (--only a,b)" + have_only=1 + if [ "$1" = "--only" ]; then + [ $# -ge 2 ] || deps_usage "--only needs a rule list" + only_arg="$2"; shift 2 + else + only_arg="${1#--only=}"; shift + fi ;; + *) deps_usage "unknown argument '$1'" ;; + esac +done +if [ "$have_only" -eq 1 ]; then + [ -n "$only_arg" ] || deps_usage "--only needs at least one rule" + case "$only_arg" in ,*|*,|*,,*) deps_usage "--only '$only_arg' has an empty rule name" ;; esac + IFS=, read -r -a only_names <<< "$only_arg" + for only_rule in "${only_names[@]}"; do + known_rule "$only_rule" || deps_usage "--only names '$only_rule', which is no rule (--list-rules says which are)" + done + only=",$only_arg," +fi +rules_seen="" +# want : is this rule selected? The guard of every rule, always in the main shell. +want() { + known_rule "$1" || { echo "check-deps: internal: want '$1' names no rule of RULES" >&2; exit 2; } + rules_seen="$rules_seen $1" + case "$only" in "") return 0 ;; *",$1,"*) return 0 ;; esac + return 1 +} +# any_wanted ...: is no selector given, or is one of these rules selected? Gates a prelude. +any_wanted() { + local r + for r in "$@"; do known_rule "$r" || { echo "check-deps: internal: any_wanted '$r' names no rule" >&2; exit 2; }; done + [ -z "$only" ] && return 0 + for r in "$@"; do case "$only" in *",$r,"*) return 0 ;; esac; done + return 1 +} + # grep_code : matching lines, minus comment-only lines, as `path:line:text`. grep_code() { local pat="$1"; shift @@ -172,7 +254,10 @@ grep_code() { # filters that list with its real pattern. The verdict and the output are unchanged, but the # prefix alternation must stay a NECESSARY part of every owner pattern, never a loose sample. OWNER_PREFIX='(crate|plx_data)::(browse|viewstate|person|search|pms|metadata)::|stores::(browse|viewstate|person|search|hubs|metadata)::' +# PRELUDE 1 of 3 (see "selecting rules"): computed only when one of the six owner rules is selected. +if any_wanted browse-owner viewstate-owner person-owner search-owner hubs-owner metadata-owner; then OWNER_LINES="$(grep -HrnE --include='*.rs' "$OWNER_PREFIX" "$SRC" "$SRC_DATA" "$SRC_APPKIT" "$SRC_SCREENS" 2>/dev/null || true)" +fi grep_code_owner() { printf '%s\n' "$OWNER_LINES" | grep -E -- "$1" | grep -vE '^[^:]+:[0-9]+:[[:space:]]*//' || true } @@ -272,12 +357,19 @@ wholly_test_files() { # question once per candidate file or line with `echo "$wholly_test" | grep -qxF`, which is two # processes an answer. WHOLLY_TEST_INDEX="" +WHOLLY_TEST_READY=0 wholly_test_index_init() { WHOLLY_TEST_INDEX=" $1 " + WHOLLY_TEST_READY=1 } is_wholly_test() { + # a rule asking before the prelude ran would read an empty index, i.e. "no file is a test file" + [ "$WHOLLY_TEST_READY" -eq 1 ] || { + echo "check-deps: internal: is_wholly_test before the wholly_test prelude (name the rule in its any_wanted list)" >&2 + exit 2 + } case "$WHOLLY_TEST_INDEX" in *" $1 @@ -299,8 +391,13 @@ gate() { } echo "== check-deps ==" +# PRELUDE 2 of 3: the test-module classification, 17 `rust_test_modules.py` runs (~3.7 s of CPU), +# computed only when a rule that reads `$wholly_test` / `is_wholly_test` (directly, or through +# `ledger_scan`) is selected. A run with no selector computes it first, as it always did. +if any_wanted libm mutators cards sink threads blocking workers globals forks fxlanes paging; then wholly_test="$(wholly_test_files)" || { fail "Rust test-module classification failed"; exit 1; } wholly_test_index_init "$wholly_test" +fi # browse-owner: Browse has one physical owner per `Stores`; the migration allowlist ended at zero # and is deliberately gone. Reject both the old storage/selector machinery and every free @@ -472,6 +569,7 @@ owner_declarations() { ' "$file" || echo "$file:0:browse declaration scanner failed" done } +if want browse-owner; then browse_owner_matches=$({ owner_declarations "$browse_facades" 'ACTIVE|LEGACY_ADAPTER|BOOTSTRAP_AVAILABLE' \ 'BrowseState|BrowseAdapter|BrowseStore' "$SRC_DATA/browse/mod.rs" @@ -489,12 +587,14 @@ else echo "$browse_owner_matches" | sed 's/^/ /' fail "browse-owner: retired Browse compatibility surface returned" fi +fi # browse-owner # viewstate-owner: ViewState's physical state, Arc transport and notice live on ViewStateStore. # Zero tolerance, no allowlist: a free facade or storage/transport static can only select process # state, which would silently reconnect separate Bridges and let a retired worker cross reset. viewstate_facades='apply|run|run_with_browse|run_with_owners|pump|pump_with_owners|is_busy|take_landed_views|take_landed|request|request_with_browse|request_with_owners|reset|hold_inflight_for_test|owe_hubs_refresh_for_test|seed_ownership_fixture_for_test|ownership_fixture_for_test|late_completion_for_test|seed_post_reset_flight_for_test' viewstate_selectors='ACTIVE|OWNER|QUEUE|SENT|RETRY_CD|WANT_HUBS|LANDED|MAIL|VIEWSTATE|VIEW_STATE|LEGACY_ADAPTER' +if want viewstate-owner; then viewstate_owner_matches=$({ owner_declarations "$viewstate_facades" "$viewstate_selectors" \ 'ViewStateState|ViewStateAdapter|ViewStateStore|Req|Completion|Done' \ @@ -507,6 +607,7 @@ else echo "$viewstate_owner_matches" | sed 's/^/ /' fail "viewstate-owner: retired ViewState compatibility surface returned" fi +fi # viewstate-owner # person-owner: Person's model/generation/retry/dev seed live in PersonState, its indexed fetch # claims/mailboxes live in the rotated Arc, and both belong to one PersonStore per @@ -514,6 +615,7 @@ fi # owners and lets an unaddressed reset, pump or optimistic edit cross the Bridge boundary. person_facades='current|loading|run|pump|apply|install_for_test|install_source_for_test|install_credits_for_test' person_selectors='ACTIVE|OWNER|CURRENT|GEN|RETRY_CD|FETCH|MAIL|PERSON|PERSON_STATE|LEGACY_ADAPTER|HELD' +if want person-owner; then person_owner_matches=$({ owner_declarations "$person_facades" "$person_selectors" \ 'PersonState|PersonAdapter|PersonStore|Person|Fetch|Mail|Landing' \ @@ -526,6 +628,7 @@ else echo "$person_owner_matches" | sed 's/^/ /' fail "person-owner: retired Person compatibility surface returned" fi +fi # person-owner # search-owner: Search's query/generation/shelf model lives in SearchState, its per-source fetch # claims/mailboxes live in the rotated Arc, and both belong to one SearchStore per @@ -540,6 +643,7 @@ fi # rotates the adapter — only a bare, parameterless global `reset()` would be the retired shape. search_facades='apply|snapshot|snapshot_with_directory|run_with_directory|pump_with_directory|query|state|query_gen|publish_shelves_for_test|settling|debounce_elapsed_for_test' search_selectors='ACTIVE|OWNER|QUERY|GEN|STATE|SHELVES|SRC|ARMED|FAV_GEN|IN_FLIGHT|MAIL|SLOT|SEARCH|SEARCH_STATE|LEGACY_ADAPTER' +if want search-owner; then search_owner_matches=$({ owner_declarations "$search_facades" "$search_selectors" \ 'SearchState|SearchAdapter|SearchStore|Fetch|Projection|Shelf' \ @@ -552,6 +656,7 @@ else echo "$search_owner_matches" | sed 's/^/ /' fail "search-owner: retired Search compatibility surface returned" fi +fi # search-owner # hubs-owner: Home's hub catalog model (`PmsState`) and its rotated worker mailbox/minter # (`Arc`) belong to one `HubsStore` per Bridge (`app/bridge.rs`'s `hubs_run`/ @@ -566,6 +671,7 @@ fi # `state`/`adapter` in, exactly like search's own `reset(state, adapter)`. hubs_facades='apply|apply_with_directory|controlled|controlled_with_directory' hubs_selectors='RESULTS|NEXT_REQUEST|HUB_GEN|CATALOG_GEN|LAST_SECTIONS_GEN|ACTIVE|OWNER|LEGACY_ADAPTER' +if want hubs-owner; then hubs_owner_matches=$({ owner_declarations "$hubs_facades" "$hubs_selectors" \ 'PmsState|PmsAdapter|HubsStore|Landing|Src|SourceBuild' \ @@ -578,6 +684,7 @@ else echo "$hubs_owner_matches" | sed 's/^/ /' fail "hubs-owner: retired Hubs compatibility surface returned" fi +fi # hubs-owner # metadata-owner: Detail's item/season/playing model (`MetadataState`) and its worker adapter # (`Arc`, D3's `record::Tracker` included) belong to one `MetadataStore` per @@ -591,6 +698,7 @@ fi # hubs' and search's own owned stores. metadata_facades='apply' metadata_selectors='DETAIL_LANDING|SEASON_LANDING|ALT_LANDING|NOW|CURRENT|TRACKER|NOTICES' +if want metadata-owner; then metadata_owner_matches=$({ owner_declarations "$metadata_facades" "$metadata_selectors" \ 'MetadataState|MetadataAdapter|MetadataStore|Tracker' \ @@ -603,11 +711,13 @@ else echo "$metadata_owner_matches" | sed 's/^/ /' fail "metadata-owner: retired Metadata compatibility surface returned" fi +fi # metadata-owner # libm: the method-call spelling, OUTSIDE machine/src/motion.rs (which owns the integrators and their # table test); `.log(&…`/`.log("…` is a logger, not a logarithm. # Wholly-test files (see `wholly_test_files`) are skipped like inline `#[cfg(test)]` blocks: a # test's reference colour maths is not logical state. +if want libm; then libm_lines=$(grep_code '\.(exp|ln|log|powf|powi|cbrt|sin|cos|tan|atan2|hypot|mul_add|sin_cos)\(' "$SRC" "$SRC_BASE" "$SRC_MACHINE" "$SRC_PLATFORM" "$SRC_GFX" "$SRC_NET" "$SRC_UI" "$SRC_PLEX" "$SRC_TELEMETRY" "$SRC_DATA" "$SRC_SESSION" "$SRC_MEDIA" "$SRC_PLAYBACK_CONTRACT" "$SRC_PLAY_URI" "$SRC_PLAY_FEED" "$SRC_MEDIA_CODECS" "$SRC_APPKIT" "$SRC_SCREENS" \ | grep -vE '\.log\((&|")' | grep -v "^$SRC_MACHINE/motion.rs:") libm_bad=0 @@ -618,19 +728,28 @@ while IFS= read -r line; do if ! allowed libm "$p"; then echo " $line"; libm_bad=$((libm_bad+1)); fi done <<< "$libm_lines" if [ "$libm_bad" -eq 0 ]; then ok "libm"; else fail "libm: $libm_bad line(s) outside ci/allow/libm.txt"; fi +fi # libm -gate ticks 'SDL_GetTicks\(' "$SRC" "$SRC_BASE" "$SRC_PLATFORM" "$SRC_GFX" "$SRC_NET" "$SRC_UI" "$SRC_PLEX" "$SRC_TELEMETRY" "$SRC_DATA" "$SRC_SESSION" "$SRC_MEDIA" "$SRC_PLAYBACK_CONTRACT" "$SRC_PLAY_URI" "$SRC_PLAY_FEED" "$SRC_MEDIA_CODECS" "$SRC_APPKIT" "$SRC_SCREENS" +want ticks && gate ticks 'SDL_GetTicks\(' "$SRC" "$SRC_BASE" "$SRC_PLATFORM" "$SRC_GFX" "$SRC_NET" "$SRC_UI" "$SRC_PLEX" "$SRC_TELEMETRY" "$SRC_DATA" "$SRC_SESSION" "$SRC_MEDIA" "$SRC_PLAYBACK_CONTRACT" "$SRC_PLAY_URI" "$SRC_PLAY_FEED" "$SRC_MEDIA_CODECS" "$SRC_APPKIT" "$SRC_SCREENS" # Every data/session module is logic unless its exact reviewed IO/instrument file is in ports.ini. +if want wall; then if python3 ci/check-ports.py; then ok "wall"; else fail "wall: outside exact ci/ports.ini files"; fi +fi # wall +if want fpflags; then if grep -rnE 'fp-contract|fast-math|\+fma' rust-modules/Cargo.toml rust-modules/build.rs rust-modules/net/Cargo.toml rust-modules/plex/Cargo.toml rust-modules/telemetry/Cargo.toml rust-modules/data/Cargo.toml rust-modules/session/Cargo.toml rust-modules/media/Cargo.toml rust-modules/appkit/Cargo.toml rust-modules/screens/Cargo.toml rust-modules/platform/Cargo.toml rust-modules/platform/build.rs rust-modules/gfx/Cargo.toml rust-modules/gfx/build.rs rust-modules/ui/Cargo.toml rust-modules/ui/build.rs rust-modules/appkit/build.rs rust-modules/screens/build.rs rust-modules/storage/Cargo.toml rust-modules/storage/build.rs rust-modules/.cargo Makefile 2>/dev/null | grep -v '^[[:space:]]*#'; then fail "fpflags: a floating-point contraction flag is set (spec §4.2 assumes none)" else ok "fpflags"; fi +fi # fpflags +if want present; then n=$(grep -cE '^static [A-Z_]+: Atomic' "$SRC_MACHINE/present.rs"); d=$(grep -c 'pub fn wake_from_worker' "$SRC_MACHINE/present.rs") if [ "$n" -eq 1 ] && [ "$d" -eq 1 ]; then ok "present: one worker door"; else fail "present: $n atomic statics, $d doors (one of each)"; fi +fi # present +if want effect; then if [ -n "$(grep_code '\bEffect::' "$SRC" "$SRC_BASE" "$SRC_MACHINE" "$SRC_PLATFORM" "$SRC_GFX" "$SRC_NET" "$SRC_UI" "$SRC_PLEX" "$SRC_TELEMETRY" "$SRC_DATA" "$SRC_SESSION" "$SRC_MEDIA" "$SRC_PLAYBACK_CONTRACT" "$SRC_PLAY_URI" "$SRC_PLAY_FEED" "$SRC_MEDIA_CODECS" "$SRC_APPKIT" "$SRC_SCREENS")" ]; then fail "effect: \`Effect::\` is spelled (use Fx:: / AppFx::)"; else ok "effect"; fi +fi # effect # mutators: production lines of ui/, screens/ and app/ (everything before the file's first # `#[cfg(test)]` + `mod` pair, which is where every screen keeps its tests) — PLUS, since D3, every @@ -663,6 +782,7 @@ MUTATORS='\b(browse|pms|metadata|search|person|viewstate)::(set_cur|note_library # production lines of ui/detail.rs go unscanned. `stores::::apply(` lines are the new # spelling and are excluded by name; a SCREEN's own `crate::ui::person::open(` is not a store # call and is masked before the match. +if want mutators; then mut_bad=0 while IFS= read -r f; do if is_wholly_test "$f"; then continue; fi @@ -678,6 +798,7 @@ while IFS= read -r f; do # that can produce a hit. done < <(grep -rlE --include='*.rs' "$MUTATORS" "$SRC_UI" "$SRC_MACHINE" "$SRC_APPKIT" "$SRC_SCREENS" "$SRC/app" "$SRC_MEDIA/route" "$SRC_MEDIA/player" "$SRC/dev" 2>/dev/null | sort) if [ "$mut_bad" -eq 0 ]; then ok "mutators"; else fail "mutators: $mut_bad line(s) call a store mutator directly (use the owner's run/step method, e.g. Bridge::_run)"; fi +fi # mutators # mutators-visibility (D3): the call-site rule above can only ever prove "nobody currently calls # this directly" — it says nothing about whether they COULD. This reads the DECLARATION line of @@ -718,6 +839,7 @@ MUT_FNS_TABLE=( store_seamed() { grep -qE "^${1}::${2}( |$)" ci/allow/store-seams.txt 2>/dev/null } +if want mutators-visibility; then vis_bad=0 for entry in "${MUT_FNS_TABLE[@]}"; do relf="${entry%%|*}" @@ -732,15 +854,19 @@ for entry in "${MUT_FNS_TABLE[@]}"; do done done if [ "$vis_bad" -eq 0 ]; then ok "mutators-visibility"; else fail "mutators-visibility: $vis_bad fn(s) still crate-visible"; fi +fi # mutators-visibility -gate nav '(crate::ui|plx_ui)::nav::' "$SRC" "$SRC_UI" "$SRC_APPKIT" "$SRC_SCREENS" +want nav && gate nav '(crate::ui|plx_ui)::nav::' "$SRC" "$SRC_UI" "$SRC_APPKIT" "$SRC_SCREENS" # Completed ownership migration: legacy publications and the old gate cannot return. +if want ui-owner-legacy; then ui_owner_hits=$(grep_code '(plx_ui|crate::ui)::press::|(plx_machine|crate)::idle::' "$SRC" "$SRC_BASE" "$SRC_MACHINE" "$SRC_PLATFORM" "$SRC_GFX" "$SRC_NET" "$SRC_UI" "$SRC_PLEX" "$SRC_TELEMETRY" "$SRC_DATA" "$SRC_SESSION" "$SRC_MEDIA" "$SRC_PLAYBACK_CONTRACT" "$SRC_PLAY_URI" "$SRC_PLAY_FEED" "$SRC_MEDIA_CODECS" "$SRC_APPKIT" "$SRC_SCREENS") if [ -z "$ui_owner_hits" ]; then ok "ui-owner-legacy"; else printf '%s\n' "$ui_owner_hits" fail "ui-owner-legacy: retired global readers must not return" fi +fi # ui-owner-legacy +if want ui-owner-files; then legacy_owners=0 for legacy in "$SRC_UI/nav.rs" "$SRC_UI/press.rs" "$SRC_MACHINE/idle.rs"; do if [ -e "$legacy" ]; then @@ -749,21 +875,26 @@ for legacy in "$SRC_UI/nav.rs" "$SRC_UI/press.rs" "$SRC_MACHINE/idle.rs"; do fi done if [ "$legacy_owners" -eq 0 ]; then ok "ui-owner-files"; fi +fi # ui-owner-files # Motion collectors may not own generic damage or a second process-global notification adapter. +if want owned-damage; then owned_damage_hits=$(grep_code 'motion::report::(invalidate|take_damage|select_damage|take_page_damage|OwnScope)' "$SRC" "$SRC_UI" "$SRC_APPKIT" "$SRC_SCREENS" "$SRC_DATA" "$SRC_PLEX" "$SRC_MEDIA" "$SRC_PLATFORM") report_adapter=$(grep_code '\bAtomic[A-Za-z0-9_]*\b|pub fn (invalidate|take_damage|select_damage|take_page_damage|present_dirty|wake)\b' "$SRC_MACHINE/motion/report.rs") if [ -z "$owned_damage_hits$report_adapter" ]; then ok "owned-damage"; else printf '%s\n%s\n' "$owned_damage_hits" "$report_adapter" fail "owned-damage: presentation changes must reach the owned gate, never a global damage adapter" fi +fi # owned-damage # Main-thread render/deferred work must address its owner; only actual IO workers use the atomic door. +if want owned-wake; then main_wake_hits=$(grep_code 'motion::report::wake|wake_from_worker[[:space:]]*\(' "$SRC_UI" "$SRC/dev" "$SRC/app/run.rs") if [ -z "$main_wake_hits" ]; then ok "owned-wake"; else printf '%s\n' "$main_wake_hits" fail "owned-wake: main-thread work must request PresentEvent::Wake from its owner" fi +fi # owned-wake # cards: a screen's card shelves and grids come from `plx_ui::cards::{Shelf, Grid}` (the # shared-card-sections plan, layer L1), which own the pop, press, stops, restore and paging a @@ -781,6 +912,7 @@ fi # allowlist (empty) is the screens that still assemble their own, one line per file, and only # SHRINKS. cards_pat='cards::(paint_visible|draw_tile|draw_focused)\b|use [^;]*cards::\{[^}]*\b(paint_visible|draw_tile|draw_focused)\b|\bCardRow\b|\bGridPop\b|\bGridBands\b|press::scale\(\)' +if want cards; then cards_bad=0 while IFS= read -r line; do [ -z "$line" ] && continue @@ -795,6 +927,7 @@ while IFS= read -r line; do echo " $line"; cards_bad=$((cards_bad+1)) done < <(grep_code '\bAvatarRow\b' "$SRC_SCREENS") if [ "$cards_bad" -eq 0 ]; then ok "cards"; else fail "cards: $cards_bad line(s) outside ci/allow/cards.txt (or AvatarRow outside profiles.rs) — draw card sections with plx_ui::cards::Shelf / Grid"; fi +fi # cards # layer: a SCREEN never names the application. §2.1's table says `screens/` may name `ui/`, # `stores/`, `plex/` and `player/` and never `app/`, and until phase 10 that half of the rule was @@ -805,24 +938,28 @@ if [ "$cards_bad" -eq 0 ]; then ok "cards"; else fail "cards: $cards_bad line(s) # and nothing else) is only worth as much as the boundary underneath it. Count is zero, with no # allowlist: a screen that needs something of the loop's asks for it as an effect (`AppFx`, # `LoopReq`) — that is what the bundle in `registry.rs` is. +if want layer; then if [ -n "$(grep_code '(crate|super)::app::' "$SRC_SCREENS")" ]; then grep_code '(crate|super)::app::' "$SRC_SCREENS" | sed 's/^/ /' fail "layer: a screen names the application (§2.1) — ask for it as an AppFx/LoopReq instead" else ok "layer"; fi -gate sessionwrite 'session::load\(' "$SRC_SCREENS" "$SRC_UI" "$SRC_MACHINE" "$SRC_APPKIT" +fi # layer +want sessionwrite && gate sessionwrite 'session::load\(' "$SRC_SCREENS" "$SRC_UI" "$SRC_MACHINE" "$SRC_APPKIT" # uistorage: the LIBRARY (`ui/`) never names the storage layer (§2.1: `ui/` may name only # `crate::{gfx,text,paths,task}`). A ui-owned sweep that needs the app's removal rule takes it as an # injected `fn` (`ui::rec::erase_owned_artifacts`). Zero, no allowlist. The wider table is not a # grep yet: ui/ still names other application modules, mostly from tests and dev instruments. -gate uistorage '(crate|super|plx_platform)::storage::' "$SRC_UI" "$SRC_MACHINE" +want uistorage && gate uistorage '(crate|super|plx_platform)::storage::' "$SRC_UI" "$SRC_MACHINE" # legacypage: the word itself, anywhere under src — a doc that still describes the type is as much # a hit as a declaration, which is the point (nothing compiles the prose either). +if want legacypage; then legacy_hits=$(grep -rn --include='*.rs' 'LegacyPage' "$SRC" "$SRC_BASE" "$SRC_MACHINE" "$SRC_PLATFORM" "$SRC_GFX" "$SRC_NET" "$SRC_UI" "$SRC_PLEX" "$SRC_TELEMETRY" "$SRC_DATA" "$SRC_SESSION" "$SRC_MEDIA" "$SRC_PLAYBACK_CONTRACT" "$SRC_PLAY_URI" "$SRC_PLAY_FEED" "$SRC_MEDIA_CODECS" "$SRC_APPKIT" "$SRC_SCREENS" 2>/dev/null || true) if [ -z "$legacy_hits" ]; then ok "legacypage"; else echo "$legacy_hits" | sed 's/^/ /' fail "legacypage: $(echo "$legacy_hits" | wc -l | tr -d ' ') mention(s) — the type is retired (§15.2)" fi +fi # legacypage # sibling: one screen family per directory; `` is the first path component under screens/. # @@ -832,6 +969,7 @@ fi # gate that forbade it would forbid the structure the spec asks for. It was an allowlist entry # until phase 10 moved the mounter into it; an entry would have had to say "this file names all of # them, permanently", which is a rule and not a migration. +if want sibling; then sib_bad=0 while IFS= read -r f; do [ "$f" = "$SRC_SCREENS/registry.rs" ] && continue @@ -849,6 +987,7 @@ while IFS= read -r f; do done < <(grep -rlE --include='*.rs' 'crate::[a-z_]+' "$SRC_SCREENS" 2>/dev/null | sort) if [ "$sib_bad" -eq 0 ]; then ok "sibling" else fail "sibling: $sib_bad file(s) name a sibling screen (use crate::registry)"; fi +fi # sibling # ============================================================================================ # Phase 12 rules (spec §15.2, D4): the gates the earlier phases' own comments above never wrote, @@ -878,6 +1017,7 @@ else fail "sibling: $sib_bad file(s) name a sibling screen (use crate::registry) # `impl Measure for` added later still only exempts ITS OWN body, and any other raw call anywhere # in the tree fails. tm_seams="$SRC_UI/text_view.rs $SRC_UI/text_buffer.rs $SRC_GFX/text.rs" +if want textmeasure; then tm_bad=0 while IFS= read -r f; do is_seam=0 @@ -895,6 +1035,7 @@ while IFS= read -r f; do # an `impl … Measure for …` block, so a file with no raw call has nothing for it to find. done < <(grep -rlE --include='*.rs' '(crate|plx_gfx)::text::(text_width|elide|cap_h)\(' "$SRC" "$SRC_GFX" "$SRC_UI" "$SRC_APPKIT" "$SRC_SCREENS" 2>/dev/null | sort) if [ "$tm_bad" -eq 0 ]; then ok "textmeasure"; else fail "textmeasure: $tm_bad line(s) outside the Measure seam"; fi +fi # textmeasure # dt (phase 12, D4 — ZERO now, was an allowlist): idle::dt() (deleted from machine/src/idle.rs entirely — # card_row.rs's focused-title marquee, its last caller, now reads the absolute idle::now_ms() @@ -906,11 +1047,13 @@ if [ "$tm_bad" -eq 0 ]; then ok "textmeasure"; else fail "textmeasure: $tm_bad l # class this whole gate exists to catch. motion.rs currently has no hit either; the exclusion is # the documented intent (spec §4.2: the ONLY file licensed to touch a raw per-frame delta), not a # live carve-out. +if want dt; then dt_hits=$(grep_code 'idle::dt\(\)|(\+=|-=)\s*dt\b' "$SRC" "$SRC_MACHINE" "$SRC_PLATFORM" "$SRC_GFX" "$SRC_NET" "$SRC_UI" "$SRC_PLEX" "$SRC_TELEMETRY" "$SRC_DATA" "$SRC_SESSION" "$SRC_MEDIA" "$SRC_PLAYBACK_CONTRACT" "$SRC_PLAY_URI" "$SRC_PLAY_FEED" "$SRC_MEDIA_CODECS" "$SRC_APPKIT" "$SRC_SCREENS" | grep -v "^$SRC_MACHINE/motion.rs:") if [ -z "$dt_hits" ]; then ok "dt"; else echo "$dt_hits" | sed 's/^/ /' fail "dt: $(echo "$dt_hits" | wc -l | tr -d ' ') line(s) — see rule comment above" fi +fi # dt # ladder: the old per-screen focus/hit ladder shape, zero across ui/ + screens/ once every Screen # answers FocusSource::Engine/HitSource::Engine (D2). No allowlist: every remaining hit is a @@ -923,13 +1066,13 @@ gate_zero() { fail "$rule: $(echo "$hits" | wc -l | tr -d ' ') line(s) — see rule comment above" fi } -gate_zero ladder 'fn move_focus|fn pointer_focus|fn top_focus|fn zones\b|fn key\(sym|fn focus_is_card|fn focus_is_ctl' "$SRC_UI" "$SRC_MACHINE" "$SRC_APPKIT" "$SRC_SCREENS" +want ladder && gate_zero ladder 'fn move_focus|fn pointer_focus|fn top_focus|fn zones\b|fn key\(sym|fn focus_is_card|fn focus_is_ctl' "$SRC_UI" "$SRC_MACHINE" "$SRC_APPKIT" "$SRC_SCREENS" # hittest: the narrowed raw hit-tester call shape, zero in app/ once the player's HUD registers # its stops through DrawFrame::stop (D2) instead of app/run.rs testing raw coordinates against # player_hud's geometry by hand. Deliberately NOT a blanket `_at(` — that false-positives on # resume_at/memory_at/open_settings_at/write_at, which are unrelated lookups. -gate_zero hittest 'pointer_focus\(|\b(failure_quality|icon|scrub)_hit\(' "$SRC/app" +want hittest && gate_zero hittest 'pointer_focus\(|\b(failure_quality|icon|scrub)_hit\(' "$SRC/app" # frame: the three privileged OS-primitive calls, ZERO-TOLERANCE outside `app/run.rs` (D4) — no # allowlist file, because there is exactly one legitimate home once D1 lands: `app/run.rs` is the @@ -946,6 +1089,7 @@ gate_zero hittest 'pointer_focus\(|\b(failure_quality|icon|scrub)_hit\(' "$SRC/a # actual call typed outside a string still fails this gate. `// `-prefixed comment lines (`app/run.rs` keeps one, describing where a call # used to live) are stripped the same way `grep_code` above does for every other rule. frame_pat='(crate|plx_platform)::tv::window::(pump_bus|opaque_route|clear_opaque_region)\(' +if want frame; then frame_bad=0 while IFS= read -r f; do [ "$f" = "$SRC/app/run.rs" ] && continue @@ -964,6 +1108,7 @@ while IFS= read -r f; do done < <(grep -rlE --include='*.rs' "$frame_pat" "$SRC" "$SRC_BASE" "$SRC_MACHINE" "$SRC_PLATFORM" "$SRC_GFX" "$SRC_NET" "$SRC_UI" "$SRC_PLEX" "$SRC_TELEMETRY" "$SRC_DATA" "$SRC_SESSION" "$SRC_MEDIA" "$SRC_PLAYBACK_CONTRACT" "$SRC_PLAY_URI" "$SRC_PLAY_FEED" "$SRC_MEDIA_CODECS" "$SRC_APPKIT" "$SRC_SCREENS" 2>/dev/null | sort) if [ "$frame_bad" -eq 0 ]; then ok "frame" else fail "frame: $frame_bad line(s) of a privileged OS-primitive call outside app/run.rs"; fi +fi # frame # sink: the Starfish/ACB verbs (`tv::sink::VideoSink`) are the player's alone (step L15). Only # `player/`, `play-uri/`, the native `webos/` port, and `port.rs` (which installs one) @@ -972,6 +1117,7 @@ else fail "frame: $frame_bad line(s) of a privileged OS-primitive call outside a # ACB plane's boot and hands it on (it was `player/plane_boot.rs`; the composition root is where the # driver set is built). Every other module reaches the television through the narrower `tv` interfaces. Wholly-test files are skipped like inline # `#[cfg(test)]` blocks. Zero, no allowlist. +if want sink; then sink_bad=0 while IFS= read -r line; do [ -z "$line" ] && continue @@ -987,9 +1133,11 @@ while IFS= read -r line; do done < <(grep_code 'tv::sink::(installed|display_installed)|\b(VideoSink|DisplaySink)\b' "$SRC" "$SRC_PLATFORM" "$SRC_UI" "$SRC_MEDIA" "$SRC_PLAYBACK_CONTRACT" "$SRC_PLAY_URI" "$SRC_PLAY_FEED" "$SRC_MEDIA_CODECS" "$SRC_APPKIT" "$SRC_SCREENS") if [ "$sink_bad" -eq 0 ]; then ok "sink" else fail "sink: $sink_bad line(s) naming the video sink outside playback execution, port.rs, tv.rs and tv/"; fi +fi # sink # route: `Route::` in app/ = 0, and `enum Route` gone from the whole tree (D1/D4). No allowlist: # the type is meant to be retired, not narrowed. +if want route; then route_app=$(grep_code 'Route::' "$SRC/app") if [ -z "$route_app" ]; then ok "route: Route:: in app/" else fail "route: $(echo "$route_app" | wc -l | tr -d ' ') \`Route::\` use(s) in app/ — the page alphabet is \`AppArg\` (D1)"; fi @@ -999,6 +1147,7 @@ else echo "$route_enum" | sed 's/^/ /' fail "route: enum Route re-declared — the page alphabet is \`AppArg\` (D1)" fi +fi # route # fnlen: app/run.rs::run <= 200 lines, run_application (app/mod.rs, the D4 skeleton) <= 10 and # plex_run (port.rs: install, then hand over) <= 10 — counted by brace @@ -1014,6 +1163,7 @@ fn_body_lines() { } ' "$file" } +if want fnlen; then run_len=$(fn_body_lines "$SRC/app/run.rs" 'run') if [ -n "$run_len" ] && [ "$run_len" -le 200 ]; then ok "fnlen: app/run.rs::run ($run_len lines)" else fail "fnlen: app/run.rs::run is ${run_len:-unknown} lines, budget 200 — a phase of the frame belongs in its own function (see run.rs's own doc)"; fi @@ -1023,14 +1173,17 @@ else fail "fnlen: run_application (app/mod.rs) is ${runapp_len:-unknown} lines, plexrun_len=$(fn_body_lines "$SRC/port.rs" 'plex_run') if [ -n "$plexrun_len" ] && [ "$plexrun_len" -le 10 ]; then ok "fnlen: plex_run (port.rs) ($plexrun_len lines)" else fail "fnlen: plex_run (port.rs) is ${plexrun_len:-unknown} lines, budget 10"; fi +fi # fnlen # testmod: `#[cfg(test)] mod` count in app/mod.rs = 0 (D4/D8) — every test module named in D8's # table is meant to have moved to its subject's own file by the time this gate is added. +if want testmod; then testmod_n=$(grep -c '^#\[cfg(test)\]$' "$SRC/app/mod.rs" 2>/dev/null || echo 0) # only count ones immediately followed by `mod `, matching the mutators gate's own convention testmod_n=$(awk '/^#\[cfg\(test\)\]$/{p=1;next} p && /^mod /{c++} {p=0} END{print c+0}' "$SRC/app/mod.rs") if [ "$testmod_n" -eq 0 ]; then ok "testmod: app/mod.rs" else fail "testmod: $testmod_n \`#[cfg(test)] mod\` block(s) in app/mod.rs — a test lives beside its subject (D8)"; fi +fi # testmod # threads: `thread::spawn(` outside task.rs, PRODUCTION lines only, EVERY spelling — a # `#[cfg(test)] mod` block is skipped by brace depth, the same convention the `mutators` gate @@ -1049,6 +1202,7 @@ else fail "testmod: $testmod_n \`#[cfg(test)] mod\` block(s) in app/mod.rs — a # `use std::thread::{..spawn..}` lines outside task.rs itself), so this spelling adds nothing # to the count yet — it exists so a FUTURE import cannot go unmatched the way the bare # `thread::spawn(` spelling used to. +if want threads; then threads_bad=0 while IFS= read -r f; do # a wholly-test file is test code exactly like an inline `#[cfg(test)] mod` block, which the @@ -1071,6 +1225,7 @@ done < <(grep -rlE --include='*.rs' '\bspawn\(' "$SRC" "$SRC_BASE" "$SRC_MACHINE threads_declared=$(sed -n 's/^# count: *//p' ci/allow/threads.txt | head -1) if [ "$threads_bad" -eq "${threads_declared:-0}" ]; then ok "threads" else fail "threads: $threads_bad line(s) outside ci/allow/threads.txt (declared count is exactly ${threads_declared:-0}, not a ceiling)"; fi +fi # threads # ---- the ledger rules: blocking, workers, globals, forks, fxlanes ------------------------------- # A LEDGER is an exact multiset of production SITES, one line per site, held under ci/allow and only @@ -1209,6 +1364,7 @@ EOF_STALE # The enclosing fn is the innermost `fn ` whose body holds the call, tracked by # brace depth; a call in a closure belongs to the fn around the closure. The scan is the shared # `ci/ledger.awk` (the ledger machinery above). +if want blocking; then blocking_sites=$( grep -rlE --include='*.rs' 'allow_blocking' "$SRC" "$SRC_BASE" "$SRC_MACHINE" "$SRC_PLATFORM" "$SRC_GFX" "$SRC_NET" "$SRC_UI" "$SRC_PLEX" "$SRC_TELEMETRY" "$SRC_DATA" "$SRC_SESSION" "$SRC_MEDIA" "$SRC_PLAYBACK_CONTRACT" "$SRC_PLAY_URI" "$SRC_PLAY_FEED" "$SRC_MEDIA_CODECS" "$SRC_APPKIT" "$SRC_SCREENS" 2>/dev/null \ | grep -v "^$SRC_BASE/task/blocking.rs\$" | sort \ @@ -1224,6 +1380,7 @@ LG_LEDGERS=ci/allow/blocking.txt LG_COUNT_FILE=ci/allow/blocking.txt \ LG_NOUN='the frame-thread exception ledger' \ LG_TAIL='a new allow_blocking site moves its work to a worker instead; the list only shrinks' \ ledger_check blocking "$blocking_sites" +fi # blocking # ---- the Sans-IO ledgers (docs/sans-io.md): workers, globals, forks, fxlanes ------------------------ # The rule they prepare: logic never performs IO. A MACHINE (a screen, a data/ store, the session @@ -1268,6 +1425,8 @@ globals_pat='client_for|current_server|current_snapshot|keypin::(revision|blocke # candidate: an item under it is skipped whole. forks_pat='cfg.*test|test.*cfg|#!?\[cfg\([^]]*$|cfg!\([^)]*$' forks_plain_re='^[[:space:]]*#\[cfg\((test|any\(test, feature = "test-support"\)|all\((test|any\(test, feature = "test-support"\)), [^()]*\))\)\][[:space:]]*$' +# PRELUDE 3 of 3: computed only when workers, globals or forks is selected. +if any_wanted workers globals forks; then ledger_hits=$( find "$SRC_DATA" "$SRC_SESSION" "$SRC_PLEX" "$SRC_MEDIA" "$SRC_PLAYBACK_CONTRACT" "$SRC_PLAY_URI" "$SRC_PLAY_FEED" "$SRC_MEDIA_CODECS" "$SRC_SCREENS" "$SRC_UI" "$SRC_APPKIT" "$SRC_MACHINE" "$SRC_PLATFORM/tv/plane.rs" \ -name '*.rs' -type f 2>/dev/null \ @@ -1283,6 +1442,7 @@ ledger_hits=$( !df && $0 ~ f && $0 !~ p { print "F\t" FILENAME; df = 1 } ' ) +fi # ledger_candidates : the files of that rule's scope the prefilter kept ledger_candidates() { printf '%s\n' "$ledger_hits" | awk -F'\t' -v r="$1" '$1 == r { print $2 }' | sort -u @@ -1299,6 +1459,7 @@ ledger_candidates() { # although no machine calls it today, because a machine that did would be starting a worker. A worker # named without a call (`.map(spawn_small)`) is a site too; only a rename (`use ... as`) is refused, # because the renamed calls are invisible. +if want workers; then workers_sites=$( ledger_candidates W \ | LG_MODE=call LG_KEYSPELL=1 LG_USE_OK=1 LG_REF_USE_ONLY=1 \ @@ -1315,6 +1476,7 @@ LG_LEDGERS="$(echo ci/allow/workers/*.txt)" LG_AREA_CHECK=1 \ LG_NOUN='the worker-start ledger' \ LG_TAIL='a machine starts no worker: its work leaves as a typed effect the app runs (docs/sans-io.md); the ledgers only shrink' \ ledger_check workers "$workers_sites" +fi # workers # globals: a production read of a process-global registry in a MACHINE — `client_for(`, `current_server(`, # `current_snapshot(`, `keypin::revision(`, `keypin::blocked_for(`, `session::peek(`, `grant::offers(`, the @@ -1358,6 +1520,7 @@ LG_LEDGERS="$(echo ci/allow/workers/*.txt)" LG_AREA_CHECK=1 \ # a call (`.and_then(client_for)`) reads the registry as surely as a call does, so it is a site too; only a # rename (`use ... as`) is refused, because the renamed calls are invisible. Each getter's own definition is # not a site. +if want globals; then globals_sites=$( { ledger_candidates G printf '%s\n' rust-modules/plex/src/plex/session.rs "$SRC_MEDIA/player/lifecycle.rs"; } \ @@ -1376,6 +1539,7 @@ LG_LEDGERS="$(echo ci/allow/globals/*.txt)" LG_AREA_CHECK=1 \ LG_NOUN='the process-global read ledger' \ LG_TAIL='a machine reads no registry: the value arrives in an event or an argument (docs/sans-io.md); the ledgers only shrink' \ ledger_check globals "$globals_sites" +fi # globals # forks: a production test/production fork across every machine crate (FORK_SCOPE: all of data/, plex/, media/, # session/, screens/, ui/, appkit/ and machine/) — a `#[cfg(..)]` @@ -1390,6 +1554,7 @@ LG_LEDGERS="$(echo ci/allow/globals/*.txt)" LG_AREA_CHECK=1 \ # it) — never a line number. A file can # hold a fork only if it has a cfg line that is not a plain test-only attribute (an item under one is # skipped whole), which is what the candidates are. +if want forks; then forks_sites=$( ledger_candidates F \ | LG_MODE=fork ledger_scan | sort @@ -1401,6 +1566,7 @@ LG_LEDGERS="$(echo ci/allow/forks/*.txt)" LG_AREA_CHECK=1 \ LG_NOUN='the test/production fork ledger' \ LG_TAIL='logic has no cfg(test) fork: the seam is a typed effect tests and replay deliver events through (docs/sans-io.md); the ledgers only shrink' \ ledger_check forks "$forks_sites" +fi # forks # fxlanes: in `Bridge::app_effect` every `AppFx::` arm either pushes `Fx::Deliver(` — the ordered # FIFO, where a result returns as one addressed event in the same drain — or is a ledger line: an arm that @@ -1408,6 +1574,7 @@ LG_LEDGERS="$(echo ci/allow/forks/*.txt)" LG_AREA_CHECK=1 \ # own timing. A NEW variant with a side queue fails; so does a new arm that is not on the FIFO. Keyed # `::AppFx::`, one line for EACH variant on an arm's head (`AppFx::A(r) | AppFx::B(r) => ..` # is two), and `::AppFx::_` for an arm whose head names none (`other => ..`, `_ => ..`). +if want fxlanes; then fxlanes_sites=$( grep -rlE --include='*.rs' 'fn app_effect' "$SRC" 2>/dev/null | sort \ | LG_MODE=arm LG_ARM_FN=app_effect LG_ARM_MATCH='(^|[^A-Za-z0-9_])match[[:space:]]+fx[[:space:]]*\{' LG_ARM_OK='Fx::Deliver\(' \ @@ -1420,6 +1587,7 @@ LG_LEDGERS="$(echo ci/allow/fxlanes/*.txt)" LG_AREA_CHECK=1 \ LG_NOUN='the Bridge::app_effect lane ledger' \ LG_TAIL='an AppFx arm pushes Fx::Deliver(..) onto the one ordered FIFO instead of a side queue (docs/sans-io.md); the ledgers only shrink' \ ledger_check fxlanes "$fxlanes_sites" +fi # fxlanes # tmppath: a literal `/tmp/plxnative-` string outside dev.rs and the log sinks, = 0 (D4). The # earlier version matched only a literal and a filesystem-open VERB co-occurring on the SAME @@ -1445,6 +1613,7 @@ LG_LEDGERS="$(echo ci/allow/fxlanes/*.txt)" LG_AREA_CHECK=1 \ # path through `paths::in_runtime_dir("plxnative-…")`, a bare filename with no `/tmp/` prefix, so # neither one is a `/tmp/plxnative-` literal in the first place and there is no second file to # name here (re-verify this if a log sink is ever given a hardcoded `/tmp/` path). +if want tmppath; then tmp_hits=$(python3 - "$SRC" "$SRC_BASE" "$SRC_MACHINE" "$SRC_PLATFORM" "$SRC_GFX" "$SRC_NET" "$SRC_UI" "$SRC_PLEX" "$SRC_TELEMETRY" "$SRC_DATA" "$SRC_SESSION" "$SRC_MEDIA" "$SRC_PLAYBACK_CONTRACT" "$SRC_PLAY_URI" "$SRC_PLAY_FEED" "$SRC_MEDIA_CODECS" "$SRC_APPKIT" "$SRC_SCREENS" <<'PY' import os, sys @@ -1536,6 +1705,7 @@ else echo "$tmp_hits" | sed 's/^/ /' fail "tmppath: $(echo "$tmp_hits" | grep -c . ) line(s) of a literal /tmp/plxnative- path outside dev.rs, not comment or log-message text" fi +fi # tmppath # paging: the two Plex paging parameter names are spelled in ONE non-test file, the `paged_path` @@ -1544,6 +1714,7 @@ fi # not counted (they cannot build a request), and test code is: whole test files (the `wholly_test` # classification above) and `#[cfg(test)]` items, found from tokens so a literal inside a string is # never mistaken for a comment. Zero, no allowlist. Scans every crate root, not only plex's. +if want paging; then paging_hits=$(WHOLLY_TEST="$wholly_test" python3 - "$SRC" "$SRC_BASE" "$SRC_MACHINE" "$SRC_PLATFORM" "$SRC_GFX" "$SRC_NET" "$SRC_UI" "$SRC_PLEX" "$SRC_TELEMETRY" "$SRC_DATA" "$SRC_SESSION" "$SRC_MEDIA" "$SRC_PLAYBACK_CONTRACT" "$SRC_PLAY_URI" "$SRC_PLAY_FEED" "$SRC_MEDIA_CODECS" "$SRC_APPKIT" "$SRC_SCREENS" <<'PY' import os, sys sys.path.insert(0, "ci") @@ -1609,15 +1780,23 @@ else echo "$paging_hits" | sed 's/^/ /' fail "paging: $(echo "$paging_hits" | grep -c . ) production literal(s) spell X-Plex-Container- outside rust-modules/plex/src/plex/paging.rs (use paged_path)" fi +fi # paging # every allowlist's declared count equals its entries — the flat lists, and the per-area ledger files # under ci/allow// (workers, globals, forks, fxlanes) +if want allowlist-counts; then for f in ci/allow/*.txt ci/allow/*/*.txt; do [ -f "$f" ] || continue declared=$(sed -n 's/^# count: *//p' "$f" | head -1) entries=$(grep -cvE '^[[:space:]]*(#|$)' "$f") [ "$declared" = "$entries" ] || fail "$f declares count $declared but has $entries entries" done +fi # allowlist-counts +# RULES and the `want` calls above must name the same rules in the same order, whatever was selected +# (every guard is visited whether or not its rule runs): a rule outside RULES cannot be selected by +# name, and a name without a guard would be "selected" and run nothing. +[ "$rules_seen" = " ${RULES[*]}" ] || fail "RULES and the want guards disagree: RULES is [${RULES[*]}], the guards are [${rules_seen# }]" +if [ -n "$only" ] && [ "$fails" -eq 0 ]; then echo "check-deps: the selected gates are green (--only $only_arg)"; exit 0; fi [ "$fails" -eq 0 ] && { echo "check-deps: all gates green"; exit 0; } echo "check-deps: $fails gate(s) failed"; exit 1 diff --git a/ci/check-ports.py b/ci/check-ports.py index 9569a27baf..f37a9e32de 100644 --- a/ci/check-ports.py +++ b/ci/check-ports.py @@ -55,7 +55,9 @@ def ports(root, ini): # `.elapsed(`, and the alias test needs the token `Instant` or `SystemTime`. A file without any of # them cannot hold a wall-clock operation, so this rule does not lex or classify it: lexing the # ~690 files of the scopes (and the wholly-test classification of every scope) was most of this -# gate's 4.6 s of CPU, run once per `ci/check-deps.sh` and so ~100 times by tests/test_harness.py. +# gate's 4.6 s of CPU, run once per `ci/check-deps.sh` that selects `wall` (every full run; the +# harness's gate self-tests run only the rule they plant for, so only its whole-script tests and +# its every-rule sweep, which runs `--only wall` too, run it). # The skip changes what an UNLEXABLE file does here, never what a wall site does: a file with no # wall word and an unterminated raw string no longer fails THIS rule. `ci/check-list-caps.py` (a step # of ci/check-python-steps.txt) reports it instead: it runs `rtm.lex` over every production file under diff --git a/tests/test_harness.py b/tests/test_harness.py index bec1db99a2..c8fe95c038 100644 --- a/tests/test_harness.py +++ b/tests/test_harness.py @@ -8593,6 +8593,61 @@ def test_opt_out_and_a_cumulative_counter(self): # ends it: a `DepGates` test still running on the pool then starts no further gate run. _run_stopped = threading.Event() +# A rule of `ci/check-deps.sh` that prints nothing when it passes (`ci/check-deps.sh --list-rules` +# names every rule; `test_every_rule_is_selectable_and_nothing_else_reports` pins this set). +_DEPS_RULES_SILENT_WHEN_GREEN = frozenset({"allowlist-counts"}) + + +def _grades(*rules): + """The rules of `ci/check-deps.sh` a `DepGates` test runs: its self-test plants ONE violation, so + it runs the script with `--only ` (a few seconds) rather than every rule (~25 s of + CPU a run, which was ~70 runs and nine tenths of this module). Name the rule or rules whose + verdict the test asserts. `_run_check_deps` then refuses a run in which one of them printed no + verdict, and `_assert_flagged` refuses a rule the test did not select, so a test that selects + the wrong rule fails instead of passing against a rule that never ran.""" + assert rules and len(set(rules)) == len(rules), rules + + def mark(test): + test.deps_rules = rules + return test + return mark + + +def _grades_whole_script(test): + """For a `DepGates` test that grades `ci/check-deps.sh` as a whole (it reads the exit code or + the summary of every rule), not one planted violation: it runs every rule.""" + test.deps_rules = None + return test + + +def _check_deps_verdict(r, rules): + """`r`, a finished `ci/check-deps.sh` run that selected `rules` (None: all), if it is a verdict. + + It must exit 0 or 1 (2 is a usage or internal error), may not trip `set -u` (an unset prelude + read inside `$( ... )` kills only that subshell and its rule reads green), and must print a + verdict line for EVERY selected rule, so a selection that ran nothing, or not the rule the test + is about, is a failure here and not a quiet pass. The result carries `deps_rules`.""" + out = r.stdout + r.stderr + if r.returncode not in (0, 1): + raise AssertionError(f"ci/check-deps.sh exited {r.returncode}, which is no verdict\n{out}") + if "unbound variable" in r.stderr: + raise AssertionError(f"ci/check-deps.sh read an unset variable (a rule reading a prelude it was not named for?)\n{out}") + for rule in rules or (): + if rule in _DEPS_RULES_SILENT_WHEN_GREEN: + continue + if not re.search(rf"^( ok — |::error::check-deps: ){re.escape(rule)}(?=[ :(]|$)", r.stdout, re.M): + raise AssertionError(f"--only {rule} printed no verdict line for {rule}\n{out}") + r.deps_rules = rules + return r + + +def _run_check_deps(root, rules): + """Run `root`'s `ci/check-deps.sh`: every rule when `rules` is None, else `--only `.""" + cmd = [os.path.join(root, "ci", "check-deps.sh")] + if rules is not None: + cmd += ["--only", ",".join(rules)] + return _check_deps_verdict(subprocess.run(cmd, capture_output=True, text=True), rules) + class DepGates(unittest.TestCase): """Restructure spec §15.2: `ci/check-deps.sh` is green, and every allowlist under ci/allow/ @@ -8657,7 +8712,7 @@ class DepGates(unittest.TestCase): @property def tree(self): """The private copy of the gate's inputs. Every gate run builds its command from this, so a - stopped run (`_run_stopped`) raises here instead of starting one more ~11 s `check-deps.sh`: + stopped run (`_run_stopped`) raises here instead of starting one more `check-deps.sh` run: the one `make check`'s stop signal never reached would outlive its 10 s grace and be SIGKILLed with the copy still on disk.""" if _run_stopped.is_set(): @@ -8697,17 +8752,131 @@ def run(self, result=None): def _real_tree(cls): """One run of the gate over the CHECKOUT, shared by the two tests that read it. Nothing in this class edits the checkout (`test_self_tests_never_touch_the_real_tree`), so the second - reader would only repeat the first's ~25 s of CPU.""" + reader would only repeat the first's ~25 s of CPU (every rule runs).""" with cls._real_tree_lock: if cls._real_tree_run is None: - cls._real_tree_run = subprocess.run([os.path.join(cls.ROOT, "ci", "check-deps.sh")], - capture_output=True, text=True) + cls._real_tree_run = _run_check_deps(cls.ROOT, None) return cls._real_tree_run + def _deps(self): + """THE way a test runs `ci/check-deps.sh` over its private copy (every helper below ends here): + the rules its `_grades(...)` names, or all of them for `_grades_whole_script`. A test that + declares neither fails here, so none runs the whole script by default or a subset by accident.""" + test = getattr(type(self), self._testMethodName) + if not hasattr(test, "deps_rules"): + raise AssertionError(f"{self._testMethodName} runs ci/check-deps.sh without saying which rules it " + "grades: decorate it with @_grades(...) or @_grades_whole_script") + return _run_check_deps(self.tree, test.deps_rules) + def test_check_deps_is_green(self): r = self._real_tree() self.assertEqual(r.returncode, 0, r.stdout + r.stderr) + def _rule_names(self, root): + r = subprocess.run([os.path.join(root, "ci", "check-deps.sh"), "--list-rules"], capture_output=True, text=True) + self.assertEqual((r.returncode, r.stderr), (0, ""), r.stdout) + return r.stdout.split() + + def test_every_rule_is_selectable_and_nothing_else_reports(self): + """The full run reports exactly the rules `--list-rules` names (in that order), so no rule can + sit outside the selector: a rule that prints a verdict but has no `want` guard (it would run + in every `--only` run and could never be selected) or a name with no rule behind it fails + here. The one rule that prints nothing when green is `_DEPS_RULES_SILENT_WHEN_GREEN`.""" + known = self._rule_names(self.ROOT) + self.assertEqual(len(known), len(set(known)), known) + self.assertTrue(_DEPS_RULES_SILENT_WHEN_GREEN <= set(known), known) + reported = [] + for name in re.findall(r"^ ok — ([a-z][a-z-]*)(?=[ :(]|$)", self._real_tree().stdout, re.M): + if name not in reported: + reported.append(name) + self.assertEqual(reported, [n for n in known if n not in _DEPS_RULES_SILENT_WHEN_GREEN]) + + def test_every_rule_prints_the_same_alone_as_in_the_full_run(self): + """Each rule run ALONE (`--only `) prints exactly the lines the full run printed for it, + and nothing to stderr. A rule block that leans on a variable another rule's block computed + (a "trapped definition"), or on a prelude it was not named for, reads an unset variable + inside `$( ... )` and reports green, which only a run of that rule by itself shows; an + unguarded block shows as an extra line. The rules run on a small pool inside this test.""" + full = self._real_tree().stdout.splitlines() + self.assertEqual(full[0], "== check-deps ==") + segments, pending = {}, [] + for line in full[1:-1]: + pending.append(line) + m = re.match(r" ok — ([a-z][a-z-]*)(?=[ :(]|$)", line) + if m: + segments.setdefault(m.group(1), []).extend(pending) + pending = [] + self.assertEqual((pending, full[-1]), ([], "check-deps: all gates green")) # `wall`'s own line is in its segment + rules = self._rule_names(self.ROOT) + + def alone(rule): + try: + return rule, _run_check_deps(self.tree, (rule,)), None + except AssertionError as e: + return rule, None, e + self.tree # build the private copy once, here: its cached_property has no lock on Python 3.12+ + with concurrent.futures.ThreadPoolExecutor(max_workers=4) as pool: + results = list(pool.map(alone, rules)) + for rule, r, error in results: + with self.subTest(rule=rule): + self.assertIsNone(error) + self.assertEqual((r.returncode, r.stderr), (0, "")) + self.assertEqual(r.stdout.splitlines(), ["== check-deps =="] + segments.get(rule, []) + + [f"check-deps: the selected gates are green (--only {rule})"]) + + def test_a_selection_runs_its_rules_in_the_scripts_order(self): + r = _run_check_deps(self.tree, ("fpflags", "present", "ticks")) + self.assertEqual(r.stdout.splitlines(), + ["== check-deps ==", " ok — ticks", " ok — fpflags", " ok — present: one worker door", + "check-deps: the selected gates are green (--only fpflags,present,ticks)"]) + + def test_a_misspelt_or_empty_selector_is_an_error_not_a_green_run(self): + """A selector that names no rule, or a second --only, must not run less than asked and pass: exit 2, before any rule runs.""" + script = os.path.join(self.ROOT, "ci", "check-deps.sh") + for argv in (["--only", "bloking"], ["--only", "libm,nope"], ["--only", ""], ["--only", "libm,"], + ["--only", ",libm"], ["--only", "libm,,ticks"], ["--only"], ["--only=zzz"], ["--only=libm "], + ["--list"], ["libm"], ["--only", "libm", "--bogus"], + # a repeated --only would overwrite the first and run the smaller set, green + ["--only", "wall", "--only", "libm"], ["--only=wall", "--only=libm"], + ["--only", "wall", "--only=libm"]): + with self.subTest(argv=argv): + r = subprocess.run([script] + argv, capture_output=True, text=True) + self.assertEqual(r.returncode, 2, r.stdout + r.stderr) + self.assertEqual(r.stdout, "", "a rule ran") + self.assertIn("usage: ci/check-deps.sh", r.stderr) + + @_grades("ticks") + def test_a_test_that_selects_the_wrong_rule_fails_instead_of_passing(self): + """The violation planted here is `libm`'s, and this test selects `ticks`: the run is green + because `libm` never ran, and grading it as `libm`'s verdict must fail.""" + name = "_check_deps_selftest_wrong_rule.rs" + r = self._plant(name, "pub fn f(x: f32) -> f32 { x.powf(2.0) }\n") + self.assertEqual(r.returncode, 0, r.stdout + r.stderr) + self.assertNotIn("libm", r.stdout) + with self.assertRaises(AssertionError): + self._assert_flagged(r, "libm", [(name, "powf")]) + + def test_the_gate_runner_refuses_a_run_that_is_no_verdict_for_its_rules(self): + def fake(code, stdout, stderr=""): + return subprocess.CompletedProcess([], code, stdout=stdout, stderr=stderr) + green = "== check-deps ==\n ok — ticks\n ok — mutators-visibility\n" + self.assertEqual(_check_deps_verdict(fake(0, green), ("ticks",)).deps_rules, ("ticks",)) + self.assertIsNone(_check_deps_verdict(fake(1, green), None).deps_rules) + # `mutators` is a prefix of the name of another rule, not a verdict line of it + for case, r, rules, why in ( + ("no verdict line", fake(0, green), ("ticks", "libm"), "no verdict line for libm"), + ("a prefix of another rule", fake(0, green), ("mutators",), "no verdict line for mutators"), + ("usage error", fake(2, ""), ("ticks",), "no verdict"), + ("unset variable", fake(0, green, "check-deps.sh: line 9: x: unbound variable"), ("ticks",), + "unset variable")): + with self.subTest(case): + with self.assertRaisesRegex(AssertionError, why): + _check_deps_verdict(r, rules) + failed = fake(1, "== check-deps ==\n::error::check-deps: libm: 1 line(s) outside ci/allow/libm.txt\n") + self.assertEqual(_check_deps_verdict(failed, ("libm",)).returncode, 1) + _check_deps_verdict(fake(0, "== check-deps ==\n"), ("allowlist-counts",)) # silent when green + + @_grades("browse-owner") def test_self_tests_never_touch_the_real_tree(self): """Red-first for the parallel gate self-tests: every planting helper below edits a private copy of the gate's inputs, never the checkout. A helper that wrote into the checkout @@ -8719,13 +8888,15 @@ def test_self_tests_never_touch_the_real_tree(self): self.assertEqual(self._prepend("browse/mod.rs", "\n").returncode, 0) self.assertEqual(os.stat(real).st_mtime_ns, before, "a self-test wrote into the real tree") + @_grades_whole_script def test_the_private_copy_grades_exactly_like_the_real_tree(self): """The copy must carry every input `ci/check-deps.sh` reads: a missing one makes a gate see nothing and pass (or fail) for a reason the real tree would not share.""" real = self._real_tree() - copy = subprocess.run([os.path.join(self.tree, "ci", "check-deps.sh")], capture_output=True, text=True) + copy = self._deps() self.assertEqual((copy.returncode, copy.stdout), (real.returncode, real.stdout), copy.stderr) + @_grades("fpflags") def test_the_private_copy_carries_every_fpflags_input(self): """The untouched copy above cannot see an input that was left out of `TREE_INPUTS` -- a gate that scans nothing is green. So plant what the `fpflags` rule looks for in each file @@ -8734,8 +8905,7 @@ def test_the_private_copy_carries_every_fpflags_input(self): All of them are planted at once and graded by ONE run: the rule prints one `path:line:text` match per offending file, so a file the rule did not scan (or the copy did not carry) is missing from the output and that input's subtest fails by name. Run one file at a - time this was 17 of the 73 `ci/check-deps.sh` runs in this class (about a quarter of - the module's CPU).""" + time this was 17 of the 73 `ci/check-deps.sh` runs this class made when each ran every rule.""" inputs = ("rust-modules/Cargo.toml", "rust-modules/build.rs", "rust-modules/net/Cargo.toml", "rust-modules/plex/Cargo.toml", "rust-modules/telemetry/Cargo.toml", "rust-modules/data/Cargo.toml", "rust-modules/session/Cargo.toml", "rust-modules/media/Cargo.toml", "rust-modules/appkit/Cargo.toml", "rust-modules/appkit/build.rs", "rust-modules/screens/Cargo.toml", "rust-modules/screens/build.rs", "rust-modules/platform/Cargo.toml", "rust-modules/platform/build.rs", "rust-modules/gfx/Cargo.toml", "rust-modules/gfx/build.rs", "rust-modules/ui/Cargo.toml", "rust-modules/ui/build.rs", @@ -8746,8 +8916,7 @@ def test_the_private_copy_carries_every_fpflags_input(self): self.assertTrue(os.path.exists(target), f"{rel} is not in the private copy (TREE_INPUTS)") with open(target, "a", encoding="utf-8") as f: f.write("\nrustflags = [\"-C\", \"target-feature=+fma\"]\n") - r = subprocess.run([os.path.join(self.tree, "ci", "check-deps.sh")], - capture_output=True, text=True) + r = self._deps() out = r.stdout + r.stderr self.assertNotEqual(r.returncode, 0, out) self.assertIn("fpflags:", out) @@ -8768,8 +8937,7 @@ def _plant(self, name, content, crate_dir=None): try: with open(target, "w", encoding="utf-8") as f: f.write(content) - return subprocess.run([os.path.join(self.tree, "ci", "check-deps.sh")], - capture_output=True, text=True) + return self._deps() finally: if os.path.exists(target): os.remove(target) @@ -8786,7 +8954,7 @@ def _plant_all(self, plants): `plants` is a list of `(name, content, crate_dir)`, each with its own file name, so the one run still shows which variants the gate caught: a gate prints the `path:line:text` (or the path) of every file it flags, and the caller requires each variant's file by name. Run - one variant at a time, a test with N variants cost N runs (about 25 s of CPU apiece).""" + one variant at a time, a test with N variants cost N runs.""" written = [] try: for name, content, crate_dir in plants: @@ -8795,8 +8963,7 @@ def _plant_all(self, plants): written.append(target) with open(target, "w", encoding="utf-8") as f: f.write(content) - return subprocess.run([os.path.join(self.tree, "ci", "check-deps.sh")], - capture_output=True, text=True) + return self._deps() finally: for target in written: if os.path.exists(target): @@ -8817,8 +8984,7 @@ def _mutate(self, relpath, needle, replacement): try: with open(target, "w", encoding="utf-8") as f: f.write(original.replace(needle, replacement, 1)) - return subprocess.run([os.path.join(self.tree, "ci", "check-deps.sh")], - capture_output=True, text=True) + return self._deps() finally: with open(target, "w", encoding="utf-8") as f: f.write(original) @@ -8839,8 +9005,7 @@ def _prepend(self, relpath, content): try: with open(target, "w", encoding="utf-8") as f: f.write(content + original) - return subprocess.run([os.path.join(self.tree, "ci", "check-deps.sh")], - capture_output=True, text=True) + return self._deps() finally: with open(target, "w", encoding="utf-8") as f: f.write(original) @@ -8851,8 +9016,8 @@ def _prepend_files(self, fixtures): `fixtures` maps a store-relative path to the module-level text to prepend. Each variant a self-test wants to prove is rejected gets its OWN declaration (a distinct name), so the one run still shows which variants the gate caught: `_assert_flagged` requires every one - by name. Run one variant at a time these were 34 of the 73 gate runs in this class, and a - run is ~7 s of CPU.""" + by name. Run one variant at a time these were 34 of the 73 gate runs this class made when + each ran every rule.""" originals = {} try: for relpath, content in fixtures.items(): @@ -8861,8 +9026,7 @@ def _prepend_files(self, fixtures): originals[target] = f.read() with open(target, "w", encoding="utf-8") as f: f.write(content + originals[target]) - return subprocess.run([os.path.join(self.tree, "ci", "check-deps.sh")], - capture_output=True, text=True) + return self._deps() finally: for target, original in originals.items(): with open(target, "w", encoding="utf-8") as f: @@ -8873,6 +9037,8 @@ def _assert_flagged(self, r, rule, flagged): a `path:line:text` line of THAT file whose text holds `marker` -- so a variant the gate missed fails by name even though the others were caught in the same run.""" out = r.stdout + r.stderr + self.assertTrue(r.deps_rules is None or rule in r.deps_rules, + f"{rule} is not among the rules this test selected, {r.deps_rules}: it never ran\n{out}") self.assertNotEqual(r.returncode, 0, out) self.assertIn(f"{rule}:", out) for relpath, marker in flagged: @@ -8881,6 +9047,7 @@ def _assert_flagged(self, r, rule, flagged): any(f"/src/{relpath}:" in line and marker in line for line in out.splitlines()), f"{rule} did not flag {marker!r} in {relpath}\n{out}") + @_grades("browse-owner") def test_browse_owner_gate_rejects_a_republished_free_mutator(self): """A valid module-level declaration is rejected even without a call site.""" r = self._prepend("browse/mod.rs", "\npub(crate) fn set_cur(i: usize) {}\n") @@ -8889,6 +9056,7 @@ def test_browse_owner_gate_rejects_a_republished_free_mutator(self): self.assertIn("browse-owner:", out) self.assertIn("fn set_cur", out) + @_grades("browse-owner") def test_browse_owner_gate_rejects_all_free_declaration_modifiers(self): declarations = ( ("set_cur", " pub(super) fn set_cur(i: usize) {}\n"), @@ -8899,6 +9067,7 @@ def test_browse_owner_gate_rejects_all_free_declaration_modifiers(self): r = self._prepend_files({"browse/mod.rs": "".join("\n" + d for _, d in declarations)}) self._assert_flagged(r, "browse-owner", [("browse/mod.rs", f"fn {n}") for n, _ in declarations]) + @_grades("browse-owner") def test_browse_owner_gate_rejects_attributes_and_split_free_declarations(self): declarations = ( ("set_cur", "#[inline] pub(super) const fn set_cur(i: usize) {}\n"), @@ -8907,11 +9076,13 @@ def test_browse_owner_gate_rejects_attributes_and_split_free_declarations(self): r = self._prepend_files({"browse/mod.rs": "".join("\n" + d for _, d in declarations)}) self._assert_flagged(r, "browse-owner", [("browse/mod.rs", name) for name, _ in declarations]) + @_grades("browse-owner") def test_browse_owner_gate_is_nonvacuous_for_indented_free_declarations(self): r = self._prepend("browse/mod.rs", "\n pub fn set_cur(i: usize) {}\n") self.assertNotEqual(r.returncode, 0, r.stdout + r.stderr) self.assertIn("browse/mod.rs", r.stdout + r.stderr) + @_grades("browse-owner") def test_browse_owner_gate_ignores_normal_string_braces_before_a_free_const_fn(self): """Compiling counterexample for the old raw brace counter: the `{` belongs to LABEL, so the indented const fn after it is still a module-level retired facade and must fail.""" @@ -8924,6 +9095,7 @@ def test_browse_owner_gate_ignores_normal_string_braces_before_a_free_const_fn(s self.assertIn("browse-owner:", out) self.assertIn("const fn set_cur", out) + @_grades("browse-owner") def test_browse_owner_gate_ignores_every_rust_noncode_brace_before_a_free_fn(self): fixtures = ( '// {\n', @@ -8946,6 +9118,7 @@ def test_browse_owner_gate_ignores_every_rust_noncode_brace_before_a_free_fn(sel r = self._prepend_files({"browse/mod.rs": text}) self._assert_flagged(r, "browse-owner", [("browse/mod.rs", f"fn {n}(") for n in names]) + @_grades("browse-owner") def test_browse_owner_gate_ignores_noncode_closing_braces_inside_an_impl(self): """A compiling impl fixture remains receiver-bound even when every Rust literal/comment form contains `}`. The old counter escaped the impl and falsely reported `cur`.""" @@ -8968,6 +9141,7 @@ def test_browse_owner_gate_ignores_noncode_closing_braces_inside_an_impl(self): self.assertEqual(r.returncode, 0, r.stdout + r.stderr) self.assertIn("ok — browse-owner", r.stdout) + @_grades("browse-owner") def test_browse_owner_gate_rejects_retired_transport_declarations(self): declarations = ( ("browse/mod.rs", "LEGACY_ADAPTER", " pub(crate) static LEGACY_ADAPTER: () = ();\n"), @@ -8980,6 +9154,7 @@ def test_browse_owner_gate_rejects_retired_transport_declarations(self): r = self._prepend_files(by_file) self._assert_flagged(r, "browse-owner", [(relpath, name) for relpath, name, _ in declarations]) + @_grades("browse-owner") def test_browse_owner_gate_rejects_retired_thread_local_selectors(self): selectors = (("browse/mod.rs", "LEGACY_ADAPTER"), ("stores/browse.rs", "ACTIVE")) r = self._prepend_files({ @@ -8987,6 +9162,7 @@ def test_browse_owner_gate_rejects_retired_thread_local_selectors(self): for relpath, selector in selectors}) self._assert_flagged(r, "browse-owner", [(relpath, f"static {selector}") for relpath, selector in selectors]) + @_grades("browse-owner") def test_browse_owner_gate_accepts_unrelated_thread_local_state(self): r = self._prepend( "browse/mod.rs", @@ -8995,6 +9171,7 @@ def test_browse_owner_gate_accepts_unrelated_thread_local_state(self): self.assertEqual(r.returncode, 0, r.stdout + r.stderr) self.assertIn("ok — browse-owner", r.stdout) + @_grades("browse-owner") def test_browse_owner_gate_fails_closed_when_a_scanner_input_is_missing(self): target = self._store_file(os.path.join("browse", "view.rs")) hidden = target + ".check-deps-selftest" @@ -9002,11 +9179,7 @@ def test_browse_owner_gate_fails_closed_when_a_scanner_input_is_missing(self): self.assertFalse(os.path.exists(hidden), f"stale self-test artifact at {hidden}") try: os.replace(target, hidden) - r = subprocess.run( - [os.path.join(self.tree, "ci", "check-deps.sh")], - capture_output=True, - text=True, - ) + r = self._deps() finally: if os.path.exists(hidden): os.replace(hidden, target) @@ -9015,6 +9188,7 @@ def test_browse_owner_gate_fails_closed_when_a_scanner_input_is_missing(self): self.assertIn("browse declaration scanner failed", out) self.assertIn("browse-owner:", out) + @_grades("browse-owner") def test_browse_owner_gate_accepts_receiver_bound_owned_methods(self): """A BrowseState selector is safe when it requires an explicit receiver. GREEN: re-declare the owned `cur(&self)` method (already `pub` since the data crate split, so the @@ -9028,6 +9202,7 @@ def test_browse_owner_gate_accepts_receiver_bound_owned_methods(self): self.assertEqual(r.returncode, 0, r.stdout + r.stderr) self.assertIn("ok — browse-owner", r.stdout) + @_grades("viewstate-owner") def test_viewstate_owner_gate_rejects_a_republished_free_state_facade(self): """A free pump can only reach process state; the owned spelling requires a receiver.""" declarations = ( @@ -9037,6 +9212,7 @@ def test_viewstate_owner_gate_rejects_a_republished_free_state_facade(self): r = self._prepend_files({"viewstate.rs": "".join("\n" + d for _, d in declarations)}) self._assert_flagged(r, "viewstate-owner", [("viewstate.rs", name) for name, _ in declarations]) + @_grades("viewstate-owner") def test_viewstate_owner_gate_rejects_storage_transport_and_selector_statics(self): fixtures = ( ("viewstate.rs", "QUEUE", "static mut QUEUE: Vec<()> = Vec::new();\n"), @@ -9050,6 +9226,7 @@ def test_viewstate_owner_gate_rejects_storage_transport_and_selector_statics(sel r = self._prepend_files(by_file) self._assert_flagged(r, "viewstate-owner", [(relpath, name) for relpath, name, _ in fixtures]) + @_grades("viewstate-owner") def test_viewstate_owner_gate_accepts_receiver_bound_owned_methods(self): fixture = """ struct ViewStateOwnerGateFixture; @@ -9078,15 +9255,16 @@ def _module_path_fixture(self, production_reference): target = os.path.join(directory, "support.rs") with open(target, "w", encoding="utf-8") as output: output.write('pub fn helper() { std::thread::spawn(|| {}); let _ = 0.5f32.powf(2.4); }\n') - result = subprocess.run([os.path.join(self.tree, "ci", "check-deps.sh")], - capture_output=True, text=True) + result = self._deps() return result, os.path.relpath(target, self.tree) + @_grades("threads", "libm") def test_cfg_test_path_modules_are_excluded_from_production_gates(self): result, target = self._module_path_fixture(False) self.assertEqual(result.returncode, 0, result.stdout + result.stderr) self.assertNotIn(target + ":", result.stdout) + @_grades("threads", "libm") def test_production_path_reference_prevents_test_file_exemption(self): result, target = self._module_path_fixture(True) self.assertNotEqual(result.returncode, 0, result.stdout + result.stderr) @@ -9094,6 +9272,7 @@ def test_production_path_reference_prevents_test_file_exemption(self): self.assertIn("libm:", result.stdout) self.assertIn(target + ":", result.stdout) + @_grades("person-owner") def test_person_owner_gate_rejects_free_read_and_mutation_facades(self): declarations = ( ("current", "pub(crate) fn current() -> Option<()> { None }\n"), @@ -9103,6 +9282,7 @@ def test_person_owner_gate_rejects_free_read_and_mutation_facades(self): r = self._prepend_files({"person.rs": "".join("\n" + d for _, d in declarations)}) self._assert_flagged(r, "person-owner", [("person.rs", name) for name, _ in declarations]) + @_grades("person-owner") def test_person_owner_gate_rejects_model_transport_and_selector_statics(self): fixtures = ( ("person.rs", "CURRENT", "static mut CURRENT: Option = None;\n"), @@ -9117,6 +9297,7 @@ def test_person_owner_gate_rejects_model_transport_and_selector_statics(self): r = self._prepend_files(by_file) self._assert_flagged(r, "person-owner", [(relpath, name) for relpath, name, _ in fixtures]) + @_grades("person-owner") def test_person_owner_gate_accepts_receiver_bound_owned_methods(self): fixture = """ struct PersonOwnerGateFixture; @@ -9130,6 +9311,7 @@ def test_person_owner_gate_accepts_receiver_bound_owned_methods(self): self.assertEqual(r.returncode, 0, r.stdout + r.stderr) self.assertIn("ok — person-owner", r.stdout) + @_grades("mutators") def test_metadata_pure_builder_allowed_but_mutator_rejected_in_dev(self): pure = "fn gate_fixture() { let _ = plx_data::metadata::alt_stand_in(); }\n" r = self._plant("dev/_check_deps_metadata_builder.rs", pure) @@ -9139,6 +9321,7 @@ def test_metadata_pure_builder_allowed_but_mutator_rejected_in_dev(self): self._assert_flagged(r, "mutators", [("dev/_check_deps_metadata_builder.rs", "alt_install(")]) self.assertNotIn("alt_stand_in(", r.stdout + r.stderr) + @_grades("threads") def test_threads_gate_catches_a_bare_thread_spawn_after_use_std_thread(self): """The gate used to match only the fully-qualified `std::thread::spawn(` spelling, so a file that does `use std::thread;` and then calls the bare `thread::spawn(` — exactly the @@ -9153,6 +9336,7 @@ def test_threads_gate_catches_a_bare_thread_spawn_after_use_std_thread(self): self.assertIn("threads:", out) self.assertIn("_check_deps_selftest_threads.rs", out) + @_grades("threads") def test_threads_gate_ignores_visible_test_modules_without_exempting_production(self): files = {} for i, visibility in enumerate(("pub", "pub(crate)", "pub(super)")): @@ -9167,6 +9351,7 @@ def test_threads_gate_ignores_visible_test_modules_without_exempting_production( self.assertIn("threads:", r.stdout + r.stderr) self.assertIn("_check_deps_visible_production.rs", r.stdout + r.stderr) + @_grades("globals") def test_globals_ledger_ignores_field_labels_without_hiding_value_reads(self): fields = ("struct Captured { current_server: u32, client_for: u32, screen_input_revision: u32 }\n" "fn captured() -> Captured { Captured { current_server: 1, client_for: 2, screen_input_revision: 3 } }\n") @@ -9180,6 +9365,7 @@ def test_globals_ledger_ignores_field_labels_without_hiding_value_reads(self): self.assertIn(key + "current_server", out) self.assertIn(key + "client_for", out) + @_grades("blocking") def test_blocking_gate_catches_a_new_allow_blocking_site(self): """A frame-thread blocking exception is a ledger entry in ci/allow/blocking.txt. RED: a new production `allow_blocking(` that the list does not name must fail `blocking`, naming the @@ -9192,6 +9378,7 @@ def test_blocking_gate_catches_a_new_allow_blocking_site(self): self.assertIn("blocking:", out) self.assertIn("_check_deps_selftest_blocking.rs::sneaky", out) + @_grades("blocking") def test_blocking_gate_ignores_tests_comments_and_declarations(self): """GREEN: the same call inside a `#[cfg(test)] mod`, in a comment, or as an `fn` declaration is not a call site.""" @@ -9204,6 +9391,7 @@ def test_blocking_gate_ignores_tests_comments_and_declarations(self): self.assertEqual(r.returncode, 0, r.stdout + r.stderr) self.assertIn("ok — blocking", r.stdout) + @_grades("blocking") def test_blocking_gate_catches_an_aliased_allow_blocking(self): """The call-site grep cannot see `use ...::allow_blocking as x; x(..)` or `let f = allow_blocking;`. RED: a production mention of the bare identifier that is not a call, the @@ -9216,6 +9404,7 @@ def test_blocking_gate_catches_an_aliased_allow_blocking(self): self.assertIn("blocking:", out) self.assertIn("_check_deps_selftest_blocking_alias.rs:1", out) + @_grades("blocking") def test_blocking_gate_catches_a_stale_entry(self): """The ledger only shrinks: an entry whose site is gone must fail `blocking`, so a migration has to delete its line (and a line cannot be left behind to excuse a later regrowth).""" @@ -9228,7 +9417,7 @@ def test_blocking_gate_catches_a_stale_entry(self): stale += "rust-modules/media/src/route/decision.rs::no_such_fn\tgone\n" with open(allow, "w", encoding="utf-8") as f: f.write(stale) - r = subprocess.run([os.path.join(self.tree, "ci", "check-deps.sh")], capture_output=True, text=True) + r = self._deps() finally: with open(allow, "w", encoding="utf-8") as f: f.write(original) @@ -9243,13 +9432,12 @@ def test_blocking_gate_catches_a_stale_entry(self): # in different areas never edit the same `# count:` header. LEDGER_RULES = ("workers", "globals", "forks", "fxlanes") - def _deps(self): - return subprocess.run([os.path.join(self.tree, "ci", "check-deps.sh")], capture_output=True, text=True) def _ledger_files(self, rule): root = os.path.join(self.tree, "ci", "allow", rule) return sorted(os.path.join(root, fn) for fn in os.listdir(root) if fn.endswith(".txt")) + @_grades("blocking") def test_blocking_ledger_keeps_its_multiset_shape_after_the_refactor(self): """`blocking` now runs on the shared ledger scanner and must grade as it always did: every call is its own ledger line (two calls in one fn are two lines), a call in a closure @@ -9268,6 +9456,7 @@ def test_blocking_ledger_keeps_its_multiset_shape_after_the_refactor(self): self.assertEqual(new, ["closure", "one_liner", "two", "two"], out) self.assertIn("new: 4, stale: 0, aliased: 0", out) + @_grades("workers") def test_workers_ledger_catches_a_new_worker_start_in_a_machine(self): """RED: a production worker start in a machine (a data/ store, a screen, the session owner ...) that no ci/allow/workers/.txt names must fail `workers`, keyed by file, enclosing fn @@ -9290,6 +9479,7 @@ def test_workers_ledger_catches_a_new_worker_start_in_a_machine(self): self.assertIn(f"{key}::{site}", out) self.assertIn("ci/allow/workers/data-_check_deps_selftest_workers.txt", out) + @_grades("globals") def test_globals_ledger_catches_a_new_registry_read_in_a_machine(self): """RED: a production read of a process-global registry in a machine fails `globals`: the getters, the qualified `session::peek`, and a bare `peek` only because this file imports it @@ -9317,6 +9507,7 @@ def test_globals_ledger_catches_a_new_registry_read_in_a_machine(self): self.assertEqual(out.count(f"{key}::peek (ledger: "), 1, "`it.peek()` is not a registry read\n" + out) self.assertIn("ci/allow/globals/screens.txt", out) + @_grades("forks") def test_forks_ledger_catches_a_new_production_test_fork(self): """RED: a `#[cfg(not(test))]` / `cfg!(not(test))` / `not(feature = \"test-support\")` fork in any machine crate (data/, plex/, media/, session/, screens/, ui/, appkit/, machine/) that no @@ -9340,6 +9531,7 @@ def test_forks_ledger_catches_a_new_production_test_fork(self): self.assertIn(f"{key}::{item} (ledger: ", out) self.assertIn("ci/allow/forks/session.txt", out) + @_grades("forks") def test_forks_ledger_reads_every_machine_crate_not_only_the_four_that_own_the_data(self): """RED: a machine in screens/, ui/, appkit/ or machine/ forks on `cfg(test)` as surely as one in data/ does (`screens/src/legal.rs` `build_sha`, `screens/src/login.rs` `harness_driven` were the live cases), so the @@ -9369,6 +9561,7 @@ def test_forks_ledger_reads_every_machine_crate_not_only_the_four_that_own_the_d with self.subTest(crate=crate, test_item=item): self.assertNotIn(f"{key}::{item}", out, "an item only a test can see is no fork\n" + out) + @_grades("fxlanes") def test_fxlanes_ledger_fails_a_new_appfx_side_queue_but_not_a_deliver_arm(self): """RED: in `Bridge::app_effect` an `AppFx` arm that pushes `Fx::Deliver(` rides the ordered FIFO and costs nothing; an arm that parks its request on a side queue must be a ledger line, @@ -9386,6 +9579,7 @@ def test_fxlanes_ledger_fails_a_new_appfx_side_queue_but_not_a_deliver_arm(self) self.assertNotIn("AppFx::Orderly", out) self.assertIn("ci/allow/fxlanes/app.txt", out) + @_grades("workers", "globals", "forks") def test_ledgers_ignore_tests_comments_strings_and_declarations(self): """GREEN: the same shapes inside a `#[cfg(test)] mod`, under a test-only `cfg(any(test, ..))` item, in a comment, a doc line or a string literal, are no site of any ledger -- so all @@ -9406,7 +9600,7 @@ def test_ledgers_ignore_tests_comments_strings_and_declarations(self): self.assertRegex(r.stdout, rf"ok — {rule} \(\d+ sites\)") def _plant_many(self, files, crate_dir): - """`_plant` for several orphan files of ONE crate, graded by a single gate run (a run is ~11 s): + """`_plant` for several orphan files of ONE crate, graded by a single gate run: each file isolates one import shape, because a `use` statement applies to its whole file.""" written = [] try: @@ -9430,6 +9624,7 @@ def _append_to(self, rel, text): f.write(text) return self._deps() + @_grades("globals") def test_globals_ledger_sees_renamed_and_bare_keypin_and_grant_getters(self): """RED: `keypin::revision`, `keypin::blocked_for` and `grant::offers` are registry reads like `session::peek`, so the two ways to hide one from the call-site scan are shut the same way: @@ -9463,6 +9658,7 @@ def test_globals_ledger_sees_renamed_and_bare_keypin_and_grant_getters(self): self.assertEqual(out.count(f"{base}bare.rs::bare::revision (ledger: "), 1, "`it.revision()` is not a registry read\n" + out) + @_grades("globals") def test_globals_ledger_sees_the_player_transport_readers_in_a_machine(self): """RED: `transport::viewer_paused` (the pause-hold claim) and `preview::paused` (the preview machine's process-global phase) still read process-wide state, so a machine that calls one is a site, as a @@ -9526,6 +9722,7 @@ def test_globals_ledger_sees_the_player_transport_readers_in_a_machine(self): self.assertNotIn(f"{base}{stem}.rs", out, "`..._preview::*` / `..._transport::{..}` is not `preview` / `transport`\n" + out) + @_grades("globals") def test_globals_ledger_sees_the_capability_answer_readers_in_a_machine(self): """RED: `devcaps::caps()` is the device's capability answer, a process-wide registry read. It has been write-once since #1047: it is the boot snapshot, a stored refusal never moves it, and the stored rows reach @@ -9591,6 +9788,7 @@ def test_globals_ledger_sees_the_capability_answer_readers_in_a_machine(self): self.assertNotIn(f"{base}{stem}.rs", out, "a `caps` parameter or an unimported `caps(` is not the capability answer\n" + out) + @_grades("globals") def test_globals_ledger_sees_screen_input_revision_without_allowance(self): r = self._plant_many({ "stores/_check_deps_screen_revision_direct.rs": "fn read() { plx_plex::plex::session::screen_input_revision(); }\n", @@ -9606,6 +9804,7 @@ def test_globals_ledger_sees_screen_input_revision_without_allowance(self): self.assertIn(base + "glob.rs::read::screen_input_revision", out) self.assertIn(base + "alias.rs:1", out) + @_grades("globals") def test_globals_ledger_sees_the_registry_readers_the_old_closed_list_missed(self): """RED: the server registry's roster readers (`server_ids`, `server_roster_gen`, `server_facts_gen`, `server_probe_result`), the session cache's two readers (`session::peek_settled`, `session::current_gen`) @@ -9618,7 +9817,7 @@ def test_globals_ledger_sees_the_registry_readers_the_old_closed_list_missed(sel `plex/src/plex/session.rs` calls its own `peek_settled()` / `current_gen()` with no `use` to say so, as it always did for `peek`; a bare call planted there is a site. `data/src/stores/tape.rs` is the registry the stores call through, not a machine, so its own bare `active()` is NOT one. All of it is - graded by ONE gate run (a run is ~14 s).""" + graded by ONE gate run.""" crate = "data" session = "rust-modules/plex/src/plex/session.rs" tape = "rust-modules/data/src/stores/tape.rs" @@ -9705,6 +9904,7 @@ def test_globals_ledger_sees_the_registry_readers_the_old_closed_list_missed(sel self.assertEqual(len(naming), 1, "`stores/tape.rs` is the registry, not a machine: its own bare `active()` is no site\n" + out) + @_grades("workers", "globals") def test_a_bare_name_that_ends_a_braced_import_is_still_imported(self): """RED: `use plx_base::task::{self, spawn};` imports `spawn` as surely as `{spawn, self}` does, and so for `submit` and `peek`; the import pattern used to eat the closing `}` of a group whose @@ -9736,6 +9936,7 @@ def test_a_bare_name_that_ends_a_braced_import_is_still_imported(self): self.assertIn(f"{base}{stem}.rs::{fn}::{spelling} (ledger: ", out) self.assertNotIn(f"{base}other.rs", out, "`{self, spawn_small}` imports no bare `spawn`\n" + out) + @_grades("fxlanes") def test_fxlanes_ledger_sees_every_variant_of_an_arm_and_a_catch_all_arm(self): """RED: an or-pattern arm (`AppFx::A(r) | AppFx::B(r) => ..`, on one line or wrapped) is a site for EVERY variant on its head, and an arm with no `AppFx::` head (`other => ..`, `_ => ..`) is a @@ -9758,6 +9959,7 @@ def test_fxlanes_ledger_sees_every_variant_of_an_arm_and_a_catch_all_arm(self): self.assertNotIn("PlantedOk", out) self.assertNotIn(f"{key}Loop", out, "the variant the ledger already holds is not new") + @_grades("globals") def test_globals_ledger_sees_every_spelling_of_the_player_transport_in_lifecycle(self): """RED: lifecycle.rs, the machine, reads no `crate::player::TX` (the transport contract lives in player/transport.rs), and the spellings stay pinned there as a zero-guard: planting `super::TX`, @@ -9784,6 +9986,7 @@ def test_globals_ledger_sees_every_spelling_of_the_player_transport_in_lifecycle rename_line = before + appended.split("\n").index("use super::TX as Transport2;") + 1 self.assertIn(f"{rel}:{rename_line}\n", out + "\n") + @_grades("workers", "globals", "forks") def test_a_cfg_test_fn_with_a_where_clause_is_skipped_whole(self): """RED: an item under `#[cfg(test)]` is skipped to the end of ITS body. A signature that spills over several lines -- a long parameter list, a `where` clause whose bounds end in a comma -- used @@ -9804,6 +10007,7 @@ def test_a_cfg_test_fn_with_a_where_clause_is_skipped_whole(self): self.assertNotIn(f"{key}::?", out, "a test fn's body was graded as production\n" + out) self.assertEqual(out.count(key), 1, out) + @_grades("forks") def test_forks_ledger_names_a_path_qualified_macro_item_and_counts_an_inline_cfg_test(self): """RED: `#[cfg(..)]` on `plx_base::devtrig::latched_flag!(..);` is an item named for its macro, like an unqualified `cache!` is, not the unnamed `?`. And `cfg!(test)` still counts as a fork whatever it @@ -9832,6 +10036,7 @@ def test_no_ledger_key_is_unnamed(self): self.assertFalse(key.endswith("::?") or "::?::" in key, f"{os.path.relpath(path, self.tree)}: {key}") + @_grades("workers", "globals") def test_worker_and_global_aliases_fail_because_the_scan_cannot_count_them(self): """RED: `use ...::spawn_small as go;` renames a worker start or a registry getter, so every `go(..)` after it is invisible to the call-site scan: the `use ... as` line fails its rule @@ -9853,6 +10058,7 @@ def test_worker_and_global_aliases_fail_because_the_scan_cannot_count_them(self) with self.subTest(site=site): self.assertIn(f"{path}::{site} (ledger: ", out) + @_grades("workers", "globals", "forks", "fxlanes") def test_ledger_files_must_be_exact_stale_lines_and_misfiled_lines_fail(self): """Every ledger only shrinks: a line whose site is gone fails its rule (so a migration has to delete it), and a line filed under the wrong area fails too, so the layout cannot drift.""" @@ -9885,6 +10091,7 @@ def test_ledger_files_must_be_exact_stale_lines_and_misfiled_lines_fail(self): self.assertIn("misfiled ledger line: rust-modules/gfx/src/_selftest_misfiled.rs::f", out) self.assertIn("belongs in ci/allow/forks/gfx.txt", out) + @_grades("allowlist-counts") def test_ledger_count_header_must_equal_its_entries_in_every_area_file(self): """The `# count:` header of every ci/allow//.txt is held to its entries, exactly like the flat allowlists: a line added or deleted without moving the header fails by name.""" @@ -9904,6 +10111,7 @@ def test_ledger_count_header_must_equal_its_entries_in_every_area_file(self): with self.subTest(rule=rule): self.assertIn(f"{rel} declares count", out) + @_grades("tmppath") def test_tmppath_gate_catches_a_path_built_on_one_line_and_opened_on_the_next(self): """The gate used to require the literal and a filesystem-open verb on the SAME line, so a value built on one line and opened on the next passed silently. RED: planting that split @@ -9918,6 +10126,7 @@ def test_tmppath_gate_catches_a_path_built_on_one_line_and_opened_on_the_next(se self.assertIn("tmppath:", out) self.assertIn("_check_deps_selftest_tmppath_open.rs", out) + @_grades("tmppath") def test_tmppath_gate_exempts_a_log_message_mention(self): """D4's own exemption: a `/tmp/plxnative-` literal that is only message text passed to `log`/`crate::eventlog::log`/`log!` must not fail the gate. GREEN: planting one, including a nested @@ -9932,6 +10141,7 @@ def test_tmppath_gate_exempts_a_log_message_mention(self): self.assertEqual(r.returncode, 0, out) self.assertIn("ok — tmppath", out) + @_grades("cards") def test_cards_gate_catches_a_screen_assembling_its_own_strip(self): """Shared-card-sections L1: a screen draws card sections with `plx_ui::cards::{Shelf, Grid}`. `card_row` / `poster_grid` are `pub(crate)`, so the gate polices what `plx_ui::cards` @@ -9955,6 +10165,7 @@ def test_cards_gate_catches_a_screen_assembling_its_own_strip(self): for line in (2, 4, 5, 6, 7, 8, 9): self.assertIn(f"_check_deps_selftest_cards_strip.rs:{line}", out) + @_grades("cards") def test_cards_gate_allows_the_shared_component(self): r = self._plant( "_check_deps_selftest_cards_ok.rs", @@ -9965,6 +10176,7 @@ def test_cards_gate_allows_the_shared_component(self): self.assertEqual(r.returncode, 0, out) self.assertIn("ok — cards", out) + @_grades("sink") def test_sink_gate_catches_the_video_sink_named_outside_the_player(self): """Step L15: the Starfish/ACB verbs are the player's alone. RED: a module outside `player/`, `port.rs` and `tv/` that reaches `tv::sink::installed()` must fail `sink`.""" @@ -9977,6 +10189,7 @@ def test_sink_gate_catches_the_video_sink_named_outside_the_player(self): self.assertIn("sink:", out) self.assertIn("_check_deps_selftest_sink_out.rs", out) + @_grades("sink") def test_sink_gate_allows_the_player_to_name_the_video_sink(self): """GREEN: the same call from a file under `player/` leaves `sink` (and the script) green.""" r = self._plant( @@ -9987,6 +10200,7 @@ def test_sink_gate_allows_the_player_to_name_the_video_sink(self): self.assertEqual(r.returncode, 0, out) self.assertIn("ok — sink", out) + @_grades("textmeasure") def test_textmeasure_gate_catches_a_bare_call_outside_the_seam(self): """Phase 12, D4: `textmeasure` went from an allowlist to zero-tolerance. RED: a raw `crate::text::text_width(` call in a file that is neither one of the three seam files @@ -10003,6 +10217,7 @@ def test_textmeasure_gate_catches_a_bare_call_outside_the_seam(self): self.assertIn("textmeasure:", out) self.assertIn("_check_deps_selftest_textmeasure_bare.rs", out) + @_grades("textmeasure") def test_textmeasure_gate_exempts_the_body_of_a_measure_impl(self): """The exemption is STRUCTURAL, not a path allowlist: any `impl … Measure for …` block, anywhere in the tree, may call the raw functions it wraps — `widgets.rs`'s `LegacyMeasure` @@ -10022,6 +10237,7 @@ def test_textmeasure_gate_exempts_the_body_of_a_measure_impl(self): self.assertEqual(r.returncode, 0, out) self.assertIn("ok — textmeasure", out) + @_grades("dt") def test_dt_gate_catches_a_raw_accumulator(self): """Phase 12, D4: `dt` went from a 12-file allowlist to zero-tolerance everywhere but `machine/src/motion.rs`. RED: a `self.t += dt;`-shaped accumulator in a new file must fail — this @@ -10038,6 +10254,7 @@ class comes from.""" self.assertIn("dt:", out) self.assertIn("_check_deps_selftest_dt_accum.rs", out) + @_grades("dt") def test_dt_gate_catches_idle_dt_by_name(self): """`idle::dt()` is deleted from `machine/src/idle.rs` — the accessor callers used to sum themselves. RED: a call spelled `idle::dt()` anywhere must fail even with no `+=`/`-=` beside it, since @@ -10051,6 +10268,7 @@ def test_dt_gate_catches_idle_dt_by_name(self): self.assertIn("dt:", out) self.assertIn("_check_deps_selftest_dt_fn.rs", out) + @_grades("nav", "ui-owner-legacy") def test_ui_owner_gate_rejects_retired_global_readers(self): readers = ( ("nav", "plx_ui::nav::page_alpha()"), @@ -10073,6 +10291,7 @@ def test_ui_owner_gate_rejects_retired_global_readers(self): any(f"_check_deps_selftest_owner_{name}.rs:" in line for line in output.splitlines()), f"{rule} did not flag the {name} reader\n{output}") + @_grades("ui-owner-files") def test_ui_owner_gate_rejects_resurrected_modules(self): modules = (("ui", "nav.rs"), ("ui", "press.rs"), ("machine", "idle.rs")) result = self._plant_all([(name, "// Retired module must remain absent.\n", crate) for crate, name in modules]) @@ -10083,6 +10302,7 @@ def test_ui_owner_gate_rejects_resurrected_modules(self): with self.subTest(crate=crate, module=name): self.assertIn(f"ui-owner-files: retired module rust-modules/{crate}/src/{name} exists", output) + @_grades("owned-damage") def test_owned_damage_gate_rejects_a_retired_transport_call(self): result = self._plant("_check_deps_selftest_damage_adapter.rs", "pub fn repaint() { plx_machine::motion::report::invalidate(); }\n") @@ -10090,6 +10310,7 @@ def test_owned_damage_gate_rejects_a_retired_transport_call(self): self.assertNotEqual(result.returncode, 0, output) self.assertIn("owned-damage:", output) + @_grades("owned-wake") def test_owned_wake_gate_rejects_worker_door_from_ui(self): result = self._plant("_check_deps_selftest_render_worker_door.rs", "pub fn deferred_draw() { plx_machine::present::wake_from_worker(); }\n", crate_dir="ui") @@ -10097,12 +10318,12 @@ def test_owned_wake_gate_rejects_worker_door_from_ui(self): self.assertNotEqual(result.returncode, 0, output) self.assertIn("owned-wake:", output) + @_grades("owned-damage") def test_owned_damage_gate_rejects_a_report_global(self): target = os.path.join(self.tree, "rust-modules", "machine", "src", "motion", "report.rs") with open(target, "a", encoding="utf-8") as stream: stream.write("\nstatic PAINT: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);\n") - result = subprocess.run([os.path.join(self.tree, "ci", "check-deps.sh")], - capture_output=True, text=True) + result = self._deps() output = result.stdout + result.stderr self.assertNotEqual(result.returncode, 0, output) self.assertIn("owned-damage:", output) @@ -10790,10 +11011,10 @@ class _ParallelSuite(unittest.TestSuite): """Runs its tests on a thread pool and replays each one's outcome into the real result. Only for tests whose work is a subprocess and that share no state (`DepGates`: each runs - `ci/check-deps.sh` over its own private copy of the tree, about 11 s apiece (a few of them run it - several times), - which was 630 of the 645 s this module took when they ran one after another). Threads are - enough because the time is spent waiting on the child. A test runs against a private + `ci/check-deps.sh` over its own private copy of the tree, which was 630 of the 645 s this + module took when they ran one after another and each ran every rule; now each selects only + the rule it plants for, `_grades`). Threads are enough because the time is spent waiting on + the child. A test runs against a private `TestResult`, then its counters and failure lists are folded into the shared one on the calling thread, so the shared result is only ever touched from one thread.