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

fix: null-safe comment access, test isolation, and DST-safe date arithmetic (#85)

[._.]/ Adam Eivy8e9d2f16195d
diff --git a/server/routes/apps.test.js b/server/routes/apps.test.js
index 217910bf38..2a42b4baef 100644
--- a/server/routes/apps.test.js
+++ b/server/routes/apps.test.js
@@ -32,6 +32,22 @@ vi.mock('../services/streamingDetect.js', () => ({
parseEcosystemFromPath: vi.fn()
}));
+vi.mock('../services/appUpdater.js', () => ({
+ updateApp: vi.fn()
+}));
+
+vi.mock('../services/cos.js', () => ({
+ getAgents: vi.fn().mockResolvedValue([]),
+ getAgentDates: vi.fn().mockResolvedValue([]),
+ getAgentsByDate: vi.fn().mockResolvedValue([])
+}));
+
+vi.mock('../services/git.js', () => ({
+ stageFiles: vi.fn(),
+ getStatus: vi.fn(),
+ commit: vi.fn()
+}));
+
// Import mocked modules
import * as appsService from '../services/apps.js';
import * as pm2Service from '../services/pm2.js';
diff --git a/server/services/agentActionExecutor.js b/server/services/agentActionExecutor.js
index e21366f2c4..f5f7370651 100644
--- a/server/services/agentActionExecutor.js
+++ b/server/services/agentActionExecutor.js
@@ -134,7 +134,7 @@ async function executeComment(client, agent, params) {
console.log(`🤖 AI generating comment for "${agent.name}" on post ${postId}`);
const post = await client.getPost(postId);
const commentsResponse = await client.getComments(postId);
- const comments = Array.isArray(commentsResponse.comments) ? commentsResponse.comments : Array.isArray(commentsResponse) ? commentsResponse : [];
+ const comments = Array.isArray(commentsResponse?.comments) ? commentsResponse.comments : Array.isArray(commentsResponse) ? commentsResponse : [];
const contentConfig = agent.aiConfig?.content || agent.aiConfig;
if (parentId) {
@@ -330,7 +330,7 @@ async function executeMonitor(client, agent, schedule, params) {
});
if (suspended) break;
- const allComments = Array.isArray(commentsResponse.comments) ? commentsResponse.comments : Array.isArray(commentsResponse) ? commentsResponse : [];
+ const allComments = Array.isArray(commentsResponse?.comments) ? commentsResponse.comments : Array.isArray(commentsResponse) ? commentsResponse : [];
totalComments += allComments.length;
const otherComments = allComments.filter(c => {
diff --git a/server/services/meatspacePostTraining.test.js b/server/services/meatspacePostTraining.test.js
index b5beac2ceb..d6387458cd 100644
--- a/server/services/meatspacePostTraining.test.js
+++ b/server/services/meatspacePostTraining.test.js
@@ -96,10 +96,8 @@ describe('getTrainingStats', () => {
});
it('computes streak for consecutive days', async () => {
- const today = new Date();
const dates = [0, 1, 2].map(d => {
- const dt = new Date(today);
- dt.setDate(dt.getDate() - d);
+ const dt = new Date(Date.now() - d * 86400000);
return dt.toISOString().split('T')[0];
});