mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-06 06:58:40 +01:00
* design: Loki has no orange; the public call to action is the achromatic accent The app's own buttons went monochrome on 2026-10-19; the public site kept a warm orange (#ff5c00) on Start a project, Get started, the auth submit, the focus ring and the essay progress bar. It is not Bitcoin orange and it means nothing on a product that is not about Bitcoin (owner, 2026-11-11). - --accent-warm, --accent-warm-hover and --public-accent are removed; every class that used them reads --accent-primary / --accent-hover, so one filled button exists in Loki and it is theme-aware - --on-accent is the inverted text. It was a fixed near-black, which on the near-black light-theme accent left .ui-btn-xs.ui-btn-primary unreadable - the focus ring and the public glow are neutral - token-drift declares the divergence from @bitbaum/design-tokens; the widget theme is regenerated from the tokens Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmtUQb9BM11ycpApwGq * fix(workbench): a failed task says why and gives the words back Sent an OrangeCat task from the workbench on 2026-11-11. Claude was signed out on the cloud runner; the status API said so with the fix, and the composer showed the two words 'Dispatch failed' over an emptied box. - dispatchFailureForPerson: a signed-out agent is named in the sender's words; any other reason is passed through instead of dropped - the composer shows that reason under the label and offers 'Put my words back', since the box is cleared on send Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmtUQb9BM11ycpApwGq * fix(nav): the phone's chat screen names Home, Projects and Terminal The owner, signed in on a phone on 2026-11-11, could not find the terminal. The chat is the default screen and hides the tab bar; its left button opened a list of chats and nothing else, and its menu offered 'Projects' (which only set the chat's project) and 'Everything else'. The page itself was called Sessions, so no menu contained the word. - CHAT_PLACES (config/navigation.ts) is one list of Home, Projects, Terminal - the chat menu lists them by name, then 'All pages'; the item that sets the chat's project says so - the chats panel the left button opens lists the same three, phones only - the page is called Terminal in the nav, its title and its links Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmtUQb9BM11ycpApwGq * fix(sessions): a signed-out Claude is one button in the chat view A session opens in its Chat view. When Claude's login had expired, that view showed the agent's own line, 'Please run /login', and reply chips that would fail the same way; the 'Sign in /login' button existed only in the Terminal view. The owner, on a phone, could not find how to sign in (2026-11-11). The chat view reads the reply through the same detector as the terminal (screenActions) and offers 'Sign Claude in', which types /login and switches to the terminal where the link is printed. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmtUQb9BM11ycpApwGq --------- Co-authored-by: Claude <noreply@anthropic.com>
327 lines
12 KiB
TypeScript
327 lines
12 KiB
TypeScript
/**
|
||
* Inline tests for dispatch queue status copy.
|
||
* Run: npx tsx scripts/test/dispatch-status.ts
|
||
*/
|
||
import {
|
||
deriveDispatchLiveStatus,
|
||
deriveMultiDispatchView,
|
||
dispatchAssistantContent,
|
||
dispatchFailureForPerson,
|
||
dispatchStatusLabel,
|
||
dispatchToneDotClass,
|
||
elapsedLabel,
|
||
} from "@/lib/dispatch-status";
|
||
import { EXECUTOR_COPY } from "@/config/executor-copy";
|
||
import { BUILDER_CHANNELS } from "@/lib/constants/statuses";
|
||
|
||
const offline = dispatchStatusLabel({
|
||
mode: "queued",
|
||
runnerConnected: false,
|
||
warning: "runner-offline",
|
||
});
|
||
if (!offline.warn || offline.label !== EXECUTOR_COPY.queuedWhenOffline) {
|
||
throw new Error("offline queued label");
|
||
}
|
||
|
||
const online = dispatchStatusLabel({ mode: "queued", runnerConnected: true });
|
||
if (online.warn || online.label !== EXECUTOR_COPY.queuedWithBuilderOnline) {
|
||
throw new Error("online queued label");
|
||
}
|
||
|
||
const direct = dispatchStatusLabel({ mode: "direct" });
|
||
if (direct.warn || direct.label !== "Running now") {
|
||
throw new Error("direct label");
|
||
}
|
||
|
||
const md = dispatchAssistantContent("loki", {
|
||
ok: true,
|
||
mode: "queued",
|
||
runnerConnected: true,
|
||
});
|
||
if (!md.includes("loki") || !md.includes("runner")) {
|
||
throw new Error("assistant content");
|
||
}
|
||
|
||
const delivered = deriveDispatchLiveStatus({
|
||
claimedAt: new Date(),
|
||
executedAt: new Date(),
|
||
result: { ok: true, verified: true },
|
||
run: { state: "waiting", outcome: null },
|
||
});
|
||
if (delivered.label !== "Delivered to agent" || delivered.terminal) {
|
||
throw new Error("tracked delivery must keep polling");
|
||
}
|
||
|
||
const completed = deriveDispatchLiveStatus({
|
||
claimedAt: new Date(),
|
||
executedAt: new Date(),
|
||
result: { ok: true, verified: true },
|
||
run: { state: "done", outcome: "success" },
|
||
});
|
||
if (completed.label !== "Completed" || !completed.terminal || completed.tone !== "positive") {
|
||
throw new Error("successful run completion");
|
||
}
|
||
|
||
const timeout = deriveDispatchLiveStatus({
|
||
claimedAt: new Date(),
|
||
executedAt: new Date(),
|
||
result: { ok: true, verified: true },
|
||
run: { state: "error", outcome: "timeout", payload: { error: "timed out" } },
|
||
});
|
||
if (timeout.label !== "Run timed out" || !timeout.terminal || timeout.tone !== "negative") {
|
||
throw new Error("timed out run completion");
|
||
}
|
||
|
||
// ── Naming the builder ──────────────────────────────────────────────────────
|
||
//
|
||
// The operator should never have to wonder which machine has their work. Two
|
||
// rules, and the second matters more than the first: name it when we know, and
|
||
// NEVER name it when we don't — a label pointing at the wrong computer sends
|
||
// someone hunting through a checkout that never had the change.
|
||
|
||
const onLocal = dispatchStatusLabel({ mode: "direct", channel: "local" });
|
||
if (!onLocal.label.includes(EXECUTOR_COPY.ranOn.local) || onLocal.warn) {
|
||
throw new Error("direct dispatch must name the local runner");
|
||
}
|
||
|
||
const onCloud = dispatchStatusLabel({ mode: "direct", channel: "cloud" });
|
||
if (!onCloud.label.includes(EXECUTOR_COPY.ranOn.cloud)) {
|
||
throw new Error("direct dispatch must name the cloud runner");
|
||
}
|
||
|
||
// The highest-value case: nothing is happening, and this says which machine to
|
||
// wake rather than a generic "builder offline".
|
||
const offlineNamed = dispatchStatusLabel({
|
||
mode: "queued",
|
||
runnerConnected: false,
|
||
warning: "runner-offline",
|
||
channel: "local",
|
||
});
|
||
if (!offlineNamed.label.includes(EXECUTOR_COPY.ranOn.local) || !offlineNamed.warn) {
|
||
throw new Error("offline queue must name the runner it is waiting on");
|
||
}
|
||
|
||
const queuedNamed = dispatchStatusLabel({
|
||
mode: "queued",
|
||
runnerConnected: true,
|
||
channel: "cloud",
|
||
});
|
||
if (!queuedNamed.label.includes(EXECUTOR_COPY.ranOn.cloud) || queuedNamed.warn) {
|
||
throw new Error("queued-with-builder must name the runner");
|
||
}
|
||
|
||
// Never guess. Messages persisted before routing was recorded carry no channel;
|
||
// they must fall back to the unnamed copy, not to a default machine.
|
||
for (const missing of [undefined, null]) {
|
||
const bare = dispatchStatusLabel({ mode: "direct", channel: missing });
|
||
if (bare.label !== "Running now") {
|
||
throw new Error(`absent channel must not be named — got ${bare.label}`);
|
||
}
|
||
const bareQueued = dispatchStatusLabel({
|
||
mode: "queued",
|
||
runnerConnected: true,
|
||
channel: missing,
|
||
});
|
||
if (bareQueued.label !== EXECUTOR_COPY.queuedWithBuilderOnline) {
|
||
throw new Error(`absent channel must keep the unnamed queued copy — got ${bareQueued.label}`);
|
||
}
|
||
}
|
||
|
||
// A failed dispatch names no machine: the failure, not the locus, is the point.
|
||
const failedNamed = dispatchStatusLabel({ ok: false, mode: "direct", channel: "cloud" });
|
||
if (failedNamed.label !== "Dispatch failed" || !failedNamed.warn) {
|
||
throw new Error("failure copy must not be altered by the channel");
|
||
}
|
||
|
||
// The assistant transcript carries it too, so the chat log stays self-explaining.
|
||
const namedContent = dispatchAssistantContent("loki", {
|
||
ok: true,
|
||
mode: "queued",
|
||
runnerConnected: true,
|
||
channel: "cloud",
|
||
});
|
||
if (!namedContent.includes(EXECUTOR_COPY.ranOn.cloud)) {
|
||
throw new Error("assistant content must name the runner");
|
||
}
|
||
|
||
// Every channel in the union has a name — no channel can render as "undefined".
|
||
for (const channel of BUILDER_CHANNELS) {
|
||
const name = EXECUTOR_COPY.ranOn[channel];
|
||
if (!name || typeof name !== "string") {
|
||
throw new Error(`channel ${channel} has no operator-facing name`);
|
||
}
|
||
if (!dispatchStatusLabel({ mode: "direct", channel }).label.includes(name)) {
|
||
throw new Error(`channel ${channel} is not surfaced in its label`);
|
||
}
|
||
}
|
||
|
||
// ── Fan-out dispatch badge (2026-08-19) ─────────────────────────────────────
|
||
//
|
||
// Reported: a "develop these 3 projects" dispatch that started 0 of 3 showed
|
||
// the same generic green "Dispatched" chip as one that started 3 of 3 — the
|
||
// footer badge never read the real per-project attempts, only the reply text
|
||
// above it (formatMultiDispatchReply) was honest. deriveMultiDispatchView is
|
||
// the fix: the badge and the text now agree, because they read the same data.
|
||
|
||
const allStarted = deriveMultiDispatchView([
|
||
{ projectKey: "loki", ok: true },
|
||
{ projectKey: "orangecat", ok: true },
|
||
]);
|
||
if (allStarted.tone !== "positive" || allStarted.primaryProject !== "loki") {
|
||
throw new Error(
|
||
`all-started must be positive and link the first started project — got ${JSON.stringify(allStarted)}`,
|
||
);
|
||
}
|
||
|
||
const noneStarted = deriveMultiDispatchView([
|
||
{ projectKey: "loki", ok: false, skipped: true, reason: "busy" },
|
||
{ projectKey: "orangecat", ok: false, skipped: true, reason: "pending_command" },
|
||
]);
|
||
if (noneStarted.tone !== "negative" || noneStarted.primaryProject !== null) {
|
||
throw new Error(
|
||
`0-of-N must be negative with no link to watch — got ${JSON.stringify(noneStarted)}`,
|
||
);
|
||
}
|
||
if (!noneStarted.label.includes("0 of 2")) {
|
||
throw new Error(`0-of-N label must say so plainly — got "${noneStarted.label}"`);
|
||
}
|
||
|
||
const partialStarted = deriveMultiDispatchView([
|
||
{ projectKey: "loki", ok: true },
|
||
{ projectKey: "orangecat", ok: false, skipped: true, reason: "busy" },
|
||
{ projectKey: "datacat", ok: false, skipped: true, reason: "concurrency_cap" },
|
||
]);
|
||
if (partialStarted.tone !== "warning" || partialStarted.primaryProject !== "loki") {
|
||
throw new Error(
|
||
`partial start must warn and link a project that actually started — got ${JSON.stringify(partialStarted)}`,
|
||
);
|
||
}
|
||
if (!partialStarted.label.includes("1 of 3")) {
|
||
throw new Error(
|
||
`partial-start label must say how many of how many — got "${partialStarted.label}"`,
|
||
);
|
||
}
|
||
|
||
// The link must never point at a SKIPPED project just because it happened to
|
||
// be first in the list — that was the second half of the reported bug.
|
||
const skippedFirst = deriveMultiDispatchView([
|
||
{ projectKey: "skipped-one", ok: false, skipped: true, reason: "busy" },
|
||
{ projectKey: "started-one", ok: true },
|
||
]);
|
||
if (skippedFirst.primaryProject !== "started-one") {
|
||
throw new Error(
|
||
`link must skip past a failed first attempt to the project that actually started — got ${skippedFirst.primaryProject}`,
|
||
);
|
||
}
|
||
|
||
// Every tone in the union renders a real dot class — none can fall through to
|
||
// undefined and print "undefined" as a CSS class in the DOM.
|
||
for (const tone of ["positive", "warning", "negative", "neutral"] as const) {
|
||
const cls = dispatchToneDotClass(tone);
|
||
// Sized (ui-dot) AND coloured (ui-dot-<tone>): a colour class alone renders 0×0.
|
||
if (!cls || !cls.split(" ").includes("ui-dot") || !/\bui-dot-[a-z]+\b/.test(cls)) {
|
||
throw new Error(`tone ${tone} has no dot class — got "${cls}"`);
|
||
}
|
||
}
|
||
|
||
// ── Elapsed time on the states that can go quiet ────────────────────────────
|
||
//
|
||
// Observed 2026-09-18: a dispatch sat on "waiting for a completion handoff" for
|
||
// five minutes with no elapsed time, no heartbeat and no log. A dead builder
|
||
// and a busy one read identically, and the only way to tell them apart was to
|
||
// open another window and read git log.
|
||
|
||
const T0 = Date.parse("2026-09-18T06:40:00.000Z");
|
||
const at = (secs: number) => T0 + secs * 1000;
|
||
|
||
{
|
||
// The exact shape that went quiet: executed, run open, waiting on a handoff.
|
||
const view = deriveDispatchLiveStatus(
|
||
{
|
||
claimedAt: new Date(T0).toISOString(),
|
||
executedAt: new Date(T0).toISOString(),
|
||
result: {},
|
||
run: { state: "waiting", outcome: null },
|
||
},
|
||
at(305),
|
||
);
|
||
if (view.terminal) throw new Error("a run awaiting a handoff is not terminal");
|
||
if (!view.detail?.includes("5m")) {
|
||
throw new Error(`waiting detail must carry elapsed time — got "${view.detail}"`);
|
||
}
|
||
// The internal name for the mechanism is not what a person needs.
|
||
if (view.detail?.includes("completion handoff")) {
|
||
throw new Error("jargon leaked back into the waiting state");
|
||
}
|
||
}
|
||
|
||
{
|
||
// Picked up but not yet executed — timed from claimedAt, not executedAt.
|
||
const view = deriveDispatchLiveStatus(
|
||
{ claimedAt: new Date(T0).toISOString(), executedAt: null, result: {}, run: null },
|
||
at(90),
|
||
);
|
||
if (!view.detail?.includes("1m")) {
|
||
throw new Error(`picked-up detail must carry elapsed time — got "${view.detail}"`);
|
||
}
|
||
}
|
||
|
||
{
|
||
// A settled run says what happened, not how long it has been happening.
|
||
const view = deriveDispatchLiveStatus(
|
||
{
|
||
claimedAt: new Date(T0).toISOString(),
|
||
executedAt: new Date(T0).toISOString(),
|
||
result: {},
|
||
run: { state: "done", outcome: "success" },
|
||
},
|
||
at(9999),
|
||
);
|
||
if (!view.terminal) throw new Error("a successful run is terminal");
|
||
if (view.detail?.includes("·")) {
|
||
throw new Error("a finished run must not keep counting");
|
||
}
|
||
}
|
||
|
||
// The label itself, across the boundaries that matter.
|
||
const labels: [number, string | null][] = [
|
||
[3, "just now"],
|
||
[42, "42s"],
|
||
[60, "1m"],
|
||
[305, "5m"],
|
||
[3600, "1h"],
|
||
[4500, "1h 15m"],
|
||
];
|
||
for (const [secs, expected] of labels) {
|
||
const got = elapsedLabel(new Date(T0).toISOString(), at(secs));
|
||
if (got !== expected) throw new Error(`elapsed ${secs}s → expected ${expected}, got ${got}`);
|
||
}
|
||
// No timestamp is "no idea", never "0s" — a confident zero is worse than silence.
|
||
if (elapsedLabel(null) !== null) throw new Error("a missing timestamp has no elapsed label");
|
||
// A clock that disagrees must not render a negative age.
|
||
if (elapsedLabel(new Date(T0).toISOString(), at(-30)) !== null) {
|
||
throw new Error("a future timestamp has no elapsed label");
|
||
}
|
||
|
||
// A failed dispatch says why, in the sender's words. Seen 2026-11-11: the
|
||
// workbench showed "Dispatch failed" and nothing else for a signed-out agent.
|
||
{
|
||
const runner =
|
||
"claude is not authenticated (401 / login required) — the prompt was delivered but the agent can't run. On the runner host, remove any stale ~/.claude/.credentials.json and set CLAUDE_CODE_OAUTH_TOKEN (claude setup-token).";
|
||
const said = dispatchFailureForPerson(runner);
|
||
if (!said || !said.startsWith("Claude is signed out")) {
|
||
throw new Error(`a signed-out agent is named plainly, got: ${said}`);
|
||
}
|
||
if (/credentials\.json|OAUTH_TOKEN|401/.test(said)) {
|
||
throw new Error("the sender is not shown the administrator's instructions");
|
||
}
|
||
if (dispatchFailureForPerson("workspace missing") !== "workspace missing") {
|
||
throw new Error("an unrecognised reason is passed through, not dropped");
|
||
}
|
||
if (dispatchFailureForPerson(" ") !== null || dispatchFailureForPerson(null) !== null) {
|
||
throw new Error("no reason is no sentence");
|
||
}
|
||
}
|
||
|
||
console.log("✓ dispatch-status tests passed");
|