Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

test: use a small event page in the day-summary DB cases (#11151)

[._.]/ Adam Eivy48fcedb5708e
diff --git a/server/services/humanActivity.db.test.js b/server/services/humanActivity.db.test.js
index 66eb3cdb6e..3f9bee4dfe 100644
--- a/server/services/humanActivity.db.test.js
+++ b/server/services/humanActivity.db.test.js
@@ -18,7 +18,7 @@ import { requireDbOrSkip } from '../lib/dbTestGate.js';
const tzState = vi.hoisted(() => ({ tz: 'UTC' }));
vi.mock('./userTimezone.js', () => ({ getUserTimezone: async () => tzState.tz }));
-import { recordEvents, listEvents, getDaySummary, DAY_EVENT_PAGE_SIZE, stripParticipantsForAccount, countEventsByHandle } from './humanActivity.js';
+import { recordEvents, listEvents, getDaySummary, stripParticipantsForAccount, countEventsByHandle } from './humanActivity.js';
let dbReady = false;
let skipReason = '';
@@ -151,24 +151,25 @@ describe.skipIf(!runDb)('getDaySummary full-day aggregates (#11151)', () => {
if (dbReady) await query('DELETE FROM human_activity_events WHERE source = $1', [DAY_SOURCE]).catch(() => {});
});
- it('counts and buckets the whole day even when it exceeds the event page', async () => {
+ it('counts and buckets the whole day even when it exceeds the event page (2,001-event case, scaled)', async () => {
tzState.tz = 'UTC';
// Far-past day: no other suite or live data lands here.
const date = '2001-03-04';
- const before = await getDaySummary({ date });
+ const PAGE = 3;
+ const before = await getDaySummary({ date, eventLimit: PAGE });
await recordEvents([
- ...dayEvents(DAY_EVENT_PAGE_SIZE, '2001-03-04T12:00:00Z', 'noon'),
+ ...dayEvents(PAGE, '2001-03-04T12:00:00Z', 'noon'),
...dayEvents(1, '2001-03-04T08:00:00Z', 'early', { kind: 'calendar.event' }),
]);
- const s = await getDaySummary({ date });
- expect(s.counts.total - before.counts.total).toBe(DAY_EVENT_PAGE_SIZE + 1);
- expect(s.counts.bySource[DAY_SOURCE]).toBe(DAY_EVENT_PAGE_SIZE + 1);
+ const s = await getDaySummary({ date, eventLimit: PAGE });
+ expect(s.counts.total - before.counts.total).toBe(PAGE + 1);
+ expect(s.counts.bySource[DAY_SOURCE]).toBe(PAGE + 1);
expect(s.counts.byKind['calendar.event'] - (before.counts.byKind['calendar.event'] || 0)).toBe(1);
expect(s.histogram[8].count - before.histogram[8].count).toBe(1);
- expect(s.histogram[12].count - before.histogram[12].count).toBe(DAY_EVENT_PAGE_SIZE);
+ expect(s.histogram[12].count - before.histogram[12].count).toBe(PAGE);
// The listed page stays bounded and is honest about it.
- expect(s.events.length).toBeLessThanOrEqual(DAY_EVENT_PAGE_SIZE);
- expect(s.eventPage).toEqual({ total: s.counts.total, returned: s.events.length, limit: DAY_EVENT_PAGE_SIZE, hasMore: true });
+ expect(s.events.length).toBeLessThanOrEqual(PAGE);
+ expect(s.eventPage).toEqual({ total: s.counts.total, returned: s.events.length, limit: PAGE, hasMore: true });
// Oldest-first display order.
const times = s.events.map((e) => new Date(e.happenedAt).getTime());
expect(times).toEqual([...times].sort((a, b) => a - b));
diff --git a/server/services/humanActivity.js b/server/services/humanActivity.js
index 0e579dab84..4d1292f784 100644
--- a/server/services/humanActivity.js
+++ b/server/services/humanActivity.js
@@ -644,8 +644,10 @@ export const DAY_EVENT_PAGE_SIZE = 2000;
// rows, returned oldest-first; `eventPage` says how complete that page is
// ({ total, returned, limit, hasMore }). The aggregates and the page are read
// in one REPEATABLE READ snapshot so concurrent ingestion cannot make them
-// disagree, and share the same exclusive [start, end) UTC bounds.
-export async function getDaySummary({ date } = {}) {
+// disagree, and share the same exclusive [start, end) UTC bounds. `eventLimit`
+// can only shrink the page (tests use it to avoid thousand-row fixtures).
+export async function getDaySummary({ date, eventLimit = DAY_EVENT_PAGE_SIZE } = {}) {
+ const pageSize = Math.min(Math.max(Number(eventLimit) || DAY_EVENT_PAGE_SIZE, 1), DAY_EVENT_PAGE_SIZE);
const timezone = await getUserTimezone();
// `today` is computed in the USER's configured timezone (not the browser's) and
// returned so the client can default the bare /timeline route and gate its
@@ -653,7 +655,7 @@ export async function getDaySummary({ date } = {}) {
const today = todayInTimezone(timezone);
const day = /^\d{4}-\d{2}-\d{2}$/.test(String(date || '')) ? date : today;
const range = localDayRangeUtc(day, timezone);
- const eventPage = (returned, total) => ({ total, returned, limit: DAY_EVENT_PAGE_SIZE, hasMore: returned < total });
+ const eventPage = (returned, total) => ({ total, returned, limit: pageSize, hasMore: returned < total });
if (!range) {
return { date: day, today, timezone, events: [], eventPage: eventPage(0, 0), histogram: hourlyHistogram([], timezone), counts: summarizeCounts([]) };
}
@@ -678,7 +680,7 @@ export async function getDaySummary({ date } = {}) {
`SELECT * FROM human_activity_events
WHERE happened_at >= $1 AND happened_at < $2
ORDER BY happened_at DESC LIMIT $3`,
- [...bounds, DAY_EVENT_PAGE_SIZE],
+ [...bounds, pageSize],
);
return { aggregates: agg.rows, rows: page.rows };
});