Discovery store keeps harvest, settings and nightly state (BL-0051)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
MaashkinoozheandClaude Opus 5.5 committed 2026-10-25 09:00:41 +01:00
1 parent 62ec69bc0d
commit 23a87099c5
2 files changed
+58 -2

No files matched your search

+39
View File
@@ -46,3 +46,42 @@ test('discovery store publishes atomically and refuses to overwrite corrupt data
assert.throws(() => store.publish({ candidates: {}, feeds: {} }), /refusing to overwrite/);
assert.equal(fs.readFileSync(store.file, 'utf8'), '{broken');
});
function tempStore(t) {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'mc-discovery-meta-'));
t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
return new DiscoveryStore(dir);
}
const emptyRun = () => ({ candidates: {}, feeds: {}, startedAt: new Date().toISOString(), examined: 0, clipped: 0 });
test('store loads a Phase A file without new fields', t => {
const store = tempStore(t);
fs.writeFileSync(store.file, JSON.stringify({ schema: 1, revision: 3, candidates: {}, feeds: {}, lastRun: { status: 'success' } }));
const data = store.load();
assert.equal(data.revision, 3);
assert.equal(data.harvest, null);
assert.equal(data.settings, null);
assert.deepEqual(data.nightly, { lastDate: null });
});
test('patch keeps revision and publish keeps harvest', t => {
const store = tempStore(t);
store.publish(emptyRun());
store.patch({ harvest: { status: 'success' } });
assert.equal(store.load().revision, 1);
store.patch({ settings: { a: 1 } });
store.patch({ nightly: { lastDate: '2026-10-25' } });
store.publish(emptyRun());
const data = store.load();
assert.equal(data.harvest.status, 'success');
assert.deepEqual(data.settings, { a: 1 });
assert.equal(data.nightly.lastDate, '2026-10-25');
assert.equal(data.revision, 2);
});
test('patch refuses a corrupt store', t => {
const store = tempStore(t);
fs.writeFileSync(store.file, '{broken');
assert.throws(() => store.patch({ harvest: {} }), /refusing to overwrite/);
assert.equal(fs.readFileSync(store.file, 'utf8'), '{broken');
});