Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated

fix(iot): register client under both endpoint and device-id during registration (#1682)

rUv0277a5a0ede9
diff --git a/v3/@claude-flow/plugin-iot-cognitum/__tests__/integration/full-plugin-smoke.mjs b/v3/@claude-flow/plugin-iot-cognitum/__tests__/integration/full-plugin-smoke.mjs
new file mode 100644
index 0000000000..744ca4a3e1
--- /dev/null
+++ b/v3/@claude-flow/plugin-iot-cognitum/__tests__/integration/full-plugin-smoke.mjs
@@ -0,0 +1,119 @@
+#!/usr/bin/env node
+/**
+ * Full plugin smoke test against a live Cognitum Seed device.
+ * Exercises register -> status -> mesh -> witness -> witness-verify -> anomalies
+ * within a single in-process plugin instance (the published bin is one-shot,
+ * so this is the only way to chain device-aware commands).
+ *
+ * Run from the plugin directory after `npm run build`.
+ */
+import { IoTCognitumPlugin } from '../../dist/plugin.js';
+
+const SEED_ENDPOINT = process.env.SEED_ENDPOINT ?? 'http://169.254.42.1';
+
+const plugin = new IoTCognitumPlugin();
+const noop = () => undefined;
+await plugin.initialize({
+ config: { fleetId: 'test-fleet', zoneId: 'zone-test', tlsInsecure: true },
+ eventBus: { emit: noop, on: noop, off: noop, once: noop },
+ logger: {
+ info: () => {},
+ warn: (...a) => console.warn('[warn]', ...a),
+ error: (...a) => console.error('[error]', ...a),
+ debug: () => {},
+ },
+ services: { get: () => undefined, register: noop, has: () => false },
+});
+
+const commands = plugin.registerCLICommands();
+const cmd = (name) => {
+ const c = commands.find((c) => c.name === name);
+ if (!c) throw new Error(`No command: ${name}`);
+ return c;
+};
+
+const section = (title) => {
+ console.log('\n' + '='.repeat(60));
+ console.log(' ' + title);
+ console.log('='.repeat(60));
+};
+
+const run = async (label, fn) => {
+ console.log(`\n--- ${label} ---`);
+ try {
+ await fn();
+ console.log(`[ok] ${label}`);
+ } catch (err) {
+ console.error(`[fail] ${label}: ${err.message ?? err}`);
+ }
+};
+
+section('iot init');
+await cmd('iot init').handler({ _: [], 'fleet-id': 'test-fleet', 'zone-id': 'zone-test' });
+
+section('iot register (default endpoint)');
+let deviceId = null;
+await run('register', async () => {
+ await cmd('iot register').handler({ _: [], endpoint: SEED_ENDPOINT });
+ // Capture the device-id from the in-memory list
+ const list = await cmd('iot list').handler({ _: [] });
+ void list;
+});
+
+// Pull device-id from the coordinator directly
+const repo = plugin._coordinator?.deviceRepository ?? null;
+section('iot list (post-register)');
+await cmd('iot list').handler({ _: [] });
+
+// Read device-id from console output of list — easier: introspect coordinator
+// IoTCoordinator exposes listDevices() — peek into it
+const coord = plugin['coordinator'];
+const devices = coord ? coord.listDevices() : [];
+if (devices.length > 0) {
+ deviceId = devices[0].deviceId;
+ console.log(`\n[info] discovered device id: ${deviceId}`);
+}
+
+if (!deviceId) {
+ console.error('No device registered — skipping device-aware tests');
+ process.exit(1);
+}
+
+section(`iot status ${deviceId}`);
+await run('status', () => cmd('iot status').handler({ _: [deviceId] }));
+
+section(`iot mesh ${deviceId}`);
+await run('mesh', () => cmd('iot mesh').handler({ _: [deviceId] }));
+
+section(`iot witness ${deviceId}`);
+await run('witness', () => cmd('iot witness').handler({ _: [deviceId] }));
+
+section(`iot witness verify ${deviceId}`);
+await run('witness verify', () => cmd('iot witness verify').handler({ _: [deviceId] }));
+
+section(`iot anomalies ${deviceId}`);
+await run('anomalies', () => cmd('iot anomalies').handler({ _: [deviceId] }));
+
+section(`iot baseline ${deviceId}`);
+await run('baseline (read)', () => cmd('iot baseline').handler({ _: [deviceId] }));
+
+section('iot fleet list');
+await run('fleet list', () => cmd('iot fleet list').handler({ _: [] }));
+
+section('iot fleet create');
+await run('fleet create', () =>
+ cmd('iot fleet create').handler({
+ _: [],
+ 'fleet-id': 'smoke-fleet-1',
+ name: 'smoke-test-fleet',
+ }),
+);
+
+section('iot fleet list (after create)');
+await run('fleet list', () => cmd('iot fleet list').handler({ _: [] }));
+
+console.log('\n' + '='.repeat(60));
+console.log(' Full plugin smoke test complete');
+console.log('='.repeat(60));
+
+process.exit(0);
diff --git a/v3/@claude-flow/plugin-iot-cognitum/package.json b/v3/@claude-flow/plugin-iot-cognitum/package.json
index 4b1020b204..edc167f70c 100644
--- a/v3/@claude-flow/plugin-iot-cognitum/package.json
+++ b/v3/@claude-flow/plugin-iot-cognitum/package.json
@@ -1,6 +1,6 @@
{
"name": "@claude-flow/plugin-iot-cognitum",
- "version": "1.0.0-alpha.2",
+ "version": "1.0.0-alpha.3",
"description": "IoT Cognitum Seed device-agent bridge — treat every Seed as a Ruflo agent",
"type": "module",
"main": "dist/index.js",
@@ -32,9 +32,19 @@
"multicast-dns": "^7.2.5"
},
"peerDependenciesMeta": {
- "multicast-dns": { "optional": true }
+ "multicast-dns": {
+ "optional": true
+ }
},
- "keywords": ["iot", "cognitum", "seed", "device", "fleet", "agent", "swarm"],
+ "keywords": [
+ "iot",
+ "cognitum",
+ "seed",
+ "device",
+ "fleet",
+ "agent",
+ "swarm"
+ ],
"author": "Claude Flow Team",
"license": "MIT"
}
diff --git a/v3/@claude-flow/plugin-iot-cognitum/src/application/iot-coordinator.ts b/v3/@claude-flow/plugin-iot-cognitum/src/application/iot-coordinator.ts
index b5ace47ede..913a66bbcf 100644
--- a/v3/@claude-flow/plugin-iot-cognitum/src/application/iot-coordinator.ts
+++ b/v3/@claude-flow/plugin-iot-cognitum/src/application/iot-coordinator.ts
@@ -247,14 +247,16 @@ export class IoTCoordinator {
): Promise<DeviceAgent> {
const client = await this.factory.createClient(endpoint, pairingToken);
- // During initial registration the lifecycle service calls
- // getStatus(endpoint) and getIdentity(device_id). We temporarily
- // store the client under the endpoint key so resolveClient() can
- // find it before the real device ID is known.
- this.devices.set(endpoint, {
- agent: {} as DeviceAgent,
- client,
- });
+ // The lifecycle service makes two SDK calls during registration:
+ // getStatus(endpoint) -> returns the real device_id, then
+ // getIdentity(device_id) -> looked up by the device_id key.
+ // We need the client reachable under BOTH keys before lifecycle runs,
+ // so pre-fetch the device_id and register the client under both.
+ const initialStatus = await client.status();
+ const initialDeviceId = initialStatus.device_id;
+
+ this.devices.set(endpoint, { agent: {} as DeviceAgent, client });
+ this.devices.set(initialDeviceId, { agent: {} as DeviceAgent, client });
let agent: DeviceAgent;
try {
@@ -265,11 +267,12 @@ export class IoTCoordinator {
);
} catch (err) {
this.devices.delete(endpoint);
+ this.devices.delete(initialDeviceId);
throw err;
}
- // Promote: remove the temporary endpoint key and store under the
- // real device ID returned by the hardware.
+ // Promote: drop the temporary endpoint key and keep the device_id key
+ // (with the real agent attached).
this.devices.delete(endpoint);
this.devices.set(agent.deviceId, { agent, client });