diff --git a/.github/scripts/opencode-trigger.js b/.github/scripts/opencode-trigger.js index ecefa3b03..e796054ea 100644 --- a/.github/scripts/opencode-trigger.js +++ b/.github/scripts/opencode-trigger.js @@ -34,6 +34,24 @@ function isAnchoredNonExcluded(body) { ); } +// An anchored trigger whose own (first) verb is NOT triage. Such a comment has +// already decided its verb, so a later quoted " /oc triage" in prose must not +// start a Triage run (issue #866, mirrors #862's anchored exemption). +function isAnchoredNonTriage(body) { + var text = body || ""; + return startsWith(text, "/oc ") && !startsWith(text, "/oc triage"); +} + +function isTriageTrigger(body) { + var text = body || ""; + var hasTriageTrigger = + startsWith(text, "/oc triage") || contains(text, " /oc triage"); + if (!hasTriageTrigger) return false; + if (contains(text, "opencode.ai/s/")) return false; + if (isAnchoredNonTriage(text)) return false; + return true; +} + function isOpencodeTrigger(body) { var text = body || ""; var hasTrigger = contains(text, " /oc ") || startsWith(text, "/oc "); @@ -47,5 +65,7 @@ function isOpencodeTrigger(body) { module.exports = { isOpencodeTrigger: isOpencodeTrigger, - isAnchoredNonExcluded: isAnchoredNonExcluded + isAnchoredNonExcluded: isAnchoredNonExcluded, + isAnchoredNonTriage: isAnchoredNonTriage, + isTriageTrigger: isTriageTrigger }; diff --git a/.github/scripts/tests/triage-trigger.test.js b/.github/scripts/tests/triage-trigger.test.js new file mode 100644 index 000000000..9642c22e4 --- /dev/null +++ b/.github/scripts/tests/triage-trigger.test.js @@ -0,0 +1,102 @@ +const test = require("node:test"); +const assert = require("node:assert"); +const fs = require("node:fs"); +const path = require("node:path"); + +const { isTriageTrigger, isAnchoredNonTriage } = require("../triage-trigger.js"); + +test("an anchored /oc review quoting /oc triage does not start Triage (#866)", () => { + const body = + "/oc review\n\nSecond opinion please. The /oc triage run is separate from this review."; + assert.strictEqual(isTriageTrigger(body), false); +}); + +test("an anchored non-triage verb quoting /oc triage never starts Triage", () => { + for (const body of [ + "/oc fix Address the feedback; /oc triage was requested earlier.", + "/oc investigate why /oc triage behaves this way", + "/oc wiki Document the /oc triage flow.", + "/oc chore Sweep /oc triage references.", + "/oc test Cover the /oc triage path.", + "/oc Please proceed with this task. The /oc triage run is separate.", + "/oc frobnicate A new verb quoting /oc triage in prose.", + "/oc review The /oc triage run is separate from this review." + ]) { + assert.strictEqual(isTriageTrigger(body), false, body.slice(0, 40)); + } +}); + +test("a genuine /oc triage still starts Triage", () => { + for (const body of [ + "/oc triage", + "/oc triage issue #862", + "/oc triage\n\nAnalyzing.", + "/oc triageXYZ" + ]) { + assert.strictEqual(isTriageTrigger(body), true, body.slice(0, 40)); + } +}); + +test("an embedded triage still starts Triage", () => { + assert.strictEqual(isTriageTrigger("Please run /oc triage on this issue."), true); +}); + +test("an embedded non-triage trigger does not start Triage", () => { + assert.strictEqual(isTriageTrigger("Please run /oc fix on this."), false); +}); + +test("no trigger, a session link, or an empty body does not run", () => { + assert.strictEqual(isTriageTrigger("Just a comment."), false); + assert.strictEqual(isTriageTrigger("/oc triage done (https://opencode.ai/s/abc)"), false); + assert.strictEqual(isTriageTrigger(""), false); + assert.strictEqual(isTriageTrigger(undefined), false); +}); + +test("isAnchoredNonTriage tracks the anchored exemption", () => { + assert.strictEqual(isAnchoredNonTriage("/oc review anything"), true); + assert.strictEqual(isAnchoredNonTriage("/oc triage issue #1"), false); + assert.strictEqual(isAnchoredNonTriage("please /oc review"), false); +}); + +test("both workflows agree on the same body", () => { + const { isOpencodeTrigger } = require("../opencode-trigger.js"); + const bodies = [ + "/oc review\n\nquoting /oc triage in prose", + "/oc triage issue #1", + "Please run /oc triage on this issue.", + "Please run /oc fix on this.", + "/oc fix Address /oc triage references.", + "Just a comment." + ]; + for (const b of bodies) { + const oc = isOpencodeTrigger(b); + const tr = isTriageTrigger(b); + // never both true + assert.ok(!(oc && tr), "both true: " + b.slice(0, 40)); + } +}); + +test("triage.yml carries the anchored exemption the helper mirrors", () => { + const workflow = fs.readFileSync( + path.join(__dirname, "..", "..", "workflows", "triage.yml"), + "utf8" + ); + const exemption = + "startsWith(github.event.comment.body, '/oc ') &&\n" + + " !startsWith(github.event.comment.body, '/oc triage')"; + assert.ok( + workflow.includes(exemption), + "triage.yml job if must exempt an anchored non-triage trigger" + ); + assert.ok( + workflow.includes("contains(github.event.comment.body, ' /oc triage')"), + "triage.yml must keep the contains half for embedded triage commands" + ); +}); + +test("opencode-trigger re-exports triage predicate consistently", () => { + const oc = require("../opencode-trigger.js"); + assert.strictEqual(typeof oc.isTriageTrigger, "function"); + assert.strictEqual(oc.isTriageTrigger("/oc triage x"), true); + assert.strictEqual(oc.isTriageTrigger("/oc review quoting /oc triage"), false); +}); diff --git a/.github/scripts/triage-trigger.js b/.github/scripts/triage-trigger.js new file mode 100644 index 000000000..213f9b578 --- /dev/null +++ b/.github/scripts/triage-trigger.js @@ -0,0 +1,17 @@ +'use strict'; + +// Testable mirror of the job-level `if:` gate in workflows/triage.yml. +// Mirrors .github/scripts/opencode-trigger.js so the two workflows cannot +// disagree about the same body: an anchored non-triage command that merely +// quotes " /oc triage" in prose never starts Triage, while a genuine +// "/oc triage ..." still does. An embedded " /oc triage" still starts +// Triage, and an anchored "/oc approve" runs nothing. Session-link and +// author gates stay in the workflow (unconditional); this predicate only +// inspects the body. + +const oc = require("./opencode-trigger.js"); + +module.exports = { + isTriageTrigger: oc.isTriageTrigger, + isAnchoredNonTriage: oc.isAnchoredNonTriage +}; diff --git a/.github/workflows/triage.yml b/.github/workflows/triage.yml index 2fa182f07..4ab6115cc 100644 --- a/.github/workflows/triage.yml +++ b/.github/workflows/triage.yml @@ -16,6 +16,8 @@ jobs: (!github.event.issue.pull_request) && (startsWith(github.event.comment.body, '/oc triage') || contains(github.event.comment.body, ' /oc triage')) && + !(startsWith(github.event.comment.body, '/oc ') && + !startsWith(github.event.comment.body, '/oc triage')) && !contains(github.event.comment.body, 'opencode.ai/s/') && (github.event.comment.author_association == 'COLLABORATOR' || github.event.comment.author_association == 'MEMBER' ||