From ce63fa1faea188d8186982657a53d8a215ce3201 Mon Sep 17 00:00:00 2001 From: shin-core <153108882+shin-core@users.noreply.github.com> Date: Tue, 4 Aug 2026 12:13:58 +0900 Subject: [PATCH] fix(review): trim LOOPOVER_PUBLIC_STATS before the truthy-flag regex test isPublicStatsEnabled tested the raw, untrimmed env value against the anchored /^(1|true|yes|on)$/i regex, while every sibling flag-checker in the codebase (e.g. pr-reconciliation.ts's isPrReconciliationEnabled) trims first. A trailing newline or surrounding whitespace -- plausible from wrangler secret put reading a file, or a CI/CD-injected env var carrying a trailing newline -- made the anchored regex fail to match even though the operator clearly meant to enable the flag: the test of 'true\n' was false. Trim the value before the regex, matching the established convention. The manifestOverride early-return and every already-clean value are unchanged. Closes #10329 --- src/review/public-stats.ts | 5 ++++- test/unit/public-stats.test.ts | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) 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);