fix(automation): gate ready-state follow-ups and research web denials

Only automation bot PRs re-check source-issue pending comments before
mark-ready, so maintainer Fixes-only PRs are not stuck draft. Write
WebSearch/WebFetch denials after the isolated research pass so classify
and follow-up research can still call those tools.
This commit is contained in:
bincxz committed 2026-07-26 21:43:37 +08:00
1 parent 46864fce51
commit 2840463b3d
4 files changed
+208 -21

No files matched your search

+22 -1
View File
@@ -2642,6 +2642,22 @@ async function findOpenBotPrForIssue({ github, context, issueNumber }) {
return pulls.find((pull) => isBotPrForIssue(pull, issueNumber)) || null;
}
/**
* Source-issue follow-up readiness is only meaningful for automation bot PRs.
* Maintainer/own-actor PRs that merely say `Fixes #N` must not stay draft
* forever because issue comments lack automation processed markers.
*/
function shouldGatePullOnSourceIssueFollowups(pull) {
if (!pull) return false;
if (!extractSourceIssueNumber(pull)) return false;
const body = String(pull.body || '');
if (isBotPrMarker(body)) return true;
return (pull.labels || []).some((label) => {
const name = typeof label === 'string' ? label : label?.name;
return name === BOT_PR_LABEL;
});
}
async function getPendingIssueFollowupsForPull({
github,
context,
@@ -2649,7 +2665,10 @@ async function getPendingIssueFollowupsForPull({
botLogins = ['netcatty-bot', 'github-actions[bot]'],
}) {
const issueNumber = extractSourceIssueNumber(pull);
if (!issueNumber) return { issue: null, pending: [] };
if (!issueNumber) return { issue: null, pending: [], gated: false };
if (!shouldGatePullOnSourceIssueFollowups(pull)) {
return { issue: null, pending: [], gated: false };
}
const { data: issue } = await github.rest.issues.get({
...context.repo,
issue_number: issueNumber,
@@ -2662,6 +2681,7 @@ async function getPendingIssueFollowupsForPull({
const commentList = Array.isArray(comments) ? comments.filter(Boolean) : [];
return {
issue,
gated: true,
pending: findPendingIssueFollowups({
comments: commentList,
issueAuthorLogin: issue.user?.login,
@@ -3057,6 +3077,7 @@ module.exports = {
markNeedsHuman,
isBotPrForIssue,
findOpenBotPrForIssue,
shouldGatePullOnSourceIssueFollowups,
getPendingIssueFollowupsForPull,
ensurePullRequestDraft,
ensurePullRequestReady,
+132
View File
@@ -742,6 +742,8 @@ test('getPendingIssueFollowupsForPull protects ready state with live issue comme
number: 77,
body: `${auto.BOT_PR_MARKER}\n<!-- cursor-issue-watermark:comment-id=1 -->\nFixes #42`,
created_at: '2026-07-24T10:00:00Z',
labels: [{ name: 'automation:bot-pr' }],
user: { login: 'netcatty-bot' },
};
const github = {
rest: {
@@ -776,10 +778,82 @@ test('getPendingIssueFollowupsForPull protects ready state with live issue comme
context: { repo: { owner: 'binaricat', repo: 'Netcatty' } },
pull,
});
assert.equal(result.gated, true);
assert.equal(result.issue.number, 42);
assert.deepEqual(result.pending.map((comment) => comment.id), [2]);
});
test('shouldGatePullOnSourceIssueFollowups is limited to automation bot PRs', () => {
assert.equal(
auto.shouldGatePullOnSourceIssueFollowups({
body: `${auto.BOT_PR_MARKER}\n<!-- cursor-source-issue:42 -->\nFixes #42`,
labels: [{ name: 'automation:bot-pr' }],
user: { login: 'netcatty-bot' },
}),
true,
);
assert.equal(
auto.shouldGatePullOnSourceIssueFollowups({
body: 'Maintainer fix\n\nFixes #42',
labels: [{ name: 'bug' }],
user: { login: 'binaricat' },
}),
false,
);
assert.equal(
auto.shouldGatePullOnSourceIssueFollowups({
body: 'No closing keyword or automation marker',
labels: [{ name: 'automation:bot-pr' }],
user: { login: 'netcatty-bot' },
}),
false,
);
});
test('getPendingIssueFollowupsForPull does not block maintainer Fixes-only PRs', async () => {
let issuesFetched = 0;
const pull = {
number: 88,
body: 'Hand-written fix for the reporter.\n\nFixes #42',
created_at: '2026-07-24T10:00:00Z',
labels: [{ name: 'bug' }],
user: { login: 'binaricat' },
head: { ref: 'fix/issue-42-manual', repo: { full_name: 'binaricat/Netcatty' } },
base: { repo: { full_name: 'binaricat/Netcatty' } },
};
const github = {
rest: {
issues: {
get: async () => {
issuesFetched += 1;
return { data: { number: 42, user: { login: 'alice' } } };
},
listComments: Symbol('listComments'),
},
},
paginate: async () => {
issuesFetched += 1;
return [
{
id: 99,
user: { login: 'alice', type: 'User' },
body: 'still broken after your PR',
created_at: '2026-07-24T12:00:00Z',
},
];
},
};
const result = await auto.getPendingIssueFollowupsForPull({
github,
context: { repo: { owner: 'binaricat', repo: 'Netcatty' } },
pull,
});
assert.equal(result.gated, false);
assert.equal(result.issue, null);
assert.deepEqual(result.pending, []);
assert.equal(issuesFetched, 0);
});
test('prepareIssueFollowupContext uses the triggering comment when no PR exists', async () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'cursor-followup-'));
const outputPath = path.join(dir, 'followup.json');
@@ -1891,6 +1965,9 @@ test('workflow confines forced WebSearch to isolated read-only research passes',
assert.match(run, /Read\(input\.json\)/);
assert.match(run, /process\.env\.HOME/);
assert.match(run, /process\.env\.GITHUB_WORKSPACE/);
// Research itself must not write the non-research web-tool denylist.
assert.doesNotMatch(run, /"WebSearch\(\*\)"/);
assert.doesNotMatch(run, /"WebFetch\(\*\)"/);
}
const nonResearchAgentLines = workflow
@@ -1907,6 +1984,61 @@ test('workflow confines forced WebSearch to isolated read-only research passes',
assert.match(workflow, /name: issue-research-\$\{\{ github\.run_id \}\}[\s\S]*?overwrite: true/);
});
test('workflow denies WebSearch only after isolated research, not before it', () => {
const workflow = fs.readFileSync(
path.join(__dirname, '..', '.github', 'workflows', 'cursor-automation.yml'),
'utf8',
);
const classifyJob = workflow.match(
/\n classify:\n[\s\S]*?(?=\n [a-zA-Z0-9_]+:\n)/,
)?.[0] || '';
const followupJob = workflow.match(
/\n issue_followup:\n[\s\S]*?(?=\n [a-zA-Z0-9_]+:\n)/,
)?.[0] || '';
assert.ok(classifyJob.includes('Research external context for classification'));
assert.ok(followupJob.includes('Research external context for follow-up'));
for (const [label, job] of [
['classify', classifyJob],
['issue_followup', followupJob],
]) {
const researchIdx = job.indexOf('- name: Research external context');
assert.ok(researchIdx > 0, `${label} research step missing`);
const preResearch = job.slice(0, researchIdx);
assert.doesNotMatch(
preResearch,
/"WebSearch\(\*\)"/,
`${label} must not deny WebSearch before research`,
);
assert.doesNotMatch(
preResearch,
/"WebFetch\(\*\)"/,
`${label} must not deny WebFetch before research`,
);
const postResearch = job.slice(researchIdx);
const denyStep = postResearch.match(
/- name: Deny WebSearch and WebFetch after[\s\S]*?(?=\n\s{6}- name:)/,
)?.[0] || '';
assert.match(denyStep, /"WebSearch\(\*\)"/, `${label} post-research deny missing WebSearch`);
assert.match(denyStep, /"WebFetch\(\*\)"/, `${label} post-research deny missing WebFetch`);
const denyIdx = postResearch.indexOf('- name: Deny WebSearch and WebFetch after');
const agentIdx = postResearch.search(
/- name: (Classify with Cursor CLI|Review follow-up with Cursor CLI)/,
);
assert.ok(denyIdx >= 0 && agentIdx > denyIdx, `${label} deny must precede agent`);
}
// Jobs without a research pass still deny web tools in their sandbox step.
const implementJob = workflow.match(
/\n implement:\n[\s\S]*?(?=\n [a-zA-Z0-9_]+:\n)/,
)?.[0] || '';
assert.match(implementJob, /Require the Cursor command sandbox for implementation[\s\S]*?"WebSearch\(\*\)"/);
assert.doesNotMatch(implementJob, /Research external context/);
});
test('initial issue failures still label and notify without a trigger comment id', () => {
const workflow = fs.readFileSync(
path.join(__dirname, '..', '.github', 'workflows', 'cursor-automation.yml'),