From 6d78792af65923b26a80942ff77e423650a39cfe Mon Sep 17 00:00:00 2001 From: peppa-bot Date: Fri, 20 Nov 2026 21:10:33 +0500 Subject: [PATCH] =?UTF-8?q?PEP-224:=20=D0=B6=D0=B8=D0=B2=D0=BE=D0=B5=20?= =?UTF-8?q?=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=B1=D0=B5=D0=B7=20=D1=81=D0=BE=D0=BA=D0=B5=D1=82=D0=B0,=20?= =?UTF-8?q?=D0=BA=D1=8D=D1=88=20=D0=BF=D0=BE=20=D0=BE=D1=82=D0=BF=D0=B5?= =?UTF-8?q?=D1=87=D0=B0=D1=82=D0=BA=D1=83=20=D0=BE=D0=B1=D1=8A=D1=8F=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=BD=D1=8B=D1=85=20=D1=81=D1=82=D0=B0=D1=82?= =?UTF-8?q?=D1=83=D1=81=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- packages/core/src/feature-status.ts | 9 ++++++--- packages/runner/src/live.ts | 3 +++ packages/testkit/test/feature-status.test.ts | 3 +++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/core/src/feature-status.ts b/packages/core/src/feature-status.ts index debc5eff..51c65884 100644 --- a/packages/core/src/feature-status.ts +++ b/packages/core/src/feature-status.ts @@ -87,7 +87,7 @@ export function featureThresholds(): Partial> { return out; } -let cache: { at: number; value: Record } | null = null; +let cache: { at: number; print: string; value: Record } | null = null; /** Tests and the superadmin's changes: read afresh next time. */ export function resetFeatureCache(): void { @@ -97,7 +97,10 @@ export function resetFeatureCache(): void { /** Every feature's state (cached 15 s); trouble with observe.db = everything available. */ export function featureStatuses(o: { now?: Date; fresh?: boolean } = {}): Record { const now = o.now ?? new Date(); - if (!o.fresh && !o.now && cache && Date.now() - cache.at < CACHE_MS) return cache.value; + // The announced states (written by the observer) are part of the key: a change shows at once, even in + // another copy of this module (Next bundles route handlers and pages separately). + const print = o.now ? "" : featureFingerprint(); + if (!o.fresh && !o.now && cache && cache.print === print && Date.now() - cache.at < CACHE_MS) return cache.value; let value: Record; try { value = computeFeatures(listMonitors(), featureThresholds(), now); @@ -105,7 +108,7 @@ export function featureStatuses(o: { now?: Date; fresh?: boolean } = {}): Record console.error("feature-status: observe.db unavailable, everything counts as available:", (e as Error).message); value = allAvailable(); } - if (!o.now) cache = { at: Date.now(), value }; + if (!o.now) cache = { at: Date.now(), print, value }; return value; } diff --git a/packages/runner/src/live.ts b/packages/runner/src/live.ts index 624e0eef..34077c9d 100644 --- a/packages/runner/src/live.ts +++ b/packages/runner/src/live.ts @@ -196,6 +196,9 @@ class LiveHub { if (v !== this.seen) { this.seen = v; this.wake(); + } else if (this.listeners.has("features") && featureFingerprint() !== this.prints.get("features")) { + // PEP-224: the observer writes observe.db only — watch it directly (one tiny query), not just pokes. + this.wake(); } }, 1000); this.timer.unref?.(); diff --git a/packages/testkit/test/feature-status.test.ts b/packages/testkit/test/feature-status.test.ts index 07c9eb96..6ee900d8 100644 --- a/packages/testkit/test/feature-status.test.ts +++ b/packages/testkit/test/feature-status.test.ts @@ -90,9 +90,12 @@ describe("Feature status", () => { check(relayMon.id, good, new Date()); assert.equal(core.featureStatus("egov_login", { fresh: true }).state, "unavailable", "one good check is not enough (recover_threshold 2)"); + // The cache follows the announced states: another module copy (a page) sees a change at once. + assert.equal(core.featureStatus("egov_login").state, "unavailable", "cached"); check(relayMon.id, good, new Date()); assert.equal(core.featureStatus("egov_login", { fresh: true }).state, "available"); await core.featureTick(db); + assert.equal(core.featureStatus("egov_login").state, "available", "announced — the cache is dropped by the fingerprint"); msgs = await sent(); assert.equal(msgs.length, 2); assert.match(msgs[1]!, /✅ «Вход через eGov» снова включено для пользователей/);