autokap 1.3.1 → 1.3.2
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/cli.js +44 -2
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -257,9 +257,41 @@ program
|
|
|
257
257
|
logger.info(`Using local AutoKap dev server: ${LOCAL_API_BASE_URL}`);
|
|
258
258
|
}
|
|
259
259
|
const config = await requireConfig();
|
|
260
|
+
// AUTOKAP_RUN_ID is set by the cloud-runner provider when the CLI is
|
|
261
|
+
// launched on Fly.io. When present, we POST a completion callback at exit
|
|
262
|
+
// so the `capture_runs` row flips out of `queued` — without this the
|
|
263
|
+
// backend rate-limiter blocks future cloud recaptures.
|
|
264
|
+
const cloudRunId = process.env.AUTOKAP_RUN_ID;
|
|
265
|
+
/**
|
|
266
|
+
* Best-effort: tell the AutoKap backend whether this cloud run finished
|
|
267
|
+
* cleanly. Failures here do NOT change the CLI exit code — the artifact
|
|
268
|
+
* uploads are already done at this point, so a missed callback only
|
|
269
|
+
* affects status reporting (a reconciliation cron heals it later).
|
|
270
|
+
*/
|
|
271
|
+
const notifyCloudCallback = async (status, details) => {
|
|
272
|
+
if (!cloudRunId)
|
|
273
|
+
return;
|
|
274
|
+
try {
|
|
275
|
+
const response = await fetch(buildApiUrl(config, `/api/cli/cloud-recapture/${cloudRunId}/complete`), {
|
|
276
|
+
method: 'POST',
|
|
277
|
+
headers: { ...authHeaders(config), 'Content-Type': 'application/json' },
|
|
278
|
+
body: JSON.stringify({ status, ...details }),
|
|
279
|
+
});
|
|
280
|
+
if (!response.ok) {
|
|
281
|
+
const body = await response.text().catch(() => response.statusText);
|
|
282
|
+
logger.warn(`[auto-recapture] Cloud callback non-OK (${response.status}): ${body}`);
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
logger.info(`[auto-recapture] Cloud run marked ${status} on backend`);
|
|
286
|
+
}
|
|
287
|
+
catch (err) {
|
|
288
|
+
logger.warn(`[auto-recapture] Cloud callback failed (best-effort): ${err.message}`);
|
|
289
|
+
}
|
|
290
|
+
};
|
|
260
291
|
const data = await requestJson(config, `/api/cli/projects/${opts.project}/auto-recapture-presets`, { headers: authHeaders(config) }, 'Failed to list auto-recapture presets');
|
|
261
292
|
if (data.presets.length === 0) {
|
|
262
293
|
logger.info(`[auto-recapture] No presets enabled for project ${opts.project}`);
|
|
294
|
+
await notifyCloudCallback('completed', { totalPresets: 0, failedPresets: 0 });
|
|
263
295
|
process.exit(0);
|
|
264
296
|
}
|
|
265
297
|
const { runCapture } = await import('./cli-runner.js');
|
|
@@ -280,12 +312,22 @@ program
|
|
|
280
312
|
}
|
|
281
313
|
}
|
|
282
314
|
if (failures.length > 0) {
|
|
283
|
-
|
|
315
|
+
const errorMessage = `${failures.length}/${data.presets.length} preset(s) failed: ${failures
|
|
284
316
|
.map((failure) => failure.name ?? failure.id)
|
|
285
|
-
.join(', ')}
|
|
317
|
+
.join(', ')}`;
|
|
318
|
+
logger.error(`[auto-recapture] ${errorMessage}`);
|
|
319
|
+
await notifyCloudCallback('failed', {
|
|
320
|
+
totalPresets: data.presets.length,
|
|
321
|
+
failedPresets: failures.length,
|
|
322
|
+
errorMessage,
|
|
323
|
+
});
|
|
286
324
|
process.exit(1);
|
|
287
325
|
}
|
|
288
326
|
logger.success(`[auto-recapture] ${data.presets.length} preset(s) recaptured successfully`);
|
|
327
|
+
await notifyCloudCallback('completed', {
|
|
328
|
+
totalPresets: data.presets.length,
|
|
329
|
+
failedPresets: 0,
|
|
330
|
+
});
|
|
289
331
|
process.exit(0);
|
|
290
332
|
});
|
|
291
333
|
// ── project commands ───────────────────────────────────────────────
|