diff --git a/src/infra/runtime-status.test.ts b/src/infra/runtime-status.test.ts index fec5c68e67b..132cffae072 100644 --- a/src/infra/runtime-status.test.ts +++ b/src/infra/runtime-status.test.ts @@ -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"); + }); }); diff --git a/src/infra/runtime-status.ts b/src/infra/runtime-status.ts index 4f0cfe2ef1d..e826c5cd32e 100644 --- a/src/infra/runtime-status.ts +++ b/src/infra/runtime-status.ts @@ -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;