mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-17 12:22:34 +03:00
* fix(dashboard): keep the first failure timestamp in sourceStale buildSourceStatuses stamped nowIso on every failing source at every poll, so the stale indicator reported "since the last poll" instead of the first failure — and, because snapshotContentKey serializes sources, the snapshot identity churned on every tick while any source was down. The failing branches now reuse the staleSince already held by that source in the previous status list, via the functional setStatuses updater (no ref read during render, no setState inside an effect body). Refs #12392 * fix(dashboard): flag a source that starts failing after it had data buildRootAndSourceEdges only materialized a placeholder SourceNode when the failing source had no node at all. A source that already had work nodes and then started failing (or went offline) kept its healthy-looking SourceNode forever: no ⚠, no stale styling, no `sourceStale` line — the operator saw a normal source while it was actually broken. Now every non-ok/offline source is flagged: when its SourceNode is missing the placeholder is created as before; when it exists, the node is replaced by a copy carrying `sourceIssue` and `staleSince`. The copy (never a mutation) keeps the function pure — the original object is still referenced by the caller's `parts`, the same trap the droppedByState aliasing fix covered. Tests: three cases in tests/unit/ui/orchestrationModel.test.ts — existing node starting to fail (flags set, work nodes kept, no duplicate node, input object untouched), existing node going offline (no invented staleSince), and a healthy source staying free of both fields. Refs #12392 * fix(dashboard): canvas polish batch (#12392) Seven pointwise fixes on the Orchestration Canvas, each covered by a test: 1. Debounce x chip race: every chip/clear write in OrchestrationToolbar now cancels the pending search timer first. Left armed, it fired ~300ms later with a setParams closed over the pre-chip query string and silently reverted the chip. 2. The search input carries an aria-label (searchPlaceholder) — the placeholder alone is not an accessible name. 3. parseCsvSet trims each token, so `?state=running, failed` parses like the unpadded form instead of dropping the padded value. 4. toggleCsv was duplicated in the toolbar and the page client; both now import the single definition from the new model/urlParams.ts (pure, never mutates its inputs). 5. AgentsTab tells "nothing running" apart from "the filter matched nothing": with an active filter and no work node it renders noMatches + a clear-filters button instead of the setup CTAs, which would be wrong advice there. 6. Particle cap: orchestrationToFlow stamps `particles` on every edge and turns it off above PARTICLE_EDGE_CAP (40) simultaneously active edges — StatusEdge then renders the colored stroke without its 3 SMIL particles per edge. 7. The drawer's error banner clears when an action succeeds, so a recovered failure does not stay on screen. Only `noMatches` is added to en.json here; the other locales are task B4. Refs #12392 * chore(dashboard): canvas polish i18n + changelog Real translations for orchestration.noMatches in the 41 non-English locales, each one written against that file's own neighbouring keys (emptyTitle, stateRunning, searchPlaceholder) so the wording for "task" and "filter" matches what the locale already uses. No i18n:sync-ui, no __MISSING__ left. Adds the changelog fragment for the nine PR-B fixes. Closes #12392
279 lines
10 KiB
TypeScript
279 lines
10 KiB
TypeScript
// @vitest-environment jsdom
|
|
import React, { act } from "react";
|
|
import { createRoot } from "react-dom/client";
|
|
import { describe, it, expect, beforeAll, afterEach, vi } from "vitest";
|
|
|
|
beforeAll(() => {
|
|
globalThis.ResizeObserver = class {
|
|
observe() {}
|
|
unobserve() {}
|
|
disconnect() {}
|
|
} as unknown as typeof ResizeObserver;
|
|
});
|
|
vi.mock("@xyflow/react", async () => {
|
|
const actual = (await vi.importActual("@xyflow/react")) as Record<string, unknown>;
|
|
return { ...actual, Handle: () => null, Position: { Top: "top", Bottom: "bottom" } };
|
|
});
|
|
vi.mock("next-intl", () => ({
|
|
useTranslations: () => (k: string, v?: Record<string, unknown>) =>
|
|
v ? `${k}:${JSON.stringify(v)}` : k,
|
|
}));
|
|
|
|
import type { EdgeProps } from "@xyflow/react";
|
|
import { WorkNode } from "@/app/(dashboard)/dashboard/orchestration/nodes/WorkNode";
|
|
import { SourceNode } from "@/app/(dashboard)/dashboard/orchestration/nodes/SourceNode";
|
|
import { OrchestratorNode } from "@/app/(dashboard)/dashboard/orchestration/nodes/OrchestratorNode";
|
|
import { ActivityNode } from "@/app/(dashboard)/dashboard/orchestration/nodes/ActivityNode";
|
|
import { OverflowNode } from "@/app/(dashboard)/dashboard/orchestration/nodes/OverflowNode";
|
|
import { StatusEdge } from "@/app/(dashboard)/dashboard/orchestration/edges/StatusEdge";
|
|
|
|
function render(el: React.ReactElement) {
|
|
const c = document.createElement("div");
|
|
document.body.appendChild(c);
|
|
const root = createRoot(c);
|
|
act(() => root.render(el));
|
|
return {
|
|
c,
|
|
cleanup: () => {
|
|
act(() => root.unmount());
|
|
c.remove();
|
|
},
|
|
};
|
|
}
|
|
afterEach(() => {
|
|
document.body.innerHTML = "";
|
|
});
|
|
|
|
describe("orchestration nodes", () => {
|
|
it("WorkNode shows label, state text and an aria-label", () => {
|
|
const data = {
|
|
id: "cloud-agent:t1",
|
|
kind: "work",
|
|
source: "cloud-agent",
|
|
state: "waiting_approval",
|
|
label: "Fix CI",
|
|
sublabel: "devin",
|
|
};
|
|
const { c, cleanup } = render(<WorkNode data={data as never} />);
|
|
expect(c.textContent).toContain("Fix CI");
|
|
expect(c.textContent).toContain("stateWaitingApproval");
|
|
expect(c.querySelector("[aria-label]")).toBeTruthy();
|
|
cleanup();
|
|
});
|
|
it("SourceNode with sourceIssue=error shows the warning marker", () => {
|
|
const data = {
|
|
id: "source:a2a",
|
|
kind: "source",
|
|
source: "a2a",
|
|
label: "A2A",
|
|
sublabel: "error",
|
|
sourceIssue: "error",
|
|
};
|
|
const { c, cleanup } = render(<SourceNode data={data as never} />);
|
|
expect(c.textContent).toContain("⚠");
|
|
cleanup();
|
|
});
|
|
|
|
it("SourceNode with sourceIssue=error and a parseable staleSince renders the formatted time in sourceStale", () => {
|
|
const staleSince = "2026-09-01T12:34:56.000Z";
|
|
const data = {
|
|
id: "source:a2a",
|
|
kind: "source",
|
|
source: "a2a",
|
|
label: "A2A",
|
|
sublabel: "error",
|
|
sourceIssue: "error",
|
|
staleSince,
|
|
};
|
|
const { c, cleanup } = render(<SourceNode data={data as never} />);
|
|
// Mocked next-intl `t` returns `${key}:${JSON.stringify(values)}` when values are passed —
|
|
// asserts the component actually forwards `{ since }`, not just the raw key.
|
|
const since = new Date(staleSince).toLocaleTimeString();
|
|
expect(c.textContent).toContain(`sourceStale:${JSON.stringify({ since })}`);
|
|
cleanup();
|
|
});
|
|
|
|
it("SourceNode with sourceIssue=error and no staleSince falls back to an em dash", () => {
|
|
const data = {
|
|
id: "source:a2a",
|
|
kind: "source",
|
|
source: "a2a",
|
|
label: "A2A",
|
|
sublabel: "error",
|
|
sourceIssue: "error",
|
|
};
|
|
const { c, cleanup } = render(<SourceNode data={data as never} />);
|
|
expect(c.textContent).toContain(`sourceStale:${JSON.stringify({ since: "—" })}`);
|
|
cleanup();
|
|
});
|
|
|
|
it("SourceNode with sourceIssue=error and an unparseable staleSince also falls back to an em dash", () => {
|
|
const data = {
|
|
id: "source:a2a",
|
|
kind: "source",
|
|
source: "a2a",
|
|
label: "A2A",
|
|
sublabel: "error",
|
|
sourceIssue: "error",
|
|
staleSince: "not-a-date",
|
|
};
|
|
const { c, cleanup } = render(<SourceNode data={data as never} />);
|
|
expect(c.textContent).toContain(`sourceStale:${JSON.stringify({ since: "—" })}`);
|
|
cleanup();
|
|
});
|
|
|
|
it("all 5 memo'd orchestration node components have a displayName", () => {
|
|
expect(WorkNode.displayName).toBe("WorkNode");
|
|
expect(SourceNode.displayName).toBe("SourceNode");
|
|
expect(OrchestratorNode.displayName).toBe("OrchestratorNode");
|
|
expect(ActivityNode.displayName).toBe("ActivityNode");
|
|
expect(OverflowNode.displayName).toBe("OverflowNode");
|
|
});
|
|
|
|
it("OrchestratorNode renders the label as text content and as aria-label", () => {
|
|
const data = { id: "orchestrator", kind: "orchestrator", label: "OmniRoute" };
|
|
const { c, cleanup } = render(<OrchestratorNode data={data as never} />);
|
|
expect(c.textContent).toContain("OmniRoute");
|
|
expect(c.querySelector('[aria-label="OmniRoute"]')).toBeTruthy();
|
|
cleanup();
|
|
});
|
|
|
|
it("ActivityNode renders label + sublabel and exposes the label as aria-label", () => {
|
|
const data = {
|
|
id: "cloud-agent:t1:activity",
|
|
kind: "activity",
|
|
source: "cloud-agent",
|
|
label: "npm test",
|
|
sublabel: "command",
|
|
};
|
|
const { c, cleanup } = render(<ActivityNode data={data as never} />);
|
|
expect(c.textContent).toContain("npm test");
|
|
expect(c.textContent).toContain("command");
|
|
expect(c.querySelector('[aria-label="npm test"]')).toBeTruthy();
|
|
cleanup();
|
|
});
|
|
|
|
it("OverflowNode renders the overflowMore count in text + aria-label and a badge per non-zero state", () => {
|
|
const data = {
|
|
id: "overflow:cloud-agent",
|
|
kind: "overflow",
|
|
source: "cloud-agent",
|
|
label: "+7 more",
|
|
counts: { running: 5, failed: 2, queued: 0 },
|
|
};
|
|
const { c, cleanup } = render(<OverflowNode data={data as never} />);
|
|
// Mocked next-intl `t` returns `${key}:${JSON.stringify(values)}` — asserts the
|
|
// component forwards the summed total (5 + 2 = 7), not a raw/stale count.
|
|
const expectedText = `overflowMore:${JSON.stringify({ count: 7 })}`;
|
|
expect(c.textContent).toContain(expectedText);
|
|
const labelled = c.querySelector("[aria-label]");
|
|
expect(labelled?.getAttribute("aria-label")).toBe(expectedText);
|
|
// One badge span per state with a non-zero count (running, failed) — queued (0) omitted.
|
|
const badges = Array.from(c.querySelectorAll("div.flex.gap-1 span"));
|
|
expect(badges.length).toBe(2);
|
|
expect(badges.map((b) => b.textContent)).toEqual(["5", "2"]);
|
|
cleanup();
|
|
});
|
|
|
|
it("OverflowNode with no counts renders a zero total and no per-state badges", () => {
|
|
const data = { id: "overflow:a2a", kind: "overflow", source: "a2a", label: "+0 more" };
|
|
const { c, cleanup } = render(<OverflowNode data={data as never} />);
|
|
expect(c.textContent).toContain(`overflowMore:${JSON.stringify({ count: 0 })}`);
|
|
expect(c.querySelectorAll("div.flex.gap-1 span").length).toBe(0);
|
|
cleanup();
|
|
});
|
|
|
|
it("SourceNode shows a collapse caret + aria-expanded + title reflecting !data.collapsed", () => {
|
|
const expandedData = { id: "source:a2a", kind: "source", source: "a2a", label: "A2A" };
|
|
const r1 = render(<SourceNode data={expandedData as never} />);
|
|
const expandedEl = r1.c.querySelector("[aria-expanded]");
|
|
expect(expandedEl?.getAttribute("aria-expanded")).toBe("true");
|
|
expect(expandedEl?.getAttribute("title")).toBe("sourceCollapse");
|
|
expect(r1.c.textContent).toContain("▾");
|
|
r1.cleanup();
|
|
|
|
const collapsedData = { ...expandedData, collapsed: true };
|
|
const r2 = render(<SourceNode data={collapsedData as never} />);
|
|
const collapsedEl = r2.c.querySelector("[aria-expanded]");
|
|
expect(collapsedEl?.getAttribute("aria-expanded")).toBe("false");
|
|
expect(collapsedEl?.getAttribute("title")).toBe("sourceExpand");
|
|
expect(r2.c.textContent).toContain("▸");
|
|
r2.cleanup();
|
|
});
|
|
});
|
|
|
|
describe("StatusEdge", () => {
|
|
const baseProps = {
|
|
id: "e1",
|
|
source: "a",
|
|
target: "b",
|
|
sourceX: 0,
|
|
sourceY: 0,
|
|
targetX: 100,
|
|
targetY: 100,
|
|
sourcePosition: "bottom",
|
|
targetPosition: "top",
|
|
};
|
|
|
|
it("data.active renders PARTICLES ellipses, each starting opacity=0 with a paired <set> reveal", () => {
|
|
const props = { ...baseProps, data: { state: "running", active: true, mirror: false } };
|
|
const { c, cleanup } = render(
|
|
<svg>
|
|
<StatusEdge {...(props as unknown as EdgeProps)} />
|
|
</svg>
|
|
);
|
|
const ellipses = c.querySelectorAll("ellipse.orch-edge-particle");
|
|
expect(ellipses.length).toBe(3);
|
|
ellipses.forEach((ellipse) => {
|
|
expect(ellipse.getAttribute("opacity")).toBe("0");
|
|
const set = ellipse.querySelector("set");
|
|
expect(set).toBeTruthy();
|
|
expect(set?.getAttribute("attributeName")).toBe("opacity");
|
|
expect(set?.getAttribute("to")).toBe("1");
|
|
expect(set?.getAttribute("fill")).toBe("freeze");
|
|
expect(ellipse.querySelector("animateMotion")).toBeTruthy();
|
|
});
|
|
cleanup();
|
|
});
|
|
|
|
it("without data.active there is no particle ellipse", () => {
|
|
const props = { ...baseProps, data: { state: "succeeded", active: false, mirror: false } };
|
|
const { c, cleanup } = render(
|
|
<svg>
|
|
<StatusEdge {...(props as unknown as EdgeProps)} />
|
|
</svg>
|
|
);
|
|
expect(c.querySelectorAll("ellipse.orch-edge-particle").length).toBe(0);
|
|
cleanup();
|
|
});
|
|
|
|
it("data.particles === false renders the stroke only, even while active (particle cap)", () => {
|
|
const props = {
|
|
...baseProps,
|
|
data: { state: "running", active: true, mirror: false, particles: false },
|
|
};
|
|
const { c, cleanup } = render(
|
|
<svg>
|
|
<StatusEdge {...(props as unknown as EdgeProps)} />
|
|
</svg>
|
|
);
|
|
expect(c.querySelectorAll("ellipse.orch-edge-particle").length).toBe(0);
|
|
expect(c.querySelector("path")).toBeTruthy();
|
|
cleanup();
|
|
});
|
|
|
|
it("data.particles === true keeps the particles (explicit opt-in from orchestrationToFlow)", () => {
|
|
const props = {
|
|
...baseProps,
|
|
data: { state: "running", active: true, mirror: false, particles: true },
|
|
};
|
|
const { c, cleanup } = render(
|
|
<svg>
|
|
<StatusEdge {...(props as unknown as EdgeProps)} />
|
|
</svg>
|
|
);
|
|
expect(c.querySelectorAll("ellipse.orch-edge-particle").length).toBe(3);
|
|
cleanup();
|
|
});
|
|
});
|