@indra.ai/deva.systems 0.15.3 → 0.15.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.test.js +356 -1
  2. package/package.json +1 -1
package/index.test.js CHANGED
@@ -1,7 +1,362 @@
1
1
  "use strict";
2
- // Systems Deva test file
2
+ // Systems Deva Test File
3
3
  // Copyright ©2000-2026 Quinn Michaels; All rights reserved.
4
4
  // Owner Signature Required For Lawful Use.
5
5
  // Distributed under VLA:24296120490769123430 LICENSE.md
6
6
  // Saturday, November 28, 2026 - 6:15:10 AM PST
7
7
 
8
+ // run with: npm test
9
+ import test, {after} from 'node:test';
10
+ import assert from 'node:assert/strict';
11
+ import {createHash} from 'node:crypto';
12
+ import {dirname} from 'node:path';
13
+ import {fileURLToPath} from 'node:url';
14
+ import Deva from '@indra.ai/deva';
15
+ import core from '@indra.ai/deva/package.json' with {type:'json'};
16
+ import pkg from './package.json' with {type:'json'};
17
+ import featureMethods from './feature/methods.js';
18
+ import SYSTEMS from './index.js';
19
+
20
+ const DIR = dirname(fileURLToPath(import.meta.url));
21
+ const STAGES = ['start', 'enter', 'done', 'ready'];
22
+ const TIERS = ['md5', 'sha256', 'sha512'];
23
+ const PLACEHOLDER = /::[a-z-]+::|\{\{profile\.[a-z]+\}\}/;
24
+ const FEATURE_KEYS = ['systems'];
25
+ const CLIENT_ID = '00000000000000000000';
26
+
27
+ const digest = (data, algo) => createHash(algo).update(JSON.stringify(data)).digest('base64');
28
+
29
+ function assertTiers(stamped, label) {
30
+ const base = {};
31
+ for (const [k, v] of Object.entries(stamped)) {
32
+ if (!TIERS.includes(k)) base[k] = v;
33
+ }
34
+ const walk = {...base};
35
+ for (const t of TIERS) {
36
+ assert.equal(typeof stamped[t], 'string', `${label} has ${t}`);
37
+ assert.equal(stamped[t], digest(walk, t), `${label} ${t} covers the data and the tiers before it`);
38
+ walk[t] = stamped[t];
39
+ }
40
+ }
41
+
42
+ // stub client built in code: the core VLA for the core check and the agent VLA for Systems Deva.
43
+ // methods, when set, is bound at init from features.systems.methods by the feature loader.
44
+ // restricted lists the lowercase field names that systems() masks. smoke is a nested block with an id,
45
+ // secret is a top-level restricted field, and visible is a top-level field that stays readable.
46
+ const client = (agentVLA = pkg.VLA, methods = false) => ({
47
+ id: CLIENT_ID,
48
+ key: 'client',
49
+ VLA: structuredClone(core.VLA),
50
+ prompt: {
51
+ emoji: '🧪',
52
+ text: 'client',
53
+ colors: {
54
+ label: {R: 2, G: 229, B: 77},
55
+ text: {R: 2, G: 229, B: 77},
56
+ },
57
+ },
58
+ profile: {
59
+ id: CLIENT_ID,
60
+ name: 'Test Client',
61
+ describe: 'Test client for Systems Deva',
62
+ lang: 'en',
63
+ locale: 'en-US',
64
+ currency: 'USD',
65
+ },
66
+ features: {
67
+ license: {
68
+ concerns: [],
69
+ global: {},
70
+ devas: {
71
+ systems: structuredClone(agentVLA),
72
+ },
73
+ },
74
+ systems: {
75
+ concerns: ['first systems concern', 'second systems concern'],
76
+ global: {
77
+ restricted: ['uri', 'password', 'secret', 'token'],
78
+ smoke: {id: 'g1', text: 'ok', token: 'nested-token-value', uri: 'nested-uri-value', Password: 'nested-mixed-case-value'},
79
+ secret: 'top-secret-value',
80
+ password: 'top-password-value',
81
+ visible: 'public-ok',
82
+ },
83
+ methods: methods || undefined,
84
+ },
85
+ },
86
+ });
87
+
88
+ const packet = (deva, text = 'help', params = []) => ({
89
+ id: deva.uid(),
90
+ q: {text, meta: {params}},
91
+ });
92
+
93
+ function parseAnswer(text = 'parsed', html = '<p>ok</p>', data = {ok: true}) {
94
+ return {a: {text, html, data}};
95
+ }
96
+
97
+ // Systems Deva onError console.logs every error that this.err hands it.
98
+ // the error-path test throws on purpose, so mute console.log while it runs.
99
+ async function withMutedLog(fn) {
100
+ const orig = console.log;
101
+ console.log = () => {};
102
+ try {
103
+ return await fn();
104
+ } finally {
105
+ console.log = orig;
106
+ }
107
+ }
108
+
109
+ let FEATURE = null;
110
+
111
+ after(async () => {
112
+ if (SYSTEMS._active) await SYSTEMS.stop();
113
+ if (FEATURE._active) await FEATURE.stop();
114
+ });
115
+
116
+ test('systems builds as a Deva and waits offline before init', async () => {
117
+ assert.ok(SYSTEMS instanceof Deva, 'the export is a Deva');
118
+ assert.equal(SYSTEMS._agent.key, 'systems', 'agent key is systems');
119
+ assert.equal(SYSTEMS.agent(), SYSTEMS._messages.offline, 'agent answers offline before init');
120
+ assert.equal(await SYSTEMS.stop(), SYSTEMS._messages.offline, 'stop before init answers offline');
121
+ });
122
+
123
+ test('systems data has no placeholders left', () => {
124
+ assert.doesNotMatch(JSON.stringify(pkg.data), PLACEHOLDER, 'package.json data');
125
+ assert.doesNotMatch(JSON.stringify(pkg.VLA), PLACEHOLDER, 'package.json VLA');
126
+ assert.doesNotMatch(pkg.copyright, PLACEHOLDER, 'package.json copyright');
127
+ });
128
+
129
+ test('func, methods, and listeners start empty, and onInit, onReady, and onError exist', () => {
130
+ assert.deepEqual(Object.keys(SYSTEMS.func), [], 'func starts empty');
131
+ assert.deepEqual(Object.keys(SYSTEMS.methods), [], 'methods starts empty');
132
+ assert.deepEqual(Object.keys(SYSTEMS.listeners), [], 'listeners starts empty');
133
+ assert.equal(typeof SYSTEMS.onInit, 'function', 'onInit');
134
+ assert.equal(typeof SYSTEMS.onReady, 'function', 'onReady');
135
+ assert.equal(typeof SYSTEMS.onError, 'function', 'onError');
136
+ });
137
+
138
+ test('systems comes online and walks to ready', async () => {
139
+ const prompts = [];
140
+ SYSTEMS.listen('devacore:prompt', packet => prompts.push(packet.text));
141
+ const data = await SYSTEMS.init(client());
142
+ for (const k of STAGES) assert.equal(typeof data[k], 'number', `${k} timestamp`);
143
+ assert.ok(data.start <= data.enter && data.enter <= data.done && data.done <= data.ready, 'stages in order');
144
+ assert.equal(data.value, 'init');
145
+ assert.equal(typeof data.id.uid, 'string', 'uid');
146
+ assertTiers(data, 'init packet');
147
+ assertTiers(data.id, 'init packet id');
148
+ assert.ok(prompts.includes(`${SYSTEMS.vars.messages.ready} > VLA:${pkg.VLA.uid}`), 'onReady prompts the ready message');
149
+ assert.ok(SYSTEMS._active, 'the Deva is active');
150
+ });
151
+
152
+ test('systems info matches the package', () => {
153
+ const info = SYSTEMS.info();
154
+ assert.equal(info.name, '@indra.ai/deva.systems');
155
+ assert.equal(info.version, pkg.version);
156
+ assert.equal(info.id, pkg.id);
157
+ assert.equal(info.describe, pkg.description);
158
+ assert.equal(info.url, pkg.homepage);
159
+ assert.equal(info.git, pkg.repository.url);
160
+ assert.equal(info.bugs, pkg.bugs.url);
161
+ assert.equal(info.VLA.uid, pkg.VLA.uid);
162
+ assertTiers(info, 'info()');
163
+ });
164
+
165
+ test('systems agent matches the package', () => {
166
+ const agent = SYSTEMS.agent();
167
+ const profile = pkg.data.agent.profile;
168
+ assert.equal(agent.key, 'systems');
169
+ assert.equal(agent.id, pkg.id);
170
+ assert.equal(agent.profile.id, pkg.id);
171
+ assert.equal(agent.profile.name, 'Systems Deva');
172
+ assert.equal(agent.profile.describe, profile.describe);
173
+ assert.equal(agent.profile.owner, 'Quinn Michaels');
174
+ assert.equal(agent.profile.creator, 'Quinn Michaels');
175
+ assert.equal(agent.profile.vector, '#SystemsDeva');
176
+ assert.equal(agent.profile.vectors, '#Quinn #QuinnMichaels #InsideTheNet #IndraAI #DEVA #DevaWorld #Systems #SystemsDeva #Merit #Demerit');
177
+ assert.equal(agent.profile.updated, profile.updated);
178
+ assertTiers(agent, 'agent()');
179
+ });
180
+
181
+ test('systems agent warning carries the corrected spellings', () => {
182
+ const {warning} = SYSTEMS.agent().profile;
183
+ assert.match(warning, /^🖥️ Systems Deva \(he\/him\) declares /, 'warning names Systems Deva');
184
+ for (const word of ['MERITORIOUS', 'COMMISSION', 'INDULGENCE']) assert.ok(warning.includes(word), `warning has ${word}`);
185
+ for (const word of ['MERITOUS', 'COMISSION', 'INDULGANCE']) assert.ok(!warning.includes(word), `warning has no ${word}`);
186
+ });
187
+
188
+ test('systems uid carries hash tiers and a fingerprint of its contents', () => {
189
+ const id = SYSTEMS.uid();
190
+ assert.equal(typeof id.uid, 'string', 'uid');
191
+ assert.ok(id.uid.length > 0, 'uid is not empty');
192
+ assert.equal(id.license, pkg.VLA.uid, 'license is the package VLA uid');
193
+ assertTiers(id, 'uid()');
194
+ assert.equal(id.fingerprint, digest({
195
+ license: id.license,
196
+ client: id.client,
197
+ agent: id.agent,
198
+ machine: id.machine,
199
+ core_hash: id.core_hash,
200
+ }, 'sha256'), 'fingerprint is the sha256 of license, client, agent, machine, and core_hash');
201
+ });
202
+
203
+ test('package VLA fingerprint is the sha256 of license, client, agent, machine, and core_hash', () => {
204
+ const {VLA} = pkg;
205
+ assert.equal(VLA.uid, pkg.id, 'VLA uid is the package id');
206
+ assert.equal(pkg.license, `VLA:${VLA.uid} LICENSE.md`, 'license field names the VLA uid');
207
+ assert.equal(VLA.fingerprint, digest({
208
+ license: VLA.license,
209
+ client: VLA.client,
210
+ agent: VLA.agent,
211
+ machine: VLA.machine,
212
+ core_hash: VLA.core_hash,
213
+ }, 'sha256'), 'package fingerprint matches its contents');
214
+ });
215
+
216
+ test('systems status returns the active-since string', () => {
217
+ const status = SYSTEMS.status();
218
+ assert.equal(typeof status, 'string', 'status is a string');
219
+ assert.match(status, /^Systems Deva active since /, 'status names the Deva and the start time');
220
+ });
221
+
222
+ test('systems utils answer with trimmed text', () => {
223
+ const {translate, parse, process} = SYSTEMS.utils;
224
+ for (const util of [translate, parse, process]) assert.equal(util(' hello '), 'hello');
225
+ });
226
+
227
+ test('systems vars include the ready message, trigger, and empty context', () => {
228
+ assert.equal(SYSTEMS.vars.messages.ready, '🖥️ Systems Deva Ready');
229
+ assert.equal(SYSTEMS.vars.trigger, '@SYSTEMS');
230
+ assert.deepEqual(SYSTEMS.vars.context, {}, 'context starts empty');
231
+ assert.deepEqual(SYSTEMS.vars.ask.history, [], 'ask history starts empty');
232
+ });
233
+
234
+ test('systems help pages match the files and carry the package license', async () => {
235
+ const main = await SYSTEMS.help('main', DIR);
236
+ assert.match(main, /^# \{\{profile\.name\}\}$/m, 'main help heading as in help/main.feecting');
237
+ assert.match(main, /^#bg = \{\{profile\.background\}\}$/m, 'main help uses profile.background');
238
+ const corpus = await SYSTEMS.help('corpus', DIR);
239
+ assert.match(corpus, /^# \{\{profile\.name\}\}$/m, 'corpus help heading');
240
+ const license = await SYSTEMS.help('main:license', DIR);
241
+ assert.match(license, new RegExp(`^\\s*uid: ${pkg.VLA.uid}$`, 'm'), 'license uid');
242
+ assert.match(license, new RegExp(`^\\s*fingerprint: ${pkg.VLA.fingerprint.replaceAll('+', '\\+')}$`, 'm'), 'license fingerprint');
243
+ for (const t of TIERS) assert.ok(license.includes(`${t}: ${pkg.VLA[t]}`), `${t} hash in the license help`);
244
+ });
245
+
246
+ test('feature/methods.js exports only the current methods', () => {
247
+ assert.deepEqual(Object.keys(featureMethods), FEATURE_KEYS, 'feature export names');
248
+ for (const key of FEATURE_KEYS) assert.equal(typeof featureMethods[key], 'function', `feature.${key}`);
249
+ });
250
+
251
+ test('systems stops through the full chain', async () => {
252
+ const data = await SYSTEMS.stop();
253
+ assert.equal(data.key, 'shutdown', 'the chain ends on shutdown');
254
+ assert.equal(data.value, 'systems');
255
+ assert.equal(SYSTEMS._active, false, 'the Deva is offline after stop');
256
+ });
257
+
258
+ // the feature loader binds client.features.systems.methods onto the Deva at init.
259
+ // this uses a fresh instance after SYSTEMS has stopped so only one systems Deva is active on the shared event bus.
260
+ test('feature methods from feature/methods.js load at runtime', async () => {
261
+ ({default: FEATURE} = await import('./index.js?feature'));
262
+ const data = await FEATURE.init(client(pkg.VLA, featureMethods));
263
+ assert.equal(typeof data.ready, 'number', 'feature instance reaches ready');
264
+ for (const key of FEATURE_KEYS) assert.equal(typeof FEATURE.methods[key], 'function', `the feature loader binds ${key}`);
265
+ });
266
+
267
+ test('methods.systems returns the parsed concerns and id end tags', async () => {
268
+ const orig = FEATURE.question.bind(FEATURE);
269
+ let asked = '';
270
+ FEATURE.question = async text => {
271
+ asked = String(text);
272
+ return parseAnswer('parsed-systems', '<p>systems</p>', {ok: true});
273
+ };
274
+ try {
275
+ const out = await FEATURE.methods.systems(packet(FEATURE));
276
+ assert.equal(out.text, 'parsed-systems');
277
+ assert.equal(out.html, '<p>systems</p>');
278
+ assert.deepEqual(out.data, ['first systems concern', 'second systems concern'], 'data is the systems concerns');
279
+ assert.ok(asked.includes(`${FEATURE.askChr}feecting parse `), 'asks Feecting to parse the systems view');
280
+ assert.ok(asked.includes('::BEGIN:SYSTEMS'), 'opens the systems block');
281
+ assert.ok(asked.includes('::END:SYSTEMS'), 'closes the systems block');
282
+ assert.ok(asked.includes(`::begin:client:${CLIENT_ID}`), 'client begin tag uses the client id');
283
+ assert.ok(asked.includes(`id: ${CLIENT_ID}`), 'client id line');
284
+ assert.ok(asked.includes('client: Test Client'), 'client name line');
285
+ assert.ok(asked.includes('1. first systems concern'), 'concerns are numbered from 1');
286
+ assert.ok(asked.includes('2. second systems concern'), 'every concern is listed');
287
+ assert.match(asked, new RegExp(`::end:client:${CLIENT_ID}(?:\\n|$)`), 'client end tag is the client id with no hash suffix');
288
+ assert.match(asked, /::end:global:smoke:g1(?:\n|$)/, 'global end tag is item.id with no hash suffix');
289
+ assert.ok(asked.includes('::begin:global:smoke:g1'), 'global begin tag uses key and item.id');
290
+ } finally {
291
+ FEATURE.question = orig;
292
+ }
293
+ });
294
+
295
+ test('methods.systems masks every restricted field and keeps the rest readable', async () => {
296
+ const orig = FEATURE.question.bind(FEATURE);
297
+ let asked = '';
298
+ FEATURE.question = async text => {
299
+ asked = String(text);
300
+ return parseAnswer();
301
+ };
302
+ try {
303
+ await FEATURE.methods.systems(packet(FEATURE));
304
+ assert.ok(asked.includes('token: *******'), 'nested token is masked');
305
+ assert.ok(asked.includes('uri: *******'), 'nested uri is masked');
306
+ assert.ok(asked.includes('Password: *******'), 'a mixed case restricted field name is masked');
307
+ assert.ok(asked.includes('secret: *******'), 'top-level secret is masked');
308
+ assert.ok(asked.includes('password: *******'), 'top-level password is masked');
309
+ assert.ok(asked.includes('text: ok'), 'nested field that is not restricted stays readable');
310
+ assert.ok(asked.includes('visible: public-ok'), 'top-level field that is not restricted stays readable');
311
+ for (const value of ['nested-token-value', 'nested-uri-value', 'nested-mixed-case-value', 'top-secret-value', 'top-password-value']) {
312
+ assert.ok(!asked.includes(value), `${value} does not leak`);
313
+ }
314
+ assert.ok(!asked.includes('::begin:global:restricted:'), 'restricted list is not printed as a block');
315
+ assert.ok(!asked.includes('restricted'), 'restricted list is not printed at all');
316
+ } finally {
317
+ FEATURE.question = orig;
318
+ }
319
+ });
320
+
321
+ // the timeout makes a broken this.err fail the test instead of leaving the promise pending forever.
322
+ test('methods.systems routes a question rejection through this.err', {timeout: 10000}, async () => {
323
+ const origQuestion = FEATURE.question.bind(FEATURE);
324
+ const origErr = FEATURE.err.bind(FEATURE);
325
+ const calls = [];
326
+ FEATURE.question = async () => {
327
+ throw new Error('feecting-parse-fail');
328
+ };
329
+ FEATURE.err = (err, pkt, reject) => {
330
+ calls.push({message: err.message, hasPacket: !!pkt, hasReject: typeof reject === 'function'});
331
+ return origErr(err, pkt, reject);
332
+ };
333
+ try {
334
+ await withMutedLog(async () => {
335
+ await assert.rejects(
336
+ FEATURE.methods.systems(packet(FEATURE)),
337
+ err => err.message === 'feecting-parse-fail',
338
+ 'systems rejects with the question error'
339
+ );
340
+ });
341
+ assert.equal(calls.length, 1, 'this.err is called once');
342
+ assert.equal(calls[0].message, 'feecting-parse-fail');
343
+ assert.equal(calls[0].hasPacket, true, 'this.err receives the packet');
344
+ assert.equal(calls[0].hasReject, true, 'this.err receives reject');
345
+ } finally {
346
+ FEATURE.question = origQuestion;
347
+ FEATURE.err = origErr;
348
+ }
349
+ });
350
+
351
+ // the refusal check loads a fresh Systems Deva instance from the same file, so it starts from a clean state.
352
+ // onInit runs the agent license check, so a bad agent VLA stops the Deva before it goes active.
353
+ test('systems refuses to start with a bad agent VLA', async () => {
354
+ if (FEATURE._active) await FEATURE.stop();
355
+ const {default: REFUSE} = await import('./index.js?refuse');
356
+ const prompts = [];
357
+ REFUSE.listen('devacore:prompt', packet => prompts.push(packet.text));
358
+ const result = await REFUSE.init(client({uid: 'bad'}));
359
+ assert.equal(result, REFUSE._messages.checkVLA, 'init answers with the invalid VLA message');
360
+ assert.ok(prompts.includes(REFUSE._messages.checkVLA), 'core prompts the invalid VLA message');
361
+ assert.equal(REFUSE._active, false, 'the Deva stays offline');
362
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "24296120490769123430",
3
3
  "name": "@indra.ai/deva.systems",
4
- "version": "0.15.3",
4
+ "version": "0.15.5",
5
5
  "license": "VLA:24296120490769123430 LICENSE.md",
6
6
  "VLA": {
7
7
  "uid": "24296120490769123430",