Skip to content
Merged
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
5 changes: 4 additions & 1 deletion pm-stack/aggregator/src/weights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ export function effortWeight(labels: readonly string[] | undefined): number | nu
const label = raw.trim().toLowerCase();
if (!label.startsWith("effort/")) continue;
const size = label.slice("effort/".length);
const w = EFFORT_WEIGHTS[size];
// Own-key lookup: EFFORT_WEIGHTS is a plain object literal, so an
// inherited member (effort/constructor, effort/__proto__) must not
// resolve as a weight (#2734).
const w = Object.hasOwn(EFFORT_WEIGHTS, size) ? EFFORT_WEIGHTS[size] : undefined;
if (w !== undefined) return w;
}
return null;
Expand Down
28 changes: 28 additions & 0 deletions pm-stack/aggregator/test/weights.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,34 @@ describe("effortWeight (#1108 slice 1)", () => {
expect(effortWeight(["kind/task"])).toBeNull();
expect(effortWeight(["effort/xl"])).toBeNull();
});

test("unsized: prototype-chain members are not weights (#2734)", () => {
expect(effortWeight(["effort/constructor"])).toBeNull();
expect(effortWeight(["effort/__proto__"])).toBeNull();
expect(effortWeight(["effort/hasOwnProperty"])).toBeNull();
expect(effortWeight(["effort/toString"])).toBeNull();
});

test("prototype-labelled items count as unsized with numeric totals (#2734)", () => {
const s = summarizeWeights([
item("closed", ["effort/constructor"]),
item("open", ["effort/__proto__", "kind/task"]),
item("open", ["effort/xs"]), // 1 open, the only sized item
]);
expect(s.totalWeight).toBe(1);
expect(s.closedWeight).toBe(0);
expect(s.openWeight).toBe(1);
expect(typeof s.totalWeight).toBe("number");
expect(typeof s.closedWeight).toBe("number");
expect(s.unsizedCount).toBe(2);
expect(s.unsizedClosedCount).toBe(1);
expect(s.unsizedOpenCount).toBe(1);
expect(s.weightedPct).toBe(0);
const line = weightedLine(s);
expect(line).not.toContain("function");
expect(line).not.toContain("[object Object]");
expect(line).toContain("2 unsized");
});
});

describe("modeOf", () => {
Expand Down