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: distinguish unreadable quality snapshots from missing files

[._.]/ Adam Eivy86de75bd2bdf
diff --git a/server/services/appQualityFederation.test.js b/server/services/appQualityFederation.test.js
index 4cdcc66b2a..f1cafad22f 100644
--- a/server/services/appQualityFederation.test.js
+++ b/server/services/appQualityFederation.test.js
@@ -171,7 +171,7 @@ it('reads v2 and legacy snapshot files without writing, and drops future dates',
expect(JSON.stringify(records)).not.toMatch(/Users|agent-security|app_id|github/);
const legacy = await readReleaseQuality(file(path => {
- if (path.endsWith('.quality.json')) throw new Error('ENOENT');
+ if (path.endsWith('.quality.json')) throw Object.assign(new Error('missing'), { code: 'ENOENT' });
return JSON.stringify(published);
}), managed);
expect(legacy).toMatchObject([{ report: { score: 76 } }]);
diff --git a/server/services/appQualitySnapshotFile.js b/server/services/appQualitySnapshotFile.js
index d784d33966..4ca04c6cbc 100644
--- a/server/services/appQualitySnapshotFile.js
+++ b/server/services/appQualitySnapshotFile.js
@@ -51,8 +51,8 @@ async function readSnapshotEntry(repoPath, filename, deps = {}) {
if (typeof body !== 'string') return { status: 'absent' };
if (Buffer.byteLength(body) > APP_QUALITY_SNAPSHOT_MAX_BYTES) return { status: 'oversize' };
return { status: 'text', body };
- } catch {
- return { status: 'absent' };
+ } catch (error) {
+ return { status: error?.code === 'ENOENT' ? 'absent' : 'unreadable' };
}
}
@@ -73,8 +73,8 @@ async function readClassified(repoPath, filename, deps) {
let body;
try {
body = await (deps.readFile || readFile)(snapshotPath(repoPath, filename), 'utf8');
- } catch {
- return { status: 'absent' };
+ } catch (error) {
+ return { status: error?.code === 'ENOENT' ? 'absent' : 'unreadable', filename };
}
if (typeof body !== 'string') return { status: 'absent' };
if (Buffer.byteLength(body) > APP_QUALITY_SNAPSHOT_MAX_BYTES) return { status: 'oversize' };
diff --git a/server/services/appQualitySnapshotFile.test.js b/server/services/appQualitySnapshotFile.test.js
index c4eef358d4..908bef6205 100644
--- a/server/services/appQualitySnapshotFile.test.js
+++ b/server/services/appQualitySnapshotFile.test.js
@@ -73,7 +73,7 @@ it('reads a committed snapshot and answers null for every unusable file', async
expect(await read('"a string"')).toBeNull();
expect(await read(' '.repeat(APP_QUALITY_SNAPSHOT_MAX_BYTES + 1))).toBeNull();
expect(await readAppQualitySnapshotFile('', { readFile: async () => '{}' })).toBeNull();
- expect(await readAppQualitySnapshotFile('/repo/example-app', { readFile: async () => { throw new Error('ENOENT'); } })).toBeNull();
+ expect(await readAppQualitySnapshotFile('/repo/example-app', { readFile: async () => { throw Object.assign(new Error('missing'), { code: 'ENOENT' }); } })).toBeNull();
expect(APP_QUALITY_SNAPSHOT_FILENAME).toBe('.quality.json');
expect(QUALITY_SNAPSHOT_BRANCH).toBe('portos/quality-snapshot');
});
@@ -427,7 +427,7 @@ it('reads v1, v2, and the legacy filename without falling past a canonical file'
const read = files => readStoredQualitySnapshot('/repo/example-app', {
readFile: async path => {
const name = basename(path);
- if (!Object.hasOwn(files, name)) throw new Error('ENOENT');
+ if (!Object.hasOwn(files, name)) throw Object.assign(new Error('missing'), { code: 'ENOENT' });
return files[name];
},
});
@@ -440,4 +440,12 @@ it('reads v1, v2, and the legacy filename without falling past a canonical file'
expect(both.status).toBe('v2');
expect((await read({ '.quality.json': 'not-json', [APP_QUALITY_LEGACY_SNAPSHOT_FILENAME]: v1 })).status).toBe('unrecognized');
expect((await read({ '.quality.json': ' '.repeat(APP_QUALITY_SNAPSHOT_MAX_BYTES + 1) })).status).toBe('oversize');
+ const unreadable = await readStoredQualitySnapshot('/repo/example-app', {
+ readFile: async path => {
+ if (basename(path) === '.quality.json') throw Object.assign(new Error('denied'), { code: 'EACCES' });
+ return v1;
+ },
+ });
+ expect(unreadable.status).toBe('unreadable');
+ expect(unreadable.filename).toBe('.quality.json');
});