Files
loki/scripts/test/push-notifications.ts
T
Mao NakamotoandClaude Opus 4.8 7432f16053 refactor(runner): rename daemon→runner across the live system, keep legacy contracts
The bash daemon was deleted in Session 4 of killing-the-bash-daemon; Fleet
Runner (the desktop poller) is the local executor now. This retires the
'daemon' name from everything describing the live system — constants
(DAEMON_*→RUNNER_*), types (DaemonStateKey→RunnerStateKey), the status
banner component, state-derivation fns, control props, CSS classes
(ui-control-fleet-daemon→-runner), and comments/UI strings.

Backward-compat shims (no breakage to deployed Fleet Runner installs):
- src/lib/constants/daemon.ts re-exports RUNNER_* under the old DAEMON_*
  names for the desktop Electron build until it points at the runner path.
- Fleet Doctor reads runner.env, falls back to legacy daemon.env.

Deliberately KEPT as 'daemon' (they name the genuinely-dead/legacy thing):
the deprecated DAEMON_TOKEN bearer contract, the /api/agent/daemon 410
tombstone, the legacyDaemon developer download, and historical
killing-the-bash-daemon references. systemctl daemon-reload / NX_DAEMON
left untouched (not ours).

tsc clean · eslint 0 errors · test:home 97/97 · smoke 44/44

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-15 01:05:12 +02:00

70 lines
3.0 KiB
TypeScript

/**
* Inline self-tests for Web Push (Stage 5) — keeps the subscribe/notify
* surface, service worker, and Stop-hook bridge wired together.
* Run: npm run test:push-notifications
*/
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");
});
check("Stop hook calls push_notify_stop", () => {
const sh = readFileSync("scripts/agent-hook-bridge.sh", "utf8");
assert(/push_notify_stop/.test(sh), "push_notify_stop helper must exist");
assert(/\/api\/push\/notify/.test(sh), "push_notify_stop must POST /api/push/notify");
const stopCalls = sh.match(/push_notify_stop\s+"\$TAB_NAME"/g) ?? [];
assert(stopCalls.length >= 1, "handle_stop must invoke push_notify_stop");
});
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();