Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

chore(cli): a gap-report handler's budget starts after its module loads (#9804)

Christopher Chedeau36cde5e8ca43
diff --git a/.changeset/gap-report-handler-budget-after-load.md b/.changeset/gap-report-handler-budget-after-load.md
new file mode 100644
index 0000000000..d84d89c88d
--- /dev/null
+++ b/.changeset/gap-report-handler-budget-after-load.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/cli': patch
+---
+
+[chore] Internal: a gap-report handler's time budget starts once its module has loaded. Starting its worker and loading the module have the default deadline, so a short budget in a contract test no longer covers a slow start on a busy machine. The 30-second handler budget is unchanged.
+
+@vjeux
diff --git a/packages/cli/api/gap-report/gap-report.mjs b/packages/cli/api/gap-report/gap-report.mjs
index b4e4b02c08..a59d467e91 100644
--- a/packages/cli/api/gap-report/gap-report.mjs
+++ b/packages/cli/api/gap-report/gap-report.mjs
@@ -345,6 +345,9 @@ function failedHandler(message) {
* process.exitCode, stdout, and every continuation the handler creates. A
* timeout aborts the supplied signal, gives the handler one short turn to
* observe it, then terminates the isolate before the next handler starts.
+ * `timeoutMs` is the handler's own time and starts once its module has
+ * loaded. Starting the worker and loading the module have the default
+ * deadline.
*
* @param {Extract<HandlerEntry, {kind: 'handler'}>} entry
* @param {GapReport} report cloned before this call
@@ -393,7 +396,8 @@ async function callHandler(entry, report, timeoutMs = HANDLER_TIMEOUT_MS) {
.finally(() => resolve(outcome));
};
- const beginTimeout = () => {
+ /** @param {number} deadlineMs */
+ const beginTimeout = deadlineMs => {
if (timeout !== undefined) clearTimeout(timeout);
timeout = setTimeout(() => {
if (settled) return;
@@ -407,13 +411,13 @@ async function callHandler(entry, report, timeoutMs = HANDLER_TIMEOUT_MS) {
() => finish(timeoutOutcome),
HANDLER_ABORT_GRACE_MS,
);
- }, timeoutMs);
+ }, deadlineMs);
};
worker.on('message', message => {
if (settled || timedOut) return;
if (message?.kind === 'ready') {
- beginTimeout();
+ beginTimeout(timeoutMs);
return;
}
if (message?.kind === 'exit-code') {
@@ -458,7 +462,8 @@ async function callHandler(entry, report, timeoutMs = HANDLER_TIMEOUT_MS) {
finish(failedHandler(`Handler called process.exit(${String(code)}).`));
});
- beginTimeout();
+ // A short handler budget must not cover a slow start on a busy machine.
+ beginTimeout(Math.max(timeoutMs, HANDLER_TIMEOUT_MS));
});
}
diff --git a/packages/cli/api/gap-report/gap-report.test.mjs b/packages/cli/api/gap-report/gap-report.test.mjs
index 8bf6ca2d59..922f4854f7 100644
--- a/packages/cli/api/gap-report/gap-report.test.mjs
+++ b/packages/cli/api/gap-report/gap-report.test.mjs
@@ -501,6 +501,37 @@ describe('gapReport handler isolation', () => {
]);
});
+ it('gives a handler its whole budget after its module loads slower than that budget', async () => {
+ // The module's load outlasts the 200 ms budget, as a busy machine's
+ // worker start can. The handler then answers at once. `malformedExport`
+ // writes this module source as given.
+ addIntegration({
+ name: '@test/slow-load',
+ malformedExport:
+ 'await new Promise(resolve => setTimeout(resolve, 400));\n' +
+ "export const gapReport = {audience: 'internal', handle: async () => ({status: 'filed', message: 'loaded late'})};\n",
+ });
+ configure(['@test/slow-load']);
+ const project = await Project.load(projectDir);
+
+ const deliveries = await deliverGapReportHandlers(
+ collectGapReportHandlers(project),
+ /** @type {any} */ ({component: 'Button'}),
+ {timeoutMs: 200},
+ );
+
+ expect(deliveries).toEqual([
+ {
+ handlerType: 'integration',
+ handler: '@test/slow-load',
+ audience: 'internal',
+ status: 'filed',
+ url: null,
+ message: 'loaded late',
+ },
+ ]);
+ });
+
it('a timed-out late process.exit cannot terminate the caller', () => {
addIntegration({
name: '@test/late-exit',