Skip to content
Closed
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
1 change: 1 addition & 0 deletions changelog.d/fixes/8589-file-size-update-remove-at-cap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- **fix(quality):** `check:file-size --update` now removes baseline entries that already fit the new-file cap even when LOC equals the frozen value (`redundant` path) — closes the #8584 gap where at-cap entries were stuck forever ([#8589](https://github.com/diegosouzapw/OmniRoute/pull/8589)) — thanks @MumuTW
53 changes: 41 additions & 12 deletions scripts/check/check-file-size.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
// - arquivo congelado: só pode ENCOLHER (nunca crescer);
// - arquivo NOVO (fora do baseline): não pode passar do CAP.
// Assim o próximo arquivo de 12.760 linhas é impossível, e os 91 atuais só melhoram.
// --update ratcheta o baseline para baixo (encolhimentos + remove quem caiu < cap).
// --update ratcheta o baseline para baixo: encolhimentos + remove toda entrada que
// já cabe no cap, inclusive quem NÃO encolheu nesta rodada (loc === frozen[file]).
// Antes a remoção só acontecia dentro do ramo de encolhimento, então uma entrada
// igual ao próprio teto ficava presa no baseline para sempre — ver #8584.
import fs from "node:fs";
import path from "node:path";
import { pathToFileURL } from "node:url";
Expand All @@ -27,21 +30,30 @@ const SKIP_DIRS = new Set(["node_modules", "dist-electron", ".next", ".build", "

/**
* Avalia LOC atuais contra o baseline congelado.
* @returns {{violations: string[], improvements: [string, number][]}}
*
* `redundant` (#8584): entrada que NAO precisa mais existir — o arquivo esta
* exatamente no valor congelado E ja cabe no cap de arquivo novo. Antes, a
* remocao do baseline so acontecia dentro do ramo de `improvements`
* (loc < frozen), entao uma entrada igual ao proprio teto nunca saia da lista,
* por mais abaixo do cap que estivesse (3 casos reais no v3.8.49).
*
* @returns {{violations: string[], improvements: [string, number][], redundant: string[]}}
*/
export function evaluateFileSizes(currentLocByFile, frozen, cap) {
const violations = [];
const improvements = [];
const redundant = [];
for (const [file, loc] of Object.entries(currentLocByFile)) {
if (file in frozen) {
if (loc > frozen[file])
violations.push(`${file}: ${loc} > congelado ${frozen[file]} (não pode crescer)`);
else if (loc < frozen[file]) improvements.push([file, loc]);
else if (loc <= cap) redundant.push(file);
} else if (loc > cap) {
violations.push(`${file}: ${loc} > cap ${cap} (arquivo novo acima do limite)`);
}
}
return { violations, improvements };
return { violations, improvements, redundant };
}

function countLines(file) {
Expand Down Expand Up @@ -105,40 +117,57 @@ function main() {
const cap = baseline.cap;
const frozen = baseline.frozen || {};
const current = collectLoc();
const { violations, improvements } = evaluateFileSizes(current, frozen, cap);
const { violations, improvements, redundant } = evaluateFileSizes(current, frozen, cap);

// Test-file gate (Layer 1 anti-reinflation): same shrink-only + new-≤cap semantics,
// reusing evaluateFileSizes against the testFrozen baseline + testCap.
const testCap = baseline.testCap;
const testFrozen = baseline.testFrozen || {};
const currentTests = collectTestLoc();
const { violations: testViolations, improvements: testImprovements } =
typeof testCap === "number"
? evaluateFileSizes(currentTests, testFrozen, testCap)
: { violations: [], improvements: [] };
const {
violations: testViolations,
improvements: testImprovements,
redundant: testRedundant,
} = typeof testCap === "number"
? evaluateFileSizes(currentTests, testFrozen, testCap)
: { violations: [], improvements: [], redundant: [] };

if (UPDATE) {
let changed = false;
if (violations.length === 0 && improvements.length) {
if (violations.length === 0 && (improvements.length || redundant.length)) {
for (const [file, loc] of improvements) {
if (loc <= cap)
delete frozen[file]; // caiu para dentro do cap → sai do baseline
else frozen[file] = loc; // continua grande mas encolheu → trava no novo valor
}
// #8584: entradas que já cabem no cap sem terem encolhido nesta rodada
// (loc === frozen[file]) também saem — antes ficavam presas para sempre.
for (const file of redundant) delete frozen[file];
baseline.frozen = Object.fromEntries(Object.entries(frozen).sort());
changed = true;
console.log(`[file-size] baseline ratcheado: ${improvements.length} arquivo(s) encolheram`);
console.log(
`[file-size] baseline ratcheado: ${improvements.length} arquivo(s) encolheram` +
(redundant.length ? `, ${redundant.length} entrada(s) redundante(s) removida(s)` : "")
);
}
if (typeof testCap === "number" && testViolations.length === 0 && testImprovements.length) {
if (
typeof testCap === "number" &&
testViolations.length === 0 &&
(testImprovements.length || testRedundant.length)
) {
for (const [file, loc] of testImprovements) {
if (loc <= testCap)
delete testFrozen[file]; // caiu para dentro do testCap → sai do baseline
else testFrozen[file] = loc; // continua grande mas encolheu → trava no novo valor
}
for (const file of testRedundant) delete testFrozen[file];
baseline.testFrozen = Object.fromEntries(Object.entries(testFrozen).sort());
changed = true;
console.log(
`[test-file-size] baseline ratcheado: ${testImprovements.length} arquivo(s) de teste encolheram`
`[test-file-size] baseline ratcheado: ${testImprovements.length} arquivo(s) de teste encolheram` +
(testRedundant.length
? `, ${testRedundant.length} entrada(s) redundante(s) removida(s)`
: "")
);
}
if (changed) fs.writeFileSync(BASELINE_PATH, JSON.stringify(baseline, null, 2) + "\n");
Expand Down
9 changes: 0 additions & 9 deletions skills/cli-backup-sync/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,6 @@ omniroute backup disable

### `backup status`

**Flags:**

- `--name <name>`
- `--cloud`
- `--encrypt`
- `--key-file <path>`
- `--exclude <pattern>`
- `--retention <n>`

**Example:**

```bash
Expand Down
60 changes: 60 additions & 0 deletions tests/unit/check-file-size.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,63 @@ test("frozen test file that shrank is an improvement, not a violation", () => {
assert.deepEqual(r.violations, []);
assert.deepEqual(r.improvements, [["tests/unit/combo-routing-engine.test.ts", 3000]]);
});

// --- Redundant entries (#8584): an entry that no longer needs to exist ---
// `--update` could only ever delete an entry from inside the improvement branch
// (loc < frozen), so a file sitting at EXACTLY its frozen value while already
// within the new-file cap could never leave the baseline, however far under the
// cap it was. Those entries are reported separately as `redundant`.

test("frozen file sitting at its baseline but already within the cap is redundant", () => {
const r = evaluateFileSizes({ "a.ts": 500 }, { "a.ts": 500 }, cap);
assert.deepEqual(r.violations, []);
assert.deepEqual(r.improvements, []);
assert.deepEqual(r.redundant, ["a.ts"]);
});

test("frozen file sitting at its baseline but still over the cap is NOT redundant", () => {
const r = evaluateFileSizes({ "a.ts": 1000 }, { "a.ts": 1000 }, cap);
assert.deepEqual(r.violations, []);
assert.deepEqual(r.improvements, []);
assert.deepEqual(r.redundant, []);
});

test("frozen file exactly at the cap is redundant (cap is inclusive)", () => {
const r = evaluateFileSizes({ "a.ts": 800 }, { "a.ts": 800 }, cap);
assert.deepEqual(r.redundant, ["a.ts"]);
});

test("a file that shrank stays an improvement and is not double-counted as redundant", () => {
const r = evaluateFileSizes({ "a.ts": 500 }, { "a.ts": 1000 }, cap);
assert.deepEqual(r.improvements, [["a.ts", 500]]);
assert.deepEqual(r.redundant, []);
});

test("a frozen file that grew is a violation and never redundant", () => {
const r = evaluateFileSizes({ "a.ts": 1001 }, { "a.ts": 1000 }, cap);
assert.equal(r.violations.length, 1);
assert.deepEqual(r.redundant, []);
});

test("the real residual entries from #8584 are reported as redundant", () => {
// Measured on release/v3.8.49 @ 4053e2314: each sits at exactly its frozen
// value and far below the 800 cap, yet survived a full `--update` run.
const frozen = {
"src/app/(dashboard)/dashboard/providers/[id]/ProviderDetailPageClient.tsx": 798,
"src/app/(dashboard)/dashboard/providers/[id]/hooks/useProviderModels.ts": 155,
"src/app/(dashboard)/dashboard/providers/[id]/hooks/useProviderSettings.ts": 264,
};
const r = evaluateFileSizes({ ...frozen }, frozen, cap);
assert.deepEqual(r.violations, []);
assert.deepEqual(r.improvements, []);
assert.deepEqual(r.redundant.sort(), Object.keys(frozen).sort());
});

test("redundant applies to the test-file path too", () => {
const r = evaluateFileSizes(
{ "tests/unit/small.test.ts": 300 },
{ "tests/unit/small.test.ts": 300 },
testCap
);
assert.deepEqual(r.redundant, ["tests/unit/small.test.ts"]);
});
Loading