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 src/review/public-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions test/unit/public-stats.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down