Fresh production baseline [skip ci]

This commit is contained in:
DuneRealms 2026-11-27 23:43:05 +00:00
commit 0a11a18274

View file

@ -0,0 +1,44 @@
<?php
// Explicit operator workflow for the human-requested permanent example ticket.
// Uses the installed form validator and native Ticket API, not a web login bypass.
if(PHP_SAPI!=='cli'||posix_geteuid()!==0)exit("Server administrator CLI required\n");
$mode=$argv[1]??'';if(!in_array($mode,['create','complete','verify-protection'],true))exit("Choose create, complete or verify-protection\n");
$root='/home/dunerealms/apps/integrations/osticket';chdir($root);
$_SERVER['SCRIPT_NAME']='dev-example-cli.php';$_SERVER['REQUEST_METHOD']='CLI';$_SERVER['REMOTE_ADDR']='127.0.0.1';$_SERVER['SERVER_PORT']='443';
require $root.'/main.inc.php';require_once $root.'/dev-policy.php';
$identity=json_decode(file_get_contents('/tmp/dune-dev-example-identity.json'),true,512,JSON_THROW_ON_ERROR);
if(!dune_dev_owner($identity))throw new RuntimeException('Verified current Dev owner authority required');
$c=json_decode(file_get_contents('/home/dunerealms/.config/integrations.json'),true);
$db=new PDO('mysql:host='.$c['host'].';dbname='.$c['database'].';charset=utf8mb4',$c['username'],$c['password'],[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION,PDO::ATTR_DEFAULT_FETCH_MODE=>PDO::FETCH_ASSOC]);
$key='gary:jarvis-dev-form-example:20261119';$q=$db->prepare('SELECT d.*,t.number FROM dune_dev_tasks d JOIN drsupport_ticket t ON t.ticket_id=d.ticket_id WHERE d.task_key=?');$q->execute([$key]);$row=$q->fetch();
if($mode==='create'&&!$row){
$input=['title'=>'Rebuild the staff Dev request form for J.A.R.V.I.S. — permanent worked example','type'=>'Feature','system'=>'osTicket Dev Center / J.A.R.V.I.S. request planning','objective'=>'Replace the old request form with a staff-friendly Jarvis form. Support existing actions, future feature ideas, new key/action proposals, code/interface work and explicit DEV KEY REQUESTS. Preserve the useful context, outcome and acceptance questions. This ticket demonstrates request, implementation, testing, publication and closure.','current'=>'The existing form assumes every approved task should lead to code changes and predates the Jarvis catalogue and controlled execution model.','expected'=>'Staff can state an idea without knowing implementation details. Existing actions collect typed parameters; new proposals explain their intended outcome; developer key requests are unambiguous review requests, never web key issuance.','acceptance'=>'Old form replaced; existing-action parameters validated; future ideas/new action proposals supported; devkey route records actor, environment, scope, lifetime, destructive effects and recovery. No real keys issued by this form. Existing tickets unchanged. Positive and negative tests pass, source commit and CI recorded, live form verified. Close this ticket only with actual evidence and preserve it against deletion.','scope'=>'Only the Dev request form, its planning/validation/publisher and this one worked-example ticket. Do not rewrite, bulk close or migrate older tickets. Do not change key execution permissions or issue developer keys.','reproduction'=>'Open the old Dev new-request form: it has no Jarvis route or typed action fields.','testplan'=>'Validate all routes and reject unknown actions, malformed typed parameters and incomplete developer requests. Check markup escaping, old-ticket preservation, publisher idempotency, PHP syntax and live form rendering. Verify this example cannot be deleted.','references'=>'https://support.dunerealms.com/dev-tasks.php?view=new','dependencies'=>'Existing osTicket approval/private visibility rules and Jarvis masterkey catalogue.','risk'=>'No domain data operations or devkey issuance. Preserve all older requests and their history. Publish via reviewed source and CI; retain the existing native view if its boundaries changed.','priority'=>'Medium','timing'=>'Current owner-requested batch','privacy'=>'1'];
[$values,$errors]=dune_dev_validate($input);if($errors)throw new RuntimeException(implode('; ',$errors));
$topic=$db->query("SELECT topic_id,dept_id,team_id FROM drsupport_help_topic WHERE topic='Development task' AND ispublic=0")->fetch();if(!$topic)throw new RuntimeException('Native Dev routing unavailable');
$email=$identity['id'].'@accounts.dunerealms.invalid';$user=User::lookupByEmail($email)?:User::fromVars(['name'=>$identity['username'],'email'=>$email]);if(!$user)throw new RuntimeException('Native requester unavailable');
$nativeErrors=[];$ticket=Ticket::create(['uid'=>$user->getId(),'name'=>$identity['username'],'email'=>$email,'topicId'=>$topic['topic_id'],'deptId'=>$topic['dept_id'],'teamId'=>$topic['team_id'],'subject'=>$values['title'],'message'=>nl2br(htmlspecialchars(dune_dev_prompt($values),ENT_QUOTES,'UTF-8')),'source'=>'API','ip'=>'127.0.0.1','autorespond'=>false],$nativeErrors,'API',false,false);
if(!$ticket)throw new RuntimeException('Native ticket creation failed');
$q=$db->prepare("INSERT INTO dune_dev_tasks(task_key,ticket_id,submitter_id,title,prompt_json,approval,priority,task_type,approved_by,decision_note,execution_spec,created_at,updated_at) VALUES(?,?,?,?,?,'approved',?,?,?,?,?,NOW(),NOW())");
$q->execute([$key,$ticket->getId(),$identity['id'],$values['title'],json_encode($values,JSON_THROW_ON_ERROR),'Medium','Feature',$identity['id'],'Explicit Owner submission: permanent worked example.',dune_dev_execution_brief($values)]);
$row=['ticket_id'=>$ticket->getId(),'number'=>$ticket->getNumber(),'approval'=>'approved'];
}
if(!$row)throw new RuntimeException('Example ticket unavailable');
// A restrictive foreign key protects native deletion routes and direct ticket DELETE.
$column=$db->query("SHOW COLUMNS FROM drsupport_ticket LIKE 'ticket_id'")->fetch();$type=$column['Type'];if(!preg_match('/^(?:int|bigint)\([0-9]+\)(?: unsigned)?$/i',$type)&&!preg_match('/^(?:int|bigint)(?: unsigned)?$/i',$type))throw new RuntimeException('Unexpected native ticket ID type');
$db->exec("CREATE TABLE IF NOT EXISTS dune_retained_dev_tickets(ticket_id $type PRIMARY KEY,reason VARCHAR(255) NOT NULL,created_at DATETIME NOT NULL,CONSTRAINT dune_retained_dev_ticket_fk FOREIGN KEY(ticket_id) REFERENCES drsupport_ticket(ticket_id) ON DELETE RESTRICT) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4");
$q=$db->prepare('INSERT IGNORE INTO dune_retained_dev_tickets(ticket_id,reason,created_at) VALUES(?,?,NOW())');$q->execute([$row['ticket_id'],'Owner-requested permanent Jarvis worked example; preserve request, implementation and evidence.']);
if($mode==='verify-protection'){
$blocked=false;$db->beginTransaction();
try{$q=$db->prepare('DELETE FROM drsupport_ticket WHERE ticket_id=?');$q->execute([$row['ticket_id']]);}
catch(PDOException $error){$blocked=($error->errorInfo[1]??null)===1451;}
finally{$db->rollBack();}
if(!$blocked)throw new RuntimeException('Deletion protection was not confirmed');
echo json_encode(['ticketId'=>(int)$row['ticket_id'],'number'=>$row['number'],'nativeDeleteBlocked'=>true,'testTransactionRolledBack'=>true])."\n";exit;
}
if($mode==='complete'&&$row['approval']!=='completed'){
$note=file_get_contents('php://stdin');$next=dune_dev_transition($identity,'complete',$row['approval'],$note);$ticket=Ticket::lookup($row['ticket_id']);$errors=[];
if(!$ticket->setStatus(3,$note,$errors,false,true))throw new RuntimeException('Native close failed; completion not saved');
$q=$db->prepare("UPDATE dune_dev_tasks SET approval=?,approved_by=?,decision_note=?,updated_at=NOW() WHERE ticket_id=? AND approval='approved'");$q->execute([$next,$identity['id'],$note,$row['ticket_id']]);
$q=$db->prepare('INSERT INTO dune_dev_task_events(ticket_id,actor_id,action,note,created_at) VALUES(?,?,?,?,NOW())');$q->execute([$row['ticket_id'],$identity['id'],'completed',$note]);$row['approval']=$next;
}
echo json_encode(['ticketId'=>(int)$row['ticket_id'],'number'=>$row['number'],'state'=>$row['approval'],'deletionProtected'=>true,'url'=>'https://support.dunerealms.com/dev-tasks.php?id='.$row['ticket_id']],JSON_THROW_ON_ERROR)."\n";