Files
loki/scripts/test/failure-message-pairing.ts
CatoandClaude Fable 5.1 95c40a9cd8 refactor: rename the product from FleetCrown to Loki (#695)
The product, its assistant, the repo, the host and every unit on the box now
share one name. 638 files, ~3,000 mentions: UI copy, config, env keys
(FLEETCROWN_* -> LOKI_*), systemd units (fleetcrown-* -> loki-*), docs,
articles, the deploy workflow other repos reuse, and nine file names.

- Three article slugs carried the old name and had been shared; permanent
  redirects keep those links alive (next.config.ts).
- test-no-retired-name.sh now also forbids the old product name across the
  whole repo, so the rename cannot creep back through templates and examples.
- ASSISTANT_STACK collapses the product and the assistant into one entry,
  because they are now the same name.

Infra was cut over ahead of this merge: /opt/loki, loki-* units, the `loki`
database and role, loki.orangecat.ch (old host 308s to it; /api, /widget,
/embed keep proxying), GitHub repos bitbaum/loki and bitbaum/loki-releases.
The Resend sending domain stays fleetcrown.orangecat.ch until the new domain
is verified in DNS.


Claude-Session: https://claude.ai/code/session_016YJVAanfj8keVSXyZnTemh

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-13 16:13:10 -07:00

56 lines
2.3 KiB
TypeScript

// Every failure the desktop runner can throw about a missing agent must classify
// to a real remedy.
//
// `desktop/src/main/poller.ts` composes its own error strings. `remedyForFailure`
// matches on literal phrases. They are two definitions of the same sentence in
// two independently-released codebases, so they drift — and the drift is
// SILENT, because an unclassified failure still renders a plausible Retry
// button. This pairs the producer with the matcher: read the literals poller.ts
// actually throws, and assert each one that talks about an agent/terminal is
// recognised. Reword either side and this fails before anyone sees a button
// that cannot work.
//
// Run: npx tsx scripts/test/failure-message-pairing.ts
import { readFileSync } from "fs";
import { join, dirname } from "path";
import { fileURLToPath } from "url";
import { remedyForFailure, FAILURE_REMEDY, FAILURE_PHRASE } from "../../src/lib/failure-remedy";
const ROOT = join(dirname(fileURLToPath(import.meta.url)), "..", "..");
const POLLER = join(ROOT, "desktop/src/main/poller.ts");
let pass = 0;
let fail = 0;
function ok(cond: boolean, label: string) {
if (cond) pass++;
else {
fail++;
console.error(`✗ ${label}`);
}
}
const src = readFileSync(POLLER, "utf8");
const thrown = [...src.matchAll(/throw new Error\(\s*`([^`]{6,160})`/g)]
.map((m) => m[1].replace(/\$\{[^}]+\}/g, "loki").trim())
.concat([...src.matchAll(/throw new Error\(\s*'([^']{6,160})'/g)].map((m) => m[1].trim()))
.filter((s) => /running agent|terminal|focus|session/i.test(s));
ok(thrown.length >= 1, `found agent/terminal throws in poller.ts (got ${thrown.length})`);
// The invariant is RECOGNITION: a message must reach a remedy because the
// classifier was taught it, never by accident of the default.
const PHRASES = Object.values(FAILURE_PHRASE);
for (const message of thrown) {
const recognised = PHRASES.some((p) => message.toLowerCase().includes(p));
ok(recognised, `poller throw is recognised by a FAILURE_PHRASE: ${JSON.stringify(message)}`);
if (recognised) {
ok(
remedyForFailure(message) !== FAILURE_REMEDY.RETRY,
`recognised message does not fall to RETRY: ${JSON.stringify(message)}`,
);
}
}
console.log(`failure-message-pairing: ${pass} passed, ${fail} failed`);
if (fail > 0) process.exit(1);