@indra.ai/deva 1.64.8 → 1.64.9
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/index.js +6 -2
- package/package.json +1 -1
- package/tests/suite/06-shutdown.test.js +23 -2
package/index.js
CHANGED
|
@@ -1280,12 +1280,16 @@ class Deva {
|
|
|
1280
1280
|
Recursion Framework.
|
|
1281
1281
|
***************/
|
|
1282
1282
|
stop() {
|
|
1283
|
-
if (!this._active) return this._messages.offline; // check for active status
|
|
1283
|
+
if (!this._active) return Promise.resolve(this._messages.offline); // check for active status
|
|
1284
1284
|
const key = 'stop'; // set the stop key
|
|
1285
1285
|
const id = this.uid(); // generate the stop uid
|
|
1286
1286
|
let data;
|
|
1287
|
-
return new Promise((resolve, reject) => {
|
|
1287
|
+
return new Promise(async (resolve, reject) => {
|
|
1288
1288
|
try {
|
|
1289
|
+
// stop the child Devas first so none are left running when the parent closes. ready() loads them last.
|
|
1290
|
+
this.state('loop', `${key}:devas:${id.uid}`);
|
|
1291
|
+
for (const deva in this.devas) await this.devas[deva].stop();
|
|
1292
|
+
|
|
1289
1293
|
this.state('set', `${key}:agent:${id.uid}`); // state stop agent
|
|
1290
1294
|
const agentData = this.agent();
|
|
1291
1295
|
const agent = agentData.sha256; // get the current agent
|
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.9",
|
|
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",
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import test from 'node:test';
|
|
8
8
|
import assert from 'node:assert/strict';
|
|
9
|
-
import {build, client} from './_deva.js';
|
|
9
|
+
import {build, client, agent} from './_deva.js';
|
|
10
10
|
|
|
11
11
|
const TIERS = ['md5', 'sha256', 'sha512'];
|
|
12
12
|
const CHAIN = ['stop', 'close', 'leave', 'exit', 'shutdown'];
|
|
@@ -14,7 +14,9 @@ const fresh = () => structuredClone(client);
|
|
|
14
14
|
|
|
15
15
|
test('stop() answers offline before init()', async () => {
|
|
16
16
|
const deva = build();
|
|
17
|
-
|
|
17
|
+
const stopped = deva.stop();
|
|
18
|
+
assert.ok(stopped instanceof Promise, 'offline stop still returns a Promise');
|
|
19
|
+
assert.equal(await stopped, deva._messages.offline);
|
|
18
20
|
});
|
|
19
21
|
|
|
20
22
|
test('stop() runs the full chain and resolves the stamped stop data', async () => {
|
|
@@ -99,4 +101,23 @@ test('a pending ask at shutdown answers offline and leaves nothing behind', asyn
|
|
|
99
101
|
assert.equal(deva._pending.size, 0);
|
|
100
102
|
bus.removeListener('silent:ask', silent);
|
|
101
103
|
assert.deepEqual(bus.eventNames(), []);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('stop() stops the child Devas first and leaves nothing on the bus', async () => {
|
|
107
|
+
const order = [];
|
|
108
|
+
const helper = build({
|
|
109
|
+
agent: {...agent, id: 'helper', key: 'helper', profile: {...agent.profile, name: 'Helper'}},
|
|
110
|
+
onShutdown(data, resolve) { order.push('helper:shutdown'); return resolve(data); },
|
|
111
|
+
});
|
|
112
|
+
const deva = build({devas: {helper}});
|
|
113
|
+
await deva.init(fresh());
|
|
114
|
+
assert.ok(helper._active, 'the child is running after init');
|
|
115
|
+
const bus = deva.events;
|
|
116
|
+
const heard = packet => order.push(`${packet.value}:stop`);
|
|
117
|
+
bus.on(deva._events.stop, heard);
|
|
118
|
+
await deva.stop();
|
|
119
|
+
bus.removeListener(deva._events.stop, heard);
|
|
120
|
+
assert.equal(helper._active, false, 'the child is offline');
|
|
121
|
+
assert.deepEqual(order, ['helper:stop', 'helper:shutdown', 'test:stop'], 'the child finishes before the parent starts');
|
|
122
|
+
assert.deepEqual(bus.eventNames(), [], 'nothing left on the bus');
|
|
102
123
|
});
|