Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.
TypeScript aeoai-agentai-searchanswer-engine-optimizationbrand-monitoringchatgptclaudecopilotdockergeminigeogoogle-ai-overviewsgrokmcpnextjsopen-sourceperplexityseosupabasetypescript
fix(insights): compare 24h with the day before when the previous run was on the same day (#1204)
Gökhan Geyik583ffa0232e1
diff --git a/web/src/lib/insights-windows.test.ts b/web/src/lib/insights-windows.test.tsindex a8bd05485..f8ef9f0f7 100644--- a/web/src/lib/insights-windows.test.ts+++ b/web/src/lib/insights-windows.test.ts@@ -77,6 +77,25 @@ describe('comparisonWindows', () => {expect(w.prev).toEqual({ kind: 'days', days: previousDays });expect(deltaDayWindows(days, previousDays).prev).toEqual(previousDays);});++ it('compares with the day before when the previous run was on the same day', () => {+ // The nightly run, then a Run All later the same UTC day.+ const days = { dayFrom: '2026-10-19', dayTo: '2026-10-19' };+ const w = comparisonWindows({ days, previousDays: days });++ expect(w.prev).toEqual({ kind: 'days', days: { dayFrom: '2026-10-18', dayTo: '2026-10-18' } });+ });++ it('compares with the day before when the previous run ran into the current day', () => {+ // The previous run started before midnight and completed after it.+ const days = { dayFrom: '2026-10-19', dayTo: '2026-10-19' };+ const previousDays = { dayFrom: '2026-10-18', dayTo: '2026-10-19' };++ expect(deltaDayWindows(days, previousDays).prev).toEqual({+ dayFrom: '2026-10-18',+ dayTo: '2026-10-18',+ });+ });});describe('visibilityChange', () => {diff --git a/web/src/lib/insights-windows.ts b/web/src/lib/insights-windows.tsindex b07ce3e65..ca843f657 100644--- a/web/src/lib/insights-windows.ts+++ b/web/src/lib/insights-windows.ts@@ -52,9 +52,12 @@ export function addDays(day: string, n: number): string {* unbounded window anchors to the trailing 7 days, mirroring what the raw* path's `now() - 7d` default has always compared against. When a previous* completed run's window is supplied, use it instead of deriving an adjacent- * equal-length period. The previous window ends the day BEFORE the current- * one starts by default — the raw path's- * timestamp arithmetic let the two windows share their boundary instant.+ * equal-length period — but only when it ends before the current one starts:+ * two runs on the same UTC day (the nightly one, then a Run All) would+ * otherwise compare the day with itself and read every change as 0. The+ * previous window ends the day BEFORE the current one starts by default — the+ * raw path's timestamp arithmetic let the two windows share their boundary+ * instant.*/export function deltaDayWindows(days: DayWindow,@@ -69,7 +72,7 @@ export function deltaDayWindows(const prevTo = addDays(curFrom, -1);const defaultPrev = { dayFrom: addDays(prevTo, -(len - 1)), dayTo: prevTo };const prev =- previousDays?.dayFrom && previousDays?.dayTo+ previousDays?.dayFrom && previousDays?.dayTo && previousDays.dayTo < curFrom? { dayFrom: previousDays.dayFrom, dayTo: previousDays.dayTo }: defaultPrev;return {