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

stub access() in the settings fail-closed test instead of relying on a POSIX-only errno

[._.]/ Adam Eivyd8aa6a82e6c1
diff --git a/server/services/settings.test.js b/server/services/settings.test.js
index a307bc04bf..13c1e9d5c7 100644
--- a/server/services/settings.test.js
+++ b/server/services/settings.test.js
@@ -13,6 +13,16 @@ vi.mock('../lib/fileUtils.js', async (importActual) => {
};
});
+// readSettingsStrict probes with a real access() for the absent-vs-unreadable
+// split, so keep the real implementation as the default and let a single test
+// override it to drive the non-ENOENT branch (see below for why it can't use a
+// real filesystem quirk).
+vi.mock('fs/promises', async (importActual) => {
+ const actual = await importActual();
+ return { ...actual, access: vi.fn(actual.access) };
+});
+
+import { access } from 'fs/promises';
import { writeFileSync, mkdtempSync, rmSync } from 'fs';
import { join as joinPath } from 'path';
import { tmpdir } from 'os';
@@ -546,13 +556,19 @@ describe('settings.js', () => {
});
it('fails closed when access() errors for a non-ENOENT reason (only ENOENT is absent)', async () => {
- // A path whose parent component is a FILE, not a directory, makes access()
- // throw ENOTDIR (not ENOENT) — we cannot confirm the file is absent, so it
- // must classify as corrupt (fail closed), never as an absent fresh install.
- const notADir = joinPath(dir, 'iamafile');
- writeFileSync(notADir, 'x');
+ // access() failing does not by itself prove the file is absent — ENOTDIR (a
+ // path component is a file), EACCES (parent lacks search permission) and EIO
+ // all leave absence unconfirmed, so they must classify as corrupt (fail
+ // closed), never as an absent fresh install.
+ //
+ // Driven through a stubbed access() rather than a real filesystem quirk: the
+ // errno for "parent component is a file" is ENOTDIR on POSIX but ENOENT on
+ // Windows, so a real path flipped this assertion by platform and failed CI.
+ const notADirErr = new Error('ENOTDIR: not a directory');
+ notADirErr.code = 'ENOTDIR';
+ access.mockRejectedValueOnce(notADirErr);
tryReadFile.mockResolvedValue(null);
- const res = await readSettingsStrict(joinPath(notADir, 'settings.json'));
+ const res = await readSettingsStrict(joinPath(dir, 'settings.json'));
expect(res.present).toBe(true);
expect(res.corrupt).toBe(true);
});