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
40 changes: 39 additions & 1 deletion scripts/sync-vsm-oss-metrics.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const pagePath = fs.existsSync(templatePath) ? templatePath : path.join(root, 'v
const START = '<!-- VSM OSS METRICS:START -->';
const END = '<!-- VSM OSS METRICS:END -->';
const INDEX_METRICS_END = '<!-- VSM INDEX METRICS:END -->';
const PUBLIC_START = '<!-- VERIFIED UPSTREAM:START -->';
const PUBLIC_END = '<!-- VERIFIED UPSTREAM:END -->';
const stylesheetVersion = 'vsm-index-metrics.css?v=20260922-vsm-oss';

function argValue(name) {
Expand Down Expand Up @@ -197,14 +199,50 @@ if (updated.includes(START) || updated.includes(END)) {
updated = updated.replace(INDEX_METRICS_END, `${INDEX_METRICS_END}\n${section}`);
}


// The source-only HTML template is omitted from Pages. Add just a bounded
// source-linked summary to the served page without violating its 18 KB budget.
const servedPage = path.join(root, 'vsm-index.html');
const servedOriginal = pagePath === servedPage ? updated : requiredFile(servedPage);
const outcome = snapshot.repositories['opensiro/upstream'] &&
snapshot.repositories['opensiro/upstream'].metrics.verified_external_outcomes;
const compactEvidence = outcomeEvidence ? (
'<p id="upstream-verified">Verified merged changes: <strong>'
+ escapeHtml(String(outcome.value)) + '</strong> (not measured benefit). '
+ outcome.accepted.slice(0, 2).map((record) => {
const parts = record.external_pr_url.split('/');
return '<a href="' + escapeHtml(record.external_pr_url) + '">'
+ escapeHtml(parts[4] + ' #' + parts[6]) + '</a>';
}).join(' · ')
+ ' · <a href="upstream-portfolio.html">All PRs</a></p>'
) : '<p id="upstream-verified">Verified merges: evidence-gated. '
+ '<a href="upstream-portfolio.html">Other PR states</a></p>';
const publicSection = PUBLIC_START + '\n' + compactEvidence + '\n' + PUBLIC_END;
let servedUpdated;
if (servedOriginal.includes(PUBLIC_START) || servedOriginal.includes(PUBLIC_END)) {
if (servedOriginal.split(PUBLIC_START).length !== 2
|| servedOriginal.split(PUBLIC_END).length !== 2
|| servedOriginal.indexOf(PUBLIC_START) > servedOriginal.indexOf(PUBLIC_END)) {
throw new Error('Missing or duplicate public Upstream markers');
}
servedUpdated = servedOriginal.replace(
new RegExp(PUBLIC_START + '[\\s\\S]*?' + PUBLIC_END), publicSection);
} else {
if (servedOriginal.split('</main>').length !== 2
|| !servedOriginal.includes('<main id="main-content"')) {
throw new Error('Missing unique publicly served Index insertion point');
}
servedUpdated = servedOriginal.replace('</main>', publicSection + '\n</main>');
}
if (checkOnly) {
if (updated !== original) {
if (updated !== original || servedUpdated !== servedOriginal) {
console.error(`VSM OSS metrics are stale against ${sourcePath}. Run node scripts/sync-vsm-oss-metrics.cjs --source ${sourcePath}`);
process.exitCode = 1;
} else {
console.log(`VSM OSS metrics are current for ${snapshot.scope.length} repository surfaces.`);
}
} else {
if (updated !== original) fs.writeFileSync(pagePath, updated);
if (servedUpdated !== servedOriginal) fs.writeFileSync(servedPage, servedUpdated);
console.log(`Synced VSM OSS metrics for ${snapshot.scope.length} repository surfaces.`);
}
8 changes: 5 additions & 3 deletions tests/vsm-oss-metrics-sync.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ test('VSM Index renders organization-owned VSM OSS activity without calculating
const script = path.join(dir, 'scripts', 'sync-vsm-oss-metrics.cjs');
const source = path.join(dir, 'vsm-oss-metrics.json');
put(script, fs.readFileSync(path.join(root, 'scripts', 'sync-vsm-oss-metrics.cjs'), 'utf8'));
put(path.join(dir, 'vsm-index.html'), '<!doctype html><html><head></head><body><main><!-- VSM INDEX METRICS:START --><section>index</section><!-- VSM INDEX METRICS:END --><section class="vhi-combos">table</section></main></body></html>');
put(path.join(dir, 'vsm-index.html'), '<!doctype html><html><head></head><body><main id="main-content"><!-- VSM INDEX METRICS:START --><section>index</section><!-- VSM INDEX METRICS:END --><section class="vhi-combos">table</section></main></body></html>');

const scope = [
'opensiro/vsm-harness-profile',
Expand Down Expand Up @@ -112,6 +112,8 @@ test('VSM Index renders organization-owned VSM OSS activity without calculating
assert.match(page, /href="https:\/\/github.com\/chankov\/agent-fleet\/pull\/43"/);
assert.match(page, /href="https:\/\/github.com\/SethGammon\/Citadel\/pull\/366"/);
assert.match(page, /2 source-verified merged changes/);
assert.match(page, /id="upstream-verified"/);
assert.match(page, /All PRs/);
assert.match(page, /not deployment or measured user benefit/);
assert.match(page, /blob\/main\/docs\/METRICS.md/);
assert.match(page, /Engineering activity <span>non-KPI<\/span>/);
Expand All @@ -129,7 +131,7 @@ test('renderer rejects snapshots that promote engineering activity to KPI', () =
const script = path.join(dir, 'scripts', 'sync-vsm-oss-metrics.cjs');
const source = path.join(dir, 'snapshot.json');
put(script, fs.readFileSync(path.join(root, 'scripts', 'sync-vsm-oss-metrics.cjs'), 'utf8'));
put(path.join(dir, 'vsm-index.html'), '<html><body><!-- VSM INDEX METRICS:END --></body></html>');
put(path.join(dir, 'vsm-index.html'), '<html><body><main id="main-content"><!-- VSM INDEX METRICS:END --></main></body></html>');
put(source, JSON.stringify({ scope: ['opensiro/x'], repositories: {}, publication: { window_change_semantics: 'net canonical state change, not gross event count', engineering_activity_is_productivity_kpi: true } }));
try {
const run = spawnSync(process.execPath, [script, '--source', source], { cwd: dir, encoding: 'utf8' });
Expand All @@ -145,7 +147,7 @@ test('rendered merged-change evidence rejects benefit inflation or mutable recei
const script = path.join(dir, 'scripts', 'sync-vsm-oss-metrics.cjs');
const source = path.join(dir, 'snapshot.json');
put(script, fs.readFileSync(path.join(root, 'scripts', 'sync-vsm-oss-metrics.cjs'), 'utf8'));
put(path.join(dir, 'vsm-index.html'), '<html><body><!-- VSM INDEX METRICS:END --></body></html>');
put(path.join(dir, 'vsm-index.html'), '<html><body><main id="main-content"><!-- VSM INDEX METRICS:END --></main></body></html>');
const row = repo('verified_external_outcomes', 1, {
'24h': { status: 'source_unavailable_at_baseline', value: null },
'7d': { status: 'source_unavailable_at_baseline', value: null },
Expand Down
Loading