@7365admin1/core 3.122.4 → 3.122.6
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 +77 -3
- package/dist/index.js +182 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +177 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/test/e2e/padbot.e2e.test.mjs +1 -1
- package/test/padbot-command-readiness.test.mjs +103 -0
- package/test/padbot-mqtt.test.mjs +2 -2
- package/test/padbot-patrol-start.test.mjs +105 -0
- package/test/padbot-real-data.test.mjs +4 -2
- package/test/padbot.test.mjs +11 -3
package/package.json
CHANGED
|
@@ -259,7 +259,7 @@ describe("PadBot security robots", { concurrency: 1 }, () => {
|
|
|
259
259
|
assert.deepEqual(call.body, { serialNumber: "PS0001", pathId: "p1", patrolCount: 2 });
|
|
260
260
|
const dflt = await post(`/robots/${id.robot}/command`, { kind: "full" });
|
|
261
261
|
assert.equal(dflt.status, 202, JSON.stringify(dflt.body));
|
|
262
|
-
assert.deepEqual(mock.seen.filter((c) => c.path === "/api/v1/robots/patrol/start").at(-1).body, { serialNumber: "PS0001", patrolCount: 1 });
|
|
262
|
+
assert.deepEqual(mock.seen.filter((c) => c.path === "/api/v1/robots/patrol/start").at(-1).body, { serialNumber: "PS0001", pathId: "p1", patrolCount: 1 }, "the default route, named once checked");
|
|
263
263
|
mock.state.nav = { actionType: 2, actionState: 2 };
|
|
264
264
|
});
|
|
265
265
|
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// Owner, prod 2026-09-26 22:36 SGT: "I click the function but it's not moving".
|
|
2
|
+
// Go to point P4 (Lvl3, robot on Lvl3) and Return to charger were both answered
|
|
3
|
+
// code 0 "success" by PadBot; the robot stayed idle at its charger. Recorded
|
|
4
|
+
// states (Diagnose 14:43Z): 1002 chargingState 2, 1006 wheelLockState 1,
|
|
5
|
+
// e-stop 0, battery 100, 1003 idle. PadBot's own 20:00 schedule also did not
|
|
6
|
+
// run that day. These tests pin what we now do before and after sending.
|
|
7
|
+
|
|
8
|
+
import assert from "node:assert/strict";
|
|
9
|
+
import { test } from "node:test";
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
PADBOT_PATHS, clearPadbotCache, createPadbotAdapter, padbotCommandBlock, padbotReadiness, padbotCommandLog, padbotAccountKey,
|
|
13
|
+
} from "./.build/services/padbot.adapter.mjs";
|
|
14
|
+
|
|
15
|
+
const CREDS = { appid: "ak-real-id", secret: "sk-real-secret-never-shown" };
|
|
16
|
+
const NOW = Date.parse("2026-09-26T14:43:10.000Z");
|
|
17
|
+
const L3 = "40f18c40a12ee2f3c0b20b38dc7a5b0f";
|
|
18
|
+
const st = (over = {}) => ({
|
|
19
|
+
"1000": { updatedAt: "2026-09-26T14:43:05.807Z" },
|
|
20
|
+
"1001": { batteryPercent: 100 },
|
|
21
|
+
"1002": { chargingState: 2 },
|
|
22
|
+
"1003": { actionType: 0, actionState: 0, message: null },
|
|
23
|
+
"1006": { emergencyStopState: 0, wheelLockState: 1 },
|
|
24
|
+
"1007": { mapId: L3, floor: 3, mapDisplayName: "Lvl3 Office" },
|
|
25
|
+
"1010": { workState: 0, taskType: 0 },
|
|
26
|
+
...over,
|
|
27
|
+
});
|
|
28
|
+
const asEntry = (s) => [{ serialNumber: "PS8517", states: Object.entries(s).map(([stateType, data]) => ({ stateType, data })) }];
|
|
29
|
+
|
|
30
|
+
test("blocks: e-stop, low battery, offline, Return while docked; cancel never", () => {
|
|
31
|
+
assert.match(padbotCommandBlock(st({ "1006": { emergencyStopState: 1 } }), "area", NOW), /emergency stop button is pressed/);
|
|
32
|
+
assert.match(padbotCommandBlock(st({ "1001": { batteryPercent: 8 } }), "go-to-point", NOW), /battery is at 8%/);
|
|
33
|
+
assert.equal(padbotCommandBlock(st({ "1001": { batteryPercent: 8 } }), "return", NOW), "The robot is already on its charger.");
|
|
34
|
+
assert.match(padbotCommandBlock(st({ "1000": { updatedAt: "2026-09-26T14:00:00Z" } }), "full", NOW), /not reporting/);
|
|
35
|
+
assert.equal(padbotCommandBlock(st(), "return", NOW), "The robot is already on its charger.");
|
|
36
|
+
assert.equal(padbotCommandBlock(st({ "1006": { emergencyStopState: 1 } }), "cancel", NOW), null);
|
|
37
|
+
// The recorded prod state: nothing PadBot documents as blocking a Go to point.
|
|
38
|
+
assert.equal(padbotCommandBlock(st(), "go-to-point", NOW), null);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("readiness shows the raw wheel lock and charging state 2 with plain notes", () => {
|
|
42
|
+
const r = padbotReadiness(st(), NOW);
|
|
43
|
+
assert.equal(r.online, true);
|
|
44
|
+
assert.equal(r.wheelLockState, 1);
|
|
45
|
+
assert.equal(r.chargingState, 2);
|
|
46
|
+
assert.equal(r.blocker, null);
|
|
47
|
+
assert.equal(r.notes.length, 2);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
function fake(sequence) {
|
|
51
|
+
const calls = [];
|
|
52
|
+
let reads = 0;
|
|
53
|
+
const fetch = async (url, init) => {
|
|
54
|
+
const path = new URL(url).pathname;
|
|
55
|
+
const body = JSON.parse(init.body);
|
|
56
|
+
calls.push({ path, body });
|
|
57
|
+
let data = null;
|
|
58
|
+
if (path === PADBOT_PATHS.states) data = asEntry(sequence[Math.min(reads++, sequence.length - 1)]);
|
|
59
|
+
if (path === PADBOT_PATHS.maps) data = [{ mapId: L3, mapDisplayName: "Lvl3 Office", floor: 3, mapGroup: "", targetPoints: [] }];
|
|
60
|
+
if (path === PADBOT_PATHS.location) data = { mapId: L3, worldX: null, worldY: null, yaw: -93 };
|
|
61
|
+
if (path === PADBOT_PATHS.robots) data = [];
|
|
62
|
+
return { status: 200, text: async () => JSON.stringify({ code: 0, message: "success", requestId: "rid-1", data }) };
|
|
63
|
+
};
|
|
64
|
+
const adapter = createPadbotAdapter(CREDS, { baseUrl: "https://pb.test", fetch, now: () => NOW, watch: { everyMs: 1, forMs: 10 }, sleep: () => Promise.resolve() });
|
|
65
|
+
return { calls, adapter };
|
|
66
|
+
}
|
|
67
|
+
const settle = () => new Promise((r) => setTimeout(r, 20));
|
|
68
|
+
|
|
69
|
+
test("Return while docked is refused in words; nothing is sent", async () => {
|
|
70
|
+
clearPadbotCache();
|
|
71
|
+
const { calls, adapter } = fake([st()]);
|
|
72
|
+
await assert.rejects(adapter.sendCommand("PS8517", { kind: "return" }), (e) => e.statusCode === 400 && e.message === "The robot is already on its charger.");
|
|
73
|
+
assert.equal(calls.filter((c) => c.path === PADBOT_PATHS.charge).length, 0);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("after an accepted Go to point the robot's own failure is kept and shown on the status line", async () => {
|
|
77
|
+
clearPadbotCache();
|
|
78
|
+
const failed = st({ "1003": { actionType: 11, actionState: 6, finalTargetPointName: "P4", message: "wheel locked" } });
|
|
79
|
+
// reads: the pre-send check, the map check, then the trace.
|
|
80
|
+
const { adapter } = fake([st(), st(), st({ "1003": { actionType: 11, actionState: 1, finalTargetPointName: "P4" } }), failed, failed]);
|
|
81
|
+
await adapter.sendCommand("PS8517", { kind: "go-to-point", mapId: L3, targetPointId: "07828d" });
|
|
82
|
+
await settle();
|
|
83
|
+
const [entry] = padbotCommandLog(padbotAccountKey(CREDS), "PS8517");
|
|
84
|
+
assert.equal(entry.vendorMessage, "success");
|
|
85
|
+
assert.equal(entry.requestId, "rid-1");
|
|
86
|
+
assert.equal(entry.reaction.watching, false);
|
|
87
|
+
assert.equal(entry.reaction.moved, true);
|
|
88
|
+
assert.equal(entry.reaction.failure, "Could not reach P4 (wheel locked)");
|
|
89
|
+
assert.ok(entry.reaction.points.length >= 2);
|
|
90
|
+
const robot = await adapter.getRobot("PS8517");
|
|
91
|
+
assert.match(robot.statusName, /^Could not reach P4 \(wheel locked\) · /);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test("no reaction at all is recorded as such (robot never moved)", async () => {
|
|
95
|
+
clearPadbotCache();
|
|
96
|
+
const { adapter } = fake([st()]);
|
|
97
|
+
await adapter.sendCommand("PS8517", { kind: "go-to-point", mapId: L3, targetPointId: "07828d" });
|
|
98
|
+
await settle();
|
|
99
|
+
const [entry] = padbotCommandLog(padbotAccountKey(CREDS), "PS8517");
|
|
100
|
+
assert.equal(entry.reaction.moved, false);
|
|
101
|
+
assert.equal(entry.reaction.failure, null);
|
|
102
|
+
assert.equal(entry.reaction.points.length, 1);
|
|
103
|
+
});
|
|
@@ -351,10 +351,10 @@ test("go-to-point: parsed strictly; needs navigateToPoint; PadBot sends §5.7 wi
|
|
|
351
351
|
calls.push({ path, body: JSON.parse(init.body) });
|
|
352
352
|
const code = path === PADBOT_PATHS.stop ? 1009 : 0;
|
|
353
353
|
// The robot reports map m1 (§4.2 1007), so a point on m1 is reachable.
|
|
354
|
-
const data = path === PADBOT_PATHS.states ? [{ serialNumber: "PS1", states: [{ stateType: "1007", data: { mapId: "m1" } }] }] : null;
|
|
354
|
+
const data = path === PADBOT_PATHS.states ? [{ serialNumber: "PS1", states: [{ stateType: "1000", data: { updatedAt: new Date().toISOString() } }, { stateType: "1007", data: { mapId: "m1" } }] }] : null;
|
|
355
355
|
return { status: 200, text: async () => JSON.stringify({ code, message: code ? "robot busy" : "success", data }) };
|
|
356
356
|
};
|
|
357
|
-
const a = createPadbotAdapter(creds, { baseUrl: "https://pb.test", fetch });
|
|
357
|
+
const a = createPadbotAdapter(creds, { baseUrl: "https://pb.test", fetch, watch: false });
|
|
358
358
|
await a.sendCommand("PS1", { kind: "go-to-point", mapId: "m1", targetPointId: "t2" });
|
|
359
359
|
assert.deepEqual(calls.at(-1), { path: "/api/v1/robots/actions/navigate-to-target", body: { serialNumber: "PS1", mapId: "m1", targetPointId: "t2" } });
|
|
360
360
|
await assert.rejects(a.sendCommand("PS1", { kind: "cancel" }), (e) => e.vendorCode === 1009 && e.vendorMessage === "robot busy");
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// Owner, prod 2026-09-26: "start patrol also not working". Start patrol sent
|
|
2
|
+
// {kind:"full"} = §6.2 with no pathId = PadBot's DEFAULT route "B1", which lies
|
|
3
|
+
// on map B1, while the S2 stood docked on "Lvl3 Office". PadBot answered code 0
|
|
4
|
+
// and the robot stayed idle. Shapes below are the robot's recorded answers
|
|
5
|
+
// (Diagnose, 2026-09-26 12:04Z), ids shortened.
|
|
6
|
+
|
|
7
|
+
import assert from "node:assert/strict";
|
|
8
|
+
import { test } from "node:test";
|
|
9
|
+
|
|
10
|
+
import { PADBOT_PATHS, clearPadbotCache, createPadbotAdapter, padbotPatrolPlan } from "./.build/services/padbot.adapter.mjs";
|
|
11
|
+
|
|
12
|
+
const CREDS = { appid: "ak-real-id", secret: "sk-real-secret-never-shown" };
|
|
13
|
+
const NOW = Date.parse("2026-09-26T12:05:00.000Z");
|
|
14
|
+
const L3 = "40f18c40a12ee2f3c0b20b38dc7a5b0f";
|
|
15
|
+
const B1 = "24fe9c97e9160548d100dab541f1662a";
|
|
16
|
+
|
|
17
|
+
const pt = (mapId, name, id) => ({ mapId, targetPointName: name, targetPointId: id, pointIndex: Number(name.slice(1)) - 1 });
|
|
18
|
+
// Recorded §6.1: route mapId null on BOTH; each point carries its own map.
|
|
19
|
+
const ROUTES = [
|
|
20
|
+
{ pathId: "0889310e", pathName: "Patrolling Lvl3", mapId: null, isDefault: false, pointNames: ["P1", "P2", "P3", "P4"],
|
|
21
|
+
points: [pt(L3, "P1", "b35a4c"), pt(L3, "P2", "f151f7"), pt(L3, "P3", "45ad80"), pt(L3, "P4", "07828d")] },
|
|
22
|
+
{ pathId: "8e29085d", pathName: "B1", mapId: null, isDefault: true, pointNames: ["P1", "P2", "P3", "P4"],
|
|
23
|
+
points: [pt(B1, "P1", "1dc040"), pt(B1, "P2", "216e69"), pt(B1, "P3", "d1bec1"), pt(B1, "P4", "391a51")] },
|
|
24
|
+
];
|
|
25
|
+
// Both maps hold P1-P4 (name matching alone cannot tell the routes apart).
|
|
26
|
+
const tps = (mapId, ids) => ["P1", "P2", "P3", "P4"].map((n, i) => ({ targetPointId: ids[i], mapId, name: n, targetPointType: 0, worldX: i, worldY: i }));
|
|
27
|
+
const MAPS = [
|
|
28
|
+
{ mapId: B1, mapName: "B1", mapDisplayName: "B1", floor: 1, isDefault: false, mapGroup: "", targetPoints: tps(B1, ["1dc040", "216e69", "d1bec1", "391a51"]) },
|
|
29
|
+
{ mapId: L3, mapName: "Lvl3 Office", mapDisplayName: "Lvl3 Office", floor: 3, isDefault: true, mapGroup: "",
|
|
30
|
+
targetPoints: [...tps(L3, ["b35a4c", "f151f7", "45ad80", "07828d"]), { targetPointId: "chg", mapId: L3, name: "Charging Area", targetPointType: 10, worldX: -13.9, worldY: 8.75 }] },
|
|
31
|
+
];
|
|
32
|
+
const STATES = [{ serialNumber: "PS8517", states: [
|
|
33
|
+
{ stateType: "1000", data: { updatedAt: "2026-09-26T12:04:05.593Z" } },
|
|
34
|
+
{ stateType: "1002", data: { updatedAt: "2026-09-26T09:44:36.968Z", chargingState: 2 } },
|
|
35
|
+
{ stateType: "1003", data: { actionType: 0, actionState: 0 } },
|
|
36
|
+
{ stateType: "1007", data: { mapId: L3, floor: 3, mapDisplayName: "Lvl3 Office" } },
|
|
37
|
+
{ stateType: "1010", data: { workState: 0, taskType: 0 } },
|
|
38
|
+
] }];
|
|
39
|
+
|
|
40
|
+
function fake(extra = {}) {
|
|
41
|
+
const calls = [];
|
|
42
|
+
const answers = {
|
|
43
|
+
[PADBOT_PATHS.states]: () => STATES,
|
|
44
|
+
[PADBOT_PATHS.maps]: () => MAPS,
|
|
45
|
+
[PADBOT_PATHS.location]: () => ({ mapId: L3, worldX: -13.889, worldY: 8.878, yaw: -94 }),
|
|
46
|
+
[PADBOT_PATHS.patrolRoutes]: () => ROUTES,
|
|
47
|
+
[PADBOT_PATHS.patrolStart]: () => null,
|
|
48
|
+
[PADBOT_PATHS.navigateTarget]: () => null,
|
|
49
|
+
...extra,
|
|
50
|
+
};
|
|
51
|
+
const fetch = async (url, init) => {
|
|
52
|
+
const path = new URL(url).pathname;
|
|
53
|
+
calls.push({ path, body: JSON.parse(init.body) });
|
|
54
|
+
const out = answers[path]?.(JSON.parse(init.body));
|
|
55
|
+
return { status: 200, text: async () => JSON.stringify(out?.__raw ?? { code: 0, message: "success", data: out ?? null }) };
|
|
56
|
+
};
|
|
57
|
+
return { calls, adapter: createPadbotAdapter(CREDS, { baseUrl: "https://pb.test", fetch, now: () => NOW }) };
|
|
58
|
+
}
|
|
59
|
+
const starts = (calls) => calls.filter((c) => c.path === PADBOT_PATHS.patrolStart);
|
|
60
|
+
|
|
61
|
+
test("routes take their map from their points (route mapId null), and the robot's map comes first", () => {
|
|
62
|
+
const plan = padbotPatrolPlan(ROUTES, MAPS, { "1007": { mapId: L3 } });
|
|
63
|
+
assert.deepEqual(plan.routes.map((r) => [r.name, r.mapId, r.floorNo]), [["Patrolling Lvl3", L3, 3], ["B1 (default)", B1, 1]]);
|
|
64
|
+
// On B1 the default (B1) comes first.
|
|
65
|
+
assert.equal(padbotPatrolPlan(ROUTES, MAPS, { "1007": { mapId: B1 } }).routes[0].name, "B1 (default)");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("Start patrol (default route) on another map is refused in words; nothing is sent", async () => {
|
|
69
|
+
clearPadbotCache();
|
|
70
|
+
const { calls, adapter } = fake();
|
|
71
|
+
await assert.rejects(adapter.sendCommand("PS8517", { kind: "full" }), (e) =>
|
|
72
|
+
e.statusCode === 400 && e.message === '"B1" is on the B1 map, but the robot is on Lvl3 Office. Pick a route on the robot\'s map.');
|
|
73
|
+
assert.equal(starts(calls).length, 0);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("Start patrol with the Lvl3 route sends exactly that route once", async () => {
|
|
77
|
+
clearPadbotCache();
|
|
78
|
+
const { calls, adapter } = fake();
|
|
79
|
+
await adapter.sendCommand("PS8517", { kind: "area", areas: ["0889310e"] });
|
|
80
|
+
assert.deepEqual(starts(calls).map((c) => c.body), [{ serialNumber: "PS8517", pathId: "0889310e", patrolCount: 1 }]);
|
|
81
|
+
await assert.rejects(adapter.sendCommand("PS8517", { kind: "area", areas: ["8e29085d"] }), /is on the B1 map/);
|
|
82
|
+
await assert.rejects(adapter.sendCommand("PS8517", { kind: "area", areas: ["gone"] }), /no longer exists/);
|
|
83
|
+
assert.equal(starts(calls).length, 1);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test("default route on the robot's map: full names it explicitly; a code != 0 inside HTTP 200 is a refusal", async () => {
|
|
87
|
+
clearPadbotCache();
|
|
88
|
+
const onB1 = [{ serialNumber: "PS8517", states: STATES[0].states.map((s) => (s.stateType === "1007" ? { ...s, data: { mapId: B1, floor: 1 } } : s)) }];
|
|
89
|
+
const { calls, adapter } = fake({ [PADBOT_PATHS.states]: () => onB1, [PADBOT_PATHS.location]: () => ({ mapId: B1, worldX: null, worldY: null }) });
|
|
90
|
+
await adapter.sendCommand("PS8517", { kind: "full" });
|
|
91
|
+
assert.deepEqual(starts(calls).at(-1).body, { serialNumber: "PS8517", pathId: "8e29085d", patrolCount: 1 });
|
|
92
|
+
|
|
93
|
+
clearPadbotCache();
|
|
94
|
+
const busy = fake({ [PADBOT_PATHS.patrolStart]: () => ({ __raw: { code: 1009, message: "robot busy", requestId: "x", data: null } }) });
|
|
95
|
+
await assert.rejects(busy.adapter.sendCommand("PS8517", { kind: "area", areas: ["0889310e"] }), (e) =>
|
|
96
|
+
e.message === "The robot is busy with something else right now." && e.vendorCode === 1009);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("go to point uses the location read's map (newer than state 1007)", async () => {
|
|
100
|
+
clearPadbotCache();
|
|
101
|
+
const stale = [{ serialNumber: "PS8517", states: STATES[0].states.map((s) => (s.stateType === "1007" ? { ...s, data: { mapId: B1, floor: 1 } } : s)) }];
|
|
102
|
+
const { calls, adapter } = fake({ [PADBOT_PATHS.states]: () => stale });
|
|
103
|
+
await adapter.sendCommand("PS8517", { kind: "go-to-point", mapId: L3, targetPointId: "b35a4c" });
|
|
104
|
+
assert.deepEqual(calls.at(-1).body, { serialNumber: "PS8517", mapId: L3, targetPointId: "b35a4c" });
|
|
105
|
+
});
|
|
@@ -141,7 +141,9 @@ test("diagnose: PadBot's raw answers per read (code, message, data); maps summar
|
|
|
141
141
|
[PADBOT_PATHS.records]: () => ({ items: [], totalItems: 0 }),
|
|
142
142
|
});
|
|
143
143
|
const steps = await createPadbotAdapter(CREDS, { baseUrl: "https://pb.test", fetch: f.fetch, now: () => NOW }).diagnose("PS8517");
|
|
144
|
-
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)", "recent commands (this server)"]);
|
|
144
|
+
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)", "recent commands (this server)", "can it move now? (from 4.2)"]);
|
|
145
|
+
assert.equal(steps.at(-1).data.online, true);
|
|
146
|
+
assert.equal(steps.at(-1).data.blocker, null);
|
|
145
147
|
const loc = steps[1];
|
|
146
148
|
assert.equal(loc.code, 1008);
|
|
147
149
|
assert.equal(loc.message, "Failed to retrieve data");
|
|
@@ -203,7 +205,7 @@ test("go to point on another map: only inside one map group, else 'The robot mus
|
|
|
203
205
|
|
|
204
206
|
clearPadbotCache();
|
|
205
207
|
const f = fake({
|
|
206
|
-
[PADBOT_PATHS.states]: () => [{ serialNumber: "PS8517", states: [{ stateType: "1007", data: { mapId: "m1" } }] }],
|
|
208
|
+
[PADBOT_PATHS.states]: () => [{ serialNumber: "PS8517", states: [{ stateType: "1000", data: { updatedAt: fresh } }, { stateType: "1007", data: { mapId: "m1" } }] }],
|
|
207
209
|
[PADBOT_PATHS.maps]: () => [{ mapId: "m1", mapGroup: "" }, { mapId: "m2", mapGroup: "" }],
|
|
208
210
|
[PADBOT_PATHS.navigateTarget]: () => null,
|
|
209
211
|
});
|
package/test/padbot.test.mjs
CHANGED
|
@@ -486,7 +486,12 @@ test("adapter getRobot: e-stop outranks alarms; unknown serial = null; offline s
|
|
|
486
486
|
});
|
|
487
487
|
|
|
488
488
|
test("adapter commands: each of ours becomes the documented PadBot call", async () => {
|
|
489
|
-
const f = fakePadbot(
|
|
489
|
+
const f = fakePadbot({
|
|
490
|
+
...Object.fromEntries(Object.values(PADBOT_PATHS).map((p) => [p, () => null])),
|
|
491
|
+
// Reporting, off its charger: every moving command passes the pre-send check.
|
|
492
|
+
[PADBOT_PATHS.states]: (b) => (b.serialNumbers ?? []).map((serialNumber) => ({ serialNumber, states: [{ stateType: "1000", data: { updatedAt: fresh } }] })),
|
|
493
|
+
[PADBOT_PATHS.patrolRoutes]: () => [{ pathId: "p1", pathName: "Loop", mapId: null, isDefault: false, pointNames: [] }],
|
|
494
|
+
});
|
|
490
495
|
const a = createPadbotAdapter(CREDS, { baseUrl: "https://pb.test", fetch: f.fetch, now: f.now });
|
|
491
496
|
await a.sendCommand("PS1", { kind: "full" });
|
|
492
497
|
await a.sendCommand("PS1", { kind: "area", areas: ["p1"], options: { cleanTimes: 3 } });
|
|
@@ -496,7 +501,7 @@ test("adapter commands: each of ours becomes the documented PadBot call", async
|
|
|
496
501
|
await a.sendCommand("PS1", { kind: "navigate", x: 1.5, y: 2, theta: Math.PI });
|
|
497
502
|
await a.sendCommand("PS1", { kind: "relocalize", floorNo: 1, x: 1, y: 2, theta: 0 });
|
|
498
503
|
assert.deepEqual(
|
|
499
|
-
f.calls.map((c) => [c.path, c.body]),
|
|
504
|
+
f.calls.filter((c) => ![PADBOT_PATHS.patrolRoutes, PADBOT_PATHS.states, PADBOT_PATHS.maps, PADBOT_PATHS.location].includes(c.path)).map((c) => [c.path, c.body]),
|
|
500
505
|
[
|
|
501
506
|
[PADBOT_PATHS.patrolStart, { serialNumber: "PS1", patrolCount: 1 }],
|
|
502
507
|
[PADBOT_PATHS.patrolStart, { serialNumber: "PS1", pathId: "p1", patrolCount: 3 }],
|
|
@@ -513,7 +518,10 @@ test("adapter commands: each of ours becomes the documented PadBot call", async
|
|
|
513
518
|
|
|
514
519
|
test("adapter errors: business codes, HTTP 401/403/5xx and timeouts are plain words; the secret never appears", async () => {
|
|
515
520
|
const err = async (answer) => {
|
|
516
|
-
const f = fakePadbot({
|
|
521
|
+
const f = fakePadbot({
|
|
522
|
+
[PADBOT_PATHS.patrolResume]: () => answer,
|
|
523
|
+
[PADBOT_PATHS.states]: () => (answer?.__status ? answer : [{ serialNumber: "PS1", states: [{ stateType: "1000", data: { updatedAt: fresh } }] }]),
|
|
524
|
+
});
|
|
517
525
|
const a = createPadbotAdapter(CREDS, { baseUrl: "https://pb.test", fetch: f.fetch, now: f.now });
|
|
518
526
|
try {
|
|
519
527
|
await a.sendCommand("PS1", { kind: "patrol-resume" });
|