aboutsummaryrefslogtreecommitdiff
path: root/modules/test/test-world-model-ask.js
blob: 4a0c21adff206e5c224184db4913555e471ed21c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// node modules/test/test-world-model-ask.js
// Executes the real class from module-world-model.js (no imports, no DOM at class level).
const fs = require('fs');
const path = require('path');
const src = fs.readFileSync(path.join(__dirname, '../core/module-world-model.js'), 'utf8');
const WorldModelModule = new Function(src + '\nreturn WorldModelModule;')();

const wm = new WorldModelModule();
const failures = [];
const check = (name, cond, detail) => {
    if (!cond) failures.push(name + (detail ? ' — ' + detail : ''));
    console.log((cond ? 'PASS' : 'FAIL'), name, detail || '');
};

// no model yet
check('empty model digest is empty', wm._modelDigest() === '');

wm._model = {
    version: 'v4.6.47', synthesized: '2026-10-21T20:00:00.000Z',
    system: { health: 'ok', memory: '3 MB' },
    modules: { loaded: 30, total: 30, modifiedCount: 0, modified: [] },
    files: { total: 42, directories: 8, size: '12 KB' },
    skills: { count: 23, skills: Array.from({ length: 60 }, (_, i) => 'skill-' + i) },
    memory: { nodes: 120, edges: 200, active: true },
    agents: { agents: 4, active: 1 },
    telemetry: { toolLatencyDataPoints: 9, recentErrors: 0 },
    projects: { totalTasks: 3, activeProjects: [] },
    recent: ['Skills directory: 23 files']
};

const digest = wm._modelDigest();
check('digest is valid JSON', (() => { try { JSON.parse(digest); return true; } catch (e) { return false; } })());
check('digest is capped at 4000', digest.length <= 4000, digest.length + ' chars');
check('digest keeps counts', /"count":23/.test(digest) && /"loaded":30/.test(digest));
check('digest trims the skill list to 40', (JSON.parse(digest).skills.skills || []).length === 40,
      String((JSON.parse(digest).skills.skills || []).length));

const prompt = wm._buildAskPrompt('  why did the build break?  ');
check('prompt carries the question', /QUESTION: why did the build break\?$/.test(prompt), prompt.slice(-60));
check('prompt carries the snapshot', prompt.indexOf('SNAPSHOT: {') > 0);
check('prompt forbids invention', /Never invent numbers/.test(prompt));

check('facts path still answers a keyword', /30 modules/.test(wm._answerQuery('how many modules')));
check('facts path still refuses nonsense', /Unknown query/.test(wm._answerQuery('why did it break')));

console.log(failures.length ? '\n' + failures.length + ' FAILED' : '\nall PASS');
process.exit(failures.length ? 1 : 0);