diff --git a/website/integrations/TICKET-350-DEPARTMENT-SEALS.md b/website/integrations/TICKET-350-DEPARTMENT-SEALS.md new file mode 100644 index 00000000..fdbdd30a --- /dev/null +++ b/website/integrations/TICKET-350-DEPARTMENT-SEALS.md @@ -0,0 +1,26 @@ +# Ticket 350: verified closure counts and personal department seals + +Owner clarification: **25 total distinct closed tickets in a department, not 25 percent**. All accounts, including Owner and Main Network Administrator, follow the same threshold. One seal represents each currently assigned department: general below 25, personalised at 25 or above. Separate rank, elected-office and recognition seals remain independent. Redundant department/team image pairs are removed from managed forum, ticket and email signatures. + +## Attribution + +`staff-closure-counts.sql` is shared by the Node roster and PHP signature adapter. It reads the native closing event’s `uid`/`uid_type`, not its assignee snapshot `staff_id`. The native actor must map through the verified DuneRealms staff backend to a central account. The event’s department is the department where the ticket was closed. + +Only currently closed tickets with a latest non-annulled closure count. Reopens and repeated closes cannot accumulate duplicate credit. System-only events are not attributed from display names. Consolidated/superseded Dev tickets and other administrative batch closures do not earn progress. A valid custom Dev completion/denial can use its authenticated audit actor when a native event has no actual staff actor; native events can have default type `S` with a null UID, which must not prevent this fallback. A real positive native staff UID takes precedence. A ticket is never credited twice. + +Public roster cards expose safe total/per-department aggregates, not ticket IDs, account UUIDs, evidence or request content. Unavailable statistics are reported as unavailable; they never unlock a personal seal. + +## Rendering and freshness + +The original imperial department artwork is composed with a deterministic gold/sapphire name ribbon and “25 RESOLVED” label using the installed GD renderer. This is a code-rendered UI badge, not a manually granted achievement. Asset names contain an opaque digest rather than a central account UUID. The PNG is generated only for an eligible currently assigned department, atomically, in the Support image directory. Artwork falls back to the general seal if generation is unavailable. + +Signature rendering reads authoritative aggregates. Native close/reopen events schedule one stored-signature refresh at request shutdown, after the native closure and any Dev audit metadata have been committed. This updates the cached email/forum records without a periodic polling job. Historic ticket message bodies are not rewritten. + +## Checks and rollout + +- 23 focused Node tests cover roster/access regressions, actual SQL attribution, assignee decoys, system/administrative exclusions, custom Dev fallback, latest close, per-department totals and private-field exclusion. +- 16 PHP assertions cover 24/25/26, per-department isolation, Owner/Main Network Administrator non-exemption, duplicate seal removal, safe badge names and unavailable-data fallback. +- The personal artwork render test uses a private staging fixture, never a live award or fabricated closure count. +- Back up source plus stored signatures, preferences and pre-existing message hashes before rollout; compare existing message hashes, preferences and rank rows afterwards. Native signature source and the public roster are the only deployment targets. No game, economy or payment changes. + +Private recovery/evidence locations: `/root/ticket350-before-20261102`, `/home/dunerealms/.config/ticket350`, and the local `output/ticket-350` directory. Do not commit those private snapshots or restore them over newer user activity without review. diff --git a/website/integrations/managed-signatures.php b/website/integrations/managed-signatures.php index a6ca225c..68115ee4 100644 --- a/website/integrations/managed-signatures.php +++ b/website/integrations/managed-signatures.php @@ -1,6 +1,7 @@ PDO::ERRMODE_EXCEPTION]);}return$p; } @@ -16,11 +17,22 @@ function dune_signature_group($badges,$label,$fluid=false){ foreach($badges as[$url,$caption]){$caption=htmlspecialchars($caption,ENT_QUOTES);$cells.=''.$caption.'';} return '
'.htmlspecialchars($label,ENT_QUOTES).'
'.$cells.'
'; } -function dune_signature_staff_badges($account){ +function dune_signature_staff_badges($account,$verifiedStats=null){ $personal=[];$teams=[];$names=['support'=>'Support','ban-appeals'=>'Ban appeals','forum-support'=>'Forum support','legal'=>'Legal','sales'=>'Sales','network-staff'=>'Network staff','dev'=>'Development']; if(!empty($account['personal_path'])&&preg_match('~^/assets/seals/(?:(owner|corestaff|main-network-admin)-[a-z0-9_-]+|rank-network-staff)-150\.png$~',$account['personal_path'],$m)){$kind=!empty($m[1])?$m[1]:'rank';$host=in_array($kind,['main-network-admin','rank'],true)?'https://support.dunerealms.com':'https://www.dunerealms.com';$personal[]=[$host.$account['personal_path'],['owner'=>'Owner','corestaff'=>'Corestaff','main-network-admin'=>'Main network administrator','rank'=>'Network Staff'][$kind]];} - foreach(json_decode($account['departments_json']??'[]',true)?:[]as$key)if(isset($names[$key])){if($key==='network-staff'&&!is_file(__DIR__.'/osticket/assets/seals/department-network-staff-150.png'))continue;$version=$key==='legal'&&is_file(__DIR__.'/osticket/assets/seals/department-legal-v2-150.png')?'-v2':'';$host=($version||$key==='network-staff')?'https://support.dunerealms.com':'https://www.dunerealms.com';$teams[]=[$host.'/assets/seals/department-'.$key.$version.'-150.png',$names[$key].' · Department'];} - foreach(json_decode($account['teams_json']??'[]',true)?:[]as$key)if(isset($names[$key])&&is_file(__DIR__.'/osticket/assets/seals/team-'.$key.'.png'))$teams[]=['https://support.dunerealms.com/assets/seals/team-'.$key.'.png',$names[$key].' · Team']; + $stats=func_num_args()>1?$verifiedStats:dune_staff_closures_for($account['website_id']); + foreach(array_unique(json_decode($account['departments_json']??'[]',true)?:[])as$key)if(isset($names[$key])){ + if($key==='network-staff'&&!is_file(__DIR__.'/osticket/assets/seals/department-network-staff-150.png'))continue; + $version=$key==='legal'&&is_file(__DIR__.'/osticket/assets/seals/department-legal-v2-150.png')?'-v2':''; + $host=($version||$key==='network-staff')?'https://support.dunerealms.com':'https://www.dunerealms.com'; + $relative='/assets/seals/department-'.$key.$version.'-150.png';$url=$host.$relative;$caption=$names[$key].' · Department'; + if(dune_department_personal_earned($stats,$key)){ + $earned=dune_personal_department_asset($account,$key,dune_department_art_source($relative)); + if($earned){$url=$earned;$caption=$names[$key].' · '.$account['username'].' · Personal department seal (25+ resolved)';} + } + $teams[]=[$url,$caption]; + } + // A department is represented once. Do not repeat a second generic team medal. return[$personal,$teams]; } function dune_signature_extra_roles($id){ @@ -36,7 +48,7 @@ function dune_render_managed_signature($id,$context='forum'){ foreach(dune_community_seal_keys($id)as$key)if(is_file(__DIR__.'/osticket/assets/seals/'.$key.'.png'))$recognition[]=['https://support.dunerealms.com/assets/seals/'.$key.'.png',$labels[$key]]; $count=max(1,count($personal)+count($teams)+count($roles)+count($recognition)+count($offices));$fluid=$context!=='email';$layout=$fluid?'display:block;width:100%;container-type:inline-size;--dune-seal-size:clamp(48px,calc((100cqw - 120px) / '.$count.'),96px);':'display:inline-block;'; $html='
'.nl2br(htmlspecialchars($p['closing'],ENT_QUOTES)).'
'.htmlspecialchars($a['username'],ENT_QUOTES).'
'; - $groups=dune_signature_group($personal,'Personal',$fluid).dune_signature_group($roles,'Roles',$fluid).dune_signature_group($teams,'Departments & teams',$fluid).dune_signature_group($offices,'Elected offices',$fluid).dune_signature_group($recognition,'Recognition',$fluid); + $groups=dune_signature_group($personal,'Personal',$fluid).dune_signature_group($roles,'Roles',$fluid).dune_signature_group($teams,'Departments',$fluid).dune_signature_group($offices,'Elected offices',$fluid).dune_signature_group($recognition,'Recognition',$fluid); if($groups)$html.=''.$groups.'
'; if($context==='forum'&&$p['banner_url']!=='')$html.='
Personal banner
Personal forum signature banner
'; return $html.'
'; @@ -44,7 +56,7 @@ function dune_render_managed_signature($id,$context='forum'){ function dune_signature_bbcode($id){ $a=dune_signature_account($id);if(!$a)return'';$p=dune_signature_preferences($id);[$personal,$teams]=dune_signature_staff_badges($a); $bb=str_replace(['[',']'],['[',']'],$p['closing'])."\n\n[b]".str_replace(['[',']'],['[',']'],$a['username'])."[/b]\n\n"; - foreach([['Personal seals',$personal],['Departments & teams',$teams]]as[$label,$badges])if($badges){$bb.='[b]'.$label."[/b]\n";foreach($badges as[$url,$caption])$bb.='[img=48x48]'.$url.'[/img] ';$bb.="\n\n";} + foreach([['Personal seals',$personal],['Departments',$teams]]as[$label,$badges])if($badges){$bb.='[b]'.$label."[/b]\n";foreach($badges as[$url,$caption])$bb.='[img=48x48]'.$url.'[/img] ';$bb.="\n\n";} foreach(dune_community_seal_keys($id)as$key)if(is_file(__DIR__.'/osticket/assets/seals/'.$key.'.png'))$bb.='[img=48x48]https://support.dunerealms.com/assets/seals/'.$key.'.png[/img] '; if($p['banner_url']!=='')$bb.="\n\n[img]".$p['banner_url'].'[/img]';return trim($bb); } diff --git a/website/integrations/osticket/authenticate.php b/website/integrations/osticket/authenticate.php index 509c3b85..48c436ff 100644 --- a/website/integrations/osticket/authenticate.php +++ b/website/integrations/osticket/authenticate.php @@ -36,6 +36,8 @@ class DuneAccountsPlugin extends Plugin { var $config_class='DuneAccountsConfig'; function bootstrap(){ UserAuthenticationBackend::register(new DuneClientAuthentication());StaffAuthenticationBackend::register(new DuneStaffAuthentication()); + require_once '/home/dunerealms/apps/integrations/managed-signatures.php'; + dune_register_closure_signature_events(); if(PHP_SAPI==='cli')return; $file=basename($_SERVER['SCRIPT_NAME']??''); if(in_array($file,['dune-sso.php','cron.php','api.php'],true))return; diff --git a/website/integrations/osticket/tests/department-seal-test.php b/website/integrations/osticket/tests/department-seal-test.php new file mode 100644 index 00000000..d33f9b89 --- /dev/null +++ b/website/integrations/osticket/tests/department-seal-test.php @@ -0,0 +1,19 @@ +['support'=>24]],'support')); +verify_seal(dune_department_personal_earned(['departments'=>['support'=>25]],'support')); +verify_seal(dune_department_personal_earned(['departments'=>['support'=>26]],'support')); +verify_seal(!dune_department_personal_earned(['departments'=>['legal'=>25]],'support')); +$a=['website_id'=>'00000000-0000-4000-8000-00000000fa25','username'=>'unimatrix999','personal_path'=>'/assets/seals/owner-unimatrix999-150.png','departments_json'=>'["support","support"]','teams_json'=>'["support"]']; +[$role,$departments]=dune_signature_staff_badges($a,['departments'=>['support'=>24]]); +verify_seal(count($role)===1);verify_seal(count($departments)===1);verify_seal(str_contains($departments[0][0],'department-support-150.png'));verify_seal(!str_contains($departments[0][0],'personal-department')); +[$role,$departments]=dune_signature_staff_badges($a,['departments'=>['support'=>25]]); +verify_seal(count($role)===1);verify_seal(count($departments)===1);verify_seal(str_contains($departments[0][0],'earned/personal-department-support-'));verify_seal(str_contains($departments[0][1],'unimatrix999')); +verify_seal(!str_contains($departments[0][0],$a['website_id'])); +$main=$a;$main['username']='grmacken';$main['personal_path']='/assets/seals/main-network-admin-grmacken-150.png'; +[, $departments]=dune_signature_staff_badges($main,['departments'=>['support'=>0]]);verify_seal(count($departments)===1&&!str_contains($departments[0][0],'personal-department')); +[, $departments]=dune_signature_staff_badges($a,null);verify_seal(count($departments)===1&&!str_contains($departments[0][0],'personal-department')); +echo "$checks department-seal assertions passed\n"; diff --git a/website/integrations/staff-closure-counts.sql b/website/integrations/staff-closure-counts.sql new file mode 100644 index 00000000..87a0fdf1 --- /dev/null +++ b/website/integrations/staff-closure-counts.sql @@ -0,0 +1,30 @@ +SELECT credited.website_id, credited.department_id, credited.department_name, + COUNT(DISTINCT credited.ticket_id) AS closed_count +FROM ( + SELECT CASE WHEN e.uid_type='S' AND e.uid>0 THEN native_actor.id ELSE dev_actor.id END AS website_id, + e.dept_id AS department_id, department.name AS department_name, ticket.ticket_id + FROM drsupport_thread_event e + JOIN drsupport_event event_type ON event_type.id=e.event_id AND event_type.name='closed' + JOIN drsupport_thread thread ON thread.id=e.thread_id AND thread.object_type='T' + JOIN drsupport_ticket ticket ON ticket.ticket_id=thread.object_id + JOIN drsupport_ticket_status status ON status.id=ticket.status_id AND status.state='closed' + JOIN drsupport_department department ON department.id=e.dept_id + LEFT JOIN drsupport_staff actor_staff ON e.uid_type='S' AND actor_staff.staff_id=e.uid + AND actor_staff.backend='dunerealms-staff' + LEFT JOIN site_accounts native_actor ON REPLACE(native_actor.id,'-','')=actor_staff.username + LEFT JOIN dune_dev_tasks dev_task ON dev_task.ticket_id=ticket.ticket_id + LEFT JOIN dune_dev_task_events dev_event ON dev_event.ticket_id=dev_task.ticket_id + AND dev_event.action IN ('completed','denied') + AND dev_event.id=(SELECT MAX(last_event.id) FROM dune_dev_task_events last_event + WHERE last_event.ticket_id=dev_task.ticket_id + AND last_event.action IN ('completed','denied')) + LEFT JOIN site_accounts dev_actor ON dev_actor.id=dev_event.actor_id + AND dev_task.approval IN ('completed','denied') + WHERE e.annulled=0 + AND (dev_task.ticket_id IS NULL OR dev_task.approval IN ('completed','denied')) + AND NOT EXISTS (SELECT 1 FROM drsupport_thread_event later + WHERE later.thread_id=e.thread_id AND later.event_id=e.event_id + AND later.annulled=0 AND later.id>e.id) +) credited +WHERE credited.website_id IS NOT NULL +GROUP BY credited.website_id, credited.department_id, credited.department_name diff --git a/website/integrations/staff-closures.php b/website/integrations/staff-closures.php new file mode 100644 index 00000000..74509d08 --- /dev/null +++ b/website/integrations/staff-closures.php @@ -0,0 +1,60 @@ +'support','Ban appeals'=>'ban-appeals','Forum support'=>'forum-support','Legal'=>'legal','Sales'=>'sales','Network staff'=>'network-staff','Dev team'=>'dev'];} +function dune_staff_closure_stats($refresh=false){ + static $stats=false; + if($refresh||$stats===false){ + try{ + $rows=dune_signature_db()->query(file_get_contents(__DIR__.'/staff-closure-counts.sql'))->fetchAll(PDO::FETCH_ASSOC);$stats=[];$keys=dune_department_keys(); + foreach($rows as$row){$count=filter_var($row['closed_count'],FILTER_VALIDATE_INT,['options'=>['min_range'=>0]]);if($count===false)throw new RuntimeException('Invalid closure count');$id=$row['website_id'];$stats[$id]??=['totalClosed'=>0,'departments'=>[]];$stats[$id]['totalClosed']+=$count;if(isset($keys[$row['department_name']])){$key=$keys[$row['department_name']];$stats[$id]['departments'][$key]=($stats[$id]['departments'][$key]??0)+$count;}} + }catch(Throwable$e){$stats=null;} + } + return $stats; +} +function dune_staff_closures_for($id){$stats=dune_staff_closure_stats();return $stats===null?null:($stats[$id]??['totalClosed'=>0,'departments'=>[]]);} +function dune_department_personal_earned($stats,$department){return is_array($stats)&&($stats['departments'][$department]??0)>=DUNE_PERSONAL_DEPARTMENT_THRESHOLD;} +function dune_department_art_source($relative){ + if(!preg_match('~^/assets/seals/department-(?:support|ban-appeals|forum-support|legal|sales|network-staff|dev)(?:-v2)?-150\.png$~',$relative))return ''; + foreach([__DIR__.'/osticket','/home/dunerealms/apps/dunerealms/current/web']as$root)if(is_file($root.$relative))return $root.$relative; + return ''; +} +function dune_personal_department_asset($account,$department,$source){ + // This is a deterministic UI badge: original department artwork plus an imperial name ribbon. + $username=$account['username']??'';$id=$account['website_id']??''; + if(!preg_match('/^[a-z0-9_]{3,32}$/i',$username)||!preg_match('/^[a-f0-9-]{36}$/i',$id)||!in_array($department,dune_department_keys(),true)||!is_file($source)||!extension_loaded('gd'))return null; + $file='personal-department-'.$department.'-'.substr(hash('sha256',$id.'|'.$department.'|'.$username),0,20).'.png';$directory=__DIR__.'/osticket/assets/seals/earned';$path=$directory.'/'.$file; + if(!is_file($path)){ + if(!is_dir($directory)&&!mkdir($directory,0755,true)&&!is_dir($directory))return null; + if(!dune_draw_personal_department_badge($username,$source,$path))return null; + } + return 'https://support.dunerealms.com/assets/seals/earned/'.$file; +} +function dune_draw_personal_department_badge($username,$source,$path){ + if(!preg_match('/^[a-z0-9_]{3,32}$/i',$username)||!extension_loaded('gd'))return false; + $directory=dirname($path); + $base=@imagecreatefrompng($source);if(!$base)return false; + $im=imagecreatetruecolor(300,300);imagealphablending($im,false);imagesavealpha($im,true);$clear=imagecolorallocatealpha($im,0,0,0,127);imagefill($im,0,0,$clear);imagealphablending($im,true);imageantialias($im,true); + imagecopyresampled($im,$base,24,0,0,0,252,252,imagesx($base),imagesy($base)); + $gold=imagecolorallocate($im,211,175,80);$light=imagecolorallocate($im,246,221,151);$dark=imagecolorallocate($im,91,65,24);$blue=imagecolorallocate($im,14,43,63); + imagefilledpolygon($im,[8,232,33,222,267,222,292,232,280,250,292,272,264,267,36,267,8,272,20,250],$dark); + imagefilledpolygon($im,[15,232,37,227,263,227,285,232,275,250,285,265,261,261,39,261,15,265,25,250],$gold); + imagefilledrectangle($im,34,229,266,266,$blue);imagerectangle($im,33,227,267,268,$light);imagerectangle($im,38,232,262,263,$gold); + imagefilledellipse($im,31,248,7,7,$light);imagefilledellipse($im,269,248,7,7,$light); + $font='/usr/share/fonts/truetype/dejavu/DejaVuSerif-Bold.ttf'; + if(is_file($font)){$size=15;do{$box=imagettfbbox($size,0,$font,$username);$width=$box[2]-$box[0];if($width<=216)break;$size--;}while($size>7);imagettftext($im,$size,0,(int)((300-$width)/2),254,$light,$font,$username);$caption='25 RESOLVED';$box=imagettfbbox(8,0,$font,$caption);imagettftext($im,8,0,(int)((300-($box[2]-$box[0]))/2),286,$gold,$font,$caption);} + else imagestring($im,2,max(5,(int)((300-strlen($username)*6)/2)),243,$username,$light); + $tmp=tempnam($directory,'.badge-');$saved=$tmp&&imagepng($im,$tmp);imagedestroy($im);imagedestroy($base); + if(!$saved){if($tmp)is_file($tmp)&&unlink($tmp);return false;}chmod($tmp,0644);if(!rename($tmp,$path)){unlink($tmp);return false;} + return is_file($path); +} +function dune_closure_signature_event($object,$details){ + if(!($object instanceof Ticket)||!is_array($details)||!in_array($details['type']??'',['closed','reopened','transferred'],true))return; + static $queued=false;if($queued)return;$queued=true; + // The native event is written after the signal; refresh only once the request has committed it. + register_shutdown_function(static function(){ + try{dune_staff_closure_stats(true);$ids=dune_signature_db()->query('SELECT website_id FROM dune_signature_accounts')->fetchAll(PDO::FETCH_COLUMN);foreach($ids as$id)dune_refresh_signature_records($id);}catch(Throwable$e){error_log('Dune closure signature refresh failed; dynamic rendering remains authoritative.');} + }); +} +function dune_register_closure_signature_events(){if(class_exists('Signal')){Signal::connect('object.created','dune_closure_signature_event');Signal::connect('object.edited','dune_closure_signature_event');}} diff --git a/website/node/staff-closure-stats.mjs b/website/node/staff-closure-stats.mjs new file mode 100644 index 00000000..19778901 --- /dev/null +++ b/website/node/staff-closure-stats.mjs @@ -0,0 +1,13 @@ +import {readFileSync} from 'node:fs'; +export const PERSONAL_DEPARTMENT_THRESHOLD=25; +export const STAFF_CLOSURES_SQL=readFileSync(new URL('../integrations/staff-closure-counts.sql',import.meta.url),'utf8'); +export const DEPARTMENT_KEYS={'Support':'support','Ban appeals':'ban-appeals','Forum support':'forum-support','Legal':'legal','Sales':'sales','Network staff':'network-staff','Dev team':'dev'}; +// Actor is the verified closer, never the assignee. No ticket IDs leave this adapter. +export async function staffClosureStats(db){ + try{ + const {results}=await db.prepare(STAFF_CLOSURES_SQL).all();const stats=new Map(); + for(const row of results){const count=Number(row.closed_count);if(!Number.isSafeInteger(count)||count<0)throw Error('Invalid closure count');const value=stats.get(row.website_id)||{totalClosed:0,departments:{}};value.totalClosed+=count;const key=DEPARTMENT_KEYS[row.department_name];if(key)value.departments[key]=(value.departments[key]||0)+count;stats.set(row.website_id,value);} + return stats; + }catch{return null;} +} +export function statsForAccount(stats,id){return stats===null?null:stats.get(id)||{totalClosed:0,departments:{}};} diff --git a/website/node/staff-roster.mjs b/website/node/staff-roster.mjs index c0f38d54..37a259dc 100644 --- a/website/node/staff-roster.mjs +++ b/website/node/staff-roster.mjs @@ -1,3 +1,4 @@ +import {staffClosureStats,statsForAccount,PERSONAL_DEPARTMENT_THRESHOLD} from './staff-closure-stats.mjs'; import {publicProfileFor} from './profile.mjs'; import {accessFor,rankFor} from './permissions.mjs'; import {SHARED_HEADER,SHARED_HEAD} from '../scripts/portal-navigation.mjs'; @@ -26,7 +27,7 @@ function sealFor(user,ranks){ } export async function publicStaffRoster(db){ const {results}=await db.prepare("SELECT DISTINCT a.id,a.username,a.role FROM site_accounts a LEFT JOIN cp_account_ranks r ON r.user_id=a.id WHERE a.role NOT IN ('user','vip','player') OR r.rank_key NOT IN ('user','vip')").all(); - const roster=[]; + const roster=[],closureStats=await staffClosureStats(db); for(const user of results){ const access=await accessFor(db,user); if(!access.ranks.some(r=>!['user','vip'].includes(r))||!access.nodes.some(n=>['web.tickets.staff','web.forum.moderate','web.posts.edit','web.ranks.manage'].includes(n)))continue; @@ -34,11 +35,12 @@ export async function publicStaffRoster(db){ let publicProfile={};try{const profile=await publicProfileFor(db,user.id);publicProfile={bio:profile.bio,socials:profile.socials,git:profile.git};}catch{} let linked=false;try{linked=!!await db.prepare('SELECT 1 AS linked FROM site_game_links WHERE user_id=?').bind(user.id).first();}catch{} const portrait={url:'https://cp.dunerealms.com/api/avatars/roster/'+encodeURIComponent(user.username),mode:linked?'skin':'image'}; - roster.push({publicProfile,portrait,username:user.username,name:user.username,rankLabels,level:access.level,seal:sealFor(user,access.ranks),teams:teams.filter(([,node])=>access.nodes.includes(node)).map(([label])=>label)}); + roster.push({publicProfile,portrait,closedTickets:statsForAccount(closureStats,user.id),username:user.username,name:user.username,rankLabels,level:access.level,seal:sealFor(user,access.ranks),teams:teams.filter(([,node])=>access.nodes.includes(node)).map(([label])=>label)}); } return roster.sort((a,b)=>b.level-a.level||a.username.localeCompare(b.username)); } -const styles=`body{margin:0;background:#0c211a;color:#eee4cc;font:15px/1.65 system-ui,sans-serif}.roster-main{max-width:1120px;margin:0 auto;padding:32px 24px 48px}.roster-intro{padding:26px;border:1px solid #8a7b4a;border-radius:9px;background:linear-gradient(110deg,#203f32eb,#142e25eb),url('/assets/sietch.webp') center/cover;margin-bottom:26px}.roster-kicker{text-transform:uppercase;letter-spacing:.18em;color:#d8b86e;font-size:11px}.roster-intro h1{font-size:32px;line-height:1.2;margin:10px 0 12px;color:#f2e3b7}.roster-intro p{max-width:690px}.roster-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(240px,1fr));gap:16px}.roster-card{border:1px solid #5b704d;background:linear-gradient(145deg,#1f3e30,#112b21);border-radius:8px;padding:22px;display:flex;gap:16px;align-items:center;box-shadow:0 4px 12px #0002}.roster-card img{width:88px;height:88px;object-fit:contain;flex-shrink:0}.roster-card h2{font-size:19px;line-height:1.25;margin:0 0 7px;color:#f0d89e;overflow-wrap:anywhere}.roster-card p{font-size:12px;color:#c4d2bc;margin:5px 0}.roster-handle{color:#aebeab!important}.roster-teams{margin-top:32px;display:grid;grid-template-columns:repeat(auto-fit,minmax(290px,1fr));gap:16px}.roster-team{border:1px solid #526849;background:#142f24;border-radius:8px;padding:20px}.roster-team h2{font-size:18px;margin:0 0 14px;color:#e4ca8b;display:flex;align-items:center;gap:10px}.roster-team h2 img{width:44px;height:44px;object-fit:contain}.roster-team ul{list-style:none;display:flex;flex-wrap:wrap;gap:8px;margin:0;padding:0}.roster-team li{border:1px solid #4d6748;border-radius:5px;background:#203e2e;padding:5px 10px;color:#e5dec6;font-size:13px}.roster-help{margin-top:25px;padding:18px 22px;border-left:3px solid #b59b55;background:#183429}.roster-help a{color:#e4c478}.roster-footer{padding:22px 24px;text-align:center;border-top:1px solid #5a6949;background:#10271e;color:#c4c9ad;font-size:12px}.roster-footer a{color:#dec17c}@media(max-width:540px){.roster-main{padding:20px 14px}.roster-intro{padding:20px}.roster-intro h1{font-size:26px}.roster-grid{grid-template-columns:1fr}.roster-card{padding:17px}.roster-card img{width:74px;height:74px}}.roster-directory{border:1px solid #5a704c;border-radius:8px;background:#142f24;padding:20px;margin-bottom:24px}.roster-directory h2{font-size:21px;margin:0 0 16px;color:#e8d39e}.roster-table-scroll{overflow:auto}.roster-directory table{width:100%;border-collapse:collapse;font-size:12px;text-align:left}.roster-directory th,.roster-directory td{padding:11px;border-bottom:1px solid #3f5d43;vertical-align:top}.roster-directory thead{background:#254734;color:#ecd49a}.roster-directory tbody th{color:#ead7ab;white-space:nowrap}.roster-teams{display:block;margin-top:24px}.roster-team{padding:18px;margin-bottom:22px}.roster-team h2{margin-bottom:8px}.roster-team h2 small{margin-left:auto;color:#b9c8ac;font-size:11px;font-weight:400}.roster-team-table{width:100%;table-layout:fixed;border-collapse:separate;border-spacing:10px}.roster-team-table>tbody>tr>td{width:50%;padding:0;vertical-align:top}.roster-member-card{padding:18px;align-items:flex-start;gap:15px;height:100%;box-sizing:border-box}.roster-portrait{position:relative;flex:0 0 72px}.roster-portrait>img{width:72px;height:72px;border:1px solid #9b8c4c;border-radius:7px;background:#10281d}.roster-portrait>.roster-role-crest{position:absolute;width:32px;height:32px;right:-7px;bottom:-7px;border:0;background:#142e23;border-radius:50%}.roster-member-info{min-width:0;flex:1}.roster-member-info h3{margin:0 0 6px;font-size:18px;line-height:1.3;color:#efd49a;overflow-wrap:anywhere}.roster-rank-label{color:#dfc58c!important;font-weight:600}.roster-member-info dl{font-size:11px;line-height:1.6;margin:11px 0 0}.roster-member-info dt{color:#a9c2aa;font-size:10px;text-transform:uppercase;letter-spacing:.1em}.roster-member-info dd{margin:3px 0 0;color:#d0d8bf}.roster-public-profile{margin-top:11px;border-top:1px solid #496447;padding-top:8px;font-size:12px}.roster-public-profile summary{cursor:pointer;color:#dfc58c}.roster-socials{display:flex;flex-wrap:wrap;gap:7px;margin-top:10px}.roster-socials a{font-size:10px;padding:3px 7px;border:1px solid #64774d;border-radius:4px;color:#ead3a1;text-decoration:none}.roster-socials a:hover{background:#34553a}@media(max-width:700px){.roster-team-table,.roster-team-table tbody,.roster-team-table tr,.roster-team-table>tbody>tr>td{display:block;width:100%;box-sizing:border-box}.roster-team-table{border-spacing:0}.roster-team-table>tbody>tr>td{margin:10px 0}.roster-empty-cell{display:none!important}.roster-team{padding:14px}.roster-member-card{padding:15px}.roster-portrait{flex-basis:62px}.roster-portrait>img{width:62px;height:62px}.roster-directory{padding:14px}} +const styles=`.roster-ticket-stats{margin-top:12px;padding:11px 13px;border:1px solid #7c814f;border-radius:6px;background:#112d22}.roster-ticket-stats>div{display:flex;align-items:center;gap:12px}.roster-ticket-stats small{text-transform:uppercase;letter-spacing:.1em;font-size:9px;color:#c5ba87}.roster-ticket-stats strong{font-size:21px;color:#edd496}.roster-ticket-stats p{font-size:10px!important;color:#b9cdb3!important;margin:7px 0 0!important}.roster-ticket-stats>span{font-size:11px;color:#b0c4ae} +body{margin:0;background:#0c211a;color:#eee4cc;font:15px/1.65 system-ui,sans-serif}.roster-main{max-width:1120px;margin:0 auto;padding:32px 24px 48px}.roster-intro{padding:26px;border:1px solid #8a7b4a;border-radius:9px;background:linear-gradient(110deg,#203f32eb,#142e25eb),url('/assets/sietch.webp') center/cover;margin-bottom:26px}.roster-kicker{text-transform:uppercase;letter-spacing:.18em;color:#d8b86e;font-size:11px}.roster-intro h1{font-size:32px;line-height:1.2;margin:10px 0 12px;color:#f2e3b7}.roster-intro p{max-width:690px}.roster-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(240px,1fr));gap:16px}.roster-card{border:1px solid #5b704d;background:linear-gradient(145deg,#1f3e30,#112b21);border-radius:8px;padding:22px;display:flex;gap:16px;align-items:center;box-shadow:0 4px 12px #0002}.roster-card img{width:88px;height:88px;object-fit:contain;flex-shrink:0}.roster-card h2{font-size:19px;line-height:1.25;margin:0 0 7px;color:#f0d89e;overflow-wrap:anywhere}.roster-card p{font-size:12px;color:#c4d2bc;margin:5px 0}.roster-handle{color:#aebeab!important}.roster-teams{margin-top:32px;display:grid;grid-template-columns:repeat(auto-fit,minmax(290px,1fr));gap:16px}.roster-team{border:1px solid #526849;background:#142f24;border-radius:8px;padding:20px}.roster-team h2{font-size:18px;margin:0 0 14px;color:#e4ca8b;display:flex;align-items:center;gap:10px}.roster-team h2 img{width:44px;height:44px;object-fit:contain}.roster-team ul{list-style:none;display:flex;flex-wrap:wrap;gap:8px;margin:0;padding:0}.roster-team li{border:1px solid #4d6748;border-radius:5px;background:#203e2e;padding:5px 10px;color:#e5dec6;font-size:13px}.roster-help{margin-top:25px;padding:18px 22px;border-left:3px solid #b59b55;background:#183429}.roster-help a{color:#e4c478}.roster-footer{padding:22px 24px;text-align:center;border-top:1px solid #5a6949;background:#10271e;color:#c4c9ad;font-size:12px}.roster-footer a{color:#dec17c}@media(max-width:540px){.roster-main{padding:20px 14px}.roster-intro{padding:20px}.roster-intro h1{font-size:26px}.roster-grid{grid-template-columns:1fr}.roster-card{padding:17px}.roster-card img{width:74px;height:74px}}.roster-directory{border:1px solid #5a704c;border-radius:8px;background:#142f24;padding:20px;margin-bottom:24px}.roster-directory h2{font-size:21px;margin:0 0 16px;color:#e8d39e}.roster-table-scroll{overflow:auto}.roster-directory table{width:100%;border-collapse:collapse;font-size:12px;text-align:left}.roster-directory th,.roster-directory td{padding:11px;border-bottom:1px solid #3f5d43;vertical-align:top}.roster-directory thead{background:#254734;color:#ecd49a}.roster-directory tbody th{color:#ead7ab;white-space:nowrap}.roster-teams{display:block;margin-top:24px}.roster-team{padding:18px;margin-bottom:22px}.roster-team h2{margin-bottom:8px}.roster-team h2 small{margin-left:auto;color:#b9c8ac;font-size:11px;font-weight:400}.roster-team-table{width:100%;table-layout:fixed;border-collapse:separate;border-spacing:10px}.roster-team-table>tbody>tr>td{width:50%;padding:0;vertical-align:top}.roster-member-card{padding:18px;align-items:flex-start;gap:15px;height:100%;box-sizing:border-box}.roster-portrait{position:relative;flex:0 0 72px}.roster-portrait>img{width:72px;height:72px;border:1px solid #9b8c4c;border-radius:7px;background:#10281d}.roster-portrait>.roster-role-crest{position:absolute;width:32px;height:32px;right:-7px;bottom:-7px;border:0;background:#142e23;border-radius:50%}.roster-member-info{min-width:0;flex:1}.roster-member-info h3{margin:0 0 6px;font-size:18px;line-height:1.3;color:#efd49a;overflow-wrap:anywhere}.roster-rank-label{color:#dfc58c!important;font-weight:600}.roster-member-info dl{font-size:11px;line-height:1.6;margin:11px 0 0}.roster-member-info dt{color:#a9c2aa;font-size:10px;text-transform:uppercase;letter-spacing:.1em}.roster-member-info dd{margin:3px 0 0;color:#d0d8bf}.roster-public-profile{margin-top:11px;border-top:1px solid #496447;padding-top:8px;font-size:12px}.roster-public-profile summary{cursor:pointer;color:#dfc58c}.roster-socials{display:flex;flex-wrap:wrap;gap:7px;margin-top:10px}.roster-socials a{font-size:10px;padding:3px 7px;border:1px solid #64774d;border-radius:4px;color:#ead3a1;text-decoration:none}.roster-socials a:hover{background:#34553a}@media(max-width:700px){.roster-team-table,.roster-team-table tbody,.roster-team-table tr,.roster-team-table>tbody>tr>td{display:block;width:100%;box-sizing:border-box}.roster-team-table{border-spacing:0}.roster-team-table>tbody>tr>td{margin:10px 0}.roster-empty-cell{display:none!important}.roster-team{padding:14px}.roster-member-card{padding:15px}.roster-portrait{flex-basis:62px}.roster-portrait>img{width:62px;height:62px}.roster-directory{padding:14px}} /* Every team owns one full-width register; keep cached earlier grid rules from squeezing tables. */ .roster-teams{display:block!important;width:100%!important;max-width:none!important}.roster-team{position:relative;isolation:isolate;width:100%;box-sizing:border-box;border:1px solid #a58d4f!important;padding:18px!important;margin:0 0 26px!important;background:linear-gradient(140deg,#1d3b2dd9,#102b21f2),url('/assets/ornament.webp') center/cover;box-shadow:inset 0 0 0 4px #d6b86c0a,0 5px 14px #0002;overflow:hidden}.roster-team::before{content:"";pointer-events:none;position:absolute;inset:5px;border:1px solid #b29b4a24;border-radius:4px;z-index:-1}.roster-team h2{margin:-18px -18px 10px!important;padding:15px 22px;border-bottom:1px solid #9f894b;background:linear-gradient(90deg,#284c35e8,#19362ade),url('/assets/ornament.webp') center/cover;box-shadow:inset 0 2px #d8bc6455;font-size:21px}.roster-team h2 img{width:47px;height:47px;filter:drop-shadow(0 2px 2px #0005)}.roster-team h2 small{padding:3px 8px;border:1px solid #a28d4b66;border-radius:4px;background:#0e261b66;font-size:11px}.roster-team-table{width:100%!important;border-spacing:12px;table-layout:fixed}.roster-team-table>tbody>tr>td{vertical-align:top}.roster-team-table>tbody>tr>.roster-single-cell{width:100%}.roster-member-card{position:relative;height:auto!important;min-height:125px;padding:18px!important;border:1px solid #7c814f!important;background:linear-gradient(140deg,#244735,#122e23);box-shadow:inset 0 0 0 3px #cbb15c0a,0 3px 8px #0002}.roster-member-card::before{content:"";position:absolute;pointer-events:none;inset:5px;border-top:1px solid #bd9f4c22;border-bottom:1px solid #bd9f4c22;border-radius:3px}.roster-portrait>img{border-color:#c7a75e;box-shadow:0 0 0 2px #091f17,0 0 0 3px #a08d4555}.roster-member-info h3{font-size:19px;margin:0 0 9px;line-height:1.25;color:#f0d99f}.roster-rank-label{display:inline-block!important;border:1px solid #ad96504d;border-radius:4px;background:#d2b35b12;padding:3px 7px;font-size:11px!important;line-height:1.5}.roster-public-profile{font-size:12px}.roster-member-info dd{overflow-wrap:anywhere}.roster-socials{position:relative}.roster-socials a:focus-visible{outline:2px solid #e0c77d;outline-offset:3px}@media(max-width:700px){.roster-team{padding:12px!important}.roster-team h2{margin:-12px -12px 8px!important;padding:12px 15px;font-size:18px}.roster-team-table{display:block;border-spacing:0}.roster-team-table>tbody>tr>.roster-single-cell{width:100%}.roster-member-card{min-height:0;padding:15px!important}.roster-member-info h3{font-size:17px}.roster-team h2 small{font-size:10px}} @@ -53,9 +55,11 @@ export function createStaffRoster(db){return async request=>{ if(new URL(request.url).pathname==='/staff-roster.css')return new Response(request.method==='HEAD'?null:styles,{headers:{'Content-Type':'text/css; charset=utf-8','Cache-Control':'no-cache'}}); const roster=await publicStaffRoster(db); const bioBox=p=>{const bio=(p.publicProfile.bio||'').trim(),characters=Array.from(bio),long=characters.length>280;return '
Introduction'+esc(bio?(long?characters.slice(0,280).join('')+'…':bio):'Introduction coming soon.').replaceAll('\n','
')+'

'+(long?'
Read full introduction

'+esc(bio).replaceAll('\n','
')+'

':'')+'
';}; - const memberCard=p=>'
'+(p.portrait.mode==='skin'?'':'Steve avatar for '+esc(p.username)+'')+''+esc(p.rankLabels[0]||'Staff')+' seal

'+esc(p.username)+'

'+bioBox(p)+(Object.keys(p.publicProfile.socials||{}).length?'
'+Object.entries(p.publicProfile.socials).map(([label,url])=>''+socialIcon(label)+''+esc(socialLabels[label]||label)+'').join('')+'
':'')+'
'; + const departmentForTeam={'Network staff':'network-staff','Dev team':'dev','Legal team':'legal','Player support':'support','Ban appeals':'ban-appeals','Forum team':'forum-support','Sales team':'sales'}; + const closureBlock=(p,team)=>{const stats=p.closedTickets;if(!stats)return '
Resolved ticketsStatistics unavailable
';const key=departmentForTeam[team],count=key?(stats.departments[key]||0):null;return '
Tickets closed'+stats.totalClosed+'
'+(key?'

'+esc(team)+': '+count+' · '+(count>=PERSONAL_DEPARTMENT_THRESHOLD?'Personal department seal earned':count+' / '+PERSONAL_DEPARTMENT_THRESHOLD+' for a personal department seal')+'

':'')+'
';}; + const memberCard=(p,team)=>'
'+(p.portrait.mode==='skin'?'':'Steve avatar for '+esc(p.username)+'')+''+esc(p.rankLabels[0]||'Staff')+' seal

'+esc(p.username)+'

'+bioBox(p)+closureBlock(p,team)+(Object.keys(p.publicProfile.socials||{}).length?'
'+Object.entries(p.publicProfile.socials).map(([label,url])=>''+socialIcon(label)+''+esc(socialLabels[label]||label)+'').join('')+'
':'')+'
'; - const groups=teams.map(([name,,seal])=>{const members=roster.filter(p=>p.teams.includes(name));if(!members.length)return'';const rows=[];for(let i=0;i'+members.slice(i,i+2).map(p=>''+memberCard(p)+'').join('')+'');return '

'+esc(name)+''+members.length+' members

'+rows.join('')+'
';}).join(''); + const groups=teams.map(([name,,seal])=>{const members=roster.filter(p=>p.teams.includes(name));if(!members.length)return'';const rows=[];for(let i=0;i'+members.slice(i,i+2).map(p=>''+memberCard(p,name)+'').join('')+'');return '

'+esc(name)+''+members.length+' members

'+rows.join('')+'
';}).join(''); const html='DuneRealms Staff Roster | Community Teams'+SHARED_HEAD+''+SHARED_HEADER+'

The Imperial Service Register

Meet the DuneRealms staff

Behind every safe caravan stands a watchful crew. Meet the people caring for our community, its worlds and the journey ahead.

Current roles and team access are drawn from the account rank system.

'+(!roster.length?'

No staff members are currently listed.

':'')+'
'+groups+'
'; return new Response(request.method==='HEAD'?null:html,{headers:{'Content-Type':'text/html; charset=utf-8','Cache-Control':'public, max-age=30'}}); };} diff --git a/website/tests/staff-closure-stats.test.mjs b/website/tests/staff-closure-stats.test.mjs new file mode 100644 index 00000000..d2f6dc67 --- /dev/null +++ b/website/tests/staff-closure-stats.test.mjs @@ -0,0 +1,62 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import {LocalD1} from './d1-adapter.mjs'; +import {staffClosureStats,statsForAccount} from '../node/staff-closure-stats.mjs'; +import {publicStaffRoster,createStaffRoster} from '../node/staff-roster.mjs'; +function setup(){return new LocalD1(` + CREATE TABLE site_accounts(id TEXT PRIMARY KEY,username TEXT,role TEXT); + CREATE TABLE cp_account_ranks(user_id TEXT,rank_key TEXT); + CREATE TABLE cp_ranks(rank_key TEXT,label TEXT,rank_level INTEGER,kind TEXT,permissions_json TEXT,version INTEGER); + CREATE TABLE drsupport_staff(staff_id INTEGER PRIMARY KEY,username TEXT,backend TEXT); + CREATE TABLE drsupport_event(id INTEGER PRIMARY KEY,name TEXT); + CREATE TABLE drsupport_thread(id INTEGER PRIMARY KEY,object_id INTEGER,object_type TEXT); + CREATE TABLE drsupport_ticket(ticket_id INTEGER PRIMARY KEY,status_id INTEGER); + CREATE TABLE drsupport_ticket_status(id INTEGER PRIMARY KEY,state TEXT); + CREATE TABLE drsupport_department(id INTEGER PRIMARY KEY,name TEXT); + CREATE TABLE drsupport_thread_event(id INTEGER PRIMARY KEY,thread_id INTEGER,event_id INTEGER,uid_type TEXT,uid INTEGER,dept_id INTEGER,annulled INTEGER,staff_id INTEGER); + CREATE TABLE dune_dev_tasks(ticket_id INTEGER PRIMARY KEY,approval TEXT); + CREATE TABLE dune_dev_task_events(id INTEGER PRIMARY KEY,ticket_id INTEGER,actor_id TEXT,action TEXT); + INSERT INTO site_accounts VALUES('owner-private-id','unimatrix999','owners'),('admin-private-id','grmacken','web_net_admin'),('dev-private-id','dev','web_dev'); + INSERT INTO drsupport_staff VALUES(1,'ownerprivateid','dunerealms-staff'),(2,'adminprivateid','dunerealms-staff'),(3,'devprivateid','dunerealms-staff'); + INSERT INTO drsupport_event VALUES(2,'closed'); + INSERT INTO drsupport_ticket_status VALUES(1,'open'),(3,'closed'); + INSERT INTO drsupport_department VALUES(1,'Support'),(2,'Legal'),(8,'Dev team'); + `);} +async function ticket(db,id,{uid=1,type='S',dept=1,state=3,annulled=0,assigned=2,devState,devActor='dev-private-id',devAction='completed'}={}){ + await db.prepare('INSERT INTO drsupport_thread VALUES(?,?,?)').bind(id,id,'T').run(); + await db.prepare('INSERT INTO drsupport_ticket VALUES(?,?)').bind(id,state).run(); + await db.prepare('INSERT INTO drsupport_thread_event VALUES(?,?,2,?,?,?,?,?)').bind(id,id,type,uid,dept,annulled,assigned).run(); + if(devState){await db.prepare('INSERT INTO dune_dev_tasks VALUES(?,?)').bind(id,devState).run();await db.prepare('INSERT INTO dune_dev_task_events VALUES(?,?,?,?)').bind(id,id,devActor,devAction).run();} +} +test('credits the verified closing actor and department, not the assignee or account rank',async()=>{ + const db=setup();try{await ticket(db,1,{uid:1,assigned:2});const s=await staffClosureStats(db);assert.equal(statsForAccount(s,'owner-private-id').departments.support,1);assert.equal(statsForAccount(s,'admin-private-id').totalClosed,0);}finally{db.close();} +}); +test('excludes reopened, annulled, system and administrative consolidation records',async()=>{ + const db=setup();try{ + await ticket(db,1,{state:1});await ticket(db,2,{annulled:1});await ticket(db,3,{type:null,uid:0}); + await ticket(db,4,{devState:'consolidated'});await ticket(db,5,{devState:'superseded'});await ticket(db,6,{devState:'approved'}); + const s=await staffClosureStats(db);assert.equal(statsForAccount(s,'owner-private-id').totalClosed,0);assert.equal(statsForAccount(s,'dev-private-id').totalClosed,0); + }finally{db.close();} +}); +test('custom Dev completion/denial attribution is used only for valid closed work, without double credit',async()=>{ + const db=setup();try{ + await ticket(db,1,{type:'S',uid:null,dept:8,devState:'completed'}); + await ticket(db,2,{type:'U',uid:56,dept:8,devState:'denied',devAction:'denied',devActor:'owner-private-id'}); + await ticket(db,3,{uid:1,dept:8,devState:'completed'}); + const s=await staffClosureStats(db);assert.equal(statsForAccount(s,'dev-private-id').departments.dev,1);assert.equal(statsForAccount(s,'owner-private-id').departments.dev,2); + }finally{db.close();} +}); +test('one latest valid closure wins even if older closure was not annulled',async()=>{ + const db=setup();try{await ticket(db,1,{uid:1});await db.prepare("INSERT INTO drsupport_thread_event VALUES(99,1,2,'S',2,2,0,1)").run();const s=await staffClosureStats(db);assert.equal(statsForAccount(s,'owner-private-id').totalClosed,0);assert.equal(statsForAccount(s,'admin-private-id').departments.legal,1);}finally{db.close();} +}); +test('25 is a total per department, not a percentage; roster exposes only safe aggregate counts',async()=>{ + const db=setup();try{ + for(let id=1;id<=25;id++)await ticket(db,id,{uid:1});await ticket(db,26,{uid:1,dept:2}); + const roster=await publicStaffRoster(db),owner=roster.find(r=>r.username==='unimatrix999');assert.equal(owner.closedTickets.totalClosed,26);assert.equal(owner.closedTickets.departments.support,25);assert.equal(owner.closedTickets.departments.legal,1); + const html=await(await createStaffRoster(db)(new Request('https://www.dunerealms.com/staff.html'))).text();assert(html.includes('Personal department seal earned'));assert(html.includes('1 / 25 for a personal department seal')); + const publicJson=JSON.stringify(roster);for(const secret of ['owner-private-id','admin-private-id','ticket_id','staff_id','department_id'])assert(!publicJson.includes(secret)); + }finally{db.close();} +}); +test('missing native statistics fail visibly unavailable, never grant an award or invent zero',async()=>{ + const db=new LocalD1('CREATE TABLE placeholder(id TEXT)');try{assert.equal(await staffClosureStats(db),null);assert.equal(statsForAccount(null,'some-id'),null);}finally{db.close();} +});