@astrofoundry/pi-astro 0.40.44 → 0.40.45
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
import type { ArcaneReport } from "./daily-report.ts";
|
|
3
3
|
import type { ToolsReport } from "./tools-report.ts";
|
|
4
|
-
import { agoSeconds, arcaneSummary, backupStatus, dnsStatus, macosStatus, edgeStatus, identityStatus, pomeriumButtonId, wazuhRelease, inferenceStatus, mediaStatus, networkStatus, pendingPackageLines, problemText, proxmoxStatus, summaryText, technitiumPlan, toolsSummary, updatesStatus } from "./daily-run.ts";
|
|
4
|
+
import { agoSeconds, arcaneSummary, guestOwner, backupStatus, dnsStatus, macosStatus, edgeStatus, identityStatus, pomeriumButtonId, wazuhRelease, inferenceStatus, mediaStatus, networkStatus, pendingPackageLines, problemText, proxmoxStatus, summaryText, technitiumPlan, toolsSummary, updatesStatus } from "./daily-run.ts";
|
|
5
5
|
|
|
6
6
|
const EDGE = `nginx active
|
|
7
7
|
wg-quick@wg0 active
|
|
@@ -88,10 +88,14 @@ describe("morning status lines", () => {
|
|
|
88
88
|
const wazuh = updatesStatus({ technitium2: held, synapse: "Listing..." });
|
|
89
89
|
expect(wazuh.line).toBe("2 hosts up to date after the nightly run; Wazuh 4.14.10 is out (agents held at 4.14.9)");
|
|
90
90
|
expect(wazuh.problem).toMatch(/^Updates: Wazuh 4\.14\.10 is out: ask me to upgrade the manager/);
|
|
91
|
-
|
|
91
|
+
const left = updatesStatus({ arcane: vm, radius: null });
|
|
92
|
+
expect(left).toMatchObject({
|
|
92
93
|
line: "still waiting after the nightly run: arcane 1; no update list from radius; Wazuh 4.14.9 is out (agents held at 4.14.7)",
|
|
93
94
|
route: "admin",
|
|
94
95
|
});
|
|
96
|
+
expect(left.items?.map((i) => i.owner)).toEqual(["Arcane", "Network", "Security"]);
|
|
97
|
+
expect(left.items?.slice(0, 2).map((i) => i.text)).toEqual(["arcane: docker-ce did not install overnight", "no update list from radius"]);
|
|
98
|
+
expect(["dmz", "observability", "backup", "tailscale-mira (Mira)", "technitium3 (Mira)", "synapse", "hermes", "Pulsar guests"].map(guestOwner)).toEqual(["Identity", "Security", "Backup", "Network", "DNS", "DNS", "Proxmox", "Proxmox"]);
|
|
95
99
|
});
|
|
96
100
|
|
|
97
101
|
it("checks RADIUS and the Tailscale router", () => {
|
|
@@ -167,32 +171,36 @@ describe("morning status lines", () => {
|
|
|
167
171
|
});
|
|
168
172
|
|
|
169
173
|
describe("morning summary", () => {
|
|
170
|
-
it("
|
|
174
|
+
it("gives each specialist and Cortex one line: all clear, or what needs the owners there, without a mention", () => {
|
|
171
175
|
const text = summaryText({
|
|
172
176
|
date: "Fri 24 Oct",
|
|
173
177
|
guildId: "1",
|
|
174
178
|
routes: { admin: "11", media: "12" },
|
|
175
179
|
reports: [
|
|
176
180
|
{ area: "Security", line: "quiet day", needs: [], channelId: "21", messageId: "31" },
|
|
177
|
-
{ area: "
|
|
181
|
+
{ area: "Cortex tools", line: "1 updated", needs: [], channelId: "23", messageId: "33" },
|
|
182
|
+
{ area: "Arcane", line: "3 stacks updated", needs: ["stirling-pdf waits for you (major version)"], channelId: "22", messageId: "32" },
|
|
178
183
|
],
|
|
179
184
|
areas: [
|
|
180
185
|
{ area: "DNS", line: "both resolvers answer" },
|
|
181
186
|
{ area: "Backup", line: "no backup last night for identity", problem: "Backup: no Proxmox backup last night for identity", route: "admin" },
|
|
187
|
+
{ area: "macOS", line: "Cortex 26.7.2" },
|
|
188
|
+
{ area: "Updates", line: "x", problem: "Updates: arcane (docker-ce) did not install overnight", items: [{ owner: "Arcane", text: "arcane: docker-ce did not install overnight" }], route: "admin" },
|
|
182
189
|
],
|
|
183
190
|
});
|
|
184
191
|
expect(text).toBe(
|
|
185
192
|
[
|
|
186
|
-
"**Daily** · Fri 24 Oct · 🟠
|
|
187
|
-
"Security ·
|
|
188
|
-
"
|
|
189
|
-
"
|
|
190
|
-
"Backup · no backup last night for identity",
|
|
191
|
-
"
|
|
193
|
+
"**Daily** · Fri 24 Oct · 🟠 3 items need you",
|
|
194
|
+
"Security · All clear boss!",
|
|
195
|
+
"Cortex · All clear boss!",
|
|
196
|
+
"Arcane · stirling-pdf waits for you (major version) ([report](https://discord.com/channels/1/22/32)); arcane: docker-ce did not install overnight (<#11>)",
|
|
197
|
+
"Backup · no Proxmox backup last night for identity (<#11>)",
|
|
198
|
+
"Proxmox · All clear boss!",
|
|
199
|
+
"DNS · All clear boss!",
|
|
192
200
|
].join("\n"),
|
|
193
201
|
);
|
|
194
202
|
expect(text).not.toContain("<@");
|
|
195
|
-
expect(summaryText({ date: "Fri 24 Oct", guildId: "1", routes: { admin: "11", media: "12" }, reports: [], areas: [] })).toBe("**Daily** · Fri 24 Oct · 🟢
|
|
203
|
+
expect(summaryText({ date: "Fri 24 Oct", guildId: "1", routes: { admin: "11", media: "12" }, reports: [], areas: [{ area: "Media", line: "downloads running" }] })).toBe("**Daily** · Fri 24 Oct · 🟢 All clear boss!\nMedia · All clear boss!");
|
|
196
204
|
});
|
|
197
205
|
|
|
198
206
|
it("tags the owners for an area's problem in its channel", () => {
|
|
@@ -215,11 +223,11 @@ describe("report summaries", () => {
|
|
|
215
223
|
expect(toolsSummary(report, "2026-10-24", "5")).toEqual({
|
|
216
224
|
area: "Cortex tools",
|
|
217
225
|
line: "1 updated (jq 1.8.2), 1 failed (herdr), Pi 1.4.0, Node 26.1.0 wait for a button",
|
|
218
|
-
needs: ["Node 26.1.0 (major version)", "herdr automatic update failed"],
|
|
226
|
+
needs: ["Node 26.1.0 waits for its button (major version)", "Pi 1.4.0 waits for its button", "herdr automatic update failed"],
|
|
219
227
|
channelId: "5",
|
|
220
228
|
messageId: "9",
|
|
221
229
|
});
|
|
222
|
-
expect(toolsSummary(report, "2026-10-25", "5")
|
|
230
|
+
expect(toolsSummary(report, "2026-10-25", "5")).toMatchObject({ line: "no report today; the bridge log has the reason", needs: ["the Cortex Tools Report did not run today; the bridge log has the reason"] });
|
|
223
231
|
});
|
|
224
232
|
|
|
225
233
|
it("says what the Arcane report updated, rolled back, and leaves to the owner", () => {
|
|
@@ -228,7 +236,7 @@ describe("report summaries", () => {
|
|
|
228
236
|
expect(arcaneSummary(report, "2026-10-24", "6")).toEqual({
|
|
229
237
|
area: "Arcane",
|
|
230
238
|
line: "1 stack updated (media), mealie rolled back, stirling-pdf waits for you, supabase held",
|
|
231
|
-
needs: ["stirling-pdf (Upgrade carefully)", "mealie automatic update rolled back"],
|
|
239
|
+
needs: ["stirling-pdf waits for you (Upgrade carefully)", "mealie automatic update rolled back"],
|
|
232
240
|
channelId: "6",
|
|
233
241
|
messageId: "8",
|
|
234
242
|
});
|
|
@@ -12,11 +12,19 @@ export interface AreaButton {
|
|
|
12
12
|
customId: string;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
/** One thing the owners must act on, under the summary line of the specialist that owns it. */
|
|
16
|
+
export interface SummaryItem {
|
|
17
|
+
owner: string;
|
|
18
|
+
text: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
15
21
|
/** One area of the morning summary: a line, and a problem that needs an owner, if any. */
|
|
16
22
|
export interface AreaStatus {
|
|
17
23
|
area: string;
|
|
18
24
|
line: string;
|
|
19
25
|
problem?: string;
|
|
26
|
+
/** The problem split by owner, when its parts belong to different specialists' lines. */
|
|
27
|
+
items?: SummaryItem[];
|
|
20
28
|
route?: Route;
|
|
21
29
|
buttons?: AreaButton[];
|
|
22
30
|
}
|
|
@@ -151,6 +159,18 @@ export function wazuhRelease(hosts: Readonly<Record<string, string | null>>): {
|
|
|
151
159
|
return found;
|
|
152
160
|
}
|
|
153
161
|
|
|
162
|
+
/** The summary line for a guest's updates: the specialist that runs the guest, else Proxmox. */
|
|
163
|
+
export function guestOwner(name: string): string {
|
|
164
|
+
const guest = name.replace(/ \(Mira\)$/, "");
|
|
165
|
+
if (guest === "arcane") return "Arcane";
|
|
166
|
+
if (guest === "dmz" || guest === "identity") return "Identity";
|
|
167
|
+
if (guest === "observability") return "Security";
|
|
168
|
+
if (guest === "backup") return "Backup";
|
|
169
|
+
if (/^(radius|tailscale)/.test(guest)) return "Network";
|
|
170
|
+
if (/^(technitium|synapse)/.test(guest)) return "DNS";
|
|
171
|
+
return "Proxmox";
|
|
172
|
+
}
|
|
173
|
+
|
|
154
174
|
/** Each guest's and Synapse's `updates` after the 04:30 run: anything still waiting did not install and needs a look. */
|
|
155
175
|
export function updatesStatus(hosts: Readonly<Record<string, string | null>>): AreaStatus {
|
|
156
176
|
const names = Object.keys(hosts);
|
|
@@ -167,12 +187,15 @@ export function updatesStatus(hosts: Readonly<Record<string, string | null>>): A
|
|
|
167
187
|
unknown.length > 0 ? `no update list from ${unknown.join(", ")}` : null,
|
|
168
188
|
wazuh ? `Wazuh ${wazuh.to} is out (agents held at ${wazuh.from})` : null,
|
|
169
189
|
].filter(Boolean);
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
190
|
+
const packages = (h: { packages: string[] }) => `${h.packages.slice(0, 4).join(", ")}${h.packages.length > 4 ? ", ..." : ""}`;
|
|
191
|
+
const wazuhText = wazuh ? `Wazuh ${wazuh.to} is out: ask me to upgrade the manager (\`observability/compose.yaml\`, then \`deploy.sh\`), then the agents (\`scripts/wazuh-agents/deploy.sh --upgrade\`); an agent must never be newer than the manager` : null;
|
|
192
|
+
const problems = [left.length > 0 ? `${left.map((h) => `${h.name} (${packages(h)})`).join("; ")} did not install overnight` : null, unknown.length > 0 ? `no update list from ${unknown.join(", ")}` : null, wazuhText].filter(Boolean);
|
|
193
|
+
const items: SummaryItem[] = [
|
|
194
|
+
...left.map((h) => ({ owner: guestOwner(h.name), text: `${h.name}: ${packages(h)} did not install overnight` })),
|
|
195
|
+
...unknown.map((n) => ({ owner: guestOwner(n), text: `no update list from ${n}` })),
|
|
196
|
+
...(wazuhText ? [{ owner: "Security", text: wazuhText }] : []),
|
|
197
|
+
];
|
|
198
|
+
return { area: "Updates", line: parts.join("; "), ...(problems.length > 0 ? { problem: `Updates: ${problems.join("; ")}`, items, route: "admin" as const } : {}) };
|
|
176
199
|
}
|
|
177
200
|
|
|
178
201
|
/** `network pulsar radius-status` and `tailscale-status`: FreeRADIUS running, and every `tailscale*` subnet router (37 and Mira) online. */
|
|
@@ -358,7 +381,7 @@ function names(items: readonly string[]): string {
|
|
|
358
381
|
|
|
359
382
|
/** The Cortex Tools Report after its automatic updates ran: what changed, what failed, and what waits for a button. */
|
|
360
383
|
export function toolsSummary(report: ToolsReport | null, date: string, channelId: string): ReportLine {
|
|
361
|
-
if (!report || report.date !== date) return { area: "Cortex tools", line: "no report today; the bridge log has the reason", needs: [], channelId };
|
|
384
|
+
if (!report || report.date !== date) return { area: "Cortex tools", line: "no report today; the bridge log has the reason", needs: ["the Cortex Tools Report did not run today; the bridge log has the reason"], channelId };
|
|
362
385
|
const updated = report.lines.filter((l) => l.state === "updated");
|
|
363
386
|
const failed = report.lines.filter((l) => l.state === "failed");
|
|
364
387
|
const waiting = report.lines.filter((l) => (l.plan === "update" || l.plan === "button") && l.state === "offered");
|
|
@@ -370,7 +393,8 @@ export function toolsSummary(report: ToolsReport | null, date: string, channelId
|
|
|
370
393
|
manual.length > 0 ? `${manual.length} by hand` : null,
|
|
371
394
|
].filter(Boolean);
|
|
372
395
|
const needs = [
|
|
373
|
-
...report.lines.filter((l) => l.plan === "update" && l.state === "offered").map((l) => `${escapeDiscord(l.label)} ${escapeDiscord(l.latest)} (${l.major ? "major version" : "release notes"})`),
|
|
396
|
+
...report.lines.filter((l) => l.plan === "update" && l.state === "offered").map((l) => `${escapeDiscord(l.label)} ${escapeDiscord(l.latest)} waits for its button (${l.major ? "major version" : "release notes"})`),
|
|
397
|
+
...report.lines.filter((l) => l.plan === "button" && l.state === "offered").map((l) => `${escapeDiscord(l.label)} ${escapeDiscord(l.latest)} waits for its button`),
|
|
374
398
|
...failed.filter((l) => l.plan === "auto").map((l) => `${escapeDiscord(l.label)} automatic update failed`),
|
|
375
399
|
];
|
|
376
400
|
return { area: "Cortex tools", line: parts.join(", ") || "everything up to date", needs, channelId, ...(report.messages[0] ? { messageId: report.messages[0].id } : {}) };
|
|
@@ -378,7 +402,7 @@ export function toolsSummary(report: ToolsReport | null, date: string, channelId
|
|
|
378
402
|
|
|
379
403
|
/** The Arcane Daily Report after its automatic updates and checks: updated, rolled back, waiting for the owner, held. */
|
|
380
404
|
export function arcaneSummary(report: ArcaneReport | null, date: string, channelId: string): ReportLine {
|
|
381
|
-
if (!report || report.date !== date) return { area: "Arcane", line: "no report today; the bridge log has the reason", needs: [], channelId };
|
|
405
|
+
if (!report || report.date !== date) return { area: "Arcane", line: "no report today; the bridge log has the reason", needs: ["the Arcane Daily Report did not run today; the bridge log has the reason"], channelId };
|
|
382
406
|
const by = (pick: (s: ArcaneReport["stacks"][number]) => boolean) => report.stacks.filter(pick).map((s) => s.stack);
|
|
383
407
|
const updated = by((s) => s.state === "updated");
|
|
384
408
|
const rolled = by((s) => s.state === "rolled back");
|
|
@@ -393,7 +417,7 @@ export function arcaneSummary(report: ArcaneReport | null, date: string, channel
|
|
|
393
417
|
held.length > 0 ? `${names(held)} held` : null,
|
|
394
418
|
].filter(Boolean);
|
|
395
419
|
const needs = [
|
|
396
|
-
...waiting.map((s) => `${escapeDiscord(s.stack)} (${s.plan === "careful" ? "Upgrade carefully" : "major version"})`),
|
|
420
|
+
...waiting.map((s) => `${escapeDiscord(s.stack)} waits for you (${s.plan === "careful" ? "Upgrade carefully" : "major version"})`),
|
|
397
421
|
...report.stacks.filter((s) => s.plan === "auto" && (s.state === "rolled back" || s.state === "failed")).map((s) => `${escapeDiscord(s.stack)} automatic update ${s.state}`),
|
|
398
422
|
];
|
|
399
423
|
return { area: "Arcane", line: parts.join(", ") || "no updates", needs, channelId, ...(report.messages[0] ? { messageId: report.messages[0].id } : {}) };
|
|
@@ -412,16 +436,36 @@ function link(guildId: string, channelId: string, messageId: string): string {
|
|
|
412
436
|
return `https://discord.com/channels/${guildId}/${channelId}/${messageId}`;
|
|
413
437
|
}
|
|
414
438
|
|
|
415
|
-
/**
|
|
439
|
+
/** Reports and areas whose summary line is another specialist's, or Cortex for this host's own tools and macOS. */
|
|
440
|
+
const AREA_OWNER: Readonly<Record<string, string>> = { "Security (weekly)": "Security", "Cortex tools": "Cortex", macOS: "Cortex", Updates: "Proxmox" };
|
|
441
|
+
|
|
442
|
+
/** The summary lines in this order; any other owner follows them. */
|
|
443
|
+
const OWNER_ORDER = ["Security", "Cortex", "Arcane", "Backup", "Edge", "Proxmox", "Network", "Identity", "DNS", "Inference", "Media"];
|
|
444
|
+
|
|
445
|
+
const ALL_CLEAR = "All clear boss!";
|
|
446
|
+
|
|
447
|
+
function ownerOf(area: string): string {
|
|
448
|
+
return AREA_OWNER[area] ?? area;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/** The #daily message: one line per specialist and Cortex, either all clear or what needs the owners there, with no mention. */
|
|
416
452
|
export function summaryText(s: Summary): string {
|
|
417
|
-
const
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
const
|
|
424
|
-
|
|
453
|
+
const lines = new Map<string, string[]>();
|
|
454
|
+
const add = (owner: string, items: readonly string[]) => lines.set(owner, [...(lines.get(owner) ?? []), ...items]);
|
|
455
|
+
for (const r of s.reports) {
|
|
456
|
+
const where = r.channelId && r.messageId ? ` ([report](${link(s.guildId, r.channelId, r.messageId)}))` : r.channelId ? ` (<#${r.channelId}>)` : "";
|
|
457
|
+
add(ownerOf(r.area), r.needs.map((n) => `${n}${where}`));
|
|
458
|
+
}
|
|
459
|
+
for (const a of s.areas) {
|
|
460
|
+
const where = ` (<#${s.routes[a.route ?? "admin"]}>)`;
|
|
461
|
+
add(ownerOf(a.area), []);
|
|
462
|
+
for (const item of a.items ?? (a.problem ? [{ owner: ownerOf(a.area), text: a.problem.replace(`${a.area}: `, "") }] : [])) add(item.owner, [`${escapeDiscord(item.text)}${where}`]);
|
|
463
|
+
}
|
|
464
|
+
const count = [...lines.values()].reduce((n, items) => n + items.length, 0);
|
|
465
|
+
const head = `**Daily** · ${s.date} · ${count === 0 ? `🟢 ${ALL_CLEAR}` : `🟠 ${count} item${count === 1 ? " needs" : "s need"} you`}`;
|
|
466
|
+
const rank = (owner: string) => (OWNER_ORDER.includes(owner) ? OWNER_ORDER.indexOf(owner) : OWNER_ORDER.length);
|
|
467
|
+
const owners = [...lines.keys()].sort((x, y) => rank(x) - rank(y));
|
|
468
|
+
return [head, ...owners.map((o) => `${o} · ${lines.get(o)?.join("; ") || ALL_CLEAR}`)].join("\n");
|
|
425
469
|
}
|
|
426
470
|
|
|
427
471
|
/** Areas read by a specialist of another name, or by none: Cortex's macOS is this host's own. */
|
|
@@ -585,20 +585,21 @@ class Bridge {
|
|
|
585
585
|
const name: ReportName = monday ? "security-weekly" : "security";
|
|
586
586
|
const posted = done(name) ? undefined : await (monday ? this.security.weeklyReport(securitySchedule, date) : this.security.dailyReport(securitySchedule, date)).catch((err) => log(`daily ${date}: security report failed: ${err instanceof Error ? err.message : String(err)}`));
|
|
587
587
|
const area = monday ? "Security (weekly)" : "Security";
|
|
588
|
-
reports.push(posted ? { area, line: posted.headline, needs: posted.tagged ? [
|
|
588
|
+
reports.push(posted ? { area, line: posted.headline, needs: posted.tagged ? [posted.headline] : [], channelId: securitySchedule.channelId, messageId: posted.messageId } : { area, line: done(name) ? "already posted today" : "the report failed; the bridge log has the reason", needs: done(name) ? [] : ["the security report failed; the bridge log has the reason"], channelId: securitySchedule.channelId });
|
|
589
589
|
}
|
|
590
590
|
const tools = reportSchedule(this.config, "tools");
|
|
591
591
|
if (tools && !this.stopping) {
|
|
592
592
|
if (!done("tools")) await this.toolsReport(tools, date).catch((err) => log(`daily ${date}: tools report failed: ${err instanceof Error ? err.message : String(err)}`));
|
|
593
|
-
reports.push(toolsSummary(readPostedReport(), date, tools.channelId));
|
|
594
593
|
}
|
|
595
594
|
const arcane = reportSchedule(this.config, "arcane");
|
|
596
595
|
if (arcane && !this.stopping) {
|
|
597
596
|
if (!done("arcane")) await this.arcaneReport(arcane, date).catch((err) => log(`daily ${date}: arcane report failed: ${err instanceof Error ? err.message : String(err)}`));
|
|
598
|
-
reports.push(arcaneSummary(readPostedArcane(), date, arcane.channelId));
|
|
599
597
|
}
|
|
600
598
|
if (this.stopping) return;
|
|
601
599
|
const areas = await this.collectAreas();
|
|
600
|
+
// Read only now: a button pressed while the areas were checked has changed what still waits.
|
|
601
|
+
if (tools) reports.push(toolsSummary(readPostedReport(), date, tools.channelId));
|
|
602
|
+
if (arcane) reports.push(arcaneSummary(readPostedArcane(), date, arcane.channelId));
|
|
602
603
|
const routes = this.routes();
|
|
603
604
|
const owners = this.config.owners;
|
|
604
605
|
for (const a of areas.filter((x) => x.problem)) {
|