diff --git a/src/review/public-stats.ts b/src/review/public-stats.ts index c93216cc3..3f9b5fdb4 100644 --- a/src/review/public-stats.ts +++ b/src/review/public-stats.ts @@ -79,7 +79,10 @@ export function isPublicStatsEnabled( manifestOverride?: PublicStatsManifestOverride | undefined, ): boolean { if (manifestOverride?.present) return manifestOverride.enabled; - return /^(1|true|yes|on)$/i.test(env.LOOPOVER_PUBLIC_STATS ?? ""); + // #10329: trim before the anchored regex, matching every sibling flag-checker (e.g. pr-reconciliation.ts). + // A trailing newline/space (plausible from `wrangler secret put` reading a file, or a CI-injected var) makes + // `/^(1|true|yes|on)$/i.test("true\n")` false even though the operator clearly meant to enable the flag. + return /^(1|true|yes|on)$/i.test((env.LOOPOVER_PUBLIC_STATS ?? "").trim()); } // Short in-isolate TTL cache for resolvePublicStatsManifestOverride, mirroring review-memory-wire.ts's diff --git a/test/unit/public-stats.test.ts b/test/unit/public-stats.test.ts index edbc45a83..5c0ac7324 100644 --- a/test/unit/public-stats.test.ts +++ b/test/unit/public-stats.test.ts @@ -76,6 +76,15 @@ describe("isPublicStatsEnabled", () => { expect(isPublicStatsEnabled({ LOOPOVER_PUBLIC_STATS: v })).toBe(false); }); + it("#10329: trims the flag before the anchored regex, matching pr-reconciliation.ts", () => { + // A trailing newline / surrounding whitespace (wrangler secret from a file, a CI-injected var) must not + // defeat the operator's clear intent to enable it. Also confirms a genuinely unrecognised value stays off. + for (const on of ["true\n", " 1 ", "\ton\t", " yes"]) + expect(isPublicStatsEnabled({ LOOPOVER_PUBLIC_STATS: on }), on).toBe(true); + for (const off of [" false ", "\n0\n", " maybe "]) + expect(isPublicStatsEnabled({ LOOPOVER_PUBLIC_STATS: off }), off).toBe(false); + }); + it("a present manifest override wins outright over the env flag, in both directions (#6275)", () => { expect(isPublicStatsEnabled({ LOOPOVER_PUBLIC_STATS: "false" }, { present: true, enabled: true })).toBe(true); expect(isPublicStatsEnabled({ LOOPOVER_PUBLIC_STATS: "true" }, { present: true, enabled: false })).toBe(false);