Skip to content

Commit 9d1cfdb

Browse files
committed
fix(partition-test-shards): keep the declaration reader that rides with the reader slice out of the cap repair
refineToCap() moved any whole package off the densest bin, the rider included, which would put declarations on a second shard. The rider now stays with its slice like the slice itself; the self-test gains the fixture where only that rule keeps it there. Claude-Session: https://claude.ai/code/session_01QSeKYmTYfaPbLQD4BJfomW Co-authored-by: Claude <noreply@anthropic.com>
1 parent 7081f7b commit 9d1cfdb

1 file changed

Lines changed: 32 additions & 5 deletions

File tree

‎scripts/partition-test-shards.mjs‎

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,10 +1214,18 @@ export function densityCapOf(timings, excluded, shardCount) {
12141214
// Deterministic (candidates in bin and item order, the first strictly best
12151215
// kept), and it terminates: every accepted move lowers the sum of squared bin
12161216
// totals. A split already within the cap comes back unchanged.
1217+
//
1218+
// ⛔ A whole package that rides with the declaration-reading slice (`rideWith`,
1219+
// DECLARATION_READER_PACKAGES) stays put like the slice itself: moved off, it
1220+
// would take declarations to a second shard, which then builds the closure the
1221+
// slice pin exists to build once.
12171222
export function refineToCap(bins, items, cap) {
12181223
const weightOf = new Map(items.map((i) => [i.name, i.weight]));
1219-
const slices = new Set(items.filter((i) => i.slice).map((i) => i.name));
1220-
const movable = (name) => !slices.has(name);
1224+
const present = new Set(items.map((i) => i.name));
1225+
const fixed = new Set(
1226+
items.filter((i) => i.slice || (i.rideWith !== undefined && present.has(i.rideWith))).map((i) => i.name)
1227+
);
1228+
const movable = (name) => !fixed.has(name);
12211229
const out = bins.map((b) => ({ total: b.total, names: [...b.names] }));
12221230
const EPSILON = 1e-9;
12231231
for (let step = 0; step < 10_000; step++) {
@@ -1746,9 +1754,9 @@ const SELF_TEST_BATTERIES = Object.freeze({
17461754
// 1 grades the committed dataset's split; 4 are fixtures, both directions.
17471755
'the whole-package leg cap and the load-sensitive pair (#25870)': 5,
17481756
// 4 grade the committed dataset and the live tree, 1 drives planRun() on
1749-
// both document shapes, 10 are fixtures (7 of the three spellings, 3 of the
1750-
// placement).
1751-
'the declaration-reading slice carries the closure (#25870)': 15,
1757+
// both document shapes, 11 are fixtures (7 of the three spellings, 3 of the
1758+
// placement, 1 of the cap repair).
1759+
'the declaration-reading slice carries the closure (#25870)': 16,
17521760
'predicted-vs-measured drift (#16173)': 9,
17531761
'drift warning tier under the red (#16465)': 12,
17541762
'file-level slice items (#16173)': 20,
@@ -2428,6 +2436,25 @@ function selfTest() {
24282436
throw new Error('declaration closure: a run with no reader slice was charged or re-placed');
24292437
}
24302438
});
2439+
check(() => {
2440+
// The cap repair moves whole packages off the densest bin; the whole
2441+
// reader riding with the reader slice is not one it may move. Here moving
2442+
// `m` would strictly lower the 800s bin (to 600s / 500s), so only the
2443+
// rider rule keeps it beside `a 1/2`.
2444+
const items = [
2445+
{ name: 'a 1/2', weight: 500, pkg: 'a', slice: { index: 1, count: 2 }, tasks: 1 },
2446+
{ name: 'a 2/2', weight: 300, pkg: 'a', slice: { index: 2, count: 2 }, tasks: 1 },
2447+
{ name: 'm', weight: 300, pkg: 'm', slice: null, tasks: 1, rideWith: 'a 1/2' },
2448+
];
2449+
const bins = [
2450+
{ total: 800, names: ['a 1/2', 'm'] },
2451+
{ total: 300, names: ['a 2/2'] },
2452+
];
2453+
const out = refineToCap(bins, items, 600);
2454+
if (binOf(out, 'm') !== binOf(out, 'a 1/2')) {
2455+
throw new Error(`declaration closure: the cap repair moved the whole reader off the reader slice's shard: ${JSON.stringify(out)}`);
2456+
}
2457+
});
24312458
}
24322459
check(() => {
24332460
// Through planRun(), the function main() runs: a Test Core document charges

0 commit comments

Comments
 (0)