Files
loki/scripts/test/feedback-run-step.ts
CatoandClaude 5b0f93f117 feat(copy): the machine that runs the work is a runner, not a builder (#1482)
"Builder" meant three things on Loki's screens: the machine that runs
agent work ("Cloud builder", "Waiting for a builder"), the role on a
project, and the approved builder a customer books through Bitbaum. The
person keeps the word; the machine becomes a runner, the word the code
and the desktop app already use (box-runner, Fleet Runner, "Hosted
runner"). Not "engine": on screen that is already the model and
subscription a change is built with.

- every user-facing string where "builder" meant the machine, with
  EXECUTOR_COPY as the source, plus docs, quickstart, pricing and voice
- unchanged: the Builder role, "a builder or owner can start work",
  people who build ("App builders", "for one builder running Loki"),
  the site widget's "Send to builder" (the site's maker), stored
  transcript parsing, and internal codes and paths (needs-builder,
  cloud-builder-private, /api/builder/presence)
- tests that pin the wording follow it


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

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-30 22:30:16 +01:00

274 lines
8.9 KiB
TypeScript

import assert from "node:assert/strict";
import { summarizeRunStep, furthestRunEventKind } from "../../src/lib/feedback/run-step";
import {
deriveFeedbackWork,
FEEDBACK_WORK_PHASE,
WAITING_ON,
} from "../../src/lib/feedback/work-phase";
import { FEEDBACK_STATUS } from "../../src/lib/constants/statuses";
import { ORCH_STATE } from "../../src/lib/orchestration/contract";
const waitingCloud = summarizeRunStep({
latestKind: "dispatched",
deliveredAt: null,
lastProgressAt: null,
pendingUnclaimed: true,
channel: "cloud",
localOnline: false,
cloudOnline: false,
});
assert.equal(waitingCloud.kind, "waiting_builder");
assert.match(waitingCloud.summary, /cloud runner/i);
// 2026-10-12: the cloud builder was offline all night and this read "Command
// is in the cloud queue. If this stays put, Watch shows why" — nothing showed
// why. Offline is a fact the line has to state.
assert.match(waitingCloud.summary, /offline/i);
assert.match(waitingCloud.detail ?? "", /nothing starts until it reconnects/i);
assert.doesNotMatch(waitingCloud.detail ?? "", /Watch shows why/);
const waitingCloudUp = summarizeRunStep({
latestKind: "dispatched",
deliveredAt: null,
lastProgressAt: null,
pendingUnclaimed: true,
channel: "cloud",
localOnline: false,
cloudOnline: true,
});
assert.equal(waitingCloudUp.kind, "waiting_builder");
assert.match(waitingCloudUp.summary, /waiting for cloud runner to claim/i);
const waitingLocal = summarizeRunStep({
latestKind: "dispatched",
deliveredAt: null,
lastProgressAt: null,
pendingUnclaimed: true,
channel: "local",
localOnline: true,
});
assert.equal(waitingLocal.kind, "waiting_builder");
assert.match(waitingLocal.summary, /This computer/i);
assert.doesNotMatch(waitingLocal.summary, /cloud/i);
const cloudQueuedLocalOnline = summarizeRunStep({
latestKind: "dispatched",
deliveredAt: null,
lastProgressAt: null,
pendingUnclaimed: true,
channel: "cloud",
localOnline: true,
cloudOnline: false,
});
assert.equal(cloudQueuedLocalOnline.kind, "waiting_builder");
assert.match(cloudQueuedLocalOnline.summary, /Switch to This computer/i);
assert.match(cloudQueuedLocalOnline.detail ?? "", /Runs on/i);
const localOffline = summarizeRunStep({
latestKind: "dispatched",
deliveredAt: null,
lastProgressAt: null,
pendingUnclaimed: true,
channel: "local",
localOnline: false,
});
assert.match(localOffline.summary, /Open Fleet Runner/i);
const hosted = summarizeRunStep({
latestKind: "dispatched",
deliveredAt: null,
lastProgressAt: null,
hosted: true,
pendingUnclaimed: true,
});
assert.equal(hosted.kind, "hosted_queued");
assert.equal(furthestRunEventKind(["dispatched", "claimed", "launched"]), "launched");
const offline = deriveFeedbackWork(FEEDBACK_STATUS.DISPATCHED, {
id: "r1",
state: ORCH_STATE.WAITING,
outcome: null,
startedAt: new Date(),
finishedAt: null,
deliveredAt: null,
lastProgressAt: null,
error: null,
builderOffline: true,
builderChannel: "cloud",
});
assert.equal(offline.phase, FEEDBACK_WORK_PHASE.STUCK);
assert.equal(offline.waitingOn, WAITING_ON.YOU);
assert.equal(offline.label, "Needs you");
assert.ok(offline.diagnostic?.toLowerCase().includes("offline"));
assert.equal(offline.watchable, true);
const localOfflineStuck = deriveFeedbackWork(FEEDBACK_STATUS.DISPATCHED, {
id: "r1b",
state: ORCH_STATE.WAITING,
outcome: null,
startedAt: new Date(),
finishedAt: null,
deliveredAt: null,
lastProgressAt: null,
error: null,
builderOffline: true,
builderChannel: "local",
localOnline: false,
});
assert.equal(localOfflineStuck.phase, FEEDBACK_WORK_PHASE.STUCK);
assert.match(localOfflineStuck.detail ?? "", /Fleet Runner|This computer/i);
const youngOnline = deriveFeedbackWork(FEEDBACK_STATUS.DISPATCHED, {
id: "r2",
state: ORCH_STATE.WAITING,
outcome: null,
startedAt: new Date(),
finishedAt: null,
deliveredAt: null,
lastProgressAt: null,
error: null,
builderOffline: false,
pendingUnclaimed: true,
builderChannel: "cloud",
localOnline: true,
cloudOnline: false,
});
assert.equal(youngOnline.phase, FEEDBACK_WORK_PHASE.QUEUED);
assert.equal(youngOnline.waitingOn, WAITING_ON.MACHINE);
assert.ok(youngOnline.stepSummary);
assert.match(youngOnline.stepSummary ?? "", /Switch to This computer/i);
assert.equal(youngOnline.watchable, true);
console.log("feedback-run-step: ok");
// ── Waiting its turn is not a broken builder ───────────────────────────────
// Loki runs one agent per project: while a run is open, the queue withholds
// the next command for that project. On 2026-09-17 a dispatch held that way
// was reported as "Retry — or Open Terminal for why it never started" on the
// row, while the panel beneath it said "confirm Fleet Runner is polling" —
// both wrong, contradicting each other, about a queue and a runner that were
// working exactly as designed.
const queuedBehind = summarizeRunStep({
latestKind: "dispatched",
deliveredAt: null,
lastProgressAt: null,
pendingUnclaimed: true,
channel: "local",
localOnline: true,
queuedBehind: { label: "Next Best Task" },
});
assert.equal(queuedBehind.kind, "waiting_builder");
assert.match(queuedBehind.summary, /Next Best Task/);
assert.doesNotMatch(
`${queuedBehind.summary} ${queuedBehind.detail ?? ""}`,
/Fleet Runner is polling|confirm .* is polling|restart/i,
"must not send the reader to inspect a runner that is doing nothing wrong",
);
// Naming Retry to say it would NOT help is the point; offering it as the
// remedy is the bug. The copy has to say the wait ends by itself.
assert.match(queuedBehind.detail ?? "", /starts by itself|when the run ahead/i);
// A blocker with no recorded label still says the true thing.
const queuedUnnamed = summarizeRunStep({
latestKind: "dispatched",
deliveredAt: null,
lastProgressAt: null,
pendingUnclaimed: true,
channel: "local",
localOnline: true,
queuedBehind: { label: null },
});
assert.match(queuedUnnamed.summary, /turn/i);
// Without a blocker the builder copy is unchanged — the fix must not swallow
// the real "nobody is claiming this" case.
assert.match(
summarizeRunStep({
latestKind: "dispatched",
deliveredAt: null,
lastProgressAt: null,
pendingUnclaimed: true,
channel: "local",
localOnline: true,
}).detail ?? "",
/Fleet Runner is polling/,
);
// ── The row agrees with the panel ──────────────────────────────────────────
const heldRun = {
id: "run-held",
state: ORCH_STATE.WAITING,
outcome: null,
startedAt: new Date(Date.now() - 20 * 60_000), // far past the "never started" age
finishedAt: null,
deliveredAt: null,
lastProgressAt: null,
error: null,
pendingUnclaimed: true,
builderChannel: "local" as const,
localOnline: true,
cloudOnline: true,
queuedBehind: {
runId: "run-ahead",
label: "Next Best Task",
startedAt: new Date(Date.now() - 30 * 60_000).toISOString(),
},
};
const heldView = deriveFeedbackWork(FEEDBACK_STATUS.DISPATCHED, heldRun);
assert.equal(
heldView.phase,
FEEDBACK_WORK_PHASE.QUEUED,
"queued behind a run is QUEUED, not STUCK",
);
assert.match(heldView.detail ?? "", /Next Best Task/);
assert.doesNotMatch(heldView.detail ?? "", /never started/i);
// The same run with nothing ahead of it keeps the honest stuck reading.
const orphanView = deriveFeedbackWork(FEEDBACK_STATUS.DISPATCHED, {
...heldRun,
queuedBehind: null,
});
assert.equal(orphanView.phase, FEEDBACK_WORK_PHASE.STUCK);
assert.match(orphanView.detail ?? "", /never started/i);
console.log(" ✓ a dispatch waiting its turn is named, not blamed");
// A run that streamed once and then went quiet must not read "Agent is
// working" beside the phase's "Needs you" (run ccaf19cf, 2026-09-25: the
// laptop went offline at 17:21, the row still said working an hour later).
{
const now = Date.parse("2026-09-25T18:00:00Z");
const base = {
latestKind: "progress" as const,
deliveredAt: "2026-09-25T17:11:00Z",
channel: "local" as const,
localOnline: false,
cloudOnline: true,
now,
};
const quiet = summarizeRunStep({ ...base, lastProgressAt: "2026-09-25T17:21:00Z" });
assert.equal(quiet.summary, "Agent went quiet");
const fresh = summarizeRunStep({ ...base, lastProgressAt: "2026-09-25T17:58:00Z" });
assert.equal(fresh.summary, "Agent is working");
const view = deriveFeedbackWork(
FEEDBACK_STATUS.DISPATCHED,
{
id: "ccaf19cf-0000-0000-0000-000000000000",
state: ORCH_STATE.WAITING,
outcome: null,
startedAt: new Date("2026-09-25T17:10:00Z"),
deliveredAt: base.deliveredAt,
lastProgressAt: "2026-09-25T17:21:00Z",
latestEventKind: "progress",
builderChannel: "local",
builderOffline: true,
localOnline: false,
cloudOnline: true,
} as Parameters<typeof deriveFeedbackWork>[1],
now,
);
assert.equal(view.label, "Needs you");
assert.notEqual(view.stepSummary, "Agent is working");
}