Files
OmniRoute/tests/unit/ui/edgeStyles.test.ts
danscMax 18a8da6df7 fix(dashboard): topology reflects connection health + clears finished requests (#7672)
The provider topology only lit nodes from live/recent traffic, so between
requests (and right after a restart) it went blank even though 50+ connections
were healthy — which reads as "lost providers". Two root causes:

1. Stuck-green latch: request.completed/request.failed are declared in the
   dashboard event map and consumed by useLiveRequests to drain the active-request
   set, but they were never emitted (only request.started was). A node's green
   "active" pulse therefore only cleared on a page reload, and accumulated over a
   session. Emit the terminal event from persistAttemptLogs — keyed by the same
   traceId as request.started — through a pure resolveRequestLifecycleEvent()
   helper (2xx/3xx + no error => completed, else failed).

2. No at-rest state: the map had nothing to show when idle. Colour each node by
   connection health (green connected / red error / grey idle) as a base layer,
   with live/recent traffic still taking precedence and pulsing brighter on top.
   edgeStyle() gains an optional trailing `healthy` param (static dim green) and
   StatusDot a `pulse` prop (static dot for connected-at-rest); both backward
   compatible. Legend "Active" -> "Connected".

Tests: resolveRequestLifecycleEvent success/failure/token-alias units, edgeStyle
healthy variant + precedence, and source guards for the emit wiring (traceId
threaded into persistAttemptLogs) and the health-colour wiring.

Co-authored-by: Diego Rodrigues de Sa e Souza <diegosouza.pw@gmail.com>
Co-authored-by: Diego Rodrigues de Sa e Souza <diegosouzapw@users.noreply.github.com>
2026-07-19 20:52:43 -03:00

72 lines
2.3 KiB
TypeScript

import { describe, it } from "node:test";
import assert from "node:assert/strict";
import { edgeStyle, FLOW_EDGE_COLORS } from "../../../src/shared/components/flow/edgeStyles.ts";
describe("flow edgeStyles (U0 — extracted from ProviderTopology)", () => {
it("exposes the shared flow palette", () => {
assert.equal(FLOW_EDGE_COLORS.active, "#22c55e");
assert.equal(FLOW_EDGE_COLORS.error, "#ef4444");
assert.equal(FLOW_EDGE_COLORS.last, "#f59e0b");
assert.equal(FLOW_EDGE_COLORS.idle, "var(--color-text-muted)");
});
it("styles an error edge", () => {
assert.deepEqual(edgeStyle(false, false, true), {
stroke: "#ef4444",
strokeWidth: 2,
opacity: 0.85,
});
});
it("styles an active edge", () => {
assert.deepEqual(edgeStyle(true, false, false), {
stroke: "#22c55e",
strokeWidth: 2.5,
opacity: 1,
});
});
it("styles a last-used edge", () => {
assert.deepEqual(edgeStyle(false, true, false), {
stroke: "#f59e0b",
strokeWidth: 1.5,
opacity: 0.6,
});
});
it("styles an idle edge", () => {
assert.deepEqual(edgeStyle(false, false, false), {
stroke: "var(--color-text-muted)",
strokeWidth: 1,
opacity: 0.3,
});
});
it("styles a healthy (connected, no in-flight traffic) edge as static dim green", () => {
assert.deepEqual(edgeStyle(false, false, false, true), {
stroke: "#22c55e",
strokeWidth: 1.5,
opacity: 0.4,
});
});
it("defaults healthy to false so 3-arg callers stay idle", () => {
assert.deepEqual(edgeStyle(false, false, false), {
stroke: "var(--color-text-muted)",
strokeWidth: 1,
opacity: 0.3,
});
});
it("applies precedence error > active > last > healthy", () => {
assert.equal(edgeStyle(true, true, true).stroke, "#ef4444"); // error wins
assert.equal(edgeStyle(true, true, false).stroke, "#22c55e"); // active beats last
assert.equal(edgeStyle(false, false, true, true).stroke, "#ef4444"); // error beats healthy
assert.equal(edgeStyle(false, true, false, true).stroke, "#f59e0b"); // last beats healthy
// healthy green is dimmer/thinner than the active pulse green
assert.equal(edgeStyle(false, false, false, true).opacity, 0.4);
assert.equal(edgeStyle(true, false, false, true).opacity, 1); // active still wins
});
});