mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 07:38:43 +01:00
* chore: add a formatter, matching the style this repo already writes singleQuote=false was chosen by counting this repo's own imports, not by fleet decree. The fleet is genuinely split and the two repos that already had a .prettierrc disagreed with each other, so there was no standard to restore. Quote style does not cross repo boundaries; having a gate does. Markdown is ignored for now — prettier rewraps prose, which would bury the real diff. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * style: format with prettier (1062 files) Mechanical. No behaviour change. This SHA is listed in .git-blame-ignore-revs so `git blame` skips it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * chore: teach git blame to skip the reformat Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * fix(lint): reattach two guards the reformat detached Both effects were one-liners, so a trailing eslint-disable-line covered the setState call: useEffect(() => { setSelected(new Set()); }, [q.length]); // eslint-disable-line ... prettier expanded the block. The comment stayed on the closing line while the call moved above it, so the guard protected nothing and the rule its author had deliberately silenced failed the build. This is the second shape of the same defect — hirnli had the eslint-disable-NEXT-line variant. Both come from the same fact: an eslint directive binds to a line number, so reformatting can silently unbind it, which makes 'mechanical, no behaviour change' false for any bulk reformat. * chore(desktop): bump the runner version the reformat requires desktop-release-drift enforces that anything built into Fleet Runner which differs from the last released tag must carry a version ahead of that tag — main read 0.8.15 and fleet-runner-v0.8.15 already shipped. A whole-repo reformat changes bytes under desktop/, so the gate fires. The alternative was adding desktop/ to .prettierignore, which would buy a quiet PR by carving a permanent hole in the formatter's coverage — the precise shape of silent drift this test was written to catch. Bumping is what the rule asks for and costs one patch release whose only content is whitespace. * chore: merge main and re-format A whole-repo reformat conflicts with any concurrent commit, and a conflicting PR runs no checks at all while reporting nothing. Conflicts resolved to main, which is correct because this branch changes formatting and nothing else. * chore: leave desktop/ out of this reformat desktop-release-drift is right to refuse this. Everything under desktop/ is built into Fleet Runner, so changing it means shipping: bump the version AND add a FLEET_RUNNER_RELEASES entry, whose stated audience is 'person who installed Fleet Runner and wants to know what changed'. For a whitespace-only build the honest answer is 'nothing', so that release should not exist — and I should not write release notes claiming otherwise. I had bumped to 0.8.16 to get the gate green. That was the wrong direction: publishing a build to three OS runners to keep a formatting PR quiet. Reverted. desktop/ is excluded in .prettierignore with the reasoning recorded there, to be formatted alongside the next real runner change, where the bump and the notes are true anyway. --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
279 lines
9.0 KiB
TypeScript
279 lines
9.0 KiB
TypeScript
/**
|
|
* One unit of work, one row.
|
|
*
|
|
* Reported from a phone 2026-08-26: the Activity feed showed every dispatch
|
|
* twice at the same minute — "sbb-lost-found - Next best" immediately followed
|
|
* by "sbb-lost-found - Next best - waiting" — because prompt_history and
|
|
* orchestration_runs are two rows describing the same action, and the feed
|
|
* rendered both. Neither copy was complete on its own.
|
|
*
|
|
* These cases pin the join: pairing, 1:1 consumption under bursts, and the two
|
|
* half-events (dispatch with no run, run with no dispatch) that must still
|
|
* render rather than vanish.
|
|
*
|
|
* Run: npx tsx scripts/test/activity-events.ts (or npm run test:unit)
|
|
*/
|
|
import assert from "node:assert/strict";
|
|
import {
|
|
CORRELATION_WINDOW_MS,
|
|
buildActivityEvents,
|
|
filterActivityEvents,
|
|
groupEventsByDay,
|
|
normalizeActivityFilter,
|
|
tallyActivityEvents,
|
|
type PromptSource,
|
|
type RunSource,
|
|
} from "@/lib/activity-events";
|
|
|
|
let passed = 0;
|
|
const check = (label: string, fn: () => void) => {
|
|
fn();
|
|
passed += 1;
|
|
console.log(` ${label}`);
|
|
};
|
|
|
|
const T0 = new Date("2026-08-26T04:00:00.000Z");
|
|
const at = (offsetMs: number) => new Date(T0.getTime() + offsetMs);
|
|
|
|
function prompt(over: Partial<PromptSource> = {}): PromptSource {
|
|
return {
|
|
id: "p1",
|
|
projectKey: "sbb-lost-found",
|
|
adapter: "claude",
|
|
intent: "next_best",
|
|
customPrompt: null,
|
|
resolvedPrompt: "Work on the project at /x.\n\nPick the highest-impact task.",
|
|
dispatchedAt: T0,
|
|
...over,
|
|
};
|
|
}
|
|
|
|
function run(over: Partial<RunSource> = {}): RunSource {
|
|
return {
|
|
id: "r1",
|
|
projectKey: "sbb-lost-found",
|
|
adapter: "claude",
|
|
intent: "next_best",
|
|
state: "running",
|
|
outcome: null,
|
|
summary: null,
|
|
payload: null,
|
|
startedAt: T0,
|
|
finishedAt: null,
|
|
...over,
|
|
};
|
|
}
|
|
|
|
console.log("buildActivityEvents - the join");
|
|
|
|
check("a dispatch and its run collapse into ONE event, not two rows", () => {
|
|
const events = buildActivityEvents({ prompts: [prompt()], runs: [run()] });
|
|
assert.equal(events.length, 1, "expected a single correlated event");
|
|
assert.equal(events[0].runId, "r1");
|
|
assert.equal(events[0].promptId, "p1");
|
|
});
|
|
|
|
check("the single event carries BOTH the ask and the outcome", () => {
|
|
const [event] = buildActivityEvents({
|
|
prompts: [prompt()],
|
|
runs: [
|
|
run({
|
|
outcome: "success",
|
|
finishedAt: at(90_000),
|
|
summary: { done: "Fixed the parser", next: "Ship it" },
|
|
}),
|
|
],
|
|
});
|
|
assert.ok(event.ask?.preview.includes("Pick the highest-impact task"), event.ask?.preview);
|
|
assert.equal(event.done, "Fixed the parser");
|
|
assert.equal(event.next, "Ship it");
|
|
assert.equal(event.outcome, "success");
|
|
assert.equal(event.durationLabel, "1m 30s");
|
|
});
|
|
|
|
check("a burst pairs 1:1 by closest time - no run reuses another's prompt", () => {
|
|
const prompts = [
|
|
prompt({ id: "pA", dispatchedAt: at(0) }),
|
|
prompt({ id: "pB", dispatchedAt: at(30_000) }),
|
|
prompt({ id: "pC", dispatchedAt: at(60_000) }),
|
|
];
|
|
const runs = [
|
|
run({ id: "rA", startedAt: at(1_000) }),
|
|
run({ id: "rB", startedAt: at(31_000) }),
|
|
run({ id: "rC", startedAt: at(61_000) }),
|
|
];
|
|
const events = buildActivityEvents({ prompts, runs });
|
|
assert.equal(events.length, 3, "three dispatches, three runs, three events");
|
|
const pairing = new Map(events.map((e) => [e.runId, e.promptId]));
|
|
assert.equal(pairing.get("rA"), "pA");
|
|
assert.equal(pairing.get("rB"), "pB");
|
|
assert.equal(pairing.get("rC"), "pC");
|
|
});
|
|
|
|
check("a dispatch nothing ran still renders, marked Sent", () => {
|
|
const events = buildActivityEvents({ prompts: [prompt()], runs: [] });
|
|
assert.equal(events.length, 1);
|
|
assert.equal(events[0].outcome, "dispatched");
|
|
assert.equal(events[0].outcomeLabel, "Sent");
|
|
assert.equal(events[0].runId, null);
|
|
});
|
|
|
|
check("a run with no dispatch row still renders", () => {
|
|
const events = buildActivityEvents({
|
|
prompts: [],
|
|
runs: [run({ outcome: "success", finishedAt: at(1_000) })],
|
|
});
|
|
assert.equal(events.length, 1);
|
|
assert.equal(events[0].ask, null, "no ask to show, and that is honest");
|
|
assert.equal(events[0].outcome, "success");
|
|
});
|
|
|
|
check("rows far apart in time are NOT paired", () => {
|
|
const events = buildActivityEvents({
|
|
prompts: [prompt({ dispatchedAt: at(0) })],
|
|
runs: [run({ startedAt: at(CORRELATION_WINDOW_MS + 1_000) })],
|
|
});
|
|
assert.equal(events.length, 2, "unrelated rows must stay separate events");
|
|
});
|
|
|
|
check("a different project never claims another's dispatch", () => {
|
|
const events = buildActivityEvents({
|
|
prompts: [prompt({ projectKey: "printcraft" })],
|
|
runs: [run({ projectKey: "sbb-lost-found" })],
|
|
});
|
|
assert.equal(events.length, 2);
|
|
});
|
|
|
|
check("the event is anchored to when work was ASKED for, not when it finished", () => {
|
|
const [event] = buildActivityEvents({
|
|
prompts: [prompt({ dispatchedAt: at(0) })],
|
|
runs: [run({ startedAt: at(1_000), finishedAt: at(3_600_000), outcome: "success" })],
|
|
});
|
|
assert.equal(event.occurredAt, T0.toISOString());
|
|
});
|
|
|
|
check("a real blocked reason beats the reaper's circular timeout text", () => {
|
|
const [event] = buildActivityEvents({
|
|
prompts: [],
|
|
runs: [
|
|
run({
|
|
id: "r9",
|
|
outcome: "timeout",
|
|
finishedAt: at(10),
|
|
payload: { error: "exceeded max duration" },
|
|
}),
|
|
],
|
|
blockedReasons: new Map([
|
|
["r9", "injected to running claude (pty), but the agent isn't generating"],
|
|
]),
|
|
});
|
|
assert.ok(event.error?.includes("isn't generating"), String(event.error));
|
|
});
|
|
|
|
check("events come back newest first", () => {
|
|
const events = buildActivityEvents({
|
|
prompts: [
|
|
prompt({ id: "old", projectKey: "a", dispatchedAt: at(0) }),
|
|
prompt({ id: "new", projectKey: "b", dispatchedAt: at(60_000) }),
|
|
],
|
|
runs: [],
|
|
});
|
|
assert.deepEqual(
|
|
events.map((e) => e.promptId),
|
|
["new", "old"],
|
|
);
|
|
});
|
|
|
|
console.log("\ntriage");
|
|
|
|
const mixed = buildActivityEvents({
|
|
prompts: [],
|
|
runs: [
|
|
run({ id: "e1", projectKey: "a", outcome: "error", finishedAt: at(1) }),
|
|
run({ id: "e2", projectKey: "b", outcome: "timeout", finishedAt: at(1) }),
|
|
run({ id: "e3", projectKey: "c", outcome: "partial", finishedAt: at(1) }),
|
|
run({ id: "e4", projectKey: "d", outcome: "success", finishedAt: at(1) }),
|
|
run({ id: "e5", projectKey: "e", state: "running", finishedAt: null }),
|
|
],
|
|
});
|
|
|
|
check("tallies count what a person triages by", () => {
|
|
const t = tallyActivityEvents(mixed);
|
|
assert.equal(t.total, 5);
|
|
assert.equal(t.attention, 3, "error + timeout + partial");
|
|
assert.equal(t.running, 1);
|
|
assert.equal(t.done, 1);
|
|
});
|
|
|
|
check("the attention filter surfaces exactly the failures and partials", () => {
|
|
const got = filterActivityEvents(mixed, "attention")
|
|
.map((e) => e.outcome)
|
|
.sort();
|
|
assert.deepEqual(got, ["error", "partial", "timeout"]);
|
|
});
|
|
|
|
check("running and done filters are exact", () => {
|
|
assert.equal(filterActivityEvents(mixed, "running").length, 1);
|
|
assert.equal(filterActivityEvents(mixed, "done").length, 1);
|
|
assert.equal(filterActivityEvents(mixed, "all").length, 5);
|
|
});
|
|
|
|
check("an unknown filter value falls back to all", () => {
|
|
assert.equal(normalizeActivityFilter("nonsense"), "all");
|
|
assert.equal(normalizeActivityFilter(undefined), "all");
|
|
assert.equal(normalizeActivityFilter("attention"), "attention");
|
|
});
|
|
|
|
console.log("\nday grouping");
|
|
|
|
check("consecutive events on one day share a single header", () => {
|
|
const events = buildActivityEvents({
|
|
prompts: [
|
|
prompt({ id: "p1", projectKey: "a", dispatchedAt: new Date("2026-08-26T09:00:00Z") }),
|
|
prompt({ id: "p2", projectKey: "b", dispatchedAt: new Date("2026-08-26T08:00:00Z") }),
|
|
prompt({ id: "p3", projectKey: "c", dispatchedAt: new Date("2026-08-25T23:00:00Z") }),
|
|
],
|
|
runs: [],
|
|
});
|
|
const groups = groupEventsByDay(events);
|
|
assert.deepEqual(
|
|
groups.map((g) => g.day),
|
|
["2026-08-26", "2026-08-25"],
|
|
);
|
|
assert.equal(groups[0].events.length, 2);
|
|
assert.equal(groups[1].events.length, 1);
|
|
});
|
|
|
|
console.log("\nintentId — what a retry replays");
|
|
|
|
check("the RAW intent id rides along, not just its label", () => {
|
|
const [event] = buildActivityEvents({ prompts: [prompt()], runs: [run()] });
|
|
assert.equal(
|
|
event.intentId,
|
|
"next_best",
|
|
"the label alone cannot be handed back to the pipeline",
|
|
);
|
|
assert.notEqual(event.intentId, event.intentLabel, "label and id are different things");
|
|
});
|
|
|
|
check("a dispatch with no run keeps its intent id too", () => {
|
|
const [event] = buildActivityEvents({ prompts: [prompt({ intent: "test_and_fix" })], runs: [] });
|
|
assert.equal(event.intentId, "test_and_fix");
|
|
});
|
|
|
|
check("a locally-typed prompt is marked custom and flagged as local", () => {
|
|
const [event] = buildActivityEvents({
|
|
prompts: [],
|
|
runs: [],
|
|
localChats: [{ id: "c1", projectKey: "a", gitBranch: null, promptText: "hey", occurredAt: T0 }],
|
|
});
|
|
assert.equal(event.intentId, "custom");
|
|
assert.equal(
|
|
event.isLocalChat,
|
|
true,
|
|
"local chat was never dispatched, so it must not offer a re-dispatch",
|
|
);
|
|
});
|
|
|
|
console.log(`\n${passed}/${passed} activity-events cases passed`);
|