From ad9f64b457d6eacc18ccf3c00ccd09000307bbea Mon Sep 17 00:00:00 2001 From: Peter Amiri Date: Tue, 1 Dec 2026 03:40:09 -0800 Subject: [PATCH] test(events): count the throttle lock warning; harden the Windows fingerprint fallback The D1 "warn once" spec asserted only that the flag was set, so a regression that kept the flag but dropped the early return (back to a WriteLog per failure) would still pass. Route the warning through an overridable $errorEmailThrottleLogWarning() seam and have the spec mock it and count the calls: three failures must produce exactly one warning. Verified by mutation: removing the early return yields "Expected [1] Actual [3]" and the spec fails; restoring it passes. Also address the Windows note: when GetFileFromPath returns empty for a normalized path, fall back to the last path segment (ListLast on "/") and then "no-frame", never the full deployment path, so the same failure cannot split across installs. No throttle behaviour changes: fail-open, one warning per application, caps accepting 0 as unlimited, and the window rejecting 0 are unchanged. Signed-off-by: Peter Amiri --- vendor/wheels/events/EventMethods.cfc | 26 ++++++++++++++++--- .../specs/events/ErrorEmailThrottleSpec.cfc | 14 +++++++--- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/vendor/wheels/events/EventMethods.cfc b/vendor/wheels/events/EventMethods.cfc index 97582317fb..7967c3e630 100644 --- a/vendor/wheels/events/EventMethods.cfc +++ b/vendor/wheels/events/EventMethods.cfc @@ -242,7 +242,14 @@ component extends="wheels.Global" implements="wheels.interfaces.events.EventHand if (Len(local.normalized)) { local.file = GetFileFromPath(local.normalized); if (!Len(local.file)) { - local.file = local.normalized; + // GetFileFromPath can return "" on Windows for a normalized path + // (e.g. a trailing separator or a drive-relative form). Fall back + // to the last path segment, never the full path: a deployment root + // in the fingerprint would split the same failure across installs. + local.file = ListLast(local.normalized, "/"); + } + if (!Len(local.file)) { + local.file = "no-frame"; } } local.line = local.use.line; @@ -275,15 +282,26 @@ component extends="wheels.Global" implements="wheels.interfaces.events.EventHand return; } application.wheels["$errorEmailThrottleLockWarned"] = true; - WriteLog( - file = "wheels", - type = "warning", + $errorEmailThrottleLogWarning( text = "Wheels: the error-email throttle lock was not available; sending error emails unthrottled (fail-open). This warning is logged once per application start." ); } catch (any e) { } } + /** + * Internal seam for the lock warning: the spec replaces this method with a + * counter, so the "one warning per application, not one per error" contract + * is actually observed rather than inferred from the flag. Production writes + * one wheels.log warning; the try/catch keeps logging failures harmless. + */ + public void function $errorEmailThrottleLogWarning(required string text) { + try { + WriteLog(file = "wheels", type = "warning", text = arguments.text); + } catch (any e) { + } + } + /** * Internal: decides whether this error email may be sent and, when one is * allowed after suppressions, returns the numbers-only summary paragraph. diff --git a/vendor/wheels/tests/specs/events/ErrorEmailThrottleSpec.cfc b/vendor/wheels/tests/specs/events/ErrorEmailThrottleSpec.cfc index 3ebfc21f64..707a7c7bd9 100644 --- a/vendor/wheels/tests/specs/events/ErrorEmailThrottleSpec.cfc +++ b/vendor/wheels/tests/specs/events/ErrorEmailThrottleSpec.cfc @@ -254,12 +254,20 @@ component extends="wheels.WheelsTest" { it("warns once, not per failure, when the throttle lock is unavailable", () => { var em = mailer(); + // Count the warnings, not just the flag: a regression that keeps the + // flag set but drops the early return would log per failure and must + // fail here. The seam is $errorEmailThrottleLogWarning. + prepareMock(em); + em.$("$errorEmailThrottleLogWarning"); expect(StructKeyExists(application.wheels, "$errorEmailThrottleLockWarned")).toBeFalse(); em.$warnErrorEmailThrottleLockFailure(); - expect(StructKeyExists(application.wheels, "$errorEmailThrottleLockWarned")).toBeTrue(); - // The second call must take the early return (one warning total). em.$warnErrorEmailThrottleLockFailure(); - expect(application.wheels.$errorEmailThrottleLockWarned).toBeTrue(); + em.$warnErrorEmailThrottleLockFailure(); + expect(em.$count("$errorEmailThrottleLogWarning")).toBe( + 1, + "the lock warning must be written once per application, not once per failure" + ); + expect(StructKeyExists(application.wheels, "$errorEmailThrottleLockWarned")).toBeTrue(); }); });