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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
test: close the review gaps in the new productivity/digest suites (#3448)
[._.]/ Adam Eivyd28f247a87db
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 47e63d2266..cf1954d8ab 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -6,4 +6,4 @@These are identifiers, not credentials — Tailscale ACLs still gate all actual network access, and no auth key, token, or secret was ever committed. The historical occurrences remain in git history by deliberate decision (see #3455): a `git filter-repo` rewrite would break every fork and clone of this fork-aware project to remove values that grant no access on their own.-- **The productivity streak store no longer hands back its module-level defaults, and both it and the weekly digest now have real tests.** `server/services/productivity.js` and `server/services/weeklyDigest.js` were referenced in the suite only as `vi.mock()` targets, so ~1,400 lines of streak arithmetic, day/week-boundary handling, and digest assembly were executed by zero tests. They now have direct suites (63 cases) that stub only the file-I/O boundary and the agent-history source and assert concrete values — streak counts across gaps, midnight and year-boundary rollovers, insight copy, week-over-week deltas, and the rendered text summary. Writing them surfaced a real bug: `loadProductivity()` returned the shared `DEFAULT_PRODUCTIVITY` object when no store file existed, so the first incremental `onTaskCompleted()` mutated the module constant in place and every later "empty store" read came back pre-populated. It now clones the defaults per read.+- **The productivity streak store no longer hands back its module-level defaults, and both it and the weekly digest now have real tests.** `server/services/productivity.js` and `server/services/weeklyDigest.js` were referenced in the suite only as `vi.mock()` targets, so ~1,400 lines of streak arithmetic, day/week-boundary handling, and digest assembly were executed by zero tests. They now have direct suites (66 cases) that stub only the file-I/O boundary and the agent-history source and assert concrete values — streak counts across gaps, midnight and year-boundary rollovers, insight copy, week-over-week deltas, and the rendered text summary. Writing them surfaced a real bug: `loadProductivity()` returned the shared `DEFAULT_PRODUCTIVITY` object when no store file existed, so the first incremental `onTaskCompleted()` mutated the module constant in place and every later "empty store" read came back pre-populated. It now clones the defaults per read.diff --git a/server/services/productivity.test.js b/server/services/productivity.test.jsindex 3aacbfa25f..cd2c959714 100644--- a/server/services/productivity.test.js+++ b/server/services/productivity.test.js@@ -81,6 +81,9 @@ beforeEach(() => {afterEach(() => {vi.useRealTimers();vi.clearAllMocks();+ // The mocked bus is shared across cases — drop listeners here so a failing+ // assertion can't strand one and have a later case observe it.+ cosEvents.removeAllListeners();});describe('recalculateProductivity — streaks', () => {@@ -331,6 +334,24 @@ describe('onTaskCompleted — incremental streak updates', () => {});});+ it('splits an ISO week that straddles the new year into two week ids (#3465)', async () => {+ // Characterization, not endorsement: getWeekId() pairs the ISO week NUMBER+ // with the CALENDAR year, so Mon 2025-12-29 and Thu 2026-01-01 — one and+ // the same ISO week — stamp as '2025-W01' and '2026-W01', and the rollover+ // branch of isConsecutiveWeek (which only accepts w1 >= 52) does not bridge+ // them. Pinned so the fix in #3465 has to update this deliberately.+ await productivity.onTaskCompleted(agentOn('dec', { month: 12, day: 29, completedAt: new Date(2025, 11, 29, 10).toISOString() }));+ expect(readStore().streaks).toMatchObject({ lastActiveWeek: '2025-W01', currentWeekly: 1 });++ await productivity.onTaskCompleted(agentOn('jan', { month: 1, day: 1 }));++ expect(readStore().streaks).toMatchObject({+ lastActiveWeek: '2026-W01',+ currentWeekly: 1,+ longestWeekly: 1,+ });+ });+it('prunes daily history older than 90 days', async () => {seed({streaks: { currentDaily: 0, longestDaily: 0, currentWeekly: 0, longestWeekly: 0, lastActiveDate: null, lastActiveWeek: null },diff --git a/server/services/weeklyDigest.test.js b/server/services/weeklyDigest.test.jsindex 0369e5bb44..6d67ac345d 100644--- a/server/services/weeklyDigest.test.js+++ b/server/services/weeklyDigest.test.js@@ -55,13 +55,14 @@ const NOW = new Date(2026, 2, 18, 12, 0, 0);const THIS_WEEK = '2026-W12';const LAST_WEEK = '2026-W11';-const at = (day, hour = 10, month = 3) => new Date(2026, month - 1, day, hour, 0, 0).toISOString();+const at = (day, hour = 10, month = 3, year = 2026) => new Date(year, month - 1, day, hour, 0, 0).toISOString();/** Completed-agent fixture. `taskType` lands in metadata.analysisType. */const agent = (id, {day = 18,hour = 10,month = 3,+ year = 2026,success = true,duration = 60000,taskType = null,@@ -73,8 +74,8 @@ const agent = (id, {id,taskId: `task-${id}`,status,- startedAt: at(day, hour - 1, month),- completedAt: completedAt === undefined ? at(day, hour, month) : completedAt,+ startedAt: at(day, hour - 1, month, year),+ completedAt: completedAt === undefined ? at(day, hour, month, year) : completedAt,result: { success, duration, ...(error ? { error } : {}) },metadata: { ...(taskType ? { analysisType: taskType } : {}), ...(description ? { taskDescription: description } : {}) },});@@ -116,6 +117,9 @@ beforeEach(() => {afterEach(() => {vi.useRealTimers();vi.clearAllMocks();+ // The mocked bus is shared across cases — drop listeners here so a failing+ // assertion can't strand one and have a later case observe it.+ cosEvents.removeAllListeners();});describe('generateWeeklyDigest — summary assembly', () => {@@ -208,6 +212,22 @@ describe('generateWeeklyDigest — summary assembly', () => {expect(issues.map(i => i.error)).toEqual(['timeout', 'lint', 'unknown']);});+ it('keeps only the five most frequent error patterns', async () => {+ // Six distinct errors with descending counts (6…1 occurrences).+ const failures = [];+ for (let rank = 6; rank >= 1; rank--) {+ for (let n = 0; n < rank; n++) {+ failures.push(agent(`e${rank}-${n}`, { day: 16, success: false, error: `error-${rank}` }));+ }+ }+ onDates(failures);++ const { issues } = await digestService.generateWeeklyDigest();++ expect(issues.map(i => i.error)).toEqual(['error-6', 'error-5', 'error-4', 'error-3', 'error-2']);+ expect(issues.map(i => i.count)).toEqual([6, 5, 4, 3, 2]);+ });+it('counts an agent present in both the date index and live state exactly once', async () => {const shared = agent('dupe', { day: 17 });onDates([shared]);@@ -219,6 +239,26 @@ describe('generateWeeklyDigest — summary assembly', () => {expect(digest.accomplishments.map(a => a.id).sort()).toEqual(['dupe', 'state-only']);});+ it('splits an ISO week straddling the new year across two digests (#3465)', async () => {+ // Characterization, not endorsement: the week id pairs the ISO week NUMBER+ // with the CALENDAR year, so the single ISO week containing Mon 2025-12-29+ // and Thu 2026-01-01 is filed as '2025-W01' and '2026-W01' — and '2025-W01'+ // is also the id of the *January* 2025 week, so the two overwrite each+ // other on disk. Pinned so the fix in #3465 has to update this deliberately.+ vi.setSystemTime(new Date(2025, 11, 29, 12, 0, 0));+ onDates([+ agent('dec', { year: 2025, month: 12, day: 29 }),+ agent('jan', { year: 2026, month: 1, day: 1 }),+ ]);++ const digest = await digestService.generateWeeklyDigest();++ expect(digest.weekId).toBe('2025-W01');+ expect(digest.summary.totalTasks).toBe(1);+ expect(digest.accomplishments.map(a => a.id)).toEqual(['dec']);+ expect(existsSync(join(DIGESTS_DIR, '2025-W01.json'))).toBe(true);+ });+it('persists the digest and announces it on the CoS event bus', async () => {const emitted = [];const listener = (d) => emitted.push(d.weekId);@@ -274,8 +314,6 @@ describe('generateWeeklyDigest — week-over-week comparison', () => {});describe('generateWeeklyDigest — insights', () => {- const titles = (digest) => digest.insights.map(i => i.title);-it('calls a week with no completions quiet', async () => {const digest = await digestService.generateWeeklyDigest();@@ -380,7 +418,7 @@ describe('generateWeeklyDigest — insights', () => {const digest = await digestService.generateWeeklyDigest();- expect(titles(digest)).toEqual(['Focus Area']);+ expect(digest.insights.map(i => i.title)).toEqual(['Focus Area']);});});