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
address review (codex): honor PORTOS_PGDUMP override outright
[._.]/ Adam Eivyf3d52439e8c0
diff --git a/server/services/backup.js b/server/services/backup.jsindex da6ee0d7d4..b7c6146367 100644--- a/server/services/backup.js+++ b/server/services/backup.js@@ -271,9 +271,10 @@ async function pgDumpMajor(binary) {* majors coexist and PATH order silently picks the wrong one).*/async function discoverPgDumpCandidates() {- const paths = [];- if (process.env.PORTOS_PGDUMP) paths.push(process.env.PORTOS_PGDUMP);- paths.push('pg_dump'); // whatever PATH resolves — preserves the old default+ // Note: the PORTOS_PGDUMP override is NOT a candidate here — resolvePgDump+ // honors it outright before discovery runs, so it's never subject to the+ // closest-major auto-selection below.+ const paths = ['pg_dump']; // whatever PATH resolves — preserves the old defaultconst kegDirs = ['/opt/homebrew/opt', '/usr/local/opt', '/Applications/Postgres.app/Contents/Versions'];for (const dir of kegDirs) {const entries = await readdir(dir).catch(() => []);@@ -285,7 +286,7 @@ async function discoverPgDumpCandidates() {}// Probe versions concurrently (each `pg_dump --version` is an independent// spawn); [...new Set(paths)] de-dups while preserving priority order, which- // Promise.all keeps — so pickPgDump still sees env > PATH > kegs.+ // Promise.all keeps — so pickPgDump still sees PATH > kegs.const probed = await Promise.all([...new Set(paths)].map(async (binary) => ({ binary, major: await pgDumpMajor(binary) })));@@ -297,10 +298,19 @@ async function discoverPgDumpCandidates() {* chosen path and whether it satisfies the server's version (false ⇒ the dump* will fail with a version mismatch and there's nothing newer installed).*+ * An explicit `PORTOS_PGDUMP` is the user's deliberate escape hatch, so it wins+ * outright — it must NOT be funneled through the closest-major auto-selection+ * (which could otherwise pick a different discovered binary over it). We assume+ * it satisfies the server and let the stderr classifier catch the rare case+ * where the user deliberately pointed at something too old.+ ** @param {number|null} serverMajor* @returns {Promise<{binary: string, satisfies: boolean}>}*/async function resolvePgDump(serverMajor) {+ if (process.env.PORTOS_PGDUMP) {+ return { binary: process.env.PORTOS_PGDUMP, satisfies: true };+ }const candidates = await discoverPgDumpCandidates();const binary = pickPgDump(serverMajor, candidates) || 'pg_dump';const chosen = candidates.find(c => c.binary === binary);diff --git a/server/services/backup.test.js b/server/services/backup.test.jsindex 4387a1c66f..0848657bbf 100644--- a/server/services/backup.test.js+++ b/server/services/backup.test.js@@ -45,7 +45,7 @@ vi.mock('fs/promises', async (importOriginal) => {return { ...actual, stat: vi.fn(actual.stat), readFile: vi.fn(actual.readFile) };});-import { checkHealth } from '../lib/db.js';+import { checkHealth, getServerMajorVersion } from '../lib/db.js';import { getBackendName } from './memoryBackend.js';import * as fs from 'fs/promises';import { DEFAULT_EXCLUDES, computeEffectiveExcludes, pickPgDump } from './backup.js';@@ -310,6 +310,31 @@ describe('dumpPostgres status classification', () => {expect(result.error).toContain('auth failed');});+ it('honors the PORTOS_PGDUMP override outright, even when the server version is known', async () => {+ // Escape hatch: an explicit override must win over auto-discovery's+ // closest-major selection, not be funneled through it (a known server+ // version triggers resolvePgDump, which is where the override short-circuits).+ checkHealth.mockResolvedValue({ connected: true, hasSchema: true });+ getServerMajorVersion.mockResolvedValue(17);+ vi.spyOn(fs, 'stat').mockResolvedValue({ size: 2048 });+ vi.spyOn(fs, 'readFile').mockResolvedValue('CREATE TABLE memories (...);\n');+ const proc = fakeProc();+ spawn.mockReturnValue(proc);+ process.env.PORTOS_PGDUMP = '/custom/bin/pg_dump';+ try {+ const p = dumpPostgres('/tmp/x.sql');+ await flush();+ proc.emit('close', 0);+ await p;+ expect(spawn).toHaveBeenCalledWith('/custom/bin/pg_dump', expect.any(Array), expect.any(Object));+ } finally {+ delete process.env.PORTOS_PGDUMP;+ // clearAllMocks() doesn't reset implementations — restore the null default+ // so later tests keep the bare-pg_dump path (no live binary discovery).+ getServerMajorVersion.mockResolvedValue(null);+ }+ });+it('classifies a "server version mismatch" stderr as failed/version_mismatch, not dump_error', async () => {// Even with the server version unknown (default mock → bare pg_dump), the// stderr regex must reclassify pg_dump's own mismatch error so the UI can