@7365admin1/core 3.103.0 → 3.107.0

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.
@@ -164,12 +164,12 @@ describe("notification categories", () => {
164
164
  assert.deepEqual(categoriesForPermissions({}), []);
165
165
  });
166
166
 
167
- it("email is claimed only where a user account is actually the recipient", () => {
168
- const emailCapable = NOTIFICATION_CATEGORIES.filter(
169
- (c) => c.channels.email,
167
+ it("every rendered category offers email (owner request 2026-09-25; opt-in, verified-only)", () => {
168
+ const noEmail = NOTIFICATION_CATEGORIES.filter(
169
+ (c) => c.rendered && !c.channels.email,
170
170
  ).map((c) => c.key);
171
171
 
172
- assert.deepEqual(emailCapable, []);
172
+ assert.deepEqual(noEmail, []);
173
173
  });
174
174
 
175
175
  it("every channel a category cannot use explains itself in plain words", () => {
@@ -199,8 +199,8 @@ describe("notification categories", () => {
199
199
 
200
200
  it("channel support is a fact about the category, not a preference", () => {
201
201
  assert.equal(categorySupportsChannel("workOrder", "push"), true);
202
- assert.equal(categorySupportsChannel("workOrder", "email"), false);
203
- assert.equal(categorySupportsChannel("serviceProviderInvite", "email"), false);
202
+ assert.equal(categorySupportsChannel("workOrder", "email"), true);
203
+ assert.equal(categorySupportsChannel("serviceProviderInvite", "email"), true);
204
204
  assert.equal(categorySupportsChannel("not-a-module", "push"), false);
205
205
  });
206
206
 
@@ -210,19 +210,12 @@ describe("notification categories", () => {
210
210
  // `email: true`, and `emergencyContact` was offered with no sender at all.
211
211
  // -------------------------------------------------------------------------
212
212
 
213
- it("no category offers a switchable Email row, because no sender reads one", () => {
214
- // `filterRecipients`/`isChannelEnabled` are never called with "email"
215
- // anywhere in the estate, so a movable Email switch would govern nothing.
213
+ it("Email no longer carries an apology: it is a real, opt-in switch", () => {
214
+ // `notification-email.service.ts` reads `emailOn` + a verified address, so
215
+ // the switch governs real mail. Opt-in is enforced there, not here.
216
216
  for (const category of NOTIFICATION_CATEGORIES) {
217
- assert.equal(
218
- category.channels.email,
219
- false,
220
- `${category.key} offers a live Email switch that no sender consults`,
221
- );
222
- assert.ok(
223
- category.channelNote?.email,
224
- `${category.key} dims Email without saying why`,
225
- );
217
+ assert.equal(category.channels.email, true, category.key);
218
+ assert.equal(category.channelNote?.email, undefined, category.key);
226
219
  }
227
220
  });
228
221
 
@@ -498,7 +491,7 @@ describe("existing categories are untouched by the marketplace addition", () =>
498
491
  for (const category of NOTIFICATION_CATEGORIES) {
499
492
  if (NEW_KEYS.includes(category.key)) continue;
500
493
 
501
- assert.equal(category.channels.email, false, category.key);
494
+ assert.equal(category.channels.email, true, category.key);
502
495
  assert.equal(category.channels.inApp, true, category.key);
503
496
  assert.equal(category.channels.push, true, category.key);
504
497
  }
@@ -0,0 +1,207 @@
1
+ // Notification emails — the pure rules: who may be emailed, the one-click
2
+ // turn-off token, the verification code, and what the email says.
3
+ import { describe, it } from "node:test";
4
+ import assert from "node:assert/strict";
5
+
6
+ import {
7
+ DEFAULT_EMAIL_ALLOWLIST,
8
+ EMAIL_PER_MODULE_PER_HOUR,
9
+ codeMatches,
10
+ effectiveEmailAllowlist,
11
+ emailOpenToEveryone,
12
+ escapeHtml,
13
+ hashCode,
14
+ isEmailAllowed,
15
+ isProductionWebBase,
16
+ newCode,
17
+ notificationEmail,
18
+ offLink,
19
+ offPage,
20
+ offToken,
21
+ offTokenMatches,
22
+ openLink,
23
+ verificationEmail,
24
+ } from "./.build/utils/notification-email.util.mjs";
25
+
26
+ const U = "65f1a2b3c4d5e6f708192a3b";
27
+ const SECRET = "a".repeat(64);
28
+
29
+ describe("allow-list (staging shares the production mailer)", () => {
30
+ it("fails closed: unset means only Seven365's own domain", () => {
31
+ assert.equal(DEFAULT_EMAIL_ALLOWLIST, "*@seven365.com.sg");
32
+ assert.equal(isEmailAllowed("security@seven365.com.sg", undefined), true);
33
+ assert.equal(isEmailAllowed("Harris@Seven365.com.sg", ""), true);
34
+ assert.equal(isEmailAllowed("someone@gmail.com", undefined), false);
35
+ assert.equal(isEmailAllowed("x@evil-seven365.com.sg", undefined), false);
36
+ assert.equal(isEmailAllowed("x@seven365.com.sg.evil.com", undefined), false);
37
+ });
38
+
39
+ it("an explicit list replaces the default", () => {
40
+ const list = "*@example.org, qa@test.io @other.net";
41
+ assert.equal(isEmailAllowed("a@example.org", list), true);
42
+ assert.equal(isEmailAllowed("qa@test.io", list), true);
43
+ assert.equal(isEmailAllowed("b@test.io", list), false);
44
+ assert.equal(isEmailAllowed("c@other.net", list), true);
45
+ assert.equal(isEmailAllowed("security@seven365.com.sg", list), false);
46
+ });
47
+
48
+ it("only '*' opens it to everyone", () => {
49
+ assert.equal(isEmailAllowed("anyone@gmail.com", "*"), true);
50
+ assert.equal(emailOpenToEveryone("*"), true);
51
+ assert.equal(emailOpenToEveryone(undefined), false);
52
+ assert.equal(emailOpenToEveryone("*@seven365.com.sg"), false);
53
+ });
54
+
55
+ it("garbage is never allowed", () => {
56
+ for (const bad of ["", null, undefined, "no-at-sign", 42]) {
57
+ assert.equal(isEmailAllowed(bad, "*"), false, String(bad));
58
+ }
59
+ });
60
+ });
61
+
62
+ const PROD = "https://account.app.iservice365.org";
63
+ const STAGING = "https://iservice365-staging-account.apptesting.work";
64
+
65
+ describe("which environment is production (positive identification only)", () => {
66
+ it("the production web domain is production", () => {
67
+ assert.equal(isProductionWebBase(PROD), true);
68
+ assert.equal(isProductionWebBase("https://app.iservice365.org"), true);
69
+ assert.equal(isProductionWebBase("https://iservice365.org/"), true);
70
+ });
71
+
72
+ it("staging, local, unset, unparsable and look-alikes are not", () => {
73
+ for (const base of [
74
+ STAGING,
75
+ "https://iservice365-staging-main.apptesting.work",
76
+ "http://localhost:3000",
77
+ "localhost",
78
+ "http:localhost:3000",
79
+ "",
80
+ "https://iservice365.org.evil.com",
81
+ "https://eviliservice365.org",
82
+ ]) {
83
+ assert.equal(isProductionWebBase(base), false, base);
84
+ }
85
+ });
86
+ });
87
+
88
+ describe("the default when EMAIL_NOTIFICATIONS_ALLOWLIST is not set", () => {
89
+ it("env set: the list wins, on production too", () => {
90
+ assert.equal(effectiveEmailAllowlist("*@example.org", PROD), "*@example.org");
91
+ assert.equal(isEmailAllowed("someone@gmail.com", "*@seven365.com.sg", PROD), false);
92
+ assert.equal(emailOpenToEveryone("*@seven365.com.sg", PROD), false);
93
+ assert.equal(isEmailAllowed("someone@gmail.com", "*", STAGING), true);
94
+ });
95
+
96
+ it("production, unset: every verified address, and email is offered to everyone", () => {
97
+ for (const unset of [undefined, "", " "]) {
98
+ assert.equal(effectiveEmailAllowlist(unset, PROD), "*");
99
+ assert.equal(isEmailAllowed("someone@gmail.com", unset, PROD), true);
100
+ assert.equal(isEmailAllowed("security@seven365.com.sg", unset, PROD), true);
101
+ assert.equal(emailOpenToEveryone(unset, PROD), true);
102
+ }
103
+ });
104
+
105
+ it("staging, unset: Seven365 addresses only, email offered only to them", () => {
106
+ assert.equal(effectiveEmailAllowlist(undefined, STAGING), DEFAULT_EMAIL_ALLOWLIST);
107
+ assert.equal(isEmailAllowed("someone@gmail.com", undefined, STAGING), false);
108
+ assert.equal(isEmailAllowed("security@seven365.com.sg", undefined, STAGING), true);
109
+ assert.equal(emailOpenToEveryone(undefined, STAGING), false);
110
+ });
111
+
112
+ it("unknown or local, unset: fails closed like staging", () => {
113
+ for (const base of ["", "http://localhost:3000", "not a url"]) {
114
+ assert.equal(isEmailAllowed("someone@gmail.com", undefined, base), false, base);
115
+ assert.equal(isEmailAllowed("security@seven365.com.sg", undefined, base), true, base);
116
+ assert.equal(emailOpenToEveryone(undefined, base), false, base);
117
+ }
118
+ });
119
+
120
+ it("garbage is never allowed, even on production", () => {
121
+ for (const bad of ["", null, undefined, "no-at-sign", 42]) {
122
+ assert.equal(isEmailAllowed(bad, undefined, PROD), false, String(bad));
123
+ }
124
+ });
125
+ });
126
+
127
+ describe("turn-off token (no sign-in, tamper-proof)", () => {
128
+ const t = offToken(U, "feedback", SECRET);
129
+
130
+ it("matches only the same person, module and secret", () => {
131
+ assert.equal(offTokenMatches(U, "feedback", t, SECRET), true);
132
+ assert.equal(offTokenMatches(U, "workOrder", t, SECRET), false, "re-aimed at another module");
133
+ assert.equal(offTokenMatches("65f1a2b3c4d5e6f708192a3c", "feedback", t, SECRET), false, "another person");
134
+ assert.equal(offTokenMatches(U, "feedback", t, "b".repeat(64)), false, "another secret");
135
+ assert.equal(offTokenMatches(U, "feedback", t.slice(0, -1) + (t.endsWith("A") ? "B" : "A"), SECRET), false);
136
+ assert.equal(offTokenMatches(U, "feedback", t, undefined), false, "no secret stored");
137
+ assert.equal(offTokenMatches(U, "feedback", "", SECRET), false);
138
+ });
139
+
140
+ it("the link carries person, module and token", () => {
141
+ const url = new URL(offLink("https://account.example", U, "feedback", SECRET));
142
+ assert.equal(url.pathname, "/api/notification-preferences/email/off");
143
+ assert.equal(url.searchParams.get("u"), U);
144
+ assert.equal(url.searchParams.get("c"), "feedback");
145
+ assert.equal(url.searchParams.get("t"), t);
146
+ });
147
+ });
148
+
149
+ describe("verification code", () => {
150
+ it("is six digits and only its hash, bound to the person, is compared", () => {
151
+ for (let i = 0; i < 50; i++) assert.match(newCode(), /^\d{6}$/);
152
+ const h = hashCode(U, "123456");
153
+ assert.equal(codeMatches(U, "123456", h), true);
154
+ assert.equal(codeMatches(U, " 123456 ", h), true);
155
+ assert.equal(codeMatches(U, "123457", h), false);
156
+ assert.equal(codeMatches("65f1a2b3c4d5e6f708192a3c", "123456", h), false);
157
+ assert.equal(codeMatches(U, "123456", ""), false);
158
+ });
159
+
160
+ it("the email says what to do in plain words", () => {
161
+ const m = verificationEmail("042917");
162
+ assert.match(m.subject, /email code/i);
163
+ assert.match(m.html, /042917/);
164
+ assert.match(m.text, /ignore this email/);
165
+ });
166
+ });
167
+
168
+ describe("the notification email", () => {
169
+ const base = {
170
+ title: "Work order <updated>",
171
+ body: 'Status is now "Done" & closed',
172
+ moduleLabel: "Work Orders",
173
+ openUrl: openLink("https://acc", { kind: "workOrder", id: "abc", site: "s1", org: "o1" }),
174
+ offUrl: "https://acc/api/notification-preferences/email/off?u=1&c=workOrder&t=x",
175
+ settingsUrl: "https://acc/notification-settings",
176
+ };
177
+
178
+ it("has the button, why, one-click turn-off and settings", () => {
179
+ const m = notificationEmail(base);
180
+ assert.equal(m.subject, base.title);
181
+ assert.match(m.html, /Open in iService365/);
182
+ assert.match(m.html, /Why am I getting this\?/);
183
+ assert.match(m.html, /Turn off email for Work Orders/);
184
+ assert.match(m.html, /Notification settings/);
185
+ assert.match(m.text, /notifications\/open\?kind=workOrder&id=abc&site=s1&org=o1/);
186
+ assert.doesNotMatch(m.html, /hold|for up to an hour/);
187
+ });
188
+
189
+ it("escapes what a user typed", () => {
190
+ const m = notificationEmail(base);
191
+ assert.doesNotMatch(m.html, /<updated>/);
192
+ assert.match(m.html, /&lt;updated&gt;/);
193
+ assert.match(m.html, /&quot;Done&quot; &amp; closed/);
194
+ assert.equal(escapeHtml(`<a href="x">'`), "&lt;a href=&quot;x&quot;&gt;&#39;");
195
+ });
196
+
197
+ it("the last one this hour says the rest are held", () => {
198
+ const m = notificationEmail({ ...base, lastThisHour: true });
199
+ assert.match(m.text, new RegExp(`${EMAIL_PER_MODULE_PER_HOUR} Work Orders emails in the last hour`));
200
+ assert.match(m.text, /still arrives in the app/);
201
+ });
202
+
203
+ it("the turn-off page is plain", () => {
204
+ assert.match(offPage(true, "Feedback", "https://acc/notification-settings"), /Email for Feedback is off/);
205
+ assert.match(offPage(false, "Other", "x"), /This link does not work/);
206
+ });
207
+ });
@@ -0,0 +1,220 @@
1
+ import assert from "node:assert/strict";
2
+ import { test } from "node:test";
3
+
4
+ import {
5
+ DEFAULT_PLAN_FRAME,
6
+ fromPlan,
7
+ legacyFromRmf,
8
+ mergeLegacyIntoRmf,
9
+ rmfFromFleetCore,
10
+ rmfProblem,
11
+ rmfSummary,
12
+ toBuildingYaml,
13
+ toNavGraphs,
14
+ toPlan,
15
+ } from "./.build/utils/rmf-building.util.mjs";
16
+ import { rmfBuildingSchema, buildingMapBodySchema } from "./.build/models/robot-building-map.model.mjs";
17
+
18
+ // A BuildingMap.msg as the fleet server returns it: two levels, walls, a hinged
19
+ // and a double-sliding door, one nav graph with a charger and a bidirectional +
20
+ // a one-way lane (speed limit, mutex), and a lift with one cabin door.
21
+ const MSG = {
22
+ name: "tower",
23
+ levels: [
24
+ {
25
+ name: "L1",
26
+ elevation: 0,
27
+ doors: [
28
+ { name: "main", v1_x: 4, v1_y: -1, v2_x: 6, v2_y: -1, door_type: 6, motion_range: Math.PI / 2, motion_direction: -1 },
29
+ { name: "slide", v1_x: 10, v1_y: -5, v2_x: 10, v2_y: -7, door_type: 2 },
30
+ ],
31
+ nav_graphs: [
32
+ {
33
+ name: "0",
34
+ vertices: [
35
+ { x: 5, y: 0, name: "entry", params: [{ name: "is_holding_point" }] },
36
+ { x: 5, y: -4, name: "hall", params: [] },
37
+ { x: 12, y: -4, name: "dock", params: [{ name: "is_charger", type: 4, value_bool: true }, { name: "dock_name", type: 1, value_string: "dock1" }] },
38
+ ],
39
+ edges: [
40
+ { v1_idx: 0, v2_idx: 1, edge_type: 0, params: [] },
41
+ { v1_idx: 1, v2_idx: 2, edge_type: 1, params: [{ name: "speed_limit", type: 3, value_float: 0.5 }, { name: "mutex", type: 1, value_string: "corridor" }] },
42
+ ],
43
+ },
44
+ ],
45
+ wall_graph: {
46
+ name: "WallGraph",
47
+ vertices: [{ x: 0, y: 0 }, { x: 20, y: 0 }, { x: 20, y: -10 }, { x: 0, y: -10 }],
48
+ edges: [{ v1_idx: 0, v2_idx: 1 }, { v1_idx: 1, v2_idx: 2 }, { v1_idx: 2, v2_idx: 3 }, { v1_idx: 3, v2_idx: 0 }],
49
+ },
50
+ },
51
+ { name: "L2", elevation: 4, doors: [], nav_graphs: [{ name: "0", vertices: [{ x: 1, y: -1, name: "top" }, { x: 3, y: -1, name: "" }], edges: [{ v1_idx: 0, v2_idx: 1, edge_type: 0 }] }], wall_graph: { vertices: [], edges: [] } },
52
+ ],
53
+ lifts: [
54
+ {
55
+ name: "Lift1",
56
+ levels: ["L1", "L2"],
57
+ ref_x: 15,
58
+ ref_y: -8,
59
+ ref_yaw: 0,
60
+ width: 2,
61
+ depth: 2,
62
+ doors: [{ name: "cabin", v1_x: 16, v1_y: -8.6, v2_x: 16, v2_y: -7.4, door_type: 2 }],
63
+ },
64
+ ],
65
+ };
66
+
67
+ test("import: levels, walls, door types, lanes + params, graphs, lift cabin doors", () => {
68
+ const rmf = rmfFromFleetCore(MSG);
69
+ assert.equal(rmf.source, "fleet-core");
70
+ assert.equal(rmf.levels.length, 2);
71
+ const l1 = rmf.levels[0];
72
+ assert.equal(l1.floorNo, 1);
73
+ assert.equal(l1.walls.length, 4);
74
+ assert.deepEqual(l1.doors.map((d) => d.type), ["double_hinged", "double_sliding"]);
75
+ assert.equal(l1.doors[0].motionDegrees, 90);
76
+ assert.equal(l1.doors[0].motionDirection, -1);
77
+ assert.equal(l1.lanes.length, 2);
78
+ assert.equal(l1.lanes[0].bidirectional, true);
79
+ assert.deepEqual({ b: l1.lanes[1].bidirectional, s: l1.lanes[1].speedLimit, m: l1.lanes[1].mutex }, { b: false, s: 0.5, m: "corridor" });
80
+ const dock = l1.vertices.find((v) => v.name === "dock");
81
+ assert.deepEqual(dock.params, { is_charger: true, dock_name: "dock1" });
82
+ assert.deepEqual(l1.vertices.find((v) => v.name === "entry").params, { is_holding_point: true });
83
+ assert.deepEqual(rmf.graphs, [{ idx: 0, name: "Graph 0", brands: ["fleet-core"] }]);
84
+ const lift = rmf.lifts[0];
85
+ assert.equal(lift.doors.length, 1);
86
+ assert.deepEqual({ x: lift.doors[0].x, y: lift.doors[0].y, w: lift.doors[0].widthM }, { x: 1, y: 0, w: 1.2 });
87
+ assert.deepEqual(lift.levelDoors, [{ level: "L1", doors: ["cabin"] }, { level: "L2", doors: ["cabin"] }]);
88
+ assert.equal(rmfProblem(rmf), null);
89
+ const { error } = rmfBuildingSchema.validate(rmf);
90
+ assert.equal(error, undefined, error?.message);
91
+ });
92
+
93
+ test("plan frame: the import frame is the robots' planShareOf extent; toPlan/fromPlan invert", () => {
94
+ const rmf = rmfFromFleetCore(MSG);
95
+ const f = rmf.levels[0].planFrame;
96
+ // nav vertices x 5..12, doors 4..10 -> 4..12 padded 3; y -7..0 padded 3
97
+ assert.deepEqual(f, { minX: 1, maxX: 15, minY: -10, maxY: 3 });
98
+ const p = { x: 7.5, y: -2.25 };
99
+ assert.deepEqual(fromPlan(f, toPlan(f, p)), p);
100
+ assert.deepEqual(toPlan(DEFAULT_PLAN_FRAME, { x: 10, y: -5 }), { x: 10, y: 5 });
101
+ });
102
+
103
+ test("legacy derived from rmf is valid for every existing reader", () => {
104
+ const legacy = legacyFromRmf(rmfFromFleetCore(MSG));
105
+ assert.deepEqual(legacy.doors.map((d) => d.type), ["hinged", "sliding"]);
106
+ assert.equal(legacy.levels[0].walls.length, 4);
107
+ assert.deepEqual(legacy.lifts[0].floors, [1, 2]);
108
+ const { error } = buildingMapBodySchema.validate({ name: "x", ...legacy });
109
+ assert.equal(error, undefined, error?.message);
110
+ });
111
+
112
+ test("a legacy save folds into rmf: lanes, waypoints, door motion and cabin doors survive", () => {
113
+ const rmf = rmfFromFleetCore(MSG);
114
+ const legacy = legacyFromRmf(rmf);
115
+ // The person moves one wall end, renames nothing, and adds a new door + a new lift.
116
+ legacy.levels[0].walls[0].end = { x: legacy.levels[0].walls[0].end.x - 1, y: legacy.levels[0].walls[0].end.y };
117
+ legacy.doors.push({ name: "new", floorNo: 2, type: "sliding", start: { x: 1, y: 1 }, end: { x: 2, y: 1 } });
118
+ legacy.lifts.push({ name: "Lift2", x: 30, y: 20, widthM: 2, depthM: 2, floors: [1, 2] });
119
+ const merged = mergeLegacyIntoRmf(rmf, legacy);
120
+ assert.equal(rmfProblem(merged), null);
121
+ const l1 = merged.levels[0];
122
+ assert.equal(l1.lanes.length, 2, "lanes kept");
123
+ assert.ok(l1.vertices.find((v) => v.name === "dock")?.params?.is_charger, "waypoint params kept");
124
+ assert.equal(l1.doors.find((d) => d.name === "main").type, "double_hinged", "door kept its RMF type");
125
+ assert.equal(l1.doors.find((d) => d.name === "main").motionDirection, -1);
126
+ assert.equal(merged.levels[1].doors[0].name, "new");
127
+ assert.equal(merged.lifts[0].doors[0].name, "cabin", "cabin door kept");
128
+ assert.equal(merged.lifts[1].doors.length, 1, "a new lift gets a default cabin door");
129
+ assert.deepEqual(merged.lifts[1].levelDoors.map((x) => x.level), ["L1", "L2"]);
130
+ // And it is stable: deriving again gives the same legacy walls.
131
+ const again = legacyFromRmf(merged);
132
+ assert.deepEqual(again.levels[0].walls, legacy.levels[0].walls);
133
+ const { error } = rmfBuildingSchema.validate(merged);
134
+ assert.equal(error, undefined, error?.message);
135
+ });
136
+
137
+ test("a door that changed kind drops its old RMF type; a removed wall's plain vertex is pruned", () => {
138
+ const rmf = rmfFromFleetCore(MSG);
139
+ const legacy = legacyFromRmf(rmf);
140
+ legacy.doors[0].type = "sliding";
141
+ legacy.levels[0].walls = legacy.levels[0].walls.slice(1);
142
+ const merged = mergeLegacyIntoRmf(rmf, legacy);
143
+ assert.equal(merged.levels[0].doors[0].type, "sliding");
144
+ assert.equal(merged.levels[0].walls.length, 3);
145
+ assert.equal(rmfProblem(merged), null);
146
+ });
147
+
148
+ test("a map drawn natively exports: default frame, y flipped up", () => {
149
+ const rmf = mergeLegacyIntoRmf(null, {
150
+ levels: [{ floorNo: 1, walls: [{ start: { x: 0, y: 0 }, end: { x: 10, y: 0 } }], zones: [] }],
151
+ doors: [],
152
+ lifts: [{ name: "L", x: 5, y: 5, widthM: 2, depthM: 2, floors: [1, 2] }],
153
+ });
154
+ assert.deepEqual(rmf.levels[0].planFrame, DEFAULT_PLAN_FRAME);
155
+ assert.deepEqual(rmf.levels[0].vertices.map((v) => [v.x, v.y]), [[0, 0], [10, 0]]);
156
+ assert.deepEqual([rmf.lifts[0].x, rmf.lifts[0].y], [5, -5]);
157
+ assert.equal(rmf.levels.length, 2, "a floor served only by a lift becomes a level");
158
+ });
159
+
160
+ test("references are checked", () => {
161
+ const rmf = rmfFromFleetCore(MSG);
162
+ rmf.levels[0].lanes.push({ v1: "v1", v2: "nope", graphIdx: 0, bidirectional: true });
163
+ assert.match(rmfProblem(rmf), /does not exist/);
164
+ const r2 = rmfFromFleetCore(MSG);
165
+ r2.levels[1].doors.push({ ...r2.levels[0].doors[0], v1: r2.levels[1].vertices[0].id, v2: r2.levels[1].vertices[1].id });
166
+ assert.match(rmfProblem(r2), /unique/);
167
+ const r3 = rmfFromFleetCore(MSG);
168
+ r3.levels[0].lanes[0].graphIdx = 5;
169
+ assert.match(rmfProblem(r3), /route graph/);
170
+ const r4 = rmfFromFleetCore(MSG);
171
+ r4.lifts[0].levelDoors[0].doors = ["ghost"];
172
+ assert.match(rmfProblem(r4), /cabin door/);
173
+ });
174
+
175
+ test("building.yaml export: cartesian metres, [type, value] params, lifts with level_doors", () => {
176
+ const y = JSON.parse(toBuildingYaml("tower", rmfFromFleetCore(MSG)));
177
+ assert.equal(y.coordinate_system, "cartesian_meters");
178
+ const l1 = y.levels.L1;
179
+ const dock = l1.vertices.find((v) => v[3] === "dock");
180
+ assert.deepEqual(dock[4], { is_charger: [4, true], dock_name: [1, "dock1"] });
181
+ assert.equal(l1.walls.length, 4);
182
+ assert.deepEqual(l1.doors[0][2].type, [1, "double_hinged"]);
183
+ assert.deepEqual(l1.lanes[1][2].speed_limit, [3, 0.5]);
184
+ assert.deepEqual(l1.lanes[0][2].graph_idx, [2, 0]);
185
+ assert.deepEqual(y.lifts.Lift1.level_doors, { L1: ["cabin"], L2: ["cabin"] });
186
+ assert.equal(y.lifts.Lift1.doors.cabin.door_type, 2);
187
+ assert.equal(y.lifts.Lift1.lowest_floor, "L1");
188
+ assert.equal(y.lifts.Lift1.highest_floor, "L2");
189
+ });
190
+
191
+ test("nav graph export: bidirectional split, dock/undock, door_name on a crossing lane, lift on a cabin vertex", () => {
192
+ const rmf = rmfFromFleetCore(MSG);
193
+ // A lane through the "main" door (4..6 at y=-1) and a vertex inside Lift1's cabin (15,-8 +-1).
194
+ const l1 = rmf.levels[0];
195
+ l1.vertices.push({ id: "vx1", x: 5, y: 2 }, { id: "vx2", x: 15, y: -8, name: "lift_stop" });
196
+ l1.lanes.push({ v1: "vx1", v2: l1.vertices.find((v) => v.name === "hall").id, graphIdx: 0, bidirectional: false });
197
+ l1.lanes.push({ v1: l1.vertices.find((v) => v.name === "dock").id, v2: "vx2", graphIdx: 0, bidirectional: true });
198
+ const g = JSON.parse(toNavGraphs("tower", rmf)[0]);
199
+ const L1 = g.levels.L1;
200
+ // entry<->hall bidirectional = 2 lanes; hall->dock one way; vx1->hall one way (crosses the door); dock<->vx2 = 2 lanes
201
+ assert.equal(L1.lanes.length, 6);
202
+ const name = (i) => L1.vertices[i][2].name;
203
+ const hallDock = L1.lanes.find((l) => name(l[0]) === "hall" && name(l[1]) === "dock");
204
+ assert.deepEqual(hallDock[2], { speed_limit: 0.5, mutex: "corridor", dock_name: "dock1" });
205
+ const fromDock = L1.lanes.find((l) => name(l[0]) === "dock" && name(l[1]) === "lift_stop");
206
+ assert.equal(fromDock[2].undock_name, "dock1");
207
+ const toDock = L1.lanes.find((l) => name(l[0]) === "lift_stop" && name(l[1]) === "dock");
208
+ assert.equal(toDock[2].dock_name, "dock1");
209
+ const throughDoor = L1.lanes.find((l) => L1.vertices[l[0]][1] === 2);
210
+ assert.equal(throughDoor[2].door_name, "main");
211
+ assert.equal(L1.vertices.find((v) => v[2].name === "lift_stop")[2].lift, "Lift1");
212
+ assert.deepEqual(g.lifts.Lift1, { position: [15, -8, 0], dims: [2, 2] });
213
+ assert.deepEqual(g.doors.main.map, "L1");
214
+ assert.equal(toNavGraphs("tower", { ...rmf, levels: rmf.levels.map((l) => ({ ...l, lanes: [] })) })[0], undefined, "empty graphs are skipped");
215
+ });
216
+
217
+ test("summary counts", () => {
218
+ assert.deepEqual(rmfSummary(rmfFromFleetCore(MSG)), { source: "fleet-core", levels: 2, lanes: 3, waypoints: 4, doors: 2, lifts: 1, graphs: 1 });
219
+ assert.equal(rmfSummary(null), null);
220
+ });
@@ -0,0 +1,110 @@
1
+ import assert from "node:assert/strict";
2
+ import crypto from "node:crypto";
3
+ import { test } from "node:test";
4
+
5
+ import {
6
+ ROBOT_CREDENTIALS_ENV,
7
+ RobotCredentialsError,
8
+ decryptCredential,
9
+ encryptCredential,
10
+ encryptedPairUpdate,
11
+ isEncryptedCredential,
12
+ robotCloudCredentials,
13
+ robotCredentialsKey,
14
+ } from "./.build/utils/robot-credentials.util.mjs";
15
+ import { adapterForRobot, clearRobotBrands, registerRobotBrand } from "./.build/utils/robot-adapter.util.mjs";
16
+
17
+ const HEX = crypto.randomBytes(32).toString("hex");
18
+ const B64 = crypto.randomBytes(32).toString("base64");
19
+
20
+ function withKey(value, fn) {
21
+ const before = process.env[ROBOT_CREDENTIALS_ENV];
22
+ if (value === undefined) delete process.env[ROBOT_CREDENTIALS_ENV];
23
+ else process.env[ROBOT_CREDENTIALS_ENV] = value;
24
+ try {
25
+ return fn();
26
+ } finally {
27
+ if (before === undefined) delete process.env[ROBOT_CREDENTIALS_ENV];
28
+ else process.env[ROBOT_CREDENTIALS_ENV] = before;
29
+ }
30
+ }
31
+
32
+ test("key: 64 hex or base64 of 32 bytes; anything else counts as no key", () => {
33
+ assert.equal(robotCredentialsKey({ [ROBOT_CREDENTIALS_ENV]: HEX }).length, 32);
34
+ assert.equal(robotCredentialsKey({ [ROBOT_CREDENTIALS_ENV]: B64 }).length, 32);
35
+ assert.equal(robotCredentialsKey({ [ROBOT_CREDENTIALS_ENV]: "" }), null);
36
+ assert.equal(robotCredentialsKey({ [ROBOT_CREDENTIALS_ENV]: "short" }), null);
37
+ assert.equal(robotCredentialsKey({ [ROBOT_CREDENTIALS_ENV]: crypto.randomBytes(16).toString("hex") }), null);
38
+ assert.equal(robotCredentialsKey({}), null);
39
+ });
40
+
41
+ test("roundtrip: encrypted value is prefixed, random per write, and decrypts", () => {
42
+ const key = Buffer.from(HEX, "hex");
43
+ const a = encryptCredential("app-key-123", "appKey", key);
44
+ const b = encryptCredential("app-key-123", "appKey", key);
45
+ assert.ok(isEncryptedCredential(a));
46
+ assert.notEqual(a, b, "fresh IV every time");
47
+ assert.equal(a.includes("app-key-123"), false);
48
+ assert.equal(decryptCredential(a, "appKey", key), "app-key-123");
49
+ assert.equal(decryptCredential(b, "appKey", key), "app-key-123");
50
+ assert.equal(encryptCredential(a, "appKey", key), a, "never double-encrypted");
51
+ });
52
+
53
+ test("tamper detection: a changed byte, the wrong field, or the wrong key all refuse", () => {
54
+ const key = Buffer.from(HEX, "hex");
55
+ const enc = encryptCredential("secret-token", "appToken", key);
56
+ const [pre, iv, tag, ct] = enc.split(":");
57
+ const flipped = Buffer.from(ct, "base64url");
58
+ flipped[0] ^= 1;
59
+ assert.throws(() => decryptCredential(`${pre}:${iv}:${tag}:${flipped.toString("base64url")}`, "appToken", key), RobotCredentialsError);
60
+ assert.throws(() => decryptCredential(enc, "appKey", key), RobotCredentialsError, "field is bound as AAD");
61
+ assert.throws(() => decryptCredential(enc, "appToken", crypto.randomBytes(32)), RobotCredentialsError);
62
+ assert.throws(() => decryptCredential("rc1:broken", "appToken", key), RobotCredentialsError);
63
+ });
64
+
65
+ test("missing key: plain passes through both ways; encrypted fails closed by name", () => {
66
+ const key = Buffer.from(HEX, "hex");
67
+ const enc = encryptCredential("k", "appKey", key);
68
+ assert.equal(encryptCredential("plain", "appKey", null), "plain");
69
+ assert.equal(decryptCredential("plain", "appKey", null), "plain");
70
+ assert.throws(() => decryptCredential(enc, "appKey", null), /no key/);
71
+ });
72
+
73
+ test("mixed: plain and encrypted pairs both reach the adapter as plain", () => {
74
+ clearRobotBrands();
75
+ const seen = [];
76
+ registerRobotBrand({
77
+ brand: "t-brand",
78
+ displayName: "T",
79
+ capabilities: {},
80
+ create: (c) => (seen.push(c), { listRobots: async () => [] }),
81
+ });
82
+ withKey(HEX, () => {
83
+ const key = robotCredentialsKey();
84
+ adapterForRobot({ brand: "t-brand", appKey: "plain-k", appToken: "plain-t" });
85
+ adapterForRobot({ brand: "t-brand", appKey: encryptCredential("enc-k", "appKey", key), appToken: encryptCredential("enc-t", "appToken", key) });
86
+ adapterForRobot({ brand: "t-brand", appKey: encryptCredential("half-k", "appKey", key), appToken: "half-t" });
87
+ });
88
+ assert.deepEqual(seen, [
89
+ { appid: "plain-k", secret: "plain-t" },
90
+ { appid: "enc-k", secret: "enc-t" },
91
+ { appid: "half-k", secret: "half-t" },
92
+ ]);
93
+ // Without the key an encrypted robot is refused, never handed an empty or ciphertext credential.
94
+ const enc = withKey(HEX, () => ({ brand: "t-brand", appKey: encryptCredential("x", "appKey"), appToken: encryptCredential("y", "appToken") }));
95
+ withKey(undefined, () => assert.throws(() => adapterForRobot(enc), /no key to read them/));
96
+ assert.equal(seen.length, 3);
97
+ clearRobotBrands();
98
+ });
99
+
100
+ test("encryptedPairUpdate: only plain, non-empty fields; nothing without a key", () => {
101
+ const key = Buffer.from(HEX, "hex");
102
+ assert.equal(encryptedPairUpdate({ appKey: "a", appToken: "b" }, null), null);
103
+ const up = encryptedPairUpdate({ appKey: "a", appToken: "b" }, key);
104
+ assert.ok(isEncryptedCredential(up.appKey) && isEncryptedCredential(up.appToken));
105
+ assert.deepEqual(Object.keys(encryptedPairUpdate({ appKey: up.appKey, appToken: "b" }, key)), ["appToken"]);
106
+ assert.equal(encryptedPairUpdate({ appKey: up.appKey, appToken: up.appToken }, key), null);
107
+ assert.equal(encryptedPairUpdate({ appKey: "", appToken: null }, key), null);
108
+ const creds = withKey(HEX, () => robotCloudCredentials({ appKey: up.appKey, appToken: " b " }));
109
+ assert.deepEqual(creds, { appid: "a", secret: "b" });
110
+ });
@@ -43,8 +43,8 @@ test("the category delivers in-app and push, and is switchable", () => {
43
43
  assert.equal(platform.rendered, true);
44
44
  assert.equal(categorySupportsChannel("platform", "inApp"), true);
45
45
  assert.equal(categorySupportsChannel("platform", "push"), true);
46
- // No mailer recipient for a staff list, so no dead email switch.
47
- assert.equal(categorySupportsChannel("platform", "email"), false);
46
+ // Staff can opt in to email too (2026-09-25): opt-in, verified-only.
47
+ assert.equal(categorySupportsChannel("platform", "email"), true);
48
48
  });
49
49
 
50
50
  test("the stored module tag is one core accepts", () => {