Skip to content

Commit e00a7cd

Browse files
committed
test: guard cleanup against stale synchronize events
1 parent b7304e5 commit e00a7cd

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

‎.github/workflows/community-assess-cleanup.yml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ jobs:
3030
// This pull_request_target job deliberately has no checkout. The
3131
// only durable operation is removal of these fixed labels.
3232
const pr = await github.rest.pulls.get({ owner, repo, pull_number: pullNumber });
33+
const eventHeadSha = context.payload.pull_request.head.sha;
34+
if (context.payload.action === 'synchronize' && pr.data.head.sha !== eventHeadSha) {
35+
core.info('A newer head is present; skip this stale cleanup event.');
36+
return;
37+
}
3338
for (const label of labels) {
3439
if (!pr.data.labels.some((item) => item.name === label)) continue;
3540
await github.rest.issues.removeLabel({

‎tests/community_assess_publish.test.mjs‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,25 @@ test('retrigger removes the previous outcome before applying the new one', async
109109
assert.deepEqual(calls.added, ['community-assessment-needs-clarification']);
110110
});
111111

112-
test('mechanical cleanup has no agent-output dependency', () => {
112+
async function runCleanup({ currentSha, eventSha, action = 'synchronize', labels = [] }) {
113+
const { github, calls } = fakeGitHub({ sha: currentSha, labels });
114+
const context = {
115+
payload: { action, pull_request: { number: 7, head: { sha: eventSha } } },
116+
repo: { owner: 'github', repo: 'spec-kit' },
117+
};
118+
const core = { info() {} };
119+
const run = new Function('context', 'github', 'core', `return (async () => {\n${cleanupScript}\n})();`);
120+
await run(context, github, core);
121+
return calls;
122+
}
123+
124+
test('mechanical cleanup removes fixed labels and skips stale synchronize events', async () => {
113125
assert.match(cleanupScript, /pulls\.get/);
114126
assert.match(cleanupScript, /removeLabel/);
115127
assert.doesNotMatch(cleanupScript, /GH_AW_AGENT_OUTPUT|agent_output/);
128+
const sha = '1'.repeat(40);
129+
const removed = await runCleanup({ currentSha: sha, eventSha: sha, labels: ['community-assessment-fits', 'community-assessment-invalid'] });
130+
assert.deepEqual(removed.removed, ['community-assessment-fits', 'community-assessment-invalid']);
131+
const stale = await runCleanup({ currentSha: '2'.repeat(40), eventSha: '3'.repeat(40), labels: ['community-assessment-fits'] });
132+
assert.deepEqual(stale.removed, []);
116133
});

0 commit comments

Comments
 (0)