mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 06:37:38 +01:00
Three follow-ups from sweeping the earlier findings. Two of the four I had
carried forward did NOT survive checking and are dropped: /api/control/dispatch
is a real route, so the docs referencing it are correct; and
scripts/test/push-notifications.ts exists. Verifying first is why this commit
is smaller than the list that prompted it.
1. THE TEST NOBODY RAN, FOR A REASON THAT WAS NEVER TRUE
scripts/test/push-notifications.ts read scripts/agent-hook-bridge.sh, which was
deleted on 2026-06-11 in 956ccf64 ("delete the bash daemon and bridge files").
It threw ENOENT and the suite exited 1. Its entry in test-unit.ts SKIP said
"needs push/web-push env — run manually". That was never the reason: every
check in the file is a static file read and it needs no environment at all.
A wrong skip reason is worse than no skip. It answers the question that would
have found the bug, so the red looked accounted for and nobody looked again for
three months.
Retargeted rather than deleted. The behaviour moved instead of going away — a
closing run reaches the operator through notify-close.ts → pushToUser →
push-fanout — and scripts/test/notify-close.ts covers that module without
mentioning push at all. So "an agent finished, tell the operator" was asserted
by nobody. Deleting the check would have quietly ratified that hole.
Removed from SKIP, so it now runs in test:unit (132/132) and therefore in CI.
Mutation-proven: renaming the pushToUser call fails with "notify-close must
call pushToUser" (exit 1); restored, exit 0.
2. THE BOX IS HALF THE MACHINE THE DOCS DESCRIBE
Measured 2026-09-04: nproc 4, 7746 MiB, 75 G disk, 4 GB swap. That is a CX33.
Three docs said CX43, 8 vCPU / 16 GB, 40 GB disk — every figure but the swap
wrong, in the direction that matters: planning against 16 GB on an 8 GB box is
how you meet the OOM killer.
src/app/api/system/hetzner/route.ts has said "the box is a cx33" all along, so
this was code and docs disagreeing with the code being right. Note the shape of
the drift: CPU and RAM went DOWN while disk went UP (40→75), which is what a
disk-inclusive rescale to a smaller tier looks like — plausibly to escape the
disk-full problem the old caveat describes. The June runbook entry is kept as
history and marked superseded rather than rewritten.
The docs now point at /api/system/hetzner instead of restating numbers. A
hardcoded spec is a second source of truth that rots silently, which is exactly
what happened here between June and September.
3. THE COMPOSER STATUS, FINISHED
#479 gave this line its own row below `sm` but kept `sm:truncate`, which left it
at 57% on a 1440 viewport — "Autopilot on: queue is empty, so FleetCr…". That is
the same defect as the phone's 14%, just less obvious, and there is no `title`
here so the remainder is unreachable at every width. It now wraps everywhere.
Costs one toolbar line when the sentence is long; truncating cost the half of
the sentence that says what will happen.
pnpm run verify passes (repo moved to pnpm in #478).
Claude-Session: https://claude.ai/code/session_01UvjGNAS9CMfEGNW26tUR4P
Co-authored-by: Mao Nakamoto <41178744+maonakamoto@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
108 lines
4.7 KiB
TypeScript
108 lines
4.7 KiB
TypeScript
/**
|
|
* Inline self-tests for Web Push (Stage 5) — keeps the subscribe/notify
|
|
* surface, the service worker, and the run-close notification wired together.
|
|
* Run: npm run test:push-notifications
|
|
*
|
|
* Needs no environment: every check is a static file read. It was excluded from
|
|
* test:unit for years as "needs push/web-push env", which was never true — see
|
|
* the note on the run-close check below.
|
|
*/
|
|
import { readFileSync, existsSync } from "fs";
|
|
|
|
function assert(condition: boolean, message: string): void {
|
|
if (!condition) throw new Error(message);
|
|
}
|
|
|
|
function runTests(): void {
|
|
let passed = 0;
|
|
const check = (label: string, fn: () => void) => {
|
|
fn();
|
|
passed += 1;
|
|
console.log(` ✓ ${label}`);
|
|
};
|
|
|
|
check("push_subscriptions schema is exported", () => {
|
|
const index = readFileSync("src/db/schema/index.ts", "utf8");
|
|
assert(/push-subscriptions/.test(index), "schema index must export push-subscriptions");
|
|
const schema = readFileSync("src/db/schema/push-subscriptions.ts", "utf8");
|
|
assert(/pushSubscriptions/.test(schema), "pushSubscriptions table must exist");
|
|
});
|
|
|
|
check("migration SQL exists", () => {
|
|
assert(
|
|
existsSync("drizzle/0020_push_subscriptions.sql"),
|
|
"0020_push_subscriptions.sql must exist",
|
|
);
|
|
});
|
|
|
|
check("API routes exist (subscribe + notify)", () => {
|
|
assert(existsSync("src/app/api/push/subscribe/route.ts"), "subscribe route must exist");
|
|
assert(existsSync("src/app/api/push/notify/route.ts"), "notify route must exist");
|
|
const notify = readFileSync("src/app/api/push/notify/route.ts", "utf8");
|
|
assert(/getApiUserId/.test(notify), "notify must accept runner bearer auth");
|
|
assert(/focus=/.test(notify), "notify payload must deep-link to /control?focus=");
|
|
});
|
|
|
|
check("service worker handles push + notificationclick", () => {
|
|
const sw = readFileSync("public/sw.js", "utf8");
|
|
assert(/addEventListener\("push"/.test(sw), "sw.js must listen for push");
|
|
assert(/addEventListener\("notificationclick"/.test(sw), "sw.js must handle notificationclick");
|
|
assert(/showNotification/.test(sw), "sw.js must show OS notifications");
|
|
});
|
|
|
|
// "An agent finished, tell the operator" — the point of this whole surface.
|
|
//
|
|
// This used to read scripts/agent-hook-bridge.sh and assert a bash helper
|
|
// called push_notify_stop. That file was deleted on 2026-06-11 (956ccf64,
|
|
// "delete the bash daemon and bridge files") when the Stop hook moved into
|
|
// TypeScript, so the check threw ENOENT and the whole suite exited 1 — while
|
|
// its entry in scripts/test-unit.ts SKIP said it "needs push/web-push env",
|
|
// which was never why it failed. A test excluded from CI for a reason that
|
|
// was not the real one is a test that rots unread: nothing has asserted this
|
|
// path for three months.
|
|
//
|
|
// Retargeted, not deleted. The behaviour did not go away, it moved —
|
|
// notify-close.ts reaches the operator through pushToUser now — and
|
|
// scripts/test/notify-close.ts covers that module without mentioning push at
|
|
// all. Deleting the check would have quietly ratified the coverage hole.
|
|
check("a closing run still pushes to the operator", () => {
|
|
const closer = readFileSync("src/lib/orchestration/notify-close.ts", "utf8");
|
|
assert(
|
|
/from "@\/lib\/push-fanout"/.test(closer),
|
|
"notify-close must reach the operator through push-fanout",
|
|
);
|
|
assert(/pushToUser\s*\(/.test(closer), "notify-close must call pushToUser");
|
|
const fanout = readFileSync("src/lib/push-fanout.ts", "utf8");
|
|
assert(
|
|
/listSubscriptionsForUser\s*\(/.test(fanout),
|
|
"push-fanout must look up the operator's subscribed devices",
|
|
);
|
|
// A fan-out that throws would take its caller down with it, and the caller
|
|
// is a run finishing — the notification is the least important thing on
|
|
// that path. The module's own contract says "must never throw".
|
|
assert(
|
|
/catch\b/.test(fanout),
|
|
"push-fanout must be fire-and-forget, never throwing at callers",
|
|
);
|
|
});
|
|
|
|
check("NotificationsPill is wired into AppTopBar", () => {
|
|
const bar = readFileSync("src/components/shell/AppTopBar.tsx", "utf8");
|
|
assert(/NotificationsPill/.test(bar), "AppTopBar must render NotificationsPill");
|
|
});
|
|
|
|
check("configureWebPush catches invalid VAPID keys", () => {
|
|
const lib = readFileSync("src/lib/push.ts", "utf8");
|
|
assert(
|
|
/try \{[\s\S]*setVapidDetails/.test(lib),
|
|
"configureWebPush must catch setVapidDetails throws",
|
|
);
|
|
const notify = readFileSync("src/app/api/push/notify/route.ts", "utf8");
|
|
assert(/catch \(err/.test(notify), "notify route must catch unhandled errors");
|
|
});
|
|
|
|
console.log(`\n${passed}/${passed} passed`);
|
|
}
|
|
|
|
runTests();
|