@astrofoundry/pi-astro 0.40.76 → 0.40.78
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/extensions/astro-discord/arcane-watch.test.ts +3 -3
- package/extensions/astro-discord/arcane-watch.ts +3 -3
- package/extensions/astro-discord/daily-report.test.ts +14 -14
- package/extensions/astro-discord/daily-report.ts +20 -20
- package/extensions/astro-discord/daily-run.test.ts +7 -7
- package/extensions/astro-discord/daily-run.ts +9 -9
- package/extensions/astro-discord/index.ts +7 -7
- package/extensions/astro-discord/security-monitor.test.ts +8 -8
- package/extensions/astro-discord/security-monitor.ts +15 -15
- package/extensions/astro-discord/security.test.ts +40 -40
- package/extensions/astro-discord/security.ts +39 -39
- package/extensions/astro-discord/supervise.test.ts +1 -1
- package/extensions/astro-discord/supervise.ts +2 -2
- package/extensions/astro-discord/tools-report.test.ts +6 -6
- package/extensions/astro-discord/tools-report.ts +12 -12
- package/package.json +1 -1
- package/skills/arcane/SKILL.md +2 -2
- package/specialists/entry/remote/spc-arcane-op.py +3 -3
- package/specialists/lib/arcane-host.test.ts +4 -0
- package/specialists/lib/arcane-host.ts +2 -2
|
@@ -145,10 +145,10 @@ describe("container watch texts", () => {
|
|
|
145
145
|
it("tags the owners and says what happened", () => {
|
|
146
146
|
const e = { name: "syncthing", project: "syncthing", restarts: [iso(T0), iso(T0 + 5 * MIN), iso(T0 + 10 * MIN)] };
|
|
147
147
|
expect(escalationText(e, [OWNER], TZ)).toBe(
|
|
148
|
-
`🔁 **Container restarting** · syncthing · 3 restarts in 24 h, last 22 Oct 10:10 CEST\nAuto-heal or Docker restarted it each time. The arcane specialist investigates in the thread
|
|
148
|
+
`🔁 **Container restarting** · syncthing · 3 restarts in 24 h, last 22 Oct 10:10 CEST\nAuto-heal or Docker restarted it each time. The arcane specialist investigates read-only in the thread.\n<@${OWNER}>`,
|
|
149
149
|
);
|
|
150
150
|
expect(unhealthyText({ name: "worker", project: "grimoire", since: iso(T0), newImage: true, problem: "unhealthy" }, [OWNER], TZ, T0 + 7 * MIN)).toBe(
|
|
151
|
-
`⚠️ **Container unhealthy after a redeploy** · worker (stack grimoire) · recreated 22 Oct 10:00 CEST with a new image, still unhealthy 7 min later\nNo stack-update or other specialist operation explains
|
|
151
|
+
`⚠️ **Container unhealthy after a redeploy** · worker (stack grimoire) · recreated 22 Oct 10:00 CEST with a new image, still unhealthy 7 min later\nNo stack-update or other specialist operation explains it; ask the arcane specialist here.\n<@${OWNER}>`,
|
|
152
152
|
);
|
|
153
153
|
});
|
|
154
154
|
|
|
@@ -271,7 +271,7 @@ describe("container watch monitor", () => {
|
|
|
271
271
|
h.answer.next = () => "not json";
|
|
272
272
|
for (let i = 0; i < 7; i++) await h.watch.poll(SCHEDULE);
|
|
273
273
|
expect(h.messages).toHaveLength(1);
|
|
274
|
-
expect(h.messages[0].message.content).toContain("⚠️ **Container checks failing:**
|
|
274
|
+
expect(h.messages[0].message.content).toContain("⚠️ **Container checks failing:** Arcane's containers unreadable for 30 min");
|
|
275
275
|
h.answer.next = () => JSON.stringify({ containers: [ct()] });
|
|
276
276
|
await h.watch.poll(SCHEDULE);
|
|
277
277
|
expect(h.messages[1].message.content).toBe("✅ Container checks work again.");
|
|
@@ -213,7 +213,7 @@ export function escalationText(e: Escalation, owners: readonly string[], timeZon
|
|
|
213
213
|
const last = e.restarts[e.restarts.length - 1];
|
|
214
214
|
return [
|
|
215
215
|
`🔁 **Container restarting** · ${where(e.name, e.project)} · ${e.restarts.length} restarts in 24 h, last ${clockText(last, timeZone)}`,
|
|
216
|
-
"Auto-heal or Docker restarted it each time. The arcane specialist investigates in the thread
|
|
216
|
+
"Auto-heal or Docker restarted it each time. The arcane specialist investigates read-only in the thread.",
|
|
217
217
|
mention(owners),
|
|
218
218
|
].join("\n");
|
|
219
219
|
}
|
|
@@ -222,13 +222,13 @@ export function unhealthyText(u: Unhealthy, owners: readonly string[], timeZone:
|
|
|
222
222
|
const minutes = Math.round((now - Date.parse(u.since)) / MINUTE);
|
|
223
223
|
return [
|
|
224
224
|
`⚠️ **Container ${u.problem} after a redeploy** · ${where(u.name, u.project)} · recreated ${clockText(u.since, timeZone)}${u.newImage ? " with a new image" : ""}, still ${u.problem} ${minutes} min later`,
|
|
225
|
-
"No stack-update or other specialist operation explains
|
|
225
|
+
"No stack-update or other specialist operation explains it; ask the arcane specialist here.",
|
|
226
226
|
mention(owners),
|
|
227
227
|
].join("\n");
|
|
228
228
|
}
|
|
229
229
|
|
|
230
230
|
export function watchFailingText(minutes: number, reason: string, owners: readonly string[]): string {
|
|
231
|
-
return `⚠️ **Container checks failing:**
|
|
231
|
+
return `⚠️ **Container checks failing:** Arcane's containers unreadable for ${minutes} min (${escapeDiscord(reason.slice(0, 200))}). Restarts and redeploys unchecked meanwhile; details in the bridge log on Cortex.\n${mention(owners)}`;
|
|
232
232
|
}
|
|
233
233
|
|
|
234
234
|
export const WATCH_RECOVERED_TEXT = "✅ Container checks work again.";
|
|
@@ -109,7 +109,7 @@ describe("Arcane Daily Report layout", () => {
|
|
|
109
109
|
["gotenberg", "Bigcapital needs Gotenberg 7", false],
|
|
110
110
|
["proxy", "wait for the next bundle", false],
|
|
111
111
|
]);
|
|
112
|
-
expect(serviceText(stack?.lines[0] as ServiceLine)).toBe("• gotenberg: 7.10.2,
|
|
112
|
+
expect(serviceText(stack?.lines[0] as ServiceLine)).toBe("• gotenberg: 7.10.2, major 8 available (tag change by hand; Update skips it)\n-# ⏸ held: Bigcapital needs Gotenberg 7");
|
|
113
113
|
const partly = buildStacks({ ...updateReport, rows: [rows[5], proxy], holds: { "bigcapital/gotenberg": "x" } });
|
|
114
114
|
expect(partly?.stacks[0].actionable).toBe(true);
|
|
115
115
|
});
|
|
@@ -133,10 +133,10 @@ describe("Arcane Daily Report layout", () => {
|
|
|
133
133
|
const text = (c: (typeof components)[number]) => (c.type === 9 ? c.components?.[0].content : c.content);
|
|
134
134
|
expect(components.slice(1).map(text)).toEqual([
|
|
135
135
|
"**arcane**\n• arcane: v2.16.1 → v2.17.0 · new version (digest pin)",
|
|
136
|
-
"**bigcapital**\n• gotenberg: 7.10.2,
|
|
136
|
+
"**bigcapital**\n• gotenberg: 7.10.2, major 8 available (tag change by hand; Update skips it)",
|
|
137
137
|
"**media**\n• sonarr: 4.0.20.3014-ls325 → 4.0.20.3014-ls326 · new build of `latest`",
|
|
138
138
|
"**postgres**\n• db: rebuild of `18`",
|
|
139
|
-
"**stirling-pdf**\n• stirling-pdf: 2.14.3 → 3.0.0 · new version · **major
|
|
139
|
+
"**stirling-pdf**\n• stirling-pdf: 2.14.3 → 3.0.0 · new version · **major**\n-# 🟡 check: the config key changed",
|
|
140
140
|
"**supabase**\n• db: 15.8.1.085 → 15.8.1.094 · new version (tag change)\n-# ⏸ held: coordinated release: review first",
|
|
141
141
|
"**vpn**\n• gluetun: new build of `latest`",
|
|
142
142
|
"**x**\n• y: check failed (stale)",
|
|
@@ -164,7 +164,7 @@ describe("Arcane Daily Report layout", () => {
|
|
|
164
164
|
expect(label("rolled back")).toMatchObject({ label: "Rolled back", style: 4, disabled: true });
|
|
165
165
|
expect(label("failed")).toEqual({ type: 2, style: 4, label: "Retry", custom_id: "arcane:stack:media" });
|
|
166
166
|
const manager = entry(report(), "arcane");
|
|
167
|
-
expect(stackComponent({ ...manager, state: "failed" }).accessory).toMatchObject({ label: "Upgrade
|
|
167
|
+
expect(stackComponent({ ...manager, state: "failed" }).accessory).toMatchObject({ label: "Upgrade incomplete", disabled: true });
|
|
168
168
|
expect(stackComponent({ ...s, state: "rolled back", detail: "rolled back: health" }).components?.[0].content).toContain("\n-# rolled back: health");
|
|
169
169
|
});
|
|
170
170
|
|
|
@@ -178,8 +178,8 @@ describe("Arcane Daily Report layout", () => {
|
|
|
178
178
|
expect(remote.stacks[0].lines[0].environment).toBe("mira");
|
|
179
179
|
expect(serviceUsage("media-mira", remote.stacks[0].lines[0])).toContain("on the Docker host of the Arcane environment mira,");
|
|
180
180
|
expect(remote.environmentErrors).toEqual([{ environment: "lab", error: "agent offline" }]);
|
|
181
|
-
expect(headText({ ...remote, timeZone: "Europe/Madrid" }).content).toContain("\n-# ⚠️ environment lab
|
|
182
|
-
expect(headText({ ...remote, timeZone: "Europe/Madrid" }).content).toContain("\n-# ⚠️
|
|
181
|
+
expect(headText({ ...remote, timeZone: "Europe/Madrid" }).content).toContain("\n-# ⚠️ environment lab unchecked: agent offline");
|
|
182
|
+
expect(headText({ ...remote, timeZone: "Europe/Madrid" }).content).toContain("\n-# ⚠️ Arcane agent of mira runs v2.17.3, manager v2.18.0");
|
|
183
183
|
expect(failureMessage().startsWith(REPORT_PREFIX)).toBe(true);
|
|
184
184
|
});
|
|
185
185
|
|
|
@@ -202,7 +202,7 @@ describe("Arcane report plans", () => {
|
|
|
202
202
|
expect(stackComponent({ ...media, state: "running" }).accessory).toMatchObject({ label: "Updating…", disabled: true });
|
|
203
203
|
const pdf = { ...entry(r, "stirling-pdf"), plan: "careful" as const };
|
|
204
204
|
expect(stackComponent(pdf).accessory).toEqual({ type: 2, style: 4, label: "Upgrade carefully", custom_id: "arcane:careful:stirling-pdf" });
|
|
205
|
-
expect(stackComponent({ ...pdf, state: "planning" }).accessory).toMatchObject({ label: "Planning in
|
|
205
|
+
expect(stackComponent({ ...pdf, state: "planning" }).accessory).toMatchObject({ label: "Planning in thread", disabled: true });
|
|
206
206
|
expect(stackComponent({ ...pdf, plan: "update" }).accessory).toMatchObject({ label: "Update", custom_id: "arcane:stack:stirling-pdf" });
|
|
207
207
|
expect(parseArcaneButton("arcane:careful:stirling-pdf")).toEqual({ kind: "careful", stack: "stirling-pdf" });
|
|
208
208
|
expect(parseArcaneButton("arcane:careful:bad name")).toBeNull();
|
|
@@ -212,11 +212,11 @@ describe("Arcane report plans", () => {
|
|
|
212
212
|
const r = report();
|
|
213
213
|
entry(r, "media").plan = "auto";
|
|
214
214
|
entry(r, "vpn").plan = "auto";
|
|
215
|
-
expect(headText({ ...r, mention: ["178096425509453824"] }).content).toContain("\n-# 2 stacks update automatically
|
|
215
|
+
expect(headText({ ...r, mention: ["178096425509453824"] }).content).toContain("\n-# 2 stacks update automatically, rechecked 5 min later.");
|
|
216
216
|
expect(headText({ ...r, mention: ["178096425509453824"] }).content).not.toContain("<@");
|
|
217
217
|
entry(r, "stirling-pdf").plan = "careful";
|
|
218
218
|
entry(r, "postgres").plan = "update";
|
|
219
|
-
expect(headText({ ...r, mention: ["178096425509453824"] }).content).toContain("\n<@178096425509453824> 2 updates need you: postgres (major
|
|
219
|
+
expect(headText({ ...r, mention: ["178096425509453824"] }).content).toContain("\n<@178096425509453824> 2 updates need you: postgres (major), stirling-pdf (Upgrade carefully)");
|
|
220
220
|
});
|
|
221
221
|
|
|
222
222
|
it("asks the specialist for a plan and the owner's go before it applies anything", () => {
|
|
@@ -252,8 +252,8 @@ describe("Arcane report buttons and outcomes", () => {
|
|
|
252
252
|
|
|
253
253
|
it("maps each stack-update status to a state and a line", () => {
|
|
254
254
|
expect(stackOutcome({ status: "updated", services: [{ service: "sonarr", to: "4.0.20.3014-ls326" }] })).toEqual({ state: "updated", detail: "updated: sonarr 4.0.20.3014-ls326" });
|
|
255
|
-
expect(stackOutcome({ status: "nothing to do" })).toEqual({ state: "current", detail: "
|
|
256
|
-
expect(stackOutcome({ status: "rolled back", reason: "health: db (unhealthy)" })).toEqual({ state: "rolled back", detail: "rolled back: health: db (unhealthy);
|
|
255
|
+
expect(stackOutcome({ status: "nothing to do" })).toEqual({ state: "current", detail: "already current" });
|
|
256
|
+
expect(stackOutcome({ status: "rolled back", reason: "health: db (unhealthy)" })).toEqual({ state: "rolled back", detail: "rolled back: health: db (unhealthy); previous Compose file runs again" });
|
|
257
257
|
expect(stackOutcome({ status: "failed", reason: "projects redeploy exited 1" })).toEqual({ state: "failed", detail: "failed: projects redeploy exited 1" });
|
|
258
258
|
expect(stackOutcome({ status: "maybe" }).state).toBe("failed");
|
|
259
259
|
});
|
|
@@ -282,10 +282,10 @@ describe("Arcane report buttons and outcomes", () => {
|
|
|
282
282
|
});
|
|
283
283
|
|
|
284
284
|
it("summarises each outcome of manager-upgrade", () => {
|
|
285
|
-
expect(managerSummary({ status: "upgraded", from: "2.16.1", to: "2.17.0", digest: `sha256:${"a".repeat(64)}`, commit: "abcdef1234567", stamp: "20261019T060500Z" })).toMatch(/^✅ Arcane v2\.16\.1 → v2\.17\.0
|
|
285
|
+
expect(managerSummary({ status: "upgraded", from: "2.16.1", to: "2.17.0", digest: `sha256:${"a".repeat(64)}`, commit: "abcdef1234567", stamp: "20261019T060500Z" })).toMatch(/^✅ Arcane v2\.16\.1 → v2\.17\.0 running/);
|
|
286
286
|
expect(managerSummary({ status: "rolled back", from: "2.16.1", to: "2.17.0", reason: "version (\"2.16.1\")", stamp: "20261019T060500Z" })).toMatch(/^⚠️ Arcane v2\.17\.0 failed its checks/);
|
|
287
|
-
expect(managerSummary({ status: "stopped", from: "2.16.1", to: "2.17.0", reason: "sync timeout" })).toMatch(/^❌
|
|
288
|
-
expect(managerSummary({})).toMatch(/
|
|
287
|
+
expect(managerSummary({ status: "stopped", from: "2.16.1", to: "2.17.0", reason: "sync timeout" })).toMatch(/^❌ Arcane upgrade to v2\.17\.0 stopped before the restart: sync timeout/);
|
|
288
|
+
expect(managerSummary({})).toMatch(/Unexpected Arcane upgrade answer/);
|
|
289
289
|
});
|
|
290
290
|
});
|
|
291
291
|
|
|
@@ -222,7 +222,7 @@ export function serviceText(l: ServiceLine): string {
|
|
|
222
222
|
text = `${name}: check failed${l.note ? ` (${escapeDiscord(l.note.slice(0, 160))})` : ""}`;
|
|
223
223
|
} else if (!PENDING.has(l.status)) {
|
|
224
224
|
const newer = /newer major (\S+) available/.exec(l.note)?.[1] ?? "?";
|
|
225
|
-
text = `${name}: ${escapeDiscord(l.running ?? l.tag)},
|
|
225
|
+
text = `${name}: ${escapeDiscord(l.running ?? l.tag)}, major ${escapeDiscord(newer)} available (tag change by hand; Update skips it)`;
|
|
226
226
|
} else if (l.status === "rebuild") {
|
|
227
227
|
text = `${name}: rebuild of ${tag}`;
|
|
228
228
|
} else if (l.latest === null) {
|
|
@@ -235,9 +235,9 @@ export function serviceText(l: ServiceLine): string {
|
|
|
235
235
|
const kind = sameRelease ? `new build of ${tag}` : l.action === "edit tag" ? "new version (tag change)" : l.action === "edit digest" ? "new version (digest pin)" : "new version";
|
|
236
236
|
text = `${name}: ${escapeDiscord(from)} → ${escapeDiscord(l.latest)} · ${kind}`;
|
|
237
237
|
}
|
|
238
|
-
if (l.major) text += " · **major
|
|
238
|
+
if (l.major) text += " · **major**";
|
|
239
239
|
const newer = PENDING.has(l.status) ? /newer major (\S+) available/.exec(l.note)?.[1] : undefined;
|
|
240
|
-
if (newer) text += ` ·
|
|
240
|
+
if (newer) text += ` · major ${escapeDiscord(newer)} available`;
|
|
241
241
|
const review = l.review ? `\n-# ${l.review.verdict ? `${VERDICT_MARK[l.review.verdict]}: ` : "notes: "}${escapeDiscord(l.review.reason)}` : "";
|
|
242
242
|
const held = l.held ? `\n-# ⏸ held: ${escapeDiscord(l.held)}` : "";
|
|
243
243
|
return `• ${text}${review}${held}`;
|
|
@@ -295,15 +295,15 @@ export function parseArcaneButton(customId: string): ArcaneButton | null {
|
|
|
295
295
|
|
|
296
296
|
function stackButton(s: StackEntry): MessageComponent {
|
|
297
297
|
if (s.plan === "careful" && (s.state === "offered" || s.state === "planning")) {
|
|
298
|
-
return s.state === "planning" ? { type: 2, style: SECONDARY, label: "Planning in
|
|
298
|
+
return s.state === "planning" ? { type: 2, style: SECONDARY, label: "Planning in thread", custom_id: carefulId(s.stack), disabled: true } : { type: 2, style: DANGER, label: "Upgrade carefully", custom_id: carefulId(s.stack) };
|
|
299
299
|
}
|
|
300
300
|
const id = s.manager ? `arcane:manager:${s.manager}` : stackId(s.stack);
|
|
301
301
|
if (s.plan === "auto" && s.state === "offered") return { type: 2, style: SECONDARY, label: "Automatic", custom_id: id, disabled: true };
|
|
302
302
|
if (s.state === "running") return { type: 2, style: SECONDARY, label: s.manager ? `Upgrading Arcane to v${s.manager}…` : "Updating…", custom_id: id, disabled: true };
|
|
303
|
-
if (s.state === "updated") return { type: 2, style: SUCCESS, label: s.manager ? `Arcane v${s.manager}
|
|
303
|
+
if (s.state === "updated") return { type: 2, style: SUCCESS, label: s.manager ? `Arcane v${s.manager} running` : "Updated", custom_id: id, disabled: true };
|
|
304
304
|
if (s.state === "current") return { type: 2, style: SECONDARY, label: "Already current", custom_id: id, disabled: true };
|
|
305
305
|
if (s.state === "rolled back") return { type: 2, style: DANGER, label: "Rolled back", custom_id: id, disabled: true };
|
|
306
|
-
if (s.state === "failed") return s.manager ? { type: 2, style: DANGER, label: "Upgrade
|
|
306
|
+
if (s.state === "failed") return s.manager ? { type: 2, style: DANGER, label: "Upgrade incomplete", custom_id: id, disabled: true } : { type: 2, style: DANGER, label: "Retry", custom_id: id };
|
|
307
307
|
return { type: 2, style: PRIMARY, label: s.manager ? `Upgrade Arcane to v${s.manager}` : "Update", custom_id: id };
|
|
308
308
|
}
|
|
309
309
|
|
|
@@ -328,14 +328,14 @@ export function headText(report: ReportView): MessageComponent {
|
|
|
328
328
|
: `**${REPORT_PREFIX}** ${withUpdates} stack${withUpdates === 1 ? "" : "s"} with updates (${scope}).`;
|
|
329
329
|
const warning =
|
|
330
330
|
(report.holdsError ? `\n-# ⚠️ ${escapeDiscord(report.holdsError)}; Update still refuses held stacks` : "") +
|
|
331
|
-
(report.environmentErrors ?? []).map((e) => `\n-# ⚠️ environment ${escapeDiscord(e.environment)}
|
|
332
|
-
(report.agentsBehind ?? []).map((a) => `\n-# ⚠️
|
|
331
|
+
(report.environmentErrors ?? []).map((e) => `\n-# ⚠️ environment ${escapeDiscord(e.environment)} unchecked: ${escapeDiscord(e.error.slice(0, 200))}`).join("") +
|
|
332
|
+
(report.agentsBehind ?? []).map((a) => `\n-# ⚠️ Arcane agent of ${escapeDiscord(a.environment)} runs ${escapeDiscord(a.agent)}, manager ${escapeDiscord(a.manager)}`).join("");
|
|
333
333
|
const attention = report.stacks.filter((s) => s.plan === "update" || s.plan === "careful");
|
|
334
334
|
const automatic = report.stacks.filter((s) => s.plan === "auto").length;
|
|
335
|
-
const plan = automatic > 0 ? `\n-# ${automatic} stack${automatic === 1 ? " updates" : "s update"} automatically
|
|
335
|
+
const plan = automatic > 0 ? `\n-# ${automatic} stack${automatic === 1 ? " updates" : "s update"} automatically, rechecked 5 min later.` : "";
|
|
336
336
|
const needs =
|
|
337
337
|
attention.length > 0 && report.mention && report.mention.length > 0
|
|
338
|
-
? `\n${report.mention.map((id) => `<@${id}>`).join(" ")} ${attention.length} update${attention.length === 1 ? " needs" : "s need"} you: ${attention.map((s) => `${escapeDiscord(s.stack)} (${s.plan === "careful" ? "Upgrade carefully" : "major
|
|
338
|
+
? `\n${report.mention.map((id) => `<@${id}>`).join(" ")} ${attention.length} update${attention.length === 1 ? " needs" : "s need"} you: ${attention.map((s) => `${escapeDiscord(s.stack)} (${s.plan === "careful" ? "Upgrade carefully" : "major"})`).join(", ")}`
|
|
339
339
|
: "";
|
|
340
340
|
return { type: 10, content: `${head}${warning}${plan}${needs}` };
|
|
341
341
|
}
|
|
@@ -380,7 +380,7 @@ export function layoutMessages(report: ReportView): Omit<PostedPage, "id">[] {
|
|
|
380
380
|
|
|
381
381
|
/** Sent when the check itself fails: no list, so nothing reads as up to date. */
|
|
382
382
|
export function failureMessage(): string {
|
|
383
|
-
return `${REPORT_PREFIX}
|
|
383
|
+
return `${REPORT_PREFIX} version check failed, no update list today. Reason in the bridge log on Cortex.`;
|
|
384
384
|
}
|
|
385
385
|
|
|
386
386
|
/** The stack's state after `stack-update`, from its JSON answer, and one line for the report. */
|
|
@@ -390,10 +390,10 @@ export function stackOutcome(out: Record<string, unknown>): { state: StackState;
|
|
|
390
390
|
const services = Array.isArray(out.services) ? (out.services as { service?: unknown; to?: unknown }[]) : [];
|
|
391
391
|
const moved = services.map((s) => `${String(s.service)} ${String(s.to)}`).join(", ");
|
|
392
392
|
if (out.status === "updated") return { state: "updated", detail: `updated: ${moved || "every service"}`, ...commit };
|
|
393
|
-
if (out.status === "nothing to do") return { state: "current", detail: "
|
|
394
|
-
if (out.status === "rolled back") return { state: "rolled back", detail: `rolled back: ${reason || "a check failed"};
|
|
393
|
+
if (out.status === "nothing to do") return { state: "current", detail: "already current" };
|
|
394
|
+
if (out.status === "rolled back") return { state: "rolled back", detail: `rolled back: ${reason || "a check failed"}; previous Compose file runs again` };
|
|
395
395
|
if (out.status === "failed") return { state: "failed", detail: `failed: ${reason || "no reason given"}` };
|
|
396
|
-
return { state: "failed", detail: "
|
|
396
|
+
return { state: "failed", detail: "unexpected answer; check the stack with the arcane specialist" };
|
|
397
397
|
}
|
|
398
398
|
|
|
399
399
|
function short(value: unknown): string {
|
|
@@ -407,13 +407,13 @@ export function managerSummary(out: Record<string, unknown>): string {
|
|
|
407
407
|
const reason = typeof out.reason === "string" ? out.reason.slice(0, 400) : "no reason given";
|
|
408
408
|
const backup = (out.backup as { archive?: unknown; stamp?: unknown } | undefined)?.stamp;
|
|
409
409
|
if (out.status === "upgraded") {
|
|
410
|
-
return `✅ Arcane ${from} → ${to}
|
|
410
|
+
return `✅ Arcane ${from} → ${to} running (digest ${short(out.digest)}, pin commit ${short(out.commit)}). All checks passed; other containers kept running. Cold backup: /var/backups/arcane-upgrades/${typeof backup === "string" ? backup : String(out.stamp)}.`;
|
|
411
411
|
}
|
|
412
412
|
if (out.status === "rolled back") {
|
|
413
|
-
return `⚠️ Arcane ${to} failed its checks (${reason}). ${from} runs again
|
|
413
|
+
return `⚠️ Arcane ${to} failed its checks (${reason}). ${from} runs again; pin reverted in git. If ${to} migrated the database, restore the pre-upgrade data from /var/backups/arcane-upgrades/${String(out.stamp)} by hand (arcane/AGENTS.md, Upgrade rollback).`;
|
|
414
414
|
}
|
|
415
|
-
if (out.status === "stopped") return `❌
|
|
416
|
-
return `❌
|
|
415
|
+
if (out.status === "stopped") return `❌ Arcane upgrade to ${to} stopped before the restart: ${reason}. Pin reverted; ${from} keeps running.`;
|
|
416
|
+
return `❌ Unexpected Arcane upgrade answer; check the manager with the arcane specialist before retrying.`;
|
|
417
417
|
}
|
|
418
418
|
|
|
419
419
|
type StackNotes = { notes: Pick<ReleaseNote, "tag" | "published" | "notes">[]; omitted: string[] } | { notes: null; reason: string };
|
|
@@ -426,8 +426,8 @@ function isNote(value: unknown): value is Pick<ReleaseNote, "tag" | "published"
|
|
|
426
426
|
/** The releases from the wrapper's `release-notes <stack>/<service>` answer, or why there are none to review. */
|
|
427
427
|
export function releaseNotesFromJson(value: unknown): StackNotes {
|
|
428
428
|
const r = value as { releases?: unknown; omitted?: unknown; reason?: unknown } | null;
|
|
429
|
-
if (!r || typeof r !== "object" || !Array.isArray(r.releases) || !r.releases.every(isNote)) return { notes: null, reason: "release-notes
|
|
430
|
-
if (r.releases.length === 0) return { notes: null, reason: typeof r.reason === "string" && r.reason.length > 0 ? r.reason.slice(0, 160) : "
|
|
429
|
+
if (!r || typeof r !== "object" || !Array.isArray(r.releases) || !r.releases.every(isNote)) return { notes: null, reason: "unexpected release-notes answer" };
|
|
430
|
+
if (r.releases.length === 0) return { notes: null, reason: typeof r.reason === "string" && r.reason.length > 0 ? r.reason.slice(0, 160) : "none found" };
|
|
431
431
|
const omitted = Array.isArray(r.omitted) ? r.omitted.filter((o): o is string => typeof o === "string") : [];
|
|
432
432
|
return { notes: r.releases, omitted };
|
|
433
433
|
}
|
|
@@ -226,7 +226,7 @@ describe("morning summary", () => {
|
|
|
226
226
|
reports: [
|
|
227
227
|
{ area: "Security", line: "quiet day", needs: [], channelId: "21", messageId: "31" },
|
|
228
228
|
{ area: "Cortex tools", line: "1 updated", needs: [], channelId: "23", messageId: "33" },
|
|
229
|
-
{ area: "Arcane", line: "3 stacks updated", needs: ["stirling-pdf waits for you (major
|
|
229
|
+
{ area: "Arcane", line: "3 stacks updated", needs: ["stirling-pdf waits for you (major)"], channelId: "22", messageId: "32" },
|
|
230
230
|
],
|
|
231
231
|
areas: [
|
|
232
232
|
{ area: "DNS", line: "both resolvers answer" },
|
|
@@ -238,7 +238,7 @@ describe("morning summary", () => {
|
|
|
238
238
|
expect(text).toBe(
|
|
239
239
|
[
|
|
240
240
|
"**Daily** · Fri 24 Oct · 🟠 3 items need you",
|
|
241
|
-
"Arcane · stirling-pdf waits for you (major
|
|
241
|
+
"Arcane · stirling-pdf waits for you (major) ([report](https://discord.com/channels/1/22/32))",
|
|
242
242
|
"Backup · no backup last night: identity ([message](https://discord.com/channels/1/11/41))",
|
|
243
243
|
"DNS · synapse: libcamera-ipa kept back. Fix by hand: `apt-get full-upgrade` (adds libcamera0.8) (<#11>)",
|
|
244
244
|
"All clear: Security, Cortex, Proxmox",
|
|
@@ -284,15 +284,15 @@ describe("report summaries", () => {
|
|
|
284
284
|
const tool = (over: Partial<ToolsReport["lines"][number]>): ToolsReport["lines"][number] => ({ key: "brew:jq", label: "jq", installed: "1.8.1", latest: "1.8.2", major: false, action: { kind: "brew", name: "jq" }, state: "offered", ...over }) as ToolsReport["lines"][number];
|
|
285
285
|
|
|
286
286
|
it("says what the tools report updated, what failed, and what waits for a button", () => {
|
|
287
|
-
const report = { date: "2026-10-24", lines: [tool({ state: "updated", plan: "auto" }), tool({ key: "brew:herdr", label: "herdr", latest: "0.10.0", state: "failed", plan: "auto" }), tool({ key: "pi", label: "Pi", latest: "1.4.0", plan: "button" }), tool({ key: "spc:node", label: "Node", latest: "26.1.0", major: true, plan: "update" }), tool({ key: "cask:temurin@17", label: "temurin@17", latest: "17.0.18", plan: "auto", manual: "
|
|
287
|
+
const report = { date: "2026-10-24", lines: [tool({ state: "updated", plan: "auto" }), tool({ key: "brew:herdr", label: "herdr", latest: "0.10.0", state: "failed", plan: "auto" }), tool({ key: "pi", label: "Pi", latest: "1.4.0", plan: "button" }), tool({ key: "spc:node", label: "Node", latest: "26.1.0", major: true, plan: "update" }), tool({ key: "cask:temurin@17", label: "temurin@17", latest: "17.0.18", plan: "auto", manual: "installer needs your password; on Cortex: brew upgrade --cask temurin@17" })], messages: [{ id: "9", keys: [], head: true, all: false }] } as unknown as ToolsReport;
|
|
288
288
|
expect(toolsSummary(report, "2026-10-24", "5")).toEqual({
|
|
289
289
|
area: "Cortex tools",
|
|
290
290
|
line: "1 updated (jq 1.8.2), 1 failed (herdr), Pi 1.4.0, Node 26.1.0 wait for a button, 1 by hand",
|
|
291
|
-
needs: ["Node 26.1.0 waits for its button (major
|
|
291
|
+
needs: ["Node 26.1.0 waits for its button (major)", "Pi 1.4.0 waits for its button", "herdr automatic update failed", "temurin@17 17.0.18 by hand: installer needs your password; on Cortex: brew upgrade --cask temurin@17"],
|
|
292
292
|
channelId: "5",
|
|
293
293
|
messageId: "9",
|
|
294
294
|
});
|
|
295
|
-
expect(toolsSummary(report, "2026-10-25", "5")).toMatchObject({ line: "no report today; the bridge log
|
|
295
|
+
expect(toolsSummary(report, "2026-10-25", "5")).toMatchObject({ line: "no report today; reason in the bridge log", needs: ["Cortex Tools Report did not run today; reason in the bridge log"] });
|
|
296
296
|
});
|
|
297
297
|
|
|
298
298
|
it("says what the Arcane report updated, rolled back, and leaves to the owner", () => {
|
|
@@ -310,11 +310,11 @@ describe("report summaries", () => {
|
|
|
310
310
|
expect(arcaneSummary(report, "2026-10-24", "6")).toEqual({
|
|
311
311
|
area: "Arcane",
|
|
312
312
|
line: "1 stack updated (media), mealie rolled back, stirling-pdf waits for you, supabase held",
|
|
313
|
-
needs: ["stirling-pdf waits for you (Upgrade carefully)", "mealie automatic update rolled back", "paperless gotenberg 8.40.0: major 9 needs a tag change by hand", "paperless broker:
|
|
313
|
+
needs: ["stirling-pdf waits for you (Upgrade carefully)", "mealie automatic update rolled back", "paperless gotenberg 8.40.0: major 9 needs a tag change by hand", "paperless broker: update check failed"],
|
|
314
314
|
channelId: "6",
|
|
315
315
|
messageId: "8",
|
|
316
316
|
});
|
|
317
317
|
const unchecked = { ...report, stacks: [], environmentErrors: [{ environment: "mira", error: "environment offline" }], agentsBehind: [{ environment: "lab", agent: "v2.17.3", manager: "v2.18.0" }] } as unknown as ArcaneReport;
|
|
318
|
-
expect(arcaneSummary(unchecked, "2026-10-24", "6").needs).toEqual(["Arcane environment mira
|
|
318
|
+
expect(arcaneSummary(unchecked, "2026-10-24", "6").needs).toEqual(["Arcane environment mira unchecked for updates", "Arcane agent of lab runs v2.17.3, manager v2.18.0: move its tag on the host"]);
|
|
319
319
|
});
|
|
320
320
|
});
|
|
@@ -518,7 +518,7 @@ function names(items: readonly string[]): string {
|
|
|
518
518
|
|
|
519
519
|
/** The Cortex Tools Report after its automatic updates ran: what changed, what failed, and what waits for a button. */
|
|
520
520
|
export function toolsSummary(report: ToolsReport | null, date: string, channelId: string): ReportLine {
|
|
521
|
-
if (!report || report.date !== date) return { area: "Cortex tools", line: "no report today; the bridge log
|
|
521
|
+
if (!report || report.date !== date) return { area: "Cortex tools", line: "no report today; reason in the bridge log", needs: ["Cortex Tools Report did not run today; reason in the bridge log"], channelId };
|
|
522
522
|
const updated = report.lines.filter((l) => l.state === "updated");
|
|
523
523
|
const failed = report.lines.filter((l) => l.state === "failed");
|
|
524
524
|
const waiting = report.lines.filter((l) => (l.plan === "update" || l.plan === "button") && l.state === "offered");
|
|
@@ -530,26 +530,26 @@ export function toolsSummary(report: ToolsReport | null, date: string, channelId
|
|
|
530
530
|
manual.length > 0 ? `${manual.length} by hand` : null,
|
|
531
531
|
].filter(Boolean);
|
|
532
532
|
const needs = [
|
|
533
|
-
...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
|
|
533
|
+
...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" : "release notes"})`),
|
|
534
534
|
...report.lines.filter((l) => l.plan === "button" && l.state === "offered").map((l) => `${escapeDiscord(l.label)} ${escapeDiscord(l.latest)} waits for its button`),
|
|
535
535
|
...failed.filter((l) => l.plan === "auto").map((l) => `${escapeDiscord(l.label)} automatic update failed`),
|
|
536
536
|
...manual.map((l) => `${escapeDiscord(l.label)} ${escapeDiscord(l.latest)} by hand: ${escapeDiscord(l.manual ?? "")}`),
|
|
537
537
|
];
|
|
538
|
-
return { area: "Cortex tools", line: parts.join(", ") || "
|
|
538
|
+
return { area: "Cortex tools", line: parts.join(", ") || "all up to date", needs, channelId, ...(report.messages[0] ? { messageId: report.messages[0].id } : {}) };
|
|
539
539
|
}
|
|
540
540
|
|
|
541
541
|
/** A service line only the owner can act on: a failed check, or a newer major that needs a tag change by hand; a held service is the owner's own decision. */
|
|
542
542
|
function byHand(stack: string, l: ArcaneReport["stacks"][number]["lines"][number]): string | null {
|
|
543
543
|
if (l.held !== undefined) return null;
|
|
544
544
|
const where = `${escapeDiscord(stack)} ${escapeDiscord(l.service)}`;
|
|
545
|
-
if (l.status === "unknown") return `${where}:
|
|
545
|
+
if (l.status === "unknown") return `${where}: update check failed`;
|
|
546
546
|
const newer = /newer major (\S+) available/.exec(l.note)?.[1];
|
|
547
547
|
return newer ? `${where} ${escapeDiscord(l.running ?? l.tag)}: major ${escapeDiscord(newer)} needs a tag change by hand` : null;
|
|
548
548
|
}
|
|
549
549
|
|
|
550
550
|
/** The Arcane Daily Report after its automatic updates and checks: updated, rolled back, waiting for the owner, held, by hand. Holds are the owner's own decisions, so they are not items. */
|
|
551
551
|
export function arcaneSummary(report: ArcaneReport | null, date: string, channelId: string): ReportLine {
|
|
552
|
-
if (!report || report.date !== date) return { area: "Arcane", line: "no report today; the bridge log
|
|
552
|
+
if (!report || report.date !== date) return { area: "Arcane", line: "no report today; reason in the bridge log", needs: ["Arcane Daily Report did not run today; reason in the bridge log"], channelId };
|
|
553
553
|
const by = (pick: (s: ArcaneReport["stacks"][number]) => boolean) => report.stacks.filter(pick).map((s) => s.stack);
|
|
554
554
|
const updated = by((s) => s.state === "updated");
|
|
555
555
|
const rolled = by((s) => s.state === "rolled back");
|
|
@@ -564,12 +564,12 @@ export function arcaneSummary(report: ArcaneReport | null, date: string, channel
|
|
|
564
564
|
held.length > 0 ? `${names(held)} held` : null,
|
|
565
565
|
].filter(Boolean);
|
|
566
566
|
const needs = [
|
|
567
|
-
...waiting.map((s) => `${escapeDiscord(s.stack)} waits for you (${s.plan === "careful" ? "Upgrade carefully" : "major
|
|
567
|
+
...waiting.map((s) => `${escapeDiscord(s.stack)} waits for you (${s.plan === "careful" ? "Upgrade carefully" : "major"})`),
|
|
568
568
|
...report.stacks.filter((s) => s.plan === "auto" && (s.state === "rolled back" || s.state === "failed")).map((s) => `${escapeDiscord(s.stack)} automatic update ${s.state}`),
|
|
569
569
|
...report.stacks.flatMap((s) => s.lines.map((l) => byHand(s.stack, l)).filter((t): t is string => t !== null)),
|
|
570
|
-
...(report.holdsError ? [`update-holds.json
|
|
571
|
-
...(report.environmentErrors ?? []).map((e) => `Arcane environment ${escapeDiscord(e.environment)}
|
|
572
|
-
...(report.agentsBehind ?? []).map((a) => `
|
|
570
|
+
...(report.holdsError ? [`update-holds.json unreadable: ${escapeDiscord(report.holdsError)}`] : []),
|
|
571
|
+
...(report.environmentErrors ?? []).map((e) => `Arcane environment ${escapeDiscord(e.environment)} unchecked for updates`),
|
|
572
|
+
...(report.agentsBehind ?? []).map((a) => `Arcane agent of ${escapeDiscord(a.environment)} runs ${escapeDiscord(a.agent)}, manager ${escapeDiscord(a.manager)}: move its tag on the host`),
|
|
573
573
|
];
|
|
574
574
|
return { area: "Arcane", line: parts.join(", ") || "no updates", needs, channelId, ...(report.messages[0] ? { messageId: report.messages[0].id } : {}) };
|
|
575
575
|
}
|
|
@@ -844,7 +844,7 @@ class Bridge {
|
|
|
844
844
|
log(`arcane auto: container-watch failed: ${err instanceof Error ? err.message.split("\n")[0] : String(err)}`);
|
|
845
845
|
}
|
|
846
846
|
if (!snapshot) {
|
|
847
|
-
await this.arcaneAttention(report, open[0].stack, `⚠️
|
|
847
|
+
await this.arcaneAttention(report, open[0].stack, `⚠️ Recheck of ${open.map((a) => a.stack).join(", ")} failed (container-watch). Ask the arcane specialist.`);
|
|
848
848
|
return;
|
|
849
849
|
}
|
|
850
850
|
const now = Date.now();
|
|
@@ -874,9 +874,9 @@ class Bridge {
|
|
|
874
874
|
rollback = `The rollback failed: ${(err instanceof Error ? err.message : String(err)).split("\n")[0].slice(0, 200)}.`;
|
|
875
875
|
}
|
|
876
876
|
} else if (a.stack === "arcane") {
|
|
877
|
-
rollback = `Not rolled back: \`manager-rollback ${a.stamp ?? "<stamp>"}
|
|
877
|
+
rollback = `Not rolled back. Fix: \`manager-rollback ${a.stamp ?? "<stamp>"}\`, then revert the pin commit in git.`;
|
|
878
878
|
} else {
|
|
879
|
-
rollback = "Not rolled back:
|
|
879
|
+
rollback = "Not rolled back: only floating tags were pulled, which cannot be undone.";
|
|
880
880
|
}
|
|
881
881
|
log(`arcane auto: ${a.stack} failed its check (${problems.join(", ")}); ${rollback}`);
|
|
882
882
|
await this.markArcane(report, a.stack, state, `${state} after the automatic update: ${problems.join(", ")}`);
|
|
@@ -885,7 +885,7 @@ class Bridge {
|
|
|
885
885
|
try {
|
|
886
886
|
const posted = await this.rest.createMessage(report.channelId, { content: autoFailureText(a, problems, rollback, owners), mentionUsers: owners, ...(page ? { replyTo: page.id } : {}) });
|
|
887
887
|
const thread = await this.rest.startThread(report.channelId, posted.id, `Update of ${a.stack}`.slice(0, 100));
|
|
888
|
-
const starter = await this.rest.createMessage(thread.id, { content: "🔎 The foreman
|
|
888
|
+
const starter = await this.rest.createMessage(thread.id, { content: "🔎 The foreman investigates read-only. Write here to continue with the arcane specialist." });
|
|
889
889
|
void this.investigateIn("foreman", { threadId: thread.id, starterId: starter.id, userId: owners[0], task: foremanTask(a, problems, rollback, Date.now()) }).then((ok) => (ok ? this.archiveThread(thread.id) : undefined));
|
|
890
890
|
} catch (err) {
|
|
891
891
|
log(`arcane auto: reporting ${a.stack} failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
@@ -992,7 +992,7 @@ class Bridge {
|
|
|
992
992
|
});
|
|
993
993
|
const verdict = isFailed(result) ? null : parseVerdict(finalOutput(result.messages));
|
|
994
994
|
log(`release review: ${subject}: ${verdict?.verdict ?? `no answer (${isFailed(result) ? "failed" : "unparsed"}: ${resultOutput(result).replace(/\s+/g, " ").slice(0, 300)})`}`);
|
|
995
|
-
return verdict ?? { verdict: null, reason: "
|
|
995
|
+
return verdict ?? { verdict: null, reason: "no usable review; read the notes before updating" };
|
|
996
996
|
} catch (err) {
|
|
997
997
|
return { verdict: null, reason: `the review failed: ${err instanceof Error ? err.message.slice(0, 120) : String(err)}` };
|
|
998
998
|
}
|
|
@@ -1006,7 +1006,7 @@ class Bridge {
|
|
|
1006
1006
|
if (interrupted.length === 0 && report.brewAll !== "running") return;
|
|
1007
1007
|
for (const l of interrupted) {
|
|
1008
1008
|
l.state = "failed";
|
|
1009
|
-
l.detail = "interrupted by a bridge restart; check the version before
|
|
1009
|
+
l.detail = "interrupted by a bridge restart; check the version before Retry";
|
|
1010
1010
|
}
|
|
1011
1011
|
if (report.brewAll === "running") {
|
|
1012
1012
|
report.brewAll = "failed";
|
|
@@ -1023,7 +1023,7 @@ class Bridge {
|
|
|
1023
1023
|
if (!report || stuck.length === 0) return;
|
|
1024
1024
|
for (const s of stuck) {
|
|
1025
1025
|
s.state = "failed";
|
|
1026
|
-
s.detail = "interrupted by a bridge restart; check the stack and the GitOps repository with the arcane specialist before
|
|
1026
|
+
s.detail = "interrupted by a bridge restart; check the stack and the GitOps repository with the arcane specialist before Retry";
|
|
1027
1027
|
}
|
|
1028
1028
|
writePostedArcane(report);
|
|
1029
1029
|
for (const m of report.messages.filter((x) => stuck.some((s) => x.stacks.includes(s.stack)))) await this.rest.editComponents(report.channelId, m.id, arcaneComponents(report, m)).catch(() => undefined);
|
|
@@ -139,7 +139,7 @@ describe("security monitor", () => {
|
|
|
139
139
|
h.answers.set("security wazuh-events", events([wazuh({ id: "a1" }), wazuh({ id: "a2", timestamp: "2026-10-21T10:00:01.000+0000" })]));
|
|
140
140
|
await h.monitor.poll(SCHEDULE);
|
|
141
141
|
expect(h.rest.components).toHaveLength(1);
|
|
142
|
-
expect(h.rest.components[0].components[0].content).toContain("first
|
|
142
|
+
expect(h.rest.components[0].components[0].content).toContain("first this week · × 2 this check");
|
|
143
143
|
const messageId = readSecurityState().alerts[0].messageId;
|
|
144
144
|
await h.monitor.onButton({ interactionId: "i", token: "t", userId: OWNER, messageId, customId: "security:ack" });
|
|
145
145
|
expect(h.rest.deferred).toBe(1);
|
|
@@ -188,7 +188,7 @@ describe("security monitor", () => {
|
|
|
188
188
|
h.clock.now += 7 * 60_000;
|
|
189
189
|
await h.monitor.poll(SCHEDULE);
|
|
190
190
|
expect(h.rest.components).toHaveLength(1);
|
|
191
|
-
expect(h.rest.components[0].components[0].content).toContain("origin unchecked:
|
|
191
|
+
expect(h.rest.components[0].components[0].content).toContain("origin unchecked: origin check kept failing: arcane: token request failed");
|
|
192
192
|
expect(readSecurityState().pending).toHaveLength(0);
|
|
193
193
|
});
|
|
194
194
|
|
|
@@ -221,7 +221,7 @@ describe("security monitor", () => {
|
|
|
221
221
|
expect(warnings[0].message.mentionUsers).toEqual([OWNER]);
|
|
222
222
|
h.answers.set("security wazuh-events", events([]));
|
|
223
223
|
await h.monitor.poll(SCHEDULE);
|
|
224
|
-
expect(h.rest.messages.at(-1)?.message.content).toBe("✅ **Security checks** read Wazuh alerts again;
|
|
224
|
+
expect(h.rest.messages.at(-1)?.message.content).toBe("✅ **Security checks** read Wazuh alerts again; the gap is checked now.");
|
|
225
225
|
});
|
|
226
226
|
|
|
227
227
|
it("posts health changes: a new problem with a tag, recovery without", async () => {
|
|
@@ -237,7 +237,7 @@ describe("security monitor", () => {
|
|
|
237
237
|
expect(h.rest.messages).toHaveLength(1);
|
|
238
238
|
h.answers.set("security attention", attention([]));
|
|
239
239
|
await h.monitor.checkHealth(SCHEDULE);
|
|
240
|
-
expect(h.rest.messages[1].message).toEqual({ content: "✅ **Security health recovered:**
|
|
240
|
+
expect(h.rest.messages[1].message).toEqual({ content: "✅ **Security health recovered:** all checks clear." });
|
|
241
241
|
});
|
|
242
242
|
|
|
243
243
|
it("lets only owners press the buttons, and only on a tracked alert", async () => {
|
|
@@ -245,7 +245,7 @@ describe("security monitor", () => {
|
|
|
245
245
|
await h.monitor.onButton({ interactionId: "i", token: "t", userId: "999999999999999999", messageId: "m", customId: "security:ack" });
|
|
246
246
|
await h.monitor.onButton({ interactionId: "i", token: "t", userId: OWNER, messageId: "m", customId: "security:nope" });
|
|
247
247
|
await h.monitor.onButton({ interactionId: "i", token: "t", userId: OWNER, messageId: "unknown", customId: "security:investigate" });
|
|
248
|
-
expect(h.rest.replies).toEqual(["
|
|
248
|
+
expect(h.rest.replies).toEqual(["Owners only.", "Button no longer active.", "Alert no longer tracked (over 14 days old); ask the security specialist in the channel."]);
|
|
249
249
|
expect(h.rest.deferred).toBe(0);
|
|
250
250
|
});
|
|
251
251
|
|
|
@@ -305,14 +305,14 @@ describe("security monitor", () => {
|
|
|
305
305
|
const summary = await h.monitor.dailyReport(SCHEDULE, "2026-10-21");
|
|
306
306
|
expect(h.rest.messages).toEqual([]);
|
|
307
307
|
const text = JSON.stringify(h.rest.components[0].components);
|
|
308
|
-
expect(text).toContain("🐳 **Arcane images** · 1 critical CVE
|
|
309
|
-
expect(text).not.toContain("waiting on
|
|
308
|
+
expect(text).toContain("🐳 **Arcane images** · 1 fixable critical CVE in 1 image\"");
|
|
309
|
+
expect(text).not.toContain("waiting on publisher");
|
|
310
310
|
expect(h.calls).toContainEqual(["arcane", "images", "list", "--all"]);
|
|
311
311
|
expect(h.calls).toContainEqual(["arcane", "images", "vulnerabilities", "list", "--severity", "critical", "--all"]);
|
|
312
312
|
expect(summary).toEqual({ headline: "quiet day (24 h to 06:05 CEST)", needs: [], messageId: "100" });
|
|
313
313
|
expect(text).toContain("## 🛡️ Security Daily Report\\n🟢 quiet day · 24 h to 06:05 CEST");
|
|
314
314
|
expect(text).toContain("🚫 **CrowdSec** · 2 bans, all front door SNI scanning");
|
|
315
|
-
expect(text).toContain("📦 **Host packages** · 1 new CVE on 1 host,
|
|
315
|
+
expect(text).toContain("📦 **Host packages** · 1 new CVE on 1 host, all fixable\\n- CVE-1 (openssl, High 7.5) on dmz");
|
|
316
316
|
expect(h.rest.components[0].mentionUsers).toBeUndefined();
|
|
317
317
|
expect(readReportState("security")).toMatchObject({ date: "2026-10-21", status: "sent" });
|
|
318
318
|
expect(readSecurityState().vulns.reported["dmz|CVE-1"]).toMatchObject({ fix: true });
|
|
@@ -235,17 +235,17 @@ export class SecurityMonitor {
|
|
|
235
235
|
for (const e of events.slice(0, MAX_ORIGIN_CALLS)) {
|
|
236
236
|
const args = originArgs(e);
|
|
237
237
|
if (!args) {
|
|
238
|
-
out.set(e.id, { verdict: "unchecked", reason: "Wazuh sent no SHA-256
|
|
238
|
+
out.set(e.id, { verdict: "unchecked", reason: "Wazuh sent no SHA-256" });
|
|
239
239
|
continue;
|
|
240
240
|
}
|
|
241
241
|
try {
|
|
242
242
|
const verdict = parseOrigin(await this.entryJson("arcane", caller, args, 3 * MINUTE));
|
|
243
|
-
out.set(e.id, verdict ?? { error: "change-origin
|
|
243
|
+
out.set(e.id, verdict ?? { error: "unexpected change-origin answer" });
|
|
244
244
|
} catch (err) {
|
|
245
245
|
out.set(e.id, { error: reason(err) });
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
|
-
for (const e of events.slice(MAX_ORIGIN_CALLS)) out.set(e.id, { error: "too many changes
|
|
248
|
+
for (const e of events.slice(MAX_ORIGIN_CALLS)) out.set(e.id, { error: "too many changes this check; retried next time" });
|
|
249
249
|
return out;
|
|
250
250
|
}
|
|
251
251
|
|
|
@@ -277,7 +277,7 @@ export class SecurityMonitor {
|
|
|
277
277
|
state.origins[e.id] = { ...r, at: e.timestamp };
|
|
278
278
|
ready.push(e);
|
|
279
279
|
} else if (now - Date.parse(since) >= ORIGIN_RETRY_MS) {
|
|
280
|
-
state.origins[e.id] = { verdict: "unchecked", reason: `
|
|
280
|
+
state.origins[e.id] = { verdict: "unchecked", reason: `origin check kept failing: ${r?.error ?? "no answer"}`, at: e.timestamp };
|
|
281
281
|
ready.push(e);
|
|
282
282
|
} else {
|
|
283
283
|
pending.push({ event: e, since, error: r?.error ?? "not checked yet" });
|
|
@@ -336,7 +336,7 @@ export class SecurityMonitor {
|
|
|
336
336
|
failed.push(...group);
|
|
337
337
|
}
|
|
338
338
|
}
|
|
339
|
-
if (overflow > 0) await this.post(s.channelId, { content: `🚨 ${overflow} more urgent event(s)
|
|
339
|
+
if (overflow > 0) await this.post(s.channelId, { content: `🚨 ${overflow} more urgent event(s) this check not posted; the next Security Daily Report lists them.` });
|
|
340
340
|
for (const e of notices) {
|
|
341
341
|
if (!(await this.post(s.channelId, { content: noticeText(e, s.timeZone) }))) failed.push(e);
|
|
342
342
|
}
|
|
@@ -380,11 +380,11 @@ export class SecurityMonitor {
|
|
|
380
380
|
this.deps.log(`security: attention failed: ${why}`);
|
|
381
381
|
state.health.failures++;
|
|
382
382
|
if (state.health.failures >= HEALTH_FAILS_TO_WARN && !state.health.warned) {
|
|
383
|
-
state.health.warned = await this.post(s.channelId, { content: `${checksFailingText("
|
|
383
|
+
state.health.warned = await this.post(s.channelId, { content: `${checksFailingText("observability VM health", (state.health.failures * HEALTH_MS) / MINUTE, why)}\n${tag}`, mentionUsers: owners });
|
|
384
384
|
}
|
|
385
385
|
return;
|
|
386
386
|
}
|
|
387
|
-
if (state.health.warned) await this.post(s.channelId, { content: checksRecoveredText("
|
|
387
|
+
if (state.health.warned) await this.post(s.channelId, { content: checksRecoveredText("health") });
|
|
388
388
|
state.health.failures = 0;
|
|
389
389
|
state.health.warned = false;
|
|
390
390
|
const change = healthChange(state.health.codes, attention.issues);
|
|
@@ -425,7 +425,7 @@ export class SecurityMonitor {
|
|
|
425
425
|
await this.update((state) => {
|
|
426
426
|
for (const e of missing) {
|
|
427
427
|
const r = checks.get(e.id);
|
|
428
|
-
state.origins[e.id] = r && !("error" in r) ? { ...r, at: e.timestamp } : { verdict: "unchecked", reason: `
|
|
428
|
+
state.origins[e.id] = r && !("error" in r) ? { ...r, at: e.timestamp } : { verdict: "unchecked", reason: `origin check failed: ${r && "error" in r ? r.error : "no answer"}`, at: e.timestamp };
|
|
429
429
|
}
|
|
430
430
|
});
|
|
431
431
|
}
|
|
@@ -559,13 +559,13 @@ export class SecurityMonitor {
|
|
|
559
559
|
async onButton(click: SecurityClick): Promise<void> {
|
|
560
560
|
const kind = parseSecurityButton(click.customId);
|
|
561
561
|
const reply = (text: string) => this.deps.rest.ephemeralReply(click.interactionId, click.token, text);
|
|
562
|
-
if (!kind) return reply("
|
|
563
|
-
if (!isOwner(this.deps.config(), click.userId)) return reply("
|
|
564
|
-
if (this.deps.stopping()) return reply("
|
|
562
|
+
if (!kind) return reply("Button no longer active.");
|
|
563
|
+
if (!isOwner(this.deps.config(), click.userId)) return reply("Owners only.");
|
|
564
|
+
if (this.deps.stopping()) return reply("Bridge restarting; retry in a minute.");
|
|
565
565
|
const found = readSecurityState().alerts.find((a) => a.messageId === click.messageId);
|
|
566
|
-
if (!found) return reply("
|
|
566
|
+
if (!found) return reply("Alert no longer tracked (over 14 days old); ask the security specialist in the channel.");
|
|
567
567
|
if (kind === "ack") return this.onAcknowledge(click, found);
|
|
568
|
-
if (found.investigation === "running") return reply("
|
|
568
|
+
if (found.investigation === "running") return reply("Investigation already running; its thread gets the answer.");
|
|
569
569
|
await this.deps.rest.deferUpdate(click.interactionId, click.token);
|
|
570
570
|
await this.runInvestigation(click, found);
|
|
571
571
|
}
|
|
@@ -605,14 +605,14 @@ export class SecurityMonitor {
|
|
|
605
605
|
threadId = (await this.deps.rest.startThread(alert.channelId, alert.messageId, `Rule ${alert.event.rule} on ${alert.event.agent}`)).id;
|
|
606
606
|
} catch (err) {
|
|
607
607
|
this.deps.log(`security: thread for ${alert.key} failed: ${reason(err)}`);
|
|
608
|
-
await this.post(alert.channelId, { content: `❌
|
|
608
|
+
await this.post(alert.channelId, { content: `❌ Thread failed to open (${reason(err)}); ask the security specialist in the channel.`, replyTo: alert.messageId });
|
|
609
609
|
await this.setInvestigation(alert.messageId, "failed");
|
|
610
610
|
return;
|
|
611
611
|
}
|
|
612
612
|
}
|
|
613
613
|
let ok = false;
|
|
614
614
|
try {
|
|
615
|
-
const starter = await this.deps.rest.createMessage(threadId, { content: `🔎
|
|
615
|
+
const starter = await this.deps.rest.createMessage(threadId, { content: `🔎 Requested by <@${click.userId}>. The security specialist reads only and may ask other specialists; a risky read asks an owner here.` });
|
|
616
616
|
await this.setInvestigation(alert.messageId, "running", threadId);
|
|
617
617
|
ok = await this.deps.investigate({ threadId, starterId: starter.id, userId: click.userId, task: investigationTask(alert) });
|
|
618
618
|
} catch (err) {
|