@7365admin1/core 3.122.5 → 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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@7365admin1/core",
3
3
  "license": "MIT",
4
- "version": "3.122.5",
4
+ "version": "3.122.6",
5
5
  "author": "7365admin1",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",
@@ -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");
@@ -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
  });
@@ -488,6 +488,8 @@ test("adapter getRobot: e-stop outranks alarms; unknown serial = null; offline s
488
488
  test("adapter commands: each of ours becomes the documented PadBot call", async () => {
489
489
  const f = fakePadbot({
490
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 } }] })),
491
493
  [PADBOT_PATHS.patrolRoutes]: () => [{ pathId: "p1", pathName: "Loop", mapId: null, isDefault: false, pointNames: [] }],
492
494
  });
493
495
  const a = createPadbotAdapter(CREDS, { baseUrl: "https://pb.test", fetch: f.fetch, now: f.now });
@@ -516,7 +518,10 @@ test("adapter commands: each of ours becomes the documented PadBot call", async
516
518
 
517
519
  test("adapter errors: business codes, HTTP 401/403/5xx and timeouts are plain words; the secret never appears", async () => {
518
520
  const err = async (answer) => {
519
- const f = fakePadbot({ [PADBOT_PATHS.patrolResume]: () => answer });
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
+ });
520
525
  const a = createPadbotAdapter(CREDS, { baseUrl: "https://pb.test", fetch: f.fetch, now: f.now });
521
526
  try {
522
527
  await a.sendCommand("PS1", { kind: "patrol-resume" });