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([hoist-certmeta-to-top-level-lib]): address codex review

[._.]/ Adam Eivyf62907023f3c
diff --git a/lib/certMeta.js b/lib/certMeta.js
index 9a6f1d2177..1762d519e6 100644
--- a/lib/certMeta.js
+++ b/lib/certMeta.js
@@ -22,11 +22,15 @@
import { readFileSync, statSync } from 'node:fs';
export function readCertMeta(metaPath) {
- const stat = statSync(metaPath, { throwIfNoEntry: false });
- if (!stat) return null;
try {
- return JSON.parse(readFileSync(metaPath, 'utf-8'));
+ const stat = statSync(metaPath, { throwIfNoEntry: false });
+ if (!stat) return null;
+ const parsed = JSON.parse(readFileSync(metaPath, 'utf-8'));
+ return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : null;
} catch {
+ // EACCES on stat / read, EIO, malformed JSON, primitive JSON — every
+ // failure mode collapses to "no meta", matching the legacy inline
+ // try/catch print-access-url.js used to carry.
return null;
}
}
diff --git a/lib/certMeta.test.js b/lib/certMeta.test.js
index bb199f5555..547b63e169 100644
--- a/lib/certMeta.test.js
+++ b/lib/certMeta.test.js
@@ -60,4 +60,24 @@ describe('certMeta.readCertMeta', () => {
expect(statSync).toHaveBeenCalledWith('/alt/data/certs/meta.json', { throwIfNoEntry: false });
expect(readFileSync).toHaveBeenCalledWith('/alt/data/certs/meta.json', 'utf-8');
});
+
+ it('returns null when statSync throws (e.g. EACCES on the parent dir)', () => {
+ statSync.mockImplementation(() => { throw Object.assign(new Error('EACCES'), { code: 'EACCES' }); });
+ expect(readCertMeta(META_PATH)).toBeNull();
+ expect(readFileSync).not.toHaveBeenCalled();
+ });
+
+ it('returns null when readFileSync throws (e.g. EACCES on the file)', () => {
+ statSync.mockReturnValue({ mtimeMs: 1 });
+ readFileSync.mockImplementation(() => { throw Object.assign(new Error('EACCES'), { code: 'EACCES' }); });
+ expect(readCertMeta(META_PATH)).toBeNull();
+ });
+
+ it('returns null when meta.json contains valid-but-primitive JSON (string / number / null / array)', () => {
+ statSync.mockReturnValue({ mtimeMs: 1 });
+ for (const primitive of ['"tailscale"', '42', 'null', 'true', '[1,2]']) {
+ readFileSync.mockReturnValue(primitive);
+ expect(readCertMeta(META_PATH), `expected null for ${primitive}`).toBeNull();
+ }
+ });
});