Skip to content

Commit 8898b4e

Browse files
feat(gates): a line ceiling on every file already in facade form (#34103)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} --> _Requested by **Steedos** · [project thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbNTugWasvhTMrtCZiFGrZYK)_ Part of #33949. This PR is ruling item 2 (the narrow line ceiling). Item 1 (eight codemod splits, one at a time) stays open on the card, and split 1 (objectql `registry.ts`) follows as its own PR. Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:给已拆成 facade 形态的 3 个文件(protocol.ts、objectql engine.ts、sql-driver.ts)加了行数上限,上限 = 今天 main 上的行数 + 100;门禁复用现有的 `check:facade-delegation-only`,没有新脚本、没有新 workflow。 - 为什么改:落实 #33949 裁决第 2 条「窄形式上限」。拆过的文件近 5 天又长了 150 到 180 行,没有上限就会重新长回热点文件。 - 风险与回滚:只改了门禁脚本和它的登记表,不发布任何包。超限时是 CI 报错,不改运行时行为。回滚就是 revert 本 PR。 - 先看:`scripts/facade-delegation-registry.json` 的 `ceilings` 三行(数字);再看 `scripts/check-facade-delegation-only.mjs` 里的 `CEILING_MARGIN`(为什么是 100)和 `checkCeilings`。 - 两分钟验证:`node scripts/check-facade-delegation-only.mjs`,预期最后几行显示每个文件「11605 lines, ceiling 11705 (100 left)」这样的余量,退出码 0。 - 需要你做的:无,席位落地。 ## What changes `scripts/check-facade-delegation-only.mjs` reads a third list in `scripts/facade-delegation-registry.json`, `ceilings`, one row per registered facade FILE: | file | baseLines @ 63db724 | maxLines | |:--|--:|--:| | `packages/metadata-protocol/src/protocol.ts` | 11,605 | 11,705 | | `packages/objectql/src/engine.ts` | 6,754 | 6,854 | | `packages/drivers/driver-sql/src/sql-driver.ts` | 9,971 | 10,071 | Each row is `{ file, baseLines, baseCommit, maxLines, ruling }`. The gate refuses: - a facade file over its `maxLines`. The message tells the author to put the new code in a new module, and says raising a ceiling is maintainer-only: it needs a maintainer ruling, cited as the row's `ruling`, with `baseLines` and `baseCommit` re-measured; - a registered facade file with no ceiling row, so the PR that registers the next facade sets its ceiling in the same edit; - a ceiling on a file that is not a registered facade. The ruling: a file not yet split takes no ceiling; - `maxLines` outside `baseLines` to `baseLines + CEILING_MARGIN`. A ceiling is the measured count plus the margin, never a number picked to fit; - a malformed field, an unknown key, or two rows for one file. **The margin is 100 lines, flat (`CEILING_MARGIN`).** Two readings on 63db724 set it: - **In-flight work.** The largest net addition any open PR makes to a facade file is +25 lines: `engine.ts`, summed across PRs #34043, #34025, #33897 and #33652. `protocol.ts` gets +9 (#33885) and `sql-driver.ts` none. That was measured over all 73 open PRs (53 carry files) through the REST files list. So 100 does not red a PR that was reviewed before the ceiling existed. - **Regrowth.** Over the last five days `protocol.ts` grew +178 (11,427 to 11,605) and `engine.ts` +157 (6,597 to 6,754), all of it delegation stubs and docblocks. At that rate 100 lines is about three days. A file that starts growing again meets its ceiling within a week, not after another thousand lines. One number fits every file because the growth comes per member (a stub plus its docblock), not in proportion to the file's size. There is no new script, workflow or `package.json` chain. CI already runs `pnpm check:facade-delegation-only` (`--self-test`, then the gate) in `Lint & Repo Gates`, step `facade-delegation-only`. ## Tests The self-test grows from 38 to 44 batteries (`SELF_TEST_BATTERY_FLOOR` 38 to 44): - C1: over the ceiling is RED. The test checks the count and the overage, the new-module fix line and the `⛔ MAINTAINER-ONLY` raise wording. - C2: at the ceiling is GREEN, with or without a last newline, and the count is reported. - C3: no ceiling row is RED. - C4: a ceiling on an unsplit file is RED. - C5: above base plus margin, or below base, is RED. - C6: a bad count, commit or ruling, an unknown key, a duplicate row, or a registry with no `ceilings` array is RED. Existing fixtures get a roomy ceiling by default, so the H/A/E/N rows still judge delegation alone. <details><summary>Ablation (each leg through scripts/ablation-replace.mjs, restore proven blob == HEAD, `git diff HEAD` empty)</summary> ```text anchor if (wellFormed && lines > row.maxLines) { -> if (wellFormed && lines > row.maxLines && false) { ok mutation landed: anchor 1 -> 0, blob 5ea4924 -> 957d6dcf8e4e ✗ C1 a facade file over its line ceiling → RED telling the author to use a new module, raising MAINTAINER-ONLY ok restored: blob == HEAD (5ea4924) anchor if (byFile.has(file)) continue; -> if (byFile.has(file) || true) continue; ok mutation landed: anchor 1 -> 0, blob 5ea4924 -> 456d3858653f ✗ C3 a registered facade file with no ceiling row → RED expected a problem matching /^pkg\/src\/facade\.ts registered as a facade but carries no line ceiling/, got [] ok restored: blob == HEAD (5ea4924) anchor if (!classesOfFile.has(row.file)) { -> if (false) { ok mutation landed: anchor 1 -> 0, blob 5ea4924 -> e075b61ce296 ✗ C4 a ceiling on a file that is not a registered facade → RED (a file not yet split takes none) ok restored: blob == HEAD (5ea4924) anchor (row.maxLines < row.baseLines || row.maxLines > row.baseLines + CEILING_MARGIN)) { -> (row.maxLines < row.baseLines)) { ok mutation landed: anchor 1 -> 0, blob 5ea4924 -> 56eae464ba7a ✗ C5 a ceiling above its base plus the margin, or below its base → RED ok restored: blob == HEAD (5ea4924) ``` The first C3 attempt used the replacement `continue;`, which is a substring of the anchor. The tool refused it as a no-op ("the replacement count moved 15 -> 15, a rise of 0, not the declared 1"). It was re-run with a replacement unique in the file. </details> <details><summary>The real files against a lowered ceiling (scratch registry, protocol.ts maxLines 11604)</summary> ```text ✗ check-facade-delegation-only: 1 problem(s). A registered facade keeps delegations only (ruling 6624258595 item 3) and stays within its line ceiling (ruling 6897467376 item 2). ✗ packages/metadata-protocol/src/protocol.ts is 11605 lines, over its line ceiling of 11604 by 1 (measured 11600 at 63db724, plus the margin; ruling 6897467376). fix: a file in facade form does not grow: put the new code in a new module (a facet file beside the facade, or a module of its own) and import it from there, instead of adding lines here. Raising a ceiling is ⛔ MAINTAINER-ONLY: it needs a maintainer ruling (ruling 6897467376 item 2), recorded in the row as its `ruling`, with `baseLines` and `baseCommit` re-measured. exit 1 ``` </details> ## Acceptance notes - **Days to the ceiling.** At the measured regrowth (about 35 lines a day on `protocol.ts` and about 31 on `engine.ts`), the first ceiling is reached in about three days. That is the ruling working as written: new code goes to a new module, or the maintainer raises the ceiling. Seats adding facade members should expect to see it soon. - **Workflow comment.** The `lint.yml` comment above the `facade-delegation-only` step describes the delegation rule only. It is left untouched because workflows are a governed surface outside this PR's file surface. The script header is the authority, and it now documents the ceiling. - **Split 1.** Split 1 (`packages/objectql/src/registry.ts`) registers its facade with its post-split ceiling in its own PR, as the header now requires. ## Verification Head `cfb690a278` (the branch merged with origin/main `27c2f1ea32`); every reading below is from that tree. <details><summary>Local gates (dispatch-gates derivation, 31 families, each exit code captured before any pipe)</summary> ```text node scripts/pm/dispatch-gates.mjs --repo objectstack-ai/objectstack --ran ran.txt ✓ dispatch-gates --ran: 31 derived famil(ies) accounted for — 31 run, 0 NOT-MEASURED (a DERIVED zero — all 31 recorded an exit code and none of them is 3). exit 0 for every derived command, among them: pnpm check:facade-delegation-only (self-test 44 cases pass; 3 files within their line ceiling) pnpm check:ratchet-remedy-authority (286 scripts swept; 14 mark the expanding remedy ⛔ MAINTAINER-ONLY) pnpm check:watch-hint-literal, check:nul-bytes, check:parse-guard, check:entry-guard, check:scripts-symbol-anchors pnpm check:pm-dispatch-gates (fast tier: 2205 cases pass, 352.7s) pnpm lint exit 0 ``` </details> No changeset: the diff is `scripts/**` only, which ships in no package's `files[]`, so it is labelled `skip-changeset`. --- _Generated by [Claude Code](https://claude.ai/code/session_01QsR2jTkZnXtRhuEiiyidvJ)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01QsR2jTkZnXtRhuEiiyidvJ Co-authored-by: Claude <noreply@anthropic.com>
1 parent 31eb2ae commit 8898b4e

2 files changed

Lines changed: 215 additions & 18 deletions

File tree

‎scripts/check-facade-delegation-only.mjs‎

Lines changed: 192 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
*
2727
* ## What it reads
2828
*
29-
* `scripts/facade-delegation-registry.json`, two lists:
29+
* `scripts/facade-delegation-registry.json`, three lists (the third,
30+
* `ceilings`, is § The line ceiling below):
3031
*
3132
* facades { file, class, card } a file that has LANDED in facade form,
3233
* the class in it that is the facade, and
@@ -42,7 +43,7 @@
4243
* `class` (in a file with one facade the `class` may be left out).
4344
*
4445
* The next split adds one `facades` row, and a NEW facade file also adds its
45-
* path to `DECLARED_WATCH_HINTS` below (the self-test refuses the registry and
46+
* `ceilings` row and its path to `DECLARED_WATCH_HINTS` below (the self-test refuses the registry and
4647
* the declaration disagreeing). ⛔ A file joins only once it is in
4748
* facade form on `main`, so the gate never reds `main` ahead of a landing: the
4849
* PR that lands the facade (or the first PR after it) adds the row.
@@ -142,6 +143,36 @@
142143
* • an EMPTY `facades` list is legal (nothing has landed yet) and the
143144
* success line says, in words, that the gate guards nothing.
144145
*
146+
* ## The line ceiling — a facade file does not grow back (ruling 6897467376 item 2)
147+
*
148+
* Delegation-only keeps logic out of the facade class, but it does not stop
149+
* the FILE growing: each new member is a stub plus its docblock, and measured
150+
* over the five days to 63db7240aa `protocol.ts` regrew 178 lines (11,427 →
151+
* 11,605) and objectql `engine.ts` 157 (6,597 → 6,754). The maintainer ruled a
152+
* line ceiling in the narrow form only, and this gate carries it as a third
153+
* list in the same registry:
154+
*
155+
* ceilings { file, baseLines, baseCommit, maxLines, ruling }
156+
* one row per registered facade FILE:
157+
* its line count measured at
158+
* `baseCommit`, the ceiling, and the
159+
* ruling record that set it.
160+
*
161+
* • a facade file over its `maxLines` → red,
162+
* telling the author to put the new code in a new module
163+
* • a registered facade file with no ceiling row → red
164+
* (the PR that registers a facade sets its ceiling with it)
165+
* • a ceiling on a file that is not a registered facade → red
166+
* (the ruling: a file not yet split takes no ceiling)
167+
* • `maxLines` outside `baseLines` … `baseLines + CEILING_MARGIN` → red
168+
* (a ceiling is the measured count plus the margin, never a number
169+
* picked to fit; a raise re-measures `baseLines` under a new ruling)
170+
* • a missing or malformed field, a second row for one file → red
171+
*
172+
* The margin is CEILING_MARGIN, one flat number for every file; why that
173+
* number is written beside it. Lines are counted as `wc -l` counts them on a
174+
* file that ends in a newline, and a last line without one still counts.
175+
*
145176
* ## What it does NOT judge (measured, so nobody assumes it)
146177
*
147178
* Only the members of the registered class. Top-level functions in the facade
@@ -151,8 +182,9 @@
151182
* head `bba9d24d`: `protocol.ts` holds two top-level functions (24 lines) and
152183
* one class, and no member of either facade head forwards into its own file.
153184
*
154-
* Exit codes: 0 every registered facade is delegation-only (exceptions aside);
155-
* 1 a body, a registry problem or an unreadable facade; 2 bad arguments;
185+
* Exit codes: 0 every registered facade is delegation-only (exceptions aside)
186+
* and within its line ceiling; 1 a body, a file over its ceiling, a registry
187+
* problem or an unreadable facade; 2 bad arguments;
156188
* 3 a source that does not parse.
157189
*/
158190

@@ -199,6 +231,28 @@ const DECLARED_WATCH_HINTS = [
199231
const CARD_REF = /^#[1-9][0-9]*$/;
200232
const FACADE_KEYS = Object.freeze(['file', 'class', 'card']);
201233
const EXCEPTION_KEYS = Object.freeze(['file', 'class', 'member', 'card', 'reason']);
234+
const CEILING_KEYS = Object.freeze(['file', 'baseLines', 'baseCommit', 'maxLines', 'ruling']);
235+
const COMMIT_REF = /^[0-9a-f]{10,40}$/;
236+
const RULING_REF = /^[1-9][0-9]*$/;
237+
238+
/** The ruling record that named the ceiling and its narrow form. */
239+
export const CEILING_RULING = '6897467376';
240+
241+
/**
242+
* Lines a facade file may grow past its measured count before the gate reds.
243+
*
244+
* 100, flat. Two readings on 63db7240aa set it. It absorbs the work already in
245+
* flight four times over: the largest net addition any open PR makes to a
246+
* facade file is +25 lines (objectql `engine.ts`, across four open PRs;
247+
* `protocol.ts` +9, `sql-driver.ts` none), so the ceiling does not red a PR
248+
* that was reviewed before it existed. And it is small against the regrowth:
249+
* about three days at the rate `protocol.ts` (+178) and `engine.ts` (+157)
250+
* grew over the last five, so a file that starts growing again meets the
251+
* ceiling inside a week instead of after another thousand lines. One number
252+
* for every file, because the regrowth is per member (a stub and its
253+
* docblock), not proportional to the file's size.
254+
*/
255+
export const CEILING_MARGIN = 100;
202256

203257
/** One level of nested call in an argument: `protocolHost(this)`. Two is logic. */
204258
const MAX_NESTED_CALL_DEPTH = 1;
@@ -208,6 +262,19 @@ export const FIX_LINE =
208262
'(`return <Facet>.<member>(<host>, ...args)`); a member that cannot move yet takes an ' +
209263
`exceptions row in ${REGISTRY_FILE} naming the card that will move it`;
210264

265+
export const CEILING_FIX_LINE =
266+
'a file in facade form does not grow: put the new code in a new module (a facet file beside ' +
267+
'the facade, or a module of its own) and import it from there, instead of adding lines here. ' +
268+
`Raising a ceiling is ⛔ MAINTAINER-ONLY: it needs a maintainer ruling (ruling ${CEILING_RULING} ` +
269+
'item 2), recorded in the row as its `ruling`, with `baseLines` and `baseCommit` re-measured';
270+
271+
/** Lines as `wc -l` counts them, plus a last line that has no newline. */
272+
export function countLines(text) {
273+
if (text === '') return 0;
274+
const n = text.split('\n').length;
275+
return text.endsWith('\n') ? n - 1 : n;
276+
}
277+
211278
// ── The delegation grammar ─────────────────────────────────────────────────
212279

213280
function unwrap(e) {
@@ -680,21 +747,23 @@ function unknownKeys(row, allowed) {
680747

681748
/**
682749
* Judge a registry against the files it names.
683-
* @param {{ facades: unknown[], exceptions: unknown[] }} registry
750+
* @param {{ facades: unknown[], exceptions: unknown[], ceilings: unknown[] }} registry
684751
* @param {(file: string) => string | null} readFile null = the file does not exist
685-
* @returns {{ problems: Array<{ where: string, message: string }>, facades: object[], excepted: object[] }}
752+
* @returns {{ problems: Array<{ where: string, message: string }>, facades: object[], excepted: object[], ceilings: object[] }}
686753
*/
687754
export function checkRegistry(registry, readFile) {
688755
const problems = [];
689756
const facades = [];
690757
const excepted = [];
758+
const ceilings = [];
691759
const problem = (where, message) => problems.push({ where, message });
692760

693-
if (!registry || typeof registry !== 'object' || !Array.isArray(registry.facades) || !Array.isArray(registry.exceptions)) {
694-
problem(REGISTRY_FILE, 'the registry must be an object with a `facades` array and an `exceptions` array');
695-
return { problems, facades, excepted };
761+
if (!registry || typeof registry !== 'object' || !Array.isArray(registry.facades) || !Array.isArray(registry.exceptions) ||
762+
!Array.isArray(registry.ceilings)) {
763+
problem(REGISTRY_FILE, 'the registry must be an object with a `facades` array, an `exceptions` array and a `ceilings` array');
764+
return { problems, facades, excepted, ceilings };
696765
}
697-
const extraTop = unknownKeys(registry, ['facades', 'exceptions']);
766+
const extraTop = unknownKeys(registry, ['facades', 'exceptions', 'ceilings']);
698767
if (extraTop.length) problem(REGISTRY_FILE, `unknown top-level key(s) ${extraTop.join(', ')}`);
699768

700769
const facadeKey = (file, cls) => `${file}\u0000${cls}`;
@@ -799,7 +868,55 @@ export function checkRegistry(registry, readFile) {
799868
problem(`${f.file}:${m.line}`, `${f.class}.${m.key} holds a body, not a delegation: ${m.why}.\n fix: ${FIX_LINE}.`);
800869
}
801870
}
802-
return { problems, facades, excepted };
871+
872+
checkCeilings(registry.ceilings, classesOfFile, readFile, problem, ceilings);
873+
return { problems, facades, excepted, ceilings };
874+
}
875+
876+
/**
877+
* The `ceilings` list (ruling 6897467376 item 2): one row per registered facade
878+
* file, none for any other file, each well-formed, and each file within it.
879+
*/
880+
function checkCeilings(rows, classesOfFile, readFile, problem, out) {
881+
const byFile = new Map();
882+
const isCount = (v) => Number.isInteger(v) && v > 0;
883+
rows.forEach((row, i) => {
884+
const where = `${REGISTRY_FILE} ceilings[${i}]`;
885+
if (!row || typeof row !== 'object') return problem(where, 'a row must be an object');
886+
const extra = unknownKeys(row, CEILING_KEYS);
887+
if (extra.length) problem(where, `unknown key(s) ${extra.join(', ')} (a row carries ${CEILING_KEYS.join(', ')})`);
888+
if (typeof row.file !== 'string' || !row.file) return problem(where, 'a row must name its `file`');
889+
if (!classesOfFile.has(row.file)) {
890+
return problem(where, `${row.file}: a line ceiling applies only to a file already in facade form, and this file is not a registered facade (ruling ${CEILING_RULING} item 2: a file not yet split takes no ceiling). Register the facade first, or delete the row.`);
891+
}
892+
if (byFile.has(row.file)) return problem(where, `${row.file} has two ceiling rows`);
893+
byFile.set(row.file, row);
894+
let wellFormed = true;
895+
const bad = (message) => { wellFormed = false; problem(where, `${row.file}: ${message}`); };
896+
if (!isCount(row.baseLines)) bad(`\`baseLines\` is the file's measured line count, a positive integer; got ${JSON.stringify(row.baseLines)}`);
897+
if (!isCount(row.maxLines)) bad(`\`maxLines\` is the ceiling, a positive integer; got ${JSON.stringify(row.maxLines)}`);
898+
if (typeof row.baseCommit !== 'string' || !COMMIT_REF.test(row.baseCommit)) {
899+
bad(`\`baseCommit\` names the commit \`baseLines\` was measured on, 10 to 40 lowercase hex digits; got ${JSON.stringify(row.baseCommit)}`);
900+
}
901+
if (typeof row.ruling !== 'string' || !RULING_REF.test(row.ruling)) {
902+
bad(`\`ruling\` names the maintainer ruling record that set this ceiling, as its record id (\`${CEILING_RULING}\`); got ${JSON.stringify(row.ruling)}`);
903+
}
904+
if (isCount(row.baseLines) && isCount(row.maxLines) &&
905+
(row.maxLines < row.baseLines || row.maxLines > row.baseLines + CEILING_MARGIN)) {
906+
bad(`\`maxLines\` ${row.maxLines} must sit between \`baseLines\` ${row.baseLines} and \`baseLines\` + ${CEILING_MARGIN} (CEILING_MARGIN): a ceiling is the measured count plus the margin, never a number picked to fit. Raising a ceiling is ⛔ MAINTAINER-ONLY: it needs a maintainer ruling, cited as the row's \`ruling\`, with \`baseLines\` and \`baseCommit\` re-measured`);
907+
}
908+
const text = readFile(row.file);
909+
if (text === null) return; // the missing facade file is refused above
910+
const lines = countLines(text);
911+
out.push({ file: row.file, lines, maxLines: row.maxLines, ruling: row.ruling });
912+
if (wellFormed && lines > row.maxLines) {
913+
problem(row.file, `is ${lines} lines, over its line ceiling of ${row.maxLines} by ${lines - row.maxLines} (measured ${row.baseLines} at ${row.baseCommit}, plus the margin; ruling ${row.ruling}).\n fix: ${CEILING_FIX_LINE}.`);
914+
}
915+
});
916+
for (const file of classesOfFile.keys()) {
917+
if (byFile.has(file)) continue;
918+
problem(file, `registered as a facade but carries no line ceiling (ruling ${CEILING_RULING} item 2). The PR that registers a facade adds its \`ceilings\` row: the file's line count as \`baseLines\`, the commit it was measured on as \`baseCommit\`, \`maxLines\` = \`baseLines\` + ${CEILING_MARGIN}, and \`ruling\` "${CEILING_RULING}".`);
919+
}
803920
}
804921

805922
// ── Self-test ───────────────────────────────────────────────────────────────
@@ -851,17 +968,29 @@ const SELF_TEST_BATTERIES = Object.freeze({
851968
'N5 an empty registry → GREEN with nothing guarded, never a crash': 1,
852969
'N6 the committed registry is well-formed against this checkout': 1,
853970
'N7 the declared watch hints are exactly the committed registry\'s facade files': 1,
971+
'C1 a facade file over its line ceiling → RED telling the author to use a new module, raising MAINTAINER-ONLY': 1,
972+
'C2 a facade file at its ceiling, with or without a last newline → GREEN, its count reported': 1,
973+
'C3 a registered facade file with no ceiling row → RED': 1,
974+
'C4 a ceiling on a file that is not a registered facade → RED (a file not yet split takes none)': 1,
975+
'C5 a ceiling above its base plus the margin, or below its base → RED': 1,
976+
'C6 a ceiling row with a bad count, commit or ruling, an unknown key, or twice for one file → RED': 1,
854977
});
855-
const SELF_TEST_BATTERY_FLOOR = 38;
978+
const SELF_TEST_BATTERY_FLOOR = 44;
856979

857980
function selfTest() {
858981
const FILE = 'pkg/src/facade.ts';
859982
const facadeOf = (body, extraTop = '') =>
860983
`${extraTop}export class Facade {\n private engine: unknown;\n${body}\n ok(a: string) { return Facet.ok(host(this), a); }\n}\n`;
861-
const reg = (facadeRows, exceptions = []) => ({ facades: facadeRows, exceptions });
984+
// Every fixture file gets a well-formed ceiling far above its size, so the
985+
// delegation cases judge delegation alone; the C rows pass their own.
986+
const ceilingFor = (file, baseLines = 1000, extra = {}) =>
987+
({ file, baseLines, baseCommit: '0123456789', maxLines: baseLines + CEILING_MARGIN, ruling: CEILING_RULING, ...extra });
988+
const roomyCeilings = (facadeRows) =>
989+
[...new Set(facadeRows.map((r) => r?.file).filter((f) => typeof f === 'string' && f))].map((f) => ceilingFor(f));
990+
const reg = (facadeRows, exceptions = [], ceilings = roomyCeilings(facadeRows)) => ({ facades: facadeRows, exceptions, ceilings });
862991
const row = { file: FILE, class: 'Facade', card: '#1' };
863-
const run = (text, exceptions = [], rows = [row]) =>
864-
checkRegistry(reg(rows, exceptions), (f) => (f === FILE ? text : null));
992+
const run = (text, exceptions = [], rows = [row], ceilings = undefined) =>
993+
checkRegistry(reg(rows, exceptions, ceilings), (f) => (f === FILE ? text : null));
865994
const red = (r, re) =>
866995
r.problems.some((p) => re.test(`${p.where} ${p.message}`))
867996
? null
@@ -1064,6 +1193,48 @@ function selfTest() {
10641193
doubled.length === 0 ? null : `DECLARED_WATCH_HINTS names ${doubled.join(', ')} twice`,
10651194
);
10661195
} },
1196+
{ label: 'C1 a facade file over its line ceiling → RED telling the author to use a new module, raising MAINTAINER-ONLY', run: () => {
1197+
const text = facadeOf('');
1198+
const lines = countLines(text);
1199+
const r = run(text, [], [row], [ceilingFor(FILE, lines - 1, { maxLines: lines - 1 })]);
1200+
if (r.problems.length !== 1) return `expected exactly 1 problem, got ${JSON.stringify(r.problems.map((p) => `${p.where} ${p.message}`))}`;
1201+
return all(
1202+
red(r, new RegExp(`^pkg/src/facade\\.ts is ${lines} lines, over its line ceiling of ${lines - 1} by 1 `)),
1203+
red(r, /fix: a file in facade form does not grow: put the new code in a new module/),
1204+
red(r, /Raising a ceiling is ⛔ MAINTAINER-ONLY: it needs a maintainer ruling/),
1205+
);
1206+
} },
1207+
{ label: 'C2 a facade file at its ceiling, with or without a last newline → GREEN, its count reported', run: () => {
1208+
const text = facadeOf('');
1209+
const lines = countLines(text);
1210+
const atCeiling = [ceilingFor(FILE, lines, { maxLines: lines })];
1211+
const r = run(text, [], [row], atCeiling);
1212+
return all(
1213+
green(r),
1214+
green(run(text.replace(/\n$/, ''), [], [row], atCeiling)),
1215+
lines === text.split('\n').length - 1 ? null : `countLines(${JSON.stringify(text)}) = ${lines}, not the wc -l count`,
1216+
r.ceilings.length === 1 && r.ceilings[0].lines === lines && r.ceilings[0].maxLines === lines ? null : `ceilings ${JSON.stringify(r.ceilings)}`,
1217+
);
1218+
} },
1219+
{ label: 'C3 a registered facade file with no ceiling row → RED', run: () =>
1220+
red(run(facadeOf(''), [], [row], []), /^pkg\/src\/facade\.ts registered as a facade but carries no line ceiling/) },
1221+
{ label: 'C4 a ceiling on a file that is not a registered facade → RED (a file not yet split takes none)', run: () =>
1222+
red(run(facadeOf(''), [], [row], [ceilingFor(FILE), ceilingFor('pkg/src/big.ts')]),
1223+
/ceilings\[1\] pkg\/src\/big\.ts: a line ceiling applies only to a file already in facade form/) },
1224+
{ label: 'C5 a ceiling above its base plus the margin, or below its base → RED', run: () => all(
1225+
red(run(facadeOf(''), [], [row], [ceilingFor(FILE, 1000, { maxLines: 1000 + CEILING_MARGIN + 1 })]),
1226+
/`maxLines` \d+ must sit between `baseLines` 1000 and `baseLines` \+ \d+ .*⛔ MAINTAINER-ONLY/),
1227+
red(run(facadeOf(''), [], [row], [ceilingFor(FILE, 1000, { maxLines: 999 })]), /`maxLines` 999 must sit between/),
1228+
) },
1229+
{ label: 'C6 a ceiling row with a bad count, commit or ruling, an unknown key, or twice for one file → RED', run: () => all(
1230+
red(run(facadeOf(''), [], [row], [ceilingFor(FILE, 1000, { baseLines: '1000' })]), /`baseLines` is the file's measured line count/),
1231+
red(run(facadeOf(''), [], [row], [ceilingFor(FILE, 1000, { maxLines: 10.5 })]), /`maxLines` is the ceiling, a positive integer/),
1232+
red(run(facadeOf(''), [], [row], [ceilingFor(FILE, 1000, { baseCommit: 'main' })]), /`baseCommit` names the commit/),
1233+
red(run(facadeOf(''), [], [row], [ceilingFor(FILE, 1000, { ruling: undefined })]), /`ruling` names the maintainer ruling record/),
1234+
red(run(facadeOf(''), [], [row], [ceilingFor(FILE, 1000, { max: 3 })]), /ceilings\[0\] unknown key\(s\) max/),
1235+
red(run(facadeOf(''), [], [row], [ceilingFor(FILE), ceilingFor(FILE)]), /pkg\/src\/facade\.ts has two ceiling rows/),
1236+
red(checkRegistry({ facades: [], exceptions: [] }, () => null), /a `ceilings` array/),
1237+
) },
10671238
];
10681239

10691240
const batterySeen = new Map();
@@ -1164,7 +1335,7 @@ function main() {
11641335
console.error(`✗ check-facade-delegation-only: ${loadError}`);
11651336
process.exit(1);
11661337
}
1167-
const { problems, facades, excepted } = result;
1338+
const { problems, facades, excepted, ceilings } = result;
11681339

11691340
if (opts.verbose) {
11701341
for (const f of facades) {
@@ -1176,7 +1347,7 @@ function main() {
11761347
}
11771348

11781349
if (problems.length > 0) {
1179-
console.error(`✗ check-facade-delegation-only: ${problems.length} problem(s). A registered facade keeps delegations only (ruling 6624258595 item 3).\n`);
1350+
console.error(`✗ check-facade-delegation-only: ${problems.length} problem(s). A registered facade keeps delegations only (ruling 6624258595 item 3) and stays within its line ceiling (ruling ${CEILING_RULING} item 2).\n`);
11801351
for (const p of problems) console.error(` ✗ ${p.where} ${p.message}`);
11811352
process.exit(1);
11821353
}
@@ -1204,8 +1375,11 @@ function main() {
12041375
);
12051376
for (const [shape, n] of [...shapes].sort((a, b) => b[1] - a[1])) console.log(` ${String(n).padStart(4)} ${shape}`);
12061377
}
1378+
for (const c of ceilings) {
1379+
console.log(`✓ ${c.file}: ${c.lines} lines, ceiling ${c.maxLines} (${c.maxLines - c.lines} left; ruling ${c.ruling})`);
1380+
}
12071381
const files = new Set(facades.map((f) => f.file)).size;
1208-
console.log(`✓ check-facade-delegation-only: ${facades.length} facade class(es) in ${files} file(s) hold delegations only, ${excepted.length} named exception(s).`);
1382+
console.log(`✓ check-facade-delegation-only: ${facades.length} facade class(es) in ${files} file(s) hold delegations only, ${excepted.length} named exception(s); ${ceilings.length} file(s) within their line ceiling.`);
12091383
}
12101384

12111385
if (isEntrypoint(import.meta.url)) {

0 commit comments

Comments
 (0)