Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions pkgs/id/scripts/prod-lines-check-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,31 +74,43 @@ check_usage_fail() {
check_usage_fail 'extra positional argument' extra-arg-test

# Clean tree: one small file, integration tests, vendored code and the
# module-gated encryption and world-session tests are all out of scope and must not trip
# a limit of 3.
# module-gated encryption, world-session and cli test modules are all out of
# scope and must not trip a limit of 3. Both the pre-split `src/...` layout
# and the post-split `crates/<crate>/src/...` layout are covered: the guard
# normalizes the crate prefix before matching (#10603).
reset_tree
write_small src
mkdir -p "$tmp/tests" "$tmp/vendor/dep" "$tmp/src/encryption" "$tmp/src/web" "$tmp/src/world_session"
mkdir -p "$tmp/crates/id-groups/src/encryption" "$tmp/crates/id-worlds/src/world_session" "$tmp/crates/id-cli/src/cli"
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\nline4\n' >"$tmp/src/world_session/tests.rs"
printf 'line1\nline2\nline3\nline4\n' >"$tmp/crates/id-groups/src/encryption/tests.rs"
printf 'line1\nline2\nline3\nline4\n' >"$tmp/crates/id-worlds/src/world_session/tests.rs"
printf 'line1\nline2\nline3\nline4\n' >"$tmp/crates/id-cli/src/cli/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.
# New over-limit production file fails and is named with its count — in the
# pre-split layout and under a crate.
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)'
reset_tree
write_small crates/x/src
for i in 1 2 3 4 5; do echo "pub fn f$i() {}"; done >"$tmp/crates/x/src/grown.rs"
check_fail 3 'new over-limit crate file fails' 'crates/x/src/grown.rs has 5 production lines (limit 3)'

# Grandfathered markdown.rs at its allowance passes; one line more fails.
# A grandfathered crate file at its allowance passes; one line more fails,
# and the allowance is reported against the real crate path.
reset_tree
mkdir -p "$tmp/src/web"
awk 'BEGIN { for (i = 0; i < 6232; i++) print "x" }' >"$tmp/src/web/markdown.rs"
mkdir -p "$tmp/crates/id-directory/src"
awk 'BEGIN { for (i = 0; i < 2610; i++) print "x" }' >"$tmp/crates/id-directory/src/directory.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: 6233 production lines (allowance 6232'
printf 'one more line\n' >>"$tmp/crates/id-directory/src/directory.rs"
check_fail 2500 'grandfather growth fails' 'grandfathered file grew: 2611 production lines (allowance 2610'

# Empty scan is a broken scan, not a pass.
reset_tree
Expand Down
71 changes: 44 additions & 27 deletions pkgs/id/scripts/prod-lines-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
# shrink: any growth fails, and deleting the entry (once the split
# lands) makes the plain 2,500 limit apply.
#
# Rows are keyed in package-relative `src/...` form. Before lookup a
# scanned path is normalized by stripping a leading `crates/<crate>/`
# (#10603), so the same row guards a module in the pre-split layout and
# after the crate split, and moving a file between crates does not
# silently disable its allowance or test-only exemption.
#
# 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
Expand All @@ -35,39 +41,24 @@ limit="${PROD_LINES_LIMIT:-2500}"

# Grandfathered over-limit production files: path|allowance|reason.
# Allowance is lines of production code, not total lines.
#
# Dropped 2026-11-16 (#10603, crate split): `src/cli.rs`, `src/web/routes.rs`
# and `src/web/markdown.rs` no longer exist at those paths and their
# successors are under the plain limit (routes.rs is now 2,096 production
# lines, markdown.rs 1,196; id-cli's modules were split out), so their
# allowances guarded nothing. Add a row only for a file that is over the
# plain limit today.
grandfather_allowance() {
case "$1" in
src/cli.rs)
# Baseline allowance 2026-11-08 at 2,817 production lines (Codex P1
crates/id-directory/src/directory.rs)
# Migrated from `src/directory.rs` after the crate split (#10603).
# Baseline allowance 2026-11-08 at 2,610 production lines (Codex P1
# baseline disposition on PR #7187: explicit allowances at exact
# current counts so the guard lands as a ratchet). The F11.10 split
# that shrinks it is tracked in #1438. Any growth fails.
printf '2817|F11.10 split tracked in #1438 — allowance must only shrink'
return 0
;;
src/directory.rs)
# Baseline allowance 2026-11-08 at 2,610 production lines (Codex P1
# baseline disposition on PR #7187, as above); the F11.10 split
# that shrinks it is tracked in #1438. Any growth fails.
printf '2610|F11.10 split tracked in #1438 — allowance must only shrink'
return 0
;;
src/web/routes.rs)
# Baseline allowance 2026-11-08 at 2,890 production lines (Codex P1
# baseline disposition on PR #7187, as above); the F11.10 split
# that shrinks it is tracked in #1438. Any growth fails.
printf '2890|F11.10 split tracked in #1438 — allowance must only shrink'
return 0
;;
src/web/markdown.rs)
# Grandfathered 2026-11-03 at 5,312 production lines; baseline
# re-established 2026-11-08 at 6,232 production lines (growth landed
# on main before the guard merged; Codex P1 baseline disposition on
# PR #7187). The F11.10 split that shrinks it is tracked in #1438
# (queue task 6599). Any growth fails.
printf '6232|F11.10 split tracked in #1438 — allowance must only shrink'
return 0
;;
esac
return 1
}
Expand All @@ -85,10 +76,36 @@ test_only_reason() {
printf 'module-gated test module (#[cfg(test)] mod tests in src/world_session/mod.rs)'
return 0
;;
src/cli/tests.rs)
printf 'module-gated test module (#[cfg(test)] mod tests in src/cli/mod.rs)'
return 0
;;
esac
return 1
}

# Package-relative lookup key: strip a leading `crates/<crate>/` so rows
# stay valid across the crate split (#10603).
normalize_rel() {
local rel="$1"
if [[ "$rel" == crates/*/* ]]; then
rel="${rel#crates/}"
printf '%s' "${rel#*/}"
else
printf '%s' "$rel"
fi
}

# Rows may be keyed by their real path (post-split) or by the normalized
# `src/...` form (pre-split and across crate moves): try exact first.
match_grandfather() {
grandfather_allowance "$1" || grandfather_allowance "$(normalize_rel "$1")"
}

match_test_only() {
test_only_reason "$1" || test_only_reason "$(normalize_rel "$1")"
}

is_skipped_dir() {
case "$1" in
tests/* | vendor/* | target/* | node_modules/* | .git/*) return 0 ;;
Expand All @@ -112,7 +129,7 @@ while IFS= read -r file; do
if is_skipped_dir "$rel"; then
continue
fi
if reason="$(test_only_reason "$rel")"; then
if reason="$(match_test_only "$rel")"; then
skipped_test_only=$((skipped_test_only + 1))
echo "test-only: $rel ($reason)"
continue
Expand All @@ -123,7 +140,7 @@ while IFS= read -r file; do
max_lines="$count"
max_file="$rel"
fi
if entry="$(grandfather_allowance "$rel")"; then
if entry="$(match_grandfather "$rel")"; then
grandfather_hits=$((grandfather_hits + 1))
allowance="${entry%%|*}"
greason="${entry#*|}"
Expand Down