From 10e2172d877ff74c27d357b3ab1a858e6ca14857 Mon Sep 17 00:00:00 2001 From: repo-worker-tmp-code-b Date: Sun, 15 Nov 2026 22:33:11 -0600 Subject: [PATCH] id(scripts): resolve prod-lines rows in the post-crate-split layout (#10603) The grandfather and test-only tables were keyed on pre-split paths (src/cli.rs, src/directory.rs, src/web/*.rs, src/encryption/tests.rs, src/world_session/tests.rs). After the crate split the scan produces crates//src/... paths, so no row could match: the guard reported module-gated test modules and an explicitly grandfathered file as over-limit, and the ratchet guarded nothing. Lookups now try the real path first and then a normalized key with the leading crates// stripped, so a row keeps working across a crate move. The directory row moves to its crate path, the three obsolete pre-split rows are dropped (their successors are under the plain limit), and the missing src/cli/tests.rs test-only row is added. prod-lines-check-test.sh gains crate-layout fixtures: module-gated test modules under crates/x/src/..., an over-limit crate file, and a grandfathered crate file that passes at its allowance and fails one line later. On the real tree the guard now fails only on the three files tracked by #8590, #8592 and #8593, and reports directory.rs as grandfathered at 2,536 <= 2,610. --- pkgs/id/scripts/prod-lines-check-test.sh | 28 +++++++--- pkgs/id/scripts/prod-lines-check.sh | 71 +++++++++++++++--------- 2 files changed, 64 insertions(+), 35 deletions(-) diff --git a/pkgs/id/scripts/prod-lines-check-test.sh b/pkgs/id/scripts/prod-lines-check-test.sh index 3744da8737..cb1267a0f9 100755 --- a/pkgs/id/scripts/prod-lines-check-test.sh +++ b/pkgs/id/scripts/prod-lines-check-test.sh @@ -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//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 diff --git a/pkgs/id/scripts/prod-lines-check.sh b/pkgs/id/scripts/prod-lines-check.sh index e7c12766b5..22a61f38d9 100755 --- a/pkgs/id/scripts/prod-lines-check.sh +++ b/pkgs/id/scripts/prod-lines-check.sh @@ -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//` +# (#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 @@ -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 } @@ -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//` 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 ;; @@ -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 @@ -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#*|}"