@dataparade/cli 0.0.29 → 0.0.31
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/package.json +3 -3
- package/dist/src/ai-enrichment/providers/platform-proxy-provider.js +6 -1
- package/dist/src/cli/scan-interrupt-handlers.d.ts +34 -0
- package/dist/src/cli/scan-interrupt-handlers.js +105 -0
- package/dist/src/cli.js +99 -28
- package/dist/src/config/scan-env.d.ts +5 -2
- package/dist/src/config/scan-env.js +8 -2
- package/dist/src/platform-api/scan-quota-client.d.ts +3 -1
- package/dist/src/platform-api/scan-quota-client.js +41 -28
- package/dist/src/ui/scan-progress-renderer.d.ts +24 -0
- package/dist/src/ui/scan-progress-renderer.js +91 -0
- package/dist/src/ui/types.d.ts +5 -0
- package/dist/tests/unit/ai-enrichment/platform-proxy-provider.spec.js +26 -0
- package/dist/tests/unit/cli/scan-interrupt-handlers.spec.d.ts +1 -0
- package/dist/tests/unit/cli/scan-interrupt-handlers.spec.js +154 -0
- package/dist/tests/unit/cli/scan-quota-flow.spec.js +2 -2
- package/dist/tests/unit/platform-api/read-cli-api-error-message.spec.js +2 -2
- package/dist/tests/unit/ui/scan-progress-renderer.spec.js +134 -0
- package/dist/vendor/scanner/dist/src/core/pipeline/diagram-layout/constants.d.ts +2 -0
- package/dist/vendor/scanner/dist/src/core/pipeline/diagram-layout/constants.js +3 -1
- package/dist/vendor/scanner/dist/src/core/pipeline/diagram-layout/section-packing.d.ts +9 -0
- package/dist/vendor/scanner/dist/src/core/pipeline/diagram-layout/section-packing.js +40 -0
- package/dist/vendor/scanner/dist/src/core/pipeline/graph-mapping.js +2 -0
- package/package.json +3 -3
|
@@ -33,8 +33,15 @@ export declare class ScanProgressRenderer {
|
|
|
33
33
|
private readonly version?;
|
|
34
34
|
private readonly columns?;
|
|
35
35
|
private readonly colorDepth?;
|
|
36
|
+
private readonly stdin?;
|
|
36
37
|
private readonly clack;
|
|
37
38
|
private started;
|
|
39
|
+
/**
|
|
40
|
+
* Set once the run is closed (finish/abort/fail). The scan keeps running
|
|
41
|
+
* while the interrupt handler reports to the API, and work queued behind a
|
|
42
|
+
* blocking phase must not draw new steps under "Scan cancelled".
|
|
43
|
+
*/
|
|
44
|
+
private closed;
|
|
38
45
|
private recognitionHandled;
|
|
39
46
|
private activeStep;
|
|
40
47
|
private spinner;
|
|
@@ -72,7 +79,24 @@ export declare class ScanProgressRenderer {
|
|
|
72
79
|
*/
|
|
73
80
|
showTechnicalDetails(title: string, lines: string[]): void;
|
|
74
81
|
finish(): void;
|
|
82
|
+
/**
|
|
83
|
+
* Cancel an in-flight scan UI (Ctrl+C). Stops the spinner with a red mark
|
|
84
|
+
* in Clack mode; prints a short line in plain mode. Does not run finish().
|
|
85
|
+
*/
|
|
86
|
+
abort(message?: string): void;
|
|
87
|
+
/**
|
|
88
|
+
* End the scan UI on an error: closes the active spinner with the error
|
|
89
|
+
* mark (or logs an error line between steps). Does not run finish().
|
|
90
|
+
*/
|
|
91
|
+
fail(message: string): void;
|
|
75
92
|
private transitionTo;
|
|
93
|
+
/**
|
|
94
|
+
* Clack's spinner puts stdin in raw mode, where Ctrl+C is a keypress it
|
|
95
|
+
* answers with process.exit(0) — skipping our SIGINT handler and leaving
|
|
96
|
+
* the scan job running. The spinner only writes, so hand Ctrl+C back to
|
|
97
|
+
* the terminal as a real signal.
|
|
98
|
+
*/
|
|
99
|
+
private restoreSignalKeys;
|
|
76
100
|
private completeActiveStep;
|
|
77
101
|
private runTeachingStep;
|
|
78
102
|
private prompts;
|
|
@@ -86,6 +86,12 @@ function formatProjectLabel(projectPath) {
|
|
|
86
86
|
class ScanProgressRenderer {
|
|
87
87
|
constructor(options, clack) {
|
|
88
88
|
this.started = false;
|
|
89
|
+
/**
|
|
90
|
+
* Set once the run is closed (finish/abort/fail). The scan keeps running
|
|
91
|
+
* while the interrupt handler reports to the API, and work queued behind a
|
|
92
|
+
* blocking phase must not draw new steps under "Scan cancelled".
|
|
93
|
+
*/
|
|
94
|
+
this.closed = false;
|
|
89
95
|
this.recognitionHandled = false;
|
|
90
96
|
this.activeStep = null;
|
|
91
97
|
this.spinner = null;
|
|
@@ -102,6 +108,7 @@ class ScanProgressRenderer {
|
|
|
102
108
|
this.version = options.version;
|
|
103
109
|
this.columns = options.columns;
|
|
104
110
|
this.colorDepth = options.colorDepth;
|
|
111
|
+
this.stdin = options.stdin;
|
|
105
112
|
this.writeLine =
|
|
106
113
|
options.writeLine ??
|
|
107
114
|
((line) => {
|
|
@@ -145,6 +152,8 @@ class ScanProgressRenderer {
|
|
|
145
152
|
}
|
|
146
153
|
}
|
|
147
154
|
onProgress(progress) {
|
|
155
|
+
if (this.closed)
|
|
156
|
+
return;
|
|
148
157
|
this.start();
|
|
149
158
|
switch (progress.phase) {
|
|
150
159
|
case 'ingest':
|
|
@@ -169,6 +178,8 @@ class ScanProgressRenderer {
|
|
|
169
178
|
}
|
|
170
179
|
}
|
|
171
180
|
onRecognition(payload) {
|
|
181
|
+
if (this.closed)
|
|
182
|
+
return;
|
|
172
183
|
if (this.recognitionHandled)
|
|
173
184
|
return;
|
|
174
185
|
this.recognitionHandled = true;
|
|
@@ -196,6 +207,8 @@ class ScanProgressRenderer {
|
|
|
196
207
|
}
|
|
197
208
|
/** Close the AI step with one plain-language result line. */
|
|
198
209
|
onAiResult(result) {
|
|
210
|
+
if (this.closed)
|
|
211
|
+
return;
|
|
199
212
|
if (this.activeStep !== 'ai_enrichment')
|
|
200
213
|
return;
|
|
201
214
|
this.completeActiveStep();
|
|
@@ -208,6 +221,8 @@ class ScanProgressRenderer {
|
|
|
208
221
|
}
|
|
209
222
|
}
|
|
210
223
|
onWroteDataflow(outputPath) {
|
|
224
|
+
if (this.closed)
|
|
225
|
+
return;
|
|
211
226
|
this.start();
|
|
212
227
|
this.completeActiveStep();
|
|
213
228
|
const label = 'Saved your data-flow map';
|
|
@@ -225,6 +240,8 @@ class ScanProgressRenderer {
|
|
|
225
240
|
}
|
|
226
241
|
/** Store preview URL for the "What to do next" note. Machine line stays in upload. */
|
|
227
242
|
onPreviewUrl(previewUrl, notice) {
|
|
243
|
+
if (this.closed)
|
|
244
|
+
return;
|
|
228
245
|
this.previewUrl = previewUrl;
|
|
229
246
|
this.previewNotice = notice;
|
|
230
247
|
}
|
|
@@ -250,6 +267,8 @@ class ScanProgressRenderer {
|
|
|
250
267
|
* keeps the `[scan] …` stderr line scripts may grep for.
|
|
251
268
|
*/
|
|
252
269
|
warn(message) {
|
|
270
|
+
if (this.closed)
|
|
271
|
+
return;
|
|
253
272
|
if (this.useClack) {
|
|
254
273
|
this.prompts().log.warn(message);
|
|
255
274
|
}
|
|
@@ -262,6 +281,8 @@ class ScanProgressRenderer {
|
|
|
262
281
|
* Clack folds them into one dimmed note so they don't break the guide rail.
|
|
263
282
|
*/
|
|
264
283
|
showTechnicalDetails(title, lines) {
|
|
284
|
+
if (this.closed)
|
|
285
|
+
return;
|
|
265
286
|
if (lines.length === 0)
|
|
266
287
|
return;
|
|
267
288
|
if (this.useClack) {
|
|
@@ -278,6 +299,9 @@ class ScanProgressRenderer {
|
|
|
278
299
|
}
|
|
279
300
|
}
|
|
280
301
|
finish() {
|
|
302
|
+
if (this.closed)
|
|
303
|
+
return;
|
|
304
|
+
this.closed = true;
|
|
281
305
|
this.completeActiveStep();
|
|
282
306
|
const nextSteps = [];
|
|
283
307
|
let closing = 'All done — nice work.';
|
|
@@ -320,6 +344,59 @@ class ScanProgressRenderer {
|
|
|
320
344
|
this.writePlain(closing);
|
|
321
345
|
}
|
|
322
346
|
}
|
|
347
|
+
/**
|
|
348
|
+
* Cancel an in-flight scan UI (Ctrl+C). Stops the spinner with a red mark
|
|
349
|
+
* in Clack mode; prints a short line in plain mode. Does not run finish().
|
|
350
|
+
*/
|
|
351
|
+
abort(message = 'Scan cancelled') {
|
|
352
|
+
if (this.closed)
|
|
353
|
+
return;
|
|
354
|
+
this.closed = true;
|
|
355
|
+
if (this.useClack && this.spinner) {
|
|
356
|
+
if (typeof this.spinner.cancel === 'function') {
|
|
357
|
+
this.spinner.cancel(message);
|
|
358
|
+
}
|
|
359
|
+
else {
|
|
360
|
+
this.spinner.stop(message);
|
|
361
|
+
}
|
|
362
|
+
this.spinner = null;
|
|
363
|
+
this.activeStep = null;
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
this.activeStep = null;
|
|
367
|
+
if (this.useClack) {
|
|
368
|
+
// Between steps: a raw line would break Clack's guide rail.
|
|
369
|
+
this.prompts().log.warn(message);
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
this.writePlain(message);
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* End the scan UI on an error: closes the active spinner with the error
|
|
376
|
+
* mark (or logs an error line between steps). Does not run finish().
|
|
377
|
+
*/
|
|
378
|
+
fail(message) {
|
|
379
|
+
if (this.closed)
|
|
380
|
+
return;
|
|
381
|
+
this.closed = true;
|
|
382
|
+
if (this.useClack && this.spinner) {
|
|
383
|
+
if (typeof this.spinner.error === 'function') {
|
|
384
|
+
this.spinner.error(message);
|
|
385
|
+
}
|
|
386
|
+
else {
|
|
387
|
+
this.spinner.stop(message);
|
|
388
|
+
}
|
|
389
|
+
this.spinner = null;
|
|
390
|
+
this.activeStep = null;
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
this.activeStep = null;
|
|
394
|
+
if (this.useClack) {
|
|
395
|
+
this.prompts().log.error(message);
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
this.writePlain(message);
|
|
399
|
+
}
|
|
323
400
|
transitionTo(step) {
|
|
324
401
|
if (this.activeStep === step || this.completedSteps.has(step)) {
|
|
325
402
|
return;
|
|
@@ -330,11 +407,24 @@ class ScanProgressRenderer {
|
|
|
330
407
|
if (this.useClack) {
|
|
331
408
|
this.spinner = this.prompts().spinner({ withGuide: true });
|
|
332
409
|
this.spinner.start(label);
|
|
410
|
+
this.restoreSignalKeys();
|
|
333
411
|
}
|
|
334
412
|
else {
|
|
335
413
|
this.writePlain(`… ${label}`);
|
|
336
414
|
}
|
|
337
415
|
}
|
|
416
|
+
/**
|
|
417
|
+
* Clack's spinner puts stdin in raw mode, where Ctrl+C is a keypress it
|
|
418
|
+
* answers with process.exit(0) — skipping our SIGINT handler and leaving
|
|
419
|
+
* the scan job running. The spinner only writes, so hand Ctrl+C back to
|
|
420
|
+
* the terminal as a real signal.
|
|
421
|
+
*/
|
|
422
|
+
restoreSignalKeys() {
|
|
423
|
+
const stdin = this.stdin;
|
|
424
|
+
if (stdin?.isTTY && typeof stdin.setRawMode === 'function') {
|
|
425
|
+
stdin.setRawMode(false);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
338
428
|
completeActiveStep() {
|
|
339
429
|
if (!this.activeStep)
|
|
340
430
|
return;
|
|
@@ -396,6 +486,7 @@ async function createScanProgressRenderer(options) {
|
|
|
396
486
|
projectLabel: options?.projectLabel,
|
|
397
487
|
version: options?.version,
|
|
398
488
|
columns: options?.columns ?? process.stdout.columns,
|
|
489
|
+
stdin: options?.stdin ?? process.stdin,
|
|
399
490
|
colorDepth: options?.colorDepth ??
|
|
400
491
|
(typeof process.stdout.getColorDepth === 'function'
|
|
401
492
|
? process.stdout.getColorDepth()
|
package/dist/src/ui/types.d.ts
CHANGED
|
@@ -25,6 +25,11 @@ export interface ScanProgressRendererOptions {
|
|
|
25
25
|
writeLine?: (line: string) => void;
|
|
26
26
|
/** Injected Clack module. Tests pass a mock; production loads the ESM package. */
|
|
27
27
|
prompts?: typeof import('@clack/prompts');
|
|
28
|
+
/** Terminal input whose raw mode the spinner toggles. Defaults to process.stdin. */
|
|
29
|
+
stdin?: {
|
|
30
|
+
isTTY?: boolean;
|
|
31
|
+
setRawMode?: (mode: boolean) => unknown;
|
|
32
|
+
};
|
|
28
33
|
}
|
|
29
34
|
export interface TeachingLineGroups {
|
|
30
35
|
routes: string[];
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const platform_proxy_provider_1 = require("../../../src/ai-enrichment/providers/platform-proxy-provider");
|
|
4
|
+
const scan_env_1 = require("../../../src/config/scan-env");
|
|
4
5
|
describe('PlatformProxyProvider', () => {
|
|
5
6
|
const originalFetch = global.fetch;
|
|
6
7
|
afterEach(() => {
|
|
7
8
|
global.fetch = originalFetch;
|
|
9
|
+
(0, scan_env_1.setScanAiDebugSuppressed)(false);
|
|
10
|
+
jest.restoreAllMocks();
|
|
8
11
|
});
|
|
9
12
|
it('submits a task and polls until completed', async () => {
|
|
10
13
|
const calls = [];
|
|
@@ -199,4 +202,27 @@ describe('PlatformProxyProvider', () => {
|
|
|
199
202
|
});
|
|
200
203
|
await expect(provider.infer({ prompt: 'test', model: 'gpt-4o-mini' })).rejects.toThrow('Could not reach the DataParade API (POST http://localhost:3000/api/scans/cli/ai/infer/tasks): ECONNRESET: other side closed. Tried 3 times. Run the scan again.');
|
|
201
204
|
});
|
|
205
|
+
it('keeps retry notices out of the terminal while the progress UI owns it', async () => {
|
|
206
|
+
const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => { });
|
|
207
|
+
global.fetch = jest.fn(async () => {
|
|
208
|
+
const err = new TypeError('fetch failed');
|
|
209
|
+
err.cause = Object.assign(new Error('other side closed'), {
|
|
210
|
+
code: 'ECONNRESET',
|
|
211
|
+
});
|
|
212
|
+
throw err;
|
|
213
|
+
});
|
|
214
|
+
const provider = new platform_proxy_provider_1.PlatformProxyProvider({
|
|
215
|
+
apiBaseUrl: 'http://localhost:3000',
|
|
216
|
+
workspaceApiKey: 'dp_anon_test',
|
|
217
|
+
jobId: 'job-1',
|
|
218
|
+
networkRetryDelaysMs: [0],
|
|
219
|
+
sleep: async () => undefined,
|
|
220
|
+
});
|
|
221
|
+
(0, scan_env_1.setScanAiDebugSuppressed)(true);
|
|
222
|
+
await expect(provider.infer({ prompt: 'test', model: 'gpt-4o-mini' })).rejects.toThrow('Tried 2 times');
|
|
223
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
224
|
+
(0, scan_env_1.setScanAiDebugSuppressed)(false);
|
|
225
|
+
await expect(provider.infer({ prompt: 'test', model: 'gpt-4o-mini' })).rejects.toThrow('Tried 2 times');
|
|
226
|
+
expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('Retrying (1/1)'));
|
|
227
|
+
});
|
|
202
228
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const node_events_1 = require("node:events");
|
|
4
|
+
const scan_interrupt_handlers_1 = require("../../../src/cli/scan-interrupt-handlers");
|
|
5
|
+
describe('installCliScanInterruptHandlers', () => {
|
|
6
|
+
function setup(options) {
|
|
7
|
+
const proc = new node_events_1.EventEmitter();
|
|
8
|
+
const exits = [];
|
|
9
|
+
const abortUi = jest.fn();
|
|
10
|
+
const reportFailed = jest.fn().mockResolvedValue(undefined);
|
|
11
|
+
let completionStatus = options?.completionStatus ?? 'none';
|
|
12
|
+
const uninstall = (0, scan_interrupt_handlers_1.installCliScanInterruptHandlers)({
|
|
13
|
+
proc,
|
|
14
|
+
exit: (code) => {
|
|
15
|
+
exits.push(code);
|
|
16
|
+
},
|
|
17
|
+
getState: () => ({
|
|
18
|
+
apiKey: options?.apiKey ?? 'dp_live_test',
|
|
19
|
+
jobId: options?.jobId ?? 'job-1',
|
|
20
|
+
completionStatus,
|
|
21
|
+
inFlight: options?.inFlight,
|
|
22
|
+
}),
|
|
23
|
+
setCompletionStatus: (status) => {
|
|
24
|
+
completionStatus = status;
|
|
25
|
+
},
|
|
26
|
+
onAbortUi: abortUi,
|
|
27
|
+
reportFailed,
|
|
28
|
+
});
|
|
29
|
+
return {
|
|
30
|
+
proc,
|
|
31
|
+
exits,
|
|
32
|
+
abortUi,
|
|
33
|
+
reportFailed,
|
|
34
|
+
uninstall,
|
|
35
|
+
setCompletionStatus: (status) => {
|
|
36
|
+
completionStatus = status;
|
|
37
|
+
},
|
|
38
|
+
getCompletionStatus: () => completionStatus,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
afterEach(() => {
|
|
42
|
+
jest.useRealTimers();
|
|
43
|
+
});
|
|
44
|
+
it('reports scan_interrupted once on SIGINT and exits 130', async () => {
|
|
45
|
+
const { proc, exits, abortUi, reportFailed, uninstall } = setup();
|
|
46
|
+
proc.emit('SIGINT');
|
|
47
|
+
await Promise.resolve();
|
|
48
|
+
await Promise.resolve();
|
|
49
|
+
expect(abortUi).toHaveBeenCalledTimes(1);
|
|
50
|
+
expect(reportFailed).toHaveBeenCalledTimes(1);
|
|
51
|
+
const [reportInput] = reportFailed.mock.calls[0];
|
|
52
|
+
expect(reportInput.apiKey).toBe('dp_live_test');
|
|
53
|
+
expect(reportInput.jobId).toBe('job-1');
|
|
54
|
+
expect(reportInput.timeoutMs).toBeGreaterThan(0);
|
|
55
|
+
expect(reportInput.timeoutMs).toBeLessThanOrEqual(scan_interrupt_handlers_1.CLI_SCAN_INTERRUPT_COMPLETE_TIMEOUT_MS);
|
|
56
|
+
expect(exits).toEqual([scan_interrupt_handlers_1.CLI_SCAN_INTERRUPT_EXIT_CODES.SIGINT]);
|
|
57
|
+
uninstall();
|
|
58
|
+
});
|
|
59
|
+
it('exits immediately on a second signal without reporting again', async () => {
|
|
60
|
+
const { proc, exits, reportFailed, uninstall } = setup();
|
|
61
|
+
let resolveReport;
|
|
62
|
+
reportFailed.mockImplementation(() => new Promise((resolve) => {
|
|
63
|
+
resolveReport = resolve;
|
|
64
|
+
}));
|
|
65
|
+
proc.emit('SIGINT');
|
|
66
|
+
await Promise.resolve();
|
|
67
|
+
expect(reportFailed).toHaveBeenCalledTimes(1);
|
|
68
|
+
proc.emit('SIGINT');
|
|
69
|
+
expect(exits).toEqual([scan_interrupt_handlers_1.CLI_SCAN_INTERRUPT_EXIT_CODES.SIGINT]);
|
|
70
|
+
expect(reportFailed).toHaveBeenCalledTimes(1);
|
|
71
|
+
resolveReport?.();
|
|
72
|
+
await Promise.resolve();
|
|
73
|
+
await Promise.resolve();
|
|
74
|
+
expect(exits).toEqual([
|
|
75
|
+
scan_interrupt_handlers_1.CLI_SCAN_INTERRUPT_EXIT_CODES.SIGINT,
|
|
76
|
+
scan_interrupt_handlers_1.CLI_SCAN_INTERRUPT_EXIT_CODES.SIGINT,
|
|
77
|
+
]);
|
|
78
|
+
uninstall();
|
|
79
|
+
});
|
|
80
|
+
it('waits for an in-flight complete instead of reporting again', async () => {
|
|
81
|
+
let resolveInFlight;
|
|
82
|
+
const inFlight = new Promise((resolve) => {
|
|
83
|
+
resolveInFlight = resolve;
|
|
84
|
+
});
|
|
85
|
+
const { proc, exits, reportFailed, uninstall, setCompletionStatus } = setup({ completionStatus: 'in_flight', inFlight });
|
|
86
|
+
proc.emit('SIGTERM');
|
|
87
|
+
await Promise.resolve();
|
|
88
|
+
expect(exits).toEqual([]);
|
|
89
|
+
// The scan's own complete lands.
|
|
90
|
+
setCompletionStatus('done');
|
|
91
|
+
resolveInFlight?.();
|
|
92
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
93
|
+
expect(reportFailed).not.toHaveBeenCalled();
|
|
94
|
+
expect(exits).toEqual([scan_interrupt_handlers_1.CLI_SCAN_INTERRUPT_EXIT_CODES.SIGTERM]);
|
|
95
|
+
uninstall();
|
|
96
|
+
});
|
|
97
|
+
it('reports scan_interrupted when the in-flight complete fails', async () => {
|
|
98
|
+
let rejectInFlight;
|
|
99
|
+
const inFlight = new Promise((_resolve, reject) => {
|
|
100
|
+
rejectInFlight = reject;
|
|
101
|
+
});
|
|
102
|
+
const { proc, exits, reportFailed, uninstall, setCompletionStatus } = setup({ completionStatus: 'in_flight', inFlight });
|
|
103
|
+
proc.emit('SIGINT');
|
|
104
|
+
await Promise.resolve();
|
|
105
|
+
// The scan path resets the status when its complete throws.
|
|
106
|
+
setCompletionStatus('none');
|
|
107
|
+
rejectInFlight?.(new Error('network down'));
|
|
108
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
109
|
+
expect(reportFailed).toHaveBeenCalledTimes(1);
|
|
110
|
+
expect(exits).toEqual([scan_interrupt_handlers_1.CLI_SCAN_INTERRUPT_EXIT_CODES.SIGINT]);
|
|
111
|
+
uninstall();
|
|
112
|
+
});
|
|
113
|
+
it('claims the completion so the scan path does not report again', async () => {
|
|
114
|
+
const { proc, reportFailed, uninstall, getCompletionStatus } = setup();
|
|
115
|
+
let statusDuringReport;
|
|
116
|
+
reportFailed.mockImplementation(() => {
|
|
117
|
+
statusDuringReport = getCompletionStatus();
|
|
118
|
+
return Promise.resolve();
|
|
119
|
+
});
|
|
120
|
+
proc.emit('SIGINT');
|
|
121
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
122
|
+
expect(statusDuringReport).toBe('in_flight');
|
|
123
|
+
expect(getCompletionStatus()).toBe('done');
|
|
124
|
+
uninstall();
|
|
125
|
+
});
|
|
126
|
+
it('does not block exit when the complete API hangs past the timeout', async () => {
|
|
127
|
+
jest.useFakeTimers();
|
|
128
|
+
const { proc, exits, reportFailed, uninstall } = setup();
|
|
129
|
+
reportFailed.mockImplementation(({ timeoutMs }) => new Promise((_resolve, reject) => {
|
|
130
|
+
setTimeout(() => {
|
|
131
|
+
reject(new Error('aborted'));
|
|
132
|
+
}, timeoutMs);
|
|
133
|
+
}));
|
|
134
|
+
proc.emit('SIGHUP');
|
|
135
|
+
await Promise.resolve();
|
|
136
|
+
expect(reportFailed).toHaveBeenCalledTimes(1);
|
|
137
|
+
expect(exits).toEqual([]);
|
|
138
|
+
await jest.advanceTimersByTimeAsync(scan_interrupt_handlers_1.CLI_SCAN_INTERRUPT_COMPLETE_TIMEOUT_MS);
|
|
139
|
+
await Promise.resolve();
|
|
140
|
+
await Promise.resolve();
|
|
141
|
+
expect(exits).toEqual([scan_interrupt_handlers_1.CLI_SCAN_INTERRUPT_EXIT_CODES.SIGHUP]);
|
|
142
|
+
uninstall();
|
|
143
|
+
});
|
|
144
|
+
it('uses exit codes 130, 143, and 129 for SIGINT, SIGTERM, and SIGHUP', async () => {
|
|
145
|
+
for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {
|
|
146
|
+
const { proc, exits, uninstall } = setup();
|
|
147
|
+
proc.emit(signal);
|
|
148
|
+
await Promise.resolve();
|
|
149
|
+
await Promise.resolve();
|
|
150
|
+
expect(exits).toEqual([scan_interrupt_handlers_1.CLI_SCAN_INTERRUPT_EXIT_CODES[signal]]);
|
|
151
|
+
uninstall();
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
});
|
|
@@ -64,11 +64,11 @@ describe('scan quota flow', () => {
|
|
|
64
64
|
statusCode: 409,
|
|
65
65
|
message: {
|
|
66
66
|
code: 'scan_already_running',
|
|
67
|
-
message: '
|
|
67
|
+
message: 'Another scan is already running in this workspace. Wait for it to finish, if it was stopped, it is released automatically after 60 minutes of inactivity.',
|
|
68
68
|
},
|
|
69
69
|
}, 409));
|
|
70
70
|
await (0, cli_1.run)(['node', 'cli', 'scan', tempRoot, '--ai-inference']);
|
|
71
|
-
expect(errorSpy).toHaveBeenCalledWith('[scan] scan in progress:
|
|
71
|
+
expect(errorSpy).toHaveBeenCalledWith('[scan] scan in progress: Another scan is already running in this workspace. Wait for it to finish, if it was stopped, it is released automatically after 60 minutes of inactivity.');
|
|
72
72
|
errorSpy.mockRestore();
|
|
73
73
|
});
|
|
74
74
|
it('reports failed completion when preflight succeeds but config validation fails', async () => {
|
|
@@ -16,11 +16,11 @@ describe("readCliApiErrorMessage", () => {
|
|
|
16
16
|
statusCode: 409,
|
|
17
17
|
message: {
|
|
18
18
|
code: "scan_already_running",
|
|
19
|
-
message: "
|
|
19
|
+
message: "Another scan is already running in this workspace. Wait for it to finish, if it was stopped, it is released automatically after 60 minutes of inactivity.",
|
|
20
20
|
},
|
|
21
21
|
}, "fallback")).toEqual({
|
|
22
22
|
code: "scan_already_running",
|
|
23
|
-
message: "
|
|
23
|
+
message: "Another scan is already running in this workspace. Wait for it to finish, if it was stopped, it is released automatically after 60 minutes of inactivity.",
|
|
24
24
|
});
|
|
25
25
|
});
|
|
26
26
|
it("joins validation message arrays", () => {
|
|
@@ -37,6 +37,8 @@ jest.mock('@clack/prompts', () => {
|
|
|
37
37
|
const spin = {
|
|
38
38
|
start: jest.fn(),
|
|
39
39
|
stop: jest.fn(),
|
|
40
|
+
cancel: jest.fn(),
|
|
41
|
+
error: jest.fn(),
|
|
40
42
|
message: jest.fn(),
|
|
41
43
|
};
|
|
42
44
|
return {
|
|
@@ -49,6 +51,7 @@ jest.mock('@clack/prompts', () => {
|
|
|
49
51
|
success: jest.fn(),
|
|
50
52
|
step: jest.fn(),
|
|
51
53
|
warn: jest.fn(),
|
|
54
|
+
error: jest.fn(),
|
|
52
55
|
},
|
|
53
56
|
};
|
|
54
57
|
});
|
|
@@ -293,4 +296,135 @@ describe('ScanProgressRenderer', () => {
|
|
|
293
296
|
'[scan] ai-usage: provider_calls=1 tokens_total=10',
|
|
294
297
|
]);
|
|
295
298
|
});
|
|
299
|
+
it('abort cancels the active spinner and skips the finish outro', async () => {
|
|
300
|
+
const { lines, writeLine } = captureLines();
|
|
301
|
+
const ui = await (0, scan_progress_renderer_1.createScanProgressRenderer)({
|
|
302
|
+
isTTY: true,
|
|
303
|
+
noColor: false,
|
|
304
|
+
writeLine,
|
|
305
|
+
prompts,
|
|
306
|
+
});
|
|
307
|
+
const spin = prompts.spinner();
|
|
308
|
+
prompts.spinner.mockClear();
|
|
309
|
+
ui.onProgress({
|
|
310
|
+
phase: 'ingest',
|
|
311
|
+
filesProcessed: 0,
|
|
312
|
+
totalFiles: 0,
|
|
313
|
+
progress: 0.05,
|
|
314
|
+
});
|
|
315
|
+
expect(prompts.spinner).toHaveBeenCalledTimes(1);
|
|
316
|
+
ui.abort('Scan cancelled');
|
|
317
|
+
expect(spin.cancel).toHaveBeenCalledWith('Scan cancelled');
|
|
318
|
+
expect(spin.stop).not.toHaveBeenCalled();
|
|
319
|
+
expect(prompts.outro).not.toHaveBeenCalled();
|
|
320
|
+
expect(lines.some((line) => line.includes('All done'))).toBe(false);
|
|
321
|
+
});
|
|
322
|
+
it('hands Ctrl+C back to the terminal after starting a spinner', async () => {
|
|
323
|
+
const { writeLine } = captureLines();
|
|
324
|
+
const stdin = { isTTY: true, setRawMode: jest.fn() };
|
|
325
|
+
const ui = await (0, scan_progress_renderer_1.createScanProgressRenderer)({
|
|
326
|
+
isTTY: true,
|
|
327
|
+
noColor: false,
|
|
328
|
+
writeLine,
|
|
329
|
+
prompts,
|
|
330
|
+
stdin,
|
|
331
|
+
});
|
|
332
|
+
ui.onProgress({
|
|
333
|
+
phase: 'ingest',
|
|
334
|
+
filesProcessed: 0,
|
|
335
|
+
totalFiles: 0,
|
|
336
|
+
progress: 0.05,
|
|
337
|
+
});
|
|
338
|
+
expect(stdin.setRawMode).toHaveBeenLastCalledWith(false);
|
|
339
|
+
});
|
|
340
|
+
it('abort between steps uses a Clack log line, not a raw write', async () => {
|
|
341
|
+
const { lines, writeLine } = captureLines();
|
|
342
|
+
const ui = await (0, scan_progress_renderer_1.createScanProgressRenderer)({
|
|
343
|
+
isTTY: true,
|
|
344
|
+
noColor: false,
|
|
345
|
+
writeLine,
|
|
346
|
+
prompts,
|
|
347
|
+
});
|
|
348
|
+
ui.abort('Scan cancelled');
|
|
349
|
+
expect(prompts.log.warn).toHaveBeenCalledWith('Scan cancelled');
|
|
350
|
+
expect(lines).not.toContain('Scan cancelled');
|
|
351
|
+
expect(prompts.outro).not.toHaveBeenCalled();
|
|
352
|
+
});
|
|
353
|
+
it('fail closes the active spinner with the error mark', async () => {
|
|
354
|
+
const { writeLine } = captureLines();
|
|
355
|
+
const ui = await (0, scan_progress_renderer_1.createScanProgressRenderer)({
|
|
356
|
+
isTTY: true,
|
|
357
|
+
noColor: false,
|
|
358
|
+
writeLine,
|
|
359
|
+
prompts,
|
|
360
|
+
});
|
|
361
|
+
const spin = prompts.spinner();
|
|
362
|
+
prompts.spinner.mockClear();
|
|
363
|
+
ui.onProgress({
|
|
364
|
+
phase: 'ingest',
|
|
365
|
+
filesProcessed: 0,
|
|
366
|
+
totalFiles: 0,
|
|
367
|
+
progress: 0.05,
|
|
368
|
+
});
|
|
369
|
+
ui.fail('Scan failed: API unreachable');
|
|
370
|
+
expect(spin.error).toHaveBeenCalledWith('Scan failed: API unreachable');
|
|
371
|
+
expect(prompts.outro).not.toHaveBeenCalled();
|
|
372
|
+
});
|
|
373
|
+
it('fail between steps logs a Clack error line', async () => {
|
|
374
|
+
const { lines, writeLine } = captureLines();
|
|
375
|
+
const ui = await (0, scan_progress_renderer_1.createScanProgressRenderer)({
|
|
376
|
+
isTTY: true,
|
|
377
|
+
noColor: false,
|
|
378
|
+
writeLine,
|
|
379
|
+
prompts,
|
|
380
|
+
});
|
|
381
|
+
ui.fail('Another scan is already running in this workspace.');
|
|
382
|
+
expect(prompts.log.error).toHaveBeenCalledWith('Another scan is already running in this workspace.');
|
|
383
|
+
expect(lines).toHaveLength(0);
|
|
384
|
+
});
|
|
385
|
+
it('ignores progress that arrives after the scan was cancelled', async () => {
|
|
386
|
+
const { lines, writeLine } = captureLines();
|
|
387
|
+
const ui = await (0, scan_progress_renderer_1.createScanProgressRenderer)({
|
|
388
|
+
isTTY: false,
|
|
389
|
+
noColor: true,
|
|
390
|
+
writeLine,
|
|
391
|
+
});
|
|
392
|
+
ui.onProgress({
|
|
393
|
+
phase: 'ingest',
|
|
394
|
+
filesProcessed: 0,
|
|
395
|
+
totalFiles: 0,
|
|
396
|
+
progress: 0.05,
|
|
397
|
+
});
|
|
398
|
+
ui.abort('Scan cancelled');
|
|
399
|
+
const linesAtAbort = lines.length;
|
|
400
|
+
// Work queued behind a blocking phase lands after Ctrl+C.
|
|
401
|
+
ui.onProgress({
|
|
402
|
+
phase: 'ai_enrichment',
|
|
403
|
+
filesProcessed: 0,
|
|
404
|
+
totalFiles: 0,
|
|
405
|
+
progress: 0.6,
|
|
406
|
+
});
|
|
407
|
+
ui.warn('late warning');
|
|
408
|
+
ui.fail('Scan failed: late');
|
|
409
|
+
ui.finish();
|
|
410
|
+
expect(lines).toHaveLength(linesAtAbort);
|
|
411
|
+
expect(lines[lines.length - 1]).toBe('Scan cancelled');
|
|
412
|
+
});
|
|
413
|
+
it('abort prints a plain cancellation line when Clack is off', async () => {
|
|
414
|
+
const { lines, writeLine } = captureLines();
|
|
415
|
+
const ui = await (0, scan_progress_renderer_1.createScanProgressRenderer)({
|
|
416
|
+
isTTY: false,
|
|
417
|
+
noColor: false,
|
|
418
|
+
writeLine,
|
|
419
|
+
});
|
|
420
|
+
ui.onProgress({
|
|
421
|
+
phase: 'ingest',
|
|
422
|
+
filesProcessed: 0,
|
|
423
|
+
totalFiles: 0,
|
|
424
|
+
progress: 0.05,
|
|
425
|
+
});
|
|
426
|
+
ui.abort('Scan cancelled');
|
|
427
|
+
expect(lines).toContain('Scan cancelled');
|
|
428
|
+
expect(lines.some((line) => line.includes('All done'))).toBe(false);
|
|
429
|
+
});
|
|
296
430
|
});
|
|
@@ -9,3 +9,5 @@ export declare const MANAGED_NODE_Y_STEP = 200;
|
|
|
9
9
|
export declare const TERRAFORM_LANE_X_STEP = 400;
|
|
10
10
|
/** Horizontal space per section (TF lanes + optional managed column beside provider). */
|
|
11
11
|
export declare const SECTION_BLOCK_WIDTH: number;
|
|
12
|
+
/** Space between the last column of one section and the first column of the next (one empty lane). */
|
|
13
|
+
export declare const SECTION_GAP_X: number;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SECTION_BLOCK_WIDTH = exports.TERRAFORM_LANE_X_STEP = exports.MANAGED_NODE_Y_STEP = exports.MANAGED_NODE_Y_BASE_OFFSET = exports.MANAGED_NODE_X_OFFSET = exports.NODES_PER_ROW = exports.NODE_VERTICAL_SPACING = exports.NODE_HORIZONTAL_SPACING = void 0;
|
|
3
|
+
exports.SECTION_GAP_X = exports.SECTION_BLOCK_WIDTH = exports.TERRAFORM_LANE_X_STEP = exports.MANAGED_NODE_Y_STEP = exports.MANAGED_NODE_Y_BASE_OFFSET = exports.MANAGED_NODE_X_OFFSET = exports.NODES_PER_ROW = exports.NODE_VERTICAL_SPACING = exports.NODE_HORIZONTAL_SPACING = void 0;
|
|
4
4
|
exports.NODE_HORIZONTAL_SPACING = 350;
|
|
5
5
|
exports.NODE_VERTICAL_SPACING = 200;
|
|
6
6
|
exports.NODES_PER_ROW = 4;
|
|
@@ -12,3 +12,5 @@ exports.MANAGED_NODE_Y_STEP = exports.NODE_VERTICAL_SPACING;
|
|
|
12
12
|
exports.TERRAFORM_LANE_X_STEP = 400;
|
|
13
13
|
/** Horizontal space per section (TF lanes + optional managed column beside provider). */
|
|
14
14
|
exports.SECTION_BLOCK_WIDTH = Math.max(exports.NODES_PER_ROW * exports.NODE_HORIZONTAL_SPACING, 5 * exports.TERRAFORM_LANE_X_STEP + exports.MANAGED_NODE_X_OFFSET + 120);
|
|
15
|
+
/** Space between the last column of one section and the first column of the next (one empty lane). */
|
|
16
|
+
exports.SECTION_GAP_X = 2 * exports.TERRAFORM_LANE_X_STEP;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DiagramNodeSchema } from "../../schema";
|
|
2
|
+
import type { ComponentByIdMap } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Section layouts start each section at a fixed `SECTION_BLOCK_WIDTH` offset,
|
|
5
|
+
* which leaves wide empty bands after sparse sections. Shift every section left
|
|
6
|
+
* so it starts `SECTION_GAP_X` after the previous one actually ends; the shape
|
|
7
|
+
* inside each section is unchanged.
|
|
8
|
+
*/
|
|
9
|
+
export declare function packSectionsHorizontally(nodes: DiagramNodeSchema[], componentsById: ComponentByIdMap, sectionIds: string[]): void;
|