diff --git a/quest/m2/README.md b/quest/m2/README.md index d4de0062915..8ca1d6aa44b 100644 --- a/quest/m2/README.md +++ b/quest/m2/README.md @@ -205,7 +205,6 @@ lite-07; bitrate enforcement is not part of this release. - [Dependency and alternatives audit](/quest/m2/audit-deps.md) - every dependency earns its weight, preferring fewer, and the rest are current, deduplicated, and the best maintained option - [Dead code and API surface audit](/quest/m2/audit-dead-code.md) - repeat the removal audit before the next major release - [Typecheck with bun check](/quest/m2/bun-check.md) - workspace packages typecheck through bun once nixpkgs ships bun 1.4.4 -- [Declare each check module once in the dispatcher](/quest/m2/dispatch-modules.md) - one registration call per module replaces its parallel tables - [Format YAML with Biome](/quest/m2/biome-yaml.md) - `just check` fails on unformatted YAML - [Format Markdown with Biome](/quest/m2/biome-markdown.md) - Biome formats every Markdown file and remark is gone, landed in a quiet window - [Test coverage audit](/quest/m2/audit-test-coverage.md) - repeat the coverage audit against the m1 baselines after the next release ships diff --git a/quest/m2/dispatch-modules.md b/quest/m2/dispatch-modules.md deleted file mode 100644 index 23b96a54d43..00000000000 --- a/quest/m2/dispatch-modules.md +++ /dev/null @@ -1,22 +0,0 @@ -# [M] Declare each check module once in the dispatcher - -## Goal - -`sh/dispatch.sh` declares each module in one `module` registration call -(scope pattern, tools, whether it compiles Rust, lane, runs alone) that fills -the tables it reads today, instead of listing the module separately in -`scope`, `tools`, `compiles`, `lane`, `alone`, and the lane order. Selection -and scheduling are unchanged. No public API or wire impact. - -## Plan - -Decided 2026-10-27 (maintainer interview, from the 2026-10-27 refactor audit): -stay in bash with a registration function; porting the dispatcher to Python -was declined. - -- Keep each table's comment with the module it explains. -- Preserve the Bun lane (concurrent `bun install` breaks), the shared C++ - build lane, and Dart running alone. -- Prove equivalence with the existing `sh/dispatch-query.test.py` and - `sh/changed.test.py`, plus a before/after diff of `just ci-select` output for - a few representative diffs. diff --git a/sh/dispatch.sh b/sh/dispatch.sh index 51b6c7231e7..2a4a4e3f461 100755 --- a/sh/dispatch.sh +++ b/sh/dispatch.sh @@ -56,69 +56,151 @@ else fi fi -# The impact map: a module is in scope when a changed path matches its -# pattern. An empty pattern is a repository-wide lint that runs on every diff. -declare -A scope=( - # The JS tests also read Rust's shared JSON vectors; sh/js/workspace.py - # fails a check that reads a cross-tree input this pattern misses. - # demo/pub is a Worker outside the Bun workspace, listed so Biome lints it. - # Root Nix inputs own the browser version every npm Playwright pin matches. - [js]='^(js/|bench/browser/|doc/|drafts/|demo/(boy|pub|web|carla/web)/|test/|rs/.*\.json$|sh/js/|sh/rs/stats-docs\.py$|package\.json$|bun\.lock(b)?$|biome\.jsonc$|flake\.(nix|lock)$)' - # Workers with lockfiles outside the Bun workspace. - [workers]='^(infra/|demo/pub/|sh/js/workers\.sh$)' - [moq_sh]='^infra/moq-sh/' - # sh/rs/select.sh widens to the whole workspace for inputs every crate shares. - # moq-cli builds the Rust interop clients as examples from outside its - # crate; sh/rs/select.test.py fails when a target's directory is missing. - # moq-relay's tests read its NixOS module. - [rs]='^(\.cargo/|nix/modules/moq-relay\.nix$|sh/local\.(sh|ts)$|rs/|demo/carla/bridge/|test/interop/clients/rust/|sh/rs/|Cargo\.(toml|lock)$|clippy\.toml$|rust-toolchain\.toml$|\.config/nextest\.toml$)' - [bench]='^bench/' - # The CARLA demo's simulator worker and launchers. Its player is a JS - # package and its GPU bridge a Rust crate, so those modules cover them. - [carla]='^demo/carla/(sim/|justfile$)' - [drafts]='^(drafts/|sh/drafts/|doc/\.vitepress/drafts\.ts$)' - # Quest documents form one graph, so any change validates the whole tree, - # as does a bump of the flake-pinned validator. - [quest]='^(quest/|flake\.lock$)' - # The drill mutations patch Rust source, so a Rust change can move the code - # they target. Only nightly runs the drills; this catches a stale patch. - [drill]='^(rs/|test/drill/)' - # maturin bundles rs/moq-ffi into the moq-ffi wheel, and the other - # bindings generate from it, built by the `cargo build-ffi` alias in - # .cargo/config.toml. Each check also compiles its doc samples. - [py]='^(py/|sh/py/|pyproject\.toml$|uv\.lock$|rs/moq-ffi/|doc/lib/py/|doc/lib/samples\.sh$)' - [kt]='^(\.cargo/config\.toml$|kt/|sh/kt/|rs/moq-ffi/|doc/lib/kt/|doc/lib/samples\.sh$)' - [swift]='^(\.cargo/config\.toml$|swift/|sh/swift/|rs/moq-ffi/|doc/lib/swift/|doc/lib/samples\.sh$)' - [go]='^(\.cargo/config\.toml$|go/|sh/go/|rs/moq-ffi/|doc/lib/go/|doc/lib/samples\.sh$)' - [dart]='^(\.cargo/config\.toml$|dart/|sh/dart/|rs/moq-ffi/|doc/lib/dart/|doc/lib/samples\.sh$)' - # The C package links moq-c's native-libs lists, and the C++ package's FFI - # pin. Both packages format with sh/clang-format.sh and OBS's style file. - [c]='^(\.cargo/config\.toml$|c/|sh/c/|sh/clang-format\.sh$|cpp/obs/\.clang-format$|rs/moq-ffi/|rs/moq-c/native-libs/|cpp/moq/FFI_VERSION$|cpp/moq/cmake/moq-ffi\.cmake$)' - # The package links moq-c's native-libs lists, and compiles its doc samples. - [cpp]='^(\.cargo/config\.toml$|cpp/moq/|cpp/justfile$|sh/cpp/|sh/clang-format\.sh$|cpp/obs/\.clang-format$|rs/moq-ffi/|rs/moq-c/native-libs/|doc/lib/cpp/|doc/lib/samples\.sh$)' - # The plugin and its tests call through the bindings generated from cpp/moq - # and moq-ffi and link through moq-c's native-libs lists, and flake.nix owns - # the libobs headers it compiles against. - [obs_compile]='^(\.cargo/config\.toml$|cpp/obs/|cpp/moq/|sh/obs/|rs/moq-ffi/|rs/moq-c/native-libs/|flake\.nix$)' - # `obs check` compares the OBS pinned in buildspec.json, flake.nix, and - # nixpkgs, and the last moves on a flake.lock bump alone. - [obs]='^(cpp/obs/|sh/obs/|flake\.(nix|lock)$)' - # Rust source is compiled below. Nix reads Cargo metadata, packaging inputs, - # and its own modules and test helpers; those still gate the full flake. - [flake]='(^\.cargo/|^rs/.*\.(toml|txt|ptx|in)$|^Cargo\.(toml|lock)$|^rust-toolchain\.toml$|^flake\.lock$|^nix/|\.nix$)' - # ts.yml's crate filters against the closure test/ts/run.sh builds, which - # moves only with a manifest, the lockfile, or the harness's packages. - [ts_paths]='^(rs/.*Cargo\.toml$|Cargo\.(toml|lock)$|test/ts/run\.sh$|\.github/workflows/release-gate\.yml$|sh/gh/ts-paths\.py$)' - # Ruff lints and formats every Python file under the nearest pyproject.toml. - [python]='(\.pyi?|(^|/)pyproject\.toml)$' - [markdown]='' - [shell]='' - [large_files]='' - [toml]='' - [nix]='' - [justfile]='' - [gh]='' -) +# The impact map: each module registers once, in the order its lane starts, so +# the slowest come first. A module is in scope when a changed path matches its +# pattern; an empty pattern is a repository-wide lint that runs on every diff. +# After the pattern: +# tools='...' The commands it needs. A module missing one is skipped +# locally, so an incomplete toolchain checks less; under +# CI_STRICT (CI) it is an error, up front, because there a skip +# is indistinguishable from a pass. +# compiles='...' The actions (check, fix) whose run compiles Rust through +# Cargo, so CI restores the Rust build cache only when one is +# selected. +# lane=NAME Modules that share mutable state run in one lane, in module +# order; every other module is a lane of its own, and lanes +# run concurrently. +# alone Its lane runs with no other lane beside it, so it waits for +# the rest. +# fix `just fix` runs it too; check and ci run every module. +declare -A scope=() tools=() compiles=([check]="" [fix]="") lane=() alone=() +checks=() +fixes=() +module() { + local name=$1 option each solo= + scope[$name]=$2 + tools[$name]= + checks+=("$name") + shift 2 + for option; do + case "$option" in + tools=*) tools[$name]=${option#tools=} ;; + compiles=*) for each in ${option#compiles=}; do compiles[$each]+=" $name"; done ;; + lane=*) lane[$name]=${option#lane=} ;; + alone) solo=1 ;; + fix) fixes+=("$name") ;; + *) + echo "error: module $name has an unknown option '$option'" >&2 + exit 2 + ;; + esac + done + [[ -z "$solo" ]] || alone[${lane[$name]:-$name}]=1 +} + +# maturin bundles rs/moq-ffi into the moq-ffi wheel, and the other bindings +# generate from it, built by the `cargo build-ffi` alias in .cargo/config.toml. +# Each binding's check also compiles its doc samples. kt, swift, go, cpp, and +# obs_compile each build moq-ffi's cdylib with the same features and profile +# before reading target/debug/libmoq_ffi.so. Cargo runs one build at a time per +# target directory and leaves a fresh output untouched, so the first of those +# lanes builds it while the rest wait in Cargo, and none rewrites it while +# another reads it. py builds its test features into a target directory of its +# own, and carla runs its tools outside py's venv. +module py '^(py/|sh/py/|pyproject\.toml$|uv\.lock$|rs/moq-ffi/|doc/lib/py/|doc/lib/samples\.sh$)' \ + tools='uv' compiles=check +# sh/rs/select.sh widens to the whole workspace for inputs every crate shares. +# moq-cli builds the Rust interop clients as examples from outside its +# crate; sh/rs/select.test.py fails when a target's directory is missing. +# moq-relay's tests read its NixOS module. +module rs '^(\.cargo/|nix/modules/moq-relay\.nix$|sh/local\.(sh|ts)$|rs/|demo/carla/bridge/|test/interop/clients/rust/|sh/rs/|Cargo\.(toml|lock)$|clippy\.toml$|rust-toolchain\.toml$|\.config/nextest\.toml$)' \ + tools='cargo jq' compiles='check fix' fix +# The C package links moq-c's native-libs lists, and the C++ package's FFI +# pin. Both packages format with sh/clang-format.sh and OBS's style file. +module c '^(\.cargo/config\.toml$|c/|sh/c/|sh/clang-format\.sh$|cpp/obs/\.clang-format$|rs/moq-ffi/|rs/moq-c/native-libs/|cpp/moq/FFI_VERSION$|cpp/moq/cmake/moq-ffi\.cmake$)' \ + tools='cargo cmake cc c++ pkg-config uniffi-bindgen-cpp clang-format' compiles=check fix +# The package links moq-c's native-libs lists, and compiles its doc samples. +# It shares a lane with obs_compile because both build cpp/moq/build. +module cpp '^(\.cargo/config\.toml$|cpp/moq/|cpp/justfile$|sh/cpp/|sh/clang-format\.sh$|cpp/obs/\.clang-format$|rs/moq-ffi/|rs/moq-c/native-libs/|doc/lib/cpp/|doc/lib/samples\.sh$)' \ + tools='cargo cmake c++ uniffi-bindgen-cpp clang-format' compiles=check lane=cpp fix +# The plugin and its tests call through the bindings generated from cpp/moq +# and moq-ffi and link through moq-c's native-libs lists, and flake.nix owns +# the libobs headers it compiles against. +module obs_compile '^(\.cargo/config\.toml$|cpp/obs/|cpp/moq/|sh/obs/|rs/moq-ffi/|rs/moq-c/native-libs/|flake\.nix$)' \ + tools='cargo cmake pkg-config uniffi-bindgen-cpp' compiles=check lane=cpp +# The JS tests also read Rust's shared JSON vectors; sh/js/workspace.py +# fails a check that reads a cross-tree input this pattern misses. +# demo/pub is a Worker outside the Bun workspace, listed so Biome lints it. +# Root Nix inputs own the browser version every npm Playwright pin matches. +# The bun lane exists because `bun install` relinks the root workspace's +# packages even when nothing changed, so a concurrent install or import of +# them fails. +module js '^(js/|bench/browser/|doc/|drafts/|demo/(boy|pub|web|carla/web)/|test/|rs/.*\.json$|sh/js/|sh/rs/stats-docs\.py$|package\.json$|bun\.lock(b)?$|biome\.jsonc$|flake\.(nix|lock)$)' \ + tools='bun python3' lane=bun fix +module kt '^(\.cargo/config\.toml$|kt/|sh/kt/|rs/moq-ffi/|doc/lib/kt/|doc/lib/samples\.sh$)' \ + tools='cargo gradle java ktfmt' compiles=check fix +# Rust source is compiled below. Nix reads Cargo metadata, packaging inputs, +# and its own modules and test helpers; those still gate the full flake. +module flake '(^\.cargo/|^rs/.*\.(toml|txt|ptx|in)$|^Cargo\.(toml|lock)$|^rust-toolchain\.toml$|^flake\.lock$|^nix/|\.nix$)' \ + tools='nix' +module bench '^bench/' \ + tools='cargo' compiles=check +# The CARLA demo's simulator worker and launchers. Its player is a JS +# package and its GPU bridge a Rust crate, so those modules cover them. +module carla '^demo/carla/(sim/|justfile$)' \ + tools='uv' +# swift needs no tools: it skips off macOS by design, and platform.yml is its +# real gate. Its formatter is absent where nixpkgs cannot build it (see +# flake.nix). +module swift '^(\.cargo/config\.toml$|swift/|sh/swift/|rs/moq-ffi/|doc/lib/swift/|doc/lib/samples\.sh$)' \ + fix +module go '^(\.cargo/config\.toml$|go/|sh/go/|rs/moq-ffi/|doc/lib/go/|doc/lib/samples\.sh$)' \ + tools='cargo go uniffi-bindgen-go' compiles=check fix +module drafts '^(drafts/|sh/drafts/|doc/\.vitepress/drafts\.ts$)' \ + tools='bun kramdown-rfc xml2rfc' lane=bun +module markdown '' \ + tools='bun' lane=bun fix +module gh '' \ + tools='actionlint zizmor bun python3 cargo clippy-driver dpkg-deb nfpm rpm' lane=bun +# The drill mutations patch Rust source, so a Rust change can move the code +# they target. Only nightly runs the drills; this catches a stale patch. +module drill '^(rs/|test/drill/)' +# Workers with lockfiles outside the Bun workspace. +module workers '^(infra/|demo/pub/|sh/js/workers\.sh$)' \ + tools='bun' +module moq_sh '^infra/moq-sh/' \ + tools='dash' +# Quest documents form one graph, so any change validates the whole tree, +# as does a bump of the flake-pinned validator. +module quest '^(quest/|flake\.lock$)' \ + tools='quest' +# `obs check` compares the OBS pinned in buildspec.json, flake.nix, and +# nixpkgs, and the last moves on a flake.lock bump alone. +module obs '^(cpp/obs/|sh/obs/|flake\.(nix|lock)$)' \ + tools='clang-format cmake gersemi jq' fix +# ts.yml's crate filters against the closure test/ts/run.sh builds, which +# moves only with a manifest, the lockfile, or the harness's packages. +module ts_paths '^(rs/.*Cargo\.toml$|Cargo\.(toml|lock)$|test/ts/run\.sh$|\.github/workflows/release-gate\.yml$|sh/gh/ts-paths\.py$)' \ + tools='cargo python3' +# Ruff lints and formats every Python file under the nearest pyproject.toml. +module python '(\.pyi?|(^|/)pyproject\.toml)$' \ + tools='ruff' fix +module shell '' \ + tools='shellcheck shfmt' fix +module large_files '' +module toml '' \ + tools='taplo' fix +module nix '' \ + tools='nixfmt' fix +module justfile '' \ + fix +# dart builds moq-ffi with the filtered environment its build hook gets, then +# checks that the hook finds that build fresh. Any other Cargo build in between +# reruns the host build scripts in target/debug that track the environment, +# such as bindgen's BINDGEN_EXTRA_CLANG_ARGS, and so rebuilds what the hook +# then rebuilds again, so it runs alone, last. +module dart '^(\.cargo/config\.toml$|dart/|sh/dart/|rs/moq-ffi/|doc/lib/dart/|doc/lib/samples\.sh$)' \ + tools='cargo dart uniffi_bindgen_dart' compiles=check alone fix # Report each native suite from the same impact map, before any toolchain is # installed. Rust dependencies can break external consumers too, so include @@ -145,87 +227,12 @@ if [[ "$action" == ci-platform ]]; then exit fi -# The tools each module needs. A module missing one is skipped locally, so an -# incomplete toolchain checks less; under CI_STRICT (CI) it is an error, up -# front, because there a skip is indistinguishable from a pass. swift needs -# none: it skips off macOS by design, and platform.yml is its real gate. Its -# formatter is absent where nixpkgs cannot build it (see flake.nix). -declare -A tools=( - [js]='bun python3' - [workers]='bun' - [moq_sh]='dash' - [rs]='cargo jq' - [bench]='cargo' - [carla]='uv' - [drafts]='bun kramdown-rfc xml2rfc' - [quest]='quest' - [drill]='' - [py]='uv' - [kt]='cargo gradle java ktfmt' - [swift]='' - [go]='cargo go uniffi-bindgen-go' - [dart]='cargo dart uniffi_bindgen_dart' - [c]='cargo cmake cc c++ pkg-config uniffi-bindgen-cpp clang-format' - [cpp]='cargo cmake c++ uniffi-bindgen-cpp clang-format' - [obs_compile]='cargo cmake pkg-config uniffi-bindgen-cpp' - [obs]='clang-format cmake gersemi jq' - [flake]='nix' - [ts_paths]='cargo python3' - [markdown]='bun' - [python]='ruff' - [shell]='shellcheck shfmt' - [large_files]='' - [toml]='taplo' - [nix]='nixfmt' - [justfile]='' - [gh]='actionlint zizmor bun python3 cargo clippy-driver dpkg-deb nfpm rpm' -) - # CI and the local check share one selection and one lint/test dispatch. verb=$action [[ "$verb" != ci ]] || verb=check -# The modules whose run compiles Rust through Cargo, so CI restores the Rust -# build cache only when one is selected. The bindings build moq-ffi. -declare -A compiles=( - [check]='rs bench py kt go dart c cpp obs_compile' - [fix]='rs' -) - -# Lanes start in this order, so the slowest come first. dart runs alone (see -# below), so it waits for the rest. -case "$action" in - check | ci) modules=(py rs c cpp obs_compile js kt flake bench carla swift go drafts markdown gh drill workers moq_sh quest obs ts_paths python shell large_files toml nix justfile dart) ;; - fix) modules=(js rs dart go kt swift c cpp obs python markdown shell toml nix justfile) ;; -esac - -# Modules that share mutable state run in one lane, in module order; every -# other module is a lane of its own, and lanes run concurrently. -declare -A lane=( - # `bun install` relinks the root workspace's packages even when nothing - # changed, so a concurrent install or import of them fails. - [js]=bun - [drafts]=bun - [markdown]=bun - [gh]=bun - # Both build cpp/moq/build. - [cpp]=cpp - [obs_compile]=cpp -) - -# kt, swift, go, cpp, and obs_compile each build moq-ffi's cdylib with the same -# features and profile before reading target/debug/libmoq_ffi.so. Cargo runs -# one build at a time per target directory and leaves a fresh output untouched, -# so the first of those lanes builds it while the rest wait in Cargo, and none -# rewrites it while another reads it. py builds its test features into a target -# directory of its own, and carla runs its tools outside py's venv. - -# Lanes that run with no other lane beside them. dart builds moq-ffi with the -# filtered environment its build hook gets, then checks that the hook finds -# that build fresh. Any other Cargo build in between reruns the host build -# scripts in target/debug that track the environment, such as bindgen's -# BINDGEN_EXTRA_CLANG_ARGS, and so rebuilds what the hook then rebuilds again. -declare -A alone=([dart]=1) +modules=("${checks[@]}") +[[ "$action" != fix ]] || modules=("${fixes[@]}") # CHECK_MODULES names the modules to run, or with a leading `-` those to skip. declare -A only=() skip=() diff --git a/sh/gh/test-inventory.py b/sh/gh/test-inventory.py index b8ec8d59d4b..d25d1b2ea38 100644 --- a/sh/gh/test-inventory.py +++ b/sh/gh/test-inventory.py @@ -436,11 +436,10 @@ def execute(self, path: Path): self.executed.add(path) # The module dispatch passes its own names: `just check` and the like. if path == self.root / "sh/dispatch.sh": - for line in re.findall(r"modules=\(([^)]*)\)", path.read_text(errors="replace")): - for name in line.split(): - for verb in ("check", "fix"): - for recipe in self.resolve([name, verb], self.root): - self.visit_recipe(recipe) + for name in re.findall(r"^module (\w+) ", path.read_text(errors="replace"), re.M): + for verb in ("check", "fix"): + for recipe in self.resolve([name, verb], self.root): + self.visit_recipe(recipe) def bases(self, text: str, cwd: Path, file: Path | None) -> list[Path]: """The directories a script path in text may be relative to.""" diff --git a/sh/gh/test-inventory.test.py b/sh/gh/test-inventory.test.py index 2444b7072e1..3df4f711efd 100644 --- a/sh/gh/test-inventory.test.py +++ b/sh/gh/test-inventory.test.py @@ -212,6 +212,17 @@ def test_a_commented_out_caller_covers_nothing(self): self.write("justfile", JUSTFILE.replace(caller, f"echo 'a # b' a#b && {caller}")) self.assertNotIn("ignore media::gpu::tests::renders", self.orphans()) + def test_the_module_dispatcher_reaches_each_registered_module(self): + # sh/dispatch.sh runs `just check` for each `module` registration. + self.write("sh/dispatch.sh", "module() { :; }\nmodule rs '^rs/' \\\n tools='cargo' fix\n") + self.write("rs/justfile", RS + "\n check:\n just rs sweep\n") + self.assertIn("recipe rs::sweep", self.orphans()) + + self.write("justfile", JUSTFILE + " bash sh/dispatch.sh check\n") + orphans = self.orphans() + self.assertNotIn("recipe rs::sweep", orphans) + self.assertNotIn("ignore media::probe::long_sweep", orphans) + def test_a_dispatcher_runs_only_the_branch_its_caller_selects(self): self.write( "sh/group.sh", diff --git a/sh/js/workspace.py b/sh/js/workspace.py index 96f56270f4d..ebe17000669 100644 --- a/sh/js/workspace.py +++ b/sh/js/workspace.py @@ -109,7 +109,7 @@ def selection(root, paths): def unmapped(root, paths): """Existing inputs the dispatcher's static JS impact map misses, so changing one would skip its readers.""" - impact = re.compile(re.search(r"^\s*\[js\]='([^']*)'", (root / "sh/dispatch.sh").read_text(), re.M).group(1)) + impact = re.compile(re.search(r"^module js '([^']*)'", (root / "sh/dispatch.sh").read_text(), re.M).group(1)) # A directory input matches through the files under it, and an import through its file. return [ path diff --git a/sh/js/workspace.test.py b/sh/js/workspace.test.py index 172df9bea98..35851b8f7d0 100644 --- a/sh/js/workspace.test.py +++ b/sh/js/workspace.test.py @@ -38,7 +38,7 @@ def setUp(self): self.write() (self.root / "test/tsconfig.json").write_text('{"exclude":["**/dist"]}') (self.root / "sh").mkdir() - (self.root / "sh/dispatch.sh").write_text(" [js]='^(js/|doc/|demo/|test/)'\n") + (self.root / "sh/dispatch.sh").write_text("module js '^(js/|doc/|demo/|test/)'\n") def write(self): (self.root / "package.json").write_text(json.dumps({"workspaces": list(self.packages)})) diff --git a/sh/rs/select.test.py b/sh/rs/select.test.py index 9dc0f5cd6b5..ba22669c1e4 100644 --- a/sh/rs/select.test.py +++ b/sh/rs/select.test.py @@ -13,6 +13,11 @@ LINUX = os.uname().sysname == "Linux" +def dispatch_scope(): + """The rs module's impact pattern, as sh/dispatch.sh registers it.""" + return re.search(r"^module rs '([^']*)'", (ROOT / "sh/dispatch.sh").read_text(), re.M).group(1) + + class SelectTest(unittest.TestCase): # CI runs target lints before its test build. def selected(self, *paths, action="lint", github_actions=False): @@ -71,7 +76,7 @@ def test_workspace_clippy_configuration_selects_workspace(self): with self.subTest(paths=paths): calls = self.selected(*paths) self.assertTrue(any(call.startswith("rs lint --workspace ") for call in calls), calls) - scope = re.search(r"^\s*\[rs\]='([^']*)'", (ROOT / "sh/dispatch.sh").read_text(), re.M).group(1) + scope = dispatch_scope() self.assertRegex("clippy.toml", scope) def test_gate_runs_no_feature_matrix(self): @@ -157,11 +162,11 @@ def test_relay_nixos_module_selects_the_relay(self): # moq-relay's tests read the module. calls = self.selected("nix/modules/moq-relay.nix", action="test") self.assertTrue(any("/rs/moq-relay#" in call for call in calls), calls) - scope = re.search(r"^\s*\[rs\]='([^']*)'", (ROOT / "sh/dispatch.sh").read_text(), re.M).group(1) + scope = dispatch_scope() self.assertRegex("nix/modules/moq-relay.nix", scope) def test_dispatch_scope_covers_out_of_crate_targets(self): - scope = re.search(r"^\s*\[rs\]='([^']*)'", (ROOT / "sh/dispatch.sh").read_text(), re.M).group(1) + scope = dispatch_scope() metadata = json.loads( subprocess.check_output(["cargo", "metadata", "--format-version", "1", "--no-deps"], cwd=ROOT, text=True) )