Home() useState 66->52, useRef 41->39. Shell-facing fields merge into one object; subtree state lives in useRectificationSurface. Chat props 20->7. Growth contract rebaselined. Zero behavior/copy change.
55 lines
2.1 KiB
TypeScript
55 lines
2.1 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { readFileSync } from "node:fs";
|
|
import test from "node:test";
|
|
|
|
const pageSource = readFileSync(new URL("../src/app/page.tsx", import.meta.url), "utf8");
|
|
|
|
// Measured 2026-09-16 after home-state-lowering on origin/staging @ 3b17c1b2.
|
|
// Line count: (pageSource.match(/\n/g) ?? []).length, same as `wc -l` = 1931.
|
|
// Hook counts use \buseState[<(] / \buseRef[<(] so `useState<Type>(` is not missed.
|
|
// Former caps were useState 66 / useRef 41 / lines 1951 on freeze-metric @ 51a65d92.
|
|
// This round moved 14 rectification useStates out of Home (15 → 1 shell object)
|
|
// and 2 rectification refs into useRectificationSurface.
|
|
const PAGE_LINE_COUNT_BASELINE = 1931;
|
|
const PAGE_LINE_COUNT_CAP = PAGE_LINE_COUNT_BASELINE + 150;
|
|
const HOME_USE_STATE_CAP = 52;
|
|
const HOME_USE_REF_CAP = 39;
|
|
|
|
const USE_STATE_RE = /\buseState[<(]/g;
|
|
const USE_REF_RE = /\buseRef[<(]/g;
|
|
|
|
function homeSource(source: string): string {
|
|
const marker = "export default function Home(";
|
|
const start = source.indexOf(marker);
|
|
assert.notEqual(start, -1, "page.tsx must export default function Home(");
|
|
return source.slice(start);
|
|
}
|
|
|
|
function countMatches(source: string, pattern: RegExp): number {
|
|
return source.match(new RegExp(pattern.source, "g"))?.length ?? 0;
|
|
}
|
|
|
|
test("Home() useState count must not grow", () => {
|
|
const n = countMatches(homeSource(pageSource), USE_STATE_RE);
|
|
assert.ok(
|
|
n <= HOME_USE_STATE_CAP,
|
|
`Home() has ${n} useState calls; cap is ${HOME_USE_STATE_CAP}. Extracted hooks and child components should own their own state.`,
|
|
);
|
|
});
|
|
|
|
test("Home() useRef count must not grow", () => {
|
|
const n = countMatches(homeSource(pageSource), USE_REF_RE);
|
|
assert.ok(
|
|
n <= HOME_USE_REF_CAP,
|
|
`Home() has ${n} useRef calls; cap is ${HOME_USE_REF_CAP}. Do not rewrite state as refs to dodge the useState freeze.`,
|
|
);
|
|
});
|
|
|
|
test("page.tsx line count stays within the coarse guardrail", () => {
|
|
const n = (pageSource.match(/\n/g) ?? []).length;
|
|
assert.ok(
|
|
n <= PAGE_LINE_COUNT_CAP,
|
|
`page.tsx has ${n} lines; cap is ${PAGE_LINE_COUNT_CAP} (${PAGE_LINE_COUNT_BASELINE} baseline + 150).`,
|
|
);
|
|
});
|