diff --git a/.github/scripts/id-pr-checks.txt b/.github/scripts/id-pr-checks.txt index af8e566528..c58cf8042c 100644 --- a/.github/scripts/id-pr-checks.txt +++ b/.github/scripts/id-pr-checks.txt @@ -29,6 +29,7 @@ taplo-check clippy-lint web-lint cargo-check +prod-lines-check test-unit test-shard-0 test-shard-1 diff --git a/pkgs/id/flake.nix b/pkgs/id/flake.nix index 11a024a4f6..81bed732eb 100644 --- a/pkgs/id/flake.nix +++ b/pkgs/id/flake.nix @@ -338,6 +338,10 @@ roc-test = mkCheck "roc-test" "roc-test"; doc = mkCheck "doc" "doc"; cargo-check = mkCheck "cargo-check" "cargo-check"; + # Production module-size guard (#1411): fails when any + # production .rs file exceeds 2,500 production lines + # (grandfathered: src/web/markdown.rs, split tracked in #1438). + prod-lines-check = mkCheck "prod-lines-check" "prod-lines-check"; crash-gate = mkCheck "crash-gate" "crash-gate"; # PR-gate splits of crash-gate (#551): the aggregate above runs # every heavy full sweep serially (~15 min, the slowest PR diff --git a/pkgs/id/just-recipes.json b/pkgs/id/just-recipes.json index 1d26ba8b53..9d07b7cf88 100644 --- a/pkgs/id/just-recipes.json +++ b/pkgs/id/just-recipes.json @@ -827,7 +827,7 @@ "windows_shell": null, "working_directory": null }, - "source": "/home/user/git/fleet/4856/root.just", + "source": "/home/user/git/fleet/6592/root.just", "unexports": [], "warnings": [] } @@ -1988,6 +1988,19 @@ "namepath": "outdated", "shebang": false }, + "prod-lines-check": { + "attributes": [{ "group": "lint" }], + "body": [["bash scripts/prod-lines-check.sh && bash scripts/prod-lines-check-test.sh"]], + "dependencies": [], + "doc": "the companion self-test proves the guard fails, not just that it passes", + "name": "prod-lines-check", + "parameters": [], + "priors": 0, + "private": false, + "quiet": false, + "namepath": "prod-lines-check", + "shebang": false + }, "release": { "attributes": [{ "group": "build" }], "body": [["./scripts/build.sh web release"]], @@ -2088,23 +2101,7 @@ }, "roc-test": { "attributes": [{ "group": "test" }], - "body": [ - ["#!/usr/bin/env bash"], - ["set -euo pipefail"], - ["if ! command -v roc >/dev/null 2>&1; then"], - [" echo \"roc-test: the pinned Roc compiler (nix/roc.nix) is not on PATH.\" >&2"], - [ - " echo \"roc-test: run inside 'nix develop' or the roc-test flake check — refusing to skip silently (#813).\" >&2" - ], - [" exit 1"], - ["fi"], - ["echo \"roc-test: $(roc version)\""], - ["for module in RocJson Screen Key; do"], - [" echo \"=== roc test examples/roc-world/${module}.roc ===\""], - [" roc test \"examples/roc-world/${module}.roc\""], - ["done"], - ["echo \"✓ Roc library expectations passed (RocJson, Screen, Key)\""] - ], + "body": [["bash scripts/roc-test.sh"]], "dependencies": [], "doc": "Run the Roc library expect() tests (RocJson, Screen, Key) with the pinned Roc compiler (#813)", "name": "roc-test", @@ -2113,7 +2110,7 @@ "private": false, "quiet": false, "namepath": "roc-test", - "shebang": true + "shebang": false }, "run": { "attributes": [{ "group": "run" }], @@ -3301,7 +3298,7 @@ "windows_shell": null, "working_directory": null }, - "source": "/home/user/git/fleet/4856/pkgs/id/justfile", + "source": "/home/user/git/fleet/6592/pkgs/id/justfile", "unexports": [], "warnings": [] } diff --git a/pkgs/id/justfile b/pkgs/id/justfile index b8c4bc3577..b089e63ea7 100644 --- a/pkgs/id/justfile +++ b/pkgs/id/justfile @@ -168,6 +168,12 @@ clippy-lint: clippy-lint-fix: cargo clippy --all-targets --all-features --fix --allow-dirty --allow-staged +# Fail when any production .rs file exceeds 2,500 production lines (#1411); +# the companion self-test proves the guard fails, not just that it passes +[group('lint')] +prod-lines-check: + bash scripts/prod-lines-check.sh && bash scripts/prod-lines-check-test.sh + # [biome] Lint web code (TypeScript + CSS) [group('lint')] web-lint: diff --git a/pkgs/id/scripts/prod-lines-check-test.sh b/pkgs/id/scripts/prod-lines-check-test.sh new file mode 100755 index 0000000000..e59d691fc0 --- /dev/null +++ b/pkgs/id/scripts/prod-lines-check-test.sh @@ -0,0 +1,85 @@ +#!/usr/bin/env bash +# Self-test for prod-lines-check.sh: proves the guard passes a clean +# tree and fails on each violation shape (new over-limit file, +# grandfather growth, broken/empty scan). Runs inside the +# prod-lines-check just recipe, so CI continuously proves the guard +# fails, not just that it passes. +set -euo pipefail + +script="$(cd "$(dirname "$0")" && pwd)/prod-lines-check.sh" +tmp="$(mktemp -d)" +out="$(mktemp)" +trap 'rm -rf "$tmp" "$out"' EXIT + +# A small production file: 3 production lines + a test module. +write_small() { + mkdir -p "$tmp/$1" + { + echo "pub fn f() {}" + echo "pub fn g() {}" + echo "pub fn h() {}" + echo "#[cfg(test)]" + echo "mod tests { }" + } >"$tmp/$1/lib.rs" +} + +reset_tree() { + rm -rf "$tmp" + mkdir -p "$tmp" +} + +check_pass() { + if ! PROD_LINES_ROOT="$tmp" PROD_LINES_LIMIT="$1" bash "$script" >"$out" 2>&1; then + cat "$out" + echo "unexpected failure: $2" >&2 + exit 1 + fi +} + +check_fail() { + if PROD_LINES_ROOT="$tmp" PROD_LINES_LIMIT="$1" bash "$script" >"$out" 2>&1; then + echo "unexpected success: $2" >&2 + exit 1 + fi + if ! grep -q "$3" "$out"; then + cat "$out" + echo "failure did not name '$3': $2" >&2 + exit 1 + fi +} + +# Clean tree: one small file, integration tests, vendored code and the +# module-gated encryption tests are all out of scope and must not trip +# a limit of 3. +reset_tree +write_small src +mkdir -p "$tmp/tests" "$tmp/vendor/dep" "$tmp/src/encryption" "$tmp/src/web" +printf 'line1\nline2\nline3\nline4\n' >"$tmp/tests/big_integration.rs" +printf 'line1\nline2\nline3\nline4\n' >"$tmp/vendor/dep/big_vendor.rs" +printf 'line1\nline2\nline3\nline4\n' >"$tmp/src/encryption/tests.rs" +printf 'line1\nline2\nline3\n#[cfg(test)]\nmod tests { }\n' >"$tmp/src/web/markdown.rs" +check_pass 3 'clean tree passes' + +# New over-limit production file fails and is named with its count. +reset_tree +write_small src +for i in 1 2 3 4 5; do echo "pub fn f$i() {}"; done >"$tmp/src/grown.rs" +check_fail 3 'new over-limit file fails' 'src/grown.rs has 5 production lines (limit 3)' + +# Grandfathered markdown.rs at its allowance passes; one line more fails. +reset_tree +mkdir -p "$tmp/src/web" +awk 'BEGIN { for (i = 0; i < 5312; i++) print "x" }' >"$tmp/src/web/markdown.rs" +check_pass 2500 'grandfather at allowance passes' +printf 'one more line\n' >>"$tmp/src/web/markdown.rs" +check_fail 2500 'grandfather growth fails' 'grandfathered file grew: 5313 production lines (allowance 5312' + +# Empty scan is a broken scan, not a pass. +reset_tree +mkdir -p "$tmp/empty" +if PROD_LINES_ROOT="$tmp/empty" bash "$script" >"$out" 2>&1; then + echo "unexpected success: empty scan passed" >&2 + exit 1 +fi + +echo "prod-lines-check tests passed" diff --git a/pkgs/id/scripts/prod-lines-check.sh b/pkgs/id/scripts/prod-lines-check.sh new file mode 100755 index 0000000000..92850d9c17 --- /dev/null +++ b/pkgs/id/scripts/prod-lines-check.sh @@ -0,0 +1,114 @@ +#!/usr/bin/env bash +# Production module-size guard for F11.10 (issue #1411). +# +# Fails when any production Rust file under pkgs/id exceeds 2,500 +# production lines, where production = lines before the first +# `#[cfg(test)]` line (the #1078 audit method). Test-only files stay +# out of scope: the package-root `tests/` tree (cargo integration +# tests), vendored third-party code, and the module-gated test modules +# in TEST_ONLY below. +# +# Grandfathered over-limit files live in grandfather_allowance() as +# path|allowance|reason rows. The allowance is a ceiling that must only +# shrink: any growth fails, and deleting the entry (once the split +# lands) makes the plain 2,500 limit apply. +# +# Test seams (used by prod-lines-check-test.sh, not in CI): +# PROD_LINES_ROOT scan this tree instead of pkgs/id +# PROD_LINES_LIMIT compare against this limit instead of 2,500 +set -euo pipefail + +pkg_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +root="${PROD_LINES_ROOT:-$pkg_dir}" +root="$(cd "$root" && pwd)" +limit="${PROD_LINES_LIMIT:-2500}" + +# Grandfathered over-limit production files: path|allowance|reason. +# Allowance is lines of production code, not total lines. +grandfather_allowance() { + case "$1" in + src/web/markdown.rs) + # Grandfathered 2026-11-03 at 5,312 production lines (10,140 total, + # first #[cfg(test)] at line 5,313); the F11.10 split that shrinks + # it is tracked in #1438 (queue task 6599). Any growth fails. + printf '5312|F11.10 split tracked in #1438 — allowance must only shrink' + return 0 + ;; + esac + return 1 +} + +# Test-only production-tree files with no in-file #[cfg(test)] marker +# (module-gated via `#[cfg(test)] mod ;` in the parent module): +# path|reason. +test_only_reason() { + case "$1" in + src/encryption/tests.rs) + printf 'module-gated test module (#[cfg(test)] mod tests in src/encryption/mod.rs)' + return 0 + ;; + esac + return 1 +} + +is_skipped_dir() { + case "$1" in + tests/* | vendor/* | target/* | node_modules/* | .git/*) return 0 ;; + esac + return 1 +} + +prod_lines() { + awk 'BEGIN { n = 0 } /^[[:space:]]*#\[cfg\(test\)\]$/ { exit } { n++ } END { print n }' "$1" +} + +scanned=0 +skipped_test_only=0 +violations=0 +max_file="" +max_lines=0 +grandfather_hits=0 + +while IFS= read -r file; do + rel="${file#"$root"/}" + if is_skipped_dir "$rel"; then + continue + fi + if reason="$(test_only_reason "$rel")"; then + skipped_test_only=$((skipped_test_only + 1)) + echo "test-only: $rel ($reason)" + continue + fi + count="$(prod_lines "$file")" + scanned=$((scanned + 1)) + if [ "$count" -gt "$max_lines" ]; then + max_lines="$count" + max_file="$rel" + fi + if entry="$(grandfather_allowance "$rel")"; then + grandfather_hits=$((grandfather_hits + 1)) + allowance="${entry%%|*}" + greason="${entry#*|}" + if [ "$count" -gt "$allowance" ]; then + violations=$((violations + 1)) + echo "::error file=$rel::grandfathered file grew: $count production lines (allowance $allowance — $greason)" + else + echo "grandfathered: $rel at $count production lines (allowance $allowance — $greason)" + fi + elif [ "$count" -gt "$limit" ]; then + violations=$((violations + 1)) + echo "::error file=$rel::$rel has $count production lines (limit $limit) — split the module per F11.10 (#1411)" + fi +done < <(find "$root" -name '*.rs' -not -path '*/target/*' -not -path '*/node_modules/*' -not -path '*/.git/*' | sort) + +if [ "$scanned" -eq 0 ]; then + echo "::error::prod-lines-check found no .rs files under $root — the scan is broken, refusing to pass" >&2 + exit 2 +fi + +echo "prod-lines-check: $scanned production files scanned (limit $limit), largest $max_file at $max_lines lines, $skipped_test_only test-only skips, $grandfather_hits grandfathered" +if [ "$violations" -ne 0 ]; then + echo "prod-lines-check: $violations file(s) over the limit" >&2 + exit 1 +fi +echo "prod-lines-check passed"