@bongos/core 1.19.514 → 1.19.515

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.
@@ -0,0 +1,337 @@
1
+ // modules/lifecycle/mingle.js — mingle: two switches, cross-craft, declinable
2
+ // without penalty (task 1003177 / C07, goal 1000075; criterion
3
+ // collab-mingle-two-switches, ADR 0187 §5).
4
+ //
5
+ // THE DECISION. Mingle introduces two builders who do NOT share a craft. The
6
+ // owner's reasoning (ADR 0187 §5) is the goal's founding premise — the person you
7
+ // need is often not another one of you — and it is also what keeps mingle doing
8
+ // something the craft-matched Collab request path does not already do.
9
+ // Same-craft pairing was considered and REJECTED as duplicating
10
+ // collab-page-matches-my-craft; do not "improve" the matcher by adding it back.
11
+ //
12
+ // TWO SWITCHES, AND ONE IS NOT CONSENT. A pair happens only when the PROJECT has
13
+ // enabled mingle AND the individual has opted in. Auto-pairing a person with a
14
+ // stranger a few times a week is a real-world social commitment, so the project
15
+ // enabling it for everyone is not the person agreeing to it, and a person opting
16
+ // in on an instance that never turned it on is not the project offering it. Both
17
+ // are read on every pairing, and both FAIL CLOSED: absent is "no", never
18
+ // "hasn't said no yet" (the ADR 0171 posture, inherited).
19
+ //
20
+ // DECLINING IS FREE, AND THAT IS A PROPERTY OF THE READ, NOT A PROMISE.
21
+ // "Without penalty" means declining affects no rank, no karma, no streak and no
22
+ // future matching weight — and the criterion insists that be verifiable rather
23
+ // than stated. Two things make it so, and both are structural:
24
+ //
25
+ // 1. `decline()` writes ONE row in ONE table — the pair it is settling. It
26
+ // touches no credit, karma, rank or streak surface, and there is no counter
27
+ // anywhere to touch (see lifecycle_007_mingle.sql, which says the same thing
28
+ // about the schema).
29
+ // 2. `eligibleBuilders()` — the matcher's ONLY input about who may be paired —
30
+ // never reads lifecycle_mingle_pairs at all. A decline therefore cannot make
31
+ // the decliner less likely to be paired again, because the read that decides
32
+ // that has no way to see it. The one thing pair history does gate is a second
33
+ // OPEN proposal for the same two people, which is the unique index's job and
34
+ // is about not double-introducing, not about declines.
35
+ //
36
+ // tests/mingle.mjs drives both against a recording pool and fails if either stops
37
+ // being true.
38
+ //
39
+ // THE CRAFT VOCABULARY IS NOT REDEFINED HERE. help-requests.js declares itself the
40
+ // one place that knows how a craft maps to `builders.preferred_disciplines`
41
+ // ('builder' the craft is 'engineer' the discipline), so this file consumes
42
+ // `craftMapSql` / `craftForDiscipline` from it rather than re-deriving. Two
43
+ // spellings of the same craft would silently match nobody.
44
+ //
45
+ // Reaches core only through the doorway (ADR 0083). The core tables it reads
46
+ // (builders) are read-only here.
47
+
48
+ 'use strict';
49
+
50
+ const api = require('../../src/module-api');
51
+ const { pool } = api;
52
+ const { craftMapSql } = require('./help-requests');
53
+
54
+ // The PROJECT switch. A module-owned knob in the project's own store
55
+ // (project_settings, migration core_231) — deliberately NOT a second settings
56
+ // table, which is the thing src/bongos/project-settings.js exists to prevent, and
57
+ // deliberately not registered in that file's core SETTING_KEYS: the key is
58
+ // namespaced to this surface, and a module's knob is the module's to name.
59
+ const MINGLE_ENABLED_KEY = 'mingle.enabled';
60
+
61
+ const MAX_ROWS = 100;
62
+
63
+ // THE MATCHING RULE, RECORDED. The criterion asks for cross-craft to be "chosen
64
+ // deliberately and recorded", so the rule is data a reader can fetch (the route
65
+ // serves this verbatim) rather than a shape you have to infer from the SQL — the
66
+ // same reason closeness-weights.json exists.
67
+ const MATCHING = Object.freeze({
68
+ rule: 'cross_craft',
69
+ description:
70
+ 'A pair is two builders whose crafts do not overlap at all — an engineer with '
71
+ + 'an artist or an ideator, never two of the same. The premise is that the '
72
+ + 'person you need is often not another one of you.',
73
+ // Stated because it is the road not taken, and an unexplained absence reads as
74
+ // an oversight to the next person holding the matcher.
75
+ rejected: 'same_craft — it duplicates the craft-matched Collab request path (criterion collab-page-matches-my-craft).',
76
+ // DISJOINT, not merely "different". A builder who is both an artist and an
77
+ // engineer shares a craft with every engineer, so pairing them would put two of
78
+ // the same in a room and call it cross-craft.
79
+ overlap: 'none',
80
+ consent: 'Both switches required: the project enables mingle AND the builder opts in. Either off means no pair.',
81
+ decline: 'Terminal and free — no rank, karma, streak or matching effect. The eligibility read never sees pair history.',
82
+ });
83
+
84
+ function matchingModel() { return MATCHING; }
85
+
86
+ // ---------------------------------------------------------------------------
87
+ // Switch 1 — the project
88
+ // ---------------------------------------------------------------------------
89
+
90
+ // TRUE only for an explicit, recognised yes. Everything else — absent, blank,
91
+ // 'maybe', a value that was valid before someone tightened this — is NO.
92
+ //
93
+ // This is the one place mingle deliberately DIVERGES from the rot timer's posture
94
+ // in src/bongos/project-settings.js. That file reports a bad value on the screen
95
+ // of the person who can fix it, because all of its callers are read surfaces. This
96
+ // is a consent gate: an unreadable switch must not open, so it fails closed the
97
+ // way ADR 0171's consent state does. One enforces, one reports.
98
+ function parseEnabled(raw) {
99
+ if (raw == null) return false;
100
+ return ['true', '1', 'on', 'yes'].includes(String(raw).trim().toLowerCase());
101
+ }
102
+
103
+ async function projectEnabled(deps = {}) {
104
+ const get = deps.getSetting || api.projectSettings.get;
105
+ let row;
106
+ try {
107
+ row = await get(MINGLE_ENABLED_KEY);
108
+ } catch (_) {
109
+ // FAIL CLOSED. An unreadable switch is not permission.
110
+ return false;
111
+ }
112
+ return parseEnabled(row && row.value);
113
+ }
114
+
115
+ async function setProjectEnabled(enabled, builderId = null, deps = {}) {
116
+ const set = deps.setSetting || api.projectSettings.set;
117
+ await set(MINGLE_ENABLED_KEY, enabled ? 'true' : 'false', builderId);
118
+ return { key: MINGLE_ENABLED_KEY, enabled: !!enabled };
119
+ }
120
+
121
+ // ---------------------------------------------------------------------------
122
+ // Switch 2 — the builder
123
+ // ---------------------------------------------------------------------------
124
+
125
+ // null = never offered / never answered. Deliberately distinct from false, which
126
+ // is a deliberate withdrawal — a surface that cannot tell them apart cannot ask
127
+ // the right question.
128
+ async function optInState(builderId, deps = {}) {
129
+ const activePool = deps.pool || pool;
130
+ const { rows } = await activePool.query(
131
+ 'SELECT opted_in, updated_at FROM lifecycle_mingle_optin WHERE builder_id = $1',
132
+ [builderId]
133
+ );
134
+ if (!rows[0]) return { opted_in: null, updated_at: null };
135
+ return { opted_in: rows[0].opted_in === true, updated_at: rows[0].updated_at };
136
+ }
137
+
138
+ async function setOptIn(builderId, optedIn, deps = {}) {
139
+ const activePool = deps.pool || pool;
140
+ const { rows } = await activePool.query(
141
+ `INSERT INTO lifecycle_mingle_optin (builder_id, opted_in, updated_at)
142
+ VALUES ($1, $2, now())
143
+ ON CONFLICT (builder_id) DO UPDATE
144
+ SET opted_in = EXCLUDED.opted_in, updated_at = now()
145
+ RETURNING builder_id, opted_in, updated_at`,
146
+ [builderId, !!optedIn]
147
+ );
148
+ return rows[0];
149
+ }
150
+
151
+ // BOTH switches, resolved together, for one builder. The surface that asks "can I
152
+ // mingle" gets back which half is off, because "no" with no reason is a dead end
153
+ // for the person who could turn their own half on.
154
+ async function mingleStateFor(builderId, deps = {}) {
155
+ const [project, mine] = await Promise.all([projectEnabled(deps), optInState(builderId, deps)]);
156
+ return {
157
+ enabled: project && mine.opted_in === true,
158
+ project_enabled: project,
159
+ opted_in: mine.opted_in,
160
+ opted_in_at: mine.updated_at,
161
+ };
162
+ }
163
+
164
+ // ---------------------------------------------------------------------------
165
+ // The matcher
166
+ // ---------------------------------------------------------------------------
167
+
168
+ // Everyone the project may introduce right now: opted in, active, and carrying at
169
+ // least one craft.
170
+ //
171
+ // IT DOES NOT JOIN lifecycle_mingle_pairs, AND MUST NOT. This read is the whole of
172
+ // "who may be paired", so the moment it can see a decline, declining has a
173
+ // matching cost and the criterion is broken. See the header.
174
+ //
175
+ // A builder with no `preferred_disciplines` produces no rows through the unnest and
176
+ // is therefore absent — the correct fail-closed answer, and the same one
177
+ // help-requests gives: belonging to a craft is a claim about yourself the system
178
+ // should not assume on your behalf.
179
+ async function eligibleBuilders(deps = {}) {
180
+ const activePool = deps.pool || pool;
181
+ const { rows } = await activePool.query(
182
+ `SELECT b.id::text AS builder_id,
183
+ array_agg(DISTINCT ${craftMapSql('d')}) FILTER (WHERE ${craftMapSql('d')} IS NOT NULL) AS crafts
184
+ FROM lifecycle_mingle_optin o
185
+ JOIN builders b ON b.id = o.builder_id
186
+ CROSS JOIN LATERAL unnest(b.preferred_disciplines) AS d
187
+ WHERE o.opted_in = true
188
+ AND b.status = 'active'
189
+ GROUP BY b.id
190
+ ORDER BY b.id`
191
+ );
192
+ return rows
193
+ .map((r) => ({ builder_id: String(r.builder_id), crafts: (r.crafts || []).filter(Boolean).sort() }))
194
+ .filter((b) => b.crafts.length > 0);
195
+ }
196
+
197
+ // PURE. Is this pair legal? Disjoint craft sets — see MATCHING.overlap.
198
+ function isCrossCraft(craftsA, craftsB) {
199
+ const a = new Set(craftsA || []);
200
+ if (!a.size || !(craftsB || []).length) return false;
201
+ return !(craftsB || []).some((c) => a.has(c));
202
+ }
203
+
204
+ // PURE. Given eligible builders, produce cross-craft pairs — each builder in at
205
+ // most one pair. Greedy over a stable order so the same input always yields the
206
+ // same pairing (a matcher that shuffles cannot be tested, and cannot be explained
207
+ // to the person it introduced).
208
+ //
209
+ // `excludePairs` is the set of "lo:hi" keys that already hold an OPEN proposal. It
210
+ // is NOT decline history: settled pairs are absent from it and may be introduced
211
+ // again, because a decline that permanently separated two people would be a
212
+ // consequence, and declining is free.
213
+ function planPairs(eligible, { excludePairs = new Set(), limit = MAX_ROWS } = {}) {
214
+ const taken = new Set();
215
+ const out = [];
216
+ const list = [...eligible].sort((a, b) => String(a.builder_id).localeCompare(String(b.builder_id)));
217
+ for (let i = 0; i < list.length && out.length < limit; i++) {
218
+ const a = list[i];
219
+ if (taken.has(a.builder_id)) continue;
220
+ for (let j = i + 1; j < list.length; j++) {
221
+ const b = list[j];
222
+ if (taken.has(b.builder_id)) continue;
223
+ if (!isCrossCraft(a.crafts, b.crafts)) continue;
224
+ const pair = orderPair(a, b);
225
+ if (excludePairs.has(pairKey(pair.lo.builder_id, pair.hi.builder_id))) continue;
226
+ taken.add(a.builder_id); taken.add(b.builder_id);
227
+ out.push({
228
+ builder_lo: pair.lo.builder_id,
229
+ builder_hi: pair.hi.builder_id,
230
+ // One representative craft each. The sets are disjoint, so any pick
231
+ // differs — recording them is what lets a pair be audited later even if
232
+ // someone changes their disciplines afterwards.
233
+ craft_lo: pair.lo.crafts[0],
234
+ craft_hi: pair.hi.crafts[0],
235
+ });
236
+ break;
237
+ }
238
+ }
239
+ return out;
240
+ }
241
+
242
+ function orderPair(a, b) {
243
+ return String(a.builder_id).padStart(24, '0') <= String(b.builder_id).padStart(24, '0')
244
+ ? { lo: a, hi: b } : { lo: b, hi: a };
245
+ }
246
+
247
+ function pairKey(lo, hi) { return `${lo}:${hi}`; }
248
+
249
+ async function openPairKeys(deps = {}) {
250
+ const activePool = deps.pool || pool;
251
+ const { rows } = await activePool.query(
252
+ `SELECT builder_lo::text AS lo, builder_hi::text AS hi
253
+ FROM lifecycle_mingle_pairs WHERE status = 'proposed'`
254
+ );
255
+ return new Set(rows.map((r) => pairKey(String(r.lo), String(r.hi))));
256
+ }
257
+
258
+ // Introduce everyone who can be introduced, and write the pairs. Refuses outright
259
+ // when the PROJECT switch is off — the per-builder switch is already enforced by
260
+ // eligibleBuilders, which only ever returns people who opted in.
261
+ async function runMingleRound({ limit = MAX_ROWS } = {}, deps = {}) {
262
+ if (!(await projectEnabled(deps))) return { paired: [], skipped: 'project_disabled' };
263
+ const activePool = deps.pool || pool;
264
+ const [eligible, open] = await Promise.all([eligibleBuilders(deps), openPairKeys(deps)]);
265
+ const planned = planPairs(eligible, { excludePairs: open, limit });
266
+ if (!planned.length) return { paired: [], skipped: null };
267
+
268
+ // ONE insert for the whole round, not one per pair. The round is bounded to
269
+ // MAX_ROWS and runs rarely, so this is not a hot path — but a loop of awaited
270
+ // INSERTs is also a partial write when the tenth throws, and unnest() makes the
271
+ // round atomic for free. ON CONFLICT DO NOTHING lets the open-pair unique index
272
+ // drop a pair another round introduced a moment ago rather than failing all of
273
+ // them; RETURNING is therefore what was actually written, never what was planned.
274
+ const { rows } = await activePool.query(
275
+ `INSERT INTO lifecycle_mingle_pairs (builder_lo, builder_hi, craft_lo, craft_hi)
276
+ SELECT * FROM unnest($1::bigint[], $2::bigint[], $3::text[], $4::text[])
277
+ ON CONFLICT DO NOTHING
278
+ RETURNING id, builder_lo::text AS builder_lo, builder_hi::text AS builder_hi,
279
+ craft_lo, craft_hi, status, created_at`,
280
+ [
281
+ planned.map((p) => p.builder_lo),
282
+ planned.map((p) => p.builder_hi),
283
+ planned.map((p) => p.craft_lo),
284
+ planned.map((p) => p.craft_hi),
285
+ ]
286
+ );
287
+ return { paired: rows, skipped: null };
288
+ }
289
+
290
+ // The open introductions for one builder, either side of the pair.
291
+ async function openPairsFor(builderId, deps = {}) {
292
+ const activePool = deps.pool || pool;
293
+ const { rows } = await activePool.query(
294
+ `SELECT p.id, p.builder_lo::text AS builder_lo, p.builder_hi::text AS builder_hi,
295
+ p.craft_lo, p.craft_hi, p.status, p.created_at,
296
+ lo.github_login AS lo_login, lo.display_name AS lo_name,
297
+ hi.github_login AS hi_login, hi.display_name AS hi_name
298
+ FROM lifecycle_mingle_pairs p
299
+ JOIN builders lo ON lo.id = p.builder_lo
300
+ JOIN builders hi ON hi.id = p.builder_hi
301
+ WHERE p.status = 'proposed'
302
+ AND (p.builder_lo = $1 OR p.builder_hi = $1)
303
+ ORDER BY p.created_at DESC`,
304
+ [builderId]
305
+ );
306
+ return rows;
307
+ }
308
+
309
+ // Accept or decline an introduction you are part of.
310
+ //
311
+ // ONE ROW, ONE TABLE. There is nothing else to write, and that absence IS the
312
+ // "without penalty" guarantee — see the header and the migration. Do not add a
313
+ // counter, a cooldown, or a karma/credit call here.
314
+ async function decidePair(pairId, builderId, decision, deps = {}) {
315
+ const activePool = deps.pool || pool;
316
+ if (!['accepted', 'declined'].includes(decision)) return { error: 'bad_decision' };
317
+ const { rows } = await activePool.query(
318
+ `UPDATE lifecycle_mingle_pairs
319
+ SET status = $3, decided_by = $2, decided_at = now()
320
+ WHERE id = $1
321
+ AND status = 'proposed'
322
+ AND (builder_lo = $2 OR builder_hi = $2)
323
+ RETURNING id, builder_lo::text AS builder_lo, builder_hi::text AS builder_hi,
324
+ craft_lo, craft_hi, status, decided_by::text AS decided_by, decided_at`,
325
+ [pairId, builderId, decision]
326
+ );
327
+ if (!rows[0]) return { error: 'not_found' };
328
+ return { pair: rows[0] };
329
+ }
330
+
331
+ module.exports = {
332
+ MINGLE_ENABLED_KEY, MAX_ROWS, MATCHING, matchingModel,
333
+ parseEnabled, projectEnabled, setProjectEnabled,
334
+ optInState, setOptIn, mingleStateFor,
335
+ eligibleBuilders, isCrossCraft, planPairs, pairKey, openPairKeys,
336
+ runMingleRound, openPairsFor, decidePair,
337
+ };
@@ -21,6 +21,7 @@
21
21
  "help-requests",
22
22
  "recommendations",
23
23
  "closeness",
24
+ "mingle",
24
25
  "visuals",
25
26
  "kickoff-seed",
26
27
  "rot"
@@ -0,0 +1,116 @@
1
+ // modules/lifecycle/routes/mingle.js — the two switches, the introductions, and
2
+ // the decline (task 1003177 / C07, goal 1000075; criterion
3
+ // collab-mingle-two-switches, ADR 0187 §5).
4
+ //
5
+ // FIVE ROUTES, AND THE SHAPE IS THE POINT:
6
+ // GET /mingle — where I stand: BOTH switches, my open
7
+ // introductions, and the matching rule itself.
8
+ // PUT /mingle/opt-in — MY half of consent. Own-scoped, any-builder.
9
+ // PUT /mingle/project — the PROJECT's half. `mingle.manage`.
10
+ // POST /mingle/round — run a pairing round. `mingle.manage`.
11
+ // POST /mingle/pairs/:id/decide — accept or decline an introduction I am in.
12
+ //
13
+ // WHY GET /mingle ANSWERS WITH BOTH SWITCHES RATHER THAN ONE BOOLEAN. "You cannot
14
+ // mingle" with no reason is a dead end for the one person who could fix half of
15
+ // it. A builder who has opted in on an instance that never enabled mingle should
16
+ // see that it is the project's half that is off, and not be told to change a
17
+ // setting they already set.
18
+ //
19
+ // THE OPERATOR GATE IS AN ATOM, NOT A RANK. `requireRank` in a modules/*/routes
20
+ // gate is what BV1.R105 exists to remove, and tests/government_require_permission
21
+ // fails the build on a new one — the two files still spelling it that way are
22
+ // documented holdouts, not a pattern to copy. So this mints `mingle.manage`
23
+ // (modules/government/catalog.js) and gates on it.
24
+ //
25
+ // FLOOR: metic, by the `discord.channels.manage` analogue — configuring a
26
+ // project-wide social surface — and not archon. What makes that safe is the OTHER
27
+ // switch: enabling mingle only OFFERS it, and can never pair a builder who has not
28
+ // personally opted in, so this gate cannot put anyone in a room with a stranger.
29
+ //
30
+ // THE DECLINE ROUTE COSTS THE DECLINER NOTHING, and there is deliberately nothing
31
+ // here that could make it cost: no counter to bump, no karma or credit call, no
32
+ // cooldown to write. See mingle.js and lifecycle_007_mingle.sql, which say the
33
+ // same thing about the read and the schema.
34
+ //
35
+ // Reaches core only through the doorway (ADR 0083).
36
+
37
+ 'use strict';
38
+
39
+ const express = require('express');
40
+ const api = require('../../../src/module-api');
41
+ const mingle = require('../mingle');
42
+
43
+ const { asyncHandler, validateOrRespond, parseId } = api;
44
+
45
+ module.exports = function buildMingleRouter() {
46
+ const router = express.Router();
47
+
48
+ // rank: any-builder, and OWN-SCOPED — your own state, never someone else's.
49
+ // Who else has opted in to being introduced is a fact about them.
50
+ router.get('/mingle', api.requireBuilder, asyncHandler('GET /mingle', async (req, res) => {
51
+ const [state, pairs] = await Promise.all([
52
+ mingle.mingleStateFor(req.builder.id),
53
+ mingle.openPairsFor(req.builder.id),
54
+ ]);
55
+ return res.json({
56
+ mingle: state,
57
+ open_pairs: pairs,
58
+ // Served VERBATIM from the module. The criterion asks for cross-craft to be
59
+ // chosen deliberately and RECORDED; this is where it is read, and a
60
+ // restatement here could drift from the matcher that actually runs.
61
+ matching: mingle.matchingModel(),
62
+ });
63
+ }, { errorCode: 'mingle_read_failed' }));
64
+
65
+ // rank: any-builder, OWN-SCOPED. Keyed by the SESSION, never a body field —
66
+ // consent you can give on someone else's behalf is not consent.
67
+ router.put('/mingle/opt-in', api.requireBuilder, asyncHandler('PUT /mingle/opt-in', async (req, res) => {
68
+ if (validateOrRespond(req, res, {
69
+ opted_in: { required: true, type: 'boolean' },
70
+ })) return;
71
+ const row = await mingle.setOptIn(req.builder.id, req.body.opted_in === true);
72
+ return res.json({ opted_in: row.opted_in, updated_at: row.updated_at });
73
+ }, { errorCode: 'mingle_optin_failed' }));
74
+
75
+ // perm: mingle.manage (floor metic) — see the header. Offering the feature to
76
+ // the project is an operator act; it still cannot pair anyone who has not
77
+ // opted themselves in.
78
+ router.put('/mingle/project', api.requireBuilder, api.requirePermission('mingle.manage'), asyncHandler('PUT /mingle/project', async (req, res) => {
79
+ if (validateOrRespond(req, res, {
80
+ enabled: { required: true, type: 'boolean' },
81
+ })) return;
82
+ const out = await mingle.setProjectEnabled(req.body.enabled === true, req.builder.id);
83
+ return res.json(out);
84
+ }, { errorCode: 'mingle_project_switch_failed' }));
85
+
86
+ // perm: mingle.manage — running a round writes introductions for other people,
87
+ // so it is an operator action rather than something a builder does to themselves.
88
+ // Refuses on its own when the project switch is off (runMingleRound checks).
89
+ router.post('/mingle/round', api.requireBuilder, api.requirePermission('mingle.manage'), asyncHandler('POST /mingle/round', async (req, res) => {
90
+ if (validateOrRespond(req, res, {
91
+ limit: { type: 'integer', min: 1, max: mingle.MAX_ROWS },
92
+ })) return;
93
+ const out = await mingle.runMingleRound({ limit: req.body.limit || mingle.MAX_ROWS });
94
+ return res.json({ paired: out.paired, count: out.paired.length, skipped: out.skipped });
95
+ }, { errorCode: 'mingle_round_failed' }));
96
+
97
+ // rank: any-builder. The UPDATE itself requires the caller to be one of the two
98
+ // people in the pair, so a builder cannot answer an introduction they are not
99
+ // part of — enforced in SQL, not by a check here that a later caller could skip.
100
+ router.post('/mingle/pairs/:id/decide', api.requireBuilder, asyncHandler('POST /mingle/pairs/:id/decide', async (req, res) => {
101
+ const pairId = parseId(req, res, { param: 'id', code: 'bad_pair_id', positiveInt: true });
102
+ if (pairId === null) return;
103
+ if (validateOrRespond(req, res, {
104
+ decision: { required: true, type: 'string', enum: ['accepted', 'declined'] },
105
+ })) return;
106
+
107
+ const out = await mingle.decidePair(pairId, req.builder.id, req.body.decision);
108
+ if (out.error === 'bad_decision') return res.fail(400, 'bad_decision', 'decision must be accepted or declined');
109
+ // ONE answer for "no such pair", "already settled" and "not yours". Telling
110
+ // them apart would let a caller probe which pair ids exist and who is in them.
111
+ if (out.error) return res.fail(404, 'pair_not_found', 'no open introduction with that id for you');
112
+ return res.json({ pair: out.pair });
113
+ }, { errorCode: 'mingle_decide_failed' }));
114
+
115
+ return router;
116
+ };
package/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@bongos/core",
3
- "version": "1.19.514",
3
+ "version": "1.19.515",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@bongos/core",
9
- "version": "1.19.514",
9
+ "version": "1.19.515",
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.514",
3
+ "version": "1.19.515",
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",
package/src/module-api.js CHANGED
@@ -45,7 +45,7 @@ const { validateOrRespond, LIMITS, parseId, asyncHandler, corsPublicGet, parsePa
45
45
  // there. scripts/gds/bump-version.js still rewrites the literal below; it appends
46
46
  // the entry to that file. Look for a version's history there, not here.
47
47
  // ---------------------------------------------------------------------------
48
- const CORE_VERSION = '1.19.514'; // CI auto-patch carrier (ADR 0161); changelog: docs/module-api-changelog.md
48
+ const CORE_VERSION = '1.19.515'; // CI auto-patch carrier (ADR 0161); changelog: docs/module-api-changelog.md
49
49
 
50
50
  // A namespaced logger so a module's log lines are attributable + consistent.
51
51
  // Usage: const log = api.logger('dev-box'); log.info('mounted');
@@ -182,3 +182,38 @@ test('migration objects are all governance_-namespaced (ADR 0083 §5)', () => {
182
182
  }
183
183
  }
184
184
  });
185
+
186
+ // THE GAP THE DRIFT GUARD ABOVE CANNOT SEE (found by the task 1003177 grader).
187
+ //
188
+ // The union model is a regex over `SELECT '<rank>', unnest(ARRAY[…])`. It reads
189
+ // the KEYS and never looks at the table those keys are inserted INTO — so a new
190
+ // grant migration copied from a `governance_*` sibling passes it while writing to
191
+ // `governance_role_permissions (role_key, …)`, the PRE-rename names.
192
+ //
193
+ // government_001_rename_from_governance renamed that table to
194
+ // `government_rank_permissions` and its `role_key` column to `rank_key`, with no
195
+ // compatibility shim. Migrations apply in filename order, so on any database —
196
+ // a fresh install included — a `government_*`-prefixed file writes AFTER the
197
+ // rename and must use the new names or error at apply time. The permission would
198
+ // then never resolve, and its routes would 403 for every rank, Archon included.
199
+ //
200
+ // Scoped to the `government_`-prefixed files on purpose: the historical
201
+ // `governance_*` migrations legitimately name the pre-rename tables (they ran
202
+ // before the rename, and renaming an applied migration re-runs it — the standing
203
+ // rule in modules/government/CLAUDE.md).
204
+ test('a post-rename grant migration writes to the RENAMED table, not the old one', () => {
205
+ const postRename = grantSqlByFile.filter(([f]) => f.startsWith('government_'));
206
+ assert.ok(postRename.length > 0, 'there is at least one government_-prefixed grant migration');
207
+
208
+ for (const [file, sql] of postRename) {
209
+ const ddl = sql.replace(/^\s*--.*$/gm, ''); // a comment may CITE the old name
210
+ assert.ok(!/governance_role_permissions/.test(ddl),
211
+ `${file}: writes to governance_role_permissions — renamed to government_rank_permissions by government_001`);
212
+ assert.ok(!/\brole_key\b/.test(ddl),
213
+ `${file}: names the role_key column — renamed to rank_key by government_001`);
214
+ if (/INSERT INTO/.test(ddl)) {
215
+ assert.match(ddl, /INSERT INTO government_rank_permissions \(rank_key, permission_key\)/,
216
+ `${file}: a grant insert must target government_rank_permissions (rank_key, permission_key)`);
217
+ }
218
+ }
219
+ });