diff --git a/src/utils/workloadState.test.ts b/src/utils/workloadState.test.ts new file mode 100644 index 0000000..4d546a8 --- /dev/null +++ b/src/utils/workloadState.test.ts @@ -0,0 +1,17 @@ +import { formatWorkloadLogResponse } from './workloadState'; + +describe('Workload Log Response Formatting', () => { + it('should include running state for active workload', () => { + const res = formatWorkloadLogResponse('test/app', 'log line 1', { running: true, state: 'running' }); + expect(res.ok).toBe(true); + expect(res.running).toBe(true); + expect(res.state).toBe('running'); + }); + + it('should surface exited state for stopped workload', () => { + const res = formatWorkloadLogResponse('test/app', 'probe line', { running: false, state: 'exited' }); + expect(res.ok).toBe(true); + expect(res.running).toBe(false); + expect(res.state).toBe('exited'); + }); +}); diff --git a/src/utils/workloadState.ts b/src/utils/workloadState.ts new file mode 100644 index 0000000..4cb60b4 --- /dev/null +++ b/src/utils/workloadState.ts @@ -0,0 +1,24 @@ +export interface WorkloadLogStatus { + ok: boolean; + workload: string; + running: boolean; + state: string; + logs: string; +} + +export function formatWorkloadLogResponse( + workload: string, + logs: string, + containerStatus?: { running?: boolean; state?: string } +): WorkloadLogStatus { + const running = containerStatus?.running ?? true; + const state = containerStatus?.state ?? (running ? 'running' : 'exited'); + + return { + ok: true, + workload, + running, + state, + logs + }; +}