@indra.ai/deva 1.64.49 → 1.64.51

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.
package/_data/tests.json CHANGED
@@ -31,7 +31,7 @@
31
31
  "file": "03-hash.test.js",
32
32
  "title": "Hash",
33
33
  "describe": "The md5, sha256 and sha512 tiers match node:crypto, every hashing site carries all three, the uid fingerprint holds, and one changed field breaks every tier.",
34
- "count": 6
34
+ "count": 10
35
35
  },
36
36
  {
37
37
  "file": "04-license.test.js",
@@ -61,7 +61,7 @@
61
61
  "file": "08-error.test.js",
62
62
  "title": "Error",
63
63
  "describe": "err() rejects or hands off to onError without calling context(), talks one stamped error packet, and context() and contexts() read each Deva's own vars.context, falling back safely when it is missing.",
64
- "count": 6
64
+ "count": 10
65
65
  }
66
66
  ],
67
67
  "edgecases": [
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "31711622713594414221",
3
3
  "name": "@indra.ai/deva",
4
- "version": "1.64.49",
4
+ "version": "1.64.51",
5
5
  "description": "Deva Core a Vedic-inspired Event Based Context Aware Feature, Zone, Action, and State Machine integrated Artificial Intelligence Framework",
6
6
  "main": "index.js",
7
7
  "license": "VLA:31711622713594414221 LICENSE.md",
@@ -70,4 +70,30 @@ test('changing one field breaks every tier', () => {
70
70
  const stamped = deva.client();
71
71
  const tampered = {...stamped, key: `${stamped.key}x`};
72
72
  assert.throws(() => verifyTiers(tampered, 'tampered'), /md5/);
73
+ });
74
+
75
+ test('_stamp() matches a manual cumulative hash of the same data', () => {
76
+ const data = {id: {uid: 'stamp-test'}, text: 'deva', n: 108};
77
+ const manual = {...data};
78
+ for (const t of TIERS) manual[t] = digest(manual, t);
79
+ const stamped = deva._stamp({...data}, 'stamp-test', 'stamp-test');
80
+ for (const t of TIERS) assert.equal(stamped[t], manual[t], t);
81
+ verifyTiers(stamped, '_stamp()');
82
+ });
83
+ test('_unstamp() then _stamp() gives back the same hashes', () => {
84
+ const stamped = deva._stamp({id: {uid: 'restamp'}, text: 'again'});
85
+ const first = {...stamped};
86
+ const again = deva._stamp(deva._unstamp({...stamped}));
87
+ for (const t of TIERS) assert.equal(again[t], first[t], t);
88
+ });
89
+ test('_stamp() without _unstamp() first hashes the old tiers in and changes them', () => {
90
+ const stamped = deva._stamp({id: {uid: 'double'}, text: 'twice'});
91
+ const first = {...stamped};
92
+ const twice = deva._stamp({...stamped});
93
+ for (const t of TIERS) assert.notEqual(twice[t], first[t], t);
94
+ });
95
+ test('_unstamp() removes every tier and leaves the data', () => {
96
+ const bare = deva._unstamp(deva._stamp({id: {uid: 'bare'}, text: 'clean'}));
97
+ for (const t of TIERS) assert.equal(t in bare, false, t);
98
+ assert.deepEqual(bare, {id: {uid: 'bare'}, text: 'clean'});
73
99
  });
@@ -96,3 +96,49 @@ test('contexts() returns this Deva\'s vars.context, or false when it has none',
96
96
  delete deva.vars.context;
97
97
  assert.equal(deva.contexts().value, false);
98
98
  });
99
+
100
+ // a child Deva whose method rejects, for the ask error test.
101
+ const failing = () => build({
102
+ agent: {...agent, id: 'helper', key: 'helper', profile: {...agent.profile, name: 'Helper'}},
103
+ vars: vars(),
104
+ methods: {fail: () => Promise.reject(new Error('helper failed'))},
105
+ });
106
+ test('a local /command that rejects rejects question() with one error packet', async () => {
107
+ const deva = build({vars: vars(), methods: {rej: () => Promise.reject(new Error('local rej'))}});
108
+ await deva.init(fresh());
109
+ const heard = [];
110
+ deva.events.on(deva._events.error, packet => heard.push(packet));
111
+ await assert.rejects(deva.question('/rej hi'), {message: 'local rej'});
112
+ assert.equal(heard.length, 1, 'one error packet');
113
+ assert.equal(heard[0].error.message, 'local rej');
114
+ assert.equal(heard[0].packet.q.meta.method, 'rej', 'the error carries the question packet');
115
+ assert.equal(deva._pending.size, 0);
116
+ await deva.stop();
117
+ });
118
+ test('a local /command that throws rejects question() the same way', async () => {
119
+ const deva = build({vars: vars(), methods: {thr: () => { throw new Error('local thr'); }}});
120
+ await deva.init(fresh());
121
+ const heard = [];
122
+ deva.events.on(deva._events.error, packet => heard.push(packet));
123
+ await assert.rejects(deva.question('/thr hi'), {message: 'local thr'});
124
+ assert.equal(heard.length, 1, 'one error packet');
125
+ assert.equal(heard[0].error.message, 'local thr');
126
+ await deva.stop();
127
+ });
128
+ test('a child ask error is logged by both the child and the asker', async () => {
129
+ const deva = build({vars: vars(), config: {hash: {}, timeout: {ask: 200}}, devas: {helper: failing()}});
130
+ await deva.init(fresh());
131
+ const heard = [];
132
+ deva.events.on(deva._events.error, packet => heard.push(packet));
133
+ await assert.rejects(deva.question('#helper fail hi'), {message: 'helper failed'});
134
+ assert.equal(heard.length, 2, 'two error packets');
135
+ assert.deepEqual(heard.map(p => p.value).sort(), [deva.agent().key, 'helper'].sort(), 'one from each Deva');
136
+ for (const p of heard) assert.equal(p.error.message, 'helper failed');
137
+ await deva.stop();
138
+ });
139
+ test('Feature() with an unknown feature rejects with invalid feature', async () => {
140
+ const deva = build({vars: vars()});
141
+ await deva.init(fresh());
142
+ await assert.rejects(new Promise((resolve, reject) => deva.Feature('nope', resolve, reject)), e => e === deva._messages.invalidfeature);
143
+ await deva.stop();
144
+ });