@outputai/cli 0.10.1-next.f6a7c1a.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/generated/api.d.ts +81 -26
- package/dist/api/generated/api.js +7 -4
- package/dist/api/http_client.js +2 -2
- package/dist/assets/docker/docker-compose-dev.yml +2 -2
- package/dist/commands/dev/down.d.ts +10 -0
- package/dist/commands/dev/down.js +34 -0
- package/dist/commands/dev/down.spec.js +71 -0
- package/dist/commands/dev/index.d.ts +4 -0
- package/dist/commands/dev/index.js +200 -53
- package/dist/commands/dev/index.spec.js +390 -42
- package/dist/commands/workflow/monitor.d.ts +5 -20
- package/dist/commands/workflow/monitor.js +20 -182
- package/dist/commands/workflow/monitor.spec.js +82 -3
- package/dist/commands/workflow/result.js +2 -2
- package/dist/commands/workflow/result.spec.js +65 -1
- package/dist/commands/workflow/run.js +10 -3
- package/dist/commands/workflow/run.spec.js +42 -5
- package/dist/commands/workflow/start.d.ts +7 -1
- package/dist/commands/workflow/start.js +107 -12
- package/dist/commands/workflow/start.spec.js +282 -5
- package/dist/commands/workflow/status.spec.js +1 -1
- package/dist/commands/workflow/{test_eval.d.ts → test.d.ts} +0 -1
- package/dist/commands/workflow/{test_eval.js → test.js} +0 -1
- package/dist/commands/workflow/test.spec.d.ts +1 -0
- package/dist/commands/workflow/{test_eval.spec.js → test.spec.js} +4 -4
- package/dist/generated/framework_version.json +1 -1
- package/dist/services/docker.d.ts +28 -1
- package/dist/services/docker.js +106 -12
- package/dist/services/docker.spec.js +144 -14
- package/dist/services/monitor_stream.d.ts +62 -0
- package/dist/services/monitor_stream.js +285 -0
- package/dist/services/monitor_stream.spec.d.ts +1 -0
- package/dist/services/monitor_stream.spec.js +285 -0
- package/dist/services/workflow_history.js +2 -2
- package/dist/templates/agent_instructions/CLAUDE.md.template +5 -3
- package/dist/templates/project/README.md.template +3 -1
- package/dist/templates/project/package.json.template +2 -2
- package/dist/templates/project/src/clients/jina.ts.template +4 -4
- package/dist/utils/env_loader.js +6 -2
- package/dist/utils/env_loader.spec.js +61 -32
- package/dist/utils/error_handler.d.ts +10 -0
- package/dist/utils/error_handler.js +14 -0
- package/dist/utils/error_handler.spec.d.ts +1 -0
- package/dist/utils/error_handler.spec.js +62 -0
- package/dist/utils/format_workflow_result.d.ts +15 -3
- package/dist/utils/format_workflow_result.js +39 -6
- package/dist/utils/format_workflow_result.spec.js +39 -6
- package/dist/utils/monitor_flags.d.ts +35 -0
- package/dist/utils/monitor_flags.js +76 -0
- package/dist/utils/normalize_workflow_status.d.ts +4 -3
- package/dist/utils/normalize_workflow_status.js +12 -3
- package/dist/utils/normalize_workflow_status.spec.js +3 -0
- package/dist/utils/port_collision.d.ts +22 -7
- package/dist/utils/port_collision.js +39 -14
- package/dist/utils/port_collision.spec.js +40 -1
- package/dist/utils/resolve_input.d.ts +9 -1
- package/dist/utils/resolve_input.js +8 -2
- package/dist/utils/resolve_input.spec.d.ts +1 -0
- package/dist/utils/resolve_input.spec.js +75 -0
- package/dist/views/dev/chrome/footer.d.ts +2 -0
- package/dist/views/dev/chrome/footer.js +4 -4
- package/dist/views/dev/components/workflow_status.js +1 -1
- package/dist/views/dev/dev_app.d.ts +1 -0
- package/dist/views/dev/dev_app.js +13 -4
- package/dist/views/dev/hooks/use_run_detail.js +4 -4
- package/dist/views/dev/hooks/use_run_detail.spec.js +1 -1
- package/dist/views/dev/panels/runs_panel.js +2 -2
- package/oclif.manifest.json +91 -10
- package/package.json +7 -9
- /package/dist/commands/{workflow/test_eval.spec.d.ts → dev/down.spec.d.ts} +0 -0
package/dist/services/docker.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { execFileSync, execSync, spawn } from 'node:child_process';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
2
3
|
import path from 'node:path';
|
|
3
4
|
import { fileURLToPath } from 'node:url';
|
|
4
5
|
import { ux } from '@oclif/core';
|
|
5
6
|
import semver from 'semver';
|
|
6
7
|
import { config } from '#config.js';
|
|
8
|
+
import { getErrorMessage } from '#utils/error_utils.js';
|
|
9
|
+
import { formatComposeFailure } from '#utils/port_collision.js';
|
|
7
10
|
const DEFAULT_COMPOSE_PATH = '../assets/docker/docker-compose-dev.yml';
|
|
8
11
|
export const SERVICE_HEALTH = {
|
|
9
12
|
HEALTHY: 'healthy',
|
|
@@ -83,6 +86,22 @@ export function validateDockerEnvironment() {
|
|
|
83
86
|
export function getDefaultDockerComposePath() {
|
|
84
87
|
return path.resolve(path.dirname(fileURLToPath(import.meta.url)), DEFAULT_COMPOSE_PATH);
|
|
85
88
|
}
|
|
89
|
+
// Resolve the compose file a `dev` command should act on — a caller-supplied
|
|
90
|
+
// path (relative to cwd) or the bundled default — and verify it exists. Shared
|
|
91
|
+
// by `dev` and `dev down` so the resolution rule and not-found error stay in
|
|
92
|
+
// one place.
|
|
93
|
+
export async function resolveDockerComposePath(customPath) {
|
|
94
|
+
const dockerComposePath = customPath ?
|
|
95
|
+
path.resolve(process.cwd(), customPath) :
|
|
96
|
+
getDefaultDockerComposePath();
|
|
97
|
+
try {
|
|
98
|
+
await fs.access(dockerComposePath);
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
throw new DockerComposeConfigNotFoundError(dockerComposePath);
|
|
102
|
+
}
|
|
103
|
+
return dockerComposePath;
|
|
104
|
+
}
|
|
86
105
|
export function parseServiceStatus(jsonOutput) {
|
|
87
106
|
if (!jsonOutput.trim()) {
|
|
88
107
|
return [];
|
|
@@ -118,6 +137,37 @@ export function isServiceHealthy(service) {
|
|
|
118
137
|
export function isServiceFailed(service) {
|
|
119
138
|
return service.state === SERVICE_STATE.EXITED || service.health === SERVICE_HEALTH.UNHEALTHY;
|
|
120
139
|
}
|
|
140
|
+
export const STACK_STATE = {
|
|
141
|
+
/** Nothing live for this project — a fresh start we own. */
|
|
142
|
+
NONE: 'none',
|
|
143
|
+
/** Every container found is running and healthy (or has no healthcheck). */
|
|
144
|
+
RUNNING: 'running',
|
|
145
|
+
/** Something is live but not everything is healthy — reconcile. */
|
|
146
|
+
PARTIAL: 'partial'
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* Classify the current state of a project's stack from `docker compose ps`.
|
|
150
|
+
*
|
|
151
|
+
* This is the detection signal `output dev` branches on: nothing live means a
|
|
152
|
+
* fresh start; an all-healthy result means we can attach and monitor without
|
|
153
|
+
* touching the stack; anything in between is reconciled with `up -d`.
|
|
154
|
+
*
|
|
155
|
+
* Scoped to the shared `output-sdk` compose project, which distinguishes our
|
|
156
|
+
* containers from unrelated processes — but not one Output checkout from
|
|
157
|
+
* another, since the project name defaults to a machine-global constant.
|
|
158
|
+
*/
|
|
159
|
+
export function classifyStackState(services) {
|
|
160
|
+
// No container is live. `ps --all` also reports exited ones, so a stack left
|
|
161
|
+
// behind by a reboot, a `docker compose stop`, or a failed teardown lands
|
|
162
|
+
// here — that's an owned fresh start, not something to attach to.
|
|
163
|
+
if (!services.some(service => service.state === SERVICE_STATE.RUNNING)) {
|
|
164
|
+
return STACK_STATE.NONE;
|
|
165
|
+
}
|
|
166
|
+
if (services.every(isServiceHealthy)) {
|
|
167
|
+
return STACK_STATE.RUNNING;
|
|
168
|
+
}
|
|
169
|
+
return STACK_STATE.PARTIAL;
|
|
170
|
+
}
|
|
121
171
|
export async function waitForServicesHealthy(dockerComposePath, timeoutMs = 120000, pollIntervalMs = 2000) {
|
|
122
172
|
const startTime = Date.now();
|
|
123
173
|
while (Date.now() - startTime < timeoutMs) {
|
|
@@ -129,6 +179,18 @@ export async function waitForServicesHealthy(dockerComposePath, timeoutMs = 1200
|
|
|
129
179
|
}
|
|
130
180
|
throw new Error('Timeout waiting for services to become healthy');
|
|
131
181
|
}
|
|
182
|
+
// A rolling buffer that retains the last ~20k chars of a spawned process's
|
|
183
|
+
// combined output, so a startup failure can surface recent Docker logs without
|
|
184
|
+
// holding the whole stream. Shared by the two compose spawn sites.
|
|
185
|
+
function createOutputBuffer() {
|
|
186
|
+
const buffer = { value: '' };
|
|
187
|
+
return {
|
|
188
|
+
append: (chunk) => {
|
|
189
|
+
buffer.value = `${buffer.value}${chunk.toString()}`.slice(-20000).trimStart();
|
|
190
|
+
},
|
|
191
|
+
read: () => buffer.value.trimEnd()
|
|
192
|
+
};
|
|
193
|
+
}
|
|
132
194
|
export async function startDockerCompose({ dockerComposePath, pullPolicy, onError, onExit }) {
|
|
133
195
|
const args = [
|
|
134
196
|
'compose',
|
|
@@ -140,29 +202,34 @@ export async function startDockerCompose({ dockerComposePath, pullPolicy, onErro
|
|
|
140
202
|
if (pullPolicy) {
|
|
141
203
|
args.push('--pull', pullPolicy);
|
|
142
204
|
}
|
|
143
|
-
const output =
|
|
144
|
-
value: ''
|
|
145
|
-
};
|
|
146
|
-
const appendOutput = (chunk) => {
|
|
147
|
-
output.value = `${output.value}${chunk.toString()}`.slice(-20000).trimStart();
|
|
148
|
-
};
|
|
205
|
+
const output = createOutputBuffer();
|
|
149
206
|
const dockerProcess = spawn('docker', args, {
|
|
150
207
|
cwd: process.cwd(),
|
|
151
208
|
// The Ink dev UI owns the terminal. Drain compose output so Docker cannot
|
|
152
209
|
// block on a full pipe, while keeping recent output for startup failures.
|
|
153
210
|
stdio: ['ignore', 'pipe', 'pipe']
|
|
154
211
|
});
|
|
155
|
-
dockerProcess.stdout?.on('data',
|
|
156
|
-
dockerProcess.stderr?.on('data',
|
|
212
|
+
dockerProcess.stdout?.on('data', output.append);
|
|
213
|
+
dockerProcess.stderr?.on('data', output.append);
|
|
157
214
|
if (onError) {
|
|
158
|
-
dockerProcess.on('error', error => onError(error, output.
|
|
215
|
+
dockerProcess.on('error', error => onError(error, output.read()));
|
|
159
216
|
}
|
|
160
217
|
if (onExit) {
|
|
161
|
-
|
|
218
|
+
// `close` rather than `exit` so stdio has drained — the buffered output is
|
|
219
|
+
// what formatComposeFailure greps for a bind failure.
|
|
220
|
+
dockerProcess.on('close', (code, signal) => onExit(code, signal, output.read()));
|
|
162
221
|
}
|
|
163
222
|
return dockerProcess;
|
|
164
223
|
}
|
|
165
|
-
|
|
224
|
+
// Run `docker compose up -d` to completion, teeing Docker's progress to the
|
|
225
|
+
// user's terminal while retaining recent output. The predecessor used
|
|
226
|
+
// execFileSync with inherited stdio, which threw a raw compose error the caller
|
|
227
|
+
// couldn't inspect; returning the exit code and output lets it surface a
|
|
228
|
+
// port-collision hint instead. Async so image pulls don't block the event loop.
|
|
229
|
+
//
|
|
230
|
+
// Trade-off: piping means Docker sees a non-TTY and drops its redrawing
|
|
231
|
+
// progress bars for plain scrolling lines.
|
|
232
|
+
export function runDockerComposeUpDetached(dockerComposePath, pullPolicy) {
|
|
166
233
|
const args = [
|
|
167
234
|
'compose',
|
|
168
235
|
'-f', dockerComposePath,
|
|
@@ -173,7 +240,34 @@ export function startDockerComposeDetached(dockerComposePath, pullPolicy) {
|
|
|
173
240
|
if (pullPolicy) {
|
|
174
241
|
args.push('--pull', pullPolicy);
|
|
175
242
|
}
|
|
176
|
-
|
|
243
|
+
const output = createOutputBuffer();
|
|
244
|
+
return new Promise((resolve, reject) => {
|
|
245
|
+
// Pipe rather than inherit so we can both echo Docker's progress and keep
|
|
246
|
+
// recent output for a startup-failure hint.
|
|
247
|
+
const child = spawn('docker', args, {
|
|
248
|
+
cwd: process.cwd(),
|
|
249
|
+
stdio: ['ignore', 'pipe', 'pipe']
|
|
250
|
+
});
|
|
251
|
+
child.stdout?.on('data', (chunk) => {
|
|
252
|
+
process.stdout.write(chunk);
|
|
253
|
+
output.append(chunk);
|
|
254
|
+
});
|
|
255
|
+
child.stderr?.on('data', (chunk) => {
|
|
256
|
+
process.stderr.write(chunk);
|
|
257
|
+
output.append(chunk);
|
|
258
|
+
});
|
|
259
|
+
// `error` fires when the spawn itself failed (docker missing, EACCES).
|
|
260
|
+
// Reject with the buffered output attached so the caller keeps the context
|
|
261
|
+
// rather than surfacing a bare `spawn docker ENOENT`.
|
|
262
|
+
child.on('error', error => {
|
|
263
|
+
reject(new Error(formatComposeFailure(getErrorMessage(error), output.read(), config.ports)));
|
|
264
|
+
});
|
|
265
|
+
// `close`, not `exit`: exit fires while stdio may still be draining, and on
|
|
266
|
+
// a fast-failing `up -d` — exactly the bind-collision case — the stderr
|
|
267
|
+
// chunk carrying the bind error can land after it. Resolving early makes
|
|
268
|
+
// the port-collision hint disappear intermittently.
|
|
269
|
+
child.on('close', (code, signal) => resolve({ code, signal, output: output.read() }));
|
|
270
|
+
});
|
|
177
271
|
}
|
|
178
272
|
export async function stopDockerCompose(dockerComposePath) {
|
|
179
273
|
ux.stdout('⏹️ Stopping services...\n');
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
2
|
import { execFileSync, spawn } from 'node:child_process';
|
|
3
|
-
import
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import fs from 'node:fs/promises';
|
|
5
|
+
import { parseServiceStatus, getServiceStatus, startDockerCompose, runDockerComposeUpDetached, stopDockerCompose, waitForServicesHealthy, isServiceHealthy, isServiceFailed, classifyStackState, STACK_STATE, resolveDockerComposePath, getDefaultDockerComposePath, DockerComposeConfigNotFoundError } from './docker.js';
|
|
4
6
|
vi.mock('node:child_process', () => ({
|
|
5
7
|
execSync: vi.fn(),
|
|
6
8
|
execFileSync: vi.fn(),
|
|
7
9
|
spawn: vi.fn()
|
|
8
10
|
}));
|
|
11
|
+
vi.mock('node:fs/promises', () => ({
|
|
12
|
+
default: { access: vi.fn() }
|
|
13
|
+
}));
|
|
9
14
|
const mockChildProcess = (process) => process;
|
|
10
15
|
vi.mock('log-update', () => {
|
|
11
16
|
const fn = vi.fn();
|
|
@@ -155,7 +160,7 @@ describe('docker service', () => {
|
|
|
155
160
|
onExit
|
|
156
161
|
});
|
|
157
162
|
expect(dockerProcess.on).toHaveBeenCalledWith('error', expect.any(Function));
|
|
158
|
-
expect(dockerProcess.on).toHaveBeenCalledWith('
|
|
163
|
+
expect(dockerProcess.on).toHaveBeenCalledWith('close', expect.any(Function));
|
|
159
164
|
streamHandlers.stdout?.(Buffer.from('starting services\n'));
|
|
160
165
|
streamHandlers.stderr?.(Buffer.from('compose failed\n'));
|
|
161
166
|
const error = new Error('Docker failed');
|
|
@@ -165,26 +170,99 @@ describe('docker service', () => {
|
|
|
165
170
|
expect(onExit).toHaveBeenCalledWith(1, null, 'starting services\ncompose failed');
|
|
166
171
|
});
|
|
167
172
|
});
|
|
168
|
-
describe('
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
+
describe('runDockerComposeUpDetached', () => {
|
|
174
|
+
const makeProcess = () => {
|
|
175
|
+
const handlers = {};
|
|
176
|
+
const proc = {
|
|
177
|
+
on: vi.fn((event, handler) => {
|
|
178
|
+
if (event === 'error') {
|
|
179
|
+
handlers.error = handler;
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
handlers.exit = handler;
|
|
183
|
+
}
|
|
184
|
+
return proc;
|
|
185
|
+
}),
|
|
186
|
+
stdout: {
|
|
187
|
+
on: vi.fn((event, handler) => {
|
|
188
|
+
handlers.stdout = handler;
|
|
189
|
+
return proc.stdout;
|
|
190
|
+
})
|
|
191
|
+
},
|
|
192
|
+
stderr: {
|
|
193
|
+
on: vi.fn((event, handler) => {
|
|
194
|
+
handlers.stderr = handler;
|
|
195
|
+
return proc.stderr;
|
|
196
|
+
})
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
return { proc, handlers };
|
|
200
|
+
};
|
|
201
|
+
it('passes --project-name and -d, tees output, and resolves with the exit code', async () => {
|
|
202
|
+
const { proc, handlers } = makeProcess();
|
|
203
|
+
vi.mocked(spawn).mockReturnValue(mockChildProcess(proc));
|
|
204
|
+
const stdoutSpy = vi.spyOn(process.stdout, 'write').mockReturnValue(true);
|
|
205
|
+
const promise = runDockerComposeUpDetached('/path/to/docker-compose.yml');
|
|
206
|
+
expect(spawn).toHaveBeenCalledWith('docker', [
|
|
173
207
|
'compose', '-f', '/path/to/docker-compose.yml',
|
|
174
208
|
'--project-directory', process.cwd(),
|
|
175
209
|
'--project-name', 'output-sdk',
|
|
176
210
|
'up', '-d'
|
|
177
|
-
], expect.objectContaining({
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
211
|
+
], expect.objectContaining({ cwd: process.cwd(), stdio: ['ignore', 'pipe', 'pipe'] }));
|
|
212
|
+
handlers.stdout?.(Buffer.from('pulling images\n'));
|
|
213
|
+
handlers.exit?.(0);
|
|
214
|
+
expect(await promise).toEqual({ code: 0, output: 'pulling images' });
|
|
215
|
+
expect(stdoutSpy).toHaveBeenCalledWith(Buffer.from('pulling images\n'));
|
|
216
|
+
stdoutSpy.mockRestore();
|
|
217
|
+
});
|
|
218
|
+
it('appends --pull when pullPolicy is provided', async () => {
|
|
219
|
+
const { proc, handlers } = makeProcess();
|
|
220
|
+
vi.mocked(spawn).mockReturnValue(mockChildProcess(proc));
|
|
221
|
+
vi.spyOn(process.stdout, 'write').mockReturnValue(true);
|
|
222
|
+
const promise = runDockerComposeUpDetached('/path/to/docker-compose.yml', 'missing');
|
|
223
|
+
handlers.exit?.(0);
|
|
224
|
+
await promise;
|
|
225
|
+
expect(spawn).toHaveBeenCalledWith('docker', [
|
|
183
226
|
'compose', '-f', '/path/to/docker-compose.yml',
|
|
184
227
|
'--project-directory', process.cwd(),
|
|
185
228
|
'--project-name', 'output-sdk',
|
|
186
229
|
'up', '-d', '--pull', 'missing'
|
|
187
|
-
], expect.objectContaining({
|
|
230
|
+
], expect.objectContaining({ cwd: process.cwd() }));
|
|
231
|
+
});
|
|
232
|
+
it('resolves with a non-zero code and captured stderr so the caller can hint the collision', async () => {
|
|
233
|
+
const { proc, handlers } = makeProcess();
|
|
234
|
+
vi.mocked(spawn).mockReturnValue(mockChildProcess(proc));
|
|
235
|
+
vi.spyOn(process.stderr, 'write').mockReturnValue(true);
|
|
236
|
+
const promise = runDockerComposeUpDetached('/path/to/docker-compose.yml');
|
|
237
|
+
handlers.stderr?.(Buffer.from('Error: address already in use\n'));
|
|
238
|
+
handlers.exit?.(1);
|
|
239
|
+
expect(await promise).toEqual({ code: 1, output: 'Error: address already in use' });
|
|
240
|
+
});
|
|
241
|
+
it('rejects when the docker process fails to spawn', async () => {
|
|
242
|
+
const { proc, handlers } = makeProcess();
|
|
243
|
+
vi.mocked(spawn).mockReturnValue(mockChildProcess(proc));
|
|
244
|
+
const promise = runDockerComposeUpDetached('/path/to/docker-compose.yml');
|
|
245
|
+
handlers.error?.(new Error('spawn ENOENT'));
|
|
246
|
+
await expect(promise).rejects.toThrow('spawn ENOENT');
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
describe('resolveDockerComposePath', () => {
|
|
250
|
+
it('resolves a custom path against cwd and returns it when it exists', async () => {
|
|
251
|
+
vi.mocked(fs.access).mockResolvedValue(undefined);
|
|
252
|
+
const result = await resolveDockerComposePath('custom/compose.yml');
|
|
253
|
+
const expected = path.resolve(process.cwd(), 'custom/compose.yml');
|
|
254
|
+
expect(result).toBe(expected);
|
|
255
|
+
expect(fs.access).toHaveBeenCalledWith(expected);
|
|
256
|
+
});
|
|
257
|
+
it('throws DockerComposeConfigNotFoundError when the path does not exist', async () => {
|
|
258
|
+
vi.mocked(fs.access).mockRejectedValue(new Error('ENOENT'));
|
|
259
|
+
await expect(resolveDockerComposePath('missing.yml'))
|
|
260
|
+
.rejects.toBeInstanceOf(DockerComposeConfigNotFoundError);
|
|
261
|
+
});
|
|
262
|
+
it('falls back to the bundled default when no custom path is given', async () => {
|
|
263
|
+
vi.mocked(fs.access).mockResolvedValue(undefined);
|
|
264
|
+
const result = await resolveDockerComposePath();
|
|
265
|
+
expect(result).toBe(getDefaultDockerComposePath());
|
|
188
266
|
});
|
|
189
267
|
});
|
|
190
268
|
describe('DOCKER_SERVICE_NAME wiring', () => {
|
|
@@ -259,6 +337,58 @@ describe('docker service', () => {
|
|
|
259
337
|
expect(isServiceFailed({ name: 'temporal', state: 'running', health: 'starting', ports: [] })).toBe(false);
|
|
260
338
|
});
|
|
261
339
|
});
|
|
340
|
+
describe('classifyStackState', () => {
|
|
341
|
+
const svc = (state, health) => ({ name: 's', state, health, ports: [] });
|
|
342
|
+
it('returns NONE for an empty stack (fresh start)', () => {
|
|
343
|
+
expect(classifyStackState([])).toBe(STACK_STATE.NONE);
|
|
344
|
+
});
|
|
345
|
+
it('returns RUNNING when every service is up and healthy', () => {
|
|
346
|
+
expect(classifyStackState([
|
|
347
|
+
svc('running', 'healthy'),
|
|
348
|
+
svc('running', 'none')
|
|
349
|
+
])).toBe(STACK_STATE.RUNNING);
|
|
350
|
+
});
|
|
351
|
+
it('returns PARTIAL when any service has failed (orphaned stack)', () => {
|
|
352
|
+
expect(classifyStackState([
|
|
353
|
+
svc('running', 'healthy'),
|
|
354
|
+
svc('exited', 'none')
|
|
355
|
+
])).toBe(STACK_STATE.PARTIAL);
|
|
356
|
+
});
|
|
357
|
+
it('returns PARTIAL when services exist but some are still coming up', () => {
|
|
358
|
+
expect(classifyStackState([
|
|
359
|
+
svc('running', 'healthy'),
|
|
360
|
+
svc('created', 'none')
|
|
361
|
+
])).toBe(STACK_STATE.PARTIAL);
|
|
362
|
+
});
|
|
363
|
+
it('treats an unhealthy service as PARTIAL, not RUNNING', () => {
|
|
364
|
+
expect(classifyStackState([
|
|
365
|
+
svc('running', 'healthy'),
|
|
366
|
+
svc('running', 'unhealthy')
|
|
367
|
+
])).toBe(STACK_STATE.PARTIAL);
|
|
368
|
+
});
|
|
369
|
+
// `ps --all` reports exited containers, so a stack stopped by a reboot, a
|
|
370
|
+
// `docker compose stop`, or a failed teardown still has rows. Nothing is
|
|
371
|
+
// live, so this invocation would be the one starting it — that makes it an
|
|
372
|
+
// owned fresh start, not an attach.
|
|
373
|
+
it('returns NONE when every service is exited — an owned fresh start, not an attach', () => {
|
|
374
|
+
expect(classifyStackState([
|
|
375
|
+
svc('exited', 'none'),
|
|
376
|
+
svc('exited', 'none')
|
|
377
|
+
])).toBe(STACK_STATE.NONE);
|
|
378
|
+
});
|
|
379
|
+
it('returns NONE when containers are created but none have started', () => {
|
|
380
|
+
expect(classifyStackState([
|
|
381
|
+
svc('created', 'none'),
|
|
382
|
+
svc('created', 'none')
|
|
383
|
+
])).toBe(STACK_STATE.NONE);
|
|
384
|
+
});
|
|
385
|
+
it('still returns PARTIAL when at least one service is live', () => {
|
|
386
|
+
expect(classifyStackState([
|
|
387
|
+
svc('running', 'healthy'),
|
|
388
|
+
svc('exited', 'none')
|
|
389
|
+
])).toBe(STACK_STATE.PARTIAL);
|
|
390
|
+
});
|
|
391
|
+
});
|
|
262
392
|
describe('waitForServicesHealthy', () => {
|
|
263
393
|
it('should resolve when all services are healthy', async () => {
|
|
264
394
|
const mockOutput = `{"Service":"redis","State":"running","Health":"healthy","Publishers":[]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type TerminalStatus } from '#utils/format_workflow_result.js';
|
|
2
|
+
export type MonitorStreamOptions = {
|
|
3
|
+
workflowId: string;
|
|
4
|
+
runId?: string;
|
|
5
|
+
includePayloads: boolean;
|
|
6
|
+
interval: number;
|
|
7
|
+
json: boolean;
|
|
8
|
+
color: boolean;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* The command surface the stream needs, kept as a parameter rather than a
|
|
12
|
+
* `Command` instance so `workflow start --monitor` can reuse the loop without
|
|
13
|
+
* constructing (or delegating to) a second oclif command — the repo has no
|
|
14
|
+
* `runCommand` precedent and `Command.run( argv, config )` would need a real
|
|
15
|
+
* oclif `Config` that unit tests don't have. `error` must be typed `never` so
|
|
16
|
+
* callers keep type narrowing after an error branch.
|
|
17
|
+
*/
|
|
18
|
+
export type MonitorStreamIo = {
|
|
19
|
+
log: (message: string) => void;
|
|
20
|
+
warn: (message: string) => void;
|
|
21
|
+
error: (message: string) => never;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Adapts an oclif command to the above. Late-bound arrows rather than
|
|
25
|
+
* `command.log.bind( command )`: oclif (and the unit tests) replace these as own
|
|
26
|
+
* properties on the instance, so they must resolve at call time. Structurally
|
|
27
|
+
* typed so a test double satisfies it without a real oclif `Config`.
|
|
28
|
+
*/
|
|
29
|
+
export declare function commandStreamIo(command: {
|
|
30
|
+
log: (message: string) => void;
|
|
31
|
+
warn: (message: string) => unknown;
|
|
32
|
+
error: (message: string, options: {
|
|
33
|
+
exit: number;
|
|
34
|
+
}) => never;
|
|
35
|
+
}): MonitorStreamIo;
|
|
36
|
+
/**
|
|
37
|
+
* Polls a workflow run and emits status updates until it reaches a terminal
|
|
38
|
+
* state, following continue-as-new chains. Shared by `workflow monitor` and
|
|
39
|
+
* `workflow start --monitor` so both behave identically; see `MonitorStreamIo`
|
|
40
|
+
* for why output is injected rather than taken from a `Command`.
|
|
41
|
+
*
|
|
42
|
+
* Sets `process.exitCode = 1` on a terminal error status rather than throwing,
|
|
43
|
+
* so the caller's own output (e.g. `start`'s "Workflow started successfully")
|
|
44
|
+
* is still the command's primary result. Returns the terminal status it stopped
|
|
45
|
+
* on — `undefined` if it stopped because the user detached — so a caller can
|
|
46
|
+
* tailor its own follow-up (`workflow result` vs `workflow debug`).
|
|
47
|
+
*/
|
|
48
|
+
export declare function streamWorkflowUpdates(options: MonitorStreamOptions, io: MonitorStreamIo): Promise<TerminalStatus | undefined>;
|
|
49
|
+
/**
|
|
50
|
+
* Shared `catch` handling for both entry points. A 400 is the generic status for
|
|
51
|
+
* several distinct causes (invalid pageToken, a missing runId, an out-of-range
|
|
52
|
+
* longPollTimeoutMs) — only override it with the stale-cursor message when the
|
|
53
|
+
* server actually identifies that specific cause; otherwise let the real
|
|
54
|
+
* validation error surface instead of misdiagnosing an unrelated 400.
|
|
55
|
+
*
|
|
56
|
+
* Deliberately no 404 here: "check the workflow ID" only reads correctly where
|
|
57
|
+
* the user typed the id, so `workflow monitor` adds it and `start --monitor`
|
|
58
|
+
* doesn't — there the id came back from `postWorkflowStart`, and the server's own
|
|
59
|
+
* message is left to surface inside the "started, but monitoring stopped" wrapper
|
|
60
|
+
* instead of advising a fix that isn't the user's to make.
|
|
61
|
+
*/
|
|
62
|
+
export declare function monitorErrorOverrides(error: Error): Record<number, string>;
|