From d9f44a2db4ce80b2280f87c988d67e6dec9f155b Mon Sep 17 00:00:00 2001 From: LSantha Date: Fri, 20 Nov 2026 19:42:14 +0000 Subject: [PATCH 1/2] Done. Assisted-by: opencode/beam-free --- .github/scripts/opencode-trigger.js | 22 +++- .github/scripts/tests/triage-trigger.test.js | 102 +++++++++++++++++++ .github/scripts/triage-trigger.js | 27 +++++ .github/workflows/triage.yml | 2 + 4 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 .github/scripts/tests/triage-trigger.test.js create mode 100644 .github/scripts/triage-trigger.js diff --git a/.github/scripts/opencode-trigger.js b/.github/scripts/opencode-trigger.js index ecefa3b033..e796054ea4 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 0000000000..9642c22e44 --- /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 0000000000..be820f3d37 --- /dev/null +++ b/.github/scripts/triage-trigger.js @@ -0,0 +1,27 @@ +'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. Session-link and author gates stay in the +// workflow (unconditional); this predicate only inspects the body. + +const oc = require("./opencode-trigger.js"); + +function startsWith(body, prefix) { + return (body || "").indexOf(prefix) === 0; +} + +function isAnchoredTriage(body) { + return startsWith(body || "", "/oc triage"); +} + +module.exports = { + isTriageTrigger: oc.isTriageTrigger, + isAnchoredNonTriage: oc.isAnchoredNonTriage, + isAnchoredTriage: isAnchoredTriage, + isAnchoredNonExcluded: oc.isAnchoredNonExcluded, + isAnchoredExcluded: oc.isAnchoredNonTriage, + isOpencodeTrigger: oc.isOpencodeTrigger +}; diff --git a/.github/workflows/triage.yml b/.github/workflows/triage.yml index 2fa182f072..4ab6115ccc 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' || From 417ad1254c5e12b247f839344fc56287f97e0c55 Mon Sep 17 00:00:00 2001 From: LSantha Date: Sat, 21 Nov 2026 06:44:38 +0000 Subject: [PATCH 2/2] triage: exempt anchored non-triage commands from the Triage gate Assisted-by: opencode/beam-free --- .github/scripts/triage-trigger.js | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/.github/scripts/triage-trigger.js b/.github/scripts/triage-trigger.js index be820f3d37..213f9b5782 100644 --- a/.github/scripts/triage-trigger.js +++ b/.github/scripts/triage-trigger.js @@ -4,24 +4,14 @@ // 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. Session-link and author gates stay in the -// workflow (unconditional); this predicate only inspects the body. +// "/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"); -function startsWith(body, prefix) { - return (body || "").indexOf(prefix) === 0; -} - -function isAnchoredTriage(body) { - return startsWith(body || "", "/oc triage"); -} - module.exports = { isTriageTrigger: oc.isTriageTrigger, - isAnchoredNonTriage: oc.isAnchoredNonTriage, - isAnchoredTriage: isAnchoredTriage, - isAnchoredNonExcluded: oc.isAnchoredNonExcluded, - isAnchoredExcluded: oc.isAnchoredNonTriage, - isOpencodeTrigger: oc.isOpencodeTrigger + isAnchoredNonTriage: oc.isAnchoredNonTriage };