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: import-less writeFile crashed every backup at the manifest step
[._.]/ Adam Eivy3e6835b8e62c
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 412dc0a582..d4b07904e0 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -18,6 +18,8 @@## Fixed+- **Backups no longer fail at the manifest step** — every `POST /api/backup/run` completed the rsync mirror and the `pg_dump`, then crashed with `writeFile is not defined` while writing the snapshot's `manifest.json` (the write used a bare `writeFile` that was never imported). The manifest now writes through the already-imported `atomicWrite` helper, and `generateManifest` gained end-to-end test coverage so a missing import can't silently reappear. (`server/services/backup.js`)+- **Uploaded init/reference images stop duplicating into the gallery on every render** — an uploaded init image (i2i / edit renders) was staged into `data/images`, the very directory the gallery enumerates, so each render dropped a fresh `init-<uuid>.png` copy there and it surfaced as a duplicate "(no prompt)" card alongside the actual output. Init uploads now stage into `data/image-refs` (the sibling dir multi-reference uploads already use — served statically but excluded from the gallery listing), and the Codex i2i path re-anchors through `resolveImageInputPath` so it still finds them. A migration relocates the orphaned staged-upload files prior renders already left in the gallery (moved, not deleted, so they stay reachable as inputs). (`server/services/imageGen/prepareParams.js`, `server/services/imageGen/codex.js`, `scripts/migrations/085-relocate-staged-upload-images-out-of-gallery.js`)- **[issue-1183] Review Hub, System Health, and song video embeds lay out better** — the Review Hub now spreads its alert/CoS/todo/briefing sections across two columns on wide screens instead of one tall stack; the System Health page no longer carries an extra band of padding on larger screens; and a TikTok reference video in the song editor now scales to fit instead of getting clipped on shorter windows.diff --git a/server/services/backup.js b/server/services/backup.jsindex 9dc5713ac6..740fdca1b4 100644--- a/server/services/backup.js+++ b/server/services/backup.js@@ -394,7 +394,7 @@ export async function generateManifest(snapshotDataDir, manifestPath, pgDumpPathfiles};- await writeFile(manifestPath, JSON.stringify(manifest, null, 2), 'utf-8');+ await atomicWrite(manifestPath, manifest);console.log(`💾 Backup manifest: ${manifest.fileCount} files`);return manifest;}diff --git a/server/services/backup.test.js b/server/services/backup.test.jsindex 6ed32949ba..32ca667502 100644--- a/server/services/backup.test.js+++ b/server/services/backup.test.js@@ -594,3 +594,64 @@ describe('runBackup pg status propagation', () => {expect(backupStatusForPg({ status: 'ok', sizeBytes: 10, tableCount: 1 })).toBe('ok');});});++describe('generateManifest', () => {+ // Regression: the manifest write used a bare `writeFile` that was never+ // imported, so every real backup threw `writeFile is not defined` at the+ // very end of generateManifest. This exercises the actual write path+ // (atomicWrite) end-to-end against a real temp dir so a missing import+ // can never silently reappear.+ let tmpRoot;+ beforeEach(async () => {+ // Earlier suites install persistent vi.spyOn(fs, 'readdir'/'stat') mocks+ // (e.g. stat → { isFile: () => true }). Those leak into these real-+ // filesystem tests, so restore the spies AND re-point the factory-level+ // stat/readFile wrappers back at the genuine implementations.+ vi.restoreAllMocks();+ vi.clearAllMocks();+ const realFs = await vi.importActual('fs/promises');+ fs.stat.mockImplementation(realFs.stat);+ fs.readFile.mockImplementation(realFs.readFile);+ vi.resetModules();+ const { mkdtemp } = await import('fs/promises');+ const { tmpdir } = await import('os');+ const { join } = await import('path');+ tmpRoot = await mkdtemp(join(tmpdir(), 'portos-manifest-'));+ });++ it('writes the manifest file and returns hashes for every data file', async () => {+ const { mkdir, writeFile, readFile } = await import('fs/promises');+ const { join } = await import('path');+ const dataDir = join(tmpRoot, 'data');+ await mkdir(join(dataDir, 'sub'), { recursive: true });+ await writeFile(join(dataDir, 'a.txt'), 'hello');+ await writeFile(join(dataDir, 'sub', 'b.txt'), 'world');++ const manifestPath = join(tmpRoot, 'manifest.json');+ const { generateManifest } = await import('./backup.js');+ const manifest = await generateManifest(dataDir, manifestPath);++ expect(manifest.fileCount).toBe(2);+ expect(manifest.files['a.txt']).toMatch(/^[0-9a-f]{64}$/);+ expect(manifest.files[join('sub', 'b.txt')]).toMatch(/^[0-9a-f]{64}$/);++ // The file must actually be written (the regression was a write-time throw).+ const written = JSON.parse(await readFile(manifestPath, 'utf-8'));+ expect(written).toEqual(manifest);+ });++ it('includes the parent-relative pg dump hash when a dump path is given', async () => {+ const { writeFile } = await import('fs/promises');+ const { join } = await import('path');+ const { mkdir } = await import('fs/promises');+ const dataDir = join(tmpRoot, 'data');+ await mkdir(dataDir, { recursive: true });+ const dumpPath = join(tmpRoot, 'portos-db.sql');+ await writeFile(dumpPath, 'PG DUMP');++ const { generateManifest } = await import('./backup.js');+ const manifest = await generateManifest(dataDir, join(tmpRoot, 'manifest.json'), dumpPath);++ expect(manifest.files['../portos-db.sql']).toMatch(/^[0-9a-f]{64}$/);+ });+});