Initial commit: OpenClaw ops workspace
This commit is contained in:
76
scripts/validate-channel-registry.sh
Executable file
76
scripts/validate-channel-registry.sh
Executable file
@@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
REG_JSON="/home/node/.openclaw/memory/channel-registry.json"
|
||||
CONF_JSON="/home/node/.openclaw/openclaw.json"
|
||||
CRON_JSON="/home/node/.openclaw/cron/jobs.json"
|
||||
|
||||
python3 - <<'PY'
|
||||
import json, sys
|
||||
from pathlib import Path
|
||||
reg = json.loads(Path('/home/node/.openclaw/memory/channel-registry.json').read_text())
|
||||
conf = json.loads(Path('/home/node/.openclaw/openclaw.json').read_text())
|
||||
jobs = json.loads(Path('/home/node/.openclaw/cron/jobs.json').read_text())['jobs']
|
||||
|
||||
index={(e['platform'],e['kind'],e['id']):e for e in reg.get('entries',[])}
|
||||
errors=[]
|
||||
|
||||
# check bindings
|
||||
for b in conf.get('bindings',[]):
|
||||
m=b.get('match',{})
|
||||
if m.get('channel')!='discord':
|
||||
continue
|
||||
gid=m.get('guildId')
|
||||
if gid:
|
||||
k=('discord','guild',gid)
|
||||
if k not in index:
|
||||
errors.append(f"Missing registry entry for binding guild:{gid}")
|
||||
peer=m.get('peer') or {}
|
||||
pid=peer.get('id'); kind=peer.get('kind')
|
||||
if pid and kind in ('channel','group'):
|
||||
k=('discord',kind,pid)
|
||||
if k not in index:
|
||||
errors.append(f"Missing registry entry for binding {kind}:{pid}")
|
||||
|
||||
# check cron delivery targets
|
||||
for j in jobs:
|
||||
d=j.get('delivery',{})
|
||||
to=d.get('to')
|
||||
if not isinstance(to,str):
|
||||
continue
|
||||
cid=None
|
||||
if to.startswith('channel:'): cid=to.split(':',1)[1]; kind='channel'
|
||||
elif to.isdigit(): cid=to; kind='channel'
|
||||
else: continue
|
||||
k=('discord',kind,cid)
|
||||
if k not in index:
|
||||
errors.append(f"Missing registry entry for cron {j['id']} target {kind}:{cid}")
|
||||
|
||||
# unresolved check for referenced entries
|
||||
referenced=set()
|
||||
for b in conf.get('bindings',[]):
|
||||
m=b.get('match',{})
|
||||
if m.get('channel')!='discord': continue
|
||||
gid=m.get('guildId')
|
||||
if gid: referenced.add(('discord','guild',gid))
|
||||
peer=m.get('peer') or {}
|
||||
pid=peer.get('id'); kind=peer.get('kind')
|
||||
if pid and kind in ('channel','group'): referenced.add(('discord',kind,pid))
|
||||
for j in jobs:
|
||||
d=j.get('delivery',{})
|
||||
to=d.get('to')
|
||||
if not isinstance(to,str): continue
|
||||
if to.startswith('channel:'): referenced.add(('discord','channel',to.split(':',1)[1]))
|
||||
elif to.isdigit(): referenced.add(('discord','channel',to))
|
||||
|
||||
for k in sorted(referenced):
|
||||
e=index.get(k)
|
||||
if e and e.get('status')=='unresolved':
|
||||
errors.append(f"Unresolved referenced ID: {k[1]}:{k[2]}")
|
||||
|
||||
if errors:
|
||||
print('CHANNEL REGISTRY VALIDATION: FAIL')
|
||||
for err in errors:
|
||||
print('-', err)
|
||||
sys.exit(1)
|
||||
print('CHANNEL REGISTRY VALIDATION: OK')
|
||||
PY
|
||||
Reference in New Issue
Block a user