The first cut grouped consecutive same-kind events, but the real noise shape is an interleave: one background cycle emits curator_run, session-memory and curator_action events carrying the same payload, and kind-keyed grouping left them all visible. The grouping key is now the rendered detail plus the task, so one cycle of noise collapses to one row regardless of which internal kind emitted each event, while events carrying different information never merge. Verified against a live daemon: 50 background events collapse to one expandable row.
101 lines
3.3 KiB
TypeScript
101 lines
3.3 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
const { groupActivity, groupKey } = await import("../src/dashboard/activity-group.ts");
|
|
|
|
import type { ActivityEvent } from "../src/dashboard/state.ts";
|
|
|
|
function ev(kind: string, taskID: number | undefined, detail: string, at = 1000): ActivityEvent {
|
|
return { kind, task_id: taskID, detail, at };
|
|
}
|
|
|
|
test("consecutive events sharing detail and task collapse into one group", () => {
|
|
const events = [
|
|
ev("session-memory", undefined, "cycle 9"),
|
|
ev("session-memory", undefined, "cycle 9"),
|
|
ev("session-memory", undefined, "cycle 9"),
|
|
];
|
|
const groups = groupActivity(events);
|
|
assert.equal(groups.length, 1);
|
|
assert.equal(groups[0].count, 3);
|
|
// The newest event (first in the feed) represents the group.
|
|
assert.equal(groups[0].representative.detail, "cycle 9");
|
|
assert.equal(groups[0].events.length, 3);
|
|
});
|
|
|
|
test("the same kind with different details does not collapse", () => {
|
|
const events = [
|
|
ev("stage_finished", 7, "build"),
|
|
ev("stage_finished", 7, "plan"),
|
|
];
|
|
const groups = groupActivity(events);
|
|
assert.equal(groups.length, 2);
|
|
});
|
|
|
|
test("a singleton stays a plain one-count group", () => {
|
|
const groups = groupActivity([ev("stage_finished", 7, "build")]);
|
|
assert.equal(groups.length, 1);
|
|
assert.equal(groups[0].count, 1);
|
|
assert.equal(groups[0].events.length, 1);
|
|
});
|
|
|
|
test("a different task breaks the run", () => {
|
|
const events = [
|
|
ev("runner_run", 7, "a"),
|
|
ev("runner_run", 9, "b"),
|
|
ev("runner_run", 7, "c"),
|
|
];
|
|
const groups = groupActivity(events);
|
|
assert.equal(groups.length, 3);
|
|
for (const group of groups) assert.equal(group.count, 1);
|
|
});
|
|
|
|
test("a different kind breaks the run when the detail differs", () => {
|
|
const events = [
|
|
ev("session-memory", undefined, "a"),
|
|
ev("runner_run", undefined, "b"),
|
|
ev("session-memory", undefined, "c"),
|
|
];
|
|
const groups = groupActivity(events);
|
|
assert.equal(groups.length, 3);
|
|
});
|
|
|
|
test("an interleave of kinds sharing one detail and task collapses", () => {
|
|
// A background cycle emits one event per internal step; the kinds differ
|
|
// but the cycle is one run of noise.
|
|
const events = [
|
|
ev("curator_action", undefined, "session-memory"),
|
|
ev("session-memory", undefined, "session-memory"),
|
|
ev("curator_run", undefined, "session-memory"),
|
|
ev("curator_action", undefined, "session-memory"),
|
|
];
|
|
const groups = groupActivity(events);
|
|
assert.equal(groups.length, 1);
|
|
assert.equal(groups[0].count, 4);
|
|
assert.equal(groups[0].label, "curator_action");
|
|
});
|
|
|
|
test("the same detail on a different task breaks the run", () => {
|
|
const events = [
|
|
ev("runner_run", 7, "building"),
|
|
ev("runner_run", 9, "building"),
|
|
];
|
|
const groups = groupActivity(events);
|
|
assert.equal(groups.length, 2);
|
|
});
|
|
|
|
test("a missing kind resolves to the same label an unset row shows", () => {
|
|
const events: ActivityEvent[] = [
|
|
{ detail: "a", at: 1000 },
|
|
{ detail: "a", at: 1001 },
|
|
];
|
|
const groups = groupActivity(events);
|
|
assert.equal(groups.length, 1);
|
|
assert.equal(groups[0].label, "event");
|
|
});
|
|
|
|
test("groupKey separates detail and task", () => {
|
|
assert.notEqual(groupKey("runner_run", 7), groupKey("runner_run", 9));
|
|
assert.equal(groupKey("runner_run", 7), groupKey("runner_run", 7));
|
|
assert.equal(groupKey("runner_run", 0), groupKey("runner_run", undefined));
|
|
}); |