Section 16 of 25

Enforcement

Contents

Mechanism first, words second. A rule that a script can check should never depend on someone remembering it.

Rule Who enforces it
only app knows Tauri Cargo.toml (no tauri dependency elsewhere); cargo-deny for transitive dependencies (16.5)
tiers depend only downward Cargo.toml
only store opens database connections checks/slat-writer.sh: Connection::open only in the store crate, which hands out the one writer and the read connections. A slice's store.rs receives them and uses rusqlite types, so the dependency alone is not enough.
#[tauri::command] only in app/**/commands.rs a grep check
every command is registered a check comparing commands in slices with generate_handler!
emit only in app/**/events.rs a grep check
no deep imports between slices a check for crate::<a>::<layer>:: from another slice
no static with state in core a grep check for a static with Mutex, RwLock or an atomic type
no lock inside an actor a grep check: no Mutex or RwLock under actor/
logic.rs and update.rs have no I/O a check: no async, tokio::, std::fs, store::, drivers:: in logic.rs, logic/ and update.rs
a slice's mod.rs holds only mod …; and pub use …; a check on every mod.rs under core/src/
no cycles between slices a check that builds the slice graph from imports and sorts it
a Tauri command has at most 10 lines a check on app/**/commands.rs
no unwrap() and panic! outside tests in kit, store, drivers, core Clippy lints unwrap_used and panic (16.5)
operating system only in drivers/src/platform/ and app/src/platform.rs a grep check with the list from 12.3
crates other than app compile on every platform cargo check on Ubuntu and Windows CI runners
size limits a check with a baseline list that may only shrink

Every check starts with a baseline list of today's violations. A new violation is red. A violation that gets fixed must be removed from the list in the same pull request, so the list can never grow back.

16.1. A check with a baseline

All checks follow one shape: find violations, subtract the baseline, fail on anything left, and fail if the baseline lists something that is already fixed.

#!/usr/bin/env bash
set -euo pipefail

baseline="checks/baselines/emit.txt"
found="$(grep -rln --include='*.rs' -E '\.emit(_to)?\(' crates src-tauri/src \
  | grep -vE '^src-tauri/src/([a-z_]+/)+events\.rs$' | sort || true)"

new="$(comm -23 <(printf '%s\n' "$found" | sed '/^$/d') <(sort "$baseline"))"
fixed="$(comm -13 <(printf '%s\n' "$found" | sed '/^$/d') <(sort "$baseline"))"

if [ -n "$new" ]; then
  printf 'emit outside app/<slice>/events.rs:\n%s\n' "$new"
  exit 1
fi
if [ -n "$fixed" ]; then
  printf 'already fixed, remove from %s:\n%s\n' "$baseline" "$fixed"
  exit 1
fi
echo "emit: $(printf '%s\n' "$found" | sed '/^$/d' | wc -l | tr -d ' ') files on the baseline, none new"

16.2. A check must be able to fail

Before you trust a check, plant a real violation, watch it turn red, and remove it. A check that has never been red has never been tested.

The grep checks in SLAT look for forbidden code, so a match inside a comment turns them red, not green. That is annoying but safe, and the fix is to delete the dead code. A check that reads the syntax tree (16.5) does not have this problem. The dangerous kind is a check that requires a string to be present: it passes on a comment. Prove a rule like that by running code, not by reading text.

16.3. The platform job in CI

name: platforms
on: [pull_request]
jobs:
  compile:
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - run: cargo check --workspace --exclude quayside --all-targets

Pin action versions to full commit hashes in a real repository. The job only compiles; it runs no tests on platforms the product does not support yet, so it is cheap. The cache step keeps it cheap: without it, every pull request compiles all dependencies from nothing on two operating systems.

16.4. Checks for the whole set

Check Rule
checks/slat-commands.sh #[tauri::command] only in src-tauri/src/**/commands.rs
checks/slat-registered.sh every command in a slice appears in generate_handler!
checks/slat-emit.sh emit only in src-tauri/src/**/events.rs
checks/slat-writer.sh Connection::open only in crates/*-store
checks/slat-deep-imports.sh no crate::<slice>::<layer>:: from another slice
checks/slat-static-state.sh no static with Mutex, RwLock or an atomic type in crates/*-core*
checks/slat-actor-lock.sh no Mutex or RwLock under actor/
checks/slat-pure.sh logic.rs, logic/ and update.rs without async, tokio::, std::fs, store::, drivers::
checks/slat-slice-mod.sh a slice's mod.rs holds only mod …; and pub use …;
checks/slat-edges.sh prints the slice graph, one <slice> <imported slice> per line
checks/slat-slice-cycles.sh no cycles between slices
checks/slat-command-size.sh every #[tauri::command] has at most 10 lines
checks/slat-platform.sh the prohibitions from 12.3 outside platform/
checks/slat-size.sh files over 1,500 lines from the baseline may only shrink

The cycle check needs no graph library. checks/slat-edges.sh prints the slice graph: every crate::<other> inside core/src/<slice>/ is an edge, including grouped imports such as use crate::{run::Run, plan::Plan};, also when they span several lines. A nested group (crate::{run::{Run, Step}, plan}) loses the names after its inner group; that is where an ast-grep rule (16.5) takes over.

checks/slat-edges.sh:

#!/usr/bin/env bash
set -euo pipefail

core="${1:-crates/quayside-core/src}"
find "$core" -mindepth 2 -name '*.rs' | sort | while read -r file; do
  slice="${file#"$core"/}"
  slice="${slice%%/*}"
  { tr '\n' ' ' < "$file" \
    | grep -oE 'crate::(\{[^}]*\}|[a-z_]+)' \
    | grep -oE '(crate::|[{,] *)[a-z_]+' \
    | sed -E 's/^(crate::|[{,] *)//' \
    | sed "s/^/$slice /"; } || true
done | awk '$1 != $2' | sort -u

tsort reports a graph with a loop on its error output. checks/slat-slice-cycles.sh:

#!/usr/bin/env bash
set -euo pipefail

edges="$(checks/slat-edges.sh crates/quayside-core/src)"
loops="$(printf '%s\n' "$edges" | tsort 2>&1 > /dev/null || true)"
if [ -n "$loops" ]; then
  printf '%s\n' "$loops"
  echo "slices import each other in a loop; move the shared part into its own slice (7.2)"
  exit 1
fi
echo "slices: $(printf '%s\n' "$edges" | sed '/^$/d' | wc -l | tr -d ' ') edges, no cycle"

The same list of edges is the slice graph that section 22.4 uses to find the slices a change can affect.

16.5. Lints and bans before scripts

Some rules need no script, because a tool the workspace already runs can enforce them.

Clippy, per tier. Clippy reads clippy.toml from the crate's own folder first, so each tier can forbid different things. Lints are switched on in Cargo.toml:

[workspace.lints.clippy]
unwrap_used = "deny"
panic = "deny"
[lints]
workspace = true

The first block goes into the workspace root, the second into kit, store, drivers and core. The app crate does not inherit them. A clippy.toml in the workspace root with allow-unwrap-in-tests = true and allow-panic-in-tests = true keeps tests readable. A clippy.toml in a crate's folder replaces the one in the root, so it repeats those two lines. A clippy.toml in core can list disallowed-types, for example std::process::Command, so that a process started from a slice is a lint error, not a grep match. Do not list std::sync::Mutex there: a cache that belongs to a slice's service (9.1) needs a short lock, never held across an await. The lock that must not exist, one inside an actor (9.3), is caught by checks/slat-actor-lock.sh.

cargo-deny, for the whole dependency graph. Cargo.toml stops use tauri::… in core, but not a library that pulls tauri in through the back door. That leak is invisible in review, and it makes the tests of core compile the heaviest part of the application. cargo-deny checks the whole graph. In deny.toml:

[bans]
deny = [
  { crate = "tauri", wrappers = ["quayside", "tauri-plugin-shell", "tauri-plugin-dialog"] },
]

tauri may then appear only as a direct dependency of the crates in wrappers: the app crate and the Tauri plugins it uses, which depend on tauri themselves. A plugin added to the application joins the list in the same pull request. Any other path to tauri, such as a library that core uses, is red.

Syntax instead of text. The grep checks of 16.4 can be written as ast-grep rules. ast-grep matches the Rust syntax tree, so a comment or a string never matches, and an import split over several lines (use crate::run::{logic::plan, model::Run};) is still one import. A rule file per check, with files and ignores globs taken from the paths in 16.4, replaces grep -E. The baseline list (16.1) stays as it is: the rules produce the list of violations, and the same script subtracts the baseline.