Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/added-18915-build-contains-ui.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- The hub hive list and each hive's version menu can now answer "does this build contain PR #N" ([#18915](https://github.com/hivecommons/hive/issues/18915)): type a PR number or commit SHA to see yes, no or unknown per hive, with the reason for every unknown and each hive's behind-by count. The version menu also shows the newest image commit and the newest merged commit as separate rows, so "merged, not yet built" is visible.
1 change: 1 addition & 0 deletions src/pkg/dashboard/sidebar_version_panel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ const window = {};
jsFunc(t, html, "versionStatusSummary") + "\n" +
jsFunc(t, html, "versionButtonHTML") + "\n" +
jsFunc(t, html, "renderVersionUpgradeAction") + "\n" +
jsFunc(t, html, "versionBuildBlockHTML") + "\n" +
jsFunc(t, html, "renderVersionDetails") + `
const out = renderVersionDetails({hash:'07d99d8426ec7b5ae364e25abcdef0123456789', short:'07d99d8', branch:'v5', channel:'candidate', tracking:'floating', latestHash:'07d99d8426ec7b5ae364e25abcdef0123456789', target:{sha:'07d99d8426ec7b5ae364e25abcdef0123456789', short:'07d99d8', managedBy:'hub'}, autoUpdate:{state:'up_to_date', managedBy:'hub', enabled:true, detail:'ok'}, releaseStatus:{attempt:{state:'succeeded', completedAt:'2026-10-02T10:00:00Z'}}}, {deliveryLabel:'candidate (v5)', offeredUpgradeHash:'07d99d8426ec7b5ae364e25abcdef0123456789', offeredUpgradeShort:'07d99d8'});
if (!out.includes('>07d99d8<')) throw new Error('short sha missing: '+out);
Expand Down
8 changes: 8 additions & 0 deletions src/pkg/dashboard/static-src/css/topbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@
.oc-version-row strong { min-width: 0; text-align: right; overflow-wrap: anywhere; }
.oc-version-row strong, .oc-version-row a { color: var(--text); }
.oc-version-row strong a { display: block; min-width: 0; overflow-wrap: anywhere; }
.oc-version-contains { display: grid; gap: var(--sp-2); padding: var(--sp-2) var(--sp-5); min-width: 0; }
.oc-version-contains-form { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.oc-version-contains-form input { flex: 1; min-width: 0; padding: var(--sp-2) var(--sp-3); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); color: var(--text); font-size: var(--fs-sm); font-family: inherit; }
.oc-version-contains-result { color: var(--muted); font-size: var(--fs-sm); overflow-wrap: anywhere; }
.oc-version-contains-chip { display: inline-block; padding: var(--sp-0) var(--sp-3); border-radius: var(--r-pill); border: 1px solid var(--border); font-size: var(--fs-xs); }
.oc-version-contains-chip.is-yes { color: var(--status-ok); border-color: var(--status-ok); }
.oc-version-contains-chip.is-no { color: var(--danger); border-color: var(--danger); }
.oc-version-contains-chip.is-unknown { color: var(--status-warn); border-color: var(--status-warn); }
.oc-version-actions { display: flex; flex-direction: column; gap: var(--sp-2); padding: var(--sp-3) var(--sp-5); min-width: 0; }
.oc-version-menu #spoke-upgrade-btn.oc-version-upgrade-available { border-color: var(--accent); box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 45%, transparent); }
.oc-version-menu #spoke-upgrade-btn.oc-version-upgrade-available::before { content: '●'; color: var(--amber); font-size: 0.7em; line-height: 1; }
Expand Down
70 changes: 70 additions & 0 deletions src/pkg/dashboard/static-src/js/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,75 @@
return versionButtonHTML('Upgrade to ' + targetShort, 'Upgrade this Hive' + runtimeDeploymentSuffix + ' to ' + (ctx.offeredUpgradeLabel || 'target') + ' ' + targetShort + ' now', target.ref || targetHash, true);
}

/* "Does this build contain PR #N?" (#18915). The lookup is answered by
GET /api/version/contains from git ancestry of the running commit: yes,
no, or unknown. Unknown is never a guess (commit not resolvable, PR not
found, lookup failed, or no GitHub access) and the reason says which.
The query and last answer live in window._versionContains so the menu,
which re-renders on every version poll, does not lose them. */
function versionContainsResultHTML(r) {
if (!r) return '';
if (r.error) return '<span class="text-muted">' + escapeHtml(String(r.error)) + '</span>';
const verdict = r.contains === 'yes' || r.contains === 'no' ? r.contains : 'unknown';
const q = r.query || {};
const what = q.kind === 'pr' ? 'PR #' + q.pr : 'commit ' + String(q.commit || '').slice(0, 7);
const tested = r.commit ? ' (' + String(r.commit).slice(0, 7) + ')' : '';
return '<span class="oc-version-contains-chip is-' + verdict + '">' + verdict + '</span> ' +
escapeHtml(what + tested) + (r.reason ? ': ' + escapeHtml(String(r.reason)) : '');
}

/* The newest image commit and the newest merged commit are shown
separately: a channel image can sit on an older commit than the newest
merge (merged, not yet built), and one number would hide that. */
function versionBuildBlockHTML(v) {
const newestImage = String((v && v.target && v.target.short) || (v && v.stableV4Short) || '');
const newestMerged = String((v && v.latestShort) || '');
const cell = function(label, text, title) {
return '<div class="oc-version-row" title="' + escapeHtml(title) + '"><span>' + escapeHtml(label) + '</span><strong>' + escapeHtml(text) + '</strong></div>';
};
let html = '';
if (newestImage) html += cell('Newest image', newestImage, 'The newest commit whose image is published for the channel this hive follows');
if (newestMerged) {
const unbuilt = newestImage && !versionSameCommit(newestImage, newestMerged);
html += cell('Newest merged', newestMerged + (unbuilt ? ' (not in the newest image)' : ''), 'The newest commit merged on this hive\'s branch');
}
const st = window._versionContains || {};
html += '<div class="oc-version-contains">' +
'<div class="oc-version-contains-form">' +
'<input type="text" id="oc-version-contains-q" placeholder="Contains PR # or commit SHA?" autocomplete="off" aria-label="Does this build contain a PR number or commit SHA" value="' + escapeHtml(st.q || '') + '" data-input-action="versionContainsDraft" data-arg-types="w" data-keydown-action="runVersionContains" data-keys="Enter">' +
'<button type="button" class="hv-btn btn-secondary btn-sm" data-action="runVersionContains">Check</button>' +
'</div>' +
'<div id="oc-version-contains-result" class="oc-version-contains-result" role="status" aria-live="polite">' + (st.html || '') + '</div>' +
'</div>';
return html;
}

function versionContainsDraft(value) {
window._versionContains = Object.assign({}, window._versionContains, { q: String(value || '') });
}

async function runVersionContains() {
const input = document.getElementById('oc-version-contains-q');
const out = document.getElementById('oc-version-contains-result');
const q = String((input && input.value) || (window._versionContains && window._versionContains.q) || '').trim();
if (!out || !q) return;
const seq = (window._versionContainsSeq = (window._versionContainsSeq || 0) + 1);
window._versionContains = { q: q, html: 'Checking…' };
out.textContent = 'Checking…';
let html;
try {
const res = await fetch('/api/version/contains?q=' + encodeURIComponent(q));
const body = await res.json();
html = versionContainsResultHTML(res.ok ? body : { error: body && body.error || 'Lookup failed; try again.' });
} catch (_) {
html = versionContainsResultHTML({ error: 'Lookup failed; try again.' });
}
if (seq !== window._versionContainsSeq) return;
window._versionContains = { q: q, html: html };
const live = document.getElementById('oc-version-contains-result');
if (live) live.innerHTML = html;
}

function renderVersionDetails(v, ctx) {
ctx = ctx || {};
const fullHash = String(v && v.hash || 'unknown');
Expand Down Expand Up @@ -871,6 +940,7 @@
if (lastUpgrade) html += row('History', value(lastUpgrade.text, lastUpgrade.title || lastUpgrade.text), lastUpgrade.title || lastUpgrade.text);
const historyHTML = versionUpgradeHistoryHTML(v);
if (historyHTML) html += '<div class="oc-version-row" title="Recent scheduled and manual upgrade attempts, as recorded by the hub"><span>Upgrade history</span></div>' + historyHTML;
html += versionBuildBlockHTML(v);
if (compareURL && (v && (v.behind || (v.commitsBehind != null && v.commitsBehind > 0)))) {
html += '<a class="avatar-menu-item" href="' + escapeHtml(compareURL) + '" target="_blank" rel="noopener noreferrer">Compare with target ↗</a>';
}
Expand Down
78 changes: 78 additions & 0 deletions src/pkg/dashboard/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,14 @@
.oc-version-row strong { min-width: 0; text-align: right; overflow-wrap: anywhere; }
.oc-version-row strong, .oc-version-row a { color: var(--text); }
.oc-version-row strong a { display: block; min-width: 0; overflow-wrap: anywhere; }
.oc-version-contains { display: grid; gap: var(--sp-2); padding: var(--sp-2) var(--sp-5); min-width: 0; }
.oc-version-contains-form { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.oc-version-contains-form input { flex: 1; min-width: 0; padding: var(--sp-2) var(--sp-3); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); color: var(--text); font-size: var(--fs-sm); font-family: inherit; }
.oc-version-contains-result { color: var(--muted); font-size: var(--fs-sm); overflow-wrap: anywhere; }
.oc-version-contains-chip { display: inline-block; padding: var(--sp-0) var(--sp-3); border-radius: var(--r-pill); border: 1px solid var(--border); font-size: var(--fs-xs); }
.oc-version-contains-chip.is-yes { color: var(--status-ok); border-color: var(--status-ok); }
.oc-version-contains-chip.is-no { color: var(--danger); border-color: var(--danger); }
.oc-version-contains-chip.is-unknown { color: var(--status-warn); border-color: var(--status-warn); }
.oc-version-actions { display: flex; flex-direction: column; gap: var(--sp-2); padding: var(--sp-3) var(--sp-5); min-width: 0; }
.oc-version-menu #spoke-upgrade-btn.oc-version-upgrade-available { border-color: var(--accent); box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 45%, transparent); }
.oc-version-menu #spoke-upgrade-btn.oc-version-upgrade-available::before { content: '●'; color: var(--amber); font-size: 0.7em; line-height: 1; }
Expand Down Expand Up @@ -62801,6 +62809,75 @@ <h3 style="color:var(--amber);text-align:center">Configure LiteLLM</h3>
return versionButtonHTML('Upgrade to ' + targetShort, 'Upgrade this Hive' + runtimeDeploymentSuffix + ' to ' + (ctx.offeredUpgradeLabel || 'target') + ' ' + targetShort + ' now', target.ref || targetHash, true);
}

/* "Does this build contain PR #N?" (#18915). The lookup is answered by
GET /api/version/contains from git ancestry of the running commit: yes,
no, or unknown. Unknown is never a guess (commit not resolvable, PR not
found, lookup failed, or no GitHub access) and the reason says which.
The query and last answer live in window._versionContains so the menu,
which re-renders on every version poll, does not lose them. */
function versionContainsResultHTML(r) {
if (!r) return '';
if (r.error) return '<span class="text-muted">' + escapeHtml(String(r.error)) + '</span>';
const verdict = r.contains === 'yes' || r.contains === 'no' ? r.contains : 'unknown';
const q = r.query || {};
const what = q.kind === 'pr' ? 'PR #' + q.pr : 'commit ' + String(q.commit || '').slice(0, 7);
const tested = r.commit ? ' (' + String(r.commit).slice(0, 7) + ')' : '';
return '<span class="oc-version-contains-chip is-' + verdict + '">' + verdict + '</span> ' +
escapeHtml(what + tested) + (r.reason ? ': ' + escapeHtml(String(r.reason)) : '');
}

/* The newest image commit and the newest merged commit are shown
separately: a channel image can sit on an older commit than the newest
merge (merged, not yet built), and one number would hide that. */
function versionBuildBlockHTML(v) {
const newestImage = String((v && v.target && v.target.short) || (v && v.stableV4Short) || '');
const newestMerged = String((v && v.latestShort) || '');
const cell = function(label, text, title) {
return '<div class="oc-version-row" title="' + escapeHtml(title) + '"><span>' + escapeHtml(label) + '</span><strong>' + escapeHtml(text) + '</strong></div>';
};
let html = '';
if (newestImage) html += cell('Newest image', newestImage, 'The newest commit whose image is published for the channel this hive follows');
if (newestMerged) {
const unbuilt = newestImage && !versionSameCommit(newestImage, newestMerged);
html += cell('Newest merged', newestMerged + (unbuilt ? ' (not in the newest image)' : ''), 'The newest commit merged on this hive\'s branch');
}
const st = window._versionContains || {};
html += '<div class="oc-version-contains">' +
'<div class="oc-version-contains-form">' +
'<input type="text" id="oc-version-contains-q" placeholder="Contains PR # or commit SHA?" autocomplete="off" aria-label="Does this build contain a PR number or commit SHA" value="' + escapeHtml(st.q || '') + '" data-input-action="versionContainsDraft" data-arg-types="w" data-keydown-action="runVersionContains" data-keys="Enter">' +
'<button type="button" class="hv-btn btn-secondary btn-sm" data-action="runVersionContains">Check</button>' +
'</div>' +
'<div id="oc-version-contains-result" class="oc-version-contains-result" role="status" aria-live="polite">' + (st.html || '') + '</div>' +
'</div>';
return html;
}

function versionContainsDraft(value) {
window._versionContains = Object.assign({}, window._versionContains, { q: String(value || '') });
}

async function runVersionContains() {
const input = document.getElementById('oc-version-contains-q');
const out = document.getElementById('oc-version-contains-result');
const q = String((input && input.value) || (window._versionContains && window._versionContains.q) || '').trim();
if (!out || !q) return;
const seq = (window._versionContainsSeq = (window._versionContainsSeq || 0) + 1);
window._versionContains = { q: q, html: 'Checking…' };
out.textContent = 'Checking…';
let html;
try {
const res = await fetch('/api/version/contains?q=' + encodeURIComponent(q));
const body = await res.json();
html = versionContainsResultHTML(res.ok ? body : { error: body && body.error || 'Lookup failed; try again.' });
} catch (_) {
html = versionContainsResultHTML({ error: 'Lookup failed; try again.' });
}
if (seq !== window._versionContainsSeq) return;
window._versionContains = { q: q, html: html };
const live = document.getElementById('oc-version-contains-result');
if (live) live.innerHTML = html;
}

function renderVersionDetails(v, ctx) {
ctx = ctx || {};
const fullHash = String(v && v.hash || 'unknown');
Expand Down Expand Up @@ -62853,6 +62930,7 @@ <h3 style="color:var(--amber);text-align:center">Configure LiteLLM</h3>
if (lastUpgrade) html += row('History', value(lastUpgrade.text, lastUpgrade.title || lastUpgrade.text), lastUpgrade.title || lastUpgrade.text);
const historyHTML = versionUpgradeHistoryHTML(v);
if (historyHTML) html += '<div class="oc-version-row" title="Recent scheduled and manual upgrade attempts, as recorded by the hub"><span>Upgrade history</span></div>' + historyHTML;
html += versionBuildBlockHTML(v);
if (compareURL && (v && (v.behind || (v.commitsBehind != null && v.commitsBehind > 0)))) {
html += '<a class="avatar-menu-item" href="' + escapeHtml(compareURL) + '" target="_blank" rel="noopener noreferrer">Compare with target ↗</a>';
}
Expand Down
63 changes: 63 additions & 0 deletions src/pkg/dashboard/version_contains_ui_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package dashboard

import (
"os/exec"
"strings"
"testing"
)

// The version menu's "Does this build contain PR #N?" block (#18915) is
// rendered by functions inside the generated index.html. This runs the shipped
// functions in node. The slice needs stubs: escapeHtml and versionSameCommit
// are real; window stands in for the browser global the block keeps its state in.
func TestVersionContainsUIRenders(t *testing.T) {
node, err := exec.LookPath("node")
if err != nil {
t.Skip("node unavailable: version contains rendering was not executed")
}
html := indexHTML(t)
var source strings.Builder
source.WriteString("const window = {};\n")
for _, name := range []string{"escapeHtml", "versionShortSHA", "versionSameCommit", "versionContainsResultHTML", "versionBuildBlockHTML", "versionContainsDraft"} {
source.WriteString(jsFunc(t, html, name))
source.WriteByte('\n')
}
source.WriteString(`
const assert = (cond, msg) => { if (!cond) throw new Error(msg); };

const yes = versionContainsResultHTML({contains: 'yes', query: {kind: 'pr', pr: 7}, commit: '1a2b3c4d5e6f'});
assert(yes.includes('is-yes') && yes.includes('PR #7') && yes.includes('1a2b3c4'), 'yes: ' + yes);

const no = versionContainsResultHTML({contains: 'no', query: {kind: 'commit', commit: 'abcdef1234'}});
assert(no.includes('is-no') && !no.includes('is-yes'), 'no: ' + no);

// Anything that is not an explicit yes or no must read as unknown, never as a confident answer.
for (const odd of [undefined, '', 'maybe', 'YES', null]) {
const out = versionContainsResultHTML({contains: odd, query: {kind: 'pr', pr: 9}, reason: 'the commit is not in the repository history'});
assert(out.includes('is-unknown') && !out.includes('is-yes') && !out.includes('is-no'), 'odd verdict ' + odd + ': ' + out);
assert(out.includes('not in the repository history'), 'reason must be shown: ' + out);
}

const failed = versionContainsResultHTML({error: 'Lookup failed; try again.'});
assert(!failed.includes('oc-version-contains-chip'), 'a failed lookup must show no verdict: ' + failed);

const escaped = versionContainsResultHTML({contains: 'unknown', query: {kind: 'pr', pr: 1}, reason: '<img src=x onerror=1>'});
assert(!escaped.includes('<img'), 'reason must be escaped: ' + escaped);

// Newest image and newest merged are separate rows; a merged commit that is
// not the image commit is called out.
const split = versionBuildBlockHTML({target: {short: '1111111'}, latestShort: '2222222'});
assert(split.includes('Newest image') && split.includes('1111111'), 'image row: ' + split);
assert(split.includes('Newest merged') && split.includes('2222222 (not in the newest image)'), 'merged row: ' + split);
const same = versionBuildBlockHTML({target: {short: '1111111'}, latestShort: '1111111'});
assert(!same.includes('not in the newest image'), 'equal commits must not be flagged: ' + same);

// The typed query survives a re-render, which happens on every version poll.
versionContainsDraft('1234');
assert(versionBuildBlockHTML({}).includes('value="1234"'), 'draft query must persist');
assert(versionBuildBlockHTML({}).includes('data-action="runVersionContains"'), 'check button must dispatch through data-action');
`)
if out, err := exec.Command(node, "-e", source.String()).CombinedOutput(); err != nil {
t.Fatalf("version contains renderer failed: %v\n%s", err, out)
}
}
Loading
Loading