@lifeaitools/rdc-skills 0.24.42 → 0.25.0
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/.claude/settings.json +15 -15
- package/.claude-plugin/marketplace.json +21 -21
- package/.claude-plugin/plugin.json +1518 -1371
- package/.github/workflows/publish.yml +34 -34
- package/.github/workflows/self-test.yml +58 -58
- package/CHANGELOG.md +310 -310
- package/LICENSE +21 -21
- package/MANIFEST.md +221 -221
- package/README.md +375 -376
- package/README.sandbox.md +3 -3
- package/assets/watcher/viewer.html +164 -164
- package/bin/rdc-skills-mcp.mjs +316 -316
- package/commands/build.md +183 -183
- package/commands/collab.md +180 -180
- package/commands/deploy.md +152 -152
- package/commands/design.md +31 -31
- package/commands/edit.md +28 -28
- package/commands/fixit.md +150 -124
- package/commands/handoff.md +173 -173
- package/commands/help.md +95 -95
- package/commands/overnight.md +220 -220
- package/commands/plan.md +158 -158
- package/commands/preplan.md +131 -131
- package/commands/prototype.md +145 -145
- package/commands/release.md +49 -49
- package/commands/report.md +99 -99
- package/commands/review.md +120 -120
- package/commands/self-test.md +113 -113
- package/commands/status.md +86 -86
- package/commands/watch.md +98 -98
- package/commands/workitems.md +137 -137
- package/git-sha.json +1 -1
- package/guides/agent-bootstrap.md +295 -295
- package/guides/agents/backend.md +104 -104
- package/guides/agents/content.md +94 -94
- package/guides/agents/cs2.md +56 -56
- package/guides/agents/data.md +87 -87
- package/guides/agents/design.md +77 -77
- package/guides/agents/frontend.md +92 -92
- package/guides/agents/infrastructure.md +81 -81
- package/guides/agents/setup.md +281 -281
- package/guides/agents/verify.md +151 -151
- package/guides/agents/viz.md +106 -106
- package/guides/backend.md +146 -146
- package/guides/content.md +147 -147
- package/guides/cs2.md +190 -190
- package/guides/data.md +123 -123
- package/guides/design.md +116 -116
- package/guides/engineering-behavior.md +43 -43
- package/guides/escalation-protocol.md +125 -125
- package/guides/frontend.md +151 -151
- package/guides/history-md-spec.md +297 -297
- package/guides/infrastructure.md +179 -179
- package/guides/lessons-learned-spec.md +145 -151
- package/guides/output-contract.md +108 -108
- package/guides/publish-md-spec.md +289 -289
- package/guides/rdc-skills-startup.md +30 -30
- package/guides/verify.md +11 -11
- package/hooks/check-cwd.js +31 -31
- package/hooks/check-rdc-environment.js +164 -164
- package/hooks/check-services.js +6 -6
- package/hooks/check-stale-work-items.js +19 -19
- package/hooks/foreground-process-gate.js +128 -128
- package/hooks/gate-watchdog-selfcheck.js +257 -257
- package/hooks/hook-logger.js +25 -25
- package/hooks/lib/run-evidence-gate.mjs +241 -241
- package/hooks/no-stop-open-epics.js +127 -127
- package/hooks/post-tool-batch-gate.js +203 -203
- package/hooks/post-work-check.js +21 -21
- package/hooks/postcompact-log.js +13 -13
- package/hooks/precompact-log.js +13 -13
- package/hooks/rate-limit-retry.js +46 -46
- package/hooks/rdc-invocation-marker.js +157 -157
- package/hooks/rdc-output-contract-gate.js +94 -94
- package/hooks/require-work-item-on-commit.js +294 -294
- package/hooks/restart-brief.js +19 -19
- package/hooks/run-hidden-hook.ps1 +47 -47
- package/hooks/task-completed-gate.js +274 -274
- package/hooks/work-item-exit-gate.js +944 -944
- package/lib/catalog.mjs +236 -236
- package/lib/cloud-rewrite.mjs +155 -155
- package/package.json +57 -57
- package/rules/work-items-rpc.md +520 -520
- package/scaffold/templates/HISTORY.md.template +39 -39
- package/scaffold/templates/PUBLISH.md.template +21 -21
- package/scaffold/templates/brochure-studio-default.html +70 -70
- package/scripts/acceptance.mjs +502 -502
- package/scripts/fixtures/guides/bad-guide.md +15 -15
- package/scripts/fixtures/guides-clean/good-guide.md +16 -16
- package/scripts/install-rdc-skills.js +1289 -1289
- package/scripts/install.ps1 +202 -202
- package/scripts/install.sh +132 -132
- package/scripts/lib/assertions.mjs +287 -287
- package/scripts/lib/manifest-schema.mjs +754 -754
- package/scripts/lib/runner.mjs +465 -465
- package/scripts/lib/sandbox.mjs +435 -435
- package/scripts/prepack.mjs +32 -32
- package/scripts/rdc-brochure.mjs +482 -482
- package/scripts/rdc-design-cli.mjs +134 -134
- package/scripts/rebuild-mcp.mjs +107 -107
- package/scripts/self-test.mjs +1460 -1460
- package/scripts/stamp-git-sha.mjs +29 -29
- package/scripts/test-guide-validator.mjs +196 -196
- package/scripts/test-rdc-hooks.mjs +145 -145
- package/scripts/uninstall.ps1 +77 -77
- package/scripts/uninstall.sh +69 -69
- package/scripts/update.ps1 +43 -43
- package/scripts/update.sh +43 -43
- package/scripts/validate-place-histories.js +461 -461
- package/scripts/validate-publish-manifests.js +502 -424
- package/scripts/watch-init.mjs +100 -100
- package/skills/brochure/SKILL.md +107 -107
- package/skills/build/SKILL.md +563 -563
- package/skills/channel-formatter/SKILL.md +538 -533
- package/skills/co-develop/SKILL.md +196 -196
- package/skills/collab/SKILL.md +239 -239
- package/skills/convert/SKILL.md +167 -140
- package/skills/deploy/SKILL.md +541 -541
- package/skills/design/SKILL.md +211 -211
- package/skills/design/reference/ownership.md +16 -16
- package/skills/design/reference/rampa.md +92 -92
- package/skills/design/reference/studio-model.md +153 -153
- package/skills/edit/SKILL.md +98 -98
- package/skills/fixit/SKILL.md +203 -165
- package/skills/fs-mcp/SKILL.md +148 -148
- package/skills/handoff/SKILL.md +236 -236
- package/skills/help/SKILL.md +143 -143
- package/skills/housekeeping/SKILL.md +160 -219
- package/skills/lifeai-brochure-author/SKILL.md +340 -340
- package/skills/onramp/SKILL.md +248 -0
- package/skills/overnight/SKILL.md +251 -251
- package/skills/plan/SKILL.md +345 -345
- package/skills/preplan/SKILL.md +90 -90
- package/skills/prototype/SKILL.md +150 -150
- package/skills/rdc-brochurify/SKILL.md +245 -245
- package/skills/rdc-extract-verifier-rules/SKILL.md +191 -191
- package/skills/release/SKILL.md +140 -140
- package/skills/report/SKILL.md +100 -100
- package/skills/review/SKILL.md +152 -152
- package/skills/rpms-filemap/SKILL.cloud.md +111 -111
- package/skills/rpms-filemap/SKILL.md +111 -111
- package/skills/self-test/SKILL.md +132 -132
- package/skills/status/SKILL.md +99 -99
- package/skills/terminal-config/SKILL.md +62 -62
- package/skills/tests/MATRIX.md +54 -54
- package/skills/tests/README.md +47 -47
- package/skills/tests/onramp.test.json +87 -0
- package/skills/tests/rdc-brochure.test.json +34 -34
- package/skills/tests/rdc-build.test.json +36 -36
- package/skills/tests/rdc-channel-formatter.test.json +45 -45
- package/skills/tests/rdc-co-develop.test.json +29 -29
- package/skills/tests/rdc-collab.test.json +29 -29
- package/skills/tests/rdc-convert.test.json +35 -35
- package/skills/tests/rdc-deploy.test.json +30 -30
- package/skills/tests/rdc-design.test.json +27 -27
- package/skills/tests/rdc-edit.test.json +29 -29
- package/skills/tests/rdc-fixit.test.json +36 -36
- package/skills/tests/rdc-fs-mcp.test.json +36 -36
- package/skills/tests/rdc-handoff.test.json +28 -28
- package/skills/tests/rdc-help.test.json +29 -29
- package/skills/tests/rdc-housekeeping.test.json +28 -32
- package/skills/tests/rdc-lifeai-brochure-author.test.json +35 -35
- package/skills/tests/rdc-overnight.test.json +37 -37
- package/skills/tests/rdc-plan.test.json +27 -27
- package/skills/tests/rdc-preplan.test.json +31 -31
- package/skills/tests/rdc-prototype.test.json +28 -28
- package/skills/tests/rdc-rdc-brochurify.test.json +23 -23
- package/skills/tests/rdc-rdc-extract-verifier-rules.test.json +34 -34
- package/skills/tests/rdc-release.test.json +29 -29
- package/skills/tests/rdc-report.test.json +28 -28
- package/skills/tests/rdc-review.test.json +29 -29
- package/skills/tests/rdc-rpms-filemap.test.json +28 -28
- package/skills/tests/rdc-self-test.test.json +24 -24
- package/skills/tests/rdc-status.test.json +29 -29
- package/skills/tests/rdc-terminal-config.test.json +29 -29
- package/skills/tests/rdc-watch.test.json +24 -24
- package/skills/tests/rdc-workitems.test.json +27 -27
- package/skills/watch/SKILL.md +97 -97
- package/skills/workitems/SKILL.md +151 -151
- package/tests/acceptance.test.mjs +59 -59
- package/tests/channel-formatter.contract.test.mjs +251 -251
- package/tests/curl-surface.test.mjs +289 -289
- package/tests/harness-gates.test.mjs +325 -325
- package/tests/help-surface.test.mjs +61 -61
- package/tests/install-rdc-skills.test.mjs +49 -49
- package/tests/manifest-contract-fields.test.mjs +78 -78
- package/tests/mcp.test.mjs +271 -271
- package/tests/rdc-brochure.test.mjs +125 -125
- package/tests/require-work-item-on-commit.test.mjs +162 -162
- package/tests/run-evidence-gate.test.mjs +82 -82
- package/tests/skill-test-matrix.test.mjs +66 -66
- package/tests/validate-skills.js +27 -27
- package/tests/work-item-exit-gate-l2.test.mjs +368 -368
- package/tests/work-item-exit-gate-l3.test.mjs +197 -197
- package/RELEASE.md +0 -42
- package/tests/housekeeping-lessons-triage.test.mjs +0 -49
- package/tests/lessons-pipeline-contract.test.mjs +0 -27
- package/tests/release-contract.test.mjs +0 -16
|
@@ -1,325 +1,325 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Truth Gate 3.0 — Layers 5+6 harness-gate tests (WP-5).
|
|
4
|
-
*
|
|
5
|
-
* Covers the three new hooks, fully offline (no DB, no brain, no clauth):
|
|
6
|
-
* task-completed-gate.js — flag OFF no-op; flag ON + no/unsound closure BLOCK;
|
|
7
|
-
* flag ON + sound closure PASS.
|
|
8
|
-
* post-tool-batch-gate.js — flag OFF no-op; flag ON + stale worktree base FLAG;
|
|
9
|
-
* flag ON + current base PASS.
|
|
10
|
-
* gate-watchdog-selfcheck — STOP-banner when a gate file/registration absent;
|
|
11
|
-
* silent when all present; checks the LIVE hookify
|
|
12
|
-
* hooks.json (plugin manifest), not the dead wrappers.
|
|
13
|
-
*
|
|
14
|
-
* Run: node tests/harness-gates.test.mjs
|
|
15
|
-
*/
|
|
16
|
-
import { mkdtempSync, rmSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
17
|
-
import { tmpdir } from 'node:os';
|
|
18
|
-
import { join, resolve, dirname } from 'node:path';
|
|
19
|
-
import { fileURLToPath } from 'node:url';
|
|
20
|
-
import { spawnSync } from 'node:child_process';
|
|
21
|
-
import { createRequire } from 'node:module';
|
|
22
|
-
|
|
23
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
24
|
-
const REPO_ROOT = resolve(__dirname, '..');
|
|
25
|
-
const HOOKS = join(REPO_ROOT, 'hooks');
|
|
26
|
-
const require = createRequire(import.meta.url);
|
|
27
|
-
|
|
28
|
-
const failures = [];
|
|
29
|
-
function assert(name, condition, detail = '') {
|
|
30
|
-
if (!condition) failures.push(`${name}${detail ? `: ${detail}` : ''}`);
|
|
31
|
-
else process.stdout.write(` ok ${name}\n`);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function runHook(file, payload, extraEnv = {}) {
|
|
35
|
-
return spawnSync(process.execPath, [join(HOOKS, file)], {
|
|
36
|
-
input: JSON.stringify(payload),
|
|
37
|
-
encoding: 'utf8',
|
|
38
|
-
env: { ...process.env, ...extraEnv },
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const WI = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee';
|
|
43
|
-
|
|
44
|
-
// ===========================================================================
|
|
45
|
-
// 1. task-completed-gate.js
|
|
46
|
-
// ===========================================================================
|
|
47
|
-
{
|
|
48
|
-
const tcg = require(join(HOOKS, 'task-completed-gate.js'));
|
|
49
|
-
|
|
50
|
-
// pure: closureIsSound branches
|
|
51
|
-
assert('TCG closureIsSound: null row → not ok', tcg.closureIsSound(null).ok === false);
|
|
52
|
-
assert('TCG closureIsSound: not-done task → not ok',
|
|
53
|
-
tcg.closureIsSound({ id: WI, item_type: 'task', status: 'review' }).ok === false);
|
|
54
|
-
assert('TCG closureIsSound: done but witness:agent → not ok',
|
|
55
|
-
tcg.closureIsSound({ id: WI, item_type: 'task', status: 'done', implementation_report: { codeflow_post: { witness: 'agent', commit: 'x', files_changed: ['f'], verification: [{ exit_code: 0 }] } } }).ok === false);
|
|
56
|
-
const soundRow = {
|
|
57
|
-
id: WI, item_type: 'task', status: 'done',
|
|
58
|
-
implementation_report: { codeflow_post: { witness: 'validator-rerun', commit: 'c3189c9d58a37d648e9de4a6bcd7d46772053eea', files_changed: ['hooks/x.js'], verification: [{ exit_code: 0 }] } },
|
|
59
|
-
};
|
|
60
|
-
assert('TCG closureIsSound: full sound closure → ok', tcg.closureIsSound(soundRow).ok === true,
|
|
61
|
-
tcg.closureIsSound(soundRow).reason || '');
|
|
62
|
-
assert('TCG closureIsSound: epic done → ok',
|
|
63
|
-
tcg.closureIsSound({ id: WI, item_type: 'epic', status: 'done' }).ok === true);
|
|
64
|
-
|
|
65
|
-
// pure: extractWorkItemId
|
|
66
|
-
assert('TCG extractWorkItemId: from field', tcg.extractWorkItemId({ work_item_id: WI }) === WI);
|
|
67
|
-
assert('TCG extractWorkItemId: from blob', tcg.extractWorkItemId({ task: { note: `closes ${WI}` } }) === WI);
|
|
68
|
-
assert('TCG extractWorkItemId: none → null', tcg.extractWorkItemId({ task: { note: 'no uuid' } }) === null);
|
|
69
|
-
|
|
70
|
-
// pure: flagEnabledEnv default OFF
|
|
71
|
-
{
|
|
72
|
-
const prev = process.env.RDC_TRUTHGATE_TASKCOMPLETED;
|
|
73
|
-
delete process.env.RDC_TRUTHGATE_TASKCOMPLETED;
|
|
74
|
-
assert('TCG flag default OFF', tcg.flagEnabledEnv() === false);
|
|
75
|
-
process.env.RDC_TRUTHGATE_TASKCOMPLETED = 'true';
|
|
76
|
-
assert('TCG flag ON via env', tcg.flagEnabledEnv() === true);
|
|
77
|
-
if (prev === undefined) delete process.env.RDC_TRUTHGATE_TASKCOMPLETED;
|
|
78
|
-
else process.env.RDC_TRUTHGATE_TASKCOMPLETED = prev;
|
|
79
|
-
}
|
|
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
|
-
|
|
92
|
-
// process: flag OFF → no-op (exit 0, no block)
|
|
93
|
-
{
|
|
94
|
-
const r = runHook('task-completed-gate.js', { work_item_id: WI }, { RDC_TRUTHGATE_TASKCOMPLETED: '' });
|
|
95
|
-
assert('TCG flag OFF → exit 0 no-op', r.status === 0, `status=${r.status} ${r.stderr}`);
|
|
96
|
-
}
|
|
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
|
-
|
|
117
|
-
// process: flag ON + no closure ref → BLOCK (exit 2)
|
|
118
|
-
{
|
|
119
|
-
const r = runHook('task-completed-gate.js', { task: { note: 'no uuid here' } },
|
|
120
|
-
{ RDC_TRUTHGATE_TASKCOMPLETED: '1' });
|
|
121
|
-
assert('TCG flag ON + no work-item ref → exit 2 BLOCK', r.status === 2, `status=${r.status}`);
|
|
122
|
-
assert('TCG block mentions no work-item reference', /no work-item reference/.test(r.stdout + r.stderr), r.stdout);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// process: flag ON + unsound closure (status review via sink) → BLOCK
|
|
126
|
-
{
|
|
127
|
-
const dir = mkdtempSync(join(tmpdir(), 'tcg-'));
|
|
128
|
-
const sink = join(dir, 'closure.json');
|
|
129
|
-
writeFileSync(sink, JSON.stringify({ id: WI, item_type: 'task', status: 'review', implementation_report: null }));
|
|
130
|
-
const r = runHook('task-completed-gate.js', { work_item_id: WI },
|
|
131
|
-
{ RDC_TRUTHGATE_TASKCOMPLETED: '1', RDC_TASKCOMPLETED_CLOSURE_SINK: sink });
|
|
132
|
-
assert('TCG flag ON + unsound closure → exit 2 BLOCK', r.status === 2, `status=${r.status} ${r.stdout}`);
|
|
133
|
-
rmSync(dir, { recursive: true, force: true });
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// process: flag ON + sound closure (via sink) → PASS (exit 0)
|
|
137
|
-
{
|
|
138
|
-
const dir = mkdtempSync(join(tmpdir(), 'tcg-'));
|
|
139
|
-
const sink = join(dir, 'closure.json');
|
|
140
|
-
writeFileSync(sink, JSON.stringify(soundRow));
|
|
141
|
-
const r = runHook('task-completed-gate.js', { work_item_id: WI },
|
|
142
|
-
{ RDC_TRUTHGATE_TASKCOMPLETED: '1', RDC_TASKCOMPLETED_CLOSURE_SINK: sink });
|
|
143
|
-
assert('TCG flag ON + sound closure → exit 0 PASS', r.status === 0, `status=${r.status} ${r.stdout}${r.stderr}`);
|
|
144
|
-
rmSync(dir, { recursive: true, force: true });
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// ===========================================================================
|
|
149
|
-
// 2. foreground-process-gate.js
|
|
150
|
-
// ===========================================================================
|
|
151
|
-
{
|
|
152
|
-
const focusPayload = {
|
|
153
|
-
tool_input: {
|
|
154
|
-
command: "powershell -NoProfile -Command \"Add-Type '[DllImport(\\\"user32.dll\\\")] public static extern bool SetForegroundWindow(System.IntPtr hWnd);'\"",
|
|
155
|
-
},
|
|
156
|
-
};
|
|
157
|
-
const r = runHook('foreground-process-gate.js', focusPayload, {});
|
|
158
|
-
assert('FPG blocks SetForegroundWindow focus API', r.status === 1, `status=${r.status} ${r.stdout}${r.stderr}`);
|
|
159
|
-
assert('FPG block mentions window focus operations', /Window focus\/restore\/minimize\/collapse/.test(r.stdout + r.stderr));
|
|
160
|
-
|
|
161
|
-
const hiddenPayload = {
|
|
162
|
-
tool_input: {
|
|
163
|
-
command: 'powershell.exe -NoProfile -NonInteractive -WindowStyle Hidden -File ".\\\\scripts\\\\helper.ps1"',
|
|
164
|
-
},
|
|
165
|
-
};
|
|
166
|
-
const h = runHook('foreground-process-gate.js', hiddenPayload, {});
|
|
167
|
-
assert('FPG allows hidden PowerShell helper', h.status === 0, `status=${h.status} ${h.stdout}${h.stderr}`);
|
|
168
|
-
|
|
169
|
-
const minimizedPayload = {
|
|
170
|
-
tool_input: {
|
|
171
|
-
command: 'Start-Process powershell.exe -WindowStyle Minimized -ArgumentList "-NoProfile"',
|
|
172
|
-
},
|
|
173
|
-
};
|
|
174
|
-
const m = runHook('foreground-process-gate.js', minimizedPayload, {});
|
|
175
|
-
assert('FPG allows minimized Start-Process without focus APIs', m.status === 0, `status=${m.status} ${m.stdout}${m.stderr}`);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// ===========================================================================
|
|
179
|
-
// 3. post-tool-batch-gate.js
|
|
180
|
-
// ===========================================================================
|
|
181
|
-
{
|
|
182
|
-
const ptb = require(join(HOOKS, 'post-tool-batch-gate.js'));
|
|
183
|
-
const DEV = 'c3189c9d58a37d648e9de4a6bcd7d46772053eea';
|
|
184
|
-
const STALE = 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef';
|
|
185
|
-
const FRESH = '1234567812345678123456781234567812345678';
|
|
186
|
-
|
|
187
|
-
// pure: evaluateWave — cannotEvaluate when no develop HEAD
|
|
188
|
-
{
|
|
189
|
-
const v = ptb.evaluateWave({ developHead: null, worktrees: [], isAncestor: () => true });
|
|
190
|
-
assert('PTB evaluateWave: no develop HEAD → cannotEvaluate', v.cannotEvaluate === true && v.ok === false);
|
|
191
|
-
}
|
|
192
|
-
// pure: current base (develop is ancestor of worktree HEAD) → ok
|
|
193
|
-
{
|
|
194
|
-
const v = ptb.evaluateWave({
|
|
195
|
-
developHead: DEV,
|
|
196
|
-
worktrees: [{ path: '/wt/a', head: FRESH }],
|
|
197
|
-
isAncestor: (a, b) => a === DEV && b === FRESH, // DEV is ancestor of FRESH
|
|
198
|
-
});
|
|
199
|
-
assert('PTB evaluateWave: current base → ok, no stale', v.ok === true && v.stale.length === 0);
|
|
200
|
-
}
|
|
201
|
-
// pure: worktree HEAD == develop HEAD → ok
|
|
202
|
-
{
|
|
203
|
-
const v = ptb.evaluateWave({
|
|
204
|
-
developHead: DEV,
|
|
205
|
-
worktrees: [{ path: '/wt/a', head: DEV }],
|
|
206
|
-
isAncestor: () => false,
|
|
207
|
-
});
|
|
208
|
-
assert('PTB evaluateWave: head==develop → ok', v.ok === true && v.stale.length === 0);
|
|
209
|
-
}
|
|
210
|
-
// pure: stale base (develop NOT an ancestor) → flagged
|
|
211
|
-
{
|
|
212
|
-
const v = ptb.evaluateWave({
|
|
213
|
-
developHead: DEV,
|
|
214
|
-
worktrees: [{ path: '/wt/stale', head: STALE }],
|
|
215
|
-
isAncestor: () => false, // DEV is NOT an ancestor of STALE
|
|
216
|
-
});
|
|
217
|
-
assert('PTB evaluateWave: stale base → not ok', v.ok === false, JSON.stringify(v));
|
|
218
|
-
assert('PTB evaluateWave: stale worktree listed', v.stale.length === 1 && v.stale[0].head === STALE);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// process: flag OFF → no-op (exit 0)
|
|
222
|
-
{
|
|
223
|
-
const r = runHook('post-tool-batch-gate.js', { hook_event_name: 'PostToolBatch' },
|
|
224
|
-
{ RDC_TRUTHGATE_POSTTOOLBATCH: '' });
|
|
225
|
-
assert('PTB flag OFF → exit 0 no-op', r.status === 0, `status=${r.status} ${r.stderr}`);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// ===========================================================================
|
|
230
|
-
// 4. gate-watchdog-selfcheck.js
|
|
231
|
-
// ===========================================================================
|
|
232
|
-
{
|
|
233
|
-
const wd = require(join(HOOKS, 'gate-watchdog-selfcheck.js'));
|
|
234
|
-
|
|
235
|
-
const allPresent = {
|
|
236
|
-
exitGateFileExists: true, exitGateRegistered: true,
|
|
237
|
-
truthGateFileExists: true, truthGateOnStop: true, truthGateOnSubagentStop: true,
|
|
238
|
-
liveHookifyManifestExists: true, deadWrapperPointsAtStaleCache: false,
|
|
239
|
-
};
|
|
240
|
-
// all present → no findings, empty banner (silent)
|
|
241
|
-
{
|
|
242
|
-
const findings = wd.evaluateWatchdog(allPresent);
|
|
243
|
-
assert('WD all present → no findings', findings.length === 0, JSON.stringify(findings));
|
|
244
|
-
assert('WD all present → empty banner (silent)', wd.renderBanner(findings) === '');
|
|
245
|
-
}
|
|
246
|
-
// truth-gate missing → finding + STOP banner
|
|
247
|
-
{
|
|
248
|
-
const findings = wd.evaluateWatchdog({ ...allPresent, truthGateFileExists: false });
|
|
249
|
-
assert('WD truth-gate missing → finding', findings.some((f) => /truth-gate\.mjs is MISSING/.test(f)), JSON.stringify(findings));
|
|
250
|
-
const banner = wd.renderBanner(findings);
|
|
251
|
-
assert('WD truth-gate missing → STOP banner emitted', /TRUTH GATE WATCHDOG/.test(banner) && banner.length > 0);
|
|
252
|
-
}
|
|
253
|
-
// truth-gate unregistered on SubagentStop → finding
|
|
254
|
-
{
|
|
255
|
-
const findings = wd.evaluateWatchdog({ ...allPresent, truthGateOnSubagentStop: false });
|
|
256
|
-
assert('WD truth-gate not on SubagentStop → finding', findings.some((f) => /SubagentStop/.test(f)));
|
|
257
|
-
}
|
|
258
|
-
// exit gate missing → finding
|
|
259
|
-
{
|
|
260
|
-
const findings = wd.evaluateWatchdog({ ...allPresent, exitGateFileExists: false });
|
|
261
|
-
assert('WD exit-gate missing → finding', findings.some((f) => /work-item-exit-gate\.js is MISSING/.test(f)));
|
|
262
|
-
}
|
|
263
|
-
// LIVE hookify manifest absent → finding mentions plugin manifest, NOT dead wrappers as trusted
|
|
264
|
-
{
|
|
265
|
-
const findings = wd.evaluateWatchdog({ ...allPresent, liveHookifyManifestExists: false });
|
|
266
|
-
const f = findings.find((x) => /hookify/i.test(x));
|
|
267
|
-
assert('WD live hookify manifest absent → finding', Boolean(f), JSON.stringify(findings));
|
|
268
|
-
assert('WD finding names the LIVE plugin hooks.json (not dead wrappers as trusted)',
|
|
269
|
-
f && /plugins\/cache.*hookify.*hooks\.json/i.test(f) && /NOT the live path/i.test(f), f || '');
|
|
270
|
-
}
|
|
271
|
-
// dead wrapper points at stale cache → drift finding
|
|
272
|
-
{
|
|
273
|
-
const findings = wd.evaluateWatchdog({ ...allPresent, deadWrapperPointsAtStaleCache: true,
|
|
274
|
-
deadWrapperRoot: '/cache/hookify/OLDHASH', liveHookifyRoot: '/cache/hookify/NEWHASH' });
|
|
275
|
-
assert('WD stale-cache drift → finding', findings.some((f) => /ORPHANED cache hash/.test(f)));
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
// structural: gatherFacts inspects the LIVE plugins/cache hooks.json path, not the wrappers.
|
|
279
|
-
{
|
|
280
|
-
const home = mkdtempSync(join(tmpdir(), 'wd-home-'));
|
|
281
|
-
const repo = mkdtempSync(join(tmpdir(), 'wd-repo-'));
|
|
282
|
-
// Build a fake LIVE hookify plugin manifest under plugins/cache/.../hookify/<hash>/hooks/hooks.json
|
|
283
|
-
const live = join(home, '.claude', 'plugins', 'cache', 'official', 'hookify', 'NEWHASH', 'hooks');
|
|
284
|
-
mkdirSync(live, { recursive: true });
|
|
285
|
-
writeFileSync(join(live, 'hooks.json'), JSON.stringify({ hooks: {} }));
|
|
286
|
-
// Build a dead wrapper that points at a DIFFERENT (orphaned) hash.
|
|
287
|
-
const deadDir = join(home, '.claude', 'hooks');
|
|
288
|
-
mkdirSync(deadDir, { recursive: true });
|
|
289
|
-
writeFileSync(join(deadDir, 'hookify-stop.js'),
|
|
290
|
-
"const PLUGIN_ROOT = 'C:/cache/official/hookify/OLDHASH';\n");
|
|
291
|
-
// Minimal settings.json registering both gates so those facts are true.
|
|
292
|
-
mkdirSync(join(repo, '.claude', 'hooks'), { recursive: true });
|
|
293
|
-
writeFileSync(join(repo, '.claude', 'hooks', 'truth-gate.mjs'), '// stub');
|
|
294
|
-
writeFileSync(join(repo, '.claude', 'settings.json'), JSON.stringify({
|
|
295
|
-
hooks: {
|
|
296
|
-
PreToolUse: [{ hooks: [{ type: 'command', command: 'node hooks/work-item-exit-gate.js' }] }],
|
|
297
|
-
Stop: [{ hooks: [{ type: 'command', command: 'node .claude/hooks/truth-gate.mjs' }] }],
|
|
298
|
-
SubagentStop: [{ hooks: [{ type: 'command', command: 'node .claude/hooks/truth-gate.mjs' }] }],
|
|
299
|
-
},
|
|
300
|
-
}));
|
|
301
|
-
|
|
302
|
-
const manifest = wd.findLiveHookifyManifest(home);
|
|
303
|
-
assert('WD findLiveHookifyManifest resolves the plugin hooks.json',
|
|
304
|
-
typeof manifest === 'string' && /plugins[\\/]cache.*hookify.*hooks\.json$/i.test(manifest.replace(/\\/g, '/')), manifest || 'null');
|
|
305
|
-
|
|
306
|
-
const facts = wd.gatherFacts({ home, repoRoot: repo, hooksDir: HOOKS });
|
|
307
|
-
assert('WD gatherFacts: live hookify manifest detected', facts.liveHookifyManifestExists === true);
|
|
308
|
-
assert('WD gatherFacts: dead wrapper stale-cache drift detected', facts.deadWrapperPointsAtStaleCache === true,
|
|
309
|
-
`dead=${facts.deadWrapperRoot} live=${facts.liveHookifyRoot}`);
|
|
310
|
-
assert('WD gatherFacts: truth-gate registered on Stop+SubagentStop',
|
|
311
|
-
facts.truthGateOnStop === true && facts.truthGateOnSubagentStop === true);
|
|
312
|
-
assert('WD gatherFacts: exit gate registered on PreToolUse', facts.exitGateRegistered === true);
|
|
313
|
-
|
|
314
|
-
rmSync(home, { recursive: true, force: true });
|
|
315
|
-
rmSync(repo, { recursive: true, force: true });
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
// ===========================================================================
|
|
320
|
-
if (failures.length > 0) {
|
|
321
|
-
console.error('\nharness-gates tests — FAIL\n');
|
|
322
|
-
for (const f of failures) console.error(` - ${f}`);
|
|
323
|
-
process.exit(1);
|
|
324
|
-
}
|
|
325
|
-
console.log('\nharness-gates tests — PASS');
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Truth Gate 3.0 — Layers 5+6 harness-gate tests (WP-5).
|
|
4
|
+
*
|
|
5
|
+
* Covers the three new hooks, fully offline (no DB, no brain, no clauth):
|
|
6
|
+
* task-completed-gate.js — flag OFF no-op; flag ON + no/unsound closure BLOCK;
|
|
7
|
+
* flag ON + sound closure PASS.
|
|
8
|
+
* post-tool-batch-gate.js — flag OFF no-op; flag ON + stale worktree base FLAG;
|
|
9
|
+
* flag ON + current base PASS.
|
|
10
|
+
* gate-watchdog-selfcheck — STOP-banner when a gate file/registration absent;
|
|
11
|
+
* silent when all present; checks the LIVE hookify
|
|
12
|
+
* hooks.json (plugin manifest), not the dead wrappers.
|
|
13
|
+
*
|
|
14
|
+
* Run: node tests/harness-gates.test.mjs
|
|
15
|
+
*/
|
|
16
|
+
import { mkdtempSync, rmSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
17
|
+
import { tmpdir } from 'node:os';
|
|
18
|
+
import { join, resolve, dirname } from 'node:path';
|
|
19
|
+
import { fileURLToPath } from 'node:url';
|
|
20
|
+
import { spawnSync } from 'node:child_process';
|
|
21
|
+
import { createRequire } from 'node:module';
|
|
22
|
+
|
|
23
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
24
|
+
const REPO_ROOT = resolve(__dirname, '..');
|
|
25
|
+
const HOOKS = join(REPO_ROOT, 'hooks');
|
|
26
|
+
const require = createRequire(import.meta.url);
|
|
27
|
+
|
|
28
|
+
const failures = [];
|
|
29
|
+
function assert(name, condition, detail = '') {
|
|
30
|
+
if (!condition) failures.push(`${name}${detail ? `: ${detail}` : ''}`);
|
|
31
|
+
else process.stdout.write(` ok ${name}\n`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function runHook(file, payload, extraEnv = {}) {
|
|
35
|
+
return spawnSync(process.execPath, [join(HOOKS, file)], {
|
|
36
|
+
input: JSON.stringify(payload),
|
|
37
|
+
encoding: 'utf8',
|
|
38
|
+
env: { ...process.env, ...extraEnv },
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const WI = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee';
|
|
43
|
+
|
|
44
|
+
// ===========================================================================
|
|
45
|
+
// 1. task-completed-gate.js
|
|
46
|
+
// ===========================================================================
|
|
47
|
+
{
|
|
48
|
+
const tcg = require(join(HOOKS, 'task-completed-gate.js'));
|
|
49
|
+
|
|
50
|
+
// pure: closureIsSound branches
|
|
51
|
+
assert('TCG closureIsSound: null row → not ok', tcg.closureIsSound(null).ok === false);
|
|
52
|
+
assert('TCG closureIsSound: not-done task → not ok',
|
|
53
|
+
tcg.closureIsSound({ id: WI, item_type: 'task', status: 'review' }).ok === false);
|
|
54
|
+
assert('TCG closureIsSound: done but witness:agent → not ok',
|
|
55
|
+
tcg.closureIsSound({ id: WI, item_type: 'task', status: 'done', implementation_report: { codeflow_post: { witness: 'agent', commit: 'x', files_changed: ['f'], verification: [{ exit_code: 0 }] } } }).ok === false);
|
|
56
|
+
const soundRow = {
|
|
57
|
+
id: WI, item_type: 'task', status: 'done',
|
|
58
|
+
implementation_report: { codeflow_post: { witness: 'validator-rerun', commit: 'c3189c9d58a37d648e9de4a6bcd7d46772053eea', files_changed: ['hooks/x.js'], verification: [{ exit_code: 0 }] } },
|
|
59
|
+
};
|
|
60
|
+
assert('TCG closureIsSound: full sound closure → ok', tcg.closureIsSound(soundRow).ok === true,
|
|
61
|
+
tcg.closureIsSound(soundRow).reason || '');
|
|
62
|
+
assert('TCG closureIsSound: epic done → ok',
|
|
63
|
+
tcg.closureIsSound({ id: WI, item_type: 'epic', status: 'done' }).ok === true);
|
|
64
|
+
|
|
65
|
+
// pure: extractWorkItemId
|
|
66
|
+
assert('TCG extractWorkItemId: from field', tcg.extractWorkItemId({ work_item_id: WI }) === WI);
|
|
67
|
+
assert('TCG extractWorkItemId: from blob', tcg.extractWorkItemId({ task: { note: `closes ${WI}` } }) === WI);
|
|
68
|
+
assert('TCG extractWorkItemId: none → null', tcg.extractWorkItemId({ task: { note: 'no uuid' } }) === null);
|
|
69
|
+
|
|
70
|
+
// pure: flagEnabledEnv default OFF
|
|
71
|
+
{
|
|
72
|
+
const prev = process.env.RDC_TRUTHGATE_TASKCOMPLETED;
|
|
73
|
+
delete process.env.RDC_TRUTHGATE_TASKCOMPLETED;
|
|
74
|
+
assert('TCG flag default OFF', tcg.flagEnabledEnv() === false);
|
|
75
|
+
process.env.RDC_TRUTHGATE_TASKCOMPLETED = 'true';
|
|
76
|
+
assert('TCG flag ON via env', tcg.flagEnabledEnv() === true);
|
|
77
|
+
if (prev === undefined) delete process.env.RDC_TRUTHGATE_TASKCOMPLETED;
|
|
78
|
+
else process.env.RDC_TRUTHGATE_TASKCOMPLETED = prev;
|
|
79
|
+
}
|
|
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
|
+
|
|
92
|
+
// process: flag OFF → no-op (exit 0, no block)
|
|
93
|
+
{
|
|
94
|
+
const r = runHook('task-completed-gate.js', { work_item_id: WI }, { RDC_TRUTHGATE_TASKCOMPLETED: '' });
|
|
95
|
+
assert('TCG flag OFF → exit 0 no-op', r.status === 0, `status=${r.status} ${r.stderr}`);
|
|
96
|
+
}
|
|
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
|
+
|
|
117
|
+
// process: flag ON + no closure ref → BLOCK (exit 2)
|
|
118
|
+
{
|
|
119
|
+
const r = runHook('task-completed-gate.js', { task: { note: 'no uuid here' } },
|
|
120
|
+
{ RDC_TRUTHGATE_TASKCOMPLETED: '1' });
|
|
121
|
+
assert('TCG flag ON + no work-item ref → exit 2 BLOCK', r.status === 2, `status=${r.status}`);
|
|
122
|
+
assert('TCG block mentions no work-item reference', /no work-item reference/.test(r.stdout + r.stderr), r.stdout);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// process: flag ON + unsound closure (status review via sink) → BLOCK
|
|
126
|
+
{
|
|
127
|
+
const dir = mkdtempSync(join(tmpdir(), 'tcg-'));
|
|
128
|
+
const sink = join(dir, 'closure.json');
|
|
129
|
+
writeFileSync(sink, JSON.stringify({ id: WI, item_type: 'task', status: 'review', implementation_report: null }));
|
|
130
|
+
const r = runHook('task-completed-gate.js', { work_item_id: WI },
|
|
131
|
+
{ RDC_TRUTHGATE_TASKCOMPLETED: '1', RDC_TASKCOMPLETED_CLOSURE_SINK: sink });
|
|
132
|
+
assert('TCG flag ON + unsound closure → exit 2 BLOCK', r.status === 2, `status=${r.status} ${r.stdout}`);
|
|
133
|
+
rmSync(dir, { recursive: true, force: true });
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// process: flag ON + sound closure (via sink) → PASS (exit 0)
|
|
137
|
+
{
|
|
138
|
+
const dir = mkdtempSync(join(tmpdir(), 'tcg-'));
|
|
139
|
+
const sink = join(dir, 'closure.json');
|
|
140
|
+
writeFileSync(sink, JSON.stringify(soundRow));
|
|
141
|
+
const r = runHook('task-completed-gate.js', { work_item_id: WI },
|
|
142
|
+
{ RDC_TRUTHGATE_TASKCOMPLETED: '1', RDC_TASKCOMPLETED_CLOSURE_SINK: sink });
|
|
143
|
+
assert('TCG flag ON + sound closure → exit 0 PASS', r.status === 0, `status=${r.status} ${r.stdout}${r.stderr}`);
|
|
144
|
+
rmSync(dir, { recursive: true, force: true });
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// ===========================================================================
|
|
149
|
+
// 2. foreground-process-gate.js
|
|
150
|
+
// ===========================================================================
|
|
151
|
+
{
|
|
152
|
+
const focusPayload = {
|
|
153
|
+
tool_input: {
|
|
154
|
+
command: "powershell -NoProfile -Command \"Add-Type '[DllImport(\\\"user32.dll\\\")] public static extern bool SetForegroundWindow(System.IntPtr hWnd);'\"",
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
const r = runHook('foreground-process-gate.js', focusPayload, {});
|
|
158
|
+
assert('FPG blocks SetForegroundWindow focus API', r.status === 1, `status=${r.status} ${r.stdout}${r.stderr}`);
|
|
159
|
+
assert('FPG block mentions window focus operations', /Window focus\/restore\/minimize\/collapse/.test(r.stdout + r.stderr));
|
|
160
|
+
|
|
161
|
+
const hiddenPayload = {
|
|
162
|
+
tool_input: {
|
|
163
|
+
command: 'powershell.exe -NoProfile -NonInteractive -WindowStyle Hidden -File ".\\\\scripts\\\\helper.ps1"',
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
const h = runHook('foreground-process-gate.js', hiddenPayload, {});
|
|
167
|
+
assert('FPG allows hidden PowerShell helper', h.status === 0, `status=${h.status} ${h.stdout}${h.stderr}`);
|
|
168
|
+
|
|
169
|
+
const minimizedPayload = {
|
|
170
|
+
tool_input: {
|
|
171
|
+
command: 'Start-Process powershell.exe -WindowStyle Minimized -ArgumentList "-NoProfile"',
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
const m = runHook('foreground-process-gate.js', minimizedPayload, {});
|
|
175
|
+
assert('FPG allows minimized Start-Process without focus APIs', m.status === 0, `status=${m.status} ${m.stdout}${m.stderr}`);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// ===========================================================================
|
|
179
|
+
// 3. post-tool-batch-gate.js
|
|
180
|
+
// ===========================================================================
|
|
181
|
+
{
|
|
182
|
+
const ptb = require(join(HOOKS, 'post-tool-batch-gate.js'));
|
|
183
|
+
const DEV = 'c3189c9d58a37d648e9de4a6bcd7d46772053eea';
|
|
184
|
+
const STALE = 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef';
|
|
185
|
+
const FRESH = '1234567812345678123456781234567812345678';
|
|
186
|
+
|
|
187
|
+
// pure: evaluateWave — cannotEvaluate when no develop HEAD
|
|
188
|
+
{
|
|
189
|
+
const v = ptb.evaluateWave({ developHead: null, worktrees: [], isAncestor: () => true });
|
|
190
|
+
assert('PTB evaluateWave: no develop HEAD → cannotEvaluate', v.cannotEvaluate === true && v.ok === false);
|
|
191
|
+
}
|
|
192
|
+
// pure: current base (develop is ancestor of worktree HEAD) → ok
|
|
193
|
+
{
|
|
194
|
+
const v = ptb.evaluateWave({
|
|
195
|
+
developHead: DEV,
|
|
196
|
+
worktrees: [{ path: '/wt/a', head: FRESH }],
|
|
197
|
+
isAncestor: (a, b) => a === DEV && b === FRESH, // DEV is ancestor of FRESH
|
|
198
|
+
});
|
|
199
|
+
assert('PTB evaluateWave: current base → ok, no stale', v.ok === true && v.stale.length === 0);
|
|
200
|
+
}
|
|
201
|
+
// pure: worktree HEAD == develop HEAD → ok
|
|
202
|
+
{
|
|
203
|
+
const v = ptb.evaluateWave({
|
|
204
|
+
developHead: DEV,
|
|
205
|
+
worktrees: [{ path: '/wt/a', head: DEV }],
|
|
206
|
+
isAncestor: () => false,
|
|
207
|
+
});
|
|
208
|
+
assert('PTB evaluateWave: head==develop → ok', v.ok === true && v.stale.length === 0);
|
|
209
|
+
}
|
|
210
|
+
// pure: stale base (develop NOT an ancestor) → flagged
|
|
211
|
+
{
|
|
212
|
+
const v = ptb.evaluateWave({
|
|
213
|
+
developHead: DEV,
|
|
214
|
+
worktrees: [{ path: '/wt/stale', head: STALE }],
|
|
215
|
+
isAncestor: () => false, // DEV is NOT an ancestor of STALE
|
|
216
|
+
});
|
|
217
|
+
assert('PTB evaluateWave: stale base → not ok', v.ok === false, JSON.stringify(v));
|
|
218
|
+
assert('PTB evaluateWave: stale worktree listed', v.stale.length === 1 && v.stale[0].head === STALE);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// process: flag OFF → no-op (exit 0)
|
|
222
|
+
{
|
|
223
|
+
const r = runHook('post-tool-batch-gate.js', { hook_event_name: 'PostToolBatch' },
|
|
224
|
+
{ RDC_TRUTHGATE_POSTTOOLBATCH: '' });
|
|
225
|
+
assert('PTB flag OFF → exit 0 no-op', r.status === 0, `status=${r.status} ${r.stderr}`);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// ===========================================================================
|
|
230
|
+
// 4. gate-watchdog-selfcheck.js
|
|
231
|
+
// ===========================================================================
|
|
232
|
+
{
|
|
233
|
+
const wd = require(join(HOOKS, 'gate-watchdog-selfcheck.js'));
|
|
234
|
+
|
|
235
|
+
const allPresent = {
|
|
236
|
+
exitGateFileExists: true, exitGateRegistered: true,
|
|
237
|
+
truthGateFileExists: true, truthGateOnStop: true, truthGateOnSubagentStop: true,
|
|
238
|
+
liveHookifyManifestExists: true, deadWrapperPointsAtStaleCache: false,
|
|
239
|
+
};
|
|
240
|
+
// all present → no findings, empty banner (silent)
|
|
241
|
+
{
|
|
242
|
+
const findings = wd.evaluateWatchdog(allPresent);
|
|
243
|
+
assert('WD all present → no findings', findings.length === 0, JSON.stringify(findings));
|
|
244
|
+
assert('WD all present → empty banner (silent)', wd.renderBanner(findings) === '');
|
|
245
|
+
}
|
|
246
|
+
// truth-gate missing → finding + STOP banner
|
|
247
|
+
{
|
|
248
|
+
const findings = wd.evaluateWatchdog({ ...allPresent, truthGateFileExists: false });
|
|
249
|
+
assert('WD truth-gate missing → finding', findings.some((f) => /truth-gate\.mjs is MISSING/.test(f)), JSON.stringify(findings));
|
|
250
|
+
const banner = wd.renderBanner(findings);
|
|
251
|
+
assert('WD truth-gate missing → STOP banner emitted', /TRUTH GATE WATCHDOG/.test(banner) && banner.length > 0);
|
|
252
|
+
}
|
|
253
|
+
// truth-gate unregistered on SubagentStop → finding
|
|
254
|
+
{
|
|
255
|
+
const findings = wd.evaluateWatchdog({ ...allPresent, truthGateOnSubagentStop: false });
|
|
256
|
+
assert('WD truth-gate not on SubagentStop → finding', findings.some((f) => /SubagentStop/.test(f)));
|
|
257
|
+
}
|
|
258
|
+
// exit gate missing → finding
|
|
259
|
+
{
|
|
260
|
+
const findings = wd.evaluateWatchdog({ ...allPresent, exitGateFileExists: false });
|
|
261
|
+
assert('WD exit-gate missing → finding', findings.some((f) => /work-item-exit-gate\.js is MISSING/.test(f)));
|
|
262
|
+
}
|
|
263
|
+
// LIVE hookify manifest absent → finding mentions plugin manifest, NOT dead wrappers as trusted
|
|
264
|
+
{
|
|
265
|
+
const findings = wd.evaluateWatchdog({ ...allPresent, liveHookifyManifestExists: false });
|
|
266
|
+
const f = findings.find((x) => /hookify/i.test(x));
|
|
267
|
+
assert('WD live hookify manifest absent → finding', Boolean(f), JSON.stringify(findings));
|
|
268
|
+
assert('WD finding names the LIVE plugin hooks.json (not dead wrappers as trusted)',
|
|
269
|
+
f && /plugins\/cache.*hookify.*hooks\.json/i.test(f) && /NOT the live path/i.test(f), f || '');
|
|
270
|
+
}
|
|
271
|
+
// dead wrapper points at stale cache → drift finding
|
|
272
|
+
{
|
|
273
|
+
const findings = wd.evaluateWatchdog({ ...allPresent, deadWrapperPointsAtStaleCache: true,
|
|
274
|
+
deadWrapperRoot: '/cache/hookify/OLDHASH', liveHookifyRoot: '/cache/hookify/NEWHASH' });
|
|
275
|
+
assert('WD stale-cache drift → finding', findings.some((f) => /ORPHANED cache hash/.test(f)));
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// structural: gatherFacts inspects the LIVE plugins/cache hooks.json path, not the wrappers.
|
|
279
|
+
{
|
|
280
|
+
const home = mkdtempSync(join(tmpdir(), 'wd-home-'));
|
|
281
|
+
const repo = mkdtempSync(join(tmpdir(), 'wd-repo-'));
|
|
282
|
+
// Build a fake LIVE hookify plugin manifest under plugins/cache/.../hookify/<hash>/hooks/hooks.json
|
|
283
|
+
const live = join(home, '.claude', 'plugins', 'cache', 'official', 'hookify', 'NEWHASH', 'hooks');
|
|
284
|
+
mkdirSync(live, { recursive: true });
|
|
285
|
+
writeFileSync(join(live, 'hooks.json'), JSON.stringify({ hooks: {} }));
|
|
286
|
+
// Build a dead wrapper that points at a DIFFERENT (orphaned) hash.
|
|
287
|
+
const deadDir = join(home, '.claude', 'hooks');
|
|
288
|
+
mkdirSync(deadDir, { recursive: true });
|
|
289
|
+
writeFileSync(join(deadDir, 'hookify-stop.js'),
|
|
290
|
+
"const PLUGIN_ROOT = 'C:/cache/official/hookify/OLDHASH';\n");
|
|
291
|
+
// Minimal settings.json registering both gates so those facts are true.
|
|
292
|
+
mkdirSync(join(repo, '.claude', 'hooks'), { recursive: true });
|
|
293
|
+
writeFileSync(join(repo, '.claude', 'hooks', 'truth-gate.mjs'), '// stub');
|
|
294
|
+
writeFileSync(join(repo, '.claude', 'settings.json'), JSON.stringify({
|
|
295
|
+
hooks: {
|
|
296
|
+
PreToolUse: [{ hooks: [{ type: 'command', command: 'node hooks/work-item-exit-gate.js' }] }],
|
|
297
|
+
Stop: [{ hooks: [{ type: 'command', command: 'node .claude/hooks/truth-gate.mjs' }] }],
|
|
298
|
+
SubagentStop: [{ hooks: [{ type: 'command', command: 'node .claude/hooks/truth-gate.mjs' }] }],
|
|
299
|
+
},
|
|
300
|
+
}));
|
|
301
|
+
|
|
302
|
+
const manifest = wd.findLiveHookifyManifest(home);
|
|
303
|
+
assert('WD findLiveHookifyManifest resolves the plugin hooks.json',
|
|
304
|
+
typeof manifest === 'string' && /plugins[\\/]cache.*hookify.*hooks\.json$/i.test(manifest.replace(/\\/g, '/')), manifest || 'null');
|
|
305
|
+
|
|
306
|
+
const facts = wd.gatherFacts({ home, repoRoot: repo, hooksDir: HOOKS });
|
|
307
|
+
assert('WD gatherFacts: live hookify manifest detected', facts.liveHookifyManifestExists === true);
|
|
308
|
+
assert('WD gatherFacts: dead wrapper stale-cache drift detected', facts.deadWrapperPointsAtStaleCache === true,
|
|
309
|
+
`dead=${facts.deadWrapperRoot} live=${facts.liveHookifyRoot}`);
|
|
310
|
+
assert('WD gatherFacts: truth-gate registered on Stop+SubagentStop',
|
|
311
|
+
facts.truthGateOnStop === true && facts.truthGateOnSubagentStop === true);
|
|
312
|
+
assert('WD gatherFacts: exit gate registered on PreToolUse', facts.exitGateRegistered === true);
|
|
313
|
+
|
|
314
|
+
rmSync(home, { recursive: true, force: true });
|
|
315
|
+
rmSync(repo, { recursive: true, force: true });
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// ===========================================================================
|
|
320
|
+
if (failures.length > 0) {
|
|
321
|
+
console.error('\nharness-gates tests — FAIL\n');
|
|
322
|
+
for (const f of failures) console.error(` - ${f}`);
|
|
323
|
+
process.exit(1);
|
|
324
|
+
}
|
|
325
|
+
console.log('\nharness-gates tests — PASS');
|