mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-10-19 08:15:12 +00:00
fix(channels): ignore zero failure timestamps (#1157)
Use the existing relative-time guard when deciding whether to show channel diagnostics, so Go zero-value timestamps do not make healthy channels look broken. Add regression coverage for zero-value first_failed_at and active failure states. Co-authored-by: evgyur <evgyur@gmail.com>
This commit is contained in:
1 parent
bdc9abd576
commit
124d4bee0d
4 files changed
+50
-6
No files matched your search
@@ -21,6 +21,7 @@ import {
|
||||
getChannelRemediationMeta,
|
||||
getRenderableChannelStatus,
|
||||
getChannelStatusMeta,
|
||||
shouldShowChannelDiagnosticsCard,
|
||||
} from "../channels-status-view";
|
||||
import { useChannelTimeline } from "./channel-detail-timeline-hook";
|
||||
import { ChannelDetailDialogs } from "./channel-detail-dialogs";
|
||||
@@ -139,12 +140,7 @@ export function ChannelDetailPage({
|
||||
|
||||
const timelineItems = useChannelTimeline(status, t);
|
||||
|
||||
const showDiagnosticsCard =
|
||||
status?.state === "failed" ||
|
||||
status?.state === "degraded" ||
|
||||
!!status?.remediation ||
|
||||
!!status?.consecutive_failures ||
|
||||
!!status?.first_failed_at;
|
||||
const showDiagnosticsCard = shouldShowChannelDiagnosticsCard(status);
|
||||
|
||||
const neutralHealthNote =
|
||||
!showDiagnosticsCard &&
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { ChannelRuntimeStatus } from "@/types/channel";
|
||||
import { shouldShowChannelDiagnosticsCard } from "./channels-status-utils";
|
||||
|
||||
function status(overrides: Partial<ChannelRuntimeStatus>): ChannelRuntimeStatus {
|
||||
return {
|
||||
enabled: true,
|
||||
running: true,
|
||||
state: "healthy",
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
describe("shouldShowChannelDiagnosticsCard", () => {
|
||||
it("ignores Go zero-value first_failed_at timestamps on healthy channels", () => {
|
||||
expect(
|
||||
shouldShowChannelDiagnosticsCard(
|
||||
status({ first_failed_at: "0001-01-01T00:00:00Z" }),
|
||||
),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("shows diagnostics for meaningful failure timestamps", () => {
|
||||
expect(
|
||||
shouldShowChannelDiagnosticsCard(
|
||||
status({ first_failed_at: "2026-01-01T00:00:00Z" }),
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("still shows diagnostics for active degraded or failed states", () => {
|
||||
expect(shouldShowChannelDiagnosticsCard(status({ state: "degraded" }))).toBe(true);
|
||||
expect(shouldShowChannelDiagnosticsCard(status({ state: "failed" }))).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -161,6 +161,18 @@ export function getChannelCheckedLabel(
|
||||
});
|
||||
}
|
||||
|
||||
export function shouldShowChannelDiagnosticsCard(
|
||||
status: ChannelRuntimeStatus | null | undefined,
|
||||
) {
|
||||
return (
|
||||
status?.state === "failed" ||
|
||||
status?.state === "degraded" ||
|
||||
!!status?.remediation ||
|
||||
!!status?.consecutive_failures ||
|
||||
!!formatRelativeTime(status?.first_failed_at)
|
||||
);
|
||||
}
|
||||
|
||||
export function getChannelFailureKindLabel(
|
||||
kind: ChannelRuntimeStatus["failure_kind"],
|
||||
t: TFunction,
|
||||
|
||||
@@ -23,6 +23,7 @@ export {
|
||||
getRenderableChannelStatus,
|
||||
getChannelCheckedLabel,
|
||||
getChannelFailureKindLabel,
|
||||
shouldShowChannelDiagnosticsCard,
|
||||
getChannelAttentionPriority,
|
||||
getChannelStatusMeta,
|
||||
getChannelRemediationMeta,
|
||||
|
||||
Reference in new issue
Block a user