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
docs([issue-1893]): document atomicWrite symlink-replace semantics with pinning test
[._.]/ Adam Eivy133edc25afbf
diff --git a/server/lib/fileUtils.js b/server/lib/fileUtils.jsindex a5b11a62dd..62cab55f86 100644--- a/server/lib/fileUtils.js+++ b/server/lib/fileUtils.js@@ -201,6 +201,16 @@ export async function ensureDirs(dirs) {* Guarantees readers never see a partial write. Accepts a string or any JSON-* serializable value (objects are stringified with 2-space indentation).*+ * Symlink semantics (design decision, issue #1893): when `filePath` is a+ * symlink, the temp+rename REPLACES the link with a regular file — it does NOT+ * follow the link to update the backing file. This is the standard atomic-write+ * contract (git, dpkg, rsync, `os.replace` all replace the link); following the+ * link would reintroduce the non-atomic in-place truncate this helper exists to+ * eliminate. PortOS ships no symlinked data files, so this is a documented+ * property rather than a supported use case — do not pass a symlink you expect+ * to be followed. Callers that genuinely need follow-the-link semantics must+ * resolve `realpath(filePath)` themselves before calling.+ ** @param {string} filePath - Destination file path* @param {string|object} data - String or JSON-serializable value* @returns {Promise<void>}diff --git a/server/lib/fileUtils.test.js b/server/lib/fileUtils.test.jsindex 8dce9022c6..0f7e4b320a 100644--- a/server/lib/fileUtils.test.js+++ b/server/lib/fileUtils.test.js@@ -1171,6 +1171,29 @@ describe('fileUtils', () => {await atomicWrite(target, { created: true });expect(JSON.parse(await readFile(target, 'utf8'))).toEqual({ created: true });});++ it.skipIf(process.platform === 'win32')(+ 'replaces a symlink target with a regular file rather than following it (design decision: #1893)',+ async () => {+ // Decision pinned by this test: temp+rename REPLACES the link, standard+ // atomic-write semantics — it does NOT follow the symlink to update the+ // backing file. Following would reintroduce the non-atomic in-place+ // truncate atomicWrite exists to avoid. See the JSDoc + issue #1893.+ const { symlinkSync, lstatSync } = await import('fs');+ const backing = join(tmpRoot, 'backing.json');+ const link = join(tmpRoot, 'link.json');+ writeFileSync(backing, '{"orig":true}');+ symlinkSync(backing, link);++ await atomicWrite(link, { replaced: true });++ // The link path is now a regular file holding the new content...+ expect(lstatSync(link).isSymbolicLink()).toBe(false);+ expect(JSON.parse(await readFile(link, 'utf8'))).toEqual({ replaced: true });+ // ...and the original backing file is untouched (link was not followed).+ expect(JSON.parse(await readFile(backing, 'utf8'))).toEqual({ orig: true });+ }+ );});});