From 9263157a9e4c0eac154fc3ac589c7e6431354d34 Mon Sep 17 00:00:00 2001 From: MrSphay Date: Sat, 4 Jul 2026 12:25:58 +0200 Subject: [PATCH 1/2] fix: persist LLM predictions without stable ID shadowing --- lib/intelligence-store.mjs | 4 +-- package.json | 2 +- test/intelligence-store.test.mjs | 44 ++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 test/intelligence-store.test.mjs diff --git a/lib/intelligence-store.mjs b/lib/intelligence-store.mjs index fff20d3..5859c50 100644 --- a/lib/intelligence-store.mjs +++ b/lib/intelligence-store.mjs @@ -205,7 +205,7 @@ export class IntelligenceStore { _recordPredictions(data, timestamp) { for (const idea of data.ideas || []) { const title = idea.title || 'Untitled idea'; - const stableId = stableId('prediction', title, idea.type || '', idea.ticker || '', idea.horizon || ''); + const predictionId = stableId('prediction', title, idea.type || '', idea.ticker || '', idea.horizon || ''); const evidence = Array.isArray(idea.signals) ? idea.signals : []; this.db.prepare(`INSERT INTO predictions ( stable_id, created_at, updated_at, title, type, hypothesis, evidence_json, confidence, @@ -217,7 +217,7 @@ export class IntelligenceStore { confidence=excluded.confidence, evidence_json=excluded.evidence_json, payload_json=excluded.payload_json`).run( - stableId, + predictionId, timestamp, timestamp, title, diff --git a/package.json b/package.json index 821f995..48e2c81 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "brief:save": "node apis/save-briefing.mjs", "diag": "node diag.mjs", "test": "npm run test:unit", - "test:unit": "node --test test/llm-openrouter.test.mjs test/llm-ollama.test.mjs test/llm-openai-compatible.test.mjs test/llm-litellm.test.mjs test/llm-ideas.test.mjs test/fetch-utils.test.mjs test/reddit-source.test.mjs test/acled-source.test.mjs test/mojibake-text.test.mjs test/adsb.test.mjs test/dashboard-geotagging.test.mjs", + "test:unit": "node --test test/llm-openrouter.test.mjs test/llm-ollama.test.mjs test/llm-openai-compatible.test.mjs test/llm-litellm.test.mjs test/llm-ideas.test.mjs test/intelligence-store.test.mjs test/fetch-utils.test.mjs test/reddit-source.test.mjs test/acled-source.test.mjs test/mojibake-text.test.mjs test/adsb.test.mjs test/dashboard-geotagging.test.mjs", "compose:config": "docker compose config", "clean": "node scripts/clean.mjs", "fresh-start": "npm run clean && npm start" diff --git a/test/intelligence-store.test.mjs b/test/intelligence-store.test.mjs new file mode 100644 index 0000000..183a719 --- /dev/null +++ b/test/intelligence-store.test.mjs @@ -0,0 +1,44 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { mkdtempSync, rmSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; +import { IntelligenceStore } from '../lib/intelligence-store.mjs'; + +test('records LLM ideas as stable predictions', async (t) => { + const directory = mkdtempSync(join(tmpdir(), 'intelligence-store-')); + t.after(() => rmSync(directory, { recursive: true, force: true })); + + const store = await new IntelligenceStore(join(directory, 'intelligence.db')).init(); + if (!store.available) { + t.skip(`node:sqlite unavailable: ${store.reason}`); + return; + } + + store.recordRun({ + meta: { + timestamp: '2026-07-04T10:17:51.011Z', + sourcesOk: 22, + sourcesDegraded: 7, + sourcesFailed: 0, + }, + ideasSource: 'llm', + ideas: [{ + title: 'Gold safe-haven hedge', + type: 'HEDGE', + ticker: 'GLD', + confidence: 'MEDIUM', + rationale: 'Geopolitical risk remains elevated.', + risk: 'Risk appetite recovers.', + horizon: 'Weeks', + signals: ['geopolitical escalation'], + source: 'llm', + }], + }, { summary: { direction: 'risk-off' } }); + + const result = store.listPredictions({ limit: 10 }); + assert.equal(result.available, true); + assert.equal(result.predictions.length, 1); + assert.equal(result.predictions[0].title, 'Gold safe-haven hedge'); + assert.match(result.predictions[0].stable_id, /^prediction-/); +}); From 84b2c9ebc9fa3577ce846be1bc2cfc639775d0cd Mon Sep 17 00:00:00 2001 From: MrSphay Date: Sat, 4 Jul 2026 12:27:57 +0200 Subject: [PATCH 2/2] test: assert hashed prediction identifier format --- test/intelligence-store.test.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/intelligence-store.test.mjs b/test/intelligence-store.test.mjs index 183a719..8ebd328 100644 --- a/test/intelligence-store.test.mjs +++ b/test/intelligence-store.test.mjs @@ -40,5 +40,5 @@ test('records LLM ideas as stable predictions', async (t) => { assert.equal(result.available, true); assert.equal(result.predictions.length, 1); assert.equal(result.predictions[0].title, 'Gold safe-haven hedge'); - assert.match(result.predictions[0].stable_id, /^prediction-/); + assert.match(result.predictions[0].stable_id, /^[a-f0-9]{24}$/); });