mirror of
https://github.com/block/buzz.git
synced 2026-10-27 12:40:30 +00:00
ci: relax file-size ceilings by surface (#6485)
## Summary - raise Desktop Rust's differential file-size ceiling from 1,000 to 1,500 lines - raise Desktop frontend and Mobile ceilings from 1,000 to 1,200 lines - keep Web at 1,000 lines and preserve the existing no-growth ratchet above each ceiling ## Why The flat 1,000-line limit is forcing mechanical trimming in Desktop and Mobile even for small cohesive changes. Surface-specific ceilings relieve that pressure without granting Web or every authored component a blanket 2,000-line budget. ## Testing - `just file-size-check` - `cd desktop && pnpm exec biome check scripts/check-file-sizes.mjs` - `node --check mobile/scripts/check-file-sizes.mjs` - `git diff HEAD^ --check` Signed-off-by: Wes <wesbillman@users.noreply.github.com> Co-authored-by: Carl <32a2e2c9d428ee08902cab75d956da2c1d235a22d4766b0dd4138bf6e2e5db1d@buzz.block.builderlab.xyz>
This commit is contained in:
@@ -1,9 +1,19 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { execFileSync } from "node:child_process";
|
||||
import { mkdtempSync } from "node:fs";
|
||||
import { execFileSync, spawnSync } from "node:child_process";
|
||||
import {
|
||||
copyFileSync,
|
||||
mkdirSync,
|
||||
mkdtempSync,
|
||||
realpathSync,
|
||||
symlinkSync,
|
||||
writeFileSync,
|
||||
} from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import test from "node:test";
|
||||
import { policy as desktopPolicy } from "../desktop/scripts/check-file-sizes.mjs";
|
||||
import { policy as mobilePolicy } from "../mobile/scripts/check-file-sizes.mjs";
|
||||
import { policy as webPolicy } from "../web/scripts/check-file-sizes.mjs";
|
||||
import {
|
||||
allowedLineCount,
|
||||
countLines,
|
||||
@@ -12,6 +22,8 @@ import {
|
||||
resolveBaseRef,
|
||||
} from "./check-file-sizes-core.mjs";
|
||||
|
||||
const repoRoot = path.resolve(import.meta.dirname, "..");
|
||||
|
||||
function git(repo, ...args) {
|
||||
// These fixture repositories inherit both hook configuration and Git's
|
||||
// repository-local environment when this test runs from pre-push. Isolate
|
||||
@@ -26,6 +38,62 @@ function git(repo, ...args) {
|
||||
}).trim();
|
||||
}
|
||||
|
||||
function createEntrypointFixture({
|
||||
surface,
|
||||
files,
|
||||
lineDelta = 1,
|
||||
symlinkEntrypoint = false,
|
||||
}) {
|
||||
const repo = realpathSync(
|
||||
mkdtempSync(path.join(tmpdir(), `file-size-${surface}-`)),
|
||||
);
|
||||
const scriptsDir = path.join(repo, "scripts");
|
||||
const surfaceScriptsDir = path.join(repo, surface, "scripts");
|
||||
mkdirSync(scriptsDir, { recursive: true });
|
||||
mkdirSync(surfaceScriptsDir, { recursive: true });
|
||||
copyFileSync(
|
||||
path.join(repoRoot, "scripts/check-file-sizes-core.mjs"),
|
||||
path.join(scriptsDir, "check-file-sizes-core.mjs"),
|
||||
);
|
||||
for (const fileName of ["check-file-sizes.mjs", "file-size-policy.mjs"]) {
|
||||
copyFileSync(
|
||||
path.join(repoRoot, surface, "scripts", fileName),
|
||||
path.join(surfaceScriptsDir, fileName),
|
||||
);
|
||||
}
|
||||
|
||||
git(repo, "init", "-b", "main");
|
||||
git(repo, "config", "user.name", "Test");
|
||||
git(repo, "config", "user.email", "test@example.com");
|
||||
git(repo, "add", ".");
|
||||
git(repo, "commit", "-m", "base");
|
||||
const base = git(repo, "rev-parse", "HEAD");
|
||||
git(repo, "switch", "-c", "feature");
|
||||
|
||||
for (const { relativeFile, maxLines } of files) {
|
||||
const governedFile = path.join(repo, surface, relativeFile);
|
||||
const lineCount = maxLines + lineDelta;
|
||||
mkdirSync(path.dirname(governedFile), { recursive: true });
|
||||
writeFileSync(governedFile, `${"line\n".repeat(lineCount - 1)}line`);
|
||||
}
|
||||
|
||||
const realEntrypointPath = path.join(
|
||||
surfaceScriptsDir,
|
||||
"check-file-sizes.mjs",
|
||||
);
|
||||
let entrypointPath = realEntrypointPath;
|
||||
if (symlinkEntrypoint) {
|
||||
entrypointPath = path.join(repo, `${surface}-file-size-check.mjs`);
|
||||
symlinkSync(realEntrypointPath, entrypointPath);
|
||||
}
|
||||
const result = spawnSync(realpathSync(process.execPath), [entrypointPath], {
|
||||
cwd: repo,
|
||||
encoding: "utf8",
|
||||
env: { ...process.env, CHECK_FILE_SIZES_BASE: base },
|
||||
});
|
||||
return { result, relativeFiles: files.map(({ relativeFile }) => relativeFile) };
|
||||
}
|
||||
|
||||
test("local base resolution uses the branch merge-base and fails without origin/main", () => {
|
||||
const repo = mkdtempSync(path.join(tmpdir(), "file-size-base-"));
|
||||
git(repo, "init", "-b", "main");
|
||||
@@ -47,12 +115,151 @@ test("local base resolution uses the branch merge-base and fails without origin/
|
||||
);
|
||||
});
|
||||
|
||||
const entrypointCases = [
|
||||
{
|
||||
surface: "desktop",
|
||||
files: [
|
||||
{ relativeFile: "src-tauri/src/oversized.rs", maxLines: 1500 },
|
||||
{ relativeFile: "src-tauri/crates/oversized.rs", maxLines: 1500 },
|
||||
{ relativeFile: "src/app/oversized.ts", maxLines: 1200 },
|
||||
{ relativeFile: "src/features/oversized.tsx", maxLines: 1200 },
|
||||
{ relativeFile: "src/shared/api/oversized.ts", maxLines: 1200 },
|
||||
{ relativeFile: "src/shared/context/oversized.tsx", maxLines: 1200 },
|
||||
{ relativeFile: "src/shared/lib/oversized.ts", maxLines: 1200 },
|
||||
{ relativeFile: "src/shared/ui/oversized.tsx", maxLines: 1200 },
|
||||
{ relativeFile: "src/shared/styles/oversized.css", maxLines: 1200 },
|
||||
],
|
||||
},
|
||||
{
|
||||
surface: "mobile",
|
||||
files: [{ relativeFile: "lib/oversized.dart", maxLines: 1200 }],
|
||||
},
|
||||
{
|
||||
surface: "web",
|
||||
files: [
|
||||
{ relativeFile: "src/app/oversized.ts", maxLines: 1000 },
|
||||
{ relativeFile: "src/features/oversized.tsx", maxLines: 1000 },
|
||||
{ relativeFile: "src/shared/api/oversized.ts", maxLines: 1000 },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
test("surface entrypoints execute every production rule", () => {
|
||||
for (const fixture of entrypointCases) {
|
||||
const { result, relativeFiles } = createEntrypointFixture(fixture);
|
||||
assert.equal(
|
||||
result.status,
|
||||
1,
|
||||
`${fixture.surface} should reject every ceiling + 1: ${result.stderr || result.stdout}`,
|
||||
);
|
||||
for (const relativeFile of relativeFiles) {
|
||||
assert.ok(
|
||||
result.stderr.includes(relativeFile),
|
||||
`${fixture.surface} should report ${relativeFile}: ${result.stderr}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("surface entrypoints execute through symlinked paths", () => {
|
||||
for (const fixture of entrypointCases) {
|
||||
const { result, relativeFiles } = createEntrypointFixture({
|
||||
...fixture,
|
||||
symlinkEntrypoint: true,
|
||||
});
|
||||
assert.equal(
|
||||
result.status,
|
||||
1,
|
||||
`${fixture.surface} symlink should reject ceiling + 1: ${result.stderr || result.stdout}`,
|
||||
);
|
||||
for (const relativeFile of relativeFiles) {
|
||||
assert.ok(
|
||||
result.stderr.includes(relativeFile),
|
||||
`${fixture.surface} symlink should report ${relativeFile}: ${result.stderr}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("surface entrypoints allow every production rule at its ceiling", () => {
|
||||
for (const fixture of entrypointCases) {
|
||||
const { result } = createEntrypointFixture({ ...fixture, lineDelta: 0 });
|
||||
assert.equal(
|
||||
result.status,
|
||||
0,
|
||||
`${fixture.surface} should allow every ceiling: ${result.stderr || result.stdout}`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test("counts empty, LF, and CRLF content with the existing semantics", () => {
|
||||
assert.equal(countLines(""), 0);
|
||||
assert.equal(countLines("one\n"), 2);
|
||||
assert.equal(countLines("one\r\ntwo"), 2);
|
||||
});
|
||||
|
||||
test("surface entrypoints expose the exact ordered production policies", () => {
|
||||
const policies = [
|
||||
[
|
||||
desktopPolicy,
|
||||
[
|
||||
["src-tauri/src", [".rs"], 1500],
|
||||
["src-tauri/crates", [".rs"], 1500],
|
||||
["src/app", [".ts", ".tsx"], 1200],
|
||||
["src/features", [".ts", ".tsx"], 1200],
|
||||
["src/shared/api", [".ts", ".tsx"], 1200],
|
||||
["src/shared/context", [".ts", ".tsx"], 1200],
|
||||
["src/shared/lib", [".ts", ".tsx"], 1200],
|
||||
["src/shared/ui", [".ts", ".tsx"], 1200],
|
||||
["src/shared/styles", [".css"], 1200],
|
||||
],
|
||||
],
|
||||
[mobilePolicy, [["lib", [".dart"], 1200]]],
|
||||
[
|
||||
webPolicy,
|
||||
[
|
||||
["src/app", [".ts", ".tsx"], 1000],
|
||||
["src/features", [".ts", ".tsx"], 1000],
|
||||
["src/shared/api", [".ts", ".tsx"], 1000],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
for (const [policy, expectedRules] of policies) {
|
||||
const actualRules = policy.rules.map((rule) => [
|
||||
rule.root,
|
||||
[...rule.extensions],
|
||||
rule.maxLines,
|
||||
]);
|
||||
assert.deepEqual(
|
||||
actualRules,
|
||||
expectedRules,
|
||||
`${policy.label} production rules`,
|
||||
);
|
||||
|
||||
for (const rule of policy.rules) {
|
||||
assert.equal(
|
||||
evaluateFileSize({
|
||||
baseLines: null,
|
||||
candidateLines: rule.maxLines,
|
||||
maxLines: rule.maxLines,
|
||||
}).violates,
|
||||
false,
|
||||
`${policy.label} ${rule.root} should allow the ceiling`,
|
||||
);
|
||||
assert.equal(
|
||||
evaluateFileSize({
|
||||
baseLines: null,
|
||||
candidateLines: rule.maxLines + 1,
|
||||
maxLines: rule.maxLines,
|
||||
}).violates,
|
||||
true,
|
||||
`${policy.label} ${rule.root} should reject ceiling + 1`,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("new files use the configured ceiling", () => {
|
||||
assert.equal(allowedLineCount(null, 1000), 1000);
|
||||
assert.deepEqual(
|
||||
|
||||
Reference in New Issue
Block a user