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
fix: address round 9 review — migration validation, drinks normalization, marker timing
Adam Eivye9a3cf173626
diff --git a/scripts/portos-update.sh b/scripts/portos-update.shindex 85ab1ce696..836aba4487 100755--- a/scripts/portos-update.sh+++ b/scripts/portos-update.sh@@ -65,10 +65,10 @@ step "restart" "running" "Restarting PortOS..."log "=== PortOS update to $TAG restarting ==="+# Write completion marker before restart so server reads it on boot+echo "{\"version\":\"${TAG#v}\",\"completedAt\":\"$(date -u +%Y-%m-%dT%H:%M:%SZ)\"}" > "$ROOT_DIR/data/update-complete.json"+# Use the local pm2 binary to restartnode "$ROOT_DIR/node_modules/pm2/bin/pm2" restart ecosystem.config.cjs >> "$LOG_FILE" 2>&1-# Write completion marker after successful restart (server reads this on boot)-echo "{\"version\":\"${TAG#v}\",\"completedAt\":\"$(date -u +%Y-%m-%dT%H:%M:%SZ)\"}" > "$ROOT_DIR/data/update-complete.json"-step "restart" "done" "PortOS restarted"diff --git a/scripts/run-migrations.js b/scripts/run-migrations.jsindex 47ef64bfe0..560e59123a 100644--- a/scripts/run-migrations.js+++ b/scripts/run-migrations.js@@ -35,7 +35,11 @@ async function run() {if (applied.includes(file)) continue;console.log(`🔄 Running migration: ${file}`);- const migration = await import(pathToFileURL(join(migrationsDir, file)).href);+ const mod = await import(pathToFileURL(join(migrationsDir, file)).href);+ const migration = (mod?.default && typeof mod.default.up === 'function') ? mod.default : mod;+ if (!migration || typeof migration.up !== 'function') {+ throw new Error(`Migration "${file}" does not export an up() function`);+ }await migration.up({ rootDir, migrationsDir });applied.push(file);await writeFile(appliedFile, JSON.stringify(applied, null, 2) + '\n');diff --git a/server/services/meatspaceAlcohol.js b/server/services/meatspaceAlcohol.jsindex 2de0381007..570d876a7c 100644--- a/server/services/meatspaceAlcohol.js+++ b/server/services/meatspaceAlcohol.js@@ -272,6 +272,7 @@ async function loadCustomDrinks() {await saveCustomDrinks(seeded);return seeded;}+ if (!Array.isArray(data.drinks)) data.drinks = [];return data;}diff --git a/server/services/meatspaceAlcohol.test.js b/server/services/meatspaceAlcohol.test.jsindex c67ad6b14f..fda0cf8064 100644--- a/server/services/meatspaceAlcohol.test.js+++ b/server/services/meatspaceAlcohol.test.js@@ -264,3 +264,72 @@ describe('computeRollingAverages', () => {expect(result.totalEntries).toBe(3);});});++// =============================================================================+// CUSTOM DRINK BUTTON LOGIC TESTS (inline logic mirroring service functions)+// =============================================================================++describe('custom drink button logic', () => {+ // Mirrors loadCustomDrinks normalization+ function normalizeCustomDrinks(data) {+ if (!data) return { drinks: [] };+ if (!Array.isArray(data.drinks)) data.drinks = [];+ return data;+ }++ it('normalizes null data to empty drinks array', () => {+ const result = normalizeCustomDrinks(null);+ expect(result).toEqual({ drinks: [] });+ });++ it('normalizes data without drinks key', () => {+ const result = normalizeCustomDrinks({ something: 'else' });+ expect(result.drinks).toEqual([]);+ });++ it('normalizes non-array drinks to empty array', () => {+ const result = normalizeCustomDrinks({ drinks: 'invalid' });+ expect(result.drinks).toEqual([]);+ });++ it('preserves valid drinks array', () => {+ const drinks = [{ name: 'Beer', oz: 12, abv: 5 }];+ const result = normalizeCustomDrinks({ drinks });+ expect(result.drinks).toEqual(drinks);+ });++ it('preserves empty drinks array', () => {+ const result = normalizeCustomDrinks({ drinks: [] });+ expect(result.drinks).toEqual([]);+ });++ // Mirrors index bounds checking in update/remove/reorder+ function isValidIndex(index, length) {+ return Number.isInteger(index) && index >= 0 && index < length;+ }++ it('rejects NaN index', () => {+ expect(isValidIndex(NaN, 5)).toBe(false);+ });++ it('rejects float index', () => {+ expect(isValidIndex(1.5, 5)).toBe(false);+ });++ it('rejects negative index', () => {+ expect(isValidIndex(-1, 5)).toBe(false);+ });++ it('rejects out-of-bounds index', () => {+ expect(isValidIndex(5, 5)).toBe(false);+ });++ it('accepts valid index', () => {+ expect(isValidIndex(0, 5)).toBe(true);+ expect(isValidIndex(4, 5)).toBe(true);+ });++ it('rejects any index for empty list', () => {+ expect(isValidIndex(0, 0)).toBe(false);+ });+});