Add nightly realm reports and observed bot activity explanations
Core tests / core (push) Successful in 59s
Core tests / core (push) Successful in 59s
This commit is contained in:
@@ -78,6 +78,17 @@ try:
|
||||
count=recovery.publish_recovery_intents(current,cfg)
|
||||
maintenance.append(f'Recovery intentions refreshed for {count} residents')
|
||||
except Exception as e:maintenance.append('Recovery check needs attention: '+type(e).__name__)
|
||||
try:
|
||||
recovery_rows=[]
|
||||
try:
|
||||
for line in sql('SELECT id,guid,name,UNIX_TIMESTAMP(at),detail FROM acore_auth.azerothai_recovery_log ORDER BY id DESC LIMIT 100').splitlines():
|
||||
fields=line.split('\t',4)
|
||||
recovery_rows.append(dict(id=int(fields[0]),guid=int(fields[1]),name=fields[2],at=int(fields[3]),detail=fields[4]))
|
||||
except Exception as e:maintenance.append('Recovery history unavailable: '+type(e).__name__)
|
||||
request=urllib.request.Request(base+'/api/realm-insights',data=json.dumps({'at':time.time(),'recoveries':recovery_rows}).encode(),headers={'Content-Type':'application/json','Authorization':'Bearer '+cfg['AUTONOMY_TOKEN']})
|
||||
with urllib.request.urlopen(request,timeout=20) as response:assert response.status==200
|
||||
maintenance.append('Realm report sampled')
|
||||
except Exception as e:maintenance.append('Realm report needs attention: '+type(e).__name__)
|
||||
try:
|
||||
backup_status=json.loads((lab/'backups/latest-status.json').read_text())
|
||||
maintenance.append(('Backup restored and verified: ' if backup_status.get('ok') else 'BACKUP NEEDS ATTENTION: ')+str(backup_status.get('at','unknown')))
|
||||
|
||||
@@ -195,6 +195,12 @@ class Handler(BaseHTTPRequestHandler):
|
||||
at = data['rosterAt'] if data else 0
|
||||
from datetime import datetime, timezone
|
||||
self.reply(200, json.dumps({'ok':bool(data),'ale':{'lastEventAt':datetime.fromtimestamp(at,timezone.utc).isoformat() if at else None,'activeRecently':bool(data and not data['stale'])},'events':[],'commands':{}}).encode())
|
||||
elif path == '/api/realm-insights':
|
||||
try:
|
||||
# Fixed read-only endpoint: public aggregate facts and bot activity only.
|
||||
self.reply(200, local_get('/api/realm-insights'))
|
||||
except Exception:
|
||||
self.reply(503,b'{"error":"Realm insights unavailable"}')
|
||||
elif path == '/api/operations':
|
||||
try:
|
||||
health = json.loads(local_get('/api/operations'))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {spawnSync} from 'node:child_process';
|
||||
import {writeFileSync,mkdirSync} from 'node:fs';
|
||||
const result=spawnSync(process.execPath,['node_modules/typescript/bin/tsc','core/service.ts','core/seed.ts','core/ale.ts','core/conversation.ts','core/autonomy.ts','--types','@cloudflare/workers-types,node','--outDir','.test-build','--module','commonjs','--target','es2022','--moduleResolution','node','--esModuleInterop','--skipLibCheck','--strict'],{stdio:'inherit'});
|
||||
const result=spawnSync(process.execPath,['node_modules/typescript/bin/tsc','core/realm-insights.ts','core/service.ts','core/seed.ts','core/ale.ts','core/conversation.ts','core/autonomy.ts','--types','@cloudflare/workers-types,node','--outDir','.test-build','--module','commonjs','--target','es2022','--moduleResolution','node','--esModuleInterop','--skipLibCheck','--strict'],{stdio:'inherit'});
|
||||
if(result.status)process.exit(result.status);
|
||||
mkdirSync('.test-build',{recursive:true});writeFileSync('.test-build/package.json','{"type":"commonjs"}');
|
||||
process.exit(spawnSync(process.execPath,['--test','tests/core.test.cjs','tests/hardcore.test.cjs','tests/living-world.test.cjs','tests/ale.test.cjs','tests/brains.test.cjs','tests/conversation.test.cjs','tests/autonomy.test.cjs','tests/community.test.cjs'],{stdio:'inherit'}).status??1);
|
||||
process.exit(spawnSync(process.execPath,['--test','tests/realm-insights.test.cjs','tests/core.test.cjs','tests/hardcore.test.cjs','tests/living-world.test.cjs','tests/ale.test.cjs','tests/brains.test.cjs','tests/conversation.test.cjs','tests/autonomy.test.cjs','tests/community.test.cjs'],{stdio:'inherit'}).status??1);
|
||||
|
||||
@@ -56,6 +56,14 @@ class SpectatorTests(unittest.TestCase):
|
||||
with patch.object(m.SNAPSHOT,'get',return_value={'state':{'bots':[]}}):
|
||||
with urllib.request.urlopen(base+'/api/state') as response:
|
||||
self.assertEqual(json.load(response),{'bots':[]})
|
||||
with patch.object(m,'local_get',return_value=b'{"reports":[]}') as upstream:
|
||||
with urllib.request.urlopen(base+'/api/realm-insights') as response:
|
||||
self.assertEqual(json.load(response),{'reports':[]})
|
||||
upstream.assert_called_once_with('/api/realm-insights')
|
||||
with self.assertRaises(urllib.error.HTTPError) as error:
|
||||
urllib.request.urlopen(urllib.request.Request(base+'/api/realm-insights',method='POST',data=b'{}'))
|
||||
self.assertEqual(error.exception.code,405)
|
||||
error.exception.close()
|
||||
for method in ['POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'TRACE']:
|
||||
with self.assertRaises(urllib.error.HTTPError) as error:
|
||||
urllib.request.urlopen(urllib.request.Request(base + '/api/actions', method=method, data=b'{}'))
|
||||
|
||||
Reference in New Issue
Block a user