@7365admin1/core 3.122.3 → 3.122.5
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 +7 -1
- package/dist/index.js +78 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +77 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/test/e2e/padbot.e2e.test.mjs +1 -1
- package/test/padbot-patrol-start.test.mjs +105 -0
- package/test/padbot.test.mjs +41 -7
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,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
|
+
});
|
package/test/padbot.test.mjs
CHANGED
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
padbotCheckpointVisit,
|
|
25
25
|
padbotPlanShare,
|
|
26
26
|
padbotCurrentMap,
|
|
27
|
+
padbotChargingPoint,
|
|
27
28
|
padbotAccountKey,
|
|
28
29
|
recordPadbotLive,
|
|
29
30
|
statesByType,
|
|
@@ -485,7 +486,10 @@ test("adapter getRobot: e-stop outranks alarms; unknown serial = null; offline s
|
|
|
485
486
|
});
|
|
486
487
|
|
|
487
488
|
test("adapter commands: each of ours becomes the documented PadBot call", async () => {
|
|
488
|
-
const f = fakePadbot(
|
|
489
|
+
const f = fakePadbot({
|
|
490
|
+
...Object.fromEntries(Object.values(PADBOT_PATHS).map((p) => [p, () => null])),
|
|
491
|
+
[PADBOT_PATHS.patrolRoutes]: () => [{ pathId: "p1", pathName: "Loop", mapId: null, isDefault: false, pointNames: [] }],
|
|
492
|
+
});
|
|
489
493
|
const a = createPadbotAdapter(CREDS, { baseUrl: "https://pb.test", fetch: f.fetch, now: f.now });
|
|
490
494
|
await a.sendCommand("PS1", { kind: "full" });
|
|
491
495
|
await a.sendCommand("PS1", { kind: "area", areas: ["p1"], options: { cleanTimes: 3 } });
|
|
@@ -495,7 +499,7 @@ test("adapter commands: each of ours becomes the documented PadBot call", async
|
|
|
495
499
|
await a.sendCommand("PS1", { kind: "navigate", x: 1.5, y: 2, theta: Math.PI });
|
|
496
500
|
await a.sendCommand("PS1", { kind: "relocalize", floorNo: 1, x: 1, y: 2, theta: 0 });
|
|
497
501
|
assert.deepEqual(
|
|
498
|
-
f.calls.map((c) => [c.path, c.body]),
|
|
502
|
+
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]),
|
|
499
503
|
[
|
|
500
504
|
[PADBOT_PATHS.patrolStart, { serialNumber: "PS1", patrolCount: 1 }],
|
|
501
505
|
[PADBOT_PATHS.patrolStart, { serialNumber: "PS1", pathId: "p1", patrolCount: 3 }],
|
|
@@ -587,26 +591,33 @@ test("adapter listRobots: the account's patrol robots with one batched state rea
|
|
|
587
591
|
const S2_LVL3 = "40f18c40a12ee2f3c0b20b38dc7a5b0f";
|
|
588
592
|
const S2_MAPS = [
|
|
589
593
|
{ mapId: "24fe9c97e9160548d100dab541f1662a", mapName: "20260528172106098_5ecd8fa9", mapDisplayName: "B1", building: "", floor: 1, isDefault: false, width: 1092, height: 1865, resolution: 0.05, originX: -27.55, originY: -80, mapGroup: "" },
|
|
590
|
-
{ mapId: S2_LVL3, mapName: "772df9dc808b45a5_20260924185244234", mapDisplayName: "Lvl3 Office", building: "", floor: 3, isDefault: true, width: 255, height: 244, resolution: 0.05, originX: -24.7, originY: -2.3, mapGroup: ""
|
|
594
|
+
{ mapId: S2_LVL3, mapName: "772df9dc808b45a5_20260924185244234", mapDisplayName: "Lvl3 Office", building: "", floor: 3, isDefault: true, width: 255, height: 244, resolution: 0.05, originX: -24.7, originY: -2.3, mapGroup: "",
|
|
595
|
+
targetPoints: [
|
|
596
|
+
{ name: "P4", targetPointType: 0, worldX: -22.3, worldY: 4.1, yaw: 188 },
|
|
597
|
+
{ name: "P3", targetPointType: 0, worldX: -18.75, worldY: 6.4, yaw: 170 },
|
|
598
|
+
{ name: "Charging Area", targetPointType: 10, worldX: -13.9, worldY: 8.75, yaw: 266 },
|
|
599
|
+
{ name: "P1", targetPointType: 0, worldX: -13.7, worldY: 5.15, yaw: 258 },
|
|
600
|
+
{ name: "P2", targetPointType: 0, worldX: -15.55, worldY: 7.1, yaw: 29 },
|
|
601
|
+
] },
|
|
591
602
|
];
|
|
592
|
-
const s2States = (mapId = S2_LVL3) => [
|
|
603
|
+
const s2States = (mapId = S2_LVL3, chargingState = 2) => [
|
|
593
604
|
{
|
|
594
605
|
serialNumber: "PS8517",
|
|
595
606
|
states: [
|
|
596
607
|
{ stateType: "1000", data: { updatedAt: fresh } },
|
|
597
608
|
{ stateType: "1001", data: { updatedAt: fresh, batteryPercent: 100 } },
|
|
598
|
-
{ stateType: "1002", data: { updatedAt: fresh, chargingState
|
|
609
|
+
{ stateType: "1002", data: { updatedAt: fresh, chargingState } },
|
|
599
610
|
{ stateType: "1003", data: { updatedAt: fresh, mapName: null, nextTargetPointName: null, finalTargetPointName: null, actionType: 0, actionState: 0, message: null } },
|
|
600
611
|
{ stateType: "1007", data: { updatedAt: "2026-09-24T10:52:45.143Z", mapId, floor: 3, mapDisplayName: "Lvl3 Office", width: 255, height: 244 } },
|
|
601
612
|
{ stateType: "1010", data: { updatedAt: fresh, workState: 0, taskType: 0, taskInfo: null } },
|
|
602
613
|
],
|
|
603
614
|
},
|
|
604
615
|
];
|
|
605
|
-
const s2Robot = (location, mapId, heardPose) => {
|
|
616
|
+
const s2Robot = (location, mapId, heardPose, chargingState = 0) => {
|
|
606
617
|
clearPadbotCache();
|
|
607
618
|
if (heardPose) recordPadbotLive(padbotAccountKey(CREDS), "PS8517", { pose: heardPose });
|
|
608
619
|
const f = fakePadbot({
|
|
609
|
-
[PADBOT_PATHS.states]: () => s2States(mapId),
|
|
620
|
+
[PADBOT_PATHS.states]: () => s2States(mapId, chargingState),
|
|
610
621
|
[PADBOT_PATHS.robots]: () => [{ serialNumber: "PS8517", robotName: "HERO-OTH-SECURITY", robotType: "PATROL", robotModel: "S2" }],
|
|
611
622
|
[PADBOT_PATHS.location]: () => location,
|
|
612
623
|
[PADBOT_PATHS.maps]: () => S2_MAPS,
|
|
@@ -654,3 +665,26 @@ test("real S2: PadBot's REST gives null coordinates while standing still -> its
|
|
|
654
665
|
assert.match(other.statusName, /Position not reported$/);
|
|
655
666
|
clearPadbotCache();
|
|
656
667
|
});
|
|
668
|
+
|
|
669
|
+
test("real S2 docked (1002 chargingState 2, REST null, no MQTT pose) -> pin at Lvl3's Charging Area, 'At charger'", async () => {
|
|
670
|
+
const r = await s2Robot({ mapId: S2_LVL3, worldX: null, worldY: null, yaw: -94 }, undefined, undefined, 2);
|
|
671
|
+
assert.deepEqual(r.planPosition, padbotPlanShare(S2_MAPS[1], -13.9, 8.75));
|
|
672
|
+
assert.match(r.statusName, /At charger$/);
|
|
673
|
+
const off = await s2Robot({ mapId: S2_LVL3, worldX: null, worldY: null, yaw: -94 }, undefined, undefined, 0);
|
|
674
|
+
assert.equal(off.position, null, "not on the charger: no pin");
|
|
675
|
+
assert.equal(padbotChargingPoint({ targetPoints: [{ targetPointType: 10, worldX: 1, worldY: 1 }, { targetPointType: 10, worldX: 2, worldY: 2 }] }), null, "two piles: no guess");
|
|
676
|
+
});
|
|
677
|
+
|
|
678
|
+
test("real S2 routes with mapId null -> each on the map holding all its stops (names repeat across maps)", () => {
|
|
679
|
+
const b1 = { ...S2_MAPS[0], targetPoints: ["P1", "P2", "P3", "P4", "P5"].map((name, i) => ({ name, targetPointType: 0, worldX: -20 + i, worldY: -70 + i })) };
|
|
680
|
+
const maps = [b1, S2_MAPS[1]];
|
|
681
|
+
const paths = [
|
|
682
|
+
{ pathId: "a", pathName: "B1", mapId: null, isDefault: true, pointNames: ["P1", "P2", "P3", "P4", "P5"] },
|
|
683
|
+
{ pathId: "b", pathName: "Patrolling Lvl3", mapId: null, isDefault: false, pointNames: ["P1", "P2", "P3", "P4"] },
|
|
684
|
+
];
|
|
685
|
+
const plan = padbotPatrolPlan(paths, maps, { "1007": { mapId: S2_LVL3, floor: 3 } });
|
|
686
|
+
const byId = Object.fromEntries(plan.routes.map((r) => [r.id, r]));
|
|
687
|
+
assert.equal(byId.a.mapId, b1.mapId);
|
|
688
|
+
assert.equal(byId.b.mapId, S2_LVL3, "on both maps -> the robot's current map");
|
|
689
|
+
assert.deepEqual(byId.b.checkpoints[0], { name: "P1", ...padbotPlanShare(S2_MAPS[1], -13.7, 5.15) }, "placed with Lvl3's P1, not B1's");
|
|
690
|
+
});
|