@indra.ai/deva 1.64.50 → 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 +1 -1
- package/package.json +1 -1
- package/tests/suite/08-error.test.js +46 -0
package/_data/tests.json
CHANGED
|
@@ -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":
|
|
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.
|
|
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",
|
|
@@ -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
|
+
});
|