Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
feat(api): expose a read-only settings inventory [O5,O6]
Corey Olsona0480524366b
diff --git a/docs/api.md b/docs/api.mdindex 5718b815..f5a601a4 100644--- a/docs/api.md+++ b/docs/api.md@@ -374,6 +374,7 @@ The server checks any Origin against its own address and grants no CORS permissi| Method and path | Result || --- | --- |+| `GET /api/v1/settings?board=id` | Local-only read-only inventory: machine settings plus all authorized boards, or the selected board. Each row has `key`, `scope`, `value`, `default`, `source`, and `origin`; repo/board rows also identify `board` and `root`. Credential rows carry `secret: true` and only `set` or `not set`. Runtime events, queues and cached relay payloads are excluded. || `GET /api/v1/boards` | Registered boards with their project details and ids || `GET /api/v1/boards/:board/state?seen=N` | The board state, listing item summaries, including open coordinator requests and the unseen shout count since N || `GET /api/v1/boards/:board/state?detail=full` | The same state with every item in full, which static view exports read |diff --git a/src/api-http.js b/src/api-http.jsindex e0b315f1..04aeca83 100644--- a/src/api-http.js+++ b/src/api-http.js@@ -224,6 +224,11 @@ export function createApiHandler(adapter, { pollMs = 200 } = {}) {const itemRoute = /^\/api\/v1\/boards\/([^/]+)\/items\/([^/]+)$/.exec(url.pathname);const boardId = route?.[1] ?? shoutRoute?.[1] ?? itemRoute?.[1] ?? null;const who = await adapter.authenticate(req, { board: boardId, write: req.method === 'POST' });+ if (url.pathname === '/api/v1/settings') {+ if (req.method !== 'GET') throw new Refused('READ_ONLY', 'settings are read-only here; use the supported settings commands');+ if (typeof adapter.settings !== 'function') throw new Refused('SETTINGS_NOT_AVAILABLE', 'read machine and repository settings from the local API');+ return json(res, 200, await adapter.settings(url.searchParams.get('board'), who));+ }if (req.method === 'GET' && url.pathname === '/api/v1/boards') {const listing = await adapter.boards(who);return json(res, 200, Array.isArray(listing) ? { boards: listing } : listing);diff --git a/src/api.js b/src/api.jsindex 50b943db..f5a5ee13 100644--- a/src/api.js+++ b/src/api.js@@ -69,6 +69,7 @@ import {} from './serve.js';import { relayPresentationShout } from './relay-presentation.js';import { createApiHandler } from './api-http.js';+import { settingsInventory } from './settings-inventory.js';import { moveArgs } from './api-moves.js';import { personRequestStatuses } from './relay-requests.js';export { moveArgs } from './api-moves.js';@@ -1025,6 +1026,7 @@ export function createLocalApiHandler({ secret, getPort, runCommand, projects =if (req.headers.origin && req.headers.origin !== 'http://' + req.headers.host && !permittedOrigins.has(req.headers.origin)) throw new Refused('API_ORIGIN', 'use the API from its own origin');return { local: true };},+ settings: (selected) => settingsInventory(apiProjects(), selected),boards: () => withGitReadFacts(() => apiBoardListing(apiProjects, codeIsMain)),board: (id) => withGitReadFacts(() => findBoard(id, apiProjects, codeIsMain)),state: (board, who, seen, options) => withGitReadFacts(() => localState(board, seen, options).state),diff --git a/src/settings-inventory.js b/src/settings-inventory.jsnew file mode 100644index 00000000..91a2fa4f--- /dev/null+++ b/src/settings-inventory.js@@ -0,0 +1,187 @@+/** Read-only, allowlisted settings projection for the local API [O5,O6]. */+import { existsSync, readFileSync } from 'node:fs';+import { homedir } from 'node:os';+import { join } from 'node:path';+import { DatabaseSync } from 'node:sqlite';+import { defaults, loadConfig } from './config.js';+import { repoInfo } from './git.js';+import { machineHome } from './machine-home.js';+import { machineSettingsFile, gateQueueSettings } from './queue-settings.js';+import { loadMachineSettings } from './settings.js';+import { performanceCores } from './gate.js';+import { defaultViewPort, DEFAULT_VIEW_PORT } from './view-port.js';+import { Refused } from './refused.js';++const MACHINE_DEFAULTS = {+ gateSlots: 2, browserSlots: 1, 'gate.shortSlots': 0,+ 'gate.queue.reviewsFirst': false, 'gate.queue.currentReleaseFirst': false, 'gate.queue.agingMinutes': 30,+ 'gate.memoryFloorMB': null, 'gate.browserFreeChecks': false, 'gate.browserByLaunch': false,+ 'health.sentinel': true, 'view.background': true, 'relay.offerAtInit': true, runners: [],+};+const OPTIONAL_REPO_DEFAULTS = {+ project: null, name: null, 'checks.provesNothing': 'warn', 'verify.unrelatedTrunkMoves': false,+ 'flakes.rerun': false, 'flakes.quarantine': false, 'rigor.budget': 400, 'relay.outbox': false,+ submitGate: null, landingShards: 1, 'landing.publish': null, positiveControl: null, affectedTests: null,+ 'health.sentinel': true, 'testConcurrency.browser': 2,+};++/** Read one optional object without migrations, writes, or parser diagnostics containing its bytes. */+function readObject(file) {+ if (!existsSync(file)) return {};+ try {+ const value = JSON.parse(readFileSync(file, 'utf8'));+ if (!value || typeof value !== 'object' || Array.isArray(value)) throw new Error();+ return value;+ } catch { throw new Refused('BAD_SETTINGS', `cannot read settings in ${file}; restore a JSON object`); }+}++/** Resolve a supported dotted key without inheriting unrelated object members. */+function at(value, key) {+ return key.split('.').reduce((part, name) => part && Object.hasOwn(part, name) ? part[name] : undefined, value);+}++/** Keep only explicitly supported fields in a user-defined structured record. */+function fields(value, names) {+ return Object.fromEntries(names.filter(name => value?.[name] !== undefined).map(name => [name, value[name]]));+}++/** Project structured settings without returning unknown nested metadata or credential fields. */+function safeValue(key, value) {+ const strings = entries => Array.isArray(entries) && entries.every(entry => typeof entry === 'string');+ if (key === 'products' && !Object.values(value).every(strings)) throw new Refused('BAD_SETTINGS', 'products must map names to spec-id lists');+ if (key === 'runners') return value.map(runner => fields(runner, ['host', 'slots', 'browser', 'node', 'root']));+ if (key === 'lanes') return Object.fromEntries(Object.entries(value).map(([name, lane]) => [name, fields(lane, ['owns', 'specs', 'starts'])]));+ if (key === 'fix') return value.map(fixer => fields(fixer, ['run', 'files']));+ return value;+}++/** Enumerate supported default leaves, keeping dynamic maps and lists as single settings. */+function leaves(value, prefix = '') {+ return Object.entries(value).flatMap(([key, entry]) => {+ const name = prefix ? prefix + '.' + key : key;+ return entry && typeof entry === 'object' && !Array.isArray(entry) && Object.keys(entry).length+ ? leaves(entry, name) : [[name, entry]];+ });+}++/** Refuse malformed supported scalar settings without echoing credential-bearing input. */+function checkedValue(key, value, fallback) {+ const expected = fallback === null ? (key === 'gate.memoryFloorMB' || key.startsWith('resources.') ? 'number' : 'string') : typeof fallback;+ if (value !== null && expected !== 'object' && typeof value !== expected) {+ throw new Refused('BAD_SETTINGS', `setting ${key} has an unsupported type; restore its documented value`);+ }+ if (key === 'relay.excluded' && (!Array.isArray(value) || !value.every(entry => typeof entry === 'string'))) {+ throw new Refused('BAD_SETTINGS', 'relay.excluded must be a list of repository paths');+ }+ if (key.endsWith('.url') && value !== null) {+ let url;+ try { url = new URL(value); } catch { throw new Refused('BAD_SETTINGS', 'restore the relay origin URL'); }+ if (url.username || url.password || url.search || url.hash) throw new Refused('BAD_SETTINGS', 'relay origins cannot carry credentials or query parameters');+ }+ return safeValue(key, value);+}++/** Append one setting with both its effective value and explicit provenance. */+function add(rows, { scope, board, root, file, raw, effective = raw }, key, fallback, { secret = false, value = at(effective, key), source, origin } = {}) {+ rows.push({ key, scope, ...(board ? { board, root } : {}), value: secret ? (value ? 'set' : 'not set') : checkedValue(key, value ?? fallback, fallback),+ default: secret ? 'not set' : fallback, source: source ?? file,+ origin: origin ?? (at(raw, key) === undefined ? 'default' : 'configured'), ...(secret ? { secret: true } : {}) });+}++/** Inspect capacity rows without opening the resource manager, which prunes and initializes storage. */+function resourceSettings(rows, context, file) {+ if (!existsSync(file)) return;+ const db = new DatabaseSync(file, { readOnly: true });+ try {+ if (!db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='resource'").get()) return;+ for (const { name, capacity } of db.prepare('SELECT name, capacity FROM resource ORDER BY name').all()) {+ add(rows, { ...context, file, raw: {} }, `resources.${name}.capacity`, null, { value: capacity });+ rows.at(-1).origin = 'configured';+ }+ } finally { db.close(); }+}++/** Read machine configuration and credential presence without migrating legacy relay sessions. */+function machineSettings(rows) {+ const file = machineSettingsFile();+ const raw = readObject(file);+ loadMachineSettings();+ gateQueueSettings();+ const context = { scope: 'machine', file, raw };+ for (const [key, fallback] of Object.entries(MACHINE_DEFAULTS)) add(rows, context, key, fallback);+ add(rows, context, 'view.port', DEFAULT_VIEW_PORT, { value: defaultViewPort(), source: process.env.PULLBOARD_VIEW_PORT === undefined ? 'built-in' : 'environment:PULLBOARD_VIEW_PORT', origin: process.env.PULLBOARD_VIEW_PORT === undefined ? 'default' : 'configured' });+ const relayFile = join(process.env.PULLBOARD_HOME || join(homedir(), '.pullboard'), 'relay-machine', 'state.json');+ const relay = readObject(relayFile);+ const relayContext = { scope: 'machine', file: relayFile, raw: { relay } };+ add(rows, relayContext, 'relay.autoLink', false);+ add(rows, relayContext, 'relay.excluded', []);+ add(rows, relayContext, 'relay.owner.account', null, { value: relay.owner?.account ?? relay.session?.account });+ add(rows, relayContext, 'relay.owner.url', null, { value: relay.owner?.url ?? relay.session?.url });+ add(rows, relayContext, 'relay.session.token', 'not set', { secret: true });+ resourceSettings(rows, { scope: 'machine' }, join(machineHome(), 'resources.sqlite'));+}++/** Project every supported repository setting plus its board's relay connection configuration. */+function repositorySettings(rows, board) {+ const info = repoInfo(board.root);+ const file = join(info.root, 'pullboard.json');+ const raw = readObject(file);+ const effective = loadConfig(info.root);+ const context = { scope: 'repo', board: board.id, root: info.root, file, raw, effective };+ const supported = new Map([...leaves(defaults()), ...Object.entries(OPTIONAL_REPO_DEFAULTS), ['testConcurrency.files', performanceCores()]]);+ for (const [key, fallback] of supported) {+ const value = key === 'testConcurrency.browser' ? Math.min(effective.testConcurrency?.files ?? supported.get('testConcurrency.files'), effective.testConcurrency?.browser ?? 2) : at(effective, key);+ add(rows, context, key, fallback, { value });+ }+ resourceSettings(rows, context, join(info.commonDir, 'pullboard', 'resources.sqlite'));+ const relayFile = join(info.commonDir, 'pullboard', 'relay.json');+ const relay = readObject(relayFile);+ const deletedFile = join(info.commonDir, 'pullboard', 'relay-deleted.json');+ const relayContext = { scope: 'board', board: board.id, root: info.root, file: relayFile, raw: { relay } };+ add(rows, { ...relayContext, file: deletedFile }, 'relay.deleted', false, { value: existsSync(deletedFile), origin: existsSync(deletedFile) ? 'configured' : 'default' });+ for (const [key, fallback] of Object.entries({ 'relay.url': null, 'relay.board': null, 'relay.agent': null, 'relay.personReauth': false, 'relay.keyStorage': null })) add(rows, relayContext, key, fallback);+ const environmentToken = process.env.PULLBOARD_RELAY_TOKEN;+ add(rows, relayContext, 'relay.token', 'not set', { secret: true, value: environmentToken ?? relay.token,+ source: environmentToken === undefined ? relayFile : 'environment:PULLBOARD_RELAY_TOKEN', origin: environmentToken === undefined && !relay.token ? 'default' : 'configured' });+ add(rows, relayContext, 'relay.agentTokens', 'not set', { secret: true, value: Object.values(relay.agentTokens ?? {}).some(value => Boolean(value?.token ?? value)) });+ const keyFile = join(process.env.PULLBOARD_HOME || join(homedir(), '.pullboard'), 'relay-keys', board.id + '.key');+ const keyEnvironment = process.env.PULLBOARD_RELAY_KEY;+ add(rows, { ...relayContext, file: keyFile }, 'relay.key', 'not set', { secret: true,+ value: existsSync(keyFile) || keyEnvironment !== undefined || relay.keyStorage === 'keychain',+ origin: existsSync(keyFile) || keyEnvironment !== undefined || relay.keyStorage === 'keychain' ? 'configured' : 'default',+ source: existsSync(keyFile) ? keyFile : keyEnvironment !== undefined ? 'environment:PULLBOARD_RELAY_KEY' : relay.keyStorage === 'keychain' ? 'system keychain' : keyFile });+}++/** Read a registered board identity without creating, migrating, or repairing its database. */+function registeredBoard(project) {+ const info = repoInfo(project.root);+ const file = join(info.commonDir, 'pullboard', 'board.sqlite');+ if (!existsSync(file)) return null;+ const db = new DatabaseSync(file, { readOnly: true });+ try {+ if (!db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='board_meta'").get()) return null;+ const id = db.prepare('SELECT meta_value FROM board_meta WHERE meta_key = ?').get('board_id')?.meta_value;+ return typeof id === 'string' && /^[0-9a-f]{32}$/u.test(id) ? { ...project, id } : null;+ } finally { db.close(); }+}++/** Return machine and registered authorized boards' settings without opening writable board helpers. */+export function settingsInventory(projects, selected = null) {+ const rows = [];+ const boards = [];+ const warnings = [];+ for (const project of projects) {+ try {+ const board = registeredBoard(project);+ if (board) boards.push(board);+ else warnings.push({ root: project.root, code: 'BOARD_UNAVAILABLE', message: 'board identity is unavailable; restore the registered board before reading its settings' });+ } catch {+ warnings.push({ root: project.root, code: 'BOARD_UNAVAILABLE', message: 'cannot read the registered board identity without repairing its storage' });+ }+ }+ const authorized = selected === null ? boards : boards.filter(board => board.id === selected);+ if (selected !== null && !authorized.length) throw new Refused('NO_BOARD', 'no registered board with this identity; use GET /api/v1/boards');+ machineSettings(rows);+ for (const board of authorized) repositorySettings(rows, board);+ return { settings: rows, ...(warnings.length ? { warnings } : {}) };+}diff --git a/test/settings-api-fixture.js b/test/settings-api-fixture.jsnew file mode 100644index 00000000..dbb0a4ef--- /dev/null+++ b/test/settings-api-fixture.js@@ -0,0 +1,160 @@+/** Real Git, SQLite and HTTP settings inventory proof [O5,O6]. */+import assert from 'node:assert/strict';+import { createServer } from 'node:http';+import { createHash } from 'node:crypto';+import { mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join } from 'node:path';+import { DatabaseSync } from 'node:sqlite';+import { createLocalApiHandler } from '../src/api.js';+import { defaults } from '../src/config.js';+import * as store from '../src/board.js';+import { runFixtureGit } from './fixture-child.js';++/** Hash durable fixture files, including the registry, settings, credentials and SQLite bytes. */+function snapshot(root) {+ return readdirSync(root, { withFileTypes: true }).flatMap(entry => {+ const path = join(root, entry.name);+ // SQLite read locks use transient WAL/shared-memory sidecars, not durable settings.+ if (/\.sqlite-(?:shm|wal)$/u.test(entry.name)) return [];+ return entry.isDirectory() ? snapshot(path) : [[path, createHash('sha256').update(readFileSync(path)).digest('hex')]];+ }).sort(([left], [right]) => left.localeCompare(right));+}++/** Exercise the real authenticated local endpoint without accessing the person's storage. */+export async function proveSettingsApi() {+ const root = mkdtempSync(join(tmpdir(), 'pullboard-settings-api-'));+ const home = join(root, 'home');+ const repo = join(root, 'repo');+ const previous = Object.fromEntries(['PULLBOARD_HOME', 'PULLBOARD_MACHINE_HOME', 'PULLBOARD_RELAY_KEY', 'PULLBOARD_RELAY_TOKEN', 'PULLBOARD_VIEW_PORT'].map(key => [key, process.env[key]]));+ delete process.env.PULLBOARD_RELAY_KEY;+ delete process.env.PULLBOARD_RELAY_TOKEN;+ delete process.env.PULLBOARD_VIEW_PORT;+ process.env.PULLBOARD_HOME = home;+ process.env.PULLBOARD_MACHINE_HOME = home;+ let server;+ let handler;+ try {+ mkdirSync(home);+ mkdirSync(repo);+ runFixtureGit(['init', '-q', '-b', 'main'], { cwd: repo, encoding: 'utf8' });+ const privateDir = join(repo, '.git', 'pullboard');+ mkdirSync(privateDir);+ const board = store.openBoard(join(privateDir, 'board.sqlite'));+ const id = store.boardId(board);+ const events = board.db.prepare('SELECT COUNT(*) AS n FROM event').get().n;+ store.closeBoard(board);+ const canary = ['fixture', 'credential', 'never-return-this'].join('-');+ const config = { ...defaults(), gate: 'node --test', health: { sentinel: false }, testConcurrency: { files: 3, browser: 1 }, claim: { reopenFirstRefusalMinutes: 30 }, lanes: { app: { owns: ['app/'], specs: ['O5'], ignoredSecret: canary } } };+ writeFileSync(join(repo, 'pullboard.json'), JSON.stringify(config));+ writeFileSync(join(home, 'settings.json'), JSON.stringify({ gateSlots: 3, browserSlots: 2, gate: { queue: { reviewsFirst: true }, shortSlots: 1 }, relay: { offerAtInit: false }, unknown: { token: canary } }));+ writeFileSync(join(home, 'projects.json'), JSON.stringify({ fixture: canary }));+ mkdirSync(join(home, 'relay-machine'));+ writeFileSync(join(home, 'relay-machine', 'state.json'), JSON.stringify({ v: 1, autoLink: true, session: { token: canary, account: 'fixture', url: 'https://relay.example.invalid' }, approvals: [{ sealed: canary }], devices: [], excluded: [] }));+ writeFileSync(join(privateDir, 'relay.json'), JSON.stringify({ version: 1, board: id, url: 'https://relay.example.invalid', token: canary, agentTokens: { fixture: { token: canary } }, snapshot: canary }));+ const resources = new DatabaseSync(join(home, 'resources.sqlite'));+ resources.exec('CREATE TABLE resource(name TEXT PRIMARY KEY, capacity INTEGER NOT NULL)');+ resources.prepare('INSERT INTO resource VALUES (?, ?)').run('custom', 4);+ resources.close();+ const legacy = join(root, 'legacy');+ const missing = join(root, 'missing');+ const legacyId = 'a'.repeat(32);+ for (const folder of [legacy, missing]) {+ mkdirSync(folder);+ runFixtureGit(['init', '-q', '-b', 'main'], { cwd: folder, encoding: 'utf8' });+ writeFileSync(join(folder, 'pullboard.json'), JSON.stringify(defaults()));+ }+ mkdirSync(join(legacy, '.git', 'pullboard'));+ const oldBoard = new DatabaseSync(join(legacy, '.git', 'pullboard', 'board.sqlite'));+ oldBoard.exec('CREATE TABLE board_meta(meta_key TEXT PRIMARY KEY, meta_value TEXT)');+ oldBoard.prepare('INSERT INTO board_meta VALUES (?, ?)').run('board_id', legacyId);+ oldBoard.close();+ let port;+ handler = createLocalApiHandler({ secret: 'api-fixture', getPort: () => port, runCommand: async () => 0,+ projects: () => [repo, legacy, missing].map(root => ({ root, name: 'fixture', project: '', added: '2026-01-01' })) });+ server = createServer(handler);+ await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));+ port = server.address().port;+ const address = `http://127.0.0.1:${port}/api/v1/settings`;+ const before = snapshot(root);+ const response = await fetch(address, { headers: { 'x-pullboard-key': 'api-fixture' } });+ assert.equal(response.status, 200, 'the settings API exists');+ const text = await response.text();+ assert.ok(!text.includes(canary), 'no unknown, nested, legacy-session or relay credential escapes');+ const result = JSON.parse(text);+ assert.equal(result.version, 1);+ assert.equal(result.warnings[0].root, missing);+ const rows = result.settings;+ const find = (scope, key) => rows.find(row => row.scope === scope && row.key === key);+ for (const row of rows) {+ assert.ok(['machine', 'repo', 'board'].includes(row.scope));+ assert.ok(Object.hasOwn(row, 'value') && Object.hasOwn(row, 'default'));+ assert.equal(typeof row.source, 'string');+ if (row.scope !== 'machine') assert.ok([id, legacyId].includes(row.board));+ }+ assert.equal(find('machine', 'gateSlots').value, 3);+ assert.equal(find('machine', 'gateSlots').default, 2);+ assert.equal(find('machine', 'gateSlots').source, join(home, 'settings.json'));+ assert.equal(find('machine', 'gate.queue.reviewsFirst').value, true);+ assert.equal(find('machine', 'gate.queue.agingMinutes').value, 30);+ assert.equal(find('machine', 'resources.custom.capacity').value, 4);+ assert.equal(find('repo', 'claim.reopenFirstRefusalMinutes').value, 30);+ assert.equal(find('repo', 'health.sentinel').value, false);+ assert.equal(find('repo', 'testConcurrency.files').value, 3);+ for (const key of ['checks.provesNothing', 'verify.unrelatedTrunkMoves', 'flakes.rerun', 'flakes.quarantine', 'rigor.budget', 'relay.outbox', 'submitGate', 'landingShards', 'landing.publish', 'positiveControl', 'affectedTests']) assert.ok(find('repo', key), key);+ assert.equal(find('board', 'relay.token').value, 'set');+ assert.equal(find('machine', 'relay.session.token').value, 'set');+ assert.deepEqual(find('repo', 'lanes').value, { app: { owns: ['app/'], specs: ['O5'] } });+ const selected = await fetch(address + '?board=' + id, { headers: { 'x-pullboard-key': 'api-fixture' } });+ assert.equal(selected.status, 200);+ assert.deepEqual((await selected.json()).settings, rows.filter(row => row.scope === 'machine' || row.board === id));+ const unknown = await fetch(address + '?board=missing', { headers: { 'x-pullboard-key': 'api-fixture' } });+ assert.equal(unknown.status, 404);+ assert.equal((await fetch(address)).status, 401);+ assert.equal((await fetch(address, { method: 'POST', headers: { 'x-pullboard-key': 'api-fixture' } })).status, 400);+ assert.deepEqual(snapshot(root), before, 'GET neither migrates credentials nor changes settings, registry, resources or board bytes');+ // Supported fields containing nested canary objects must refuse safely, not become raw JSON.+ for (const invalid of [+ { ...config, products: { app: [{ token: canary }] } },+ { ...config, lanes: { app: { owns: ['app/'], starts: { token: canary } } } },+ ]) {+ writeFileSync(join(repo, 'pullboard.json'), JSON.stringify(invalid));+ const saved = snapshot(root);+ const refused = await fetch(address + '?board=' + id, { headers: { 'x-pullboard-key': 'api-fixture' } });+ assert.equal(refused.status, 400);+ assert.ok(!(await refused.text()).includes(canary));+ assert.deepEqual(snapshot(root), saved);+ }+ writeFileSync(join(repo, 'pullboard.json'), JSON.stringify(config));+ const machineFile = join(home, 'settings.json');+ const machineSaved = readFileSync(machineFile);+ writeFileSync(machineFile, JSON.stringify({ gateSlots: { token: canary } }));+ const invalidMachine = snapshot(root);+ const refusedMachine = await fetch(address, { headers: { 'x-pullboard-key': 'api-fixture' } });+ assert.equal(refusedMachine.status, 400);+ assert.ok(!(await refusedMachine.text()).includes(canary));+ assert.deepEqual(snapshot(root), invalidMachine);+ writeFileSync(machineFile, machineSaved);+ process.env.PULLBOARD_RELAY_KEY = canary;+ process.env.PULLBOARD_RELAY_TOKEN = canary;+ const environment = await (await fetch(address + '?board=' + id, { headers: { 'x-pullboard-key': 'api-fixture' } })).json();+ for (const key of ['relay.key', 'relay.token']) {+ const row = environment.settings.find(row => row.scope === 'board' && row.key === key);+ assert.equal(row.value, 'set');+ assert.equal(row.source, 'environment:' + (key === 'relay.key' ? 'PULLBOARD_RELAY_KEY' : 'PULLBOARD_RELAY_TOKEN'));+ }+ assert.ok(!JSON.stringify(environment).includes(canary));+ const legacyRead = new DatabaseSync(join(legacy, '.git', 'pullboard', 'board.sqlite'), { readOnly: true });+ assert.equal(legacyRead.prepare('PRAGMA user_version').get().user_version, 0);+ assert.deepEqual(legacyRead.prepare("SELECT name FROM sqlite_master WHERE type='table'").all().map(row => row.name), ['board_meta']);+ legacyRead.close();+ const read = new DatabaseSync(join(privateDir, 'board.sqlite'), { readOnly: true });+ assert.equal(read.prepare('SELECT COUNT(*) AS n FROM event').get().n, events);+ read.close();+ } finally {+ if (server) { server.closeAllConnections(); await new Promise(resolve => server.close(resolve)); }+ handler?.close();+ for (const [key, value] of Object.entries(previous)) { if (value === undefined) delete process.env[key]; else process.env[key] = value; }+ rmSync(root, { recursive: true, force: true });+ }+}diff --git a/test/settings.test.js b/test/settings.test.jsindex 71b34dc5..fb3b6887 100644--- a/test/settings.test.js+++ b/test/settings.test.js@@ -60,3 +60,8 @@ test('[Q4] the machine pool ignores board and HOME overrides unless explicitly sassert.equal(privateHome.status, 0, privateHome.stderr);assert.equal(privateHome.stdout, resolve(override));});++test('the settings API reports every setting with its scope, value, default and source and never a secret [O5,O6]', async () => {+ const { proveSettingsApi } = await import('./settings-api-fixture.js');+ await proveSettingsApi();+});