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(backup): use native filesystem capability under platform fixtures

[._.]/ Adam Eivy2e9453666111
diff --git a/docs/BACKUP_PUBLICATION_ADMISSION.md b/docs/BACKUP_PUBLICATION_ADMISSION.md
index 70be1c7061..9d9d102c1d 100644
--- a/docs/BACKUP_PUBLICATION_ADMISSION.md
+++ b/docs/BACKUP_PUBLICATION_ADMISSION.md
@@ -18,7 +18,9 @@ checking the cut; the cut registers before checking readers. This ordering close
the cross-process admission race. A preliminary gate check avoids registering
and deleting leases repeatedly during a long snapshot. Directory creation and
removal work on Windows and POSIX; ownership files are fsynced, with directory
-fsync on POSIX (Windows does not support opening a directory that way).
+fsync on POSIX (Windows does not support opening a directory that way). The
+directory-sync capability follows the native host OS associated with the filesystem;
+a simulated product platform must not change durability behavior.
If a publication cannot restore its previous pair, throw an error with
`backupPublicationUncertain: true`. The boundary settles its local callback count
diff --git a/server/lib/backupSharedAdmission.js b/server/lib/backupSharedAdmission.js
index cb2f72d630..4f44d86c5a 100644
--- a/server/lib/backupSharedAdmission.js
+++ b/server/lib/backupSharedAdmission.js
@@ -2,6 +2,7 @@
import * as fs from 'node:fs';
import { randomUUID } from 'node:crypto';
import { dirname, join } from 'node:path';
+import { type as hostOsType } from 'node:os';
import { PATHS } from './paths.js';
import { assertNotRealDataWrite } from './testDataIsolation.js';
@@ -16,7 +17,7 @@ const busy = (message, details = {}) => Object.assign(new Error(message), {
* or observes the gate and never starts its mutation. No PID/age reclamation:
* a crashed writer may have left half a publication behind.
*/
-export function createBackupSharedAdmission(directory, { io = fs, makeId = randomUUID, assertWrite = assertNotRealDataWrite } = {}) {
+export function createBackupSharedAdmission(directory, { io = fs, makeId = randomUUID, assertWrite = assertNotRealDataWrite, syncDirectories = hostOsType() !== 'Windows_NT' } = {}) {
const readers = join(directory, 'publications');
const cutPath = join(directory, 'cut');
const generation = makeId();
@@ -25,7 +26,9 @@ export function createBackupSharedAdmission(directory, { io = fs, makeId = rando
catch (error) { if (error.code === 'ENOENT') return false; throw error; }
};
const syncDir = path => {
- if (process.platform === 'win32') return;
+ // This capability belongs to the backing filesystem, not a caller's
+ // emulated process.platform (e.g. a macOS render fixture on Windows).
+ if (!syncDirectories) return;
const fd = io.openSync(path, 'r');
try { io.fsyncSync(fd); } finally { io.closeSync(fd); }
};
diff --git a/server/lib/backupSharedAdmission.test.js b/server/lib/backupSharedAdmission.test.js
index bb26617dc3..8599c30d0d 100644
--- a/server/lib/backupSharedAdmission.test.js
+++ b/server/lib/backupSharedAdmission.test.js
@@ -3,7 +3,8 @@ import { spawn } from 'node:child_process';
import { mkdtemp, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
import * as syncFs from 'node:fs';
import { existsSync } from 'node:fs';
-import { tmpdir } from 'node:os';
+import { tmpdir, type as hostOsType } from 'node:os';
+import { pinPlatform } from './testHelper.js';
import { join } from 'node:path';
import { once } from 'node:events';
import { createBackupSharedAdmission } from './backupSharedAdmission.js';
@@ -137,6 +138,31 @@ describe('shared snapshot admission between real server and runner processes', (
} finally { lease.release(); }
});
+ it('keeps real filesystem durability when a caller pins the opposite platform', async () => {
+ const path = await root();
+ const directory = join(path, 'data/backup-admission');
+ const nativeWindows = hostOsType() === 'Windows_NT';
+ const opened = new Map();
+ const synced = [];
+ const io = { ...syncFs,
+ openSync(path, ...args) { const fd = syncFs.openSync(path, ...args); opened.set(fd, path); return fd; },
+ fsyncSync(fd) { synced.push(opened.get(fd)); syncFs.fsyncSync(fd); },
+ };
+ const restorePlatform = pinPlatform(nativeWindows ? 'darwin' : 'win32');
+ try {
+ const admission = createBackupSharedAdmission(directory, { io });
+ const lease = admission.tryPublication();
+ expect(synced).toContain(join(lease.path, 'owner.json'));
+ expect(synced.includes(directory)).toBe(!nativeWindows);
+ const cut = admission.reserveCut();
+ expect(admission.status().publications).toHaveLength(1);
+ lease.release();
+ expect(admission.status().publications).toHaveLength(0);
+ cut.release();
+ expect(admission.status().cut).toBeNull();
+ } finally { restorePlatform(); }
+ });
+
it('keeps a killed writer as a durable blocker across coordinator restarts', async () => {
const path = await root();
const writer = worker(path, 'publication', 'half pair');
diff --git a/server/test/admissionSetup.js b/server/test/admissionSetup.js
index 21de015d6d..fc84648726 100644
--- a/server/test/admissionSetup.js
+++ b/server/test/admissionSetup.js
@@ -33,10 +33,11 @@ vi.mock('../lib/backupSharedAdmission.js', async (importOriginal) => {
const actual = await importOriginal();
const io = await vi.importActual('node:fs');
const { randomUUID } = await vi.importActual('node:crypto');
+ const { type } = await vi.importActual('node:os');
const root = io.mkdtempSync(join(tmpdir(), 'backup-admission-workflow-'));
const entry = { io, root, closed: false };
coordinatorTestRoots.push(entry);
- return { ...actual, backupSharedAdmission: actual.createBackupSharedAdmission(root, { io, makeId: randomUUID, assertWrite: path => {
+ return { ...actual, backupSharedAdmission: actual.createBackupSharedAdmission(root, { io, makeId: randomUUID, syncDirectories: type() !== 'Windows_NT', assertWrite: path => {
if (entry.closed || path !== root) throw new Error('Unexpected backup admission test path');
} }) };
});