test(FN-5033): complete Step 1 — add failing shard-balance regression fixture

Fusion-Task-Id: FN-5033
Fusion-Task-Lineage: f1a04b65-6161-4001-b01c-3036905cb2ab
This commit is contained in:
Fusion (runfusion.ai)
2026-05-18 06:13:03 -07:00
committed by gsxdsm
parent 5a1794fc55
commit ddacebe265

View File

@@ -246,6 +246,29 @@ test("planShardAssignments: FN-5036 keeps split engine slices from co-locating w
}
});
test("planShardAssignments: FN-5033 regression workload stays below 5% 4-shard variance", () => {
const packages = [
{ name: "@fusion/dashboard", testFileCount: 608 },
{ name: "@fusion/engine", testFileCount: 380 },
{ name: "@fusion/core", testFileCount: 202 },
{ name: "@runfusion/fusion", testFileCount: 120 },
{ name: "tail-a", testFileCount: 90 },
{ name: "tail-b", testFileCount: 80 },
{ name: "tail-c", testFileCount: 70 },
{ name: "tail-d", testFileCount: 70 },
];
const shards = planShardAssignments(packages, 4);
const totals = shards.map((entries) => entries.reduce((sum, entry) => sum + entry.weight, 0));
const perShardBudget = totals.reduce((sum, weight) => sum + weight, 0) / totals.length;
const varianceRatio = (Math.max(...totals) - Math.min(...totals)) / perShardBudget;
assert.ok(
varianceRatio < 0.05,
`expected <5% variance but got ${(varianceRatio * 100).toFixed(2)}% (${totals.join("/")})`,
);
});
test("planShardAssignments: best-fit places unsplit large package on tightest under-budget shard", () => {
const packages = [
{ name: "anchor", testFileCount: 290 },