From 11c561239d19a63bad7c5508a3a3f8c9a7c0e9f8 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Wed, 18 Nov 2026 21:51:21 -0500 Subject: [PATCH 1/9] fix: add JS test for the reviewer-stated rules Settings card Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- src/pkg/dashboard/review_rules_editor.test.js | 115 ++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 src/pkg/dashboard/review_rules_editor.test.js diff --git a/src/pkg/dashboard/review_rules_editor.test.js b/src/pkg/dashboard/review_rules_editor.test.js new file mode 100644 index 0000000000..92767344ee --- /dev/null +++ b/src/pkg/dashboard/review_rules_editor.test.js @@ -0,0 +1,115 @@ +// Settings -> Features -> Review: reviewer-stated rules card (hivecommons/hive#19148). +// renderReviewRulesPanel shows each review_feedback.rules.* value with where it +// comes from (saved, env var or default); Save PUTs to +// /api/config/review-feedback/rules and shows a server refusal as-is. +// Run: node --test src/pkg/dashboard/*.test.js +const test = require('node:test'); +const assert = require('node:assert'); +const fs = require('node:fs'); +const path = require('node:path'); + +const html = fs.readFileSync(path.join(__dirname, 'static', 'index.html'), 'utf8'); +const ASYNC_PREFIX = 'async '; +const fnSrc = name => { + let start = html.indexOf('function ' + name + '('); + assert.ok(start >= 0, name + ' not found'); + if (html.slice(start - ASYNC_PREFIX.length, start) === ASYNC_PREFIX) start -= ASYNC_PREFIX.length; + let depth = 0; + for (let i = html.indexOf('{', start); i < html.length; i++) { + if (html[i] === '{') depth++; + else if (html[i] === '}' && --depth === 0) return html.slice(start, i + 1); + } + throw new Error('unbalanced ' + name); +}; + +// Minimal fake DOM: elements with children, className, textContent (which +// clears children, as in the browser), attributes and listeners. +const makeDoc = () => { + const doc = {}; + const makeEl = tag => { + const el = { tag, children: [], listeners: {}, className: '', title: '', _text: '' }; + Object.defineProperty(el, 'textContent', { + get() { return el._text + el.children.map(c => c.textContent).join(''); }, + set(v) { el._text = String(v); el.children = []; }, + }); + el.appendChild = c => { el.children.push(c); return c; }; + el.addEventListener = (type, fn) => { (el.listeners[type] = el.listeners[type] || []).push(fn); }; + el.fire = (type, ev) => (el.listeners[type] || []).map(fn => fn(ev || {})); + el.find = pred => { + const out = []; + const walk = n => { if (pred(n)) out.push(n); (n.children || []).forEach(walk); }; + walk(el); + return out; + }; + return el; + }; + doc.createElement = makeEl; + doc.createTextNode = text => ({ tag: '#text', children: [], className: '', textContent: String(text) }); + doc.getElementById = () => null; + return doc; +}; + + + +const DATA = { + enabled: { saved: null, effective: true, source: 'default', default: true, env_var: 'HIVE_REVIEW_FEEDBACK_RULES' }, + trusted_associations: { saved: null, effective: ['OWNER'], source: 'env', default: ['OWNER', 'MEMBER', 'COLLABORATOR'], env_var: 'HIVE_REVIEW_FEEDBACK_RULE_TRUSTED_ASSOCIATIONS' }, + extra_phrases: { saved: null, effective: [], source: 'default', default: [], env_var: 'HIVE_REVIEW_FEEDBACK_RULE_EXTRA_PHRASES' }, + disabled_signals: { saved: null, effective: [], source: 'default', default: [], env_var: 'HIVE_REVIEW_FEEDBACK_RULE_DISABLED_SIGNALS' }, + associations: ['OWNER', 'MEMBER', 'COLLABORATOR'], + signals: [{ name: 'source_of_truth', examples: 'X is the source of truth' }], + max_phrases: 20, +}; + +const setup = put => { + const doc = makeDoc(); + const toasts = []; + const calls = []; + const fetchStub = async (url, opts) => { + calls.push({ url, opts, body: JSON.parse(opts.body) }); + return put(calls[calls.length - 1]); + }; + const render = new Function('document', 'fetch', 'showToast', '_inceptionAuthHeaders', 'saveErrorMessage', + fnSrc('reviewRulesNode') + '\n' + fnSrc('reviewRulesSourceText') + '\n' + fnSrc('renderReviewRulesPanel') + '\nreturn renderReviewRulesPanel;')( + doc, fetchStub, (m, k) => toasts.push([m, k]), () => ({}), async res => res.errorMessage); + const host = doc.createElement('div'); + render(host, DATA); + return { host, toasts, calls }; +}; + +const saveButton = host => host.find(n => n.tag === 'button' && n.textContent === 'Save reviewer-rule settings')[0]; + +test('shows the four keys and says when an env var supplies a value', () => { + const { host } = setup(() => { throw new Error('no save'); }); + for (const key of ['review_feedback.rules.enabled', 'review_feedback.rules.trusted_associations[]', 'review_feedback.rules.extra_phrases[]', 'review_feedback.rules.disabled_signals[]']) { + assert.ok(host.textContent.includes(key), key); + } + assert.ok(host.textContent.includes('now: OWNER (from HIVE_REVIEW_FEEDBACK_RULE_TRUSTED_ASSOCIATIONS)')); + assert.ok(host.textContent.includes('now: on (default)')); + assert.strictEqual(saveButton(host).disabled, true); +}); + +test('Save PUTs the changed value to the owner-only endpoint', async () => { + const { host, calls, toasts } = setup(() => ({ ok: true, json: async () => DATA })); + const sel = host.find(n => n.tag === 'select')[0]; + sel.value = 'off'; + sel.fire('change'); + assert.strictEqual(saveButton(host).disabled, false); + await saveButton(host).fire('click')[0]; + assert.strictEqual(calls.length, 1); + assert.strictEqual(calls[0].url, '/api/config/review-feedback/rules'); + assert.strictEqual(calls[0].opts.method, 'PUT'); + assert.deepStrictEqual(calls[0].body, { enabled: false }); + assert.deepStrictEqual(toasts, [['Reviewer-rule settings saved', 'success']]); +}); + +test('a refusal is shown as-is and Save stays enabled', async () => { + const { host, toasts } = setup(() => ({ ok: false, status: 400, errorMessage: 'unknown signal "x"' })); + const sel = host.find(n => n.tag === 'select')[0]; + sel.value = 'on'; + sel.fire('change'); + await saveButton(host).fire('click')[0]; + assert.deepStrictEqual(toasts, []); + assert.match(host.textContent, /unknown signal "x"/); + assert.strictEqual(saveButton(host).disabled, false); +}); From 5962256f9447f416843230b2b0391471ea01a43b Mon Sep 17 00:00:00 2001 From: "hivecommons-hive[bot]" <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Thu, 19 Nov 2026 02:52:02 +0000 Subject: [PATCH 2/9] changelog: fragment for #19207 Generated by changelog-fragment-guard from the PR title (#5675). Edit the wording freely, or replace this file with the no-changelog label if the change is not user-visible. Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Signed-off-by: hivecommons-hive[bot] <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- changelog.d/added-19207.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/added-19207.md diff --git a/changelog.d/added-19207.md b/changelog.d/added-19207.md new file mode 100644 index 0000000000..ed5ab5a0d0 --- /dev/null +++ b/changelog.d/added-19207.md @@ -0,0 +1 @@ +- settings: JS tests for the reviewer-stated rules card (#19207) From a09a1a83937852fbed9ec2d757327f0e321b4d65 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Wed, 18 Nov 2026 22:14:33 -0500 Subject: [PATCH 3/9] =?UTF-8?q?=F0=9F=A7=B9=20remove=20test-only=20changel?= =?UTF-8?q?og=20fragment=20for=20#19207?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The PR only adds JS tests with no user-visible change, so no changelog fragment is needed. Hive-Fix-Attempt: 1/6 Co-Authored-By: Claude Sonnet 5.5 Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- changelog.d/added-19207.md | 1 - 1 file changed, 1 deletion(-) delete mode 100644 changelog.d/added-19207.md diff --git a/changelog.d/added-19207.md b/changelog.d/added-19207.md deleted file mode 100644 index ed5ab5a0d0..0000000000 --- a/changelog.d/added-19207.md +++ /dev/null @@ -1 +0,0 @@ -- settings: JS tests for the reviewer-stated rules card (#19207) From 8e87a210610e54b9ff70bf77f716cc7e9a334e8b Mon Sep 17 00:00:00 2001 From: "hivecommons-hive[bot]" <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Thu, 19 Nov 2026 03:15:14 +0000 Subject: [PATCH 4/9] changelog: fragment for #19207 Generated by changelog-fragment-guard from the PR title (#5675). Edit the wording freely, or replace this file with the no-changelog label if the change is not user-visible. Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Signed-off-by: hivecommons-hive[bot] <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- changelog.d/added-19207.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/added-19207.md diff --git a/changelog.d/added-19207.md b/changelog.d/added-19207.md new file mode 100644 index 0000000000..ed5ab5a0d0 --- /dev/null +++ b/changelog.d/added-19207.md @@ -0,0 +1 @@ +- settings: JS tests for the reviewer-stated rules card (#19207) From a1c300a01dc623f6d7e17796c6862cb1e1be1cb0 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Wed, 18 Nov 2026 22:25:54 -0500 Subject: [PATCH 5/9] changelog: drop fragment for test-only change (#19207) The PR is test-only; its body states no changelog fragment is needed. Hive-Fix-Attempt: 2/6 Co-Authored-By: Claude Sonnet 5.5 Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- changelog.d/added-19207.md | 1 - 1 file changed, 1 deletion(-) delete mode 100644 changelog.d/added-19207.md diff --git a/changelog.d/added-19207.md b/changelog.d/added-19207.md deleted file mode 100644 index ed5ab5a0d0..0000000000 --- a/changelog.d/added-19207.md +++ /dev/null @@ -1 +0,0 @@ -- settings: JS tests for the reviewer-stated rules card (#19207) From 59c728e589f88815b6c2187aaeea21f0fea3334c Mon Sep 17 00:00:00 2001 From: "hivecommons-hive[bot]" <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Thu, 19 Nov 2026 03:26:31 +0000 Subject: [PATCH 6/9] changelog: fragment for #19207 Generated by changelog-fragment-guard from the PR title (#5675). Edit the wording freely, or replace this file with the no-changelog label if the change is not user-visible. Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Signed-off-by: hivecommons-hive[bot] <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- changelog.d/added-19207.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/added-19207.md diff --git a/changelog.d/added-19207.md b/changelog.d/added-19207.md new file mode 100644 index 0000000000..ed5ab5a0d0 --- /dev/null +++ b/changelog.d/added-19207.md @@ -0,0 +1 @@ +- settings: JS tests for the reviewer-stated rules card (#19207) From 1fdc9d9414f40c366048ea26ebb0af56bb6e4d4e Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Wed, 18 Nov 2026 22:41:19 -0500 Subject: [PATCH 7/9] changelog: drop fragment for test-only change (#19207) The JS test file is not covered by the guard's _test.go exemption, so the no-changelog label is applied instead; the fragment would put a test-only line into CHANGELOG.md release notes. Hive-Fix-Attempt: 3/6 Co-Authored-By: Claude Sonnet 5.5 Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- changelog.d/added-19207.md | 1 - 1 file changed, 1 deletion(-) delete mode 100644 changelog.d/added-19207.md diff --git a/changelog.d/added-19207.md b/changelog.d/added-19207.md deleted file mode 100644 index ed5ab5a0d0..0000000000 --- a/changelog.d/added-19207.md +++ /dev/null @@ -1 +0,0 @@ -- settings: JS tests for the reviewer-stated rules card (#19207) From e7a7f2f9ddeab1c8b011d6cc049f09f1eab45cea Mon Sep 17 00:00:00 2001 From: "hivecommons-hive[bot]" <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Thu, 19 Nov 2026 03:41:55 +0000 Subject: [PATCH 8/9] changelog: fragment for #19207 Generated by changelog-fragment-guard from the PR title (#5675). Edit the wording freely, or replace this file with the no-changelog label if the change is not user-visible. Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Signed-off-by: hivecommons-hive[bot] <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- changelog.d/added-19207.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/added-19207.md diff --git a/changelog.d/added-19207.md b/changelog.d/added-19207.md new file mode 100644 index 0000000000..ed5ab5a0d0 --- /dev/null +++ b/changelog.d/added-19207.md @@ -0,0 +1 @@ +- settings: JS tests for the reviewer-stated rules card (#19207) From 1198c584e2b640ae1323b211002f4f525e067990 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Wed, 18 Nov 2026 22:50:24 -0500 Subject: [PATCH 9/9] changelog: drop fragment for test-only change (#19207) PR is test-only with no user-visible change, so no changelog fragment. Hive-Fix-Attempt: 4/6 Co-Authored-By: Claude Sonnet 5.5 Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- changelog.d/added-19207.md | 1 - 1 file changed, 1 deletion(-) delete mode 100644 changelog.d/added-19207.md diff --git a/changelog.d/added-19207.md b/changelog.d/added-19207.md deleted file mode 100644 index ed5ab5a0d0..0000000000 --- a/changelog.d/added-19207.md +++ /dev/null @@ -1 +0,0 @@ -- settings: JS tests for the reviewer-stated rules card (#19207)