@lifeaitools/rdc-skills 0.24.6 → 0.24.7
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/git-sha.json +1 -1
- package/hooks/task-completed-gate.js +25 -3
- package/package.json +1 -1
- package/tests/harness-gates.test.mjs +30 -0
package/git-sha.json
CHANGED
|
@@ -21,7 +21,11 @@
|
|
|
21
21
|
*
|
|
22
22
|
* Flag (default OFF), either enables it:
|
|
23
23
|
* - env RDC_TRUTHGATE_TASKCOMPLETED in {1,true,on,yes}, OR
|
|
24
|
-
* - DB public.truthgate_flags(flag='taskcompleted', enabled=true)
|
|
24
|
+
* - DB public.truthgate_flags(flag='taskcompleted', enabled=true) — but the
|
|
25
|
+
* DB check is OPT-IN: it only runs when RDC_TRUTHGATE_TASKCOMPLETED_DB
|
|
26
|
+
* is in {1,true,on,yes}. This keeps the default-OFF path ZERO-COST: an
|
|
27
|
+
* unset env flag returns false with NO Supabase/clauth round-trip, so a
|
|
28
|
+
* dormant gate never makes a network call on every TaskCompleted.
|
|
25
29
|
*
|
|
26
30
|
* Offline test seam: when RDC_TASKCOMPLETED_CLOSURE_SINK points at a JSON file,
|
|
27
31
|
* the hook reads the closure row from that file instead of Supabase. This lets
|
|
@@ -74,6 +78,17 @@ function flagEnabledEnv() {
|
|
|
74
78
|
return v === '1' || v === 'true' || v === 'on' || v === 'yes';
|
|
75
79
|
}
|
|
76
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Is the optional DB flag check opted into? Default OFF (returns false).
|
|
83
|
+
* The DB check is a Supabase/clauth round-trip; gating it behind this explicit
|
|
84
|
+
* env opt-in keeps the default-OFF path zero-cost (no network on every
|
|
85
|
+
* TaskCompleted). Only when this is set do we consult truthgate_flags.
|
|
86
|
+
*/
|
|
87
|
+
function flagDbOptIn() {
|
|
88
|
+
const v = String(process.env.RDC_TRUTHGATE_TASKCOMPLETED_DB || '').trim().toLowerCase();
|
|
89
|
+
return v === '1' || v === 'true' || v === 'on' || v === 'yes';
|
|
90
|
+
}
|
|
91
|
+
|
|
77
92
|
async function getServiceKey() {
|
|
78
93
|
if (process.env.SUPABASE_SERVICE_ROLE_KEY) return process.env.SUPABASE_SERVICE_ROLE_KEY;
|
|
79
94
|
if (process.env.SUPABASE_SERVICE_KEY) return process.env.SUPABASE_SERVICE_KEY;
|
|
@@ -202,8 +217,14 @@ async function main() {
|
|
|
202
217
|
let raw;
|
|
203
218
|
try { raw = JSON.parse(await readStdin()); } catch { process.exit(0); }
|
|
204
219
|
|
|
205
|
-
// Default-OFF: a no-op until the flag is flipped at deploy.
|
|
206
|
-
|
|
220
|
+
// Default-OFF: a no-op until the flag is flipped at deploy. The env flag is
|
|
221
|
+
// checked first and short-circuits — when it is unset, the DB check runs ONLY
|
|
222
|
+
// if explicitly opted in via RDC_TRUTHGATE_TASKCOMPLETED_DB, so the dormant
|
|
223
|
+
// path is zero-cost (no Supabase/clauth round-trip on every TaskCompleted).
|
|
224
|
+
let enabled = flagEnabledEnv();
|
|
225
|
+
if (!enabled && flagDbOptIn()) {
|
|
226
|
+
enabled = await flagEnabledDb().catch(() => false);
|
|
227
|
+
}
|
|
207
228
|
if (!enabled) return pass({ reason: 'flag-off' });
|
|
208
229
|
|
|
209
230
|
// FAIL-CLOSED from here: any inability to confirm a sound closure is a BLOCK.
|
|
@@ -245,6 +266,7 @@ if (require.main === module) {
|
|
|
245
266
|
} else {
|
|
246
267
|
module.exports = {
|
|
247
268
|
flagEnabledEnv,
|
|
269
|
+
flagDbOptIn,
|
|
248
270
|
extractWorkItemId,
|
|
249
271
|
closureIsSound,
|
|
250
272
|
WITNESS_ALLOWLIST,
|
package/package.json
CHANGED
|
@@ -78,12 +78,42 @@ const WI = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee';
|
|
|
78
78
|
else process.env.RDC_TRUTHGATE_TASKCOMPLETED = prev;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
// pure: flagDbOptIn default OFF, ON via env
|
|
82
|
+
{
|
|
83
|
+
const prev = process.env.RDC_TRUTHGATE_TASKCOMPLETED_DB;
|
|
84
|
+
delete process.env.RDC_TRUTHGATE_TASKCOMPLETED_DB;
|
|
85
|
+
assert('TCG DB-opt-in default OFF', tcg.flagDbOptIn() === false);
|
|
86
|
+
process.env.RDC_TRUTHGATE_TASKCOMPLETED_DB = 'on';
|
|
87
|
+
assert('TCG DB-opt-in ON via env', tcg.flagDbOptIn() === true);
|
|
88
|
+
if (prev === undefined) delete process.env.RDC_TRUTHGATE_TASKCOMPLETED_DB;
|
|
89
|
+
else process.env.RDC_TRUTHGATE_TASKCOMPLETED_DB = prev;
|
|
90
|
+
}
|
|
91
|
+
|
|
81
92
|
// process: flag OFF → no-op (exit 0, no block)
|
|
82
93
|
{
|
|
83
94
|
const r = runHook('task-completed-gate.js', { work_item_id: WI }, { RDC_TRUTHGATE_TASKCOMPLETED: '' });
|
|
84
95
|
assert('TCG flag OFF → exit 0 no-op', r.status === 0, `status=${r.status} ${r.stderr}`);
|
|
85
96
|
}
|
|
86
97
|
|
|
98
|
+
// process: flag OFF + DB-opt-in unset → ZERO-COST OFF path makes NO DB call.
|
|
99
|
+
// Point Supabase + the clauth daemon at a non-routable, slow-to-fail address.
|
|
100
|
+
// If the OFF path consulted the DB, the call would stall near the hook's
|
|
101
|
+
// Supabase timeout (~3.5s) / clauth timeout (~2s). The run completing far
|
|
102
|
+
// under that floor proves no round-trip was attempted.
|
|
103
|
+
{
|
|
104
|
+
const t0 = Date.now();
|
|
105
|
+
const r = runHook('task-completed-gate.js', { work_item_id: WI }, {
|
|
106
|
+
RDC_TRUTHGATE_TASKCOMPLETED: '',
|
|
107
|
+
RDC_TRUTHGATE_TASKCOMPLETED_DB: '', // DB check NOT opted into
|
|
108
|
+
SUPABASE_URL: 'http://10.255.255.1', // non-routable: any call would hang
|
|
109
|
+
SUPABASE_SERVICE_ROLE_KEY: 'x', // a key IS present, so only the opt-in gate keeps us off the network
|
|
110
|
+
});
|
|
111
|
+
const elapsed = Date.now() - t0;
|
|
112
|
+
assert('TCG OFF path → exit 0', r.status === 0, `status=${r.status} ${r.stderr}`);
|
|
113
|
+
assert('TCG OFF path makes no DB call (returns well under the network-timeout floor)',
|
|
114
|
+
elapsed < 1500, `elapsed=${elapsed}ms (a DB round-trip would approach the ~3.5s timeout)`);
|
|
115
|
+
}
|
|
116
|
+
|
|
87
117
|
// process: flag ON + no closure ref → BLOCK (exit 2)
|
|
88
118
|
{
|
|
89
119
|
const r = runHook('task-completed-gate.js', { task: { note: 'no uuid here' } },
|