Spaces:
Running
Running
Download fleet.test.js from cduss/MyRobotFleet: direct link, hf CLI and curl.
- Browser
- Download file 2.04 kB
-
https://huggingface.co/spaces/cduss/MyRobotFleet/resolve/main/fleet.test.js
- Command line
-
hf download hf://spaces/cduss/MyRobotFleet/fleet.test.js
-
curl -L -o fleet.test.js https://huggingface.co/spaces/cduss/MyRobotFleet/resolve/main/fleet.test.js
2.04 kB
| // node --test | |
| import test from "node:test"; | |
| import assert from "node:assert/strict"; | |
| import { kindOf, mergeWithHistory, normalizeFleet } from "./fleet.js"; | |
| test("kindOf mirrors central's classification", () => { | |
| assert.equal(kindOf({ name: "reachy", transport: "wifi" }), "reachy_mini"); | |
| assert.equal(kindOf({ kind: "Micro-Duck" }), "microduck"); | |
| assert.equal(kindOf({ kind: " ", robot_type: "grabette" }), "grabette"); | |
| assert.equal(kindOf({ kind: "toaster" }), "other"); | |
| assert.equal(kindOf(null), "reachy_mini"); | |
| }); | |
| test("normalizeFleet drops pseudo peers and keys on hardware id", () => { | |
| const now = 1_000_000; | |
| const robots = normalizeFleet( | |
| [ | |
| { peerId: "p1", meta: { name: "central-relay" } }, | |
| { peerId: "p2", meta: { name: "duck", kind: "microduck", hardware_id: "abc", release: "1.2" }, last_seen_age_seconds: 2 }, | |
| { peerId: "p3", robotName: "reachymini", meta: { name: "reachymini" }, busy: true, activeApp: "Demo" }, | |
| ], | |
| now, | |
| ); | |
| assert.equal(robots.length, 2); | |
| const duck = robots.find((r) => r.kind === "microduck"); | |
| assert.equal(duck.key, "microduck:abc"); | |
| assert.equal(duck.version, "1.2"); | |
| assert.equal(duck.lastSeenAt, now - 2000); | |
| assert.equal(robots.find((r) => r.kind === "reachy_mini").key, "reachy_mini:peer:p3"); | |
| }); | |
| test("mergeWithHistory keeps offline robots and expires old ones", () => { | |
| const now = 100 * 864e5; | |
| const live = normalizeFleet([{ peerId: "p", meta: { hardware_id: "a", name: "A" } }], now); | |
| const history = { | |
| "reachy_mini:b": { key: "reachy_mini:b", kind: "reachy_mini", name: "B", lastSeenAt: now - 864e5 }, | |
| "reachy_mini:c": { key: "reachy_mini:c", kind: "reachy_mini", name: "C", lastSeenAt: now - 60 * 864e5 }, | |
| }; | |
| const { robots, history: next } = mergeWithHistory(live, history, now); | |
| assert.deepEqual(robots.map((r) => [r.name, r.online]), [["A", true], ["B", false]]); | |
| assert.deepEqual(Object.keys(next).sort(), ["reachy_mini:a", "reachy_mini:b"]); | |
| assert.equal("meta" in next["reachy_mini:a"], false); | |
| }); | |