@7365admin1/core 3.124.0 → 3.124.1

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.124.0",
4
+ "version": "3.124.1",
5
5
  "author": "7365admin1",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",
@@ -0,0 +1,157 @@
1
+ // Owner, prod 2026-09-28: the S2 DOES move on Go to point and Return to
2
+ // charger, "but there's a delay" - and our line said "didn't start". The
3
+ // recorded command log (robot 6ab7459bb1255d0491cacf67, PS8517):
4
+ // go-to-point 04:16:27Z: chargingState 2 at +3 s, 1 at +8 s, 0 at +13 s
5
+ // return 04:16:51Z: chargingState 0 at +3 s, 3 at +24 s, 2 at +34 s
6
+ // and 1003 actionState 0 + 1006 wheelLockState 1 the WHOLE time. So movement
7
+ // is read from the charging state and the position, never from 1003 alone.
8
+
9
+ import assert from "node:assert/strict";
10
+ import { test } from "node:test";
11
+
12
+ import {
13
+ PADBOT_PATHS, clearPadbotCache, createPadbotAdapter, padbotMotion, padbotCommandLog, padbotAccountKey,
14
+ } from "./.build/services/padbot.adapter.mjs";
15
+
16
+ const CREDS = { appid: "ak-real-id", secret: "sk-real-secret-never-shown" };
17
+ const L3 = "40f18c40a12ee2f3c0b20b38dc7a5b0f";
18
+ const P4 = "07828db6e34d4e819d24f04b3eba0a60";
19
+ const T0 = Date.parse("2026-09-28T04:16:27.000Z");
20
+ // Exactly what the S2 reported while it drove: nav idle, wheel lock 1.
21
+ const st = (charging) => ({
22
+ "1000": { updatedAt: new Date(T0).toISOString() },
23
+ "1001": { batteryPercent: 100 },
24
+ "1002": { chargingState: charging },
25
+ "1003": { actionType: 0, actionState: 0, message: null },
26
+ "1006": { emergencyStopState: 0, wheelLockState: 1 },
27
+ "1007": { mapId: L3, floor: 3, mapDisplayName: "Lvl3 Office" },
28
+ "1010": { workState: 0, taskType: 0 },
29
+ });
30
+ const asEntry = (s) => [{ serialNumber: "PS8517", states: Object.entries(s).map(([stateType, data]) => ({ stateType, data })) }];
31
+ const MAPS = [{
32
+ mapId: L3, mapDisplayName: "Lvl3 Office", floor: 3, mapGroup: "", width: 400, height: 300, resolution: 0.05, originX: -10, originY: -7.5,
33
+ targetPoints: [
34
+ { targetPointId: P4, mapId: L3, name: "P4", worldX: 4, worldY: 2, targetPointType: 1 },
35
+ { targetPointId: "pile", mapId: L3, name: "Charging Area", worldX: 0, worldY: 0, targetPointType: 10 },
36
+ ],
37
+ }];
38
+
39
+ function rig({ charging, pose = () => ({ worldX: null, worldY: null }) }) {
40
+ let clock = T0;
41
+ const calls = [];
42
+ let reads = 0;
43
+ const fetch = async (url, init) => {
44
+ const path = new URL(url).pathname;
45
+ calls.push(path);
46
+ let data = null;
47
+ if (path === PADBOT_PATHS.states) data = asEntry(st(charging(reads++)));
48
+ if (path === PADBOT_PATHS.maps) data = MAPS;
49
+ if (path === PADBOT_PATHS.location) data = { mapId: L3, ...pose(), yaw: 90 };
50
+ if (path === PADBOT_PATHS.robots) data = [];
51
+ if (path === PADBOT_PATHS.alarms) data = { items: [], totalPages: 0 };
52
+ return { status: 200, text: async () => JSON.stringify({ code: 0, message: "success", requestId: "rid", data }) };
53
+ };
54
+ const adapter = createPadbotAdapter(CREDS, {
55
+ baseUrl: "https://pb.test", fetch, now: () => clock,
56
+ watch: { everyMs: 5000, forMs: 60_000 },
57
+ sleep: async (ms) => { clock += ms; },
58
+ });
59
+ return { adapter, calls, tick: (ms) => (clock += ms) };
60
+ }
61
+ const settle = () => new Promise((r) => setTimeout(r, 30));
62
+ const entry = () => padbotCommandLog(padbotAccountKey(CREDS), "PS8517")[0];
63
+
64
+ test("inferred charging meanings -> words; wheel lock and idle 1003 never decide", () => {
65
+ const go = { kind: "go-to-point", sentAt: 0, charging: 2, pose: null, target: { name: "P4", x: 4, y: 2 } };
66
+ assert.equal(padbotMotion(go, { charging: 2, pose: null }), null, "nothing changed yet");
67
+ assert.deepEqual(padbotMotion(go, { charging: 1, pose: null }), { text: "Leaving the charger", mode: "WORKING", done: false });
68
+ assert.deepEqual(padbotMotion(go, { charging: 0, pose: { x: 1, y: 1 } }), { text: "On the way to P4", mode: "WORKING", done: false });
69
+ assert.deepEqual(padbotMotion(go, { charging: 0, pose: { x: 3.8, y: 2.1 } }), { text: "Arrived at P4", mode: null, done: true });
70
+ const back = { kind: "return", sentAt: 0, charging: 0, pose: { x: 4, y: 2 }, target: null };
71
+ assert.equal(padbotMotion(back, { charging: 0, pose: { x: 4.1, y: 2 } }), null, "10 cm of jitter is not a move");
72
+ assert.equal(padbotMotion(back, { charging: 0, pose: { x: 2, y: 1 } }).text, "On the way to the charger");
73
+ assert.equal(padbotMotion(back, { charging: 3, pose: null }).text, "Docking");
74
+ assert.deepEqual(padbotMotion(back, { charging: 2, pose: null }), { text: "Back on charger", mode: null, done: true });
75
+ });
76
+
77
+ test("recorded go-to-point: 1003 stays idle, the charging state moves -> moved, first change at +10 s, never 'didn't start'", async () => {
78
+ clearPadbotCache();
79
+ // reads: 1 pre-send, then the trace every 5 s: +5 2, +10 1, +15 0, then 0
80
+ const seq = [2, 2, 1, 0];
81
+ const { adapter } = rig({ charging: (i) => seq[Math.min(i, seq.length - 1)] });
82
+ await adapter.sendCommand("PS8517", { kind: "go-to-point", mapId: L3, targetPointId: P4 });
83
+ await settle();
84
+ const e = entry();
85
+ assert.equal(e.reaction.moved, true);
86
+ assert.equal(e.reaction.firstChangeAfterSeconds, 10);
87
+ assert.equal(e.reaction.progress, "On the way to P4");
88
+ assert.ok(e.reaction.points.every((p) => p.state === 0 && p.wheelLock === 1), "the S2's 1003 and wheel lock never changed");
89
+ assert.equal(typeof e.vendorMs, "number");
90
+ });
91
+
92
+ test("recorded return: 0 -> 3 (docking) -> 2 (docked) ends the trace as back on charger", async () => {
93
+ clearPadbotCache();
94
+ const seq = [0, 0, 0, 0, 0, 3, 3, 2];
95
+ const { adapter } = rig({ charging: (i) => seq[Math.min(i, seq.length - 1)] });
96
+ await adapter.sendCommand("PS8517", { kind: "return" });
97
+ await settle();
98
+ const e = entry();
99
+ assert.equal(e.reaction.moved, true);
100
+ assert.equal(e.reaction.firstChangeAfterSeconds, 25);
101
+ assert.equal(e.reaction.progress, "Back on charger");
102
+ assert.equal(e.reaction.watching, false);
103
+ });
104
+
105
+ test("the status line says what it is doing: leaving, on the way, arrived", async () => {
106
+ clearPadbotCache();
107
+ let charging = 2;
108
+ let pose = { worldX: null, worldY: null };
109
+ const { adapter, tick } = rig({ charging: () => charging, pose: () => pose });
110
+ await adapter.sendCommand("PS8517", { kind: "go-to-point", mapId: L3, targetPointId: P4 });
111
+ const read = async () => { tick(1000); return adapter.getRobot("PS8517"); };
112
+ let r = await read();
113
+ assert.match(r.statusName, /^Standing by/, "docked, nothing changed yet");
114
+ charging = 1;
115
+ r = await read();
116
+ assert.match(r.statusName, /^Leaving the charger/);
117
+ assert.equal(r.mode, "WORKING");
118
+ assert.doesNotMatch(r.statusName, /At charger/);
119
+ charging = 0;
120
+ pose = { worldX: 1.5, worldY: 0.8 };
121
+ r = await read();
122
+ assert.match(r.statusName, /^On the way to P4/);
123
+ assert.equal(r.mode, "WORKING");
124
+ assert.ok(r.planPosition, "the map pin follows");
125
+ pose = { worldX: 4.1, worldY: 1.9 };
126
+ r = await read();
127
+ assert.match(r.statusName, /^Arrived at P4/);
128
+ assert.equal(r.mode, "IDLE");
129
+ });
130
+
131
+ test("reads within 900 ms share one PadBot read set (fast poll + map track + other viewers)", async () => {
132
+ clearPadbotCache();
133
+ const { adapter, calls, tick } = rig({ charging: () => 2 });
134
+ await Promise.all([adapter.getRobot("PS8517"), adapter.getRobot("PS8517")]);
135
+ tick(500);
136
+ await adapter.getRobot("PS8517");
137
+ assert.equal(calls.filter((p) => p === PADBOT_PATHS.states).length, 1);
138
+ tick(500);
139
+ await adapter.getRobot("PS8517");
140
+ assert.equal(calls.filter((p) => p === PADBOT_PATHS.states).length, 2);
141
+ });
142
+
143
+ test("one screen read asks PadBot everything at once; the open-alarm read is shared for 10 s", async () => {
144
+ clearPadbotCache();
145
+ const { adapter, calls, tick } = rig({ charging: () => 2 });
146
+ await adapter.getRobot("PS8517");
147
+ const first = calls.slice();
148
+ assert.ok(first.includes(PADBOT_PATHS.location) && first.includes(PADBOT_PATHS.alarms));
149
+ // Location and alarms are requested before the states answer is awaited.
150
+ assert.ok(first.indexOf(PADBOT_PATHS.location) < first.indexOf(PADBOT_PATHS.states), JSON.stringify(first));
151
+ tick(1000);
152
+ await adapter.getRobot("PS8517");
153
+ assert.equal(calls.filter((p) => p === PADBOT_PATHS.alarms).length, 1, "alarm read shared");
154
+ tick(10_000);
155
+ await adapter.getRobot("PS8517");
156
+ assert.equal(calls.filter((p) => p === PADBOT_PATHS.alarms).length, 2);
157
+ });
@@ -468,21 +468,21 @@ test("adapter getRobot: signed calls, state + location + newest open alarm, plan
468
468
  assert.deepEqual(f.calls.find((c) => c.path === PADBOT_PATHS.robots).body, { robotTypes: ["PATROL"] });
469
469
  });
470
470
 
471
- test("adapter getRobot: e-stop outranks alarms; unknown serial = null; offline skips location", async () => {
471
+ // Since 2026-09-28 all reads start together (each PadBot call takes 0.5-2.5 s); an e-stop or offline robot ignores the answers.
472
+ test("adapter getRobot: e-stop outranks alarms; unknown serial = null; offline shows no position", async () => {
472
473
  clearPadbotCache();
473
474
  const estop = [{ serialNumber: "PS0001", states: [...STATE_ANSWER[0].states, { stateType: "1006", data: { emergencyStopState: 1, updatedAt: fresh } }] }];
474
475
  const f = fakePadbot({ [PADBOT_PATHS.states]: () => estop, [PADBOT_PATHS.robots]: () => [], [PADBOT_PATHS.location]: () => null });
475
476
  const a = createPadbotAdapter(CREDS, { baseUrl: "https://pb.test", fetch: f.fetch, now: f.now });
476
477
  const r = await a.getRobot("PS0001");
477
- assert.equal(r.fault.code, "E-STOP");
478
- assert.ok(!f.calls.some((c) => c.path === PADBOT_PATHS.alarms));
478
+ assert.equal(r.fault.code, "E-STOP", "an open alarm never replaces the e-stop");
479
479
  assert.equal(await a.getRobot("NOPE"), null);
480
480
 
481
481
  clearPadbotCache();
482
482
  const g = fakePadbot({ [PADBOT_PATHS.states]: () => [{ serialNumber: "PS0001", states: [{ stateType: "1000", data: null }] }], [PADBOT_PATHS.robots]: () => [] });
483
483
  const off = await createPadbotAdapter(CREDS, { baseUrl: "https://pb.test", fetch: g.fetch, now: g.now }).getRobot("PS0001");
484
484
  assert.equal(off.online, false);
485
- assert.ok(!g.calls.some((c) => c.path === PADBOT_PATHS.location));
485
+ assert.equal(off.position, null);
486
486
  });
487
487
 
488
488
  test("adapter commands: each of ours becomes the documented PadBot call", async () => {