diff --git a/pm-stack/aggregator/src/weights.ts b/pm-stack/aggregator/src/weights.ts index 5b7533a5d4..78cf31b774 100644 --- a/pm-stack/aggregator/src/weights.ts +++ b/pm-stack/aggregator/src/weights.ts @@ -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; diff --git a/pm-stack/aggregator/test/weights.test.ts b/pm-stack/aggregator/test/weights.test.ts index 9404a9b358..215c8ccc01 100644 --- a/pm-stack/aggregator/test/weights.test.ts +++ b/pm-stack/aggregator/test/weights.test.ts @@ -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", () => {