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: address round 17 Copilot review feedback

Adam Eivy0e548cc0596a
diff --git a/server/index.js b/server/index.js
index 541fee735f..3cb2034e44 100644
--- a/server/index.js
+++ b/server/index.js
@@ -65,7 +65,7 @@ import './services/subAgentSpawner.js'; // Initialize CoS agent spawner
import * as automationScheduler from './services/automationScheduler.js';
import * as agentActionExecutor from './services/agentActionExecutor.js';
import { startBackupScheduler } from './services/backupScheduler.js';
-import { startUpdateScheduler, recordUpdateResult, clearStaleUpdateInProgress } from './services/updateChecker.js';
+import { startUpdateScheduler, recordUpdateResult, clearStaleUpdateInProgress, getCurrentVersion } from './services/updateChecker.js';
import { startBrainScheduler } from './services/brainScheduler.js';
import { recoverStuckClassifications } from './services/brain.js';
import { initBridge as initBrainMemoryBridge } from './services/brainMemoryBridge.js';
@@ -279,6 +279,15 @@ readFile(updateMarkerPath, 'utf-8').then(raw => {
if (unlinkErr?.code !== 'ENOENT') console.error(`❌ Failed to remove invalid update marker: ${unlinkErr.message}`);
});
}
+ // Verify marker version matches the currently running version to catch partial updates
+ const runningVersion = await getCurrentVersion();
+ if (marker.version !== runningVersion) {
+ console.error(`❌ Update marker version (${marker.version}) doesn't match running version (${runningVersion}) — recording as failed`);
+ return recordUpdateResult({ version: marker.version, success: false, completedAt: marker.completedAt, log: `Version mismatch: expected ${marker.version}, running ${runningVersion}` })
+ .finally(() => unlink(updateMarkerPath).catch(unlinkErr => {
+ if (unlinkErr?.code !== 'ENOENT') console.error(`❌ Failed to remove update marker: ${unlinkErr.message}`);
+ }));
+ }
console.log(`✅ Update to v${marker.version} completed at ${marker.completedAt}`);
return recordUpdateResult({ version: marker.version, success: true, completedAt: marker.completedAt, log: '' })
.then(() => unlink(updateMarkerPath).catch(unlinkErr => {
diff --git a/server/services/meatspaceAlcohol.js b/server/services/meatspaceAlcohol.js
index 11d0168a03..e112905dc3 100644
--- a/server/services/meatspaceAlcohol.js
+++ b/server/services/meatspaceAlcohol.js
@@ -267,10 +267,8 @@ export async function removeDrink(date, index) {
async function loadCustomDrinks() {
const data = await readJSONFile(CUSTOM_DRINKS_FILE, null);
if (!data) {
- // Seed with defaults on first access
- const seeded = { drinks: DEFAULT_DRINK_BUTTONS.map(d => ({ ...d })) };
- await saveCustomDrinks(seeded);
- return seeded;
+ // Return defaults in-memory without writing — persist only on explicit mutations
+ return { drinks: DEFAULT_DRINK_BUTTONS.map(d => ({ ...d })) };
}
if (!Array.isArray(data.drinks)) data.drinks = [];
return data;
diff --git a/server/services/meatspaceCustomDrinks.test.js b/server/services/meatspaceCustomDrinks.test.js
new file mode 100644
index 0000000000..13bebf4fe4
--- /dev/null
+++ b/server/services/meatspaceCustomDrinks.test.js
@@ -0,0 +1,98 @@
+import { describe, it, expect, vi, beforeEach } from 'vitest';
+
+vi.mock('fs/promises', () => ({
+ writeFile: vi.fn().mockResolvedValue(undefined)
+}));
+
+vi.mock('../lib/fileUtils.js', () => ({
+ readJSONFile: vi.fn(),
+ PATHS: {
+ root: '/mock',
+ data: '/mock/data',
+ meatspace: '/mock/data/meatspace'
+ },
+ ensureDir: vi.fn().mockResolvedValue(undefined)
+}));
+
+import { writeFile } from 'fs/promises';
+import { readJSONFile } from '../lib/fileUtils.js';
+import {
+ getCustomDrinks,
+ addCustomDrink,
+ updateCustomDrink,
+ removeCustomDrink
+} from './meatspaceAlcohol.js';
+
+beforeEach(() => {
+ vi.clearAllMocks();
+});
+
+describe('custom drink CRUD', () => {
+ it('returns default drinks when file does not exist', async () => {
+ readJSONFile.mockResolvedValue(null);
+ const drinks = await getCustomDrinks();
+ expect(drinks.length).toBeGreaterThan(0);
+ expect(drinks[0]).toHaveProperty('name');
+ expect(drinks[0]).toHaveProperty('oz');
+ expect(drinks[0]).toHaveProperty('abv');
+ // Should not write to disk on read
+ expect(writeFile).not.toHaveBeenCalled();
+ });
+
+ it('returns persisted drinks from file', async () => {
+ readJSONFile.mockResolvedValue({ drinks: [{ name: 'IPA', oz: 16, abv: 7 }] });
+ const drinks = await getCustomDrinks();
+ expect(drinks).toEqual([{ name: 'IPA', oz: 16, abv: 7 }]);
+ });
+
+ it('adds a custom drink and persists', async () => {
+ readJSONFile.mockResolvedValue({ drinks: [{ name: 'IPA', oz: 16, abv: 7 }] });
+ const result = await addCustomDrink({ name: 'Stout', oz: 12, abv: 5 });
+ expect(result).toEqual({ name: 'Stout', oz: 12, abv: 5 });
+ expect(writeFile).toHaveBeenCalledTimes(1);
+ const written = JSON.parse(writeFile.mock.calls[0][1]);
+ expect(written.drinks).toHaveLength(2);
+ expect(written.drinks[1].name).toBe('Stout');
+ });
+
+ it('updates a custom drink by index', async () => {
+ readJSONFile.mockResolvedValue({ drinks: [{ name: 'IPA', oz: 16, abv: 7 }] });
+ const result = await updateCustomDrink(0, { name: 'Double IPA', abv: 9 });
+ expect(result.name).toBe('Double IPA');
+ expect(result.abv).toBe(9);
+ expect(result.oz).toBe(16); // unchanged
+ expect(writeFile).toHaveBeenCalledTimes(1);
+ });
+
+ it('returns null for out-of-bounds update', async () => {
+ readJSONFile.mockResolvedValue({ drinks: [{ name: 'IPA', oz: 16, abv: 7 }] });
+ expect(await updateCustomDrink(5, { name: 'X' })).toBeNull();
+ expect(await updateCustomDrink(-1, { name: 'X' })).toBeNull();
+ expect(writeFile).not.toHaveBeenCalled();
+ });
+
+ it('removes a custom drink by index', async () => {
+ readJSONFile.mockResolvedValue({ drinks: [
+ { name: 'IPA', oz: 16, abv: 7 },
+ { name: 'Stout', oz: 12, abv: 5 }
+ ]});
+ const removed = await removeCustomDrink(0);
+ expect(removed.name).toBe('IPA');
+ expect(writeFile).toHaveBeenCalledTimes(1);
+ const written = JSON.parse(writeFile.mock.calls[0][1]);
+ expect(written.drinks).toHaveLength(1);
+ expect(written.drinks[0].name).toBe('Stout');
+ });
+
+ it('returns null for out-of-bounds remove', async () => {
+ readJSONFile.mockResolvedValue({ drinks: [{ name: 'IPA', oz: 16, abv: 7 }] });
+ expect(await removeCustomDrink(5)).toBeNull();
+ expect(writeFile).not.toHaveBeenCalled();
+ });
+
+ it('normalizes missing drinks array from file', async () => {
+ readJSONFile.mockResolvedValue({ notDrinks: true });
+ const drinks = await getCustomDrinks();
+ expect(drinks).toEqual([]);
+ });
+});