@7365admin1/core 3.115.0 → 3.117.0
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/CHANGELOG.md +12 -0
- package/dist/index.d.ts +165 -59
- package/dist/index.js +2921 -2522
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2381 -1985
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/test/e2e/harness.mjs +2 -0
- package/test/e2e/robot-vendor-errors.e2e.test.mjs +172 -0
- package/test/padbot-real-data.test.mjs +165 -0
- package/test/robot-vendor-errors.test.mjs +289 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@7365admin1/core",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.117.0",
|
|
5
5
|
"author": "7365admin1",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.mjs",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"build": "tsup src/index.ts --format cjs,esm --dts && shx cp -r src/public dist && shx cp -r src/utils/handlebars dist",
|
|
14
14
|
"release": "yarn run build && changeset publish",
|
|
15
15
|
"lint": "tsc",
|
|
16
|
-
"test": "tsup src/config.ts src/utils/building-map.util.ts src/utils/robot-cloud.util.ts src/utils/robot-adapter.util.ts src/utils/png-encoder.util.ts src/services/demo.adapter.ts src/services/ounitech.adapter.ts src/services/padbot.adapter.ts src/utils/padbot-sign.util.ts src/services/open-rmf.adapter.ts src/utils/robot-credentials.util.ts src/utils/rmf-building.util.ts src/utils/door-contract.util.ts src/utils/robot-fault.util.ts src/utils/robot-tracking.util.ts src/utils/robot-apps.util.ts src/utils/robot-permission.util.ts src/utils/robot-network.util.ts src/utils/lift-contract.util.ts src/models/robot-building-map.model.ts src/utils/anpr-revoke.util.ts src/utils/anpr-plate.util.ts src/utils/vehicle-request.util.ts src/utils/camera-view.util.ts src/utils/camera-bulk-import.util.ts src/utils/dashboard-metrics.util.ts src/utils/camera-capability.util.ts src/utils/camera-playback.util.ts src/services/camera-device-http.service.ts src/utils/camera-alert.util.ts src/utils/dahua-protocol.util.ts src/utils/site-name.util.ts src/utils/site-owner-edit.util.ts src/utils/service-provider-invite.util.ts src/utils/notification-category.util.ts src/utils/notification-kind.util.ts src/utils/notification-email.util.ts src/models/notification.model.ts src/utils/hid-card.util.ts src/utils/hid-json.util.ts src/utils/hid-access.util.ts src/models/customer-site.model.ts src/models/site-camera.model.ts src/models/member.model.ts src/models/subscription.model.ts src/utils/session-id.util.ts src/utils/occurrence-query.util.ts src/utils/occurrence-book-create.util.ts src/utils/update-result.util.ts src/utils/hid-amico-authz.util.ts src/utils/promo-code-currency.util.ts src/utils/console-audit.util.ts src/utils/org-suspension.util.ts src/utils/session-revoke.util.ts src/models/hid-amico.model.ts src/models/patrol-email.model.ts src/utils/patrol-email-pdf.util.ts src/utils/visitor-status.util.ts src/utils/self-service-email.util.ts src/utils/hid-secret.util.ts src/models/visitor-invite.model.ts src/models/guard-invite.model.ts src/utils/site-timezone.util.ts src/utils/bulletin-service-apps.util.ts src/models/bulletin-board.model.ts src/utils/vehicle-import.util.ts src/utils/expired-vehicle-sweep.util.ts src/models/vehicle.model.ts src/controllers/chat.controller.ts src/utils/file-owner.util.ts src/utils/console-permission.util.ts src/utils/role-scope.util.ts src/utils/org-default-roles.util.ts src/utils/org-modules.util.ts src/utils/site-modules.util.ts src/utils/resident-app-modules.util.ts src/utils/resident-default-role.util.ts src/utils/invite-role-scope.util.ts src/models/personal-emergency-chain.model.ts src/utils/self-signup-files.util.ts src/models/person.model.ts src/utils/module-gate.util.ts src/utils/member-lookup.util.ts src/utils/notification-access.util.ts src/utils/module-access.util.ts src/services/module-gate.service.ts src/controllers/site.controller.ts src/controllers/organization.controller.ts src/controllers/member.controller.ts src/utils/org-owner-repair.util.ts src/utils/socket-session.util.ts src/utils/people-create-gate.util.ts src/utils/service-app-type.util.ts src/utils/customer-site-list.util.ts src/utils/org-search.util.ts src/utils/invite-origin.util.ts src/utils/member-role-assign.util.ts src/utils/cross-site-role.util.ts --format esm --out-dir test/.build --no-dts --silent && node --test test/*.test.mjs",
|
|
16
|
+
"test": "tsup src/config.ts src/utils/building-map.util.ts src/utils/robot-cloud.util.ts src/utils/robot-adapter.util.ts src/utils/png-encoder.util.ts src/services/demo.adapter.ts src/services/ounitech.adapter.ts src/services/robot-cloud.service.ts src/services/robot-fleet.service.ts src/services/padbot.adapter.ts src/utils/padbot-sign.util.ts src/services/open-rmf.adapter.ts src/utils/robot-credentials.util.ts src/utils/rmf-building.util.ts src/utils/door-contract.util.ts src/utils/robot-fault.util.ts src/utils/robot-tracking.util.ts src/utils/robot-apps.util.ts src/utils/robot-permission.util.ts src/utils/robot-network.util.ts src/utils/lift-contract.util.ts src/models/robot-building-map.model.ts src/utils/anpr-revoke.util.ts src/utils/anpr-plate.util.ts src/utils/vehicle-request.util.ts src/utils/camera-view.util.ts src/utils/camera-bulk-import.util.ts src/utils/dashboard-metrics.util.ts src/utils/camera-capability.util.ts src/utils/camera-playback.util.ts src/services/camera-device-http.service.ts src/utils/camera-alert.util.ts src/utils/dahua-protocol.util.ts src/utils/site-name.util.ts src/utils/site-owner-edit.util.ts src/utils/service-provider-invite.util.ts src/utils/notification-category.util.ts src/utils/notification-kind.util.ts src/utils/notification-email.util.ts src/models/notification.model.ts src/utils/hid-card.util.ts src/utils/hid-json.util.ts src/utils/hid-access.util.ts src/models/customer-site.model.ts src/models/site-camera.model.ts src/models/member.model.ts src/models/subscription.model.ts src/utils/session-id.util.ts src/utils/occurrence-query.util.ts src/utils/occurrence-book-create.util.ts src/utils/update-result.util.ts src/utils/hid-amico-authz.util.ts src/utils/promo-code-currency.util.ts src/utils/console-audit.util.ts src/utils/org-suspension.util.ts src/utils/session-revoke.util.ts src/models/hid-amico.model.ts src/models/patrol-email.model.ts src/utils/patrol-email-pdf.util.ts src/utils/visitor-status.util.ts src/utils/self-service-email.util.ts src/utils/hid-secret.util.ts src/models/visitor-invite.model.ts src/models/guard-invite.model.ts src/utils/site-timezone.util.ts src/utils/bulletin-service-apps.util.ts src/models/bulletin-board.model.ts src/utils/vehicle-import.util.ts src/utils/expired-vehicle-sweep.util.ts src/models/vehicle.model.ts src/controllers/chat.controller.ts src/utils/file-owner.util.ts src/utils/console-permission.util.ts src/utils/role-scope.util.ts src/utils/org-default-roles.util.ts src/utils/org-modules.util.ts src/utils/site-modules.util.ts src/utils/resident-app-modules.util.ts src/utils/resident-default-role.util.ts src/utils/invite-role-scope.util.ts src/models/personal-emergency-chain.model.ts src/utils/self-signup-files.util.ts src/models/person.model.ts src/utils/module-gate.util.ts src/utils/member-lookup.util.ts src/utils/notification-access.util.ts src/utils/module-access.util.ts src/services/module-gate.service.ts src/controllers/site.controller.ts src/controllers/organization.controller.ts src/controllers/member.controller.ts src/utils/org-owner-repair.util.ts src/utils/socket-session.util.ts src/utils/people-create-gate.util.ts src/utils/service-app-type.util.ts src/utils/customer-site-list.util.ts src/utils/org-search.util.ts src/utils/invite-origin.util.ts src/utils/member-role-assign.util.ts src/utils/cross-site-role.util.ts --format esm --out-dir test/.build --no-dts --silent && node --test test/*.test.mjs",
|
|
17
17
|
"test:camera": "yarn test",
|
|
18
18
|
"test:e2e": "yarn build && node --test --test-concurrency=1 --test-timeout=600000 \"test/e2e/*.test.mjs\""
|
|
19
19
|
},
|
package/test/e2e/harness.mjs
CHANGED
|
@@ -952,6 +952,8 @@ function buildApp(nsu, core) {
|
|
|
952
952
|
// Reaches a vendor cloud: only exercised against a local mock (OUNITECH_API_BASE).
|
|
953
953
|
robots.post("/discover", requireAuth, f.discoverRobots);
|
|
954
954
|
robots.get("/:id([0-9a-fA-F]{24})/state", requireAuth, f.getState);
|
|
955
|
+
robots.get("/:id([0-9a-fA-F]{24})/maps", requireAuth, f.getMaps);
|
|
956
|
+
robots.get("/:id([0-9a-fA-F]{24})/diagnose", requireAuth, f.diagnoseRobot);
|
|
955
957
|
robots.post("/:id([0-9a-fA-F]{24})/command", requireAuth, f.sendCommand);
|
|
956
958
|
robots.get("/:id([0-9a-fA-F]{24})/patrol-routes", requireAuth, f.getPatrolRoutes);
|
|
957
959
|
robots.post("/:id([0-9a-fA-F]{24})/live-video", requireAuth, f.getLiveVideo);
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
// HERO-OTH (production, 2026-09-26): /api/robots/:id/state and /maps answered
|
|
2
|
+
// 500 {"status":"error","message":"Internal Server Error"}. Every Ounitech
|
|
3
|
+
// failure was a plain Error, which the shared error handler turns into a bare
|
|
4
|
+
// 500. This proves, through the real routes, that each vendor failure is now a
|
|
5
|
+
// handled answer with a plain reason, and that GET /:id/diagnose (Seven365
|
|
6
|
+
// staff only, read-only) names the failing step and what the vendor said -
|
|
7
|
+
// without ever returning a credential.
|
|
8
|
+
//
|
|
9
|
+
// The "Ounitech cloud" is a loopback mock with fake credentials. Nothing leaves
|
|
10
|
+
// the machine. Run with: yarn test:e2e
|
|
11
|
+
|
|
12
|
+
import { after, before, describe, it } from "node:test";
|
|
13
|
+
import assert from "node:assert/strict";
|
|
14
|
+
import crypto from "node:crypto";
|
|
15
|
+
import http from "node:http";
|
|
16
|
+
import { once } from "node:events";
|
|
17
|
+
import { ObjectId } from "mongodb";
|
|
18
|
+
|
|
19
|
+
import { startHarness } from "./harness.mjs";
|
|
20
|
+
|
|
21
|
+
const PASSWORD = "Robot-Passw0rd!";
|
|
22
|
+
const MANAGER = "ove-manager@e2e.example.com";
|
|
23
|
+
const STAFF = "ove-staff@e2e.example.com";
|
|
24
|
+
const APPID = "fake-oth-appid";
|
|
25
|
+
const SECRET = "fake-oth-secret";
|
|
26
|
+
|
|
27
|
+
/** The mock answers however `mode` says. */
|
|
28
|
+
let mode = "badsign";
|
|
29
|
+
async function startMock() {
|
|
30
|
+
const server = http.createServer((req, res) => {
|
|
31
|
+
req.resume();
|
|
32
|
+
req.on("end", () => {
|
|
33
|
+
const send = (status, body, type = "application/json") => {
|
|
34
|
+
res.writeHead(status, { "content-type": type });
|
|
35
|
+
res.end(typeof body === "string" ? body : JSON.stringify(body));
|
|
36
|
+
};
|
|
37
|
+
const list = req.url === "/portal/robots/get-robot-list";
|
|
38
|
+
if (mode === "badsign") return send(200, { ok: false, msg: "sign error" });
|
|
39
|
+
if (mode === "html") return send(502, "<html>Bad gateway</html>", "text/html");
|
|
40
|
+
if (mode === "slow") return setTimeout(() => send(200, { robotList: [] }), 3000);
|
|
41
|
+
if (mode === "notbound") return send(200, list ? { robotList: [{ robotSn: "OTHER-SN", onlineFlag: true }] } : { ok: false, msg: "robot not bound" });
|
|
42
|
+
return send(200, list ? { robotList: [{ robotSn: "OTH-SN", robotName: "HERO", statusFlag: 1, onlineFlag: true }] } : { ok: true, mapList: [] });
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
server.listen(0, "127.0.0.1");
|
|
46
|
+
await once(server, "listening");
|
|
47
|
+
return { server, url: `http://127.0.0.1:${server.address().port}` };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
describe("robot vendor failures are handled answers; diagnose names the step", { concurrency: 1 }, () => {
|
|
51
|
+
let h;
|
|
52
|
+
let mock;
|
|
53
|
+
let managerSid;
|
|
54
|
+
let staffSid;
|
|
55
|
+
const id = {};
|
|
56
|
+
|
|
57
|
+
before(async () => {
|
|
58
|
+
mock = await startMock();
|
|
59
|
+
process.env.OUNITECH_API_BASE = mock.url;
|
|
60
|
+
process.env.ROBOT_CLOUD_TIMEOUT_MS = "1500";
|
|
61
|
+
process.env.ROBOT_CREDENTIALS_KEY = crypto.randomBytes(32).toString("hex");
|
|
62
|
+
h = await startHarness();
|
|
63
|
+
Object.assign(id, await seed(h));
|
|
64
|
+
managerSid = await h.login(MANAGER, PASSWORD);
|
|
65
|
+
staffSid = await h.login(STAFF, PASSWORD);
|
|
66
|
+
const add = await h.api("/robots", {
|
|
67
|
+
method: "POST",
|
|
68
|
+
sid: managerSid,
|
|
69
|
+
body: { name: "HERO-OTH", brand: "ounitech", type: "cleaning", robotSn: "OTH-SN", appKey: APPID, appToken: SECRET, metadata: { orgId: String(id.org), siteId: String(id.site) } },
|
|
70
|
+
});
|
|
71
|
+
assert.equal(add.status, 201, JSON.stringify(add.body));
|
|
72
|
+
id.robot = (await h.db.collection("robots").findOne({ name: "HERO-OTH" }))._id;
|
|
73
|
+
}, { timeout: 300000 });
|
|
74
|
+
|
|
75
|
+
after(async () => {
|
|
76
|
+
delete process.env.OUNITECH_API_BASE;
|
|
77
|
+
delete process.env.ROBOT_CLOUD_TIMEOUT_MS;
|
|
78
|
+
delete process.env.ROBOT_CREDENTIALS_KEY;
|
|
79
|
+
if (h) await h.stop();
|
|
80
|
+
mock?.server.close();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const CASES = [
|
|
84
|
+
["badsign", 502, /Ounitech rejected the robot list \(sign-in\) \(sign error\)/, /Ounitech rejected the floor maps \(sign error\)/],
|
|
85
|
+
["html", 502, /Ounitech answered HTTP 502 for the robot list \(sign-in\) with a web page/, /HTTP 502 for the floor maps/],
|
|
86
|
+
["slow", 504, /didn't answer the robot list \(sign-in\) in time/, /didn't answer the floor maps in time/],
|
|
87
|
+
];
|
|
88
|
+
|
|
89
|
+
for (const [m, status, stateText, mapsText] of CASES) {
|
|
90
|
+
it(`vendor "${m}": /state and /maps answer ${status} with the reason, never a bare 500`, async () => {
|
|
91
|
+
mode = m;
|
|
92
|
+
const state = await h.api(`/robots/${id.robot}/state`, { sid: managerSid });
|
|
93
|
+
assert.equal(state.status, status, JSON.stringify(state.body));
|
|
94
|
+
assert.match(state.body.message, stateText);
|
|
95
|
+
const maps = await h.api(`/robots/${id.robot}/maps`, { sid: managerSid });
|
|
96
|
+
assert.equal(maps.status, status, JSON.stringify(maps.body));
|
|
97
|
+
assert.match(maps.body.message, mapsText);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
it("the 4 s live poll (/robots/states) carries the plain reason for the detail screen", async () => {
|
|
102
|
+
mode = "badsign";
|
|
103
|
+
await new Promise((r) => setTimeout(r, 3200)); // past the 3 s memo of the last read
|
|
104
|
+
const res = await h.api(`/robots/states?ids=${id.robot}`, { sid: managerSid });
|
|
105
|
+
assert.equal(res.status, 200, JSON.stringify(res.body));
|
|
106
|
+
const item = res.body.items.find((i) => i.id === String(id.robot));
|
|
107
|
+
assert.equal(item.ok, false);
|
|
108
|
+
assert.match(item.reason, /Ounitech rejected the robot list \(sign-in\) \(sign error\)/);
|
|
109
|
+
assert.equal(JSON.stringify(res.body).includes(SECRET), false);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("a serial the account does not list: state is a 200 saying so", async () => {
|
|
113
|
+
mode = "notbound";
|
|
114
|
+
const state = await h.api(`/robots/${id.robot}/state`, { sid: managerSid });
|
|
115
|
+
assert.equal(state.status, 200, JSON.stringify(state.body));
|
|
116
|
+
assert.match(state.body.statusName, /Serial OTH-SN is not on this Ounitech account - use Find robots/);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("diagnose is Seven365 staff only", async () => {
|
|
120
|
+
const res = await h.api(`/robots/${id.robot}/diagnose`, { sid: managerSid });
|
|
121
|
+
assert.equal(res.status, 401, JSON.stringify(res.body));
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("diagnose names the failing step and the vendor's words, with no credential", async () => {
|
|
125
|
+
mode = "badsign";
|
|
126
|
+
const bad = await h.api(`/robots/${id.robot}/diagnose`, { sid: staffSid });
|
|
127
|
+
assert.equal(bad.status, 200, JSON.stringify(bad.body));
|
|
128
|
+
assert.equal(bad.body.failedStep, "sign-in (robot list)");
|
|
129
|
+
assert.deepEqual(bad.body.credentials, { appIdSaved: true, secretSaved: true, encrypted: true, serverKeyPresent: true, readable: true });
|
|
130
|
+
assert.equal(bad.body.robot.robotSnSaved, true);
|
|
131
|
+
const step = bad.body.steps.find((s) => !s.ok);
|
|
132
|
+
assert.equal(step.vendorMessage, "sign error");
|
|
133
|
+
const row = await h.db.collection("robots").findOne({ _id: id.robot });
|
|
134
|
+
const text = JSON.stringify(bad.body);
|
|
135
|
+
for (const s of [APPID, SECRET, row.appKey, row.appToken]) assert.equal(text.includes(s), false, s);
|
|
136
|
+
|
|
137
|
+
mode = "notbound";
|
|
138
|
+
const nb = await h.api(`/robots/${id.robot}/diagnose`, { sid: staffSid });
|
|
139
|
+
assert.equal(nb.body.failedStep, "get robot");
|
|
140
|
+
assert.match(nb.body.summary, /Serial OTH-SN is not on this account/);
|
|
141
|
+
|
|
142
|
+
mode = "ok";
|
|
143
|
+
const ok = await h.api(`/robots/${id.robot}/diagnose`, { sid: staffSid });
|
|
144
|
+
assert.equal(ok.body.failedStep, null, JSON.stringify(ok.body));
|
|
145
|
+
assert.equal(ok.body.steps.length, 4);
|
|
146
|
+
assert.ok(ok.body.clock?.vendorDate, "the vendor's clock is reported");
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
async function seed(h) {
|
|
151
|
+
const now = new Date().toISOString();
|
|
152
|
+
const org = new ObjectId();
|
|
153
|
+
const site = new ObjectId();
|
|
154
|
+
const role = new ObjectId();
|
|
155
|
+
const staffRole = new ObjectId();
|
|
156
|
+
await h.db.collection("organizations").insertOne({ _id: org, name: "OVE Org", email: "ove@e2e.example.com", type: "org", nature: "property_management_agency", status: "active", createdAt: now });
|
|
157
|
+
await h.db.collection("sites").insertOne({ _id: site, name: "OVE Site", org, orgId: org, status: "active" });
|
|
158
|
+
await h.db.collection("roles").insertMany([
|
|
159
|
+
{ _id: role, name: "Manager", org, permissions: ["*"], status: "active" },
|
|
160
|
+
{ _id: staffRole, name: "Super Admin", type: "admin", default: true, permissions: [], status: "active" },
|
|
161
|
+
]);
|
|
162
|
+
const emails = [MANAGER, STAFF];
|
|
163
|
+
const users = await h.db.collection("users").insertMany(emails.map((email) => ({ email, name: email.split("@")[0], status: "active", createdAt: now })));
|
|
164
|
+
const hashed = await h.hashPassword(PASSWORD);
|
|
165
|
+
await h.db.collection("users").updateMany({ email: { $in: emails } }, { $set: { password: hashed } });
|
|
166
|
+
const [manager, staff] = [0, 1].map((i) => users.insertedIds[i]);
|
|
167
|
+
await h.db.collection("members").insertMany([
|
|
168
|
+
{ user: manager, org, type: "organization", role, status: "active" },
|
|
169
|
+
{ user: staff, type: "admin", role: staffRole, status: "active" },
|
|
170
|
+
]);
|
|
171
|
+
return { org, site };
|
|
172
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// PadBot S2 in production (2026-09-26): what the first real robot showed and
|
|
2
|
+
// how the adapter now reads it - routes whose stops cannot be placed on the
|
|
3
|
+
// plan are still listed, schedules are said to live in PadBot's app, a
|
|
4
|
+
// positive Wi-Fi number is a level (not dBm), a missing position is said in
|
|
5
|
+
// words, and staff Diagnose returns PadBot's raw answers without credentials.
|
|
6
|
+
|
|
7
|
+
import assert from "node:assert/strict";
|
|
8
|
+
import { test } from "node:test";
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
PADBOT_PATHS,
|
|
12
|
+
asList,
|
|
13
|
+
clearPadbotCache,
|
|
14
|
+
createPadbotAdapter,
|
|
15
|
+
networkText,
|
|
16
|
+
padbotPatrolPlan,
|
|
17
|
+
} from "./.build/services/padbot.adapter.mjs";
|
|
18
|
+
import { normalisePatrolPlan } from "./.build/utils/robot-adapter.util.mjs";
|
|
19
|
+
|
|
20
|
+
const CREDS = { appid: "ak-real-id", secret: "sk-real-secret-never-shown" };
|
|
21
|
+
const NOW = Date.parse("2026-09-26T08:00:00.000Z");
|
|
22
|
+
const fresh = new Date(NOW - 5000).toISOString();
|
|
23
|
+
|
|
24
|
+
function fake(routes) {
|
|
25
|
+
const calls = [];
|
|
26
|
+
const fetch = async (url, init) => {
|
|
27
|
+
const path = new URL(url).pathname;
|
|
28
|
+
calls.push({ path, body: JSON.parse(init.body), headers: init.headers });
|
|
29
|
+
const hit = routes[path];
|
|
30
|
+
if (!hit) return { status: 404, text: async () => "" };
|
|
31
|
+
const out = hit(JSON.parse(init.body));
|
|
32
|
+
return { status: 200, text: async () => JSON.stringify(out?.__raw ?? { code: 0, message: "success", data: out ?? null }) };
|
|
33
|
+
};
|
|
34
|
+
return { fetch, calls };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
test("network: negative = dBm; zero or positive = a signal level (the real S2 reports 4)", () => {
|
|
38
|
+
assert.equal(networkText({ wifi: { signalStrength: -61 } }), " · Wi-Fi -61 dBm");
|
|
39
|
+
assert.equal(networkText({ wifi: { signalStrength: 4 } }), " · Wi-Fi signal 4");
|
|
40
|
+
assert.equal(networkText({ cellular: { signalStrength: 3 } }), " · Mobile signal 3");
|
|
41
|
+
assert.equal(networkText({}), "");
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("routes: stops that cannot be placed are listed by name, the route is kept (not dropped)", () => {
|
|
45
|
+
// Map without resolution: no plan frame, so no stop can be placed.
|
|
46
|
+
const maps = [{ mapId: "m1", floor: 3, targetPoints: [{ targetPointId: "t1", name: "Gate" }, { targetPointId: "t2", name: "Lobby" }] }];
|
|
47
|
+
const paths = [{ pathId: "p1", pathName: "Night round", mapId: "m1", isDefault: true, points: [
|
|
48
|
+
{ targetPointId: "t2", targetPointName: "Lobby", pointIndex: 1 },
|
|
49
|
+
{ targetPointId: "t1", targetPointName: "Gate", pointIndex: 0 },
|
|
50
|
+
] }];
|
|
51
|
+
const plan = normalisePatrolPlan(padbotPatrolPlan(paths, maps, {}));
|
|
52
|
+
assert.equal(plan.routes.length, 1);
|
|
53
|
+
assert.equal(plan.routes[0].name, "Night round (default)");
|
|
54
|
+
assert.deepEqual(plan.routes[0].stops, ["Gate", "Lobby"]);
|
|
55
|
+
assert.deepEqual(plan.routes[0].checkpoints, [], "nothing drawn at a guessed spot");
|
|
56
|
+
assert.equal(plan.routes[0].floorNo, 3);
|
|
57
|
+
assert.equal(plan.scheduleShared, false, "schedules live in PadBot's app");
|
|
58
|
+
assert.deepEqual(plan.schedule, []);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("routes: pointNames when points are absent; a stop found on the robot's OTHER map is placed", () => {
|
|
62
|
+
const frame = { width: 200, height: 100, resolution: 0.05, originX: 0, originY: 0 };
|
|
63
|
+
const maps = [
|
|
64
|
+
{ mapId: "m1", floor: 3, ...frame, targetPoints: [] },
|
|
65
|
+
{ mapId: "m2", floor: 4, ...frame, targetPoints: [{ targetPointId: "a", name: "A", worldX: 1, worldY: 1 }, { targetPointId: "b", name: "B", worldX: 5, worldY: 2.5 }] },
|
|
66
|
+
];
|
|
67
|
+
const byNames = normalisePatrolPlan(padbotPatrolPlan([{ pathId: "p9", pathName: "Loop", mapId: "m1", pointNames: ["A", "B"] }], maps, {}));
|
|
68
|
+
assert.deepEqual(byNames.routes[0].stops, ["A", "B"]);
|
|
69
|
+
assert.equal(byNames.routes[0].checkpoints.length, 2, "found by name on m2 and placed");
|
|
70
|
+
const perPoint = normalisePatrolPlan(padbotPatrolPlan([{ pathId: "p8", pathName: "Cross", mapId: "m1", points: [
|
|
71
|
+
{ targetPointId: "a", targetPointName: "A", mapId: "m2", pointIndex: 0 },
|
|
72
|
+
{ targetPointId: "b", targetPointName: "B", mapId: "m2", pointIndex: 1 },
|
|
73
|
+
] }], maps, {}));
|
|
74
|
+
assert.deepEqual(perPoint.routes[0].checkpoints.map((c) => c.name), ["A", "B"]);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("routes: a route with neither placed checkpoints nor stop names is still dropped; demo shape unchanged", () => {
|
|
78
|
+
assert.equal(normalisePatrolPlan({ routes: [{ id: "x", name: "Empty", checkpoints: [] }] }).routes.length, 0);
|
|
79
|
+
const demo = normalisePatrolPlan({ routes: [{ id: "d", name: "Demo", checkpoints: [{ name: "a", x: 1, y: 1 }, { name: "b", x: 2, y: 2 }] }], schedule: [] });
|
|
80
|
+
assert.equal(demo.routes[0].checkpoints.length, 2);
|
|
81
|
+
assert.equal("stops" in demo.routes[0], false);
|
|
82
|
+
assert.equal("scheduleShared" in demo, false);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test("list answers: bare array or an {items}/{list}/{records} page", () => {
|
|
86
|
+
assert.deepEqual(asList([1]), [1]);
|
|
87
|
+
assert.deepEqual(asList({ items: [2] }), [2]);
|
|
88
|
+
assert.deepEqual(asList({ list: [3] }), [3]);
|
|
89
|
+
assert.deepEqual(asList({ records: [4] }), [4]);
|
|
90
|
+
assert.deepEqual(asList(null), []);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const STATES = [{ serialNumber: "PS8517", states: [
|
|
94
|
+
{ stateType: "1000", data: { updatedAt: fresh } },
|
|
95
|
+
{ stateType: "1001", data: { batteryPercent: 100, updatedAt: fresh } },
|
|
96
|
+
{ stateType: "1007", data: { mapId: "m1", floor: 3 } },
|
|
97
|
+
{ stateType: "1107", data: { wifi: { signalStrength: 4 } } },
|
|
98
|
+
] }];
|
|
99
|
+
|
|
100
|
+
test("getRobot: online with no position says so in words and is not placed", async () => {
|
|
101
|
+
clearPadbotCache();
|
|
102
|
+
const f = fake({
|
|
103
|
+
[PADBOT_PATHS.states]: () => STATES,
|
|
104
|
+
[PADBOT_PATHS.robots]: () => [{ serialNumber: "PS8517", robotModel: "S2" }],
|
|
105
|
+
[PADBOT_PATHS.location]: () => ({ __raw: { code: 1008, message: "Failed to retrieve data", data: null } }),
|
|
106
|
+
[PADBOT_PATHS.alarms]: () => ({ items: [] }),
|
|
107
|
+
});
|
|
108
|
+
const r = await createPadbotAdapter(CREDS, { baseUrl: "https://pb.test", fetch: f.fetch, now: () => NOW }).getRobot("PS8517");
|
|
109
|
+
assert.equal(r.online, true);
|
|
110
|
+
assert.equal(r.statusName, "Standing by · Wi-Fi signal 4 · Position not reported");
|
|
111
|
+
assert.equal(r.position, null);
|
|
112
|
+
assert.equal(r.planPosition, null);
|
|
113
|
+
assert.equal(r.model, "PadBot S2");
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test("getRobot: x/y in place of worldX/worldY is read; map from the current-map state when the answer omits it", async () => {
|
|
117
|
+
clearPadbotCache();
|
|
118
|
+
const f = fake({
|
|
119
|
+
[PADBOT_PATHS.states]: () => STATES,
|
|
120
|
+
[PADBOT_PATHS.robots]: () => [],
|
|
121
|
+
[PADBOT_PATHS.location]: () => ({ x: 5, y: 2.5, yaw: 0 }),
|
|
122
|
+
[PADBOT_PATHS.maps]: () => ({ items: [{ mapId: "m1", width: 200, height: 100, resolution: 0.05, originX: 0, originY: 0 }] }),
|
|
123
|
+
[PADBOT_PATHS.alarms]: () => ({ items: [] }),
|
|
124
|
+
});
|
|
125
|
+
const r = await createPadbotAdapter(CREDS, { baseUrl: "https://pb.test", fetch: f.fetch, now: () => NOW }).getRobot("PS8517");
|
|
126
|
+
assert.deepEqual(r.position, { x: 5, y: 2.5, theta: 0 });
|
|
127
|
+
assert.deepEqual(r.planPosition, { x: 50, y: 50 });
|
|
128
|
+
assert.equal(r.statusName, "Standing by · Wi-Fi signal 4");
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test("diagnose: PadBot's raw answers per read (code, message, data); maps summarised; no credential anywhere", async () => {
|
|
132
|
+
clearPadbotCache();
|
|
133
|
+
const f = fake({
|
|
134
|
+
[PADBOT_PATHS.states]: () => STATES,
|
|
135
|
+
[PADBOT_PATHS.location]: () => ({ __raw: { code: 1008, message: "Failed to retrieve data", data: null } }),
|
|
136
|
+
[PADBOT_PATHS.maps]: () => [{ mapId: "m1", mapName: "20260528172106098_5ecd8fa9", floor: 3, imageUrl: "https://img/x.png", targetPoints: [{ targetPointId: "t", name: "Gate", worldX: 1, worldY: 2, targetPointType: 6 }], restrictedAreas: [{}, {}] }],
|
|
137
|
+
[PADBOT_PATHS.patrolRoutes]: () => [{ pathId: "p1", pathName: "Night", mapId: "m1" }],
|
|
138
|
+
[PADBOT_PATHS.alarms]: () => ({ items: [], totalItems: 0 }),
|
|
139
|
+
[PADBOT_PATHS.records]: () => ({ items: [], totalItems: 0 }),
|
|
140
|
+
});
|
|
141
|
+
const steps = await createPadbotAdapter(CREDS, { baseUrl: "https://pb.test", fetch: f.fetch, now: () => NOW }).diagnose("PS8517");
|
|
142
|
+
assert.deepEqual(steps.map((s) => s.step), ["states (4.2)", "location (4.3)", "maps (5.1)", "patrol routes (6.1)", "alarms (6.4)", "patrol records (6.7)"]);
|
|
143
|
+
const loc = steps[1];
|
|
144
|
+
assert.equal(loc.code, 1008);
|
|
145
|
+
assert.equal(loc.message, "Failed to retrieve data");
|
|
146
|
+
assert.deepEqual(loc.body, { serialNumber: "PS8517" });
|
|
147
|
+
const map = steps[2].data[0];
|
|
148
|
+
assert.equal(map.mapName, "20260528172106098_5ecd8fa9");
|
|
149
|
+
assert.equal(map.counts.restrictedAreas, 2);
|
|
150
|
+
assert.equal(map.targetPoints[0].targetPointType, 6);
|
|
151
|
+
assert.equal("imageUrl" in map, false);
|
|
152
|
+
assert.deepEqual(steps[3].data, [{ pathId: "p1", pathName: "Night", mapId: "m1" }]);
|
|
153
|
+
const text = JSON.stringify(steps);
|
|
154
|
+
assert.ok(!text.includes(CREDS.secret) && !text.includes(CREDS.appid), "never a credential");
|
|
155
|
+
assert.ok(!f.calls.some((c) => c.path === "/api/v1/robots/mqtt/credentials"), "never asks for MQTT credentials");
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test("live video: HD asks PadBot for quality 1, default smooth for quality 2", async () => {
|
|
159
|
+
clearPadbotCache();
|
|
160
|
+
const f = fake({ [PADBOT_PATHS.video]: () => ({ playbackUrl: "https://v/play", expiresAt: "2026-09-26T09:00:00.000Z" }) });
|
|
161
|
+
const a = createPadbotAdapter(CREDS, { baseUrl: "https://pb.test", fetch: f.fetch, now: () => NOW });
|
|
162
|
+
await a.getLiveVideo("PS8517", "hd");
|
|
163
|
+
await a.getLiveVideo("PS8517");
|
|
164
|
+
assert.deepEqual(f.calls.map((c) => c.body.quality), [1, 2]);
|
|
165
|
+
});
|