In this section
- Register Delta energy-data · pipelinenews / tools/intelligence/register-delta.mjs lines 1–150
- Register Quarter Test test · pipelinenews / tools/intelligence/register-quarter.test.mjs lines 1–171
- Register Source energy-data · pipelinenews / tools/intelligence/register-source.mjs lines 1–75
Register Delta
A JavaScript module in the intelligence folder of PipelineNews that normalises name (`normaliseName`) and operator (`normaliseOperator`) (units: MW), covering the Renewable Energy Planning Database (REPD) register, using SHA-256.
energy-datapipelinenews / tools/intelligence/register-delta.mjs · lines 1–150 of 150 · pattern normaliseOperator (shared by 3 files)
- What it does
- It lists and searches the REPD register. Defines 12 functions or classes, including clean, normaliseName, normaliseOperator, sameNumber, computeDelta. Uses libraries node:fs, node:url. Side effects: reads or writes files; starts processes.
- Why it exists in the grid workflow
- Domain stage upstream_foresight (repository name word 'pipelinenews'): upstream engineering foresight over GB transmission and distribution topology (TSO/DNO, 132kV and above, the REPD pipeline, data centres), which Ventus Ltd states it models for foresight. Domain terms in the code: the REPD register.
- Inputs & outputs
- In: command-line arguments.
- Downstream impact
- Used directly by 2 files: Reconcile Provisional (pipelinenews); Register Quarter Test (pipelinenews). Reached from 1 other entry point, including PipelineNews BBC RSS Discovery Workflow (pipelinenews).
- What it achieves
- It normalises name (`normaliseName`), normalises operator (`normaliseOperator`) and computes delta (`computeDelta`). Quarter-to-quarter delta of the Pipeline News project register, with a safety gate.
- Why it matters
- Imported by Reconcile Provisional. Checked by Register Quarter Test.
- Application
- pipelinenews · tools/intelligence · JavaScript module
- Uses
- Register Source (import), node:fs, node:url
- Used by
- imported by Reconcile Provisional (import), run by Register Quarter Test (script call)
- Produces
- DELTA_SCHEMA, DEFAULT_LIMITS, SIGNAL_STATUSES, normaliseName, normaliseOperator, computeDelta, operatorAliases, reviewBindings, discoveryPriority
- Defines here
- clean, normaliseName, normaliseOperator, sameNumber, computeDelta, index, byNumber, describe, operatorAliases, reviewBindings, discoveryPriority, take
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- pipelinenews@45c944c8640a9d7ae65edb51d66032ba204f3f46 tools/intelligence/register-delta.mjs:1-150 · blob 75f5f593925cb16608c6fe47938a649f6e1ccd6d · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: filesystem, process · domain stage: upstream_foresight · users: IPP_developer, ICP_grid_engineer · canonical: production_core
// Quarter-to-quarter delta of the Pipeline News project register, with a safety gate.
//
// A new REPD quarter reaches news discovery as a new release whose registry points
// at a new projects payload (see register-source.mjs). This module compares two
// decoded registers and reports what discovery must react to: new refs, removed
// refs, operator renames, site renames, status changes and capacity edits. It
// never edits either register. The gate HOLDs (does not apply) on a delta that
// looks like a broken source rather than a normal quarter.
import {writeFileSync} from 'node:fs';
import {pathToFileURL} from 'node:url';
import {resolveRegister, decodeProjects, listReleases} from './register-source.mjs';
export const DELTA_SCHEMA = 'pipelinenews.register-delta.v1';
export const DEFAULT_LIMITS = Object.freeze({
max_removed_fraction: 0.02, // Q2->Q3 2026 spine: 6 of 7,680 removed (0.08%)
max_added_fraction: 0.05, // Q2->Q3 2026 spine: 101 of 7,680 added (1.3%)
max_operator_change_fraction: 0.15, // Q2->Q3 2026 full REPD: 530 of 14,648 retained (3.6%)
min_projects: 1000,
});
// Status transitions that make a project newsworthy again.
export const SIGNAL_STATUSES = Object.freeze(new Set([
'Awaiting Construction', 'Under Construction', 'Operational',
'Application Refused', 'Appeal Refused', 'Application Withdrawn', 'Appeal Lodged', 'Abandoned',
'Planning Permission Expired', 'Decommissioned',
]));
const clean = value => String(value ?? '').replace(/\s+/g, ' ').trim();
export const normaliseName = value => clean(value).normalize('NFKC').toLowerCase().replace(/&/g, ' and ').replace(/[^a-z0-9]+/g, ' ').trim();
// Operator spelling: "/", "&", "+" and "and" are the same separator; legal suffixes ignored.
export const normaliseOperator = value => normaliseName(String(value ?? '').replace(/[\/&+;,]/g, ' and '))
.replace(/\b(and|ltd|limited|plc|llp)\b/g, ' ').replace(/\s+/g, ' ').trim();
const sameNumber = (a, b) => (a === null || a === undefined || a === '') && (b === null || b === undefined || b === '')
? true : Number(a) === Number(b);
export function computeDelta(previousProjects, nextProjects, {previous = {}, next = {}, limits = DEFAULT_LIMITS} = {}) {
const reasons = [];
const index = (rows, label) => {
const map = new Map();
for (const row of rows) {
const ref = String(row.repd_ref);
if (!/^\d+$/.test(ref)) reasons.push(`${label}: non-numeric repd_ref ${ref}`);
if (map.has(ref)) reasons.push(`${label}: duplicate repd_ref ${ref}`);
map.set(ref, row);
}
return map;
};
const before = index(previousProjects, 'previous');
const after = index(nextProjects, 'next');
const added = [], removed = [], operator = [], respelled = [], site = [], status = [], capacity = [], technology = [];
for (const [ref, row] of after) {
const old = before.get(ref);
if (!old) { added.push(ref); continue; }
if (normaliseOperator(old.operator) !== normaliseOperator(row.operator)) operator.push({repd_ref: ref, from: clean(old.operator) || null, to: clean(row.operator) || null});
else if (clean(old.operator) !== clean(row.operator)) respelled.push({repd_ref: ref, from: clean(old.operator) || null, to: clean(row.operator) || null});
if (normaliseName(old.name) !== normaliseName(row.name)) site.push({repd_ref: ref, from: clean(old.name), to: clean(row.name)});
if ((old.status ?? null) !== (row.status ?? null)) status.push({repd_ref: ref, from: old.status ?? null, to: row.status ?? null, signal: SIGNAL_STATUSES.has(row.status)});
if (!sameNumber(old.capacity_mw, row.capacity_mw)) capacity.push({repd_ref: ref, from: old.capacity_mw ?? null, to: row.capacity_mw ?? null});
if ((old.technology ?? null) !== (row.technology ?? null)) technology.push({repd_ref: ref, from: old.technology ?? null, to: row.technology ?? null});
}
for (const ref of before.keys()) if (!after.has(ref)) removed.push(ref);
const byNumber = (a, b) => Number(a) - Number(b);
added.sort(byNumber); removed.sort(byNumber);
const retained = after.size - added.length;
if (after.size < limits.min_projects) reasons.push(`next register has only ${after.size} projects`);
if (before.size && removed.length / before.size > limits.max_removed_fraction) reasons.push(`removed ${removed.length} of ${before.size} refs exceeds ${limits.max_removed_fraction}`);
if (before.size && added.length / before.size > limits.max_added_fraction) reasons.push(`added ${added.length} refs exceeds ${limits.max_added_fraction} of ${before.size}`);
if (retained && operator.length / retained > limits.max_operator_change_fraction) reasons.push(`operator changed on ${operator.length} of ${retained} retained refs`);
const unchanged = previous.sha256 && previous.sha256 === next.sha256;
return {
schema: DELTA_SCHEMA,
previous: describe(previous, before.size),
next: describe(next, after.size),
counts: {added: added.length, removed: removed.length, retained, operator_renamed: operator.length, operator_respelled: respelled.length, site_renamed: site.length,
status_changed: status.length, status_signal: status.filter(row => row.signal).length, capacity_changed: capacity.length, technology_changed: technology.length},
gate: {status: unchanged ? 'NO_CHANGE' : reasons.length ? 'HOLD' : 'PASS', reasons, limits: {...limits}},
added, removed, operator_renamed: operator, operator_respelled: respelled, site_renamed: site, status_changed: status, capacity_changed: capacity, technology_changed: technology,
};
}
function describe(meta, count) {
return {release: meta.release ?? null, path: meta.path ?? null, sha256: meta.sha256 ?? null, dataset: meta.dataset ?? null, project_count: count};
}
// Every operator name a ref has carried across the two registers (normalised -> display).
// Used so that a provisional row or an article naming the previous operator still corroborates.
export function operatorAliases(delta) {
const aliases = new Map();
for (const row of [...delta.operator_renamed, ...(delta.operator_respelled ?? [])]) {
aliases.set(row.repd_ref, [...new Set([row.from, row.to].filter(Boolean))]);
}
return aliases;
}
// Re-check existing article bindings against a new register. Bindings are never
// deleted: a removed ref is marked, a status change becomes a review signal.
export function reviewBindings(bindings, delta) {
const removed = new Set(delta.removed);
const status = new Map(delta.status_changed.map(row => [row.repd_ref, row]));
const operator = new Map(delta.operator_renamed.map(row => [row.repd_ref, row]));
const site = new Map(delta.site_renamed.map(row => [row.repd_ref, row]));
return bindings.map(binding => {
const ref = binding.repd_ref ? String(binding.repd_ref) : null;
const flags = [];
if (!ref) return {...binding, register_review: []};
if (removed.has(ref)) flags.push({flag: 'REF_REMOVED_FROM_REGISTER', action: 'HOLD_BINDING_FOR_REVIEW'});
if (status.has(ref)) flags.push({flag: 'STATUS_CHANGED', from: status.get(ref).from, to: status.get(ref).to, action: status.get(ref).signal ? 'RECHECK_FOR_NEW_COVERAGE' : 'NONE'});
if (operator.has(ref)) flags.push({flag: 'OPERATOR_RENAMED', from: operator.get(ref).from, to: operator.get(ref).to, action: 'DISPLAY_NEW_KEEP_OLD_AS_ALIAS'});
if (site.has(ref)) flags.push({flag: 'SITE_RENAMED', from: site.get(ref).from, to: site.get(ref).to, action: 'ADD_OLD_NAME_AS_ALIAS'});
return {...binding, register_review: flags};
});
}
// Discovery priority for the next collection run: new refs first, then refs whose
// status became newsworthy. Returns decoded projects; the existing bounded query
// planner (buildBoundedQueryPlan) still applies its own size and count limits.
export function discoveryPriority(delta, nextProjects) {
const byRef = new Map(nextProjects.map(row => [String(row.repd_ref), row]));
const picked = [], seen = new Set();
const take = (ref, reason) => {
if (seen.has(ref) || !byRef.has(ref)) return;
seen.add(ref); picked.push({...byRef.get(ref), discovery_reason: reason});
};
for (const ref of delta.added) take(ref, 'NEW_IN_REGISTER');
for (const row of delta.status_changed) if (row.signal) take(row.repd_ref, `STATUS_${row.from}_TO_${row.to}`);
return picked;
}
// CLI: node tools/intelligence/register-delta.mjs [--previous <release>] [--next <release>] [--out file]
// Default compares the two newest releases whose registered projects digests differ.
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
const args = new Map();
for (let i = 2; i < process.argv.length; i += 2) args.set(process.argv[i], process.argv[i + 1]);
const releases = listReleases('.');
const next = resolveRegister('.', {release: args.get('--next') ?? releases.at(-1)});
let previous = null;
if (args.get('--previous')) previous = resolveRegister('.', {release: args.get('--previous')});
else for (const release of [...releases].reverse()) {
const candidate = resolveRegister('.', {release});
if (candidate.sha256 !== next.sha256) { previous = candidate; break; }
}
if (!previous) previous = next;
const delta = computeDelta(decodeProjects(previous.payload), decodeProjects(next.payload), {previous, next});
const body = JSON.stringify(delta, null, 2) + '\n';
if (args.get('--out')) writeFileSync(args.get('--out'), body);
console.log(JSON.stringify({previous: delta.previous, next: delta.next, counts: delta.counts, gate: delta.gate}));
if (delta.gate.status === 'HOLD') process.exit(2);
}Register Quarter Test
A test in the intelligence folder of PipelineNews that checks Register Source and Register Delta, using SHA-256. It writes release (`writeRelease`) and runs cli (`runCli`).
testpipelinenews / tools/intelligence/register-quarter.test.mjs · lines 1–171 of 171 · Entry point · pattern payload (shared by 6 files)
- What it does
- It tests the REPD register. Defines 7 functions or classes, including sha, payload, code, writeRelease, fixtureRepo. Uses libraries node:test, node:assert/strict, node:fs, node:os, node:path. Side effects: reads or writes files; starts processes.
- Why it exists in the grid workflow
- Domain stage upstream_foresight (repository name word 'pipelinenews'): upstream engineering foresight over GB transmission and distribution topology (TSO/DNO, 132kV and above, the REPD pipeline, data centres), which Ventus Ltd states it models for foresight. Domain terms in the code: the REPD register.
- Inputs & outputs
- In: JSON file 202608270055-aaaa-v8-fast-projects.json; JSON file 202611132345-bbbb-repd-2026q3-fast-projects.json; JSON file 202608291447-registry.json; JSON file project-register.json. Out: JSON file 202608291447-registry.json; JSON file x.json; JSON file project-register.json.
- Downstream impact
- Used directly by 1 file: PipelineNews BBC RSS Discovery Workflow (pipelinenews).
- What it achieves
- Tests a new Renewable Energy Planning Database (REPD) quarter reaches discovery through the release registry, safely.
- Why it matters
- Run by PipelineNews BBC RSS Discovery Workflow.
- Application
- pipelinenews · tools/intelligence · test
- Uses
- Register Source (script call), Register Delta (script call), Provisional Identity (script call), Reconcile Provisional (script call), node:test, node:assert/strict, node:fs, node:os, node:path, node:child_process, node:url, node:crypto
- Used by
- run by PipelineNews BBC RSS Discovery Workflow (workflow run)
- Produces
- sha, payload, code, writeRelease, fixtureRepo, cliRepo, runCli
- Defines here
- sha, payload, code, writeRelease, fixtureRepo, cliRepo, runCli
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- pipelinenews@45c944c8640a9d7ae65edb51d66032ba204f3f46 tools/intelligence/register-quarter.test.mjs:1-171 · blob 2fe292e3a36cc13f6e44e585198228f8994c1e20 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: filesystem, process · domain stage: upstream_foresight · users: IPP_developer, ICP_grid_engineer · canonical: production_core
// Tests: a new REPD quarter reaches discovery through the release registry, safely.
// run: node --test tools/intelligence/register-quarter.test.mjs
import {test} from 'node:test';
import assert from 'node:assert/strict';
import {mkdtempSync, mkdirSync, writeFileSync, readFileSync, cpSync} from 'node:fs';
import {tmpdir} from 'node:os';
import path from 'node:path';
import {execFileSync} from 'node:child_process';
import {fileURLToPath} from 'node:url';
import {createHash} from 'node:crypto';
import {resolveRegister, decodeProjects} from './register-source.mjs';
import {computeDelta, operatorAliases, reviewBindings, discoveryPriority, DEFAULT_LIMITS} from './register-delta.mjs';
import {reconcileProvisional} from '../../cartridges/provisional-identity.mjs';
const here = path.dirname(fileURLToPath(import.meta.url));
const repoRoot = path.resolve(here, '../..');
const FIELDS = ['repd_ref', 'gg_project_id', 'name', 'technology', 'status', 'capacity_mw', 'county', 'region', 'operator', 'repd_record_updated', 'geometry_status', 'latitude', 'longitude'];
const sha = bytes => createHash('sha256').update(bytes).digest('hex');
function payload(rows) {
const dictionaries = {technology: [], status: [], county: [], region: [], operator: [], geometry_status: []};
const code = (field, value) => { const list = dictionaries[field]; let i = list.indexOf(value); if (i < 0) { list.push(value); i = list.length - 1; } return i; };
return {schema: 'pipelinenews.v8.fast-project-index.v1', generation: '000000000000', cache_identity: 'x', fields: FIELDS, dictionaries,
rows: rows.map(r => [r.repd_ref, `GG2050-REPD-${r.repd_ref}`, r.name, code('technology', r.technology ?? 'solar'), code('status', r.status ?? 'Application Submitted'),
r.capacity_mw ?? null, code('county', r.county), code('region', 'X'), code('operator', r.operator), '2026-10-01', code('geometry_status', 'valid'), 52, -1])};
}
function writeRelease(root, id, files, registered, admitted) {
const dir = path.join(root, 'releases', id, 'data');
mkdirSync(dir, {recursive: true});
for (const [name, body] of Object.entries(files)) writeFileSync(path.join(dir, name), body);
const bytes = readFileSync(path.join(dir, registered));
writeFileSync(path.join(dir, '202608291447-registry.json'), JSON.stringify({
source: {dataset: `test ${id}`, admitted_project_count: admitted},
assets: {projects: {path: `data/${registered}`, schema: 'pipelinenews.v8.fast-project-index.v1', sha256: sha(bytes)}},
}));
}
const Q2 = [
{repd_ref: '100', name: 'Alpha Solar Farm', operator: 'Old Co / Partner', county: 'Kent', capacity_mw: 49.9},
{repd_ref: '101', name: 'Beta Battery Storage', operator: 'Beta Ltd', county: 'Essex', capacity_mw: 100, technology: 'bess'},
{repd_ref: '102', name: 'Gamma Solar Park', operator: 'Gamma Energy', county: 'Devon', capacity_mw: 30},
];
const Q3 = [
{repd_ref: '100', name: 'Alpha Solar Farm', operator: 'Old Co & Partner', county: 'Kent', capacity_mw: 49.9, status: 'Awaiting Construction'},
{repd_ref: '101', name: 'Beta Battery Storage', operator: 'New Owner Plc', county: 'Essex', capacity_mw: 100, technology: 'bess'},
{repd_ref: '200', name: 'Cearn Solar Farm', operator: 'Telis Energy UK', county: 'Oxfordshire', capacity_mw: 500},
];
const FILLER = Array.from({length: 1200}, (_, i) => ({repd_ref: String(5000 + i), name: `Filler ${i} Solar Farm`, operator: 'Filler Co', county: 'Kent', capacity_mw: 5}));
function fixtureRepo({pad = false, q3Rows = Q3} = {}) {
const root = mkdtempSync(path.join(tmpdir(), 'pn-quarter-'));
const q2Rows = pad ? [...Q2, ...FILLER] : Q2;
const nextRows = pad ? [...q3Rows, ...FILLER] : q3Rows;
const q2 = JSON.stringify(payload(q2Rows)), q3 = JSON.stringify(payload(nextRows));
writeRelease(root, '202609060232-pipelinenews', {'202608270055-aaaa-v8-fast-projects.json': q2}, '202608270055-aaaa-v8-fast-projects.json', q2Rows.length);
// The new release inherits the Q2 file under its old name and registers the Q3 one.
writeRelease(root, '202611132345-pipelinenews', {'202608270055-aaaa-v8-fast-projects.json': q2, '202611132345-bbbb-repd-2026q3-fast-projects.json': q3},
'202611132345-bbbb-repd-2026q3-fast-projects.json', nextRows.length);
return root;
}
test('the registered projects asset is used, not the inherited file with the old name', () => {
const root = fixtureRepo();
const register = resolveRegister(root);
assert.equal(register.release, '202611132345-pipelinenews');
assert.match(register.path, /repd-2026q3-fast-projects\.json$/);
assert.deepEqual(decodeProjects(register.payload).map(row => row.repd_ref), ['100', '101', '200']);
});
test('digest, count and path guards refuse a corrupted registry', () => {
const root = fixtureRepo();
const registry = path.join(root, 'releases/202611132345-pipelinenews/data/202608291447-registry.json');
const original = JSON.parse(readFileSync(registry, 'utf8'));
writeFileSync(registry, JSON.stringify({...original, assets: {projects: {...original.assets.projects, sha256: '0'.repeat(64)}}}));
assert.throws(() => resolveRegister(root), /digest mismatch/);
writeFileSync(registry, JSON.stringify({...original, source: {...original.source, admitted_project_count: 7}}));
assert.throws(() => resolveRegister(root), /admits 7/);
writeFileSync(registry, JSON.stringify({...original, assets: {projects: {...original.assets.projects, path: '../../x.json'}}}));
assert.throws(() => resolveRegister(root), /escapes/);
});
test('delta separates new refs, removed refs, real operator renames, respellings and status changes', () => {
const delta = computeDelta(decodeProjects(payload(Q2)), decodeProjects(payload(Q3)), {limits: {...DEFAULT_LIMITS, min_projects: 1, max_removed_fraction: 1, max_added_fraction: 1, max_operator_change_fraction: 1}});
assert.deepEqual(delta.added, ['200']);
assert.deepEqual(delta.removed, ['102']);
assert.deepEqual(delta.operator_renamed.map(r => r.repd_ref), ['101']);
assert.deepEqual(delta.operator_respelled.map(r => r.repd_ref), ['100']);
assert.deepEqual(delta.status_changed, [{repd_ref: '100', from: 'Application Submitted', to: 'Awaiting Construction', signal: true}]);
assert.equal(delta.gate.status, 'PASS');
assert.deepEqual(operatorAliases(delta).get('101'), ['Beta Ltd', 'New Owner Plc']);
});
test('the gate holds a delta that looks like a broken source', () => {
const big = Array.from({length: 1200}, (_, i) => ({repd_ref: String(1000 + i), name: `Site ${i} Solar Farm`, operator: 'Op', county: 'Kent', capacity_mw: 5}));
const halved = big.slice(0, 600);
const delta = computeDelta(decodeProjects(payload(big)), decodeProjects(payload(halved)));
assert.equal(delta.gate.status, 'HOLD');
assert.ok(delta.gate.reasons.some(reason => /removed 600/.test(reason)));
const dup = computeDelta(decodeProjects(payload(big)), decodeProjects(payload([...big, big[0]])));
assert.equal(dup.gate.status, 'HOLD');
const same = computeDelta(decodeProjects(payload(big)), decodeProjects(payload(big)), {previous: {sha256: 'a'}, next: {sha256: 'a'}});
assert.equal(same.gate.status, 'NO_CHANGE');
});
test('existing bindings are reviewed, never deleted, and new or newly consented refs lead discovery', () => {
const q3 = decodeProjects(payload(Q3));
const delta = computeDelta(decodeProjects(payload(Q2)), q3, {limits: {...DEFAULT_LIMITS, min_projects: 1, max_removed_fraction: 1, max_added_fraction: 1, max_operator_change_fraction: 1}});
const reviewed = reviewBindings([{url: 'a', repd_ref: '102'}, {url: 'b', repd_ref: '100'}, {url: 'c', repd_ref: '101'}, {url: 'd', repd_ref: null}], delta);
assert.equal(reviewed.length, 4);
assert.equal(reviewed[0].register_review[0].flag, 'REF_REMOVED_FROM_REGISTER');
assert.equal(reviewed[1].register_review[0].action, 'RECHECK_FOR_NEW_COVERAGE');
assert.equal(reviewed[2].register_review[0].flag, 'OPERATOR_RENAMED');
assert.deepEqual(discoveryPriority(delta, q3).map(row => [row.repd_ref, row.discovery_reason]),
[['200', 'NEW_IN_REGISTER'], ['100', 'STATUS_Application Submitted_TO_Awaiting Construction']]);
});
test('a provisional row recorded under last quarter\'s operator name is queued for review, never bound', () => {
const q3 = decodeProjects(payload(Q3));
const delta = computeDelta(decodeProjects(payload(Q2)), q3, {limits: {...DEFAULT_LIMITS, min_projects: 1, max_removed_fraction: 1, max_added_fraction: 1, max_operator_change_fraction: 1}});
const row = {name: 'Beta Battery Storage', operator: 'Beta Ltd', county: 'Essex', capacity_mw: 100, repd_ref: '9999-REPD-TBC', official_repd_ref: null,
gg_project_id: 'GG2050-REPD-9999-REPD-TBC', aliases: [], identity_history: []};
const source = {path: 'x', sha256: 'a'.repeat(64)};
assert.equal(reconcileProvisional([row], q3, source)[0].official_repd_ref, null, 'without the delta the renamed operator does not match');
// NL-019 decision: a name/operator match is a review item; only exact identity evidence promotes.
const queued = reconcileProvisional([row], q3, source, {operatorAliases: operatorAliases(delta)})[0];
assert.equal(queued.official_repd_ref, null);
assert.equal(queued.repd_ref, '9999-REPD-TBC');
assert.equal(queued.reconciliation.status, 'OPERATOR_ALIAS_REQUIRES_REVIEW');
assert.deepEqual(queued.reconciliation.review_candidates, [{repd_ref: '101', operator_matches: true, county_matches: true, capacity_matches: true}]);
// Separator respelling ("/" vs "&") is not a different developer.
const alpha = {...row, name: 'Alpha Solar Farm', operator: 'Old Co / Partner', county: 'Kent', capacity_mw: 49.9};
assert.equal(reconcileProvisional([alpha], q3, source)[0].official_repd_ref, '100');
// Capacity still has to agree exactly; the near miss is listed, not bound.
const near = reconcileProvisional([{...alpha, capacity_mw: 50}], q3, source)[0];
assert.equal(near.official_repd_ref, null);
assert.deepEqual(near.reconciliation.review_candidates, [{repd_ref: '100', operator_matches: true, county_matches: true, capacity_matches: false}]);
});
function cliRepo(options) {
const root = fixtureRepo(options);
mkdirSync(path.join(root, 'data/provisional'), {recursive: true});
mkdirSync(path.join(root, 'cartridges'), {recursive: true});
cpSync(path.join(repoRoot, 'tools/intelligence'), path.join(root, 'tools/intelligence'), {recursive: true, filter: src => !src.includes(`${path.sep}cartridges`)});
cpSync(path.join(repoRoot, 'cartridges/provisional-identity.mjs'), path.join(root, 'cartridges/provisional-identity.mjs'));
writeFileSync(path.join(root, 'data/provisional/project-register.json'), JSON.stringify({schema: 'pipelinenews.provisional-register.v1', projects: [
{source_key: 'bbc:x:cearn', name: 'Cearn Solar Farm', operator: 'Telis Energy UK', county: 'Oxfordshire', capacity_mw: 500,
repd_ref: '9999-REPD-TBC', official_repd_ref: null, gg_project_id: 'GG2050-REPD-9999-REPD-TBC', identity_status: 'REPD_PENDING', aliases: [], identity_history: []}]}, null, 2) + '\n');
return root;
}
const runCli = root => JSON.parse(execFileSync(process.execPath, ['tools/intelligence/reconcile-provisional.mjs'], {cwd: root, encoding: 'utf8'}).trim());
test('reconcile-provisional CLI reads the registered Q3 payload and binds a project new in Q3', () => {
const root = cliRepo({pad: true});
const out = runCli(root);
assert.match(out.source.path, /repd-2026q3-fast-projects\.json$/);
assert.equal(out.gate, 'PASS');
assert.equal(out.matched, 1);
const saved = JSON.parse(readFileSync(path.join(root, 'data/provisional/project-register.json'), 'utf8')).projects[0];
assert.equal(saved.repd_ref, '200');
assert.ok(saved.aliases.includes('9999-REPD-TBC'));
});
test('reconcile-provisional CLI leaves the register untouched when the new quarter is held', () => {
const root = cliRepo({pad: false}); // 3-project register: below the 1,000-project floor
const before = readFileSync(path.join(root, 'data/provisional/project-register.json'), 'utf8');
const out = runCli(root);
assert.equal(out.gate.status, 'HOLD');
assert.equal(readFileSync(path.join(root, 'data/provisional/project-register.json'), 'utf8'), before);
});Register Source
A JavaScript module in the intelligence folder of PipelineNews that lists releases (`listReleases`), validates payload (`validatePayload`) and decodes projects (`decodeProjects`), using SHA-256.
energy-datapipelinenews / tools/intelligence/register-source.mjs · lines 1–75 of 75 · pattern decodeProjects (shared by 2 files)
- What it does
- It loads data. Defines sha256, listReleases, resolveRegister, validatePayload, decodeProjects. Uses libraries node:fs, node:crypto, node:path. Side effects: reads or writes files.
- Why it exists in the grid workflow
- Domain stage upstream_foresight (repository name word 'pipelinenews'): upstream engineering foresight over GB transmission and distribution topology (TSO/DNO, 132kV and above, the REPD pipeline, data centres), which Ventus Ltd states it models for foresight.
- Inputs & outputs
- In: JSON file 202608291447-registry.json.
- Downstream impact
- Used directly by 3 files: Reconcile Provisional (pipelinenews); Register Delta (pipelinenews); Register Quarter Test (pipelinenews). Reached from 1 other entry point, including PipelineNews BBC RSS Discovery Workflow (pipelinenews).
- What it achieves
- It lists releases (`listReleases`), resolves register (`resolveRegister`) and validates payload (`validatePayload`). Resolve the project register a Pipeline News release actually serves.
- Why it matters
- Imported by Reconcile Provisional and Register Delta. Checked by Register Quarter Test.
- Application
- pipelinenews · tools/intelligence · JavaScript module
- Uses
- node:fs, node:crypto, node:path
- Used by
- imported by Reconcile Provisional (import), imported by Register Delta (import), run by Register Quarter Test (script call)
- Produces
- REGISTRY_FILE, PROJECT_SCHEMA, RELEASE_ID_RE, IDENTITY_FIELDS, OPTIONAL_FIELDS, sha256, listReleases, resolveRegister, validatePayload, decodeProjects
- Defines here
- sha256, listReleases, resolveRegister, validatePayload, decodeProjects
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- pipelinenews@45c944c8640a9d7ae65edb51d66032ba204f3f46 tools/intelligence/register-source.mjs:1-75 · blob 52df7f4d7338d62088c4746cb6a72074f45d163c · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: ingest · effects: filesystem · domain stage: upstream_foresight · users: IPP_developer, ICP_grid_engineer · canonical: production_core
// Resolve the project register a Pipeline News release actually serves.
//
// The release registry (data/202608291447-registry.json, assets.projects) is the
// only authority for which project payload is live in a release. Searching a
// release folder for "*-v8-fast-projects.json" is unsafe: release_builder copies
// every parent file forward, so a release that replaced its register (for example
// 202611132345, REPD Q3 2026) still carries the inherited Q2 payload under the old
// name. Choosing by file name silently reconciles against the previous quarter.
import {readFileSync, readdirSync, existsSync} from 'node:fs';
import {createHash} from 'node:crypto';
import path from 'node:path';
export const REGISTRY_FILE = 'data/202608291447-registry.json';
export const PROJECT_SCHEMA = 'pipelinenews.v8.fast-project-index.v1';
export const RELEASE_ID_RE = /^\d{12}-pipelinenews$/;
export const IDENTITY_FIELDS = ['repd_ref', 'name', 'operator', 'county', 'capacity_mw'];
export const OPTIONAL_FIELDS = ['technology', 'status', 'region', 'repd_record_updated', 'geometry_status', 'latitude', 'longitude', 'gg_project_id'];
export const sha256 = bytes => createHash('sha256').update(bytes).digest('hex');
export function listReleases(root = '.') {
const dir = path.join(root, 'releases');
if (!existsSync(dir)) return [];
return readdirSync(dir).filter(name => RELEASE_ID_RE.test(name)).sort();
}
// Returns {release, path, sha256, dataset, admitted_project_count, payload, bytes}.
// Throws on any inconsistency; never falls back to a file-name search.
export function resolveRegister(root = '.', {release} = {}) {
const releases = listReleases(root);
const chosen = release ?? releases.at(-1);
if (!chosen || !RELEASE_ID_RE.test(chosen)) throw Error('No release to read a register from');
const registryPath = path.join(root, 'releases', chosen, REGISTRY_FILE);
if (!existsSync(registryPath)) throw Error(`Release ${chosen} has no registry`);
const registry = JSON.parse(readFileSync(registryPath, 'utf8'));
const asset = registry?.assets?.projects;
if (!asset?.path || !/^[a-f0-9]{64}$/.test(asset.sha256 ?? '')) throw Error(`Release ${chosen} registry has no pinned projects asset`);
const relative = path.posix.normalize(asset.path);
if (relative.startsWith('..') || path.isAbsolute(relative) || !relative.startsWith('data/')) throw Error('Projects asset escapes the release folder');
const file = path.join(root, 'releases', chosen, relative);
const bytes = readFileSync(file);
const digest = sha256(bytes);
if (digest !== asset.sha256) throw Error(`Projects asset digest mismatch in ${chosen}: ${digest} != ${asset.sha256}`);
const payload = JSON.parse(bytes);
validatePayload(payload);
const admitted = registry?.source?.admitted_project_count;
if (Number.isInteger(admitted) && admitted !== payload.rows.length) throw Error(`Registry admits ${admitted} projects but payload has ${payload.rows.length}`);
return {
release: chosen,
path: path.posix.join('releases', chosen, relative),
sha256: digest,
dataset: registry?.source?.dataset ?? null,
admitted_project_count: payload.rows.length,
payload,
};
}
export function validatePayload(payload) {
if (payload?.schema !== PROJECT_SCHEMA || !Array.isArray(payload.fields) || !Array.isArray(payload.rows)) throw Error('Unsupported project payload');
for (const field of IDENTITY_FIELDS) if (!payload.fields.includes(field)) throw Error('Project identity field missing: ' + field);
return true;
}
// Decode the dictionary-compressed rows into plain objects (identity + optional fields).
export function decodeProjects(payload) {
validatePayload(payload);
const wanted = [...IDENTITY_FIELDS, ...OPTIONAL_FIELDS].filter(field => payload.fields.includes(field));
const index = Object.fromEntries(wanted.map(field => [field, payload.fields.indexOf(field)]));
return payload.rows.map(values => Object.fromEntries(wanted.map(field => {
const raw = values[index[field]];
const dictionary = payload.dictionaries?.[field];
const value = dictionary && raw !== null && raw !== undefined ? dictionary[raw] : raw;
return [field, field === 'repd_ref' ? String(value) : value ?? null];
})));
}