Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Keep CI cancellation refusals visible after a run completes

pulse-triage[bot]203d1a8fb5af
diff --git a/.github/scripts/reclaim-closed-pr-capacity.cjs b/.github/scripts/reclaim-closed-pr-capacity.cjs
index 5ce02e5399..bb44817f20 100644
--- a/.github/scripts/reclaim-closed-pr-capacity.cjs
+++ b/.github/scripts/reclaim-closed-pr-capacity.cjs
@@ -69,7 +69,12 @@ async function cancelClosedPullRequestRuns({ github, context, core }) {
core.info(`Requested cancellation of ${run.name} run ${run.id} (${run.status}).`);
} catch (error) {
// Completion can race cancellation. Suppress only that proven terminal
- // race; authentication and API failures stay visible.
+ // conflict; a later completed run cannot clear a refusal, rate limit,
+ // transport error or unknown cancellation result. Stop without another
+ // API call for those errors, even if the run has since completed.
+ if (error?.status !== 409) {
+ throw error;
+ }
const refreshed = await github.rest.actions.getWorkflowRun({
owner,
repo,
diff --git a/.github/scripts/reclaim-closed-pr-capacity.test.cjs b/.github/scripts/reclaim-closed-pr-capacity.test.cjs
index a835b36a61..a53a3097e0 100644
--- a/.github/scripts/reclaim-closed-pr-capacity.test.cjs
+++ b/.github/scripts/reclaim-closed-pr-capacity.test.cjs
@@ -8,8 +8,10 @@ const {
cancelClosedPullRequestRuns,
} = require('./reclaim-closed-pr-capacity.cjs');
-function fixture({ state = 'closed', openForHead = [], runs = {}, cancelError, refreshed = 'completed' } = {}) {
+function fixture({ state = 'closed', openForHead = [], runs = {}, cancelError, refreshed = 'completed', refreshError } = {}) {
const cancelled = [];
+ const cancellationAttempts = [];
+ const readbacks = [];
const messages = [];
const github = {
paginate: async (method, input) => method(input),
@@ -21,10 +23,15 @@ function fixture({ state = 'closed', openForHead = [], runs = {}, cancelError, r
actions: {
listWorkflowRunsForRepo: async ({ status }) => runs[status] || [],
cancelWorkflowRun: async ({ run_id: runId }) => {
+ cancellationAttempts.push(runId);
if (cancelError) throw cancelError;
cancelled.push(runId);
},
- getWorkflowRun: async () => ({ data: { status: refreshed } }),
+ getWorkflowRun: async ({ run_id: runId }) => {
+ readbacks.push(runId);
+ if (refreshError) throw refreshError;
+ return { data: { status: refreshed } };
+ },
},
},
};
@@ -45,7 +52,21 @@ function fixture({ state = 'closed', openForHead = [], runs = {}, cancelError, r
warning: (message) => messages.push(message),
setFailed: (message) => messages.push(message),
};
- return { github, context, core, cancelled, messages };
+ return { github, context, core, cancelled, cancellationAttempts, readbacks, messages };
+}
+
+function requestError(status) {
+ return Object.assign(new Error(`request failed (${status})`), { status });
+}
+
+function matchingRun(id = 10) {
+ return {
+ id,
+ name: 'Core E2E Tests',
+ status: 'in_progress',
+ head_branch: 'topic/old',
+ head_repository: { full_name: 'rcourtman/Pulse' },
+ };
}
test('cancels only unfinished runs for the exact closed head', async () => {
@@ -89,22 +110,56 @@ test('does nothing when an open pull request reused the head branch', async () =
});
test('accepts only a proven completion race', async () => {
- const run = {
- id: 10,
- name: 'Core E2E Tests',
- status: 'in_progress',
- head_branch: 'topic/old',
- head_repository: { full_name: 'rcourtman/Pulse' },
- };
- const raced = fixture({ runs: { in_progress: [run] }, cancelError: new Error('409') });
+ const run = matchingRun();
+ const conflict = requestError(409);
+ const raced = fixture({ runs: { in_progress: [run] }, cancelError: conflict });
await cancelClosedPullRequestRuns(raced);
+ assert.deepEqual(raced.cancellationAttempts, [10]);
+ assert.deepEqual(raced.readbacks, [10]);
assert.match(raced.messages[0], /completed before cancellation/);
assert.match(raced.messages.at(-1), /Requested cancellation for 0 of 1/);
const failed = fixture({
runs: { in_progress: [run] },
- cancelError: new Error('authentication failed'),
+ cancelError: conflict,
refreshed: 'in_progress',
});
- await assert.rejects(cancelClosedPullRequestRuns(failed), /authentication failed/);
+ await assert.rejects(cancelClosedPullRequestRuns(failed), (error) => error === conflict);
+ assert.deepEqual(failed.readbacks, [10]);
+});
+
+for (const status of [400, 401, 403, 404, 429, 500, undefined, '409']) {
+ test(`does not clear cancellation error ${status} with a completed run`, async () => {
+ const error = requestError(status);
+ const subject = fixture({
+ runs: { in_progress: [matchingRun(), matchingRun(11)] },
+ cancelError: error,
+ refreshed: 'completed',
+ });
+ await assert.rejects(cancelClosedPullRequestRuns(subject), (caught) => caught === error);
+ assert.deepEqual(subject.cancellationAttempts, [10], 'stop before cancelling another run');
+ assert.deepEqual(subject.cancelled, []);
+ assert.deepEqual(subject.readbacks, [], 'no follow-up API call after the failed cancellation');
+ assert.deepEqual(subject.messages, [], 'do not report the failed operation as a completion race');
+ });
+}
+
+test('does not infer a conflict from an error message', async () => {
+ const error = new Error('409');
+ const subject = fixture({ runs: { in_progress: [matchingRun()] }, cancelError: error });
+ await assert.rejects(cancelClosedPullRequestRuns(subject), (caught) => caught === error);
+ assert.deepEqual(subject.readbacks, []);
+});
+
+test('stops when the conflict readback fails', async () => {
+ const error = requestError(403);
+ const subject = fixture({
+ runs: { in_progress: [matchingRun(), matchingRun(11)] },
+ cancelError: requestError(409),
+ refreshError: error,
+ });
+ await assert.rejects(cancelClosedPullRequestRuns(subject), (caught) => caught === error);
+ assert.deepEqual(subject.readbacks, [10]);
+ assert.deepEqual(subject.cancellationAttempts, [10]);
+ assert.deepEqual(subject.messages, []);
});