@7365admin1/core 3.124.0 → 3.124.2

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.
@@ -5,15 +5,15 @@
5
5
  },
6
6
  "auditLog": "logs\\.6b77785a74c362881f6fb7e95a7530280abbf9ed-audit.json",
7
7
  "files": [
8
- {
9
- "date": 1789008603082,
10
- "name": "logs\\error-2026-09-10.log",
11
- "hash": "ea96d42a9881c629d5b87fa8ce141575a177edfc9aef559c47d82848cdc5df47"
12
- },
13
8
  {
14
9
  "date": 1790145019990,
15
10
  "name": "logs\\error-2026-09-23.log",
16
11
  "hash": "6e81a0234c7b52f196d78508cf2167c58491140d446371c3a823b62ace1ed770"
12
+ },
13
+ {
14
+ "date": 1790578085876,
15
+ "name": "logs\\error-2026-09-28.log",
16
+ "hash": "090eef778e4a0d0e7343e2752822f247daa6fa85800fcf9f7d2892f296670ee8"
17
17
  }
18
18
  ],
19
19
  "hashType": "sha256"
@@ -5,15 +5,15 @@
5
5
  },
6
6
  "auditLog": "logs\\.ca6dad43b7d35307d69543a741eb24d3ce997028-audit.json",
7
7
  "files": [
8
- {
9
- "date": 1789008603086,
10
- "name": "logs\\combined-2026-09-10.log",
11
- "hash": "055e77a0887051fb145bef3e749b6db5d193493d5332f359c80c3052d0e9dcea"
12
- },
13
8
  {
14
9
  "date": 1790145020005,
15
10
  "name": "logs\\combined-2026-09-23.log",
16
11
  "hash": "769ffe827dc48bd68cf6b2e69179b7178cf1d9ce0f0e8da27ccbef7208437632"
12
+ },
13
+ {
14
+ "date": 1790578085878,
15
+ "name": "logs\\combined-2026-09-28.log",
16
+ "hash": "0fabbf77efacc2e42a7669272c630fa860dacf4b1322d5f0b0a3206427b88004"
17
17
  }
18
18
  ],
19
19
  "hashType": "sha256"
@@ -9,6 +9,11 @@
9
9
  "date": 1789995497468,
10
10
  "name": "logs/dahua/combined-2026-09-21.log",
11
11
  "hash": "e9f559a17482c8db46516a98837d06aefb2c89a9a1cced1984c898aac2211687"
12
+ },
13
+ {
14
+ "date": 1790578089763,
15
+ "name": "logs\\dahua\\combined-2026-09-28.log",
16
+ "hash": "551ad46847a556b3cb3508cbb65b7a2714025bf7f62c41b4027b6e06d4b88ade"
12
17
  }
13
18
  ],
14
19
  "hashType": "sha256"
@@ -9,6 +9,11 @@
9
9
  "date": 1789995497455,
10
10
  "name": "logs/dahua/error-2026-09-21.log",
11
11
  "hash": "d5a28fc0fc6195af7c8ce89e5b17b5b895de405cd4df6ada014a4581ed52eb9a"
12
+ },
13
+ {
14
+ "date": 1790578089761,
15
+ "name": "logs\\dahua\\error-2026-09-28.log",
16
+ "hash": "c59b070720c0b4b117e3a88ba2d9812e1987c939864266afa2127928d80286a6"
12
17
  }
13
18
  ],
14
19
  "hashType": "sha256"
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.2",
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/robot-cloud.service.ts src/services/robot-fleet.service.ts src/services/padbot.adapter.ts src/utils/padbot-sign.util.ts src/utils/padbot-mqtt.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/utils/padbot-mqtt.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/site.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
  },
@@ -119,3 +119,23 @@ test("nothing is reported while the camera is connected", () => {
119
119
  assert.equal(shouldAlertOnFailure(-1), false);
120
120
  assert.equal(shouldAlertOnFailure(1.5), false);
121
121
  });
122
+
123
+ import { shouldStoreCameraFault } from "./.build/utils/camera-alert.util.mjs";
124
+
125
+ test("one inbox row per outage, not one per paced toast", () => {
126
+ // Replay the reconnect loop: failures 1..100, alerts where shouldAlertOnFailure says.
127
+ let alerted = 0;
128
+ let stored = 0;
129
+ let toasts = 0;
130
+ for (let failure = 1; failure <= 100; failure++) {
131
+ if (!shouldAlertOnFailure(failure)) continue;
132
+ toasts++;
133
+ if (shouldStoreCameraFault(alerted)) stored++;
134
+ alerted = failure;
135
+ }
136
+ assert.ok(toasts >= 4, "the live toast keeps its pacing");
137
+ assert.equal(stored, 1, "the inbox gets exactly one row for this outage");
138
+ // Reconnect resets the count, so the next outage is stored again.
139
+ alerted = 0;
140
+ assert.equal(shouldStoreCameraFault(alerted), true);
141
+ });
@@ -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 () => {
@@ -0,0 +1,70 @@
1
+ import test from "node:test";
2
+ import assert from "node:assert/strict";
3
+
4
+ import { MSite } from "./.build/models/site.model.mjs";
5
+
6
+ /**
7
+ * A new site's incident counter.
8
+ *
9
+ * `incident-report.service.ts` increments `metadata.incidentCounter` for every
10
+ * report filed. The key used to appear only on the first report — a dotted
11
+ * `$set` creates it — so a site's shape depended on whether anybody had filed
12
+ * one yet: absent on a new site, a number on an old one.
13
+ *
14
+ * Seeded at creation, every site has the same shape from the start. Every
15
+ * creation path funnels through `MSite`, so one default covers all three.
16
+ */
17
+
18
+ /** The minimum `siteSchema` accepts — every field below is required by it. */
19
+ const VALID = {
20
+ name: "Seventh Condominium",
21
+ orgId: "692132394150ca6a69b9f298",
22
+ address: {
23
+ line1: "1 Example Road",
24
+ city: "Singapore",
25
+ postalCode: "123456",
26
+ country: "Singapore",
27
+ },
28
+ };
29
+
30
+ test("a new site starts with a zero incident counter", () => {
31
+ const site = MSite({ ...VALID });
32
+ assert.equal(site.metadata.incidentCounter, 0);
33
+ });
34
+
35
+ /*
36
+ * Zero, not one. The service reads the current value and adds one, so the first
37
+ * report must produce 1 — seeding 1 would make it 2 and skip a number.
38
+ */
39
+ test("the seed is zero, so the first report is number one", () => {
40
+ const site = MSite({ ...VALID });
41
+ const firstReport = (site.metadata?.incidentCounter || 0) + 1;
42
+ assert.equal(firstReport, 1);
43
+ });
44
+
45
+ /*
46
+ * `siteSchema` refuses `metadata` on creation, so the counter cannot be
47
+ * supplied by a caller and the seeded value is the only one a new site can
48
+ * have. Documented here because it is the reason the default is unconditional.
49
+ */
50
+ test("metadata cannot be supplied at creation at all", () => {
51
+ assert.throws(
52
+ () => MSite({ ...VALID, metadata: { incidentCounter: 42 } }),
53
+ /metadata.*not allowed/,
54
+ );
55
+ });
56
+
57
+ /*
58
+ * The old behaviour for everything else: metadata held nothing when none was
59
+ * given, and the counter is still all a new site carries.
60
+ */
61
+ test("nothing else is invented in metadata", () => {
62
+ const site = MSite({ ...VALID });
63
+ assert.deepEqual(Object.keys(site.metadata), ["incidentCounter"]);
64
+ });
65
+ /* Optional fields left out entirely must not disturb the default. */
66
+ test("a site created with only the required fields still gets the counter", () => {
67
+ const site = MSite({ ...VALID });
68
+ assert.equal(site.metadata.incidentCounter, 0);
69
+ assert.equal(site.status, "active");
70
+ });
File without changes
File without changes