@bongos/core 1.19.942 → 1.19.944
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.bongos-core.json +13 -13
- package/docs/module-api-changelog.md +4 -0
- package/package-lock.json +2 -2
- package/package.json +1 -1
- package/scripts/gds/agents-sync.js +17 -7
- package/scripts/migrate.sh +12 -2
- package/src/module-api.js +1 -1
- package/tests/agents_sync.mjs +36 -1
- package/tests/migrate_module_overrides_db.mjs +63 -28
package/.bongos-core.json
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
"artifact": "bongos-core",
|
|
3
3
|
"manifest_schema": 1,
|
|
4
4
|
"generator": "scripts/gds/package-core.js",
|
|
5
|
-
"core_version": "1.19.
|
|
6
|
-
"core_contract": "1.19.
|
|
7
|
-
"source_commit": "
|
|
5
|
+
"core_version": "1.19.944",
|
|
6
|
+
"core_contract": "1.19.944",
|
|
7
|
+
"source_commit": "9bb024296de8bc08497922c176fac32f1cbd4072",
|
|
8
8
|
"source_ref": "HEAD",
|
|
9
|
-
"built_at": "2026-09-
|
|
9
|
+
"built_at": "2026-09-21T22:56:15.068Z",
|
|
10
10
|
"redaction": {
|
|
11
11
|
"model": "docs-redacted+functional-verbatim",
|
|
12
12
|
"docs_redacted": 511,
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"gate": "passed"
|
|
18
18
|
},
|
|
19
19
|
"file_count": 2877,
|
|
20
|
-
"tree_sha256": "
|
|
20
|
+
"tree_sha256": "0ba58d1da09b858f4ba434ece27993e6d514cbb7622e15d3987343c832c6710e",
|
|
21
21
|
"files": [
|
|
22
22
|
{
|
|
23
23
|
"path": ".claude/skills/ask-for-help/SKILL.md",
|
|
@@ -2677,7 +2677,7 @@
|
|
|
2677
2677
|
{
|
|
2678
2678
|
"path": "docs/module-api-changelog.md",
|
|
2679
2679
|
"mode": "0000644",
|
|
2680
|
-
"sha256": "
|
|
2680
|
+
"sha256": "fd85af374ab5c378414a246c9575a5254fb720e1c9ba0792093c96ebdd07b1f7"
|
|
2681
2681
|
},
|
|
2682
2682
|
{
|
|
2683
2683
|
"path": "docs/modules-contract.md",
|
|
@@ -8002,12 +8002,12 @@
|
|
|
8002
8002
|
{
|
|
8003
8003
|
"path": "package-lock.json",
|
|
8004
8004
|
"mode": "0000644",
|
|
8005
|
-
"sha256": "
|
|
8005
|
+
"sha256": "915c0d9eda15ebe2198dff6cbc476e11b5ef5c286b3bcd5cb47aed9f7eba3599"
|
|
8006
8006
|
},
|
|
8007
8007
|
{
|
|
8008
8008
|
"path": "package.json",
|
|
8009
8009
|
"mode": "0000644",
|
|
8010
|
-
"sha256": "
|
|
8010
|
+
"sha256": "9174d7da67f1bce8d88d2e2ef0da7c656910d53c955040d3a9f74e8b0dede5f6"
|
|
8011
8011
|
},
|
|
8012
8012
|
{
|
|
8013
8013
|
"path": "public-docs/index.html",
|
|
@@ -8097,7 +8097,7 @@
|
|
|
8097
8097
|
{
|
|
8098
8098
|
"path": "scripts/gds/agents-sync.js",
|
|
8099
8099
|
"mode": "0000644",
|
|
8100
|
-
"sha256": "
|
|
8100
|
+
"sha256": "29f3d1521c04165a891a8055f005cb51ca019c51c556063e55167675051a43af"
|
|
8101
8101
|
},
|
|
8102
8102
|
{
|
|
8103
8103
|
"path": "scripts/gds/api-alias-caller-scan.js",
|
|
@@ -9617,7 +9617,7 @@
|
|
|
9617
9617
|
{
|
|
9618
9618
|
"path": "scripts/migrate.sh",
|
|
9619
9619
|
"mode": "0000644",
|
|
9620
|
-
"sha256": "
|
|
9620
|
+
"sha256": "1ba289b008ef4118cfd464ab5eb24ad4b694981942680220f115913691645e08"
|
|
9621
9621
|
},
|
|
9622
9622
|
{
|
|
9623
9623
|
"path": "scripts/migrate_cost_ledger.sh",
|
|
@@ -10012,7 +10012,7 @@
|
|
|
10012
10012
|
{
|
|
10013
10013
|
"path": "src/module-api.js",
|
|
10014
10014
|
"mode": "0000644",
|
|
10015
|
-
"sha256": "
|
|
10015
|
+
"sha256": "ff95cfa479f2e1c5d4b9598d832a43743122b621338de3f5e902289d00e379d8"
|
|
10016
10016
|
},
|
|
10017
10017
|
{
|
|
10018
10018
|
"path": "src/module-loader/catalog.js",
|
|
@@ -10187,7 +10187,7 @@
|
|
|
10187
10187
|
{
|
|
10188
10188
|
"path": "tests/agents_sync.mjs",
|
|
10189
10189
|
"mode": "0000644",
|
|
10190
|
-
"sha256": "
|
|
10190
|
+
"sha256": "daa2d58b9a248222a54305c3fa41d30e73c8ea8cd65db8a14e31d30dfe0ca555"
|
|
10191
10191
|
},
|
|
10192
10192
|
{
|
|
10193
10193
|
"path": "tests/agents_validate.mjs",
|
|
@@ -12512,7 +12512,7 @@
|
|
|
12512
12512
|
{
|
|
12513
12513
|
"path": "tests/migrate_module_overrides_db.mjs",
|
|
12514
12514
|
"mode": "0000644",
|
|
12515
|
-
"sha256": "
|
|
12515
|
+
"sha256": "9d96fe899e8f3f25030ae13b471d2ec9b2f8edb1f9242d221c927e7eac5d7329"
|
|
12516
12516
|
},
|
|
12517
12517
|
{
|
|
12518
12518
|
"path": "tests/migrate_root_resolution.mjs",
|
|
@@ -2358,5 +2358,9 @@ is load-bearing: the script throws rather than guess if it is missing, and
|
|
|
2358
2358
|
landed since 1.19.940 with no explicit bump. run 35652433730. (task 1002620)
|
|
2359
2359
|
1.19.942 — CI auto-patch (publish-on-merge, ADR 0161): carrier for merges
|
|
2360
2360
|
landed since 1.19.941 with no explicit bump. run 35659043986. (task 1002620)
|
|
2361
|
+
1.19.943 — CI auto-patch (publish-on-merge, ADR 0161): carrier for merges
|
|
2362
|
+
landed since 1.19.942 with no explicit bump. run 35661533404. (task 1002620)
|
|
2363
|
+
1.19.944 — CI auto-patch (publish-on-merge, ADR 0161): carrier for merges
|
|
2364
|
+
landed since 1.19.943 with no explicit bump. run 35665131778. (task 1002620)
|
|
2361
2365
|
---------------------------------------------------------------------------
|
|
2362
2366
|
```
|
package/package-lock.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bongos/core",
|
|
3
|
-
"version": "1.19.
|
|
3
|
+
"version": "1.19.944",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@bongos/core",
|
|
9
|
-
"version": "1.19.
|
|
9
|
+
"version": "1.19.944",
|
|
10
10
|
"license": "AGPL-3.0-or-later",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"express": "^4.21.2",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bongos/core",
|
|
3
|
-
"version": "1.19.
|
|
3
|
+
"version": "1.19.944",
|
|
4
4
|
"description": "Cloud Bongos — the AI-first build platform core (GDS + platform surfaces + module system), installed as a versioned dependency (ADR 0108).",
|
|
5
5
|
"license": "AGPL-3.0-or-later",
|
|
6
6
|
"main": "src/platform-server.js",
|
|
@@ -317,6 +317,14 @@ function planSync(files, { existingByName = new Map(), authorRankFor = () => nul
|
|
|
317
317
|
|
|
318
318
|
// ---- disk + git ------------------------------------------------------------
|
|
319
319
|
|
|
320
|
+
// The repo a definitions dir belongs to, by the `<root>/.claude/agents` layout.
|
|
321
|
+
// Not REPO_ROOT: a split-root instance runs this script from the core package
|
|
322
|
+
// while its definitions live in the instance repo (task 1004139), so paths and
|
|
323
|
+
// git history must be read against the definitions' repo, not the core's.
|
|
324
|
+
function definitionsRoot(dir) {
|
|
325
|
+
return path.resolve(dir, '..', '..');
|
|
326
|
+
}
|
|
327
|
+
|
|
320
328
|
// An ABSENT directory is a legitimate state, not an error: `.claude/agents/`
|
|
321
329
|
// does not exist in the core tree at all today, and an instance that ships no
|
|
322
330
|
// agents must deploy cleanly. Zero files, exit 0, nothing written.
|
|
@@ -328,10 +336,11 @@ function readAgentFiles(dir = DEFAULT_DIR) {
|
|
|
328
336
|
if (err.code === 'ENOENT') return [];
|
|
329
337
|
throw err;
|
|
330
338
|
}
|
|
339
|
+
const root = definitionsRoot(dir);
|
|
331
340
|
return names.sort().map((f) => {
|
|
332
341
|
const full = path.join(dir, f);
|
|
333
342
|
return {
|
|
334
|
-
file: path.relative(
|
|
343
|
+
file: path.relative(root, full).split(path.sep).join('/'),
|
|
335
344
|
candidate: parseAgentFile(fs.readFileSync(full, 'utf8'), { name: f.replace(/\.md$/, '') }),
|
|
336
345
|
};
|
|
337
346
|
});
|
|
@@ -350,9 +359,9 @@ function readAgentFiles(dir = DEFAULT_DIR) {
|
|
|
350
359
|
//
|
|
351
360
|
// It is kept because provenance is genuinely useful where nothing is riding on
|
|
352
361
|
// it. The wall is that it is never consulted where it could grant anything.
|
|
353
|
-
function lastCommitterLogin(file, { runGit = defaultRunGit } = {}) {
|
|
362
|
+
function lastCommitterLogin(file, { runGit = defaultRunGit, cwd = REPO_ROOT } = {}) {
|
|
354
363
|
let out;
|
|
355
|
-
try { out = runGit(['log', '-1', '--format=%ae%n%an', '--', file]); }
|
|
364
|
+
try { out = runGit(['log', '-1', '--format=%ae%n%an', '--', file], cwd); }
|
|
356
365
|
catch { return null; }
|
|
357
366
|
const [email = '', authorName = ''] = String(out || '').split(/\r?\n/);
|
|
358
367
|
const noreply = /^(?:\d+\+)?([A-Za-z0-9-]+)@users\.noreply\.github\.com$/.exec(email.trim());
|
|
@@ -360,8 +369,8 @@ function lastCommitterLogin(file, { runGit = defaultRunGit } = {}) {
|
|
|
360
369
|
return authorName.trim() || null;
|
|
361
370
|
}
|
|
362
371
|
|
|
363
|
-
function defaultRunGit(args) {
|
|
364
|
-
return execFileSync('git', args, { cwd
|
|
372
|
+
function defaultRunGit(args, cwd = REPO_ROOT) {
|
|
373
|
+
return execFileSync('git', args, { cwd, encoding: 'utf8' });
|
|
365
374
|
}
|
|
366
375
|
|
|
367
376
|
module.exports = {
|
|
@@ -386,11 +395,12 @@ async function main() {
|
|
|
386
395
|
const asJson = argv.includes('--json');
|
|
387
396
|
const dirIdx = argv.indexOf('--dir');
|
|
388
397
|
const dir = dirIdx >= 0 ? argv[dirIdx + 1] : DEFAULT_DIR;
|
|
398
|
+
const root = definitionsRoot(dir);
|
|
389
399
|
|
|
390
400
|
const files = readAgentFiles(dir);
|
|
391
401
|
if (files.length === 0) {
|
|
392
402
|
if (asJson) console.log(JSON.stringify({ ok: true, scanned: 0, plan: [] }));
|
|
393
|
-
else console.log(`agents-sync: no definitions under ${path.relative(
|
|
403
|
+
else console.log(`agents-sync: no definitions under ${path.relative(root, dir) || dir} — nothing to reconcile.`);
|
|
394
404
|
return 0;
|
|
395
405
|
}
|
|
396
406
|
|
|
@@ -413,7 +423,7 @@ async function main() {
|
|
|
413
423
|
// ONE git subprocess per file, memoised — `authorRankFor` is called again from
|
|
414
424
|
// planSync, and re-shelling out there doubled the blocking spawns for an answer
|
|
415
425
|
// that cannot have changed mid-run.
|
|
416
|
-
const loginByFile = new Map(files.map((f) => [f.file, lastCommitterLogin(f.file)]));
|
|
426
|
+
const loginByFile = new Map(files.map((f) => [f.file, lastCommitterLogin(f.file, { cwd: root })]));
|
|
417
427
|
// One query for every distinct committer, not one per file.
|
|
418
428
|
const logins = [...new Set([...loginByFile.values()].filter(Boolean))];
|
|
419
429
|
const rankByLogin = new Map();
|
package/scripts/migrate.sh
CHANGED
|
@@ -407,10 +407,20 @@ fi
|
|
|
407
407
|
#
|
|
408
408
|
# Silent when the module is off: `agents` is default:false, so on most instances
|
|
409
409
|
# there is no table to reconcile into and nothing to say about it.
|
|
410
|
-
|
|
410
|
+
#
|
|
411
|
+
# Gated on the module set the module loop just migrated (DB overrides included,
|
|
412
|
+
# task 1004138). A fresh isModuleEnabled() read never loaded the overrides, so an
|
|
413
|
+
# `agents` switched on in the hall got its tables but never its registry. Pinned to
|
|
414
|
+
# $DB like that read, so the reconcile writes into the schema this run applied.
|
|
415
|
+
#
|
|
416
|
+
# The script is the core's, the definitions are the instance's own (task 1004139, an
|
|
417
|
+
# owner decision): a split-root instance (core in node_modules) reconciles ITS
|
|
418
|
+
# .claude/agents, never the core package's shipped set and no merge of the two.
|
|
419
|
+
# Single-root, CORE_ROOT == INSTANCE_ROOT and this is the same call as before.
|
|
420
|
+
if [[ " $NODE_ENABLED_MODULES " == *" agents "* ]]; then
|
|
411
421
|
echo
|
|
412
422
|
echo "post-deploy: reconciling .claude/agents/ into the agent registry"
|
|
413
|
-
if ! node scripts/gds/agents-sync.js; then
|
|
423
|
+
if ! DATABASE_URL='' PGDATABASE="$DB" node "$CORE_ROOT/scripts/gds/agents-sync.js" --dir "$INSTANCE_ROOT/.claude/agents"; then
|
|
414
424
|
echo "post-deploy: agents-sync failed — the registry is stale by one deploy, not broken" >&2
|
|
415
425
|
fi
|
|
416
426
|
fi
|
package/src/module-api.js
CHANGED
|
@@ -71,7 +71,7 @@ const { responsibilityFor, ROLE_RESPONSIBILITIES } = require('./role-responsibil
|
|
|
71
71
|
// there. scripts/gds/bump-version.js still rewrites the literal below; it appends
|
|
72
72
|
// the entry to that file. Look for a version's history there, not here.
|
|
73
73
|
// ---------------------------------------------------------------------------
|
|
74
|
-
const CORE_VERSION = '1.19.
|
|
74
|
+
const CORE_VERSION = '1.19.944'; // CI auto-patch carrier (ADR 0161); changelog: docs/module-api-changelog.md
|
|
75
75
|
|
|
76
76
|
// A namespaced logger so a module's log lines are attributable + consistent.
|
|
77
77
|
// Usage: const log = api.logger('dev-box'); log.info('mounted');
|
package/tests/agents_sync.mjs
CHANGED
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
// Run: node tests/agents_sync.mjs
|
|
25
25
|
|
|
26
26
|
import { strict as assert } from 'node:assert';
|
|
27
|
+
import { execFileSync } from 'node:child_process';
|
|
27
28
|
import { createRequire } from 'node:module';
|
|
28
29
|
import fs from 'node:fs';
|
|
29
30
|
import os from 'node:os';
|
|
@@ -279,6 +280,32 @@ t('a real directory is read, .md only, sorted', () => {
|
|
|
279
280
|
assert.deepEqual(files.map((f) => f.candidate.name), ['alpha', 'historian'], 'sorted, so a run is reproducible');
|
|
280
281
|
});
|
|
281
282
|
|
|
283
|
+
console.log('\na split-root instance reconciles its OWN definitions (task 1004139):');
|
|
284
|
+
|
|
285
|
+
t('definitions outside the core read against their own repo, not the core', () => {
|
|
286
|
+
// The core runs from node_modules while .claude/agents lives in the instance repo.
|
|
287
|
+
// Read against the core, source_path came out as ../../../.claude/agents/x.md and the
|
|
288
|
+
// git author lookup ran in the wrong repo.
|
|
289
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'agents-sync-instance-'));
|
|
290
|
+
const dir = path.join(root, '.claude', 'agents');
|
|
291
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
292
|
+
fs.writeFileSync(path.join(dir, 'scout.md'), FILE.replace('name: historian', 'name: scout'));
|
|
293
|
+
const git = (...args) => execFileSync('git', args, { cwd: root, stdio: 'ignore' });
|
|
294
|
+
try {
|
|
295
|
+
git('init', '-q');
|
|
296
|
+
git('add', '.');
|
|
297
|
+
git('-c', 'user.email=12345+octocat@users.noreply.github.com', '-c', 'user.name=Someone',
|
|
298
|
+
'-c', 'commit.gpgsign=false', 'commit', '-q', '--no-verify', '-m', 'add scout');
|
|
299
|
+
|
|
300
|
+
const [f] = sync.readAgentFiles(dir);
|
|
301
|
+
assert.equal(f.file, '.claude/agents/scout.md', 'source_path is relative to the instance root');
|
|
302
|
+
assert.equal(sync.lastCommitterLogin(f.file, { cwd: root }), 'octocat', 'history is read from the instance repo');
|
|
303
|
+
assert.equal(sync.lastCommitterLogin(f.file), null, 'the core repo has no history for an instance file');
|
|
304
|
+
} finally {
|
|
305
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
|
|
282
309
|
console.log('\nplanSync — the whole reconcile, still pure:');
|
|
283
310
|
|
|
284
311
|
t('one plan entry per file, each carrying its own author rank', () => {
|
|
@@ -403,7 +430,15 @@ t('migrate.sh invokes agents-sync, module-gated and fail-open', () => {
|
|
|
403
430
|
// writes into a few lines above, so the table exists by the time it runs.
|
|
404
431
|
const sh = fs.readFileSync(new URL('../scripts/migrate.sh', import.meta.url), 'utf8');
|
|
405
432
|
assert.match(sh, /scripts\/gds\/agents-sync\.js/, 'the deploy path must call it');
|
|
406
|
-
|
|
433
|
+
// Gated on the set the module loop migrated, DB overrides included (task 1004138);
|
|
434
|
+
// a fresh isModuleEnabled() read never saw a hall toggle.
|
|
435
|
+
assert.match(sh, /\$NODE_ENABLED_MODULES " == \*" agents "\*/, "gated on the module — it is default:false");
|
|
436
|
+
assert.doesNotMatch(sh, /isModuleEnabled\('agents'\)/, 'no override-blind re-read of the module flag');
|
|
437
|
+
// Split-root (task 1004139): the core's script, the instance's own definitions, pinned to
|
|
438
|
+
// $DB — and no instance-relative file check, which silenced every split-root instance.
|
|
439
|
+
assert.match(sh, /DATABASE_URL='' PGDATABASE="\$DB" node "\$CORE_ROOT\/scripts\/gds\/agents-sync\.js" --dir "\$INSTANCE_ROOT\/\.claude\/agents"/,
|
|
440
|
+
'reconcile the instance .claude/agents with the core script, against $DB');
|
|
441
|
+
assert.doesNotMatch(sh, /-f scripts\/gds\/agents-sync\.js/, 'no instance-relative existence check');
|
|
407
442
|
// Fail-OPEN: a stale registry is a nuisance, an aborted deploy is an outage,
|
|
408
443
|
// and the script is already fail-closed about what it imports.
|
|
409
444
|
assert.match(sh, /agents-sync failed — the registry is stale by one deploy/,
|
|
@@ -1,19 +1,24 @@
|
|
|
1
|
-
// tests/migrate_module_overrides_db.mjs — migrate.sh
|
|
1
|
+
// tests/migrate_module_overrides_db.mjs — migrate.sh follows the hall's module toggles (tasks 1004137, 1004138).
|
|
2
2
|
//
|
|
3
3
|
// The hall's Modules toggle writes module_enablement_overrides, and the server reads that table
|
|
4
4
|
// before it mounts any routes. migrate.sh used to pick its module set in a fresh process that never
|
|
5
5
|
// read it, so a module on ONLY by override was skipped on every deploy while the next restart
|
|
6
|
-
// mounted its routes against tables that did not exist. This drives the real migrate.sh
|
|
7
|
-
// --print-modules seam (the same function its module loop calls)
|
|
6
|
+
// mounted its routes against tables that did not exist. This drives the real migrate.sh against a
|
|
7
|
+
// real database: its --print-modules seam (the same function its module loop calls), and a full run
|
|
8
|
+
// with psql stubbed out to show the post-deploy agents reconcile gates on that same set.
|
|
8
9
|
//
|
|
9
|
-
// Integration lane: needs Postgres
|
|
10
|
-
//
|
|
10
|
+
// Integration lane: needs Postgres, reached BOTH through DATABASE_URL (this process) and the PG*
|
|
11
|
+
// env (migrate.sh blanks DATABASE_URL so its reads hit the database psql migrates) — the lane sets
|
|
12
|
+
// both. Self-skips when no Postgres is reachable. Leaves the override table as it found it.
|
|
11
13
|
//
|
|
12
|
-
// Run: DATABASE_URL=postgres
|
|
14
|
+
// Run: PGHOST=… PGPORT=… PGUSER=… PGPASSWORD=… PGDATABASE=… DATABASE_URL=postgres://… \
|
|
15
|
+
// node tests/migrate_module_overrides_db.mjs
|
|
13
16
|
|
|
14
17
|
import { strict as assert } from 'node:assert';
|
|
15
18
|
import { execFileSync } from 'node:child_process';
|
|
16
19
|
import { createRequire } from 'node:module';
|
|
20
|
+
import { chmodSync, mkdtempSync, writeFileSync } from 'node:fs';
|
|
21
|
+
import { tmpdir } from 'node:os';
|
|
17
22
|
import { fileURLToPath } from 'node:url';
|
|
18
23
|
import path from 'node:path';
|
|
19
24
|
|
|
@@ -23,13 +28,15 @@ const { moduleScopeKey } = require('../src/modules.js');
|
|
|
23
28
|
|
|
24
29
|
const REPO_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
25
30
|
const MIGRATE = path.join(REPO_ROOT, 'scripts', 'migrate.sh');
|
|
26
|
-
//
|
|
31
|
+
// Both ship migrations and are off in the packs, so the override alone decides them.
|
|
27
32
|
const MODULE = 'discord';
|
|
33
|
+
const AGENTS = 'agents';
|
|
34
|
+
const RECONCILE_LINE = 'post-deploy: reconciling .claude/agents/ into the agent registry';
|
|
28
35
|
|
|
29
36
|
try {
|
|
30
37
|
await pool.query('SELECT 1');
|
|
31
38
|
} catch (e) {
|
|
32
|
-
console.log(`migrate_module_overrides_db.mjs SKIPPED — no reachable Postgres (${e.code || e.message}). Set DATABASE_URL to run.`);
|
|
39
|
+
console.log(`migrate_module_overrides_db.mjs SKIPPED — no reachable Postgres (${e.code || e.message}). Set DATABASE_URL and the PG* env to run.`);
|
|
33
40
|
await pool.end().catch(() => {});
|
|
34
41
|
process.exit(0);
|
|
35
42
|
}
|
|
@@ -37,34 +44,47 @@ try {
|
|
|
37
44
|
const { rows: [{ db }] } = await pool.query('SELECT current_database() AS db');
|
|
38
45
|
const scope = moduleScopeKey();
|
|
39
46
|
|
|
40
|
-
|
|
47
|
+
// A psql that records nothing and applies nothing: the full run below walks every loop without
|
|
48
|
+
// touching the schema, so only the module-set read (node, real DB) decides what it reaches.
|
|
49
|
+
const stubDir = mkdtempSync(path.join(tmpdir(), 'migrate-stub-psql-'));
|
|
50
|
+
writeFileSync(path.join(stubDir, 'psql'), '#!/usr/bin/env bash\nexit 0\n');
|
|
51
|
+
chmodSync(path.join(stubDir, 'psql'), 0o755);
|
|
52
|
+
|
|
53
|
+
function migrate(args, overrides = {}) {
|
|
41
54
|
const env = { ...process.env, PGDATABASE: db, ...overrides };
|
|
42
55
|
delete env.INIT_CWD;
|
|
43
|
-
|
|
56
|
+
return execFileSync('bash', [MIGRATE, ...args], {
|
|
44
57
|
cwd: REPO_ROOT, env, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'],
|
|
45
58
|
});
|
|
46
|
-
return out.trim().split(/\s+/).filter(Boolean);
|
|
47
59
|
}
|
|
60
|
+
const printModules = (overrides) => migrate(['--print-modules'], overrides).trim().split(/\s+/).filter(Boolean);
|
|
61
|
+
const fullRunWithStubPsql = () => migrate([], { PATH: `${stubDir}${path.delimiter}${process.env.PATH}` });
|
|
48
62
|
|
|
49
|
-
const setOverride = (enabled) => pool.query(
|
|
63
|
+
const setOverride = (key, enabled) => pool.query(
|
|
50
64
|
`INSERT INTO module_enablement_overrides (scope, module_key, enabled) VALUES ($1, $2, $3)
|
|
51
65
|
ON CONFLICT (scope, module_key) DO UPDATE SET enabled = EXCLUDED.enabled`,
|
|
52
|
-
[scope,
|
|
66
|
+
[scope, key, enabled],
|
|
67
|
+
);
|
|
68
|
+
const clearOverride = (key) => pool.query(
|
|
69
|
+
'DELETE FROM module_enablement_overrides WHERE scope = $1 AND module_key = $2', [scope, key],
|
|
53
70
|
);
|
|
54
71
|
|
|
55
72
|
const { rows: prior } = await pool.query(
|
|
56
|
-
'SELECT enabled, set_by, set_at FROM module_enablement_overrides WHERE scope = $1 AND module_key = $2',
|
|
57
|
-
[scope, MODULE],
|
|
73
|
+
'SELECT module_key, enabled, set_by, set_at FROM module_enablement_overrides WHERE scope = $1 AND module_key = ANY($2)',
|
|
74
|
+
[scope, [MODULE, AGENTS]],
|
|
58
75
|
);
|
|
59
76
|
|
|
60
77
|
try {
|
|
61
|
-
await
|
|
78
|
+
await clearOverride(MODULE);
|
|
79
|
+
await clearOverride(AGENTS);
|
|
62
80
|
const packs = printModules();
|
|
63
81
|
assert.ok(packs.length > 0, 'with no override the pack set still resolves (not an empty read)');
|
|
64
|
-
|
|
82
|
+
for (const key of [MODULE, AGENTS]) {
|
|
83
|
+
assert.ok(!packs.includes(key), `precondition: ${key} is off in the packs, so only an override can turn it on`);
|
|
84
|
+
}
|
|
65
85
|
console.log(` ok no override: ${MODULE} is not migrated`);
|
|
66
86
|
|
|
67
|
-
await setOverride(true);
|
|
87
|
+
await setOverride(MODULE, true);
|
|
68
88
|
const toggled = printModules();
|
|
69
89
|
assert.ok(toggled.includes(MODULE), `a hall toggle ON must reach migrate's module set, got: ${toggled.join(' ')}`);
|
|
70
90
|
assert.deepEqual(toggled.filter((m) => m !== MODULE), packs, 'and changes nothing else');
|
|
@@ -75,17 +95,32 @@ try {
|
|
|
75
95
|
const unreadable = printModules({ PGHOST: '127.0.0.1', PGPORT: '1' });
|
|
76
96
|
assert.deepEqual(unreadable, packs, 'an unreachable override database resolves exactly the pack set');
|
|
77
97
|
console.log(' ok unreadable overrides fall back to the packs');
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
DO UPDATE SET enabled = EXCLUDED.enabled, set_by = EXCLUDED.set_by, set_at = EXCLUDED.set_at`,
|
|
85
|
-
[scope, MODULE, prior[0].enabled, prior[0].set_by, prior[0].set_at],
|
|
86
|
-
);
|
|
98
|
+
|
|
99
|
+
// The reconcile itself is real: where its table exists it would write registry rows this test
|
|
100
|
+
// cannot cleanly undo, so it only runs where the sync fails harmlessly (the lane: agents is off).
|
|
101
|
+
const { rows: [{ reg }] } = await pool.query("SELECT to_regclass('agents_definitions') AS reg");
|
|
102
|
+
if (reg) {
|
|
103
|
+
console.log(` SKIP ${AGENTS} reconcile case — agents_definitions exists here, and a full run would write into it`);
|
|
87
104
|
} else {
|
|
88
|
-
|
|
105
|
+
assert.ok(!fullRunWithStubPsql().includes(RECONCILE_LINE), `${AGENTS} off: the post-deploy reconcile stays silent`);
|
|
106
|
+
await setOverride(AGENTS, true);
|
|
107
|
+
assert.ok(fullRunWithStubPsql().includes(RECONCILE_LINE), `a hall toggle ON for ${AGENTS} must reach the post-deploy reconcile`);
|
|
108
|
+
console.log(` ok override on: the ${AGENTS} registry reconcile runs`);
|
|
109
|
+
}
|
|
110
|
+
} finally {
|
|
111
|
+
for (const key of [MODULE, AGENTS]) {
|
|
112
|
+
const row = prior.find((r) => r.module_key === key);
|
|
113
|
+
if (row) {
|
|
114
|
+
await pool.query(
|
|
115
|
+
`INSERT INTO module_enablement_overrides (scope, module_key, enabled, set_by, set_at)
|
|
116
|
+
VALUES ($1, $2, $3, $4, $5)
|
|
117
|
+
ON CONFLICT (scope, module_key)
|
|
118
|
+
DO UPDATE SET enabled = EXCLUDED.enabled, set_by = EXCLUDED.set_by, set_at = EXCLUDED.set_at`,
|
|
119
|
+
[scope, key, row.enabled, row.set_by, row.set_at],
|
|
120
|
+
);
|
|
121
|
+
} else {
|
|
122
|
+
await clearOverride(key);
|
|
123
|
+
}
|
|
89
124
|
}
|
|
90
125
|
await pool.end().catch(() => {});
|
|
91
126
|
}
|