Files
loki/scripts/test/fleet-kick.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

115 lines
3.8 KiB
TypeScript

/**
* Inline tests for fleet-kick helpers and Loki NL detection.
* Run: npm run test:fleet-kick
*/
import assert from "node:assert/strict";
import {
formatFleetKickReply,
sortProjectsForKick,
type FleetKickReplyResult,
} from "@/lib/fleet-kick-format";
import { isDevelopAllFleetRequest } from "@/lib/loki-fleet-commands";
import { resolveDispatchTargets } from "@/lib/loki/dispatch-targets";
import { deriveProjectLoopReadiness } from "@/lib/project-loop-readiness";
import {
shouldDispatchScreenshot,
isDefaultVisionQuestion,
isScreenshotImplementIntent,
} from "@/lib/loki/screenshot-dispatch";
import type { CommandResolution } from "@/lib/command-resolve";
function testSortProjectsForKick() {
const ready = new Set(["beta", "alpha"]);
const sorted = sortProjectsForKick(["zeta", "alpha", "beta", "gamma"], ready);
assert.deepEqual(sorted, ["alpha", "beta", "gamma", "zeta"]);
}
function testDevelopAllFleetPhrases() {
assert.equal(isDevelopAllFleetRequest("develop all my projects"), true);
assert.equal(isDevelopAllFleetRequest("build the whole fleet"), true);
assert.equal(isDevelopAllFleetRequest("start every project"), true);
assert.equal(isDevelopAllFleetRequest("code review for loki"), false);
assert.equal(isDevelopAllFleetRequest("next best for loki"), false);
}
function testDispatchTargets() {
const resolution = (partial: Partial<CommandResolution>): CommandResolution => ({
kind: "command",
projectKey: null,
intentId: "quality",
prompt: "code review",
needsProject: false,
reason: "test",
...partial,
});
assert.deepEqual(
resolveDispatchTargets({
resolution: resolution({ projectKey: "a" }),
selectedProjects: ["b", "c"],
namedInText: null,
}),
["b", "c"],
);
assert.deepEqual(
resolveDispatchTargets({
resolution: resolution({ projectKey: "a" }),
selectedProjects: ["b", "c"],
namedInText: "a",
}),
["a"],
);
}
function testScreenshotDispatch() {
assert.equal(
shouldDispatchScreenshot("What's wrong here and what should we change?", true, "loki"),
true,
);
assert.equal(shouldDispatchScreenshot("implement this ui", true, "loki"), true);
assert.equal(shouldDispatchScreenshot("what do you think?", true, "loki"), false);
assert.equal(shouldDispatchScreenshot("implement this", true, null), false);
assert.equal(isDefaultVisionQuestion("What's wrong here and what should we change?"), true);
assert.equal(isScreenshotImplementIntent("please implement the layout"), true);
}
function testProjectLoopReadiness() {
assert.equal(deriveProjectLoopReadiness({ dirPath: "/repo/app" }).label, "Loop-ready");
const missing = deriveProjectLoopReadiness({ dirPath: null });
assert.equal(missing.reason, "no_path");
assert.equal(missing.label, "Needs path");
const paused = deriveProjectLoopReadiness({
dirPath: "/repo/app",
autoInjectModeOverride: "off",
});
assert.equal(paused.reason, "project_paused");
}
function testFleetKickReplyExplainsSkippedProjects() {
const result: FleetKickReplyResult = {
runnerConnected: false,
fleetMode: "on",
kicked: 0,
activeBefore: 0,
details: [
{ projectKey: "profile-only", outcome: "skipped", reason: "no_path" },
{ projectKey: "queued", outcome: "skipped", reason: "pending_command" },
],
message: "No idle projects to kick right now.",
};
const reply = formatFleetKickReply(result);
assert.match(reply, /\*\*Skipped:\*\*/);
assert.match(reply, /profile-only: needs a local path/);
assert.match(reply, /queued: already queued/);
}
testSortProjectsForKick();
testDevelopAllFleetPhrases();
testDispatchTargets();
testScreenshotDispatch();
testProjectLoopReadiness();
testFleetKickReplyExplainsSkippedProjects();
console.log("✓ fleet-kick helper tests passed");