fix: tighten runtime status detail coverage

This commit is contained in:
Peter Steinberger 2026-03-14 00:24:59 +00:00
parent 70489cbed0
commit 6ad2f793af
2 changed files with 26 additions and 4 deletions

View File

@ -18,6 +18,16 @@ describe("formatRuntimeStatusWithDetails", () => {
).toBe("running (pid 1234, state sleeping, healthy, port 18789)");
});
it("trims distinct state and detail text before formatting", () => {
expect(
formatRuntimeStatusWithDetails({
status: "running",
state: " sleeping ",
details: [" healthy ", " port 18789 "],
}),
).toBe("running (state sleeping, healthy, port 18789)");
});
it("omits duplicate state text and falsy pid values", () => {
expect(
formatRuntimeStatusWithDetails({
@ -35,4 +45,14 @@ describe("formatRuntimeStatusWithDetails", () => {
}),
).toBe("RUNNING");
});
it("drops whitespace-only state and detail entries", () => {
expect(
formatRuntimeStatusWithDetails({
status: "running",
state: " ",
details: ["", " "],
}),
).toBe("running");
});
});

View File

@ -16,12 +16,14 @@ export function formatRuntimeStatusWithDetails({
if (pid) {
fullDetails.push(`pid ${pid}`);
}
if (state && state.toLowerCase() !== runtimeStatus.toLowerCase()) {
fullDetails.push(`state ${state}`);
const normalizedState = state?.trim();
if (normalizedState && normalizedState.toLowerCase() !== runtimeStatus.toLowerCase()) {
fullDetails.push(`state ${normalizedState}`);
}
for (const detail of details) {
if (detail) {
fullDetails.push(detail);
const normalizedDetail = detail.trim();
if (normalizedDetail) {
fullDetails.push(normalizedDetail);
}
}
return fullDetails.length > 0 ? `${runtimeStatus} (${fullDetails.join(", ")})` : runtimeStatus;